From 1440190921cdcc18ab021d88fa9d464cee887af0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 14 Sep 2015 21:15:01 +0200 Subject: [PATCH 001/360] Post-release alpha-0.1.6 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7aa9cde..2732fe53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,9 @@ set(COLOBOT_VERSION_MINOR 1) set(COLOBOT_VERSION_REVISION 6) # Used on official releases -set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha") +#set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha") # Used on unreleased, development builds -#set(COLOBOT_VERSION_UNRELEASED "+alpha") +set(COLOBOT_VERSION_UNRELEASED "+alpha") # Append git characteristics to version if(DEFINED COLOBOT_VERSION_UNRELEASED) From 53e4470dbf7a33349e66858a94dcd2a3ea2712ce Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 24 Sep 2015 21:09:46 +0200 Subject: [PATCH 002/360] Started SDL2 migration --- CMakeLists.txt | 21 +- cmake/FindSDL2.cmake | 163 ++++++ cmake/FindSDL2_image.cmake | 158 +++++ cmake/FindSDL2_ttf.cmake | 157 +++++ lib/clipboard/.gitignore | 1 - lib/clipboard/CMakeLists.txt | 18 - lib/clipboard/COPYING.README | 72 --- lib/clipboard/include/clipboard/clipboard.h | 55 -- lib/clipboard/include/clipboard/types.h | 100 ---- lib/clipboard/include/clipboard/utf.h | 115 ---- lib/clipboard/include/clipboard/wzglobal.h | 614 -------------------- lib/clipboard/readme.txt | 1 - lib/clipboard/src/clipboardOSX.m | 24 - lib/clipboard/src/clipboardWin32.c | 160 ----- lib/clipboard/src/clipboardX11.c | 293 ---------- lib/clipboard/src/utf.c | 530 ----------------- src/CMakeLists.txt | 18 +- src/app/app.cpp | 232 +++----- src/app/app.h | 21 +- src/app/input.cpp | 18 +- src/common/image.cpp | 2 +- src/common/key.cpp | 4 +- src/common/key.h | 5 +- src/common/resources/sdl_file_wrapper.cpp | 15 +- src/common/resources/sdl_file_wrapper.h | 7 +- src/common/restext.cpp | 7 +- src/common/thread/resource_owning_thread.h | 8 +- src/graphics/engine/engine.cpp | 2 +- src/graphics/engine/text.cpp | 2 +- src/graphics/opengl/gl21device.cpp | 4 +- src/graphics/opengl/gl33device.cpp | 4 +- src/graphics/opengl/gldevice.cpp | 4 +- src/level/robotmain.cpp | 3 +- src/ui/controls/edit.cpp | 7 +- src/ui/controls/key.cpp | 3 +- src/ui/screen/screen_setup_display.cpp | 6 +- 36 files changed, 641 insertions(+), 2213 deletions(-) create mode 100644 cmake/FindSDL2.cmake create mode 100644 cmake/FindSDL2_image.cmake create mode 100644 cmake/FindSDL2_ttf.cmake delete mode 100644 lib/clipboard/.gitignore delete mode 100644 lib/clipboard/CMakeLists.txt delete mode 100644 lib/clipboard/COPYING.README delete mode 100644 lib/clipboard/include/clipboard/clipboard.h delete mode 100644 lib/clipboard/include/clipboard/types.h delete mode 100644 lib/clipboard/include/clipboard/utf.h delete mode 100644 lib/clipboard/include/clipboard/wzglobal.h delete mode 100644 lib/clipboard/readme.txt delete mode 100644 lib/clipboard/src/clipboardOSX.m delete mode 100644 lib/clipboard/src/clipboardWin32.c delete mode 100644 lib/clipboard/src/clipboardX11.c delete mode 100644 lib/clipboard/src/utf.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2732fe53..501982cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,9 +229,9 @@ endif() ## find_package(OpenGL 1.4 REQUIRED) -find_package(SDL 1.2.10 REQUIRED) -find_package(SDL_image 1.2 REQUIRED) -find_package(SDL_ttf 2.0 REQUIRED) +find_package(SDL2 REQUIRED) +find_package(SDL2_image REQUIRED) +find_package(SDL2_ttf REQUIRED) find_package(PNG 1.2 REQUIRED) find_package(Gettext REQUIRED) find_package(PhysFS REQUIRED) @@ -295,21 +295,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(WINGETOPT 1) # use wingetopt library endif() -## -# Clipboard support needs X11 libraries -## -if(PLATFORM_GNU) - find_package(X11 REQUIRED) -endif() - - -## -# Clipboard support -## -set(CLIPBOARD_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/clipboard/include) -add_subdirectory(lib/clipboard) - - ## # Localename ## diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 00000000..236d6b4b --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,163 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +SET(SDL2_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include + PATHS ${SDL2_SEARCH_PATHS} +) + +FIND_LIBRARY(SDL2_LIBRARY_TEMP + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2_SEARCH_PATHS} +) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2_SEARCH_PATHS} + ) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL2_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/cmake/FindSDL2_image.cmake b/cmake/FindSDL2_image.cmake new file mode 100644 index 00000000..78704cbe --- /dev/null +++ b/cmake/FindSDL2_image.cmake @@ -0,0 +1,158 @@ +# Locate SDL2_image library +# This module defines +# SDL2_IMAGE_LIBRARY, the name of the library to link against +# SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image +# SDL2_IMAGE_INCLUDE_DIR, where to find SDL_image.h +# +# Additional Note: If you see an empty SDL2_IMAGE_LIBRARY_TEMP in your configuration +# and no SDL2_IMAGE_LIBRARY, it means CMake did not find your SDL2_Image library +# (SDL2_image.dll, libsdl2_image.so, SDL2_image.framework, etc). +# Set SDL2_IMAGE_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_IMAGE_LIBRARY +# variable, but when these values are unset, SDL2_IMAGE_LIBRARY does not get created. +# +# $SDL2 is an environment variable that would +# correspond to the ./configure --prefix=$SDL2 +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_IMAGE_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. +# +# Note that on windows this will only search for the 32bit libraries, to search +# for 64bit change x86/i686-w64 to x64/x86_64-w64 + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES include/SDL2 include SDL2 + i686-w64-mingw32/include/SDL2 + x86_64-w64-mingw32/include/SDL2 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Lookup the 64 bit libs on x64 +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP + NAMES SDL2_image + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +# On 32bit build find the 32bit libs +ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP + NAMES SDL2_image + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_IMAGE} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + +SET(SDL2_IMAGE_FOUND "NO") + IF(SDL2_IMAGE_LIBRARY_TEMP) + # Set the final string here so the GUI reflects the final state. + SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_image Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "") + SET(SDL2_IMAGE_FOUND "YES") +ENDIF(SDL2_IMAGE_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_IMAGE REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) + diff --git a/cmake/FindSDL2_ttf.cmake b/cmake/FindSDL2_ttf.cmake new file mode 100644 index 00000000..9f38607e --- /dev/null +++ b/cmake/FindSDL2_ttf.cmake @@ -0,0 +1,157 @@ +# Locate SDL2_ttf library +# This module defines +# SDL2_TTF_LIBRARY, the name of the library to link against +# SDL2_TTF_FOUND, if false, do not try to link to SDL2_ttf +# SDL2_TTF_INCLUDE_DIR, where to find SDL_image.h +# +# Additional Note: If you see an empty SDL2_TTF_LIBRARY_TEMP in your configuration +# and no SDL2_TTF_LIBRARY, it means CMake did not find your SDL2_Image library +# (SDL2_ttf.dll, libsdl2_image.so, SDL2_ttf.framework, etc). +# Set SDL2_TTF_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_TTF_LIBRARY +# variable, but when these values are unset, SDL2_TTF_LIBRARY does not get created. +# +# $SDL2 is an environment variable that would +# correspond to the ./configure --prefix=$SDL2 +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_TTF_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. +# +# Note that on windows this will only search for the 32bit libraries, to search +# for 64bit change x86/i686-w64 to x64/x86_64-w64 + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2014 Kitware, Inc. +# Copyright 2000-2011 Insight Software Consortium +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_TTF_INCLUDE_DIR SDL_ttf.h + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES include/SDL2 include SDL2 + i686-w64-mingw32/include/SDL2 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Lookup the 64 bit libs on x64 +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP + NAMES SDL2_ttf + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES lib64 lib + lib/x64 + x86_64-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +# On 32bit build find the 32bit libs +ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8) + FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP + NAMES SDL2_ttf + HINTS + ${SDL2} + $ENV{SDL2} + $ENV{SDL2_TTF} + PATH_SUFFIXES lib + lib/x86 + i686-w64-mingw32/lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) +ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8) + +SET(SDL2_TTF_FOUND "NO") + IF(SDL2_TTF_LIBRARY_TEMP) + # Set the final string here so the GUI reflects the final state. + SET(SDL2_TTF_LIBRARY ${SDL2_TTF_LIBRARY_TEMP} CACHE STRING "Where the SDL2_ttf Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_TTF_LIBRARY_TEMP "${SDL2_TTF_LIBRARY_TEMP}" CACHE INTERNAL "") + SET(SDL2_TTF_FOUND "YES") +ENDIF(SDL2_TTF_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_TTF REQUIRED_VARS SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR) + diff --git a/lib/clipboard/.gitignore b/lib/clipboard/.gitignore deleted file mode 100644 index ffbe18e0..00000000 --- a/lib/clipboard/.gitignore +++ /dev/null @@ -1 +0,0 @@ -libclipboard.a diff --git a/lib/clipboard/CMakeLists.txt b/lib/clipboard/CMakeLists.txt deleted file mode 100644 index ff9157e8..00000000 --- a/lib/clipboard/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -include_directories(. include/clipboard) - -add_definitions(-DLIB_COMPILE=1) - - -if(PLATFORM_WINDOWS) - set(CLIPBOARD_SRC src/clipboardWin32.c) -elseif(PLATFORM_MACOSX) - set(CMAKE_CXX_FLAGS "-fobjc-arc") - set(CLIPBOARD_SRC src/clipboardOSX.m) -else() - set(CLIPBOARD_SRC src/clipboardX11.c) -endif() - -include_directories(${SDL_INCLUDE_DIR}) -add_library(clipboard STATIC src/utf.c ${CLIPBOARD_SRC}) diff --git a/lib/clipboard/COPYING.README b/lib/clipboard/COPYING.README deleted file mode 100644 index 2f8aad83..00000000 --- a/lib/clipboard/COPYING.README +++ /dev/null @@ -1,72 +0,0 @@ -Warzone 2100 Source & Data --------------------------- - -This document replaces the file "readme.txt" as present in the Warzone 2100 GPL - release of December 6th 2004. - -1) These source and data files are provided as is with no guarantees: - - No assistance or support will be offered or given. - - Everything you will require to make a build of the game should be here. If - it isn't, you'll have to improvise. - - None of us here at Pivotal Games are in a position to be able to offer any - help with making this work. - -2) Everything included (source code and data), as well as the not included - videos and music, is released under the terms of the GNU General Public - License, version 2 or (at your option) any later version. - Please be sure to read the entirety of this license, but the summary is that - you're free to do what you want with the source subject to making the full - source code freely available in the event of the distribution of new - binaries. - -3) Following exception to the GPL is granted: - ------ - Linking Warzone 2100 statically or dynamically with other modules is making - a combined work based on Warzone 2100. Thus, the terms and conditions of - the GNU General Public License cover the whole combination. - - In addition, as a special exception, the copyright holders of Warzone 2100 - give you permission to combine Warzone 2100 with code included in the - standard release of libraries that are accessible, redistributable and - linkable free of charge. You may copy and distribute such a system - following the terms of the GNU GPL for Warzone 2100 and the licenses of the - other code concerned. - - Note that people who make modified versions of Warzone 2100 are not - obligated to grant this special exception for their modified versions; it - is their choice whether to do so. The GNU General Public License gives - permission to release a modified version without this exception; this - exception also makes it possible to release a modified version which - carries forward this exception. - ------ - -4) Permission is granted to use the name "Warzone 2100", the logos, stories, - texts and related materials. - -5) Permission is granted to copy and distribute unaltered copies and/or images - of the original game discs in any medium, provided that they are distributed - free of charge and retain their original copyright and trademark notices. - -Finally, the primary motivation for this release is for entertainment and - educational purposes. On the subject of the latter, don't be surprised to see - some pretty gnarly old-school C code in here; the game was a classic, but large - areas of the code aren't pretty; OO design and C++ evangelists beware! We - haven't spent any time cleaning the code or making it pretty - what you see is - what you're getting, warts n' all. - -Thank you to Jonathan Kemp of Eidos Europe for permitting the release. Thanks to - Martin Severn for allowing to use his soundtrack. Thanks to Jason Walker for - helping to facilitate the release of the movies and sound tracks, as well as - clarifying the meaning of this license. Thanks also to Frank Lamboy for - assistance with the release and for campaigning along with many many others - over the years for the source to be made available. -The correspondence, online petitions and persistence made this possible. We were - constantly amazed at the community support for Warzone even after all this - time; it's nice to be able to give something back, assuming you can get it to - compile... ;-) - -Original - 6th December 2004 -Alex M - ex Pumpkin Studios (Eidos) - -Amended - 10th June 2008 -Jason W - Eidos diff --git a/lib/clipboard/include/clipboard/clipboard.h b/lib/clipboard/include/clipboard/clipboard.h deleted file mode 100644 index dcee2eae..00000000 --- a/lib/clipboard/include/clipboard/clipboard.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 2008 Freddie Witherden - Copyright (C) 2008-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef CLIPBOARD_H_ -#define CLIPBOARD_H_ - -#include - -#ifdef __cplusplus - extern "C" { -#endif - -/** - * Returns a copy of the text in the systems clipboard. Should the clipboard be - * empty, or populated with non-textual data NULL is returned. The character set - * of the returned is guaranteed to be UTF-8. - * - * It remains the responsibility of the caller to free() the string when - * finished with it. - * - * @return The textual contents of the clipboard (if any), otherwise NULL. - */ -char *widgetGetClipboardText(void); - -/** - * Attempts to set the contents of the systems clipboard to text. The character - * set of text must be UTF-8. - * - * @param text The UTF-8 text to set the clipboard to. - * @return True if the contents were successfully set, false otherwise. - */ -bool widgetSetClipboardText(const char *text); - -#ifdef __cplusplus -} -#endif - -#endif /*CLIPBOARD_H_*/ diff --git a/lib/clipboard/include/clipboard/types.h b/lib/clipboard/include/clipboard/types.h deleted file mode 100644 index ff7ca683..00000000 --- a/lib/clipboard/include/clipboard/types.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -/*! \file - * \brief Simple type definitions. - */ - -#ifndef __INCLUDED_LIB_FRAMEWORK_TYPES_H__ -#define __INCLUDED_LIB_FRAMEWORK_TYPES_H__ - -#include "wzglobal.h" - -#ifdef HAVE_INTTYPES_H // defined WZ_C99 -/* Compilers that have support for C99 have all values below defined in stdint.h */ -# include -#else -// Defines C99 types for C99 incompatible compilers (e.g. MSVC) -#include -#ifndef WZ_CC_MINGW -# define INT8_MIN (-128) -# define INT16_MIN (-32767-1) -# define INT32_MIN (-2147483647-1) -# define INT8_MAX (127) -# define INT16_MAX (32767) -# define INT32_MAX (2147483647) -# define UINT8_MAX (255) -# define UINT16_MAX (65535) -# define UINT32_MAX (4294967295U) -#endif -#ifdef WZ_CC_MSVC -# define PRIu32 "u" -# define PRIu64 "I64u" -typedef SSIZE_T ssize_t; -#endif -#endif // WZ_C99 - -#include -#include - -/* Basic numeric types */ -typedef uint8_t UBYTE; -typedef int8_t SBYTE; -typedef uint16_t UWORD; -typedef int16_t SWORD; -typedef uint32_t UDWORD; -typedef int32_t SDWORD; - -/* Numeric size defines */ -#define UBYTE_MAX UINT8_MAX -#define SBYTE_MIN INT8_MIN -#define SBYTE_MAX INT8_MAX -#define UWORD_MAX UINT16_MAX -#define SWORD_MIN INT16_MIN -#define SWORD_MAX INT16_MAX -#define UDWORD_MAX UINT32_MAX -#define SDWORD_MIN INT32_MIN -#define SDWORD_MAX INT32_MAX - -// If we are C99 compatible, the "bool" macro will be defined in (as _Bool) -// C++ comes with an integrated bool type -#if defined(WZ_CXX98) -#elif defined(WZ_C99) -# include -#else -// Pretend we are C99 compatible (well, for the bool type then) -# ifndef bool -# define bool BOOL -# endif -# ifndef true -# define true (1) -# endif -# ifndef false -# define false (0) -# endif -# ifndef __bool_true_false_are_defined -# define __bool_true_false_are_defined (1) -# endif -#endif /* WZ_C99 */ - -#if !defined(WZ_OS_WIN) -typedef int BOOL; -#endif // WZ_OS_WIN - -#endif // __INCLUDED_LIB_FRAMEWORK_TYPES_H__ diff --git a/lib/clipboard/include/clipboard/utf.h b/lib/clipboard/include/clipboard/utf.h deleted file mode 100644 index eadc3b3f..00000000 --- a/lib/clipboard/include/clipboard/utf.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 2007 Giel van Schijndel - Copyright (C) 2007-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - $Revision: 9336 $ - $Id: utf.h 9336 2010-01-18 19:10:17Z cypr $ - $HeadURL: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk/lib/framework/utf.h $ -*/ - -#ifndef __INCLUDE_LIB_FRAMEWORK_UTF8_H__ -#define __INCLUDE_LIB_FRAMEWORK_UTF8_H__ - -/* Allow frame header files to be singly included */ -#define FRAME_LIB_INCLUDE - -#include "types.h" - -#ifdef __cplusplus -extern "C" -{ -#endif //__cplusplus - -/** Used to store a UTF-32 character in - */ -typedef uint32_t utf_32_char; - -/** Used to store a UTF-16 character in (this is not necessarily a - * full Unicode codepoint) - */ -typedef uint16_t utf_16_char; - -/** Decodes a single Unicode character from the given UTF-16 string. - * - * \param utf16_char Points to a character string that should contain at - * least one valid UTF-16 character sequence. - * \param[out] next_char Will be modified to point to the first character - * following the UTF-16 character sequence. - * - * \return The Unicode character encoded as UTF-32 with native endianness. - */ -utf_32_char UTF16DecodeChar(const utf_16_char *utf16_char, const utf_16_char **next_char); - -/** Decodes a single Unicode character from the given UTF-8 string. - * - * \param utf8_char Points to a character string that should contain at - * least one valid UTF-8 character sequence. - * \param[out] next_char Will be modified to point to the first character - * following the UTF-8 character sequence. - * - * \return The Unicode character encoded as UTF-32 with native endianness. - */ -utf_32_char UTF8DecodeChar(const char *utf8_char, const char **next_char); - -/** Determines the amount of unicode codepoints in a UTF-8 encoded string - * \param utf8_string the UTF-8 encoded string to count - * \return the amount of codepoints found in the UTF-8 string - */ -size_t UTF8CharacterCount(const char *utf8_string); - -size_t UTF16CharacterCount(const uint16_t *utf16); - -/** Encodes a UTF-16 encoded unicode string to a UTF-8 encoded string - * \param unicode_string the UTF-16 encoded unicode string to encode into UTF-8 - * \param[out] nbytes the number of bytes allocated, may be NULL - * \return a UTF-8 encoded unicode nul terminated string (use free() to deallocate it) - */ -char *UTF16toUTF8(const utf_16_char *unicode_string, size_t *nbytes); - -/** Decodes a UTF-8 encoded string to a UTF-16 encoded string (native endianess) - * \param utf8_string a UTF-8 encoded nul terminated string - * \param[out] nbytes the number of bytes allocated, may be NULL - * \return a UTF-16 encoded unicode nul terminated string (use free() to deallocate it) - */ -utf_16_char *UTF8toUTF16(const char *utf8_string, size_t *nbytes); - -char *UTF8CharacterAtOffset(const char *utf8_string, size_t index); -utf_16_char *UTF16CharacterAtOffset(const utf_16_char *utf16_string, size_t index); - -/** Encodes a UTF-32 string to a UTF-8 encoded string - * \param unicode_string the UTF-32 string to encode into UTF-8 - * \param[out] nbytes the number of bytes allocated, may be NULL - * \return a UTF-8 encoded unicode nul terminated string (use free() to deallocate it) - */ -char *UTF32toUTF8(const utf_32_char *unicode_string, size_t *nbytes); - -/** Decodes a UTF-8 encoded string to a UTF-32 string - * \param utf8_string a UTF-8 encoded nul terminated string - * \param[out] nbytes the number of bytes allocated, may be NULL - * \return a UTF-32 nul terminated string (use free() to deallocate it) - */ -utf_32_char *UTF8toUTF32(const char *utf8_string, size_t *nbytes); - -/** Returns number of characters, not including terminating nul. */ -size_t utf32len(const utf_32_char *unicode_string); - -#ifdef __cplusplus -} -#endif //__cplusplus - -#endif // __INCLUDE_LIB_FRAMEWORK_UTF8_H__ diff --git a/lib/clipboard/include/clipboard/wzglobal.h b/lib/clipboard/include/clipboard/wzglobal.h deleted file mode 100644 index 113223e8..00000000 --- a/lib/clipboard/include/clipboard/wzglobal.h +++ /dev/null @@ -1,614 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 1992-2007 Trolltech ASA. - Copyright (C) 2005-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -/*! \file wzglobal.h - * \brief Platform detection, workarounds and compat fixes - * - * OS and CC detection code shamelessly stolen from Qt4 (Qt/qglobal.h) by Dennis. - * This has been stripped down, feel free to add checks as you need them. - */ - -#ifndef WZGLOBAL_H -#define WZGLOBAL_H - -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS -#endif - -#if defined(HAVE_CONFIG_H) -# undef _XOPEN_SOURCE -# include "config.h" -#elif defined(__MACOSX__) -# include "config-macosx.h" -#endif - - -/* ---- Platform detection ---- */ - - -/* - The operating system, must be one of: (WZ_OS_x) - - DARWIN - Darwin OS (synonym for WZ_OS_MAC) - OS2 - OS/2 - OS2EMX - XFree86 on OS/2 (not PM) - WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP) - CYGWIN - Cygwin - SOLARIS - Sun Solaris - HPUX - HP-UX - ULTRIX - DEC Ultrix - LINUX - Linux - FREEBSD - FreeBSD - GNU_kFREEBSD - GNU/kFreeBSD - NETBSD - NetBSD - OPENBSD - OpenBSD - BSDI - BSD/OS - IRIX - SGI Irix - OSF - HP Tru64 UNIX - SCO - SCO OpenServer 5 - UNIXWARE - UnixWare 7, Open UNIX 8 - AIX - AIX - HURD - GNU Hurd - DGUX - DG/UX - RELIANT - Reliant UNIX - DYNIX - DYNIX/ptx - QNX - QNX - QNX6 - QNX RTP 6.1 - LYNX - LynxOS - BSD4 - Any BSD 4.4 system - UNIX - Any UNIX BSD/SYSV system -*/ - -#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__)) -# define WZ_OS_DARWIN -# define WZ_OS_BSD4 -# ifdef __LP64__ -# define WZ_OS_DARWIN64 -# else -# define WZ_OS_DARWIN32 -# endif -#elif defined(__CYGWIN__) -# define WZ_OS_CYGWIN -#elif defined(__OS2__) -# if defined(__EMX__) -# define WZ_OS_OS2EMX -# else -# define WZ_OS_OS2 -# endif -#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) -# define WZ_OS_WIN32 -# define WZ_OS_WIN64 -#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) -# define WZ_OS_WIN32 -#elif defined(__MWERKS__) && defined(__INTEL__) -# define WZ_OS_WIN32 -#elif defined(__sun) || defined(sun) -# define WZ_OS_SOLARIS -#elif defined(hpux) || defined(__hpux) -# define WZ_OS_HPUX -#elif defined(__ultrix) || defined(ultrix) -# define WZ_OS_ULTRIX -#elif defined(sinix) -# define WZ_OS_RELIANT -#elif defined(__linux__) || defined(__linux) -# define WZ_OS_LINUX -#elif defined(__FreeBSD__) || defined(__DragonFly__) -# define WZ_OS_FREEBSD -# define WZ_OS_BSD4 -#elif defined(__FreeBSD_kernel__) && !defined(__FreeBSD__) - /* We're running a non-FreeBSD system with a FreeBSD kernel. Find out what C - * library we're using to detect the system we're running on. */ -# include -# if defined(__GLIBC__) - /* We're running GNU/kFreeBSD */ -# define WZ_OS_GNU_kFREEBSD -# endif -#elif defined(__NetBSD__) -# define WZ_OS_NETBSD -# define WZ_OS_BSD4 -#elif defined(__OpenBSD__) -# define WZ_OS_OPENBSD -# define WZ_OS_BSD4 -#elif defined(__bsdi__) -# define WZ_OS_BSDI -# define WZ_OS_BSD4 -#elif defined(__sgi) -# define WZ_OS_IRIX -#elif defined(__osf__) -# define WZ_OS_OSF -#elif defined(_AIX) -# define WZ_OS_AIX -#elif defined(__Lynx__) -# define WZ_OS_LYNX -#elif defined(__GNU__) -# define WZ_OS_HURD -#elif defined(__DGUX__) -# define WZ_OS_DGUX -#elif defined(__QNXNTO__) -# define WZ_OS_QNX6 -#elif defined(__QNX__) -# define WZ_OS_QNX -#elif defined(_SEQUENT_) -# define WZ_OS_DYNIX -#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */ -# define WZ_OS_SCO -#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */ -# define WZ_OS_UNIXWARE -#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */ -# define WZ_OS_UNIXWARE -#elif defined(__INTEGRITY) -# define WZ_OS_INTEGRITY -#elif defined(__MAKEDEPEND__) -#else -# error "Warzone has not been tested on this OS. Please contact warzone-dev@gna.org" -#endif /* WZ_OS_x */ - -#if defined(WZ_OS_WIN32) || defined(WZ_OS_WIN64) -# define WZ_OS_WIN -#endif /* WZ_OS_WIN32 */ - -#if defined(WZ_OS_DARWIN) -# define WZ_OS_MAC /* WZ_OS_MAC is mostly for compatibility, but also more clear */ -# define WZ_OS_MACX /* WZ_OS_MACX is only for compatibility.*/ -# if defined(WZ_OS_DARWIN64) -# define WZ_OS_MAC64 -# elif defined(WZ_OS_DARWIN32) -# define WZ_OS_MAC32 -# endif -#endif /* WZ_OS_DARWIN */ - -#if defined(WZ_OS_MSDOS) || defined(WZ_OS_OS2) || defined(WZ_OS_WIN) -# undef WZ_OS_UNIX -#elif !defined(WZ_OS_UNIX) -# define WZ_OS_UNIX -#endif /* WZ_OS_* */ - - -/* - The compiler, must be one of: (WZ_CC_x) - - MSVC - Microsoft Visual C/C++, Intel C++ for Windows - GNU - GNU C++ - CLANG - Clang LLVM - INTEL - Intel C++ for Linux, Intel C++ for Windows - TINYC - Fabrice Bellard's Tiny C Compiler - - Should be sorted most to least authoritative. -*/ - -#if defined(_MSC_VER) -# define WZ_CC_MSVC -/* All ISO C89 compliant compilers _should_ define the macro __STDC__, MSVC - * however is known _not_ to do this, so work around that here. */ -# if !defined(__STDC__) -# define __STDC__ 1 -# endif -/* Visual C++.Net issues for _MSC_VER >= 1300 */ -# if _MSC_VER >= 1300 -# define WZ_CC_MSVC_NET -# endif -/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */ -# if defined(__INTEL_COMPILER) -# define WZ_CC_INTEL -# endif -/* x64 does not support mmx intrinsics on windows */ -# if (defined(ZS_OS_WIN64) && defined(_M_X64)) -# undef ZS_HAVE_SSE -# undef ZS_HAVE_SSE2 -# undef ZS_HAVE_MMX -# undef ZS_HAVE_3DNOW -# endif - -#elif defined(__GNUC__) -# define WZ_CC_GNU -# if defined(__MINGW32__) -# define WZ_CC_MINGW -# endif -# if defined(__INTEL_COMPILER) -/* Intel C++ also masquerades as GCC 3.2.0 */ -# define WZ_CC_INTEL -# endif - -# if defined(__llvm__) -# define WZ_CC_LLVM -# endif -# if defined(__clang__) -# define WZ_CC_CLANG -# endif -/* Clang may not always masquerade as gcc */ -#elif defined(__clang__) -# define WZ_CC_CLANG -# define WZ_CC_LLVM - -#elif defined(__TINYC__) -# define WZ_CC_TINYC - -#else -# error "Warzone has not been tested on this compiler. Please contact warzone-dev@gna.org" -#endif /* WZ_CC_x */ - - -/* - The window system, must be one of: (WZ_WS_x) - - MACX - Mac OS X - WIN32 - Windows - X11 - X Window System - QNX - QNX -*/ - -#if defined(_WIN32_X11_) -# define WZ_WS_X11 - -#elif defined(WZ_OS_WIN32) -# define WZ_WS_WIN32 -# if defined(WZ_OS_WIN64) -# define WZ_WS_WIN64 -# endif - -#elif defined(WZ_OS_MAC) -# define WZ_WS_MAC -# define WZ_WS_MACX -# if defined(WZ_OS_MAC64) -# define WZ_WS_MAC64 -# elif defined(WZ_OS_MAC32) -# define WZ_WS_MAC32 -# endif - -#elif defined(WZ_OS_QNX) -# define WZ_WS_QNX - -#elif defined(WZ_OS_UNIX) -# define WZ_WS_X11 - -#else -# error "Warzone has not been tested on this window system. Please contact warzone-dev@gna.org" -#endif /* WZ_WS_x */ - -#if defined(WZ_WS_WIN16) || defined(WZ_WS_WIN32) -# define WZ_WS_WIN -#endif - - -/* - The supported C standard, must be one of: (WZ_Cxx) - - 99 - ISO/IEC 9899:1999 / C99 -*/ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -# define WZ_C99 -#endif /* WZ_Cxx */ - -/* - The supported C++ standard, must be one of: (WZ_CXXxx) - - 98 - ISO/IEC 14882:1998 / C++98 -*/ -#if defined(__cplusplus) -# define WZ_CXX98 -#endif /* WZ_CXXxx */ - - -/* - Convenience macros to test the versions of gcc. - Copied from glibc's features.h. -*/ -#if defined(WZ_CC_GNU) && defined __GNUC__ && defined __GNUC_MINOR__ -# define WZ_CC_GNU_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else -# define WZ_CC_GNU_PREREQ(maj, min) 0 -#endif - - -/* - Convenience macros to test the versions of icc. -*/ -#if defined(WZ_CC_INTEL) && defined __ICC -# define WZ_CC_INTEL_PREREQ(maj, min) \ - ((__ICC) >= ((maj) * 100) + (min)) -#else -# define WZ_CC_INTEL_PREREQ(maj, min) 0 -#endif - - - - -/* ---- Declaration attributes ---- */ - - -/*! - * \def WZ_DECL_DEPRECATED - * - * The WZ_DECL_DEPRECATED macro can be used to trigger compile-time warnings - * with newer compilers when deprecated functions are used. - * - * For non-inline functions, the macro gets inserted at front of the - * function declaration, right before the return type: - * - * \code - * WZ_DECL_DEPRECATED void deprecatedFunctionA(); - * WZ_DECL_DEPRECATED int deprecatedFunctionB() const; - * \endcode - * - * For functions which are implemented inline, - * the WZ_DECL_DEPRECATED macro is inserted at the front, right before the return - * type, but after "static", "inline" or "virtual": - * - * \code - * WZ_DECL_DEPRECATED void deprecatedInlineFunctionA() { .. } - * virtual WZ_DECL_DEPRECATED int deprecatedInlineFunctionB() { .. } - * static WZ_DECL_DEPRECATED bool deprecatedInlineFunctionC() { .. } - * inline WZ_DECL_DEPRECATED bool deprecatedInlineFunctionD() { .. } - * \endcode - * - * You can also mark whole structs or classes as deprecated, by inserting the - * WZ_DECL_DEPRECATED macro after the struct/class keyword, but before the - * name of the struct/class: - * - * \code - * class WZ_DECL_DEPRECATED DeprecatedClass { }; - * struct WZ_DECL_DEPRECATED DeprecatedStruct { }; - * \endcode - * - * \note - * Description copied from KDE4, code copied from Qt4. - * - */ -#if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0) -# define WZ_DECL_DEPRECATED __attribute__((__deprecated__)) -#elif defined(WZ_CC_MSVC) && defined(WZ_CC_MSVC_NET) -# define WZ_DECL_DEPRECATED __declspec(deprecated) -#else -# define WZ_DECL_DEPRECATED -#endif - - -/*! \def WZ_DECL_FORMAT - * GCC: "The format attribute specifies that a function takes printf, scanf, strftime or strfmon - * style arguments which should be type-checked against a format string." - */ -#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL) -# define WZ_DECL_FORMAT(archetype, string_index, first_to_check) \ - __attribute__((__format__(archetype, string_index, first_to_check))) -#else -# define WZ_DECL_FORMAT(archetype, string_index, first_to_check) -#endif - - -/*! - * \def WZ_DECL_NORETURN - * "A few standard library functions, such as abort and exit, cannot return. GCC knows this - * automatically. Some programs define their own functions that never return. - * You can declare them noreturn to tell the compiler this fact." - */ -#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL) -# define WZ_DECL_NORETURN __attribute__((__noreturn__)) -#elif defined(WZ_CC_MSVC) -# define WZ_DECL_NORETURN __declspec(noreturn) -#else -# define WZ_DECL_NORETURN -#endif - - -/*! - * \def WZ_DECL_CONST - * GCC: "Many functions do not examine any values except their arguments, and have no effects - * except the return value. Basically this is just slightly more strict class than - * the pure attribute below, since function is not allowed to read global memory." - */ -#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL) -# define WZ_DECL_CONST __attribute__((__const__,__warn_unused_result__)) -#else -# define WZ_DECL_CONST -#endif - - -/*! - * \def WZ_DECL_PURE - * GCC: "Many functions have no effects except the return value and their return value depends - * only on the parameters and/or global variables. Such a function can be subject to - * common subexpression elimination and loop optimization just as an arithmetic operator - * would be." - */ -#if WZ_CC_GNU_PREREQ(2,96) && !defined(WZ_CC_INTEL) -# define WZ_DECL_PURE __attribute__((__pure__)) -#else -# define WZ_DECL_PURE -#endif - - -/*! - * \def WZ_DECL_UNUSED - * GCC: "This attribute, attached to a function, means that the function is meant to be possibly - * unused. GCC will not produce a warning for this function." - */ -#if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0) -# define WZ_DECL_UNUSED __attribute__((__unused__)) -#else -# define WZ_DECL_UNUSED -#endif - - -/*! - * \def WZ_DECL_WARN_UNUSED_RESULT - * GCC: "The warn_unused_result attribute causes a warning to be emitted if a caller of the - * function with this attribute does not use its return value. This is useful for - * functions where not checking the result is either a security problem or always a bug, - * such as realloc." - */ -#if defined(WZ_CC_GNU) && !defined(WZ_CC_INTEL) -# define WZ_DECL_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) -#else -# define WZ_DECL_WARN_UNUSED_RESULT -#endif - - -/*! \def WZ_DECL_MAY_ALIAS - * GCC: "Accesses to objects with types with this attribute are not subjected to type-based alias - * analysis, but are instead assumed to be able to alias any other type of objects, - * just like the char type. See -fstrict-aliasing for more information on aliasing issues." - */ -#if WZ_CC_GNU_PREREQ(3,3) && !defined(WZ_CC_INTEL) -# define WZ_DECL_MAY_ALIAS __attribute__((__may_alias__)) -#else -# define WZ_DECL_MAY_ALIAS -#endif - - -/*! - * \def WZ_DECL_RESTRICT - * Apply the "restrict" keyword found in the C99 revision of the standard. - * The compiler may assume that the memory referenced by a "restrict" pointer is not aliased - * by any other pointer. Thus this forms the opposite of WZ_DECL_MAY_ALIAS. - */ -#if defined(WZ_C99) && WZ_CC_GNU_PREREQ(4,1) && !defined(WZ_CC_INTEL) -# define WZ_DECL_RESTRICT restrict -#elif defined(WZ_CC_MSVC) && defined(WZ_CC_MSVC_NET) -# define WZ_DECL_RESTRICT __restrict -#else -# define WZ_DECL_RESTRICT -#endif - - -/*! \def WZ_DECL_THREAD - * Declares a variable to be local to the running thread, and not shared between threads. - */ -#if defined(WZ_CC_GNU) || defined(WZ_CC_INTEL) -# define WZ_DECL_THREAD __thread -#elif defined(WZ_CC_MSVC) -# define WZ_DECL_THREAD __declspec(thread) -#else -# error "Thread local storage attribute required" -#endif - - -/*! \def WZ_ASSERT_STATIC_STRING - * Asserts that the given string is statically allocated. - */ -#if defined(__cplusplus) -# include -# define WZ_ASSERT_STATIC_STRING(_var) assert(typeid(_var) == typeid(char[sizeof(_var)])) -#elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL) -# define WZ_ASSERT_STATIC_STRING(_var) STATIC_ASSERT(__builtin_types_compatible_p(typeof(_var), char[])) -#else -# define WZ_ASSERT_STATIC_STRING(_var) (void)(_var) -#endif - -/*! \def WZ_ASSERT_ARRAY - * Asserts that the given variable is a (statically sized) array, not just a pointer. - */ -#if defined(__cplusplus) -# define WZ_ASSERT_ARRAY_EXPR(a) 0 -#elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL) -/* &a[0] degrades to a pointer: a different type from an array */ -# define WZ_ASSERT_ARRAY_EXPR(a) STATIC_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(a), typeof(&(a)[0]))) -#else -# define WZ_ASSERT_ARRAY_EXPR(a) 0 -#endif -#define WZ_ASSERT_ARRAY(a) (void)WZ_ASSERT_ARRAY_EXPR(a) - - -/* ---- Platform specific setup ---- */ - - -#if defined(WZ_OS_WIN) -# if defined(WZ_CC_MINGW) -# include -# include -# include -# define _WIN32_IE IE5 -// Required for alloca -# include - -# elif defined(WZ_CC_MSVC) -# if defined(_DEBUG) -# define DEBUG -# define _CRTDBG_MAP_ALLOC -# include -# include -# endif /* _DEBUG */ -# endif /* WZ_CC_* */ - -# define WIN32_LEAN_AND_MEAN -# define WIN32_EXTRA_LEAN -# undef NOMINMAX -# define NOMINMAX 1 // disable the min / max macros -# include - -# if defined(WZ_CC_MSVC) -// notify people we are disabling these warning messages. -# pragma message (" *** Warnings 4018,4100,4127,4204,4244,4267,4389 have been squelched. ***") -# pragma warning (disable : 4018) // Shut up: '>' : signed/unsigned mismatch -# pragma warning (disable : 4100) // Shut up: unreferenced formal parameter (FIXME) -# pragma warning (disable : 4127) // Shut up: conditional expression is constant (eg. "while(0)") -# pragma warning (disable : 4204) // Shut up: non-constant aggregate initializer -# pragma warning (disable : 4244) // Shut up: conversion from 'float' to 'int', possible loss of data -# pragma warning (disable : 4267) // Shut up: conversion from 'size_t' to 'type', possible loss of data -# pragma warning (disable : 4389) // Shut up: '==' : signed/unsigned mismatch - -# define strcasecmp _stricmp -# define strncasecmp _strnicmp -# define inline __inline -# define alloca _alloca -# define fileno _fileno - -# define isnan _isnan -# define isfinite _finite - -# define PATH_MAX MAX_PATH -# endif /* WZ_CC_MSVC */ - -/* Make sure that PATH_MAX is large enough to use as the size for return - * buffers for Windows API calls - */ -# if (PATH_MAX < MAX_PATH) -# undef PATH_MAX -# define PATH_MAX MAX_PATH -# endif - -#elif defined(WZ_OS_UNIX) -# include -# if defined(HAVE_ALLOCA_H) -# include -# endif -#endif /* WZ_OS_* */ - -// Define PATH_MAX for systems that don't have it, like Hurd -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - - -#if !defined(WZ_C99) && !defined(va_copy) -/** - * Implements the interface of the C99 macro va_copy such that we can use it on - * non-C99 systems as well. - * - * This implementation assumes that va_list is just a pointer to the stack - * frame of the variadic function. This is by far the most common setup, though - * it might not always work. - */ -# define va_copy(dest, src) (void)((dest) = (src)) -#endif // !WZ_C99 && !va_copy - -#endif /* WZGLOBAL_H */ diff --git a/lib/clipboard/readme.txt b/lib/clipboard/readme.txt deleted file mode 100644 index 196c127e..00000000 --- a/lib/clipboard/readme.txt +++ /dev/null @@ -1 +0,0 @@ -Source code in this directory was taken from Warzone2100 source. Please read COPING.README for licence or visit https://github.com/cybersphinx/wzgraphicsmods for more information. diff --git a/lib/clipboard/src/clipboardOSX.m b/lib/clipboard/src/clipboardOSX.m deleted file mode 100644 index 893dba89..00000000 --- a/lib/clipboard/src/clipboardOSX.m +++ /dev/null @@ -1,24 +0,0 @@ - -#include -#include - -#include - -char *widgetGetClipboardText() -{ - NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; - NSString *myString = [pasteboard stringForType:NSPasteboardTypeString]; - - if (myString == nil || [myString length] == 0) return NULL; - - return strdup([myString UTF8String]); -} - -bool widgetSetClipboardText(const char *text) -{ - NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; - [pasteboard clearContents]; - - NSString *stringFromUTFString = [[NSString alloc] initWithUTF8String:text]; - return [pasteboard setString:stringFromUTFString forType:NSStringPboardType]; -} diff --git a/lib/clipboard/src/clipboardWin32.c b/lib/clipboard/src/clipboardWin32.c deleted file mode 100644 index be48906f..00000000 --- a/lib/clipboard/src/clipboardWin32.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 2008 Freddie Witherden - Copyright (C) 2008-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#define WIN32_LEAN_AND_MEAN -#include - -#include "utf.h" -// Defines most macros and types from and -#include "types.h" - -char *widgetGetClipboardText() -{ - uint16_t *clipboardText; - char *ourText = NULL; - - // If there is any text on the clipboard, open it - if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) - { - // Get any text on the clipboard - HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT); - - // If the handle is valid, fetch the text - if (hClipboardData) - { - // Get the text - clipboardText = GlobalLock(hClipboardData); - - // So long as we got something - if (clipboardText) - { - int i, j; - - // Convert it to UTF-8 (from UTF-16) - ourText = UTF16toUTF8(clipboardText, NULL); - - // Unlock the text - GlobalUnlock(hClipboardData); - - // Strip any '\r' from the text - for (i = j = 0; ourText[i]; i++) - { - if (ourText[i] != '\r') - { - ourText[j++] = ourText[i]; - } - } - - // NUL terminate - ourText[j] = '\0'; - } - } - - // Close the clipboard - CloseClipboard(); - } - - return ourText; -} - -bool widgetSetClipboardText(const char *text) -{ - bool ret = false; - - // Copy of text with \n => \r\n - char *newText; - - // UTF-16 version of newText - uint16_t *utf16NewText; - - // Number of bytes utf16NewText is in size - size_t nbytes; - - int count, i, j; - - // Get the number of '\n' characters in the text - for (i = count = 0; text[i]; i++) - { - if (text[i] == '\n') - { - count++; - } - } - - // Allocate enough space for the \r\n string - newText = malloc(strlen(text) + count + 1); - - // Copy the string, converting \n to \r\n - for (i = j = 0; text[i]; i++, j++) - { - // If the character is a newline prepend a \r - if (text[i] == '\n') - { - newText[j++] = '\r'; - } - - // Copy the character (\n or otherwise) - newText[j] = text[i]; - } - - // NUL terminate - newText[j] = '\0'; - - // Convert to UTF-16 - utf16NewText = UTF8toUTF16(newText, &nbytes); - - // Open the clipboard - if (OpenClipboard(NULL)) - { - HGLOBAL hGlobal; - uint16_t *clipboardText; - - // Empty it (which also transfers ownership of it to ourself) - EmptyClipboard(); - - // Allocate global space for the text - hGlobal = GlobalAlloc(GMEM_MOVEABLE, nbytes); - - // Lock the newly allocated memory - clipboardText = GlobalLock(hGlobal); - - // Copy the text - memcpy(clipboardText, utf16NewText, nbytes); - - // Unlock the memory (must come before CloseClipboard()) - GlobalUnlock(hGlobal); - - // Place the handle on the clipboard - if (SetClipboardData(CF_UNICODETEXT, hGlobal)) - { - // We were successful - ret = true; - } - - // Close the clipboard - CloseClipboard(); - } - - // Release the malloc-ed strings - free(newText); - free(utf16NewText); - - return ret; -} diff --git a/lib/clipboard/src/clipboardX11.c b/lib/clipboard/src/clipboardX11.c deleted file mode 100644 index 0653250b..00000000 --- a/lib/clipboard/src/clipboardX11.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 2008 Freddie Witherden - Copyright (C) 2008-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/* - * Something wicked this way comes... - * Documentation/reference: - * http://svr-www.eng.cam.ac.uk/~er258/code/dist/x_clipboard/paste.cc - */ - -#include -#include - -#include -#include - -static SDL_SysWMinfo info; - -// Atoms -static Atom XA_CLIPBOARD; -static Atom XA_COMPOUND_TEXT; -static Atom XA_UTF8_STRING; -static Atom XA_TARGETS; - -/** - * Filters through SDL_Events searching for clipboard requests from the X - * server. - * - * @param evt The event to filter. - */ -static int widgetClipboardFilterX11(const SDL_Event *evt) -{ - // We are only interested in window manager events - if (evt->type == SDL_SYSWMEVENT) - { - XEvent xevent = evt->syswm.msg->event.xevent; - - // See if the event is a selection/clipboard request - if (xevent.type == SelectionRequest) - { - // Get the request in question - XSelectionRequestEvent *request = &xevent.xselectionrequest; - - // Generate a reply to the selection request - XSelectionEvent reply; - - reply.type = SelectionNotify; - reply.serial = xevent.xany.send_event; - reply.send_event = True; - reply.display = info.info.x11.display; - reply.requestor = request->requestor; - reply.selection = request->selection; - reply.property = request->property; - reply.target = None; - reply.time = request->time; - - // They want to know what we can provide/offer - if (request->target == XA_TARGETS) - { - Atom possibleTargets[] = - { - XA_STRING, - XA_UTF8_STRING, - XA_COMPOUND_TEXT - }; - - XChangeProperty(info.info.x11.display, request->requestor, - request->property, XA_ATOM, 32, PropModeReplace, - (unsigned char *) possibleTargets, 3); - } - // They want a string (all we can provide) - else if (request->target == XA_STRING - || request->target == XA_UTF8_STRING - || request->target == XA_COMPOUND_TEXT) - { - int len; - char *xdata = XFetchBytes(info.info.x11.display, &len); - - XChangeProperty(info.info.x11.display, request->requestor, - request->property, request->target, 8, - PropModeReplace, (unsigned char *) xdata, - len); - XFree(xdata); - } - else - { - // Did not have what they wanted, so no property set - reply.property = None; - } - - // Dispatch the event - XSendEvent(request->display, request->requestor, 0, NoEventMask, - (XEvent *) &reply); - XSync(info.info.x11.display, False); - } - } - - return 1; -} - -static void widgetInitialiseClipboardX11() -{ - static bool initialised = false; - - if (!initialised) - { - // Get the window manager information - SDL_GetWMInfo(&info); - - // Ensure we're running under X11 - assert(info.subsystem == SDL_SYSWM_X11); - - // Register the event filter - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(widgetClipboardFilterX11); - - // Lock the connection to the X server - info.info.x11.lock_func(); - - // Get the clipboard atom (it is not defined by default) - XA_CLIPBOARD = XInternAtom(info.info.x11.display, "CLIPBOARD", True); - - // Get the compound text type atom - XA_COMPOUND_TEXT = XInternAtom(info.info.x11.display, "COMPOUND_TEXT", - True); - - // UTF-8 string atom - XA_UTF8_STRING = XInternAtom(info.info.x11.display, "UTF8_STRING", - True); - - // TARGETS atom - XA_TARGETS = XInternAtom(info.info.x11.display, "TARGETS", True); - - // Unlock the connection - info.info.x11.unlock_func(); - - // We are initialised - initialised = true; - } -} - -char *widgetGetClipboardText() -{ - char *text = NULL; - unsigned char *data = NULL; - Atom type; - int format, result; - unsigned long len, bytesLeft, dummy; - Window selectionOwner; - - // Make sure we are initialised - widgetInitialiseClipboardX11(); - - // Lock the connection - info.info.x11.lock_func(); - - // Get the owner of the clipboard selection - selectionOwner = XGetSelectionOwner(info.info.x11.display, XA_CLIPBOARD); - - // If there is a selection (and therefore owner) fetch it - if (selectionOwner != None) - { - SDL_Event event; - bool response = false; - - /* - * Ask the window whom current owns the clipboard to convert it to an - * XA_UTF8_STRING and place it into the XA_CLIPBOARD property of our - * window. - */ - XConvertSelection(info.info.x11.display, XA_CLIPBOARD, XA_UTF8_STRING, - XA_CLIPBOARD, info.info.x11.window, CurrentTime); - XFlush(info.info.x11.display); - - /* - * We now need to wait for a response from the window that owns the - * clipboard. - */ - - // Unlock the connection so that the SDL event loop may function - info.info.x11.unlock_func(); - - while (!response) - { - // Wait for an event - SDL_WaitEvent(&event); - - // If the event is a window manager event - if (event.type == SDL_SYSWMEVENT) - { - XEvent xevent = event.syswm.msg->event.xevent; - - // See if it is a response to our request - if (xevent.type == SelectionNotify - && xevent.xselection.requestor == info.info.x11.window) - { - response = true; - } - } - } - - // Lock the connection once again - info.info.x11.lock_func(); - - // See how much data is there - XGetWindowProperty(info.info.x11.display, info.info.x11.window, - XA_CLIPBOARD, 0, 0, False, AnyPropertyType, &type, - &format, &len, &bytesLeft, &data); - - // If any 0-length data was returned, free it - if (data) - { - XFree(data); - data = NULL; - } - - // If there is any data - if (bytesLeft) - { - // Fetch the data - result = XGetWindowProperty(info.info.x11.display, - info.info.x11.window, XA_CLIPBOARD, 0, - bytesLeft, False, AnyPropertyType, - &type, &format, &len, &dummy, &data); - - // If we got some data, duplicate it - if (result == Success) - { - text = strdup((char *) data); - XFree(data); - } - } - - // Delete the property now that we are finished with it - XDeleteProperty(info.info.x11.display, info.info.x11.window, - XA_CLIPBOARD); - } - - // Unlock the connection - info.info.x11.unlock_func(); - - return text; -} - -bool widgetSetClipboardText(const char *text) -{ - Window selectionOwner; - - // Make sure we are initialised - widgetInitialiseClipboardX11(); - - // Lock the connection - info.info.x11.lock_func(); - - // Copy the text into the root windows cut buffer (for Xterm compatibility) - XStoreBytes(info.info.x11.display, text, strlen(text) + 1); - - // Set ourself as the owner of the CLIPBOARD atom - XSetSelectionOwner(info.info.x11.display, XA_CLIPBOARD, - info.info.x11.window, CurrentTime); - - // Check if we acquired ownership or not - selectionOwner = XGetSelectionOwner(info.info.x11.display, XA_CLIPBOARD); - - // We got ownership - if (selectionOwner == info.info.x11.window) - { - info.info.x11.unlock_func(); - return true; - } - // We did not get ownership - else - { - info.info.x11.unlock_func(); - return false; - } -} diff --git a/lib/clipboard/src/utf.c b/lib/clipboard/src/utf.c deleted file mode 100644 index 2313bb61..00000000 --- a/lib/clipboard/src/utf.c +++ /dev/null @@ -1,530 +0,0 @@ -/* - This file is part of Warzone 2100. - Copyright (C) 2007 Giel van Schijndel - Copyright (C) 2007-2009 Warzone Resurrection Project - - Warzone 2100 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 2 of the License, or - (at your option) any later version. - - Warzone 2100 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 Warzone 2100; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - $Revision: 9101 $ - $Id: utf.c 9101 2010-01-10 13:11:55Z zarelsl $ - $HeadURL: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk/lib/framework/utf.c $ -*/ - -/** \file - * Functions to convert between different Unicode Transformation Formats (UTF for short) - */ - -#include "utf.h" -#include -#include - -#if defined(LIB_COMPILE) -# define ASSERT(expr, ...) (assert(expr)) -# define debug(part, ...) ((void)0) -#else -# include "debug.h" -#endif - -// Assert that non-starting octets are of the form 10xxxxxx -#define ASSERT_NON_START_OCTET(octet) \ - assert((octet & 0xC0) == 0x80 && "invalid non-start UTF-8 octet") - -// Assert that starting octets are either of the form 0xxxxxxx (ASCII) or 11xxxxxx -#define ASSERT_START_OCTECT(octet) \ - assert((octet & 0x80) == 0x00 || (octet & 0xC0) == 0xC0 || !"invalid starting UTF-8 octet") - -// Assert that hexadect (16bit sequence) 1 of UTF-16 surrogate pair sequences are of the form 110110XXXXXXXXXX -#define ASSERT_START_HEXADECT(hexadect) \ - assert(((hexadect) & 0xD800) == 0xD800 && "invalid first UTF-16 hexadect") - -// Assert that hexadect (16bit sequence) 2 of UTF-16 surrogate pair sequences are of the form 110111XXXXXXXXXX -#define ASSERT_FINAL_HEXADECT(hexadect) \ - assert(((hexadect) & 0xDC00) == 0xDC00 && "invalid first UTF-16 hexadect") - -utf_32_char UTF8DecodeChar(const char *utf8_char, const char **next_char) -{ - utf_32_char decoded = '\0'; - *next_char = utf8_char; - - ASSERT_START_OCTECT(*utf8_char); - - // first octect: 0xxxxxxx: 7 bit (ASCII) - if ((*utf8_char & 0x80) == 0x00) - { - // 1 byte long encoding - decoded = *((*next_char)++); - } - // first octect: 110xxxxx: 11 bit - else if ((*utf8_char & 0xe0) == 0xc0) - { - // 2 byte long encoding - ASSERT_NON_START_OCTET(utf8_char[1]); - - decoded = (*((*next_char)++) & 0x1f) << 6; - decoded |= (*((*next_char)++) & 0x3f) << 0; - } - // first octect: 1110xxxx: 16 bit - else if ((*utf8_char & 0xf0) == 0xe0) - { - // 3 byte long encoding - ASSERT_NON_START_OCTET(utf8_char[1]); - ASSERT_NON_START_OCTET(utf8_char[2]); - - decoded = (*((*next_char)++) & 0x0f) << 12; - decoded |= (*((*next_char)++) & 0x3f) << 6; - decoded |= (*((*next_char)++) & 0x3f) << 0; - } - // first octect: 11110xxx: 21 bit - else if ((*utf8_char & 0xf8) == 0xf0) - { - // 4 byte long encoding - ASSERT_NON_START_OCTET(utf8_char[1]); - ASSERT_NON_START_OCTET(utf8_char[2]); - ASSERT_NON_START_OCTET(utf8_char[3]); - - decoded = (*((*next_char)++) & 0x07) << 18; - decoded |= (*((*next_char)++) & 0x3f) << 12; - decoded |= (*((*next_char)++) & 0x3f) << 6; - decoded |= (*((*next_char)++) & 0x3f) << 0; - } - else - { - // apparently this character uses more than 21 bit - // this decoder is not developed to cope with those - // characters so error out - ASSERT(!"out-of-range UTF-8 character", "this UTF-8 character is too large (> 21bits) for this UTF-8 decoder and too large to be a valid Unicode codepoint"); - } - - return decoded; -} - -size_t UTF8CharacterCount(const char *utf8_string) -{ - size_t length = 0; - - while (*utf8_string != '\0') - { - UTF8DecodeChar(utf8_string, &utf8_string); - - ++length; - } - - return length; -} - -size_t UTF16CharacterCount(const uint16_t *utf16) -{ - size_t length = 0; - - while (*utf16) - { - UTF16DecodeChar(utf16, &utf16); - - ++length; - } - - return length; -} - -static size_t unicode_utf8_char_length(const utf_32_char unicode_char) -{ - // an ASCII character, which uses 7 bit at most, which is one byte in UTF-8 - if (unicode_char < 0x00000080) - return 1; // stores 7 bits - else if (unicode_char < 0x00000800) - return 2; // stores 11 bits - else if (unicode_char < 0x00010000) - return 3; // stores 16 bits - /* This encoder can deal with < 0x00200000, but Unicode only ranges - * from 0x0 to 0x10FFFF. Thus we don't accept anything else. - */ - else if (unicode_char < 0x00110000) - return 4; // stores 21 bits - - /* Apparently this character lies outside the 0x0 - 0x10FFFF - * Unicode range, so don't accept it. - */ - ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char); - - // Dummy value to prevent warnings about missing return from function - return 0; -} - -char *UTF8CharacterAtOffset(const char *utf8_string, size_t index) -{ - while (*utf8_string != '\0' - && index != 0) - { - // Move to the next character - UTF8DecodeChar(utf8_string, &utf8_string); - - --index; - } - - if (*utf8_string == '\0') - return NULL; - - return (char*)utf8_string; -} - -/** Encodes a single Unicode character to a UTF-8 encoded string. - * - * \param unicode_char A UTF-32 encoded Unicode codepoint that will be encoded - * into UTF-8. This should be a valid Unicode codepoint - * (i.e. ranging from 0x0 to 0x10FFFF inclusive). - * \param out_char Points to the position in a buffer where the UTF-8 - * encoded character can be stored. - * - * \return A pointer pointing to the first byte after the encoded - * UTF-8 sequence. This can be used as the \c out_char parameter for a - * next invocation of encode_utf8_char(). - */ -static char *encode_utf8_char(const utf_32_char unicode_char, char *out_char) -{ - char *next_char = out_char; - - // 7 bits - if (unicode_char < 0x00000080) - { - *(next_char++) = unicode_char; - } - // 11 bits - else if (unicode_char < 0x00000800) - { - // 0xc0 provides the counting bits: 110 - // then append the 5 most significant bits - *(next_char++) = 0xc0 | (unicode_char >> 6); - // Put the next 6 bits in a byte of their own - *(next_char++) = 0x80 | (unicode_char & 0x3f); - } - // 16 bits - else if (unicode_char < 0x00010000) - { - // 0xe0 provides the counting bits: 1110 - // then append the 4 most significant bits - *(next_char++) = 0xe0 | (unicode_char >> 12); - // Put the next 12 bits in two bytes of their own - *(next_char++) = 0x80 | ((unicode_char >> 6) & 0x3f); - *(next_char++) = 0x80 | (unicode_char & 0x3f); - } - // 21 bits - /* This encoder can deal with < 0x00200000, but Unicode only ranges - * from 0x0 to 0x10FFFF. Thus we don't accept anything else. - */ - else if (unicode_char < 0x00110000) - { - // 0xf0 provides the counting bits: 11110 - // then append the 3 most significant bits - *(next_char++) = 0xf0 | (unicode_char >> 18); - // Put the next 18 bits in three bytes of their own - *(next_char++) = 0x80 | ((unicode_char >> 12) & 0x3f); - *(next_char++) = 0x80 | ((unicode_char >> 6) & 0x3f); - *(next_char++) = 0x80 | (unicode_char & 0x3f); - } - else - { - /* Apparently this character lies outside the 0x0 - 0x10FFFF - * Unicode range, so don't accept it. - */ - ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char); - } - - return next_char; -} - -utf_32_char UTF16DecodeChar(const utf_16_char *utf16_char, const utf_16_char **next_char) -{ - utf_32_char decoded; - *next_char = utf16_char; - - // Are we dealing with a surrogate pair - if (*utf16_char >= 0xD800 - && *utf16_char <= 0xDFFF) - { - ASSERT_START_HEXADECT(utf16_char[0]); - ASSERT_FINAL_HEXADECT(utf16_char[1]); - - decoded = (*((*next_char)++) & 0x3ff) << 10; - decoded |= *((*next_char)++) & 0x3ff; - - decoded += 0x10000; - } - // Not a surrogate pair, so it's a valid Unicode codepoint right away - else - { - decoded = *((*next_char)++); - } - - return decoded; -} - -/** Encodes a single Unicode character to a UTF-16 encoded string. - * - * \param unicode_char A UTF-32 encoded Unicode codepoint that will be encoded - * into UTF-16. This should be a valid Unicode codepoint - * (i.e. ranging from 0x0 to 0x10FFFF inclusive). - * \param out_char Points to the position in a buffer where the UTF-16 - * encoded character can be stored. - * - * \return A pointer pointing to the first byte after the encoded - * UTF-16 sequence. This can be used as the \c out_char parameter for a - * next invocation of encode_utf16_char(). - */ -static utf_16_char *encode_utf16_char(const utf_32_char unicode_char, utf_16_char *out_char) -{ - utf_16_char *next_char = out_char; - - // 16 bits - if (unicode_char < 0x10000) - { - *(next_char++) = unicode_char; - } - else if (unicode_char < 0x110000) - { - const utf_16_char v = unicode_char - 0x10000; - - *(next_char++) = 0xD800 | (v >> 10); - *(next_char++) = 0xDC00 | (v & 0x3ff); - - ASSERT_START_HEXADECT(out_char[0]); - ASSERT_FINAL_HEXADECT(out_char[1]); - } - else - { - /* Apparently this character lies outside the 0x0 - 0x10FFFF - * Unicode range, and UTF-16 cannot cope with that, so error - * out. - */ - ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char); - } - - return next_char; -} - -static size_t utf16_utf8_buffer_length(const utf_16_char* unicode_string) -{ - const utf_16_char* curChar = unicode_string; - - // Determine length of string (in octets) when encoded in UTF-8 - size_t length = 0; - - while (*curChar) - { - length += unicode_utf8_char_length(UTF16DecodeChar(curChar, &curChar)); - } - - return length; -} - -char *UTF16toUTF8(const utf_16_char *unicode_string, size_t *nbytes) -{ - const utf_16_char* curChar; - - const size_t utf8_length = utf16_utf8_buffer_length(unicode_string); - - // Allocate memory to hold the UTF-8 encoded string (plus a terminating nul char) - char* utf8_string = malloc(utf8_length + 1); - char* curOutPos = utf8_string; - - if (utf8_string == NULL) - { - debug(LOG_ERROR, "Out of memory"); - return NULL; - } - - curChar = unicode_string; - while (*curChar) - { - curOutPos = encode_utf8_char(UTF16DecodeChar(curChar, &curChar), curOutPos); - } - - // Terminate the string with a nul character - utf8_string[utf8_length] = '\0'; - - // Set the number of bytes allocated - if (nbytes) - { - *nbytes = utf8_length + 1; - } - - return utf8_string; -} - -static size_t utf8_as_utf16_buf_size(const char* utf8_string) -{ - const char* curChar = utf8_string; - - size_t length = 0; - while (*curChar != '\0') - { - const utf_32_char unicode_char = UTF8DecodeChar(curChar, &curChar); - - if (unicode_char < 0x10000) - { - length += 1; - } - else if (unicode_char < 0x110000) - { - length += 2; - } - else - { - /* Apparently this character lies outside the 0x0 - 0x10FFFF - * Unicode range, and UTF-16 cannot cope with that, so error - * out. - */ - ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint too large (%u > 0x10FFFF) for the UTF-16 encoding", (unsigned int)unicode_char); - } - } - - return length; -} - -utf_16_char *UTF8toUTF16(const char* utf8_string, size_t *nbytes) -{ - const char* curChar = utf8_string; - const size_t unicode_length = utf8_as_utf16_buf_size(utf8_string); - - // Allocate memory to hold the UTF-16 encoded string (plus a terminating nul) - utf_16_char* unicode_string = malloc(sizeof(utf_16_char) * (unicode_length + 1)); - utf_16_char* curOutPos = unicode_string; - - if (unicode_string == NULL) - { - debug(LOG_ERROR, "Out of memory"); - return NULL; - } - - while (*curChar != '\0') - { - curOutPos = encode_utf16_char(UTF8DecodeChar(curChar, &curChar), curOutPos); - } - - // Terminate the string with a nul - unicode_string[unicode_length] = '\0'; - - // Set the number of bytes allocated - if (nbytes) - { - *nbytes = sizeof(utf_16_char) * (unicode_length + 1); - } - - return unicode_string; -} - -utf_16_char *UTF16CharacterAtOffset(const utf_16_char *utf16_string, size_t index) -{ - while (*utf16_string != '\0' - && index != 0) - { - // Move to the next character - UTF16DecodeChar(utf16_string, &utf16_string); - - --index; - } - - if (*utf16_string == '\0') - return NULL; - - return (utf_16_char*)utf16_string; -} - - -static size_t utf32_utf8_buffer_length(const utf_32_char* unicode_string) -{ - const utf_32_char* curChar; - - // Determine length of string (in octets) when encoded in UTF-8 - size_t length = 0; - for (curChar = unicode_string; *curChar != '\0'; ++curChar) - { - length += unicode_utf8_char_length(*curChar); - } - - return length; -} - -char *UTF32toUTF8(const utf_32_char *unicode_string, size_t *nbytes) -{ - const utf_32_char* curChar; - - const size_t utf8_length = utf32_utf8_buffer_length(unicode_string); - - // Allocate memory to hold the UTF-8 encoded string (plus a terminating nul char) - char* utf8_string = malloc(utf8_length + 1); - char* curOutPos = utf8_string; - - if (utf8_string == NULL) - { - debug(LOG_ERROR, "Out of memory"); - return NULL; - } - - for (curChar = unicode_string; *curChar != 0; ++curChar) - { - curOutPos = encode_utf8_char(*curChar, curOutPos); - } - - // Terminate the string with a nul character - utf8_string[utf8_length] = '\0'; - - // Set the number of bytes allocated - if (nbytes) - { - *nbytes = utf8_length + 1; - } - - return utf8_string; -} - -utf_32_char *UTF8toUTF32(const char *utf8_string, size_t *nbytes) -{ - const char* curChar = utf8_string; - const size_t unicode_length = UTF8CharacterCount(utf8_string); - - // Allocate memory to hold the UTF-32 encoded string (plus a terminating nul) - utf_32_char* unicode_string = malloc(sizeof(utf_32_char) * (unicode_length + 1)); - utf_32_char* curOutPos = unicode_string; - - if (unicode_string == NULL) - { - debug(LOG_ERROR, "Out of memory"); - return NULL; - } - - while (*curChar != '\0') - { - *(curOutPos++) = UTF8DecodeChar(curChar, &curChar); - } - - // Terminate the string with a nul - unicode_string[unicode_length] = '\0'; - - // Set the number of bytes allocated - if (nbytes) - { - *nbytes = sizeof(utf_32_char) * (unicode_length + 1); - } - - return unicode_string; -} - -size_t utf32len(const utf_32_char *unicode_string) -{ - size_t ret = 0; - while (*unicode_string++) - ++ret; - return ret; -} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ddb35a9..df49cd69 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,10 +41,10 @@ elseif(PLATFORM_WINDOWS) set(PLATFORM_LIBS "-lintl") endif() elseif(PLATFORM_GNU) - set(PLATFORM_LIBS "-lX11") + #set(PLATFORM_LIBS "-lX11") elseif(PLATFORM_LINUX) # for clock_gettime - set(PLATFORM_LIBS "-lrt -lX11") + set(PLATFORM_LIBS "-lrt") # -lX11") elseif(PLATFORM_MACOSX) find_library(LIBINTL_LIBRARY NAMES intl libintl) find_path(LIBINTL_INCLUDE_PATH NAMES libintl.h) @@ -271,11 +271,10 @@ set(MAIN_SOURCES # Libraries set(LIBS CBot - clipboard localename - ${SDL_LIBRARY} - ${SDLIMAGE_LIBRARY} - ${SDLTTF_LIBRARY} + ${SDL2_LIBRARY} + ${SDL2_IMAGE_LIBRARY} + ${SDL2_TTF_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARIES} ${GLEW_LIBRARY} @@ -297,15 +296,14 @@ set(LOCAL_INCLUDES ) set(SYSTEM_INCLUDES - ${SDL_INCLUDE_DIR} - ${SDLIMAGE_INCLUDE_DIR} - ${SDLTTF_INCLUDE_DIR} + ${SDL2_INCLUDE_DIR} + ${SDL2_IMAGE_INCLUDE_DIR} + ${SDL2_TTF_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} ${LIBSNDFILE_INCLUDE_DIR} ${LOCALENAME_INCLUDE_DIR} - ${CLIPBOARD_INCLUDE_DIR} ${PHYSFS_INCLUDE_PATH} ${LIBINTL_INCLUDE_PATH} ${OPTIONAL_INCLUDES} diff --git a/src/app/app.cpp b/src/app/app.cpp index a799105a..fb2e12a4 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -79,8 +79,10 @@ Uint32 JoystickTimerCallback(Uint32 interval, void *); */ struct ApplicationPrivate { - //! Display surface - SDL_Surface *surface; + //! Main game window + SDL_Window *window; + //! Main game OpenGL context + SDL_GLContext glcontext; //! Currently handled event SDL_Event currentEvent; //! Mouse motion event to be handled @@ -94,9 +96,9 @@ struct ApplicationPrivate { SDL_memset(¤tEvent, 0, sizeof(SDL_Event)); SDL_memset(&lastMouseMotionEvent, 0, sizeof(SDL_Event)); - surface = nullptr; + window = nullptr; joystick = nullptr; - joystickTimer = nullptr; + joystickTimer = 0; } }; @@ -203,10 +205,16 @@ CApplication::~CApplication() m_private->joystick = nullptr; } - if (m_private->surface != nullptr) + if (m_private->glcontext != nullptr) { - SDL_FreeSurface(m_private->surface); - m_private->surface = nullptr; + SDL_GL_DeleteContext(m_private->glcontext); + m_private->glcontext = nullptr; + } + + if (m_private->window != nullptr) + { + SDL_DestroyWindow(m_private->window); + m_private->window = nullptr; } IMG_Quit(); @@ -526,7 +534,7 @@ bool CApplication::Create() // GetVideoResolutionList() has to be called here because it is responsible // for list of resolutions in options menu, not calling it results in empty list std::vector modes; - GetVideoResolutionList(modes, true, true); + GetVideoResolutionList(modes); if ( GetConfigFile().GetStringProperty("Setup", "Resolution", sValue) && !m_resolutionOverride ) { @@ -560,7 +568,7 @@ bool CApplication::Create() if (! CreateVideoSurface()) return false; // dialog is in function - if (m_private->surface == nullptr) + if (m_private->window == nullptr) { m_errorMessage = std::string("SDL error while setting video mode:\n") + std::string(SDL_GetError()); @@ -568,13 +576,9 @@ bool CApplication::Create() m_exitCode = 4; return false; } - - SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str()); } - // Enable translating key codes of key press events to unicode chars - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //TODO: ? // Don't generate joystick events SDL_JoystickEventState(SDL_IGNORE); @@ -651,7 +655,7 @@ bool CApplication::Create() bool CApplication::CreateVideoSurface() { - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + /*const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); if (videoInfo == nullptr) { m_errorMessage = std::string("SDL error while getting video info:\n ") + @@ -659,23 +663,23 @@ bool CApplication::CreateVideoSurface() GetLogger()->Error(m_errorMessage.c_str()); m_exitCode = 7; return false; - } + }*/ - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; + Uint32 videoFlags = SDL_WINDOW_OPENGL; // | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE // Use hardware surface if available - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; + /*if (videoInfo->hw_available) + videoFlags |= SDL_HWSURFACE;*/ // Enable hardware blit if available - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; + /*if (videoInfo->blit_hw) + videoFlags |= SDL_HWACCEL;*/ if (m_deviceConfig.fullScreen) - videoFlags |= SDL_FULLSCREEN; + videoFlags |= SDL_WINDOW_FULLSCREEN; if (m_deviceConfig.resizeable) - videoFlags |= SDL_RESIZABLE; + videoFlags |= SDL_WINDOW_RESIZABLE; // Set OpenGL attributes @@ -694,8 +698,12 @@ bool CApplication::CreateVideoSurface() if (m_deviceConfig.hardwareAccel) SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); - m_private->surface = SDL_SetVideoMode(m_deviceConfig.size.x, m_deviceConfig.size.y, - m_deviceConfig.bpp, videoFlags); + m_private->window = SDL_CreateWindow(m_windowTitle.c_str(), + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + m_deviceConfig.size.x, m_deviceConfig.size.y, + videoFlags); + + m_private->glcontext = SDL_GL_CreateContext(m_private->window); return true; } @@ -707,8 +715,8 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) m_lastDeviceConfig = m_deviceConfig; m_deviceConfig = newConfig; - - SDL_FreeSurface(m_private->surface); + SDL_GL_DeleteContext(m_private->glcontext); //TODO: refactor this + SDL_DestroyWindow(m_private->window); // TODO: ? if (! CreateVideoSurface()) { @@ -717,7 +725,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) return false; } - if (m_private->surface == nullptr) + if (m_private->window == nullptr) { if (! restore) { @@ -899,14 +907,14 @@ int CApplication::Run() } // To be sure no old event remains - m_private->currentEvent.type = SDL_NOEVENT; + m_private->currentEvent.type = SDL_LASTEVENT; // Call SDL_PumpEvents() only once here // (SDL_PeepEvents() doesn't call it) if (m_active) SDL_PumpEvents(); - m_private->lastMouseMotionEvent.type = SDL_NOEVENT; + m_private->lastMouseMotionEvent.type = SDL_LASTEVENT; bool haveEvent = true; while (haveEvent) @@ -917,7 +925,7 @@ int CApplication::Run() // Use SDL_PeepEvents() if the app is active, so we can use idle time to // render the scene. Else, use SDL_WaitEvent() to avoid eating CPU time. if (m_active) - count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_ALLEVENTS); + count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); else count = SDL_WaitEvent(&m_private->currentEvent); @@ -949,7 +957,7 @@ int CApplication::Run() } // Now, process the last received mouse motion - if (m_private->lastMouseMotionEvent.type != SDL_NOEVENT) + if (m_private->lastMouseMotionEvent.type != SDL_LASTEVENT) { m_private->currentEvent = m_private->lastMouseMotionEvent; @@ -1048,13 +1056,32 @@ Event CApplication::ProcessSystemEvent() { event.type = EVENT_SYS_QUIT; } - else if (m_private->currentEvent.type == SDL_VIDEORESIZE) + else if (m_private->currentEvent.type == SDL_WINDOWEVENT) { - Gfx::DeviceConfig newConfig = m_deviceConfig; - newConfig.size.x = m_private->currentEvent.resize.w; - newConfig.size.y = m_private->currentEvent.resize.h; - if (newConfig.size != m_deviceConfig.size) - ChangeVideoConfig(newConfig); + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + Gfx::DeviceConfig newConfig = m_deviceConfig; + newConfig.size.x = m_private->currentEvent.window.data1; + newConfig.size.y = m_private->currentEvent.window.data2; + if (newConfig.size != m_deviceConfig.size) + ChangeVideoConfig(newConfig); + } + // TODO: EVENT_ACTIVE + /*{ + event.type = EVENT_ACTIVE; + + auto data = MakeUnique(); + + if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS) + data->flags |= ACTIVE_INPUT; + if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS) + data->flags |= ACTIVE_MOUSE; + if (m_private->currentEvent.active.type & SDL_APPACTIVE) + data->flags |= ACTIVE_APP; + + data->gain = m_private->currentEvent.active.gain == 1; + + event.data = std::move(data); + }*/ } else if ( (m_private->currentEvent.type == SDL_KEYDOWN) || (m_private->currentEvent.type == SDL_KEYUP) ) @@ -1068,7 +1095,7 @@ Event CApplication::ProcessSystemEvent() data->virt = false; data->key = m_private->currentEvent.key.keysym.sym; - data->unicode = m_private->currentEvent.key.keysym.unicode; + data->unicode = m_private->currentEvent.key.keysym.sym; // TODO: use SDL_TEXTINPUT for this, and remove this field event.kmodState = m_private->currentEvent.key.keysym.mod; // Some keyboards return numerical enter keycode instead of normal enter @@ -1079,47 +1106,38 @@ Event CApplication::ProcessSystemEvent() if (data->key == KEY(TAB) && ((event.kmodState & KEY_MOD(ALT)) != 0)) { GetLogger()->Debug("Minimize to taskbar\n"); - SDL_WM_IconifyWindow(); + SDL_MinimizeWindow(m_private->window); event.type = EVENT_NULL; } event.data = std::move(data); } + else if (m_private->currentEvent.type == SDL_MOUSEWHEEL) + { + event.type = EVENT_MOUSE_WHEEL; + + auto data = MakeUnique(); + + if (m_private->currentEvent.wheel.y < 0) // TODO: properly use this value + data->dir = WHEEL_DOWN; + else + data->dir = WHEEL_UP; + + event.data = std::move(data); + } else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) || (m_private->currentEvent.type == SDL_MOUSEBUTTONUP) ) { - if ((m_private->currentEvent.button.button == SDL_BUTTON_WHEELUP) || - (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN)) - { + auto data = MakeUnique(); - if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) // ignore the following up event - { - event.type = EVENT_MOUSE_WHEEL; - - auto data = MakeUnique(); - - if (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN) - data->dir = WHEEL_DOWN; - else - data->dir = WHEEL_UP; - - event.data = std::move(data); - } - - } + if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) + event.type = EVENT_MOUSE_BUTTON_DOWN; else - { - auto data = MakeUnique(); + event.type = EVENT_MOUSE_BUTTON_UP; - if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) - event.type = EVENT_MOUSE_BUTTON_DOWN; - else - event.type = EVENT_MOUSE_BUTTON_UP; + data->button = static_cast(1 << m_private->currentEvent.button.button); - data->button = static_cast(1 << m_private->currentEvent.button.button); - - event.data = std::move(data); - } + event.data = std::move(data); } else if (m_private->currentEvent.type == SDL_MOUSEMOTION) { @@ -1148,23 +1166,6 @@ Event CApplication::ProcessSystemEvent() data->button = m_private->currentEvent.jbutton.button; event.data = std::move(data); } - else if (m_private->currentEvent.type == SDL_ACTIVEEVENT) - { - event.type = EVENT_ACTIVE; - - auto data = MakeUnique(); - - if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS) - data->flags |= ACTIVE_INPUT; - if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS) - data->flags |= ACTIVE_MOUSE; - if (m_private->currentEvent.active.type & SDL_APPACTIVE) - data->flags |= ACTIVE_APP; - - data->gain = m_private->currentEvent.active.gain == 1; - - event.data = std::move(data); - } return event; } @@ -1307,7 +1308,7 @@ void CApplication::Render() StartPerformanceCounter(PCNT_SWAP_BUFFERS); if (m_deviceConfig.doubleBuf) - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(m_private->window); StopPerformanceCounter(PCNT_SWAP_BUFFERS); } @@ -1447,47 +1448,17 @@ Gfx::DeviceConfig CApplication::GetVideoConfig() const return m_deviceConfig; } -VideoQueryResult CApplication::GetVideoResolutionList(std::vector &resolutions, - bool fullScreen, bool resizeable) const +void CApplication::GetVideoResolutionList(std::vector &resolutions, int display) const { resolutions.clear(); - const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - if (videoInfo == nullptr) - return VIDEO_QUERY_ERROR; + for(int i = 0; i < SDL_GetNumDisplayModes(display); i++) + { + SDL_DisplayMode mode; + SDL_GetDisplayMode(display, i, &mode); - Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; - - // Use hardware surface if available - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - // Enable hardware blit if available - if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - - if (resizeable) - videoFlags |= SDL_RESIZABLE; - - if (fullScreen) - videoFlags |= SDL_FULLSCREEN; - - - SDL_Rect **modes = SDL_ListModes(nullptr, videoFlags); - - if (modes == reinterpret_cast(0) ) - return VIDEO_QUERY_NONE; // no modes available - - if (modes == reinterpret_cast(-1) ) - return VIDEO_QUERY_ALL; // all resolutions are possible - - - for (int i = 0; modes[i] != nullptr; ++i) - resolutions.push_back(Math::IntPoint(modes[i]->w, modes[i]->h)); - - return VIDEO_QUERY_OK; + resolutions.push_back(Math::IntPoint(mode.w, mode.h)); + } } void CApplication::SetDebugModeActive(DebugMode mode, bool active) @@ -1541,17 +1512,6 @@ bool CApplication::ParseDebugModes(const std::string& str, int& debugModes) return true; } -void CApplication::SetGrabInput(bool grab) -{ - SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF); -} - -bool CApplication::GetGrabInput() const -{ - int result = SDL_WM_GrabInput(SDL_GRAB_QUERY); - return result == SDL_GRAB_ON; -} - void CApplication::SetMouseMode(MouseMode mode) { m_mouseMode = mode; @@ -1570,7 +1530,7 @@ void CApplication::MoveMouse(Math::Point pos) { Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos); m_input->MouseMove(windowPos); - SDL_WarpMouse(windowPos.x, windowPos.y); + SDL_WarpMouseInWindow(m_private->window, windowPos.x, windowPos.y); } std::vector CApplication::GetJoystickList() const @@ -1583,7 +1543,7 @@ std::vector CApplication::GetJoystickList() const { JoystickDevice device; device.index = index; - device.name = SDL_JoystickName(index); + device.name = SDL_JoystickNameForIndex(index); result.push_back(device); } diff --git a/src/app/app.h b/src/app/app.h index 4547792d..6295adc7 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -71,18 +71,6 @@ struct JoystickDevice : index(-1), axisCount(0), buttonCount(0) {} }; -/** - * \enum VideoQueryResult - * \brief Result of querying for available video resolutions - */ -enum VideoQueryResult -{ - VIDEO_QUERY_ERROR, - VIDEO_QUERY_NONE, - VIDEO_QUERY_ALL, - VIDEO_QUERY_OK -}; - /** * \enum ParseArgsStatus * \brief State of parsing commandline arguments @@ -215,8 +203,7 @@ public: const std::string& GetErrorMessage() const; //! Returns a list of possible video modes - VideoQueryResult GetVideoResolutionList(std::vector &resolutions, - bool fullScreen, bool resizeable) const; + void GetVideoResolutionList(std::vector &resolutions, int display = 0) const; //! Returns the current video mode Gfx::DeviceConfig GetVideoConfig() const; @@ -277,12 +264,6 @@ public: //! Updates the mouse position explicitly void UpdateMouse(); - //! Management of the grab mode for input (keyboard & mouse) - //@{ - void SetGrabInput(bool grab); - bool GetGrabInput() const; - //@} - //! Management of mouse mode //@{ void SetMouseMode(MouseMode mode); diff --git a/src/app/input.cpp b/src/app/input.cpp index b9ec5548..32400dca 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -135,10 +135,10 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 1.0f; if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = -1.0f; - if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = -1.0f; - if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 1.0f; - if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 1.0f; - if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = -1.0f; + if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = -1.0f; + if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 1.0f; + if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 1.0f; + if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = -1.0f; } else if (event.type == EVENT_KEY_UP) { @@ -153,10 +153,10 @@ void CInput::EventProcess(Event& event) if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 0.0f; if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = 0.0f; - if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = 0.0f; - if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 0.0f; - if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 0.0f; - if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = 0.0f; + if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = 0.0f; + if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 0.0f; + if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 0.0f; + if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = 0.0f; } else if (event.type == EVENT_JOY_AXIS) { @@ -253,7 +253,7 @@ void CInput::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_DESEL ].primary = KEY(KP0); + m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP_0); m_inputBindings[INPUT_SLOT_ACTION ].primary = KEY(RETURN); m_inputBindings[INPUT_SLOT_ACTION ].secondary = KEY(e); m_inputBindings[INPUT_SLOT_NEAR ].primary = KEY(KP_PLUS); diff --git a/src/common/image.cpp b/src/common/image.cpp index da36aafb..845eb064 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -238,7 +238,7 @@ void CImage::ConvertToRGBA() void CImage::BlitToNewRGBASurface(int width, int height) { - m_data->surface->flags &= (~SDL_SRCALPHA); + //m_data->surface->flags &= (~SDL_SRCALPHA); //TODO: ? SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); assert(convertedSurface != nullptr); diff --git a/src/common/key.cpp b/src/common/key.cpp index 4975caf4..a574f3af 100644 --- a/src/common/key.cpp +++ b/src/common/key.cpp @@ -27,8 +27,8 @@ unsigned int GetVirtualKey(unsigned int key) return VIRTUAL_KMOD(SHIFT); if(key == KEY(LALT) || key == KEY(RALT)) return VIRTUAL_KMOD(ALT); - if(key == KEY(LMETA) || key == KEY(RMETA)) - return VIRTUAL_KMOD(META); + if(key == KEY(LGUI) || key == KEY(RGUI)) + return VIRTUAL_KMOD(GUI); if(key == KEY(KP_ENTER)) return KEY(RETURN); diff --git a/src/common/key.h b/src/common/key.h index d0fec00c..a0d66587 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -25,7 +25,8 @@ #pragma once -#include +#include +#define SDLK_LAST (SDLK_SCANCODE_MASK << 1) //TODO /* Key definitions are specially defined here so that it is clear in other parts of the code that these are used. It is to avoid having SDL-related enum values or #defines lying around @@ -51,7 +52,7 @@ enum VirtualKmod VIRTUAL_KMOD_CTRL = SDLK_LAST + 100, //! < control (left or right) VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right) VIRTUAL_KMOD_ALT = SDLK_LAST + 102, //! < alt (left or right) - VIRTUAL_KMOD_META = SDLK_LAST + 103 //! < win key (left or right) + VIRTUAL_KMOD_GUI = SDLK_LAST + 103 //! < windows logo (on windows/linux) or command (on mac os) key (left or right) }; // Just syntax sugar diff --git a/src/common/resources/sdl_file_wrapper.cpp b/src/common/resources/sdl_file_wrapper.cpp index 27ce7384..97cd2eef 100644 --- a/src/common/resources/sdl_file_wrapper.cpp +++ b/src/common/resources/sdl_file_wrapper.cpp @@ -52,11 +52,12 @@ CSDLFileWrapper::CSDLFileWrapper(const std::string& filename) return; } - m_rwops->type = PHYSFS_RWOPS_TYPE; + m_rwops->type = PHYSFS_RWOPS_TYPE; //TODO: Documentation recommends to leave SDL_RWOPS_UNKNOWN here for application-defined RWops. Did that change in SDL2? m_rwops->hidden.unknown.data1 = file; m_rwops->seek = SDLSeek; m_rwops->read = SDLRead; m_rwops->write = SDLWrite; + m_rwops->size = SDLSize; // This is safe because SDL_FreeRW will be called in destructor m_rwops->close = SDLCloseWithoutFreeRW; } @@ -117,7 +118,7 @@ bool CSDLFileWrapper::CheckSDLContext(SDL_RWops *context) return true; } -int CSDLFileWrapper::SDLSeek(SDL_RWops *context, int offset, int whence) +Sint64 CSDLFileWrapper::SDLSeek(SDL_RWops *context, Sint64 offset, int whence) { if (CheckSDLContext(context)) { @@ -151,7 +152,12 @@ int CSDLFileWrapper::SDLSeek(SDL_RWops *context, int offset, int whence) return -1; } -int CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum) +Sint64 CSDLFileWrapper::SDLSize(SDL_RWops *context) +{ + return -1; // Not needed for now +} + +size_t CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, size_t size, size_t maxnum) { if (CheckSDLContext(context)) { @@ -165,7 +171,8 @@ int CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum return 0; } -int CSDLFileWrapper::SDLWrite(SDL_RWops *context, const void *ptr, int size, int num) +size_t CSDLFileWrapper::SDLWrite(SDL_RWops *context, const void *ptr, size_t size, size_t num) { + assert(!!"Writing to CSDLFileWrapper is currently not supported"); return 0; } diff --git a/src/common/resources/sdl_file_wrapper.h b/src/common/resources/sdl_file_wrapper.h index 96b4d92f..2c9f8a1e 100644 --- a/src/common/resources/sdl_file_wrapper.h +++ b/src/common/resources/sdl_file_wrapper.h @@ -37,9 +37,10 @@ public: SDL_RWops* GetHandler(); private: - static int SDLSeek(SDL_RWops *context, int offset, int whence); - static int SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum); - static int SDLWrite(SDL_RWops *context, const void *ptr, int size, int num); + static Sint64 SDLSeek(SDL_RWops *context, Sint64 offset, int whence); + static Sint64 SDLSize(SDL_RWops *context); + static size_t SDLRead(SDL_RWops *context, void *ptr, size_t size, size_t maxnum); + static size_t SDLWrite(SDL_RWops *context, const void *ptr, size_t size, size_t num); static int SDLClose(SDL_RWops *context, bool freeRW); static int SDLCloseWithoutFreeRW(SDL_RWops *context); static int SDLCloseWithFreeRW(SDL_RWops *context); diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 7e6acff1..40d17aba 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -866,6 +866,7 @@ bool GetResource(ResType type, unsigned int num, std::string& text) } else { + // TODO: fix signed/unsigned comparations if (num == KEY_INVALID) text.clear(); else if (num == VIRTUAL_KMOD_CTRL) @@ -874,8 +875,8 @@ bool GetResource(ResType type, unsigned int num, std::string& text) text = "Shift"; else if (num == VIRTUAL_KMOD_ALT) text = "Alt"; - else if (num == VIRTUAL_KMOD_META) - text = "Win"; + else if (num == VIRTUAL_KMOD_GUI) + text = "Win"; // TODO: Better description of this key? else if (num > VIRTUAL_JOY(0)) { text = gettext("Button %1"); @@ -883,7 +884,7 @@ bool GetResource(ResType type, unsigned int num, std::string& text) } else { - text = SDL_GetKeyName(static_cast(num)); + text = SDL_GetKeyName(static_cast(num)); text = boost::regex_replace(text, boost::regex("\\[(.*)\\]"), "\\1"); text[0] = toupper(text[0]); } diff --git a/src/common/thread/resource_owning_thread.h b/src/common/thread/resource_owning_thread.h index c12ade45..d74755ca 100644 --- a/src/common/thread/resource_owning_thread.h +++ b/src/common/thread/resource_owning_thread.h @@ -52,9 +52,10 @@ public: using ResourceUPtr = std::unique_ptr; using ThreadFunctionPtr = void(*)(ResourceUPtr); - CResourceOwningThread(ThreadFunctionPtr threadFunction, ResourceUPtr resource) + CResourceOwningThread(ThreadFunctionPtr threadFunction, ResourceUPtr resource, std::string name = "") : m_threadFunction(threadFunction), - m_resource(std::move(resource)) + m_resource(std::move(resource)), + m_name(name) {} void Start() @@ -72,7 +73,7 @@ public: SDL_LockMutex(*mutex); - SDL_CreateThread(Run, reinterpret_cast(&data)); + SDL_CreateThread(Run, !m_name.empty() ? m_name.c_str() : nullptr, reinterpret_cast(&data)); while (!condition) { @@ -114,4 +115,5 @@ private: ThreadFunctionPtr m_threadFunction; ResourceUPtr m_resource; + std::string m_name; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 195a1edb..ae5aaf70 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -500,7 +500,7 @@ void CEngine::WriteScreenShot(const std::string& fileName) data->fileName = fileName; - CResourceOwningThread thread(CEngine::WriteScreenShotThread, std::move(data)); + CResourceOwningThread thread(CEngine::WriteScreenShotThread, std::move(data), "WriteScreenShot thread"); thread.Start(); } diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 22bd4f05..e8f3840b 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -1014,7 +1014,7 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) int w = Math::NextPowerOfTwo(textSurface->w); int h = Math::NextPowerOfTwo(textSurface->h); - textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); + //textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); //TODO: ? SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr); diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index fb362034..bf3756ea 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -718,8 +718,8 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - format.alpha = 0; - format.colorkey = 0; + //format.alpha = 0; //TODO: ? + //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 65d78f7c..251c1ec4 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -745,8 +745,8 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - format.alpha = 0; - format.colorkey = 0; + //format.alpha = 0; //TODO: ? + //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 4f59cae4..2e3c9315 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -687,8 +687,8 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - format.alpha = 0; - format.colorkey = 0; + //format.alpha = 0; //TODO: ? + //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 8d7cd0a0..7d76bd7a 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -107,7 +107,6 @@ #include #include -#include #include @@ -931,7 +930,7 @@ bool CRobotMain::ProcessEvent(Event &event) std::stringstream ss; ss << line; - widgetSetClipboardText(ss.str().c_str()); + SDL_SetClipboardText(ss.str().c_str()); } } break; diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 3fe94219..07af407b 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -40,8 +40,7 @@ #include "ui/controls/scroll.h" -#include - +#include #include #include @@ -2537,7 +2536,7 @@ bool CEdit::Copy(bool memorize_cursor) std::vector text(len + 1, '\0'); strncpy(text.data(), m_text.data() + start, len); text[len] = 0; - widgetSetClipboardText(text.data()); + SDL_SetClipboardText(text.data()); //TODO: Move to CApplication if (memorize_cursor) { @@ -2560,7 +2559,7 @@ bool CEdit::Paste() return false; } - text = widgetGetClipboardText(); + text = SDL_GetClipboardText(); // TODO: Move to CApplication if ( text == nullptr ) { diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index 448e4c95..854f3064 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -105,7 +105,7 @@ bool CKey::EventProcess(const Event &event) bool CKey::TestKey(unsigned int key) { - if (key == KEY(PAUSE) || key == KEY(PRINT)) return true; // blocked key + if (key == KEY(PAUSE)) return true; // blocked key for (int i = 0; i < INPUT_SLOT_MAX; i++) { @@ -210,4 +210,3 @@ InputBinding CKey::GetBinding() } // namespace Ui - diff --git a/src/ui/screen/screen_setup_display.cpp b/src/ui/screen/screen_setup_display.cpp index 2f4f0a66..f9cd2cc9 100644 --- a/src/ui/screen/screen_setup_display.cpp +++ b/src/ui/screen/screen_setup_display.cpp @@ -64,7 +64,7 @@ void CScreenSetupDisplay::CreateInterface() if ( pw == nullptr ) return; std::vector modes; - m_app->GetVideoResolutionList(modes, true, true); + m_app->GetVideoResolutionList(modes); for (auto it = modes.begin(); it != modes.end(); ++it) { if (it->x == m_app->GetVideoConfig().size.x && it->y == m_app->GetVideoConfig().size.y) @@ -183,7 +183,7 @@ void CScreenSetupDisplay::UpdateDisplayMode() pl->Flush(); std::vector modes; - m_app->GetVideoResolutionList(modes, true, true); + m_app->GetVideoResolutionList(modes); int i = 0; std::stringstream mode_text; for (Math::IntPoint mode : modes) @@ -220,7 +220,7 @@ void CScreenSetupDisplay::ChangeDisplay() m_setupFull = bFull; std::vector modes; - m_app->GetVideoResolutionList(modes, true, true); + m_app->GetVideoResolutionList(modes); Gfx::DeviceConfig config = m_app->GetVideoConfig(); config.size = modes[m_setupSelMode]; From dfa06dafcf0ec98d99361fde9fa1de7cc8a80322 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 11:11:35 +0200 Subject: [PATCH 003/360] Refactored window resize --- src/app/app.cpp | 67 +++--------------------------- src/app/app.h | 2 - src/graphics/engine/engine.cpp | 60 +++++++------------------- src/graphics/engine/engine.h | 5 ++- src/graphics/engine/text.cpp | 15 ++++--- src/graphics/engine/text.h | 5 ++- src/graphics/opengl/gl21device.cpp | 15 +++++-- src/graphics/opengl/gl33device.cpp | 15 +++++-- src/graphics/opengl/gldevice.cpp | 15 +++++-- src/level/robotmain.cpp | 14 ++++--- src/level/robotmain.h | 3 +- 11 files changed, 84 insertions(+), 132 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index fb2e12a4..ecdaa5e9 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -655,25 +655,7 @@ bool CApplication::Create() bool CApplication::CreateVideoSurface() { - /*const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); - if (videoInfo == nullptr) - { - m_errorMessage = std::string("SDL error while getting video info:\n ") + - std::string(SDL_GetError()); - GetLogger()->Error(m_errorMessage.c_str()); - m_exitCode = 7; - return false; - }*/ - - Uint32 videoFlags = SDL_WINDOW_OPENGL; // | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE - - // Use hardware surface if available - /*if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE;*/ - - // Enable hardware blit if available - /*if (videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL;*/ + Uint32 videoFlags = SDL_WINDOW_OPENGL; if (m_deviceConfig.fullScreen) videoFlags |= SDL_WINDOW_FULLSCREEN; @@ -710,54 +692,15 @@ bool CApplication::CreateVideoSurface() bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) { - static bool restore = false; - - m_lastDeviceConfig = m_deviceConfig; m_deviceConfig = newConfig; - SDL_GL_DeleteContext(m_private->glcontext); //TODO: refactor this - SDL_DestroyWindow(m_private->window); // TODO: ? - - if (! CreateVideoSurface()) - { - // Fatal error, so post the quit event - m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT)); - return false; - } - - if (m_private->window == nullptr) - { - if (! restore) - { - std::string error = std::string("SDL error while setting video mode:\n") + - std::string(SDL_GetError()) + std::string("\n") + - std::string("Previous mode will be restored"); - GetLogger()->Error(error.c_str()); - m_systemUtils->SystemDialog( SDT_ERROR, "COLOBOT - Error", error); - - restore = true; - ChangeVideoConfig(m_lastDeviceConfig); - return false; - } - else - { - restore = false; - - std::string error = std::string("SDL error while restoring previous video mode:\n") + - std::string(SDL_GetError()); - GetLogger()->Error(error.c_str()); - m_systemUtils->SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error", error); - - - // Fatal error, so post the quit event - m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT)); - return false; - } - } + // TODO: Somehow this doesn't work for maximized windows (at least on Ubuntu) + SDL_SetWindowSize(m_private->window, m_deviceConfig.size.x, m_deviceConfig.size.y); + SDL_SetWindowFullscreen(m_private->window, m_deviceConfig.fullScreen ? SDL_WINDOW_FULLSCREEN : 0); m_device->ConfigChanged(m_deviceConfig); - m_engine->ResetAfterDeviceChanged(); + m_engine->ResetAfterVideoConfigChanged(); return true; } diff --git a/src/app/app.h b/src/app/app.h index 6295adc7..ef737b4e 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -369,8 +369,6 @@ protected: //! Current configuration of OpenGL display device Gfx::DeviceConfig m_deviceConfig; - //! Previous configuration of OpenGL display device - Gfx::DeviceConfig m_lastDeviceConfig; //! Text set as window title std::string m_windowTitle; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index ae5aaf70..7cb4ed3e 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -362,55 +362,27 @@ void CEngine::Destroy() m_planet.reset(); } -void CEngine::ResetAfterDeviceChanged() +void CEngine::ResetAfterVideoConfigChanged() { m_size = m_app->GetVideoConfig().size; m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast(m_size.x) / static_cast(m_size.y))); - if (m_shadowMap.id != 0) - { - if (m_offscreenShadowRendering) - m_device->DeleteFramebuffer("shadow"); - else - m_device->DestroyTexture(m_shadowMap); - - m_shadowMap = Texture(); - } - - m_text->FlushCache(); - - FlushTextureCache(); - - CRobotMain::GetInstancePointer()->ResetAfterDeviceChanged(); - - LoadAllTextures(); - - for (int baseObjRank = 0; baseObjRank < static_cast( m_baseObjects.size() ); baseObjRank++) - { - EngineBaseObject& p1 = m_baseObjects[baseObjRank]; - if (! p1.used) - continue; - - for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) - { - EngineBaseObjTexTier& p2 = p1.next[l2]; - - for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) - { - EngineBaseObjDataTier& p3 = p2.next[l3]; - - m_device->DestroyStaticBuffer(p3.staticBufferId); - p3.staticBufferId = 0; - p3.updateStaticBuffer = true; - } - } - } + CRobotMain::GetInstancePointer()->ResetAfterVideoConfigChanged(); //TODO: Remove cross-reference to CRobotMain // Update the camera projection matrix for new aspect ratio SetFocus(m_focus); - // Because reloading textures takes a long time - m_app->ResetTimeAfterLoading(); + // This needs to be recreated on resolution change + m_device->DeleteFramebuffer("multisample"); +} + +void CEngine::ReloadAllTextures() +{ + FlushTextureCache(); + m_text->FlushCache(); + + CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain + LoadAllTextures(); } bool CEngine::ProcessEvent(const Event &event) @@ -2875,7 +2847,7 @@ void CEngine::SetTextureFilterMode(TexFilter value) m_defaultTexParams.filter = m_terrainTexParams.filter = value; m_defaultTexParams.mipmap = m_terrainTexParams.mipmap = (value == TEX_FILTER_TRILINEAR); - ResetAfterDeviceChanged(); + ReloadAllTextures(); } TexFilter CEngine::GetTextureFilterMode() @@ -2890,7 +2862,7 @@ void CEngine::SetTextureMipmapLevel(int value) if(m_textureMipmapLevel == value) return; m_textureMipmapLevel = value; - ResetAfterDeviceChanged(); + ReloadAllTextures(); } int CEngine::GetTextureMipmapLevel() @@ -2906,7 +2878,7 @@ void CEngine::SetTextureAnisotropyLevel(int value) if(m_textureAnisotropy == value) return; m_textureAnisotropy = value; - ResetAfterDeviceChanged(); + ReloadAllTextures(); } int CEngine::GetTextureAnisotropyLevel() diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 29e0b565..3d5fbbe5 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -659,7 +659,7 @@ public: void Destroy(); //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) - void ResetAfterDeviceChanged(); + void ResetAfterVideoConfigChanged(); //! Called once per frame, the call is the entry point for rendering @@ -1271,6 +1271,9 @@ protected: }; static void WriteScreenShotThread(std::unique_ptr data); + //! Reloads all textures + void ReloadAllTextures(); + protected: CApplication* m_app; CSystemUtils* m_systemUtils; diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index e8f3840b..5cf724c6 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -389,7 +389,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) auto it = cf->cache.find(ch); if (it != cf->cache.end()) { - charSize = (*it).second.charSize; + charSize = m_engine->WindowToInterfaceSize((*it).second.charSize); } else { @@ -926,8 +926,11 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P CharTexture tex = GetCharTexture(ch, font, size); - Math::Point p1(pos.x, pos.y + tex.charSize.y - tex.texSize.y); - Math::Point p2(pos.x + tex.texSize.x, pos.y + tex.charSize.y); + Math::Point charSize = m_engine->WindowToInterfaceSize(tex.charSize); + Math::Point texSize = m_engine->WindowToInterfaceSize(tex.texSize); + + Math::Point p1(pos.x, pos.y + charSize.y - texSize.y); + Math::Point p2(pos.x + texSize.x, pos.y + charSize.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal @@ -943,7 +946,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); m_engine->AddStatisticTriangle(2); - pos.x += tex.charSize.x * width; + pos.x += charSize.x * width; } } @@ -1038,8 +1041,8 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) else { texture.id = tex.id; - texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h)); - texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h)); + texture.texSize = Math::IntPoint(textureSurface->w, textureSurface->h); + texture.charSize = Math::IntPoint(textSurface->w, textSurface->h); } SDL_FreeSurface(textSurface); diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 1ab48219..6ce6be33 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -28,6 +28,7 @@ #include "graphics/core/color.h" #include "math/point.h" +#include "math/intpoint.h" #include #include @@ -190,8 +191,8 @@ struct UTF8Char struct CharTexture { unsigned int id = 0; - Math::Point texSize; - Math::Point charSize; + Math::IntPoint texSize; + Math::IntPoint charSize; }; // Definition is private - in text.cpp diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index bf3756ea..d07c6be8 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -164,7 +164,7 @@ bool CGL21Device::Create() { GetLogger()->Info("Creating CDevice - OpenGL 2.1\n"); - /*static*/ bool glewInited = false; + static bool glewInited = false; if (!glewInited) { @@ -396,8 +396,17 @@ void CGL21Device::ConfigChanged(const DeviceConfig& newConfig) // Reset state m_lighting = false; - Destroy(); - Create(); + + glViewport(0, 0, m_config.size.x, m_config.size.y); + + // create default framebuffer object + FramebufferParams framebufferParams; + + framebufferParams.width = m_config.size.x; + framebufferParams.height = m_config.size.y; + framebufferParams.depth = m_config.depthSize; + + m_framebuffers["default"] = MakeUnique(framebufferParams); } void CGL21Device::BeginScene() diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 251c1ec4..65a85845 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -164,7 +164,7 @@ bool CGL33Device::Create() { GetLogger()->Info("Creating CDevice - OpenGL 3.3\n"); - /*static*/ bool glewInited = false; + static bool glewInited = false; if (!glewInited) { @@ -421,8 +421,17 @@ void CGL33Device::ConfigChanged(const DeviceConfig& newConfig) // Reset state m_lighting = false; - Destroy(); - Create(); + + glViewport(0, 0, m_config.size.x, m_config.size.y); + + // create default framebuffer object + FramebufferParams framebufferParams; + + framebufferParams.width = m_config.size.x; + framebufferParams.height = m_config.size.y; + framebufferParams.depth = m_config.depthSize; + + m_framebuffers["default"] = MakeUnique(framebufferParams); } void CGL33Device::BeginScene() diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 2e3c9315..102fa9bf 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -160,7 +160,7 @@ bool CGLDevice::Create() { GetLogger()->Info("Creating CDevice - OpenGL 1.4\n"); - /*static*/ bool glewInited = false; + static bool glewInited = false; if (!glewInited) { @@ -337,8 +337,17 @@ void CGLDevice::ConfigChanged(const DeviceConfig& newConfig) // Reset state m_lighting = false; - Destroy(); - Create(); + + glViewport(0, 0, m_config.size.x, m_config.size.y); + + // create default framebuffer object + FramebufferParams framebufferParams; + + framebufferParams.width = m_config.size.x; + framebufferParams.height = m_config.size.y; + framebufferParams.depth = m_config.depthSize; + + m_framebuffers["default"] = MakeUnique(framebufferParams); } void CGLDevice::BeginScene() diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 7d76bd7a..674fca40 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -293,7 +293,15 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() return m_displayText.get(); } -void CRobotMain::ResetAfterDeviceChanged() +void CRobotMain::ResetAfterVideoConfigChanged() +{ + // Recreate the interface (needed if the aspect ratio changes) + // TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring. + m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); + CreateShortcuts(); +} + +void CRobotMain::ReloadAllTextures() { if (m_phase == PHASE_SETUPds || m_phase == PHASE_SETUPgs || @@ -307,10 +315,6 @@ void CRobotMain::ResetAfterDeviceChanged() ChangeColor(); UpdateMap(); } - - // Recreate the interface (needed if the aspect ratio changes) - m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); - CreateShortcuts(); } diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 604e5e59..dbe319b5 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -162,7 +162,8 @@ public: void CreateConfigFile(); void LoadConfigFile(); - void ResetAfterDeviceChanged(); + void ResetAfterVideoConfigChanged(); + void ReloadAllTextures(); void ChangePhase(Phase phase); bool ProcessEvent(Event &event); From 7839dce6241e4df9f549e9f7f171ac6a2d66150f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 11:16:09 +0200 Subject: [PATCH 004/360] Fixed duplicate resolutions appearing on the list --- src/app/app.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index ecdaa5e9..19b7fe73 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1399,8 +1399,10 @@ void CApplication::GetVideoResolutionList(std::vector &resolutio { SDL_DisplayMode mode; SDL_GetDisplayMode(display, i, &mode); + Math::IntPoint resolution = Math::IntPoint(mode.w, mode.h); - resolutions.push_back(Math::IntPoint(mode.w, mode.h)); + if (std::find(resolutions.begin(), resolutions.end(), resolution) == resolutions.end()) + resolutions.push_back(resolution); } } From e965414d34b7c51196bafbe5f45983d6c3a8ffc8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 19:49:50 +0200 Subject: [PATCH 005/360] Rewritten text input to SDL2 --- src/app/app.cpp | 43 +++++++++++++++++++++++++++++++++++----- src/app/app.h | 11 +++++++--- src/common/event.cpp | 2 ++ src/common/event.h | 23 +++++++++++++++++---- src/ui/controls/edit.cpp | 30 ++++++++++++++++++++-------- src/ui/controls/edit.h | 2 ++ 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 19b7fe73..c57b6824 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -97,6 +97,7 @@ struct ApplicationPrivate SDL_memset(¤tEvent, 0, sizeof(SDL_Event)); SDL_memset(&lastMouseMotionEvent, 0, sizeof(SDL_Event)); window = nullptr; + glcontext = nullptr; joystick = nullptr; joystickTimer = 0; } @@ -1038,7 +1039,6 @@ Event CApplication::ProcessSystemEvent() data->virt = false; data->key = m_private->currentEvent.key.keysym.sym; - data->unicode = m_private->currentEvent.key.keysym.sym; // TODO: use SDL_TEXTINPUT for this, and remove this field event.kmodState = m_private->currentEvent.key.keysym.mod; // Some keyboards return numerical enter keycode instead of normal enter @@ -1055,6 +1055,13 @@ Event CApplication::ProcessSystemEvent() event.data = std::move(data); } + else if (m_private->currentEvent.type == SDL_TEXTINPUT) + { + event.type = EVENT_TEXT_INPUT; + auto data = MakeUnique(); + data->text = m_private->currentEvent.text.text; + event.data = std::move(data); + } else if (m_private->currentEvent.type == SDL_MOUSEWHEEL) { event.type = EVENT_MOUSE_WHEEL; @@ -1127,11 +1134,17 @@ void CApplication::LogEvent(const Event &event) }; // Print the events in debug mode to test the code - if (IsDebugModeActive(DEBUG_SYS_EVENTS) || IsDebugModeActive(DEBUG_APP_EVENTS)) + if (IsDebugModeActive(DEBUG_SYS_EVENTS) || IsDebugModeActive(DEBUG_UPDATE_EVENTS) || IsDebugModeActive(DEBUG_APP_EVENTS)) { std::string eventType = ParseEventType(event.type); - if (IsDebugModeActive(DEBUG_SYS_EVENTS) && event.type <= EVENT_SYS_MAX) + if (IsDebugModeActive(DEBUG_UPDATE_EVENTS) && event.type == EVENT_FRAME) + { + l->Trace("Update event: %s\n", eventType.c_str()); + PrintEventDetails(); + } + + if (IsDebugModeActive(DEBUG_SYS_EVENTS) && (event.type <= EVENT_SYS_MAX && event.type != EVENT_FRAME)) { l->Trace("System event %s:\n", eventType.c_str()); switch (event.type) @@ -1142,7 +1155,12 @@ void CApplication::LogEvent(const Event &event) auto data = event.GetData(); l->Trace(" virt = %s\n", data->virt ? "true" : "false"); l->Trace(" key = %d\n", data->key); - l->Trace(" unicode = 0x%04x\n", data->unicode); + break; + } + case EVENT_TEXT_INPUT: + { + auto data = event.GetData(); + l->Trace(" text = %s\n", data->text.c_str()); break; } case EVENT_MOUSE_BUTTON_DOWN: @@ -1231,7 +1249,6 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent) auto data = MakeUnique(); data->virt = true; data->key = VIRTUAL_JOY(sourceData->button); - data->unicode = 0; virtualEvent.data = std::move(data); } else @@ -1431,6 +1448,10 @@ bool CApplication::ParseDebugModes(const std::string& str, int& debugModes) { debugModes |= DEBUG_SYS_EVENTS; } + else if (modeToken == "update_events") + { + debugModes |= DEBUG_UPDATE_EVENTS; + } else if (modeToken == "app_events") { debugModes |= DEBUG_APP_EVENTS; @@ -1758,3 +1779,15 @@ bool CApplication::GetSceneTestMode() { return m_sceneTest; } + +void CApplication::SetTextInput(bool textInputEnabled) +{ + if (textInputEnabled) + { + SDL_StartTextInput(); + } + else + { + SDL_StopTextInput(); + } +} diff --git a/src/app/app.h b/src/app/app.h index ef737b4e..e8294813 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -125,9 +125,10 @@ enum PerformanceCounter enum DebugMode { DEBUG_SYS_EVENTS = 1 << 0, - DEBUG_APP_EVENTS = 1 << 1, - DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS, - DEBUG_MODELS = 1 << 2, + DEBUG_UPDATE_EVENTS = 1 << 1, + DEBUG_APP_EVENTS = 1 << 2, + DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_UPDATE_EVENTS | DEBUG_APP_EVENTS, + DEBUG_MODELS = 1 << 3, DEBUG_ALL = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS | DEBUG_MODELS }; @@ -270,6 +271,10 @@ public: MouseMode GetMouseMode() const; //@} + //! Enable/disable text input, this toggles the on-screen keyboard on some platforms + /** This also allows for writing in CJK languages (not tested!), see https://wiki.libsdl.org/Tutorials/TextInput for detailed explanation */ + void SetTextInput(bool textInputEnabled); + //! Moves (warps) the mouse cursor to the specified position (in interface coords) void MoveMouse(Math::Point pos); diff --git a/src/common/event.cpp b/src/common/event.cpp index 9bd0cff9..de326bb2 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -57,6 +57,8 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_ACTIVE] = "EVENT_ACTIVE"; + EVENT_TYPE_TEXT[EVENT_TEXT_INPUT] = "EVENT_TEXT_INPUT"; + EVENT_TYPE_TEXT[EVENT_JOY_AXIS] = "EVENT_JOY_AXIS"; EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_DOWN] = "EVENT_JOY_BUTTON_DOWN"; EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_UP] = "EVENT_JOY_BUTTON_UP"; diff --git a/src/common/event.h b/src/common/event.h index a905833e..d7230b07 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -70,6 +70,9 @@ enum EventType //! Event sent when application window loses/gains focus EVENT_ACTIVE = 10, + //! Event sent when user inputs some character + EVENT_TEXT_INPUT = 11, + //! Event sent after moving joystick axes EVENT_JOY_AXIS = 12, //! Event sent after pressing a joystick button @@ -569,13 +572,25 @@ struct KeyEventData : public EventData bool virt = false; //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h) unsigned int key = 0; - //! Unicode character - //! NOTE: applicable only to EVENT_KEY_DOWN events! - unsigned int unicode = 0; //! Input binding slot for this key - InputSlot slot = INPUT_SLOT_LEFT; + InputSlot slot = INPUT_SLOT_MAX; }; +/** + * \struct TextInputData + * \brief Additional data for text input event + */ + struct TextInputData : public EventData + { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + + //! Text entered by the user (usually one character, UTF-8 encoded) + std::string text = ""; + }; + /** * \enum MouseButton * \brief Mouse button diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 07af407b..a5535757 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -143,6 +143,11 @@ CEdit::CEdit() CEdit::~CEdit() { FreeImage(); + + if (m_bFocus) + { + CApplication::GetInstancePointer()->SetTextInput(false); + } } @@ -473,15 +478,12 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.type == EVENT_KEY_DOWN && !bControl && m_bFocus ) + if ( event.type == EVENT_TEXT_INPUT && !bControl && m_bFocus ) { - auto data = event.GetData(); - if (data->unicode >= ' ') - { - Insert(static_cast(data->unicode)); // TODO: insert utf-8 char - SendModifEvent(); - return true; - } + auto data = event.GetData(); + Insert(data->text[0]); // TODO: insert utf-8 char + SendModifEvent(); + return true; } if ( event.type == EVENT_FOCUS ) @@ -3215,4 +3217,16 @@ void CEdit::UpdateScroll() } } +void CEdit::SetFocus(CControl* control) +{ + bool oldFocus = m_bFocus; + CControl::SetFocus(control); + + if (oldFocus != m_bFocus) + { + // Start/stop text input mode, this toggles the on-screen keyboard + CApplication::GetInstancePointer()->SetTextInput(m_bFocus); + } +} + } diff --git a/src/ui/controls/edit.h b/src/ui/controls/edit.h index 9a33884d..0a453a6c 100644 --- a/src/ui/controls/edit.h +++ b/src/ui/controls/edit.h @@ -227,6 +227,8 @@ protected: void UpdateScroll(); + void SetFocus(CControl* control) override; + protected: std::unique_ptr m_scroll; // vertical scrollbar on the right From a0034f8000c424ad5f4b2d709db4ee9e13d13a05 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 21:26:49 +0200 Subject: [PATCH 006/360] Finalized SDL2 migration --- src/app/app.cpp | 41 ++++++++++----------- src/app/input.cpp | 22 +++++++----- src/common/event.cpp | 9 +++-- src/common/event.h | 58 +++++++++--------------------- src/common/image.cpp | 1 - src/common/key.h | 4 ++- src/common/restext.cpp | 15 ++++---- src/graphics/engine/text.cpp | 1 - src/graphics/opengl/gl21device.cpp | 2 -- src/graphics/opengl/gl33device.cpp | 2 -- src/graphics/opengl/gldevice.cpp | 2 -- 11 files changed, 62 insertions(+), 95 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index c57b6824..94976a72 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -579,8 +579,6 @@ bool CApplication::Create() } } - //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //TODO: ? - // Don't generate joystick events SDL_JoystickEventState(SDL_IGNORE); @@ -1002,30 +1000,34 @@ Event CApplication::ProcessSystemEvent() } else if (m_private->currentEvent.type == SDL_WINDOWEVENT) { - if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) + { Gfx::DeviceConfig newConfig = m_deviceConfig; newConfig.size.x = m_private->currentEvent.window.data1; newConfig.size.y = m_private->currentEvent.window.data2; if (newConfig.size != m_deviceConfig.size) ChangeVideoConfig(newConfig); } - // TODO: EVENT_ACTIVE - /*{ - event.type = EVENT_ACTIVE; - auto data = MakeUnique(); + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_ENTER) + { + event.type = EVENT_MOUSE_ENTER; + } - if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS) - data->flags |= ACTIVE_INPUT; - if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS) - data->flags |= ACTIVE_MOUSE; - if (m_private->currentEvent.active.type & SDL_APPACTIVE) - data->flags |= ACTIVE_APP; + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_LEAVE) + { + event.type = EVENT_MOUSE_LEAVE; + } - data->gain = m_private->currentEvent.active.gain == 1; + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) + { + event.type = EVENT_FOCUS_GAINED; + } - event.data = std::move(data); - }*/ + if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_FOCUS_LOST) + { + event.type = EVENT_FOCUS_LOST; + } } else if ( (m_private->currentEvent.type == SDL_KEYDOWN) || (m_private->currentEvent.type == SDL_KEYUP) ) @@ -1190,13 +1192,6 @@ void CApplication::LogEvent(const Event &event) l->Trace(" button = %d\n", data->button); break; } - case EVENT_ACTIVE: - { - auto data = event.GetData(); - l->Trace(" flags = 0x%x\n", data->flags); - l->Trace(" gain = %s\n", data->gain ? "true" : "false"); - break; - } default: break; } diff --git a/src/app/input.cpp b/src/app/input.cpp index 32400dca..1ffecf84 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -330,6 +330,7 @@ InputSlot CInput::FindBinding(unsigned int key) void CInput::SaveKeyBindings() { std::stringstream key; + CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", "_Version", "SDL2"); for (int i = 0; i < INPUT_SLOT_MAX; i++) { InputBinding b = GetInputBinding(static_cast(i)); @@ -355,19 +356,22 @@ void CInput::LoadKeyBindings() { std::stringstream skey; std::string keys; - for (int i = 0; i < INPUT_SLOT_MAX; i++) + if (CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", "_Version", keys) && keys == "SDL2") // Keybindings from SDL1.2 are incompatible with SDL2 !! { - InputBinding b; + for (int i = 0; i < INPUT_SLOT_MAX; i++) + { + InputBinding b; - if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast(i)], keys)) - continue; - skey.clear(); - skey.str(keys); + if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast(i)], keys)) + continue; + skey.clear(); + skey.str(keys); - skey >> b.primary; - skey >> b.secondary; + skey >> b.primary; + skey >> b.secondary; - SetInputBinding(static_cast(i), b); + SetInputBinding(static_cast(i), b); + } } for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++) diff --git a/src/common/event.cpp b/src/common/event.cpp index de326bb2..5fce71b7 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -52,17 +52,20 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_MOUSE_BUTTON_UP] = "EVENT_MOUSE_BUTTON_UP"; EVENT_TYPE_TEXT[EVENT_MOUSE_WHEEL] = "EVENT_MOUSE_WHEEL"; EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_MOVE"; + EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_ENTER"; + EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_LEAVE"; + EVENT_TYPE_TEXT[EVENT_KEY_DOWN] = "EVENT_KEY_DOWN"; EVENT_TYPE_TEXT[EVENT_KEY_UP] = "EVENT_KEY_UP"; - - EVENT_TYPE_TEXT[EVENT_ACTIVE] = "EVENT_ACTIVE"; - EVENT_TYPE_TEXT[EVENT_TEXT_INPUT] = "EVENT_TEXT_INPUT"; EVENT_TYPE_TEXT[EVENT_JOY_AXIS] = "EVENT_JOY_AXIS"; EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_DOWN] = "EVENT_JOY_BUTTON_DOWN"; EVENT_TYPE_TEXT[EVENT_JOY_BUTTON_UP] = "EVENT_JOY_BUTTON_UP"; + EVENT_TYPE_TEXT[EVENT_FOCUS_GAINED] = "EVENT_FOCUS_GAINED"; + EVENT_TYPE_TEXT[EVENT_FOCUS_LOST] = "EVENT_FOCUS_LOST"; + EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE"; EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN"; diff --git a/src/common/event.h b/src/common/event.h index d7230b07..0da15182 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -62,23 +62,29 @@ enum EventType EVENT_MOUSE_WHEEL = 5, //! Event sent after moving the mouse EVENT_MOUSE_MOVE = 7, + //! Event sent when mouse enters the window + EVENT_MOUSE_ENTER = 8, + //! Event sent when mouse leaves the window + EVENT_MOUSE_LEAVE = 9, + //! Event sent after pressing a key - EVENT_KEY_DOWN = 8, + EVENT_KEY_DOWN = 10, //! Event sent after releasing a key - EVENT_KEY_UP = 9, - - //! Event sent when application window loses/gains focus - EVENT_ACTIVE = 10, - + EVENT_KEY_UP = 11, //! Event sent when user inputs some character - EVENT_TEXT_INPUT = 11, + EVENT_TEXT_INPUT = 12, //! Event sent after moving joystick axes - EVENT_JOY_AXIS = 12, + EVENT_JOY_AXIS = 13, //! Event sent after pressing a joystick button - EVENT_JOY_BUTTON_DOWN = 13, + EVENT_JOY_BUTTON_DOWN = 14, //! Event sent after releasing a joystick button - EVENT_JOY_BUTTON_UP = 14, + EVENT_JOY_BUTTON_UP = 15, + + //! Event sent when the app winddow gains focus + EVENT_FOCUS_GAINED = 16, + //! Event sent when the app winddow loses focus + EVENT_FOCUS_LOST = 17, //!< Maximum value of system events EVENT_SYS_MAX, @@ -678,38 +684,6 @@ struct JoyButtonEventData : public EventData unsigned char button = 0; }; -/** - * \enum ActiveEventFlags - * \brief Type of focus gained/lost - */ -enum ActiveEventFlags -{ - //! Application window focus - ACTIVE_APP = 0x01, - //! Input focus - ACTIVE_INPUT = 0x02, - //! Mouse focus - ACTIVE_MOUSE = 0x04 - -}; - -/** - * \struct ActiveEventData - * \brief Additional data for active event - */ -struct ActiveEventData : public EventData -{ - std::unique_ptr Clone() const override - { - return MakeUnique(*this); - } - - //! Flags (bitmask of enum values ActiveEventFlags) - unsigned char flags = 0; - //! True if the focus was gained; false otherwise - bool gain = false; -}; - /** * \struct Event * \brief Event sent by system, interface or game diff --git a/src/common/image.cpp b/src/common/image.cpp index 845eb064..dd57b616 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -238,7 +238,6 @@ void CImage::ConvertToRGBA() void CImage::BlitToNewRGBASurface(int width, int height) { - //m_data->surface->flags &= (~SDL_SRCALPHA); //TODO: ? SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); assert(convertedSurface != nullptr); diff --git a/src/common/key.h b/src/common/key.h index a0d66587..d57dd098 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -26,7 +26,9 @@ #include -#define SDLK_LAST (SDLK_SCANCODE_MASK << 1) //TODO + +// TODO: This is a bit ugly hack +#define SDLK_LAST (SDLK_SCANCODE_MASK << 1) /* Key definitions are specially defined here so that it is clear in other parts of the code that these are used. It is to avoid having SDL-related enum values or #defines lying around diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 40d17aba..1c1a27fe 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -866,18 +866,17 @@ bool GetResource(ResType type, unsigned int num, std::string& text) } else { - // TODO: fix signed/unsigned comparations - if (num == KEY_INVALID) + if (num == static_cast(KEY_INVALID)) text.clear(); - else if (num == VIRTUAL_KMOD_CTRL) + else if (num == static_cast(VIRTUAL_KMOD(CTRL))) text = "Ctrl"; - else if (num == VIRTUAL_KMOD_SHIFT) + else if (num == static_cast(VIRTUAL_KMOD(SHIFT))) text = "Shift"; - else if (num == VIRTUAL_KMOD_ALT) + else if (num == static_cast(VIRTUAL_KMOD(ALT))) text = "Alt"; - else if (num == VIRTUAL_KMOD_GUI) + else if (num == static_cast(VIRTUAL_KMOD(GUI))) text = "Win"; // TODO: Better description of this key? - else if (num > VIRTUAL_JOY(0)) + else if (num > static_cast(VIRTUAL_JOY(0))) { text = gettext("Button %1"); text = StrUtils::Replace(text, "%1", StrUtils::ToString(1 + num - VIRTUAL_JOY(0))); @@ -885,8 +884,6 @@ bool GetResource(ResType type, unsigned int num, std::string& text) else { text = SDL_GetKeyName(static_cast(num)); - text = boost::regex_replace(text, boost::regex("\\[(.*)\\]"), "\\1"); - text[0] = toupper(text[0]); } return true; } diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 5cf724c6..d1003443 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -1017,7 +1017,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) int w = Math::NextPowerOfTwo(textSurface->w); int h = Math::NextPowerOfTwo(textSurface->h); - //textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); //TODO: ? SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr); diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index d07c6be8..1c63deb6 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -727,8 +727,6 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - //format.alpha = 0; //TODO: ? - //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 65a85845..a3cc6254 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -754,8 +754,6 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - //format.alpha = 0; //TODO: ? - //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 102fa9bf..f283a0aa 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -696,8 +696,6 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par SDL_PixelFormat format; format.BytesPerPixel = 4; format.BitsPerPixel = 32; - //format.alpha = 0; //TODO: ? - //format.colorkey = 0; //TODO: ? format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; format.Amask = 0xFF000000; format.Ashift = 24; From 0c64e6297942bf931fe35bf042b1b461cd7e14b3 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 22:18:44 +0200 Subject: [PATCH 007/360] Fixed a minor error in event logging --- src/common/event.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/event.cpp b/src/common/event.cpp index 5fce71b7..0ebc23eb 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -52,8 +52,8 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_MOUSE_BUTTON_UP] = "EVENT_MOUSE_BUTTON_UP"; EVENT_TYPE_TEXT[EVENT_MOUSE_WHEEL] = "EVENT_MOUSE_WHEEL"; EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_MOVE"; - EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_ENTER"; - EVENT_TYPE_TEXT[EVENT_MOUSE_MOVE] = "EVENT_MOUSE_LEAVE"; + EVENT_TYPE_TEXT[EVENT_MOUSE_ENTER] = "EVENT_MOUSE_ENTER"; + EVENT_TYPE_TEXT[EVENT_MOUSE_LEAVE] = "EVENT_MOUSE_LEAVE"; EVENT_TYPE_TEXT[EVENT_KEY_DOWN] = "EVENT_KEY_DOWN"; EVENT_TYPE_TEXT[EVENT_KEY_UP] = "EVENT_KEY_UP"; From 07df35ca011952018a16b9e25504502ce83c128c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 22:54:48 +0200 Subject: [PATCH 008/360] Refactored mouse wheel --- src/app/app.cpp | 10 +++---- src/common/event.h | 6 ++-- src/graphics/engine/camera.cpp | 55 +++++++++++----------------------- src/graphics/engine/camera.h | 2 +- src/ui/controls/edit.cpp | 9 +----- src/ui/controls/editvalue.cpp | 13 ++------ src/ui/controls/list.cpp | 16 ++++------ src/ui/controls/scroll.cpp | 30 +++++++++++-------- src/ui/controls/slider.cpp | 30 +++++++++++-------- 9 files changed, 70 insertions(+), 101 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 94976a72..1ab3caa1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1069,11 +1069,8 @@ Event CApplication::ProcessSystemEvent() event.type = EVENT_MOUSE_WHEEL; auto data = MakeUnique(); - - if (m_private->currentEvent.wheel.y < 0) // TODO: properly use this value - data->dir = WHEEL_DOWN; - else - data->dir = WHEEL_UP; + data->y = m_private->currentEvent.wheel.y; + data->x = m_private->currentEvent.wheel.x; event.data = std::move(data); } @@ -1175,7 +1172,8 @@ void CApplication::LogEvent(const Event &event) case EVENT_MOUSE_WHEEL: { auto data = event.GetData(); - l->Trace(" dir = %s\n", (data->dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); + l->Trace(" y = %d\n", data->y); + l->Trace(" x = %d\n", data->x); break; } case EVENT_JOY_AXIS: diff --git a/src/common/event.h b/src/common/event.h index 0da15182..5b5680a4 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -648,8 +648,10 @@ struct MouseWheelEventData : public EventData return MakeUnique(*this); } - //! Wheel direction - WheelDirection dir = WHEEL_UP; + //! Amount scrolled vertically, positive value is away from the user + signed int y = 0; + //! Amount scrolled horizontally (if the mouse supports it), positive value is to the right + signed int x = 0; }; /** diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index abfac64c..df92d6a8 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1065,7 +1065,7 @@ bool CCamera::EventProcess(const Event &event) break; case EVENT_MOUSE_WHEEL: - EventMouseWheel(event.GetData()->dir); + EventMouseWheel(event.GetData()->y); break; default: @@ -1080,55 +1080,34 @@ bool CCamera::EventMouseMove(const Event &event) return true; } -void CCamera::EventMouseWheel(WheelDirection dir) +void CCamera::EventMouseWheel(int dir) { if (m_type == CAM_TYPE_BACK) { - if (dir == WHEEL_UP) - { - m_backDist -= 8.0f; - if (m_backDist < m_backMin) - m_backDist = m_backMin; - } - else if (dir == WHEEL_DOWN) - { - m_backDist += 8.0f; - if (m_backDist > 200.0f) - m_backDist = 200.0f; - } + m_backDist -= 8.0f*dir; + if (m_backDist < m_backMin) + m_backDist = m_backMin; + if (m_backDist > 200.0f) + m_backDist = 200.0f; } if ( m_type == CAM_TYPE_FIX || m_type == CAM_TYPE_PLANE ) { - if (dir == WHEEL_UP) - { - m_fixDist -= 8.0f; - if (m_fixDist < 10.0f) - m_fixDist = 10.0f; - } - else if (dir == WHEEL_DOWN) - { - m_fixDist += 8.0f; - if (m_fixDist > 200.0f) - m_fixDist = 200.0f; - } + m_fixDist -= 8.0f*dir; + if (m_fixDist < 10.0f) + m_fixDist = 10.0f; + if (m_fixDist > 200.0f) + m_fixDist = 200.0f; } if ( m_type == CAM_TYPE_VISIT ) { - if (dir == WHEEL_UP) - { - m_visitDist -= 8.0f; - if (m_visitDist < 20.0f) - m_visitDist = 20.0f; - } - else if (dir == WHEEL_DOWN) - { - m_visitDist += 8.0f; - if (m_visitDist > 200.0f) - m_visitDist = 200.0f; - } + m_visitDist -= 8.0f*dir; + if (m_visitDist < 20.0f) + m_visitDist = 20.0f; + if (m_visitDist > 200.0f) + m_visitDist = 200.0f; } } diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 10ea6606..52f84cd9 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -226,7 +226,7 @@ protected: //! Changes the camera according to the mouse moved bool EventMouseMove(const Event &event); //! Mouse wheel operation - void EventMouseWheel(WheelDirection dir); + void EventMouseWheel(int dir); //! Changes the camera according to the time elapsed bool EventFrame(const Event &event); //! Moves the point of view diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index a5535757..c2c67782 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -254,14 +254,7 @@ bool CEdit::EventProcess(const Event &event) Detect(event.mousePos)) { auto data = event.GetData(); - if (data->dir == WHEEL_UP) - { - Scroll(m_lineFirst - 3, true); - } - else - { - Scroll(m_lineFirst + 3, true); - } + Scroll(m_lineFirst - data->y, true); return true; } diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index ddd2cf55..48274792 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -184,20 +184,11 @@ bool CEditValue::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && Detect(event.mousePos)) { - float value = GetValue()+m_stepValue; - if ( value > m_maxValue ) value = m_maxValue; - SetValue(value, true); - HiliteValue(event); - } - if ( event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos)) - { - float value = GetValue()-m_stepValue; + float value = GetValue() + (m_stepValue * event.GetData()->y); if ( value < m_minValue ) value = m_minValue; + if ( value > m_maxValue ) value = m_maxValue; SetValue(value, true); HiliteValue(event); } diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 3ad13b99..102e34bc 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -280,16 +280,11 @@ bool CList::EventProcess(const Event &event) if (event.type == EVENT_MOUSE_WHEEL && Detect(event.mousePos)) { auto data = event.GetData(); - if (data->dir == WHEEL_UP) - { - if (m_firstLine > 0) - m_firstLine--; - } - else - { - if (m_firstLine < m_totalLine - m_displayLine) - m_firstLine++; - } + m_firstLine -= data->y; + if (m_firstLine < 0) + m_firstLine = 0; + if (m_firstLine > m_totalLine - m_displayLine) + m_firstLine = m_totalLine - m_displayLine; UpdateScroll(); UpdateButton(); @@ -855,4 +850,3 @@ void CList::MoveScroll() } // namespace Ui - diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 3c939ab3..3ac00ef3 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -273,18 +273,25 @@ bool CScroll::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && - Detect(event.mousePos) && - m_buttonUp != nullptr) + Detect(event.mousePos)) { - m_event->AddEvent(Event(m_buttonUp->GetEventType())); - } - if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos) && - m_buttonDown != nullptr) - { - m_event->AddEvent(Event(m_buttonDown->GetEventType())); + auto data = event.GetData(); + if (data->y > 0) + { + if (m_buttonUp != nullptr) + { + for (int i = 0; i < data->y; i++) + m_event->AddEvent(Event(m_buttonUp->GetEventType())); + } + } + else + { + if (m_buttonDown != nullptr) + { + for (int i = 0; i < -(data->y); i++) + m_event->AddEvent(Event(m_buttonDown->GetEventType())); + } + } } return true; @@ -443,4 +450,3 @@ float CScroll::GetArrowStep() } } // namespace Ui - diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 07079210..dbaf1a69 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -338,19 +338,25 @@ bool CSlider::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_UP && - Detect(event.mousePos) && - m_buttonLeft != nullptr) + Detect(event.mousePos)) { - m_event->AddEvent(Event(m_buttonLeft->GetEventType())); - } - - if (event.type == EVENT_MOUSE_WHEEL && - event.GetData()->dir == WHEEL_DOWN && - Detect(event.mousePos) && - m_buttonRight != nullptr) - { - m_event->AddEvent(Event(m_buttonRight->GetEventType())); + auto data = event.GetData(); + if (data->y > 0) + { + if (m_buttonLeft != nullptr) + { + for (int i = 0; i < data->y; i++) + m_event->AddEvent(Event(m_buttonLeft->GetEventType())); + } + } + else + { + if (m_buttonRight != nullptr) + { + for (int i = 0; i < -(data->y); i++) + m_event->AddEvent(Event(m_buttonRight->GetEventType())); + } + } } return true; From f6823389ccd7b3c43d1146561f51bf0d21b5bbe3 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Sep 2015 23:24:29 +0200 Subject: [PATCH 009/360] Fixed displaying joystick button 0 name, closes #646 --- src/common/restext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 1c1a27fe..c1b8a311 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -876,7 +876,7 @@ bool GetResource(ResType type, unsigned int num, std::string& text) text = "Alt"; else if (num == static_cast(VIRTUAL_KMOD(GUI))) text = "Win"; // TODO: Better description of this key? - else if (num > static_cast(VIRTUAL_JOY(0))) + else if (num >= static_cast(VIRTUAL_JOY(0))) { text = gettext("Button %1"); text = StrUtils::Replace(text, "%1", StrUtils::ToString(1 + num - VIRTUAL_JOY(0))); From 27758dacada9dce2b0f4b879dcc3efd6bb564187 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Sep 2015 14:24:53 +0200 Subject: [PATCH 010/360] MXE build fixes --- cmake/mxe.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmake/mxe.cmake b/cmake/mxe.cmake index 2c24b1bd..03564539 100644 --- a/cmake/mxe.cmake +++ b/cmake/mxe.cmake @@ -12,9 +12,6 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) # All must be static, CBOT and GLEW too set(CBOT_STATIC ON) set(GLEW_STATIC ON) - # Because find package scripts are lame - set(SDLTTF_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL) - set(SDLIMAGE_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL) if (${OPENAL_SOUND}) set(OPENAL_MXE_LIBS @@ -23,7 +20,6 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) ${CMAKE_FIND_ROOT_PATH}/lib/libvorbisenc.a ${CMAKE_FIND_ROOT_PATH}/lib/libvorbisfile.a ${CMAKE_FIND_ROOT_PATH}/lib/libogg.a - ${CMAKE_FIND_ROOT_PATH}/lib/libwsock32.a ) endif() @@ -39,10 +35,18 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) ${CMAKE_FIND_ROOT_PATH}/lib/libwinmm.a ${CMAKE_FIND_ROOT_PATH}/lib/libdxguid.a ${CMAKE_FIND_ROOT_PATH}/lib/libbz2.a + ${CMAKE_FIND_ROOT_PATH}/lib/libimm32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libole32.a + ${CMAKE_FIND_ROOT_PATH}/lib/liboleaut32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libharfbuzz.a + ${CMAKE_FIND_ROOT_PATH}/lib/libwebp.a + ${CMAKE_FIND_ROOT_PATH}/lib/libversion.a + ${CMAKE_FIND_ROOT_PATH}/lib/libglib-2.0.a + ${CMAKE_FIND_ROOT_PATH}/lib/libwsock32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libws2_32.a + ${CMAKE_FIND_ROOT_PATH}/lib/libintl.a ${OPENAL_MXE_LIBS} ) - # This fixes problem with multiple definition of `IID_IDirectSoundNotify' - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition") else() set(MXE 0) endif() From 24c16744340e660b7b8e380fba2fec0b4174d9a8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Sep 2015 14:46:26 +0200 Subject: [PATCH 011/360] Updated install instructions for SDL2 --- INSTALL-MXE.md | 34 +++++++++++++++++++++++----------- INSTALL.md | 8 ++++---- README.md | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/INSTALL-MXE.md b/INSTALL-MXE.md index d4b0bff7..addbbaab 100644 --- a/INSTALL-MXE.md +++ b/INSTALL-MXE.md @@ -18,40 +18,52 @@ To cross-compile Colobot using MXE: It already contains a universal Makefile for everything. Usage is simply `make name_of_package`. It will automatically check for dependencies, etc. - The packages will be installed in the MXE directory under `usr/`. + The packages will be installed in the MXE directory under `usr/i686-w64-mingw32.static`. You need to `make gcc` first for basic compiler and then do the same for some additional libraries. In the end, you should have the following - packages installed (this is the final listing of `usr/installed/`): + packages installed (this is the final listing of `usr/i686-w64-mingw32.static/installed/`): * binutils * boost * bzip2 - * check-requirements + * cairo + * dbus * expat * flac + * fontconfig * freetype + * freetype-bootstrap * gcc * gcc-gmp + * gcc-isl * gcc-mpc * gcc-mpfr * gettext * glew + * glib + * harfbuzz + * icu4c * jpeg + * libffi * libiconv * libpng * libsndfile - * libtool - * mingwrt + * libwebp + * lzo + * mingw-w64 + * mxe-conf * ogg * openal + * pcre * physfs + * pixman + * pkgconf * portaudio - * sdl - * sdl_image - * sdl_ttf + * sdl2 + * sdl2_image + * sdl2_ttf * tiff * vorbis - * w32api * xz * zlib @@ -60,7 +72,7 @@ To cross-compile Colobot using MXE: `mkdir build-mxe && cd build-mxe` In order to cross-compile a CMake project, you have to specify a CMake toolchain file. - MXE has such file in MXE's directory: `usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake` + MXE has such file in MXE's directory: `usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake` So you should use the following cmake command: `cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe-conf.cmake ..` CMake files in Colobot should detect that MXE is being used and they will modify flags, paths, etc. as required. You should not run into any problems. @@ -74,6 +86,6 @@ To cross-compile Colobot using MXE: 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 - in MXE's directory under `usr/i686-pc-mingw32/bin`. + in MXE's directory under `usr/i686-w64-mingw32.static/bin`. This will create a versioned colobot-$version.exe installer that will install Colobot in system directories, add a shortcut in the start menu and setup an uninstaller. diff --git a/INSTALL.md b/INSTALL.md index fed781dd..47c79977 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -56,9 +56,9 @@ You will need: * recent compiler (GCC >= 4.7, or Clang >= 3.1) since we are using some features of C++11 * CMake >= 2.8 * Boost >= 1.51 (header files + components: filesystem and regex) - * SDL >= 1.2.10 - * SDL_image >= 1.2 - * SDL_ttf >= 2.0 + * SDL2 + * SDL2_image + * SDL2_ttf * GLEW >= 1.8.0 * libpng >= 1.2 * gettext >= 0.18 @@ -72,7 +72,7 @@ You will need: On Ubuntu (and probably any other Debian-based system), you can use the following command to install all required packages: ``` - $ apt-get install build-essential cmake libsdl1.2debian libsdl1.2-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools + $ apt-get install build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng12-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools ``` Make sure you install the packages along with header files (often distributed in separate *-dev packages). If you miss any requirements, diff --git a/README.md b/README.md index 3ec51944..be44f545 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# English +# Colobot: Gold Edition Welcome to the Colobot: Gold Edition project code repository From 377a331e2a8495b85debc0fce477f76ecf8ea150 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Sep 2015 14:58:43 +0200 Subject: [PATCH 012/360] Forgot to clean this up --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df49cd69..b8d69879 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,10 +41,10 @@ elseif(PLATFORM_WINDOWS) set(PLATFORM_LIBS "-lintl") endif() elseif(PLATFORM_GNU) - #set(PLATFORM_LIBS "-lX11") + set(PLATFORM_LIBS "") elseif(PLATFORM_LINUX) # for clock_gettime - set(PLATFORM_LIBS "-lrt") # -lX11") + set(PLATFORM_LIBS "-lrt") elseif(PLATFORM_MACOSX) find_library(LIBINTL_LIBRARY NAMES intl libintl) find_path(LIBINTL_INCLUDE_PATH NAMES libintl.h) From 4dc7a301eb52ea191bd790b414ba41a100bd3952 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Sep 2015 21:03:17 +0200 Subject: [PATCH 013/360] Always reverse forward/backward and up/down axes on a joypad --- src/app/input.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/input.cpp b/src/app/input.cpp index 1ffecf84..ff75d917 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -171,14 +171,14 @@ void CInput::EventProcess(Event& event) if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis) { - m_joyMotion.y = Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); + m_joyMotion.y = -Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); if (GetJoyAxisBinding(JOY_AXIS_SLOT_Y).invert) m_joyMotion.y *= -1.0f; } if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis) { - m_joyMotion.z = Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); + m_joyMotion.z = -Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); if (GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert) m_joyMotion.z *= -1.0f; } From fd07589ebb0d89162322194e1bf556c7162b7ed7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 26 Sep 2015 21:12:12 +0200 Subject: [PATCH 014/360] Separated config.h and version.h This prevents unnecessary recompilation of some files when version number changes --- src/CMakeLists.txt | 1 + src/app/app.cpp | 2 +- src/app/main.cpp | 1 + src/app/signal_handlers.cpp | 2 +- src/common/config.h.cmake | 5 ----- src/common/version.h.cmake | 6 ++++++ src/ui/screen/screen.cpp | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 src/common/version.h.cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8d69879..5e445a98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ endif() # Configure file configure_file(common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h) +configure_file(common/version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/version.h) set(OPENAL_SRC "") diff --git a/src/app/app.cpp b/src/app/app.cpp index 1ab3caa1..502e60a4 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -19,7 +19,7 @@ #include "app/app.h" -#include "common/config.h" +#include "common/version.h" #include "app/controller.h" #include "app/input.h" diff --git a/src/app/main.cpp b/src/app/main.cpp index b732adf1..cf0283ca 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,6 +23,7 @@ */ #include "common/config.h" +#include "common/version.h" #include "app/app.h" #include "app/signal_handlers.h" diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index d2a7bf52..f00a8d84 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -19,7 +19,7 @@ #include "app/signal_handlers.h" -#include "common/config.h" +#include "common/version.h" #include "common/resources/resourcemanager.h" diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 05af962f..2d3dbe1e 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -26,10 +26,5 @@ #cmakedefine PORTABLE @PORTABLE@ -#define COLOBOT_FULLNAME "Colobot: Gold Edition @COLOBOT_VERSION_FULL@" -#define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@" - #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" - -#define BUILD_NUMBER @BUILD_NUMBER@ diff --git a/src/common/version.h.cmake b/src/common/version.h.cmake new file mode 100644 index 00000000..5749421e --- /dev/null +++ b/src/common/version.h.cmake @@ -0,0 +1,6 @@ +#pragma once + +#define COLOBOT_FULLNAME "Colobot: Gold Edition @COLOBOT_VERSION_FULL@" +#define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@" + +#define BUILD_NUMBER @BUILD_NUMBER@ diff --git a/src/ui/screen/screen.cpp b/src/ui/screen/screen.cpp index 6eb508a8..7adc5df8 100644 --- a/src/ui/screen/screen.cpp +++ b/src/ui/screen/screen.cpp @@ -19,7 +19,7 @@ #include "ui/screen/screen.h" -#include "common/config.h" +#include "common/version.h" #include "app/app.h" From 6a6025f55783ad4b37a2f79f120a31208919177e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 27 Sep 2015 00:34:03 +0200 Subject: [PATCH 015/360] Implemented force feedback --- src/app/app.cpp | 43 ++++++++++++++++++++++++++++++++++ src/app/app.h | 5 ++++ src/graphics/engine/camera.cpp | 21 +++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/app/app.cpp b/src/app/app.cpp index 502e60a4..6186e9b2 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -91,6 +91,8 @@ struct ApplicationPrivate SDL_Joystick *joystick; //! Id of joystick timer SDL_TimerID joystickTimer; + //! Haptic subsystem for the joystick + SDL_Haptic *haptic; ApplicationPrivate() { @@ -100,6 +102,7 @@ struct ApplicationPrivate glcontext = nullptr; joystick = nullptr; joystickTimer = 0; + haptic = nullptr; } }; @@ -516,6 +519,10 @@ bool CApplication::Create() { GetLogger()->Warn("Joystick subsystem init failed\nJoystick(s) will not be available\n"); } + if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) + { + GetLogger()->Warn("Joystick haptic subsystem init failed\nForce feedback will not be available\n"); + } if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0) { @@ -725,6 +732,20 @@ bool CApplication::OpenJoystick() // Create a timer for polling joystick state m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, nullptr); + // Initialize haptic subsystem + m_private->haptic = SDL_HapticOpenFromJoystick(m_private->joystick); + if (m_private->haptic == nullptr) + { + GetLogger()->Warn("Haptic subsystem open failed\n"); + return true; + } + + if (SDL_HapticRumbleInit(m_private->haptic) != 0) + { + GetLogger()->Warn("Haptic rumble effect init failed\n"); + return true; + } + return true; } @@ -734,6 +755,11 @@ void CApplication::CloseJoystick() GetLogger()->Info("Closing joystick\n"); + StopForceFeedbackEffect(); + + SDL_HapticClose(m_private->haptic); + m_private->haptic = nullptr; + SDL_JoystickClose(m_private->joystick); m_private->joystick = nullptr; } @@ -1784,3 +1810,20 @@ void CApplication::SetTextInput(bool textInputEnabled) SDL_StopTextInput(); } } + +void CApplication::PlayForceFeedbackEffect(float strength, int length) +{ + if (m_private->haptic == nullptr) return; + + GetLogger()->Trace("Force feedback! length = %d ms, strength = %.2f\n", length, strength); + if (SDL_HapticRumblePlay(m_private->haptic, strength, length) != 0) + { + GetLogger()->Debug("Failed to play haptic effect\n"); + } +} + +void CApplication::StopForceFeedbackEffect() +{ + if (m_private->haptic == nullptr) return; + SDL_HapticRumbleStop(m_private->haptic); +} diff --git a/src/app/app.h b/src/app/app.h index e8294813..962bf30c 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -314,6 +314,11 @@ public: //! Renders the image in window if needed void RenderIfNeeded(int updateRate); + //! Starts a force feedback effect on the joystick + void PlayForceFeedbackEffect(float strength = 1.0f, int length = 999999); + //! Stops a force feedback effect on the joystick + void StopForceFeedbackEffect(); + protected: //! Creates the window's SDL_Surface bool CreateVideoSurface(); diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index df92d6a8..400b256b 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -570,6 +570,8 @@ void CCamera::FlushEffect() m_effectForce = 0.0f; m_effectProgress = 0.0f; m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); + + CApplication::GetInstancePointer()->StopForceFeedbackEffect(); } void CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) @@ -655,6 +657,25 @@ void CCamera::EffectFrame(const Event &event) force *= 1.0f-dist; m_effectOffset *= force; + float forceFeedback = force; + if (m_effectType == CAM_EFFECT_VIBRATION) + { + forceFeedback *= 0.5f; + } + if (m_effectType == CAM_EFFECT_PET) + { + forceFeedback *= 0.75f; + } + if (m_effectType == CAM_EFFECT_EXPLO) + { + forceFeedback *= 3.0f; + } + if (forceFeedback > 1.0f) forceFeedback = 1.0f; + if (forceFeedback >= 0.1f) + { + CApplication::GetInstancePointer()->PlayForceFeedbackEffect(forceFeedback); + } + if (m_effectProgress >= 1.0f) FlushEffect(); } From 66ce745be0e13d626469d6d59e433d0266d61c2b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 27 Sep 2015 16:28:11 +0200 Subject: [PATCH 016/360] Introduce forward declarations as suggested by colobot-lint --- src/app/input.h | 5 +- src/graphics/core/device.h | 19 +++++-- src/graphics/core/nulldevice.h | 6 ++- src/graphics/engine/camera.cpp | 8 ++- src/graphics/engine/camera.h | 6 +-- src/graphics/engine/engine.cpp | 1 + src/graphics/engine/engine.h | 1 - src/graphics/engine/lightman.h | 4 +- src/graphics/engine/oldmodelmanager.h | 1 - src/graphics/engine/pyro.h | 3 +- src/graphics/engine/terrain.h | 2 +- src/graphics/engine/water.h | 4 +- src/graphics/model/model_mesh.h | 2 - src/graphics/opengl/gl21device.cpp | 2 + src/graphics/opengl/gl21device.h | 6 ++- src/graphics/opengl/gl33device.cpp | 2 + src/graphics/opengl/gl33device.h | 4 ++ src/graphics/opengl/gldevice.cpp | 2 + src/graphics/opengl/gldevice.h | 6 ++- src/level/mainmovie.h | 6 +-- src/level/robotmain.cpp | 1 + src/level/robotmain.h | 1 + src/object/auto/auto.h | 8 ++- src/object/auto/autolabo.h | 2 - .../implementation/power_container_impl.h | 1 - src/object/interface/programmable_object.h | 4 +- src/object/interface/task_executor_object.h | 2 - src/object/motion/motion.h | 7 +-- src/object/motion/motionlevelcontroller.cpp | 2 - src/object/motion/motiontoto.h | 2 +- src/object/object.h | 2 +- src/object/old_object.h | 2 + src/object/old_object_interface.cpp | 1 - src/object/old_object_interface.h | 5 +- src/object/task/task.h | 4 +- src/object/task/taskgoto.h | 6 ++- src/object/task/tasktake.h | 3 +- src/physics/physics.h | 3 +- src/sound/oalsound/channel.cpp | 2 + src/sound/oalsound/channel.h | 31 ++++++------ src/sound/sound.h | 7 ++- src/ui/controls/check.h | 8 +-- src/ui/controls/color.h | 7 +-- src/ui/controls/editvalue.h | 8 +-- src/ui/controls/group.h | 12 +---- src/ui/controls/image.h | 10 +--- src/ui/controls/interface.cpp | 19 +++++++ src/ui/controls/interface.h | 50 ++++++++++--------- src/ui/controls/label.h | 4 +- src/ui/controls/list.h | 2 - src/ui/controls/scroll.h | 3 +- src/ui/controls/target.h | 12 ++--- src/ui/controls/window.cpp | 20 +++++++- src/ui/controls/window.h | 39 ++++++++------- src/ui/displayinfo.h | 5 +- src/ui/maindialog.cpp | 1 + src/ui/maindialog.h | 8 +-- src/ui/mainmap.cpp | 6 +++ src/ui/mainmap.h | 13 +++-- src/ui/mainshort.cpp | 3 ++ src/ui/mainshort.h | 15 ++++-- src/ui/mainui.cpp | 1 + src/ui/mainui.h | 2 +- src/ui/object_interface.cpp | 8 +++ src/ui/object_interface.h | 1 - src/ui/screen/screen_apperance.cpp | 2 + src/ui/screen/screen_io.cpp | 3 ++ src/ui/screen/screen_io_read.cpp | 2 + src/ui/screen/screen_io_write.cpp | 2 + src/ui/screen/screen_loading.cpp | 1 + src/ui/screen/screen_main_menu.cpp | 1 + src/ui/screen/screen_main_menu.h | 2 - src/ui/screen/screen_player_select.cpp | 3 ++ src/ui/screen/screen_quit.cpp | 2 + src/ui/screen/screen_setup.cpp | 1 + src/ui/screen/screen_setup_controls.cpp | 1 + src/ui/screen/screen_setup_controls.h | 7 --- src/ui/screen/screen_setup_display.cpp | 1 + src/ui/screen/screen_setup_display.h | 7 --- src/ui/screen/screen_setup_game.cpp | 1 + src/ui/screen/screen_setup_game.h | 7 --- src/ui/screen/screen_setup_graphics.cpp | 1 + src/ui/screen/screen_setup_graphics.h | 7 --- src/ui/screen/screen_setup_sound.cpp | 1 + src/ui/screen/screen_setup_sound.h | 7 --- src/ui/studio.cpp | 2 + src/ui/studio.h | 3 +- 87 files changed, 276 insertions(+), 231 deletions(-) diff --git a/src/app/input.h b/src/app/input.h index 2fcee839..771267b8 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -24,14 +24,17 @@ #pragma once -#include "common/event.h" #include "common/key.h" #include "common/singleton.h" #include "math/intpoint.h" +#include "math/point.h" +#include "math/vector.h" #include +struct Event; + /** * \struct InputBinding * \brief Binding for input slot diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 5c1acdcb..36ba9580 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -25,14 +25,9 @@ #pragma once #include "graphics/core/color.h" -#include "graphics/core/framebuffer.h" -#include "graphics/core/light.h" -#include "graphics/core/material.h" #include "graphics/core/texture.h" -#include "graphics/core/vertex.h" #include "math/intpoint.h" -#include "math/matrix.h" #include #include @@ -41,11 +36,25 @@ class CImage; struct ImageData; +namespace Math +{ +struct Matrix; +struct Vector; +} // namespace Math + // Graphics module namespace namespace Gfx { +class CFramebuffer; +struct FramebufferParams; +struct Light; +struct Material; +struct Vertex; +struct VertexCol; +struct VertexTex2; + /** * \struct DeviceConfig * \brief General config for graphics device diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h index 7395261e..3ca387ba 100644 --- a/src/graphics/core/nulldevice.h +++ b/src/graphics/core/nulldevice.h @@ -24,9 +24,13 @@ #pragma once - #include "graphics/core/device.h" +#include "graphics/core/light.h" +#include "graphics/core/material.h" + +#include "math/matrix.h" + // Graphics module namespace namespace Gfx { diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 400b256b..62e6edb9 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -23,6 +23,8 @@ #include "app/app.h" #include "app/input.h" +#include "common/event.h" + #include "graphics/engine/engine.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" @@ -1086,7 +1088,7 @@ bool CCamera::EventProcess(const Event &event) break; case EVENT_MOUSE_WHEEL: - EventMouseWheel(event.GetData()->y); + EventMouseWheel(event); break; default: @@ -1101,8 +1103,10 @@ bool CCamera::EventMouseMove(const Event &event) return true; } -void CCamera::EventMouseWheel(int dir) +void CCamera::EventMouseWheel(const Event &event) { + auto dir = event.GetData()->y; + if (m_type == CAM_TYPE_BACK) { m_backDist -= 8.0f*dir; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 52f84cd9..453f9947 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -24,15 +24,13 @@ #pragma once - -#include "common/event.h" - #include "graphics/engine/engine.h" class CObject; class CRobotMain; class CInput; +struct Event; // Graphics module namespace @@ -226,7 +224,7 @@ protected: //! Changes the camera according to the mouse moved bool EventMouseMove(const Event &event); //! Mouse wheel operation - void EventMouseWheel(int dir); + void EventMouseWheel(const Event& event); //! Changes the camera according to the time elapsed bool EventFrame(const Event &event); //! Moves the point of view diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7cb4ed3e..daa0f39d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -34,6 +34,7 @@ #include "common/thread/resource_owning_thread.h" #include "graphics/core/device.h" +#include "graphics/core/framebuffer.h" #include "graphics/engine/camera.h" #include "graphics/engine/cloud.h" diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 3d5fbbe5..67f2c408 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -46,7 +46,6 @@ class CApplication; -class CObject; class CSoundInterface; class CImage; class CPauseManager; diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 53f3d41b..9d1eb5ea 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -24,8 +24,6 @@ #pragma once - -#include "graphics/core/color.h" #include "graphics/core/light.h" #include "graphics/engine/engine.h" @@ -37,6 +35,8 @@ namespace Gfx { +struct Color; + /** * \struct LightProgression * \brief Describes the progression of light parameters change diff --git a/src/graphics/engine/oldmodelmanager.h b/src/graphics/engine/oldmodelmanager.h index 08bee6da..64cbb681 100644 --- a/src/graphics/engine/oldmodelmanager.h +++ b/src/graphics/engine/oldmodelmanager.h @@ -31,7 +31,6 @@ namespace Gfx { class CEngine; -class CModelFile; /** * \class COldModelManager diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index b90a0b94..2289b78f 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -25,7 +25,6 @@ #pragma once -#include "common/event.h" #include "common/error.h" #include "graphics/core/color.h" @@ -41,6 +40,7 @@ class CObject; class CRobotMain; class CSoundInterface; +struct Event; // Graphics module namespace @@ -51,7 +51,6 @@ class CEngine; class CTerrain; class CCamera; class CParticle; -class CLight; class CLightManager; /** diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 3b182648..3235f401 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -24,7 +24,6 @@ #pragma once -#include "graphics/core/material.h" #include "graphics/core/vertex.h" #include "math/const.h" @@ -41,6 +40,7 @@ namespace Gfx class CEngine; class CWater; +struct Material; //! Limit of slope considered a flat piece of land diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 77ce8da9..2be10447 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -24,13 +24,11 @@ #pragma once - -#include "common/event.h" - #include "graphics/engine/particle.h" class CSoundInterface; +struct Event; // Graphics module namespace diff --git a/src/graphics/model/model_mesh.h b/src/graphics/model/model_mesh.h index 4908e722..fa52d3fa 100644 --- a/src/graphics/model/model_mesh.h +++ b/src/graphics/model/model_mesh.h @@ -28,8 +28,6 @@ namespace Gfx { -struct ModelTriangle; - /** * \class CModelMesh * \brief Mesh data saved in model file diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index 1c63deb6..1a86fade 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -26,6 +26,8 @@ #include "common/image.h" #include "common/logger.h" +#include "graphics/core/light.h" + #include "graphics/engine/engine.h" #include "graphics/opengl/glframebuffer.h" diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index c6d1c8ad..9e8a18f6 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -26,8 +26,12 @@ #include "graphics/core/device.h" +#include "graphics/core/material.h" + #include "graphics/opengl/glutil.h" +#include "math/matrix.h" + #include #include #include @@ -38,8 +42,6 @@ namespace Gfx { -struct GLDevicePrivate; - /** \class CGL21Device \brief Implementation of CDevice interface in OpenGL diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index a3cc6254..1246564d 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -26,6 +26,8 @@ #include "common/logger.h" #include "common/make_unique.h" +#include "graphics/core/light.h" + #include "graphics/engine/engine.h" #include "graphics/opengl/glframebuffer.h" diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index 2e6382f8..b872bb0c 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -26,9 +26,13 @@ #include "graphics/core/device.h" +#include "graphics/core/material.h" + #include "graphics/opengl/glframebuffer.h" #include "graphics/opengl/glutil.h" +#include "math/matrix.h" + #include #include #include diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index f283a0aa..6070acdf 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -25,6 +25,8 @@ #include "common/image.h" #include "common/logger.h" +#include "graphics/core/light.h" + #include "graphics/engine/engine.h" #include "graphics/opengl/glframebuffer.h" diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index f510e6b8..664bdc51 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -26,9 +26,13 @@ #include "graphics/core/device.h" +#include "graphics/core/material.h" + #include "graphics/opengl/glframebuffer.h" #include "graphics/opengl/glutil.h" +#include "math/matrix.h" + #include #include #include @@ -57,8 +61,6 @@ enum ShadowMappingSupport SMS_CORE //! Core support }; -struct GLDevicePrivate; - /** \class CGLDevice \brief Implementation of CDevice interface in OpenGL diff --git a/src/level/mainmovie.h b/src/level/mainmovie.h index 81d5113c..955e6f78 100644 --- a/src/level/mainmovie.h +++ b/src/level/mainmovie.h @@ -24,20 +24,18 @@ #pragma once - -#include "common/event.h" - #include "math/vector.h" class CRobotMain; class CSoundInterface; +struct Event; namespace Gfx { class CCamera; class CEngine; -} +} // namespace Gfx enum MainMovieType { diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 674fca40..98da4e84 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -95,6 +95,7 @@ #include "ui/controls/button.h" #include "ui/controls/edit.h" +#include "ui/controls/group.h" #include "ui/controls/interface.h" #include "ui/controls/label.h" #include "ui/controls/map.h" diff --git a/src/level/robotmain.h b/src/level/robotmain.h index dbe319b5..9ce4a1b7 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -27,6 +27,7 @@ #include "app/pausemanager.h" #include "common/error.h" +#include "common/event.h" #include "common/singleton.h" #include "level/build_type.h" diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index a305a61b..c685e261 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -35,22 +35,20 @@ namespace Ui { class CInterface; class CWindow; -} /* Ui */ +} // namespace Ui namespace Gfx { class CEngine; class CParticle; -class CLightManager; -class CTarrain; +class CTerrain; class CWater; class CCloud; class CCamera; class CPlanet; class CLightning; -class CTerrain; -} /* Gfx */ +} // namespace Gfx class CAuto diff --git a/src/object/auto/autolabo.h b/src/object/auto/autolabo.h index 83fbee8e..5723bb24 100644 --- a/src/object/auto/autolabo.h +++ b/src/object/auto/autolabo.h @@ -25,8 +25,6 @@ #include "level/research_type.h" -class CPoweredObject; - enum AutoLaboPhase { ALAP_WAIT = 1, diff --git a/src/object/implementation/power_container_impl.h b/src/object/implementation/power_container_impl.h index a20c8e2f..2392c422 100644 --- a/src/object/implementation/power_container_impl.h +++ b/src/object/implementation/power_container_impl.h @@ -21,7 +21,6 @@ #include "object/interface/power_container_object.h" -class CObject; class CPowerContainerObjectImpl : public CPowerContainerObject { diff --git a/src/object/interface/programmable_object.h b/src/object/interface/programmable_object.h index 2affb795..0c44421c 100644 --- a/src/object/interface/programmable_object.h +++ b/src/object/interface/programmable_object.h @@ -21,12 +21,12 @@ #include "object/object_interface_type.h" -#include "object/interface/program_storage_object.h" - #include #include #include +struct Program; + /** * \class CProgrammableObject * \brief Interface for programmable objects diff --git a/src/object/interface/task_executor_object.h b/src/object/interface/task_executor_object.h index ece8cd6e..8b33d9ad 100644 --- a/src/object/interface/task_executor_object.h +++ b/src/object/interface/task_executor_object.h @@ -29,8 +29,6 @@ #include "object/task/taskmanip.h" #include "object/task/taskshield.h" -class CTask; - /** * \class CTaskExecutorObject * \brief Interface for objects that can execute tasks diff --git a/src/object/motion/motion.h b/src/object/motion/motion.h index 1a206158..c0d8225b 100644 --- a/src/object/motion/motion.h +++ b/src/object/motion/motion.h @@ -19,10 +19,10 @@ #pragma once - -#include "common/event.h" #include "common/error.h" +#include "math/vector.h" + #include "object/object_type.h" namespace Gfx @@ -33,7 +33,7 @@ class CTerrain; class CWater; class CCamera; class COldModelManager; -} +} // namespace Gfx class CApplication; class CPhysics; @@ -41,6 +41,7 @@ class COldObject; class CRobotMain; class CSoundInterface; class CLevelParserLine; +struct Event; class CMotion diff --git a/src/object/motion/motionlevelcontroller.cpp b/src/object/motion/motionlevelcontroller.cpp index 494f2aa5..d8cd11d1 100644 --- a/src/object/motion/motionlevelcontroller.cpp +++ b/src/object/motion/motionlevelcontroller.cpp @@ -20,8 +20,6 @@ #include "object/motion/motionlevelcontroller.h" -#include "graphics/engine/oldmodelmanager.h" - #include "object/old_object.h" #include "physics/physics.h" diff --git a/src/object/motion/motiontoto.h b/src/object/motion/motiontoto.h index e5460f69..2325b01a 100644 --- a/src/object/motion/motiontoto.h +++ b/src/object/motion/motiontoto.h @@ -19,9 +19,9 @@ #pragma once - #include "object/motion/motion.h" +#include "math/point.h" enum MotionTotoAction diff --git a/src/object/object.h b/src/object/object.h index 03baceb5..be71b46f 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -25,9 +25,9 @@ #pragma once #include "object/crash_sphere.h" +#include "object/object_create_params.h" #include "object/object_interface_type.h" #include "object/old_object_interface.h" -#include "object/object_create_params.h" #include diff --git a/src/object/old_object.h b/src/object/old_object.h index 513892e5..a44458b4 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -24,6 +24,8 @@ #pragma once +#include "common/event.h" + #include "object/object.h" #include "object/interface/carrier_object.h" diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index 9e47c2eb..eee183cf 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -21,7 +21,6 @@ #include - void COldObjectInterface::Simplify() { throw std::logic_error("Simplify: not implemented!"); diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index 22f50fdb..b8e55581 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -24,11 +24,14 @@ #pragma once -#include "math/matrix.h" #include "math/vector.h" #include "object/object_type.h" +namespace Math +{ +struct Matrix; +} // namespace Math class CAuto; diff --git a/src/object/task/task.h b/src/object/task/task.h index 671b02a0..7d0552ef 100644 --- a/src/object/task/task.h +++ b/src/object/task/task.h @@ -19,8 +19,6 @@ #pragma once - -#include "common/event.h" #include "common/error.h" #include "math/const.h" @@ -32,7 +30,7 @@ class COldObject; class CProgrammableObject; class CRobotMain; class CSoundInterface; - +struct Event; namespace Gfx { diff --git a/src/object/task/taskgoto.h b/src/object/task/taskgoto.h index e49f7830..80536209 100644 --- a/src/object/task/taskgoto.h +++ b/src/object/task/taskgoto.h @@ -19,13 +19,17 @@ #pragma once - #include "object/task/task.h" #include "math/vector.h" #include +namespace Math +{ +struct Point; +} // namespace Math; + class CObject; diff --git a/src/object/task/tasktake.h b/src/object/task/tasktake.h index fa7c2b8f..7d994f54 100644 --- a/src/object/task/tasktake.h +++ b/src/object/task/tasktake.h @@ -19,9 +19,10 @@ #pragma once - #include "object/task/task.h" +#include "math/vector.h" + #include "object/object_type.h" diff --git a/src/physics/physics.h b/src/physics/physics.h index 3b63b4b1..d6f987c0 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -46,12 +46,11 @@ namespace Gfx { class CCamera; class CEngine; -class CLight; class CParticle; class CTerrain; class CWater; class CLightManager; -} +} // namespace Gfx enum PhysicsMode diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index f86c5332..4b3b5593 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -20,6 +20,8 @@ #include "sound/oalsound/channel.h" +#include "sound/oalsound/buffer.h" + Channel::Channel() : m_buffer(nullptr), m_source(0), diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index eb499bd2..b6050062 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -24,9 +24,10 @@ #pragma once +#include "math/vector.h" + #include "sound/sound.h" -#include "sound/oalsound/buffer.h" #include "sound/oalsound/check.h" #include @@ -36,6 +37,8 @@ #include #include +class Buffer; + struct SoundOper { float finalAmplitude = 0.0f; @@ -56,47 +59,47 @@ public: bool Pause(); bool Stop(); - bool SetPosition(const Math::Vector &); + bool SetPosition(const Math::Vector &pos); - bool SetFrequency(float); + bool SetFrequency(float freq); float GetFrequency(); float GetCurrentTime(); - void SetCurrentTime(float); + void SetCurrentTime(float current); float GetDuration(); - bool SetVolume(float); + bool SetVolume(float vol); float GetVolume(); - void SetVolumeAtrib(float); + void SetVolumeAtrib(float volume); float GetVolumeAtrib(); bool IsPlaying(); bool IsReady(); bool IsLoaded(); - bool SetBuffer(Buffer *); + bool SetBuffer(Buffer *buffer); bool HasEnvelope(); SoundOper& GetEnvelope(); void PopEnvelope(); int GetPriority(); - void SetPriority(int); + void SetPriority(int pri); - void SetStartAmplitude(float); - void SetStartFrequency(float); - void SetChangeFrequency(float); + void SetStartAmplitude(float gain); + void SetStartFrequency(float freq); + void SetChangeFrequency(float freq); float GetStartAmplitude(); float GetStartFrequency(); float GetChangeFrequency(); float GetInitFrequency(); - void AddOper(SoundOper); + void AddOper(SoundOper oper); void ResetOper(); SoundType GetSoundType(); - void SetLoop(bool); - void Mute(bool); + void SetLoop(bool loop); + void Mute(bool mute); bool IsMuted(); void Reset(); diff --git a/src/sound/sound.h b/src/sound/sound.h index e378aa86..cb37e08b 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -24,12 +24,15 @@ #pragma once -#include "math/vector.h" - #include "sound/sound_type.h" #include +namespace Math +{ +struct Vector; +} // namespace Math + /*! * Maximum possible audio volume */ diff --git a/src/ui/controls/check.h b/src/ui/controls/check.h index 8bef2eb4..c4341e45 100644 --- a/src/ui/controls/check.h +++ b/src/ui/controls/check.h @@ -21,12 +21,6 @@ #include "ui/controls/control.h" - -namespace Gfx -{ -class CEngine; -} - namespace Ui { @@ -43,4 +37,4 @@ public: void Draw() override; }; -} +} // namespace Ui diff --git a/src/ui/controls/color.h b/src/ui/controls/color.h index 9bb285a9..9b489dfc 100644 --- a/src/ui/controls/color.h +++ b/src/ui/controls/color.h @@ -21,12 +21,7 @@ #include "ui/controls/control.h" - -namespace Gfx -{ -class CEngine; -struct Color; -} +#include "graphics/core/color.h" namespace Ui { diff --git a/src/ui/controls/editvalue.h b/src/ui/controls/editvalue.h index c11b36b3..acac7542 100644 --- a/src/ui/controls/editvalue.h +++ b/src/ui/controls/editvalue.h @@ -19,16 +19,10 @@ #pragma once - #include "ui/controls/control.h" #include -namespace Gfx -{ -class CEngine; -} - namespace Ui { @@ -91,4 +85,4 @@ protected: }; -} +} // namespace Ui diff --git a/src/ui/controls/group.h b/src/ui/controls/group.h index e6746206..bfb59f49 100644 --- a/src/ui/controls/group.h +++ b/src/ui/controls/group.h @@ -19,14 +19,8 @@ #pragma once - #include "ui/controls/control.h" -namespace Gfx -{ -class CEngine; -} - namespace Ui { @@ -41,11 +35,7 @@ public: bool EventProcess(const Event &event) override; void Draw() override; - -protected: - -protected: }; -} +} // namespace Ui diff --git a/src/ui/controls/image.h b/src/ui/controls/image.h index 1d8a697c..7b1bd4b5 100644 --- a/src/ui/controls/image.h +++ b/src/ui/controls/image.h @@ -19,15 +19,8 @@ #pragma once - #include "ui/controls/control.h" -namespace Gfx -{ -class CEngine; -} - - namespace Ui { @@ -49,5 +42,4 @@ protected: std::string m_filename; }; - -} +} // namespace Ui diff --git a/src/ui/controls/interface.cpp b/src/ui/controls/interface.cpp index 939bd0b4..3d8c1aca 100644 --- a/src/ui/controls/interface.cpp +++ b/src/ui/controls/interface.cpp @@ -24,6 +24,25 @@ #include "level/robotmain.h" +#include "ui/controls/button.h" +#include "ui/controls/check.h" +#include "ui/controls/color.h" +#include "ui/controls/control.h" +#include "ui/controls/edit.h" +#include "ui/controls/editvalue.h" +#include "ui/controls/enumslider.h" +#include "ui/controls/group.h" +#include "ui/controls/image.h" +#include "ui/controls/key.h" +#include "ui/controls/label.h" +#include "ui/controls/list.h" +#include "ui/controls/map.h" +#include "ui/controls/scroll.h" +#include "ui/controls/shortcut.h" +#include "ui/controls/slider.h" +#include "ui/controls/target.h" +#include "ui/controls/window.h" + #include diff --git a/src/ui/controls/interface.h b/src/ui/controls/interface.h index 39474a23..93131472 100644 --- a/src/ui/controls/interface.h +++ b/src/ui/controls/interface.h @@ -20,39 +20,41 @@ #pragma once #include "common/event.h" -#include "common/misc.h" - -#include "graphics/engine/camera.h" -#include "graphics/engine/engine.h" #include "math/point.h" -#include "ui/controls/button.h" -#include "ui/controls/check.h" -#include "ui/controls/color.h" -#include "ui/controls/control.h" -#include "ui/controls/edit.h" -#include "ui/controls/editvalue.h" -#include "ui/controls/enumslider.h" -#include "ui/controls/group.h" -#include "ui/controls/image.h" -#include "ui/controls/key.h" -#include "ui/controls/label.h" -#include "ui/controls/list.h" -#include "ui/controls/map.h" -#include "ui/controls/scroll.h" -#include "ui/controls/shortcut.h" -#include "ui/controls/slider.h" -#include "ui/controls/target.h" -#include "ui/controls/window.h" - +#include #include #include -#include + +namespace Gfx +{ +class CCamera; +class CEngine; +} // namespace Gfx namespace Ui { +class CButton; +class CCheck; +class CColor; +class CControl; +class CEdit; +class CEditValue; +class CEnumSlider; +class CGroup; +class CImage; +class CKey; +class CLabel; +class CList; +class CMap; +class CScroll; +class CShortcut; +class CSlider; +class CTarget; +class CWindow; + const int MAXCONTROL = 100; class CInterface diff --git a/src/ui/controls/label.h b/src/ui/controls/label.h index f935ed65..113f3cf2 100644 --- a/src/ui/controls/label.h +++ b/src/ui/controls/label.h @@ -19,11 +19,9 @@ #pragma once - #include "ui/controls/control.h" #include "common/event.h" -#include "common/misc.h" namespace Ui { @@ -41,4 +39,4 @@ public: }; -} +} // namespace Ui diff --git a/src/ui/controls/list.h b/src/ui/controls/list.h index 0509ecb4..abf90b22 100644 --- a/src/ui/controls/list.h +++ b/src/ui/controls/list.h @@ -19,11 +19,9 @@ #pragma once - #include "ui/controls/control.h" #include "common/event.h" -#include "common/misc.h" #include "graphics/engine/text.h" diff --git a/src/ui/controls/scroll.h b/src/ui/controls/scroll.h index 30561bff..46f82848 100644 --- a/src/ui/controls/scroll.h +++ b/src/ui/controls/scroll.h @@ -19,11 +19,10 @@ #pragma once +#include "ui/controls/control.h" #include "common/event.h" -#include "ui/controls/control.h" - #include namespace Ui diff --git a/src/ui/controls/target.h b/src/ui/controls/target.h index 8ba69ad3..b7d70494 100644 --- a/src/ui/controls/target.h +++ b/src/ui/controls/target.h @@ -19,16 +19,14 @@ #pragma once -#include "common/event.h" -#include "common/misc.h" -#include "common/restext.h" - -#include "graphics/engine/engine.h" - #include "ui/controls/control.h" +#include "common/event.h" + #include +class CObject; + namespace Ui { @@ -50,4 +48,4 @@ protected: }; -} +} // namespace Ui diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index d5840007..6f8c8614 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -17,9 +17,27 @@ * along with this program. If not, see http://gnu.org/licenses */ - #include "ui/controls/window.h" +#include "ui/controls/button.h" +#include "ui/controls/check.h" +#include "ui/controls/color.h" +#include "ui/controls/control.h" +#include "ui/controls/edit.h" +#include "ui/controls/editvalue.h" +#include "ui/controls/enumslider.h" +#include "ui/controls/gauge.h" +#include "ui/controls/group.h" +#include "ui/controls/image.h" +#include "ui/controls/key.h" +#include "ui/controls/label.h" +#include "ui/controls/list.h" +#include "ui/controls/map.h" +#include "ui/controls/scroll.h" +#include "ui/controls/shortcut.h" +#include "ui/controls/slider.h" +#include "ui/controls/target.h" + #include diff --git a/src/ui/controls/window.h b/src/ui/controls/window.h index 4c8b3dea..9b1659f3 100644 --- a/src/ui/controls/window.h +++ b/src/ui/controls/window.h @@ -21,24 +21,7 @@ #include "ui/controls/control.h" -#include "ui/controls/button.h" -#include "ui/controls/check.h" -#include "ui/controls/color.h" -#include "ui/controls/control.h" -#include "ui/controls/edit.h" -#include "ui/controls/editvalue.h" -#include "ui/controls/enumslider.h" -#include "ui/controls/gauge.h" -#include "ui/controls/group.h" -#include "ui/controls/image.h" -#include "ui/controls/key.h" -#include "ui/controls/label.h" -#include "ui/controls/list.h" -#include "ui/controls/map.h" -#include "ui/controls/scroll.h" -#include "ui/controls/shortcut.h" -#include "ui/controls/slider.h" -#include "ui/controls/target.h" +#include "graphics/engine/engine.h" // TODO: only needed for EngineMouseType #include #include @@ -47,6 +30,24 @@ namespace Ui { +class CButton; +class CColor; +class CCheck; +class CKey; +class CGroup; +class CImage; +class CLabel; +class CEdit; +class CEditValue; +class CScroll; +class CSlider; +class CEnumSlider; +class CList; +class CShortcut; +class CMap; +class CGauge; +class CTarget; + class CWindow : public CControl { public: @@ -150,4 +151,4 @@ protected: }; -} +} // namespace Ui diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index c269921d..935cafbb 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -19,8 +19,6 @@ #pragma once -#include "common/event.h" - #include "graphics/engine/camera.h" #include @@ -30,7 +28,6 @@ class CObject; class CEventQueue; class CPauseManager; struct ActivePause; - struct Event; namespace Gfx @@ -38,7 +35,7 @@ namespace Gfx class CEngine; class CParticle; class CLightManager; -} +} // namespace Gfx namespace Ui { diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index def29925..31e5ebbb 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -35,6 +35,7 @@ #include "sound/sound.h" #include "ui/controls/button.h" +#include "ui/controls/label.h" #include "ui/controls/interface.h" #include "ui/controls/window.h" diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index a9d186d1..84829b1c 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -19,9 +19,10 @@ #pragma once -#include "common/event.h" #include "common/restext.h" +#include "math/point.h" + #include #include @@ -29,12 +30,13 @@ class CSettings; class CSoundInterface; class CRobotMain; +struct Event; namespace Gfx { class CEngine; class CParticle; -} +} // namespace Gfx namespace Ui { @@ -50,7 +52,7 @@ public: bool EventProcess(const Event &event); - typedef std::function DialogCallback; + using DialogCallback = std::function; void StartQuestion(const std::string& text, bool warningYes = false, bool warningNo = false, bool fireParticles = false, diff --git a/src/ui/mainmap.cpp b/src/ui/mainmap.cpp index b5ea2a2d..f80c27d7 100644 --- a/src/ui/mainmap.cpp +++ b/src/ui/mainmap.cpp @@ -24,6 +24,12 @@ #include "level/robotmain.h" +#include "ui/controls/interface.h" +#include "ui/controls/map.h" +#include "ui/controls/scroll.h" +#include "ui/controls/slider.h" +#include "ui/controls/window.h" + namespace Ui { diff --git a/src/ui/mainmap.h b/src/ui/mainmap.h index d3f1b2a1..b80e9a47 100644 --- a/src/ui/mainmap.h +++ b/src/ui/mainmap.h @@ -19,18 +19,23 @@ #pragma once -#include "common/event.h" - #include "graphics/core/color.h" #include "math/point.h" -#include "ui/controls/interface.h" +class CObject; +class CEventQueue; +namespace Gfx +{ +class CEngine; +} // namespace Gfx namespace Ui { +class CInterface; + class CMainMap { public: @@ -64,4 +69,4 @@ protected: bool m_bFixImage; }; -} +} // namespace Ui diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index c74dbaba..13b111a4 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -33,6 +33,9 @@ #include "object/interface/controllable_object.h" #include "object/interface/programmable_object.h" +#include "ui/controls/interface.h" +#include "ui/controls/shortcut.h" + #include diff --git a/src/ui/mainshort.h b/src/ui/mainshort.h index c2f4aaf7..58df5773 100644 --- a/src/ui/mainshort.h +++ b/src/ui/mainshort.h @@ -21,17 +21,24 @@ #include "common/event.h" -#include "graphics/engine/engine.h" - #include "math/point.h" #include "object/object_type.h" -#include "ui/controls/interface.h" +#include + +class CRobotMain; +class CObject; + +namespace Gfx +{ +class CEngine; +} // namespace Gfx namespace Ui { +class CInterface; class CMainShort { @@ -60,4 +67,4 @@ protected: bool m_bBuilding; }; -} +} // namespace Ui diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index cbccba20..c61dd033 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -52,6 +52,7 @@ #include "ui/screen/screen_welcome.h" #include "ui/controls/interface.h" +#include "ui/controls/group.h" #include "ui/controls/label.h" #include "ui/controls/window.h" diff --git a/src/ui/mainui.h b/src/ui/mainui.h index b0c962af..da41a1de 100644 --- a/src/ui/mainui.h +++ b/src/ui/mainui.h @@ -34,7 +34,7 @@ namespace Gfx { class CEngine; class CParticle; -} +} // namespace Gfx namespace Ui { diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 7d8bc9b4..4a29ac5d 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -22,6 +22,7 @@ #include "app/app.h" #include "common/global.h" +#include "common/restext.h" #include "graphics/core/color.h" @@ -52,8 +53,15 @@ #include "ui/studio.h" +#include "ui/controls/button.h" +#include "ui/controls/color.h" +#include "ui/controls/gauge.h" +#include "ui/controls/group.h" #include "ui/controls/interface.h" +#include "ui/controls/label.h" +#include "ui/controls/list.h" #include "ui/controls/slider.h" +#include "ui/controls/target.h" #include "ui/controls/window.h" diff --git a/src/ui/object_interface.h b/src/ui/object_interface.h index c1ddb8cc..2e991d76 100644 --- a/src/ui/object_interface.h +++ b/src/ui/object_interface.h @@ -29,7 +29,6 @@ class CPhysics; class CMotion; class CRobotMain; class CSoundInterface; -class CLevelParserLine; struct Program; namespace Gfx diff --git a/src/ui/screen/screen_apperance.cpp b/src/ui/screen/screen_apperance.cpp index 0a9b3202..2dc4ebe8 100644 --- a/src/ui/screen/screen_apperance.cpp +++ b/src/ui/screen/screen_apperance.cpp @@ -21,6 +21,8 @@ #include "app/app.h" +#include "common/restext.h" + #include "graphics/engine/camera.h" #include "level/player_profile.h" diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index f9c6b28d..fbae0483 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -20,6 +20,8 @@ #include "ui/screen/screen_io.h" #include "common/logger.h" +#include "common/misc.h" +#include "common/restext.h" #include "common/stringutils.h" #include "level/player_profile.h" @@ -35,6 +37,7 @@ #include "ui/controls/edit.h" #include "ui/controls/interface.h" #include "ui/controls/image.h" +#include "ui/controls/list.h" #include "ui/controls/window.h" #include diff --git a/src/ui/screen/screen_io_read.cpp b/src/ui/screen/screen_io_read.cpp index a9b8a01e..5ce9753e 100644 --- a/src/ui/screen/screen_io_read.cpp +++ b/src/ui/screen/screen_io_read.cpp @@ -21,6 +21,8 @@ #include "app/app.h" +#include "common/restext.h" + #include "level/robotmain.h" #include "ui/controls/button.h" diff --git a/src/ui/screen/screen_io_write.cpp b/src/ui/screen/screen_io_write.cpp index 3a373248..f5dcaca2 100644 --- a/src/ui/screen/screen_io_write.cpp +++ b/src/ui/screen/screen_io_write.cpp @@ -21,6 +21,8 @@ #include "app/app.h" +#include "common/restext.h" + #include "level/robotmain.h" #include "ui/controls/button.h" diff --git a/src/ui/screen/screen_loading.cpp b/src/ui/screen/screen_loading.cpp index 4f68f036..7bf9cea7 100644 --- a/src/ui/screen/screen_loading.cpp +++ b/src/ui/screen/screen_loading.cpp @@ -24,6 +24,7 @@ #include "ui/controls/button.h" #include "ui/controls/edit.h" #include "ui/controls/gauge.h" +#include "ui/controls/group.h" #include "ui/controls/interface.h" #include "ui/controls/label.h" #include "ui/controls/window.h" diff --git a/src/ui/screen/screen_main_menu.cpp b/src/ui/screen/screen_main_menu.cpp index 3c582fe2..fcab0623 100644 --- a/src/ui/screen/screen_main_menu.cpp +++ b/src/ui/screen/screen_main_menu.cpp @@ -22,6 +22,7 @@ #include "app/app.h" #include "common/logger.h" +#include "common/restext.h" #include "level/parser/parser.h" diff --git a/src/ui/screen/screen_main_menu.h b/src/ui/screen/screen_main_menu.h index 0527c788..b0350c01 100644 --- a/src/ui/screen/screen_main_menu.h +++ b/src/ui/screen/screen_main_menu.h @@ -24,8 +24,6 @@ namespace Ui { -class CScreenSetup; - class CScreenMainMenu : public CScreen { public: diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 295aa924..680af0c6 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -24,6 +24,7 @@ #include "level/robotmain.h" #include "common/logger.h" +#include "common/misc.h" #include "common/stringutils.h" #include "level/player_profile.h" @@ -34,6 +35,8 @@ #include "ui/controls/button.h" #include "ui/controls/edit.h" +#include "ui/controls/gauge.h" +#include "ui/controls/group.h" #include "ui/controls/interface.h" #include "ui/controls/label.h" #include "ui/controls/list.h" diff --git a/src/ui/screen/screen_quit.cpp b/src/ui/screen/screen_quit.cpp index 96ff97de..6086a835 100644 --- a/src/ui/screen/screen_quit.cpp +++ b/src/ui/screen/screen_quit.cpp @@ -21,6 +21,8 @@ #include "app/app.h" +#include "common/restext.h" + #include "level/robotmain.h" #include "ui/controls/button.h" diff --git a/src/ui/screen/screen_setup.cpp b/src/ui/screen/screen_setup.cpp index 6ee8967a..e1b91822 100644 --- a/src/ui/screen/screen_setup.cpp +++ b/src/ui/screen/screen_setup.cpp @@ -23,6 +23,7 @@ #include "app/app.h" +#include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_setup_controls.cpp b/src/ui/screen/screen_setup_controls.cpp index 264b2e02..2436107f 100644 --- a/src/ui/screen/screen_setup_controls.cpp +++ b/src/ui/screen/screen_setup_controls.cpp @@ -27,6 +27,7 @@ #include "graphics/engine/camera.h" #include "ui/controls/button.h" +#include "ui/controls/check.h" #include "ui/controls/group.h" #include "ui/controls/interface.h" #include "ui/controls/key.h" diff --git a/src/ui/screen/screen_setup_controls.h b/src/ui/screen/screen_setup_controls.h index 90d0f653..b7c614c8 100644 --- a/src/ui/screen/screen_setup_controls.h +++ b/src/ui/screen/screen_setup_controls.h @@ -21,13 +21,6 @@ #include "ui/screen/screen_setup.h" -class CSettings; - -namespace Gfx -{ -class CCamera; -} - namespace Ui { diff --git a/src/ui/screen/screen_setup_display.cpp b/src/ui/screen/screen_setup_display.cpp index f9cd2cc9..aa46f8e4 100644 --- a/src/ui/screen/screen_setup_display.cpp +++ b/src/ui/screen/screen_setup_display.cpp @@ -23,6 +23,7 @@ #include "app/app.h" +#include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_setup_display.h b/src/ui/screen/screen_setup_display.h index c93df652..97b2d50b 100644 --- a/src/ui/screen/screen_setup_display.h +++ b/src/ui/screen/screen_setup_display.h @@ -21,13 +21,6 @@ #include "ui/screen/screen_setup.h" -class CSettings; - -namespace Gfx -{ -class CCamera; -} - namespace Ui { diff --git a/src/ui/screen/screen_setup_game.cpp b/src/ui/screen/screen_setup_game.cpp index 90afee16..f59dc9f1 100644 --- a/src/ui/screen/screen_setup_game.cpp +++ b/src/ui/screen/screen_setup_game.cpp @@ -21,6 +21,7 @@ #include "app/app.h" +#include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_setup_game.h b/src/ui/screen/screen_setup_game.h index 937f02f1..13d31233 100644 --- a/src/ui/screen/screen_setup_game.h +++ b/src/ui/screen/screen_setup_game.h @@ -21,13 +21,6 @@ #include "ui/screen/screen_setup.h" -class CSettings; - -namespace Gfx -{ -class CCamera; -} - namespace Ui { diff --git a/src/ui/screen/screen_setup_graphics.cpp b/src/ui/screen/screen_setup_graphics.cpp index 327f04f1..5a05dac7 100644 --- a/src/ui/screen/screen_setup_graphics.cpp +++ b/src/ui/screen/screen_setup_graphics.cpp @@ -23,6 +23,7 @@ #include "app/app.h" +#include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_setup_graphics.h b/src/ui/screen/screen_setup_graphics.h index c2e836bf..29578659 100644 --- a/src/ui/screen/screen_setup_graphics.h +++ b/src/ui/screen/screen_setup_graphics.h @@ -21,13 +21,6 @@ #include "ui/screen/screen_setup.h" -class CSettings; - -namespace Gfx -{ -class CCamera; -} - namespace Ui { diff --git a/src/ui/screen/screen_setup_sound.cpp b/src/ui/screen/screen_setup_sound.cpp index d613b474..feb784e4 100644 --- a/src/ui/screen/screen_setup_sound.cpp +++ b/src/ui/screen/screen_setup_sound.cpp @@ -21,6 +21,7 @@ #include "app/app.h" +#include "common/restext.h" #include "common/settings.h" #include "common/stringutils.h" diff --git a/src/ui/screen/screen_setup_sound.h b/src/ui/screen/screen_setup_sound.h index 5d7fef22..4ea58937 100644 --- a/src/ui/screen/screen_setup_sound.h +++ b/src/ui/screen/screen_setup_sound.h @@ -21,13 +21,6 @@ #include "ui/screen/screen_setup.h" -class CSettings; - -namespace Gfx -{ -class CCamera; -} - namespace Ui { diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index cd446a5d..31f4bc6e 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -40,6 +40,7 @@ #include "object/object.h" +#include "object/interface/program_storage_object.h" #include "object/interface/programmable_object.h" #include "script/cbottoken.h" @@ -59,6 +60,7 @@ #include "ui/controls/list.h" #include "ui/controls/map.h" #include "ui/controls/shortcut.h" +#include "ui/controls/slider.h" #include "ui/controls/target.h" #include "ui/controls/window.h" diff --git a/src/ui/studio.h b/src/ui/studio.h index 3b2b2088..cdb8cf08 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -19,8 +19,6 @@ #pragma once -#include "common/event.h" - #include "graphics/engine/camera.h" #include @@ -32,6 +30,7 @@ class CSettings; struct Program; class CPauseManager; struct ActivePause; +struct Event; namespace Ui { From 7a6e669a37ba0d46b13efc62c095498db31f92c6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 27 Sep 2015 18:54:02 +0200 Subject: [PATCH 017/360] Show detailed error info when opening haptic device fails --- src/app/app.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 6186e9b2..b83a45f4 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -736,13 +736,13 @@ bool CApplication::OpenJoystick() m_private->haptic = SDL_HapticOpenFromJoystick(m_private->joystick); if (m_private->haptic == nullptr) { - GetLogger()->Warn("Haptic subsystem open failed\n"); + GetLogger()->Warn("Haptic subsystem open failed: %s\n", SDL_GetError()); return true; } if (SDL_HapticRumbleInit(m_private->haptic) != 0) { - GetLogger()->Warn("Haptic rumble effect init failed\n"); + GetLogger()->Warn("Haptic rumble effect init failed: %s\n", SDL_GetError()); return true; } @@ -1818,7 +1818,7 @@ void CApplication::PlayForceFeedbackEffect(float strength, int length) GetLogger()->Trace("Force feedback! length = %d ms, strength = %.2f\n", length, strength); if (SDL_HapticRumblePlay(m_private->haptic, strength, length) != 0) { - GetLogger()->Debug("Failed to play haptic effect\n"); + GetLogger()->Debug("Failed to play haptic effect: %s\n", SDL_GetError()); } } From 2cb2782c9d6fd83c9ce0f9fcf35633a54c99b9f7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Sep 2015 22:08:04 +0200 Subject: [PATCH 018/360] Restored old Ceebot-Teen objects In preparations for new programming course --- data | 2 +- src/CMakeLists.txt | 1 + src/graphics/engine/particle.cpp | 6 +- src/graphics/engine/pyro.cpp | 27 +- src/level/parser/parserparam.cpp | 90 ++++ src/object/auto/autokid.cpp | 204 +++++++ src/object/auto/autokid.h | 48 ++ src/object/object_factory.cpp | 846 ++++++++++++++++++++++++++++++ src/object/object_factory.h | 1 + src/object/object_type.h | 45 ++ src/object/old_object.cpp | 3 +- src/object/task/taskterraform.cpp | 5 +- src/script/cbottoken.cpp | 1 + src/ui/controls/map.cpp | 26 +- 14 files changed, 1294 insertions(+), 11 deletions(-) create mode 100644 src/object/auto/autokid.cpp create mode 100644 src/object/auto/autokid.h diff --git a/data b/data index 14518ff4..d90d0da9 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 14518ff47694de5bf13a5f43826187cf3d8e40a1 +Subproject commit d90d0da944ad77e461dbc7b623491016f952fc21 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e445a98..53865091 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,6 +147,7 @@ set(BASE_SOURCES object/auto/autoflag.cpp object/auto/autohouston.cpp object/auto/autojostle.cpp + object/auto/autokid.cpp object/auto/autolabo.cpp object/auto/automush.cpp object/auto/autonest.cpp diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index afd9f4d1..1903554d 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -67,7 +67,9 @@ bool IsAlien(ObjectType type) type == OBJECT_NEST || type == OBJECT_BULLET || type == OBJECT_EGG || - type == OBJECT_MOBILEtg ); + type == OBJECT_MOBILEtg || + type == OBJECT_TEEN28 || + type == OBJECT_TEEN31 ); } CParticle::CParticle(CEngine* engine) @@ -3611,6 +3613,8 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, if ( type == PARTIRAY1 && oType != OBJECT_MOBILEtg && + oType != OBJECT_TEEN28 && + oType != OBJECT_TEEN31 && oType != OBJECT_ANT && oType != OBJECT_SPIDER && oType != OBJECT_BEE && diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 68038902..a0f962cf 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -119,6 +119,12 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) m_lastParticleSmoke = 0.0f; m_lightRank = -1; + if ( oType == OBJECT_TEEN28 || + oType == OBJECT_TEEN31 ) + { + m_pos.y = pos.y+1.0f; + } + // Seeking the position of the battery. CObject* power = nullptr; @@ -456,7 +462,9 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) m_type == PT_FRAGW || m_type == PT_SPIDER || m_type == PT_EGG || - (m_type == PT_EXPLOT && oType == OBJECT_MOBILEtg) ) + (m_type == PT_EXPLOT && oType == OBJECT_MOBILEtg) || + (m_type == PT_EXPLOT && oType == OBJECT_TEEN28 ) || + (m_type == PT_EXPLOT && oType == OBJECT_TEEN31 ) ) { for (int part = 0; part < OBJECTMAXPART; part++) { @@ -1414,7 +1422,8 @@ void CPyro::CreateTriangle(CObject* obj, ObjectType oType, int part) oType == OBJECT_ATOMIC || oType == OBJECT_URANIUM || oType == OBJECT_TNT || - oType == OBJECT_BOMB ) + oType == OBJECT_BOMB || + oType == OBJECT_TEEN28) { percent = 0.75f; } @@ -1720,6 +1729,15 @@ void CPyro::BurnStart() angle.y = 0.0f; angle.z = (Math::Rand()-0.5f)*0.4f; } + else if ( m_burnType == OBJECT_TEEN31 ) // basket? + { + pos.x = 0.0f; + pos.y = 0.0f; + pos.z = 0.0f; + angle.x = (Math::Rand()-0.5f)*0.8f; + angle.y = 0.0f; + angle.z = (Math::Rand()-0.5f)*0.2f; + } else { pos.x = 0.0f; @@ -2094,6 +2112,11 @@ void CPyro::BurnAddPart(int part, Math::Vector pos, Math::Vector angle) void CPyro::BurnProgress() { + if ( m_burnType == OBJECT_TEEN31 ) // basket? + { + m_object->SetScaleY(1.0f-m_progress*0.5f); // slight flattening + } + for (int i = 0; i < m_burnPartTotal; i++) { Math::Vector pos = m_burnPart[i].initialPos + m_progress*(m_burnPart[i].finalPos-m_burnPart[i].initialPos); diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp index 1933f843..e6c361ed 100644 --- a/src/level/parser/parserparam.cpp +++ b/src/level/parser/parserparam.cpp @@ -467,6 +467,51 @@ ObjectType CLevelParserParam::ToObjectType(std::string value) if (value == "Barrier1" ) return OBJECT_BARRIER1; if (value == "Barrier2" ) return OBJECT_BARRIER2; if (value == "Barrier3" ) return OBJECT_BARRIER3; + if (value == "Teen0" ) return OBJECT_TEEN0; + if (value == "Teen1" ) return OBJECT_TEEN1; + if (value == "Teen2" ) return OBJECT_TEEN2; + if (value == "Teen3" ) return OBJECT_TEEN3; + if (value == "Teen4" ) return OBJECT_TEEN4; + if (value == "Teen5" ) return OBJECT_TEEN5; + if (value == "Teen6" ) return OBJECT_TEEN6; + if (value == "Teen7" ) return OBJECT_TEEN7; + if (value == "Teen8" ) return OBJECT_TEEN8; + if (value == "Teen9" ) return OBJECT_TEEN9; + if (value == "Teen10" ) return OBJECT_TEEN10; + if (value == "Teen11" ) return OBJECT_TEEN11; + if (value == "Teen12" ) return OBJECT_TEEN12; + if (value == "Teen13" ) return OBJECT_TEEN13; + if (value == "Teen14" ) return OBJECT_TEEN14; + if (value == "Teen15" ) return OBJECT_TEEN15; + if (value == "Teen16" ) return OBJECT_TEEN16; + if (value == "Teen17" ) return OBJECT_TEEN17; + if (value == "Teen18" ) return OBJECT_TEEN18; + if (value == "Teen19" ) return OBJECT_TEEN19; + if (value == "Teen20" ) return OBJECT_TEEN20; + if (value == "Teen21" ) return OBJECT_TEEN21; + if (value == "Teen22" ) return OBJECT_TEEN22; + if (value == "Teen23" ) return OBJECT_TEEN23; + if (value == "Teen24" ) return OBJECT_TEEN24; + if (value == "Teen25" ) return OBJECT_TEEN25; + if (value == "Teen26" ) return OBJECT_TEEN26; + if (value == "Teen27" ) return OBJECT_TEEN27; + if (value == "Teen28" ) return OBJECT_TEEN28; + if (value == "Teen29" ) return OBJECT_TEEN29; + if (value == "Teen30" ) return OBJECT_TEEN30; + if (value == "Teen31" ) return OBJECT_TEEN31; + if (value == "Teen32" ) return OBJECT_TEEN32; + if (value == "Teen33" ) return OBJECT_TEEN33; + if (value == "Stone" ) return OBJECT_TEEN34; + if (value == "Teen35" ) return OBJECT_TEEN35; + if (value == "Teen36" ) return OBJECT_TEEN36; + if (value == "Teen37" ) return OBJECT_TEEN37; + if (value == "Teen38" ) return OBJECT_TEEN38; + if (value == "Teen39" ) return OBJECT_TEEN39; + if (value == "Teen40" ) return OBJECT_TEEN40; + if (value == "Teen41" ) return OBJECT_TEEN41; + if (value == "Teen42" ) return OBJECT_TEEN42; + if (value == "Teen43" ) return OBJECT_TEEN43; + if (value == "Teen44" ) return OBJECT_TEEN44; if (value == "Quartz0" ) return OBJECT_QUARTZ0; if (value == "Quartz1" ) return OBJECT_QUARTZ1; if (value == "Quartz2" ) return OBJECT_QUARTZ2; @@ -617,6 +662,51 @@ const std::string CLevelParserParam::FromObjectType(ObjectType value) if (value == OBJECT_BARRIER1 ) return "Barrier1"; if (value == OBJECT_BARRIER2 ) return "Barrier2"; if (value == OBJECT_BARRIER3 ) return "Barrier3"; + if (value == OBJECT_TEEN0 ) return "Teen0"; + if (value == OBJECT_TEEN1 ) return "Teen1"; + if (value == OBJECT_TEEN2 ) return "Teen2"; + if (value == OBJECT_TEEN3 ) return "Teen3"; + if (value == OBJECT_TEEN4 ) return "Teen4"; + if (value == OBJECT_TEEN5 ) return "Teen5"; + if (value == OBJECT_TEEN6 ) return "Teen6"; + if (value == OBJECT_TEEN7 ) return "Teen7"; + if (value == OBJECT_TEEN8 ) return "Teen8"; + if (value == OBJECT_TEEN9 ) return "Teen9"; + if (value == OBJECT_TEEN10 ) return "Teen10"; + if (value == OBJECT_TEEN11 ) return "Teen11"; + if (value == OBJECT_TEEN12 ) return "Teen12"; + if (value == OBJECT_TEEN13 ) return "Teen13"; + if (value == OBJECT_TEEN14 ) return "Teen14"; + if (value == OBJECT_TEEN15 ) return "Teen15"; + if (value == OBJECT_TEEN16 ) return "Teen16"; + if (value == OBJECT_TEEN17 ) return "Teen17"; + if (value == OBJECT_TEEN18 ) return "Teen18"; + if (value == OBJECT_TEEN19 ) return "Teen19"; + if (value == OBJECT_TEEN20 ) return "Teen20"; + if (value == OBJECT_TEEN21 ) return "Teen21"; + if (value == OBJECT_TEEN22 ) return "Teen22"; + if (value == OBJECT_TEEN23 ) return "Teen23"; + if (value == OBJECT_TEEN24 ) return "Teen24"; + if (value == OBJECT_TEEN25 ) return "Teen25"; + if (value == OBJECT_TEEN26 ) return "Teen26"; + if (value == OBJECT_TEEN27 ) return "Teen27"; + if (value == OBJECT_TEEN28 ) return "Teen28"; + if (value == OBJECT_TEEN29 ) return "Teen29"; + if (value == OBJECT_TEEN30 ) return "Teen30"; + if (value == OBJECT_TEEN31 ) return "Teen31"; + if (value == OBJECT_TEEN32 ) return "Teen32"; + if (value == OBJECT_TEEN33 ) return "Teen33"; + if (value == OBJECT_TEEN34 ) return "Stone"; + if (value == OBJECT_TEEN35 ) return "Teen35"; + if (value == OBJECT_TEEN36 ) return "Teen36"; + if (value == OBJECT_TEEN37 ) return "Teen37"; + if (value == OBJECT_TEEN38 ) return "Teen38"; + if (value == OBJECT_TEEN39 ) return "Teen39"; + if (value == OBJECT_TEEN40 ) return "Teen40"; + if (value == OBJECT_TEEN41 ) return "Teen41"; + if (value == OBJECT_TEEN42 ) return "Teen42"; + if (value == OBJECT_TEEN43 ) return "Teen43"; + if (value == OBJECT_TEEN44 ) return "Teen44"; if (value == OBJECT_QUARTZ0 ) return "Quartz0"; if (value == OBJECT_QUARTZ1 ) return "Quartz1"; if (value == OBJECT_QUARTZ2 ) return "Quartz2"; diff --git a/src/object/auto/autokid.cpp b/src/object/auto/autokid.cpp new file mode 100644 index 00000000..2cdf3238 --- /dev/null +++ b/src/object/auto/autokid.cpp @@ -0,0 +1,204 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + + +#include "object/auto/autokid.h" + +#include "graphics/engine/particle.h" +#include "graphics/engine/water.h" + +#include "object/old_object.h" + +#include "sound/sound.h" + +#include + + +// Object's constructor. + +CAutoKid::CAutoKid(COldObject* object) : CAuto(object) +{ + m_soundChannel = -1; + Init(); +} + +// Object's constructor. + +CAutoKid::~CAutoKid() +{ + if ( m_soundChannel != -1 ) + { + m_sound->FlushEnvelope(m_soundChannel); + m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.0f, 1.0f, SOPER_STOP); + m_soundChannel = -1; + } +} + + +// Destroys the object. + +void CAutoKid::DeleteObject(bool bAll) +{ + CAuto::DeleteObject(bAll); +} + + +// Initialize the object. + +void CAutoKid::Init() +{ + Math::Vector pos; + + m_speed = 1.0f/1.0f; + m_progress = 0.0f; + m_lastParticle = 0.0f; + + if ( m_type == OBJECT_TEEN36 ) // trunk ? + { + pos = m_object->GetPosition(); + m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f)); + m_progress = Math::Mod(pos.x/10.0f, 1.0f); + } + + if ( m_type == OBJECT_TEEN37 ) // boat? + { + pos = m_object->GetPosition(); + m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f))*2.5f; + m_progress = Math::Mod(pos.x/10.0f, 1.0f); + } + + if ( m_type == OBJECT_TEEN38 ) // fan? + { + if ( m_soundChannel == -1 ) + { +//? m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 1.0f, 0.5f, true); + m_bSilent = false; + } + } +} + + +// Management of an event. + +bool CAutoKid::EventProcess(const Event &event) +{ + Math::Vector vib, pos, speed; + Math::Point dim; + + CAuto::EventProcess(event); + + if ( m_soundChannel != -1 ) + { + if ( m_engine->GetPause() ) + { + if ( !m_bSilent ) + { + m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.1f, SOPER_CONTINUE); + m_bSilent = true; + } + } + else + { + if ( m_bSilent ) + { + m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 0.1f, SOPER_CONTINUE); + m_bSilent = false; + } + } + } + + if ( m_engine->GetPause() ) return true; + if ( event.type != EVENT_FRAME ) return true; + + m_progress += event.rTime*m_speed; + + if ( m_type == OBJECT_TEEN36 ) // trunk? + { + vib.x = 0.0f; + vib.y = sinf(m_progress)*1.0f; + vib.z = 0.0f; + m_object->SetLinVibration(vib); + + vib.x = 0.0f; + vib.y = 0.0f; + vib.z = sinf(m_progress*0.5f)*0.05f; + m_object->SetCirVibration(vib); + + if ( m_lastParticle+m_engine->ParticleAdapt(0.15f) <= m_time ) + { + m_lastParticle = m_time; + + pos = m_object->GetPosition(); + pos.y = m_water->GetLevel()+1.0f; + pos.x += (Math::Rand()-0.5f)*50.0f; + pos.z += (Math::Rand()-0.5f)*50.0f; + speed.y = 0.0f; + speed.x = 0.0f; + speed.z = 0.0f; + dim.x = 50.0f; + dim.y = dim.x; + m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f); + } + } + + if ( m_type == OBJECT_TEEN37 ) // boat? + { + vib.x = 0.0f; + vib.y = sinf(m_progress)*1.0f; + vib.z = 0.0f; + m_object->SetLinVibration(vib); + + vib.x = 0.0f; + vib.y = 0.0f; + vib.z = sinf(m_progress*0.5f)*0.15f; + m_object->SetCirVibration(vib); + + if ( m_lastParticle+m_engine->ParticleAdapt(0.15f) <= m_time ) + { + m_lastParticle = m_time; + + pos = m_object->GetPosition(); + pos.y = m_water->GetLevel()+1.0f; + pos.x += (Math::Rand()-0.5f)*20.0f; + pos.z += (Math::Rand()-0.5f)*20.0f; + speed.y = 0.0f; + speed.x = 0.0f; + speed.z = 0.0f; + dim.x = 20.0f; + dim.y = dim.x; + m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f); + } + } + + if ( m_type == OBJECT_TEEN38 ) // fan? + { + m_object->SetPartRotationY(1, sinf(m_progress*0.6f)*0.4f); + m_object->SetPartRotationX(2, m_progress*5.0f); + } + + return true; +} + + +// Returns an error due the state of the automation. + +Error CAutoKid::GetError() +{ + return ERR_OK; +} diff --git a/src/object/auto/autokid.h b/src/object/auto/autokid.h new file mode 100644 index 00000000..605587c9 --- /dev/null +++ b/src/object/auto/autokid.h @@ -0,0 +1,48 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// autokid.h + +#pragma once + + +#include "object/auto/auto.h" + + +class CAutoKid : public CAuto +{ +public: + CAutoKid(COldObject* object); + ~CAutoKid(); + + void DeleteObject(bool bAll=false); + + void Init(); + bool EventProcess(const Event &event); + Error GetError(); + +protected: + +protected: + float m_speed; + float m_progress; + float m_lastParticle; + int m_soundChannel; + bool m_bSilent; +}; diff --git a/src/object/object_factory.cpp b/src/object/object_factory.cpp index 484d6a28..b8f86f4c 100644 --- a/src/object/object_factory.cpp +++ b/src/object/object_factory.cpp @@ -38,6 +38,7 @@ #include "object/auto/autoegg.h" #include "object/auto/autoflag.h" #include "object/auto/autojostle.h" +#include "object/auto/autokid.h" #include "object/auto/automush.h" #include "object/auto/autoroot.h" @@ -182,6 +183,53 @@ CObjectUPtr CObjectFactory::CreateObject(const ObjectCreateParams& params) case OBJECT_MUSHROOM2: return CreateMushroom(params); + case OBJECT_TEEN0: + case OBJECT_TEEN1: + case OBJECT_TEEN2: + case OBJECT_TEEN3: + case OBJECT_TEEN4: + case OBJECT_TEEN5: + case OBJECT_TEEN6: + case OBJECT_TEEN7: + case OBJECT_TEEN8: + case OBJECT_TEEN9: + case OBJECT_TEEN10: + case OBJECT_TEEN11: + case OBJECT_TEEN12: + case OBJECT_TEEN13: + case OBJECT_TEEN14: + case OBJECT_TEEN15: + case OBJECT_TEEN16: + case OBJECT_TEEN17: + case OBJECT_TEEN18: + case OBJECT_TEEN19: + case OBJECT_TEEN20: + case OBJECT_TEEN21: + case OBJECT_TEEN22: + case OBJECT_TEEN23: + case OBJECT_TEEN24: + case OBJECT_TEEN25: + case OBJECT_TEEN26: + case OBJECT_TEEN27: + case OBJECT_TEEN28: + case OBJECT_TEEN29: + case OBJECT_TEEN30: + case OBJECT_TEEN31: + case OBJECT_TEEN32: + case OBJECT_TEEN33: + case OBJECT_TEEN34: + case OBJECT_TEEN35: + case OBJECT_TEEN36: + case OBJECT_TEEN37: + case OBJECT_TEEN38: + case OBJECT_TEEN39: + case OBJECT_TEEN40: + case OBJECT_TEEN41: + case OBJECT_TEEN42: + case OBJECT_TEEN43: + case OBJECT_TEEN44: + return CreateTeen(params); + case OBJECT_QUARTZ0: case OBJECT_QUARTZ1: case OBJECT_QUARTZ2: @@ -845,6 +893,798 @@ CObjectUPtr CObjectFactory::CreateMushroom(const ObjectCreateParams& params) return std::move(obj); } +// Creates a toy placed on the ground. + +CObjectUPtr CObjectFactory::CreateTeen(const ObjectCreateParams& params) +{ + Math::Vector pos = params.pos; + float angle = params.angle; + float height = params.height; + ObjectType type = params.type; + int option = params.option; + + COldObjectUPtr obj{new COldObject(params.id)}; + + obj->SetType(type); + obj->SetOption(option); + + float fShadow = Math::Norm(1.0f-height/10.0f); + bool floorAdjust = true; + + if ( type == OBJECT_TEEN0 ) // orange pencil lg=10 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen0.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 5.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 2.5f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-2.5f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(5.0f, 0.8f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN1 ) // blue pencil lg=14 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen1.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 6.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 2.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-2.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-4.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-6.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(6.0f, 0.8f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN2 ) // red pencil lg=16 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen2.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 7.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.7f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 2.3f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-2.3f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-4.7f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-7.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(6.0f, 0.8f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN3 ) // jar with pencils + { + int rank = m_engine->CreateObject(); +//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen3.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 0.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 4.0f, 0.0f), 4.0f)); + obj->CreateShadowCircle(6.0f, 0.5f*fShadow); + } + + if ( type == OBJECT_TEEN4 ) // scissors + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen4.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-9.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-6.0f, 1.0f, 0.0f), 1.1f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-3.0f, 1.0f, 0.0f), 1.2f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 1.0f, 0.0f), 1.3f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 5.1f, 1.0f,-1.3f), 2.6f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 8.0f, 1.0f, 2.2f), 2.3f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 9.4f, 1.0f,-2.0f), 2.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(10.0f, 0.5f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN5 ) // CD + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen5.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + obj->SetFloorHeight(0.0f); + floorAdjust = false; + + m_terrain->AddBuildingLevel(pos, 5.9f, 6.1f, 0.2f, 0.5f); + obj->CreateShadowCircle(8.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN6 ) // book 1 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen6.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN7 ) // book 2 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen7.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN8 ) // a stack of books 1 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen8.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 10.0f, 0.0f), 12.0f)); + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN9 ) // a stack of books 2 + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen9.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-5.0f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 4.5f, 3.0f,-7.5f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 10.0f, 0.0f), 12.0f)); + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN10 ) // bookcase + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen10.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-26.0f, 3.0f, 0.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-15.0f, 3.0f,-4.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-15.0f, 3.0f, 5.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -4.0f, 3.0f,-4.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -4.0f, 3.0f, 5.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 6.0f, 3.0f,-4.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 6.0f, 3.0f, 4.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 14.0f, 3.0f,-3.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 14.0f, 3.0f, 2.0f), 6.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 24.0f, 3.0f, 5.0f), 6.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 6.0f, 0.0f), 20.0f)); + obj->CreateShadowCircle(40.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN11 ) // lamp + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen11.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + obj->SetFloorHeight(0.0f); + + Math::Matrix* mat = obj->GetWorldMatrix(0); + pos = Math::Transform(*mat, Math::Vector(-56.0f, 22.0f, 0.0f)); + m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(20.0f, 20.0f), Gfx::PARTISELY, 1.0f, 0.0f, 0.0f); + + pos = Math::Transform(*mat, Math::Vector(-65.0f, 40.0f, 0.0f)); + /* TODO: ? + Gfx::Color color; + color.r = 4.0f; + color.g = 2.0f; + color.b = 0.0f; // yellow-orange + color.a = 0.0f; + m_main->CreateSpot(pos, color); + */ + } + + if ( type == OBJECT_TEEN12 ) // coke + { + int rank = m_engine->CreateObject(); +//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen12.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 0.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 9.0f, 0.0f), 5.0f)); + obj->CreateShadowCircle(4.5f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN13 ) // cardboard farm + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen13.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 5.0f, 0.0f), 15.0f)); + obj->CreateShadowCircle(20.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN14 ) // open box + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen14.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 5.0f, 0.0f), 15.0f)); + obj->CreateShadowCircle(20.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN15 ) // stack of cartons + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen15.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f,-7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 4.0f, 7.0f), 5.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 5.0f, 0.0f), 15.0f)); + obj->CreateShadowCircle(20.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN16 ) // watering can + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen16.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-8.0f, 4.0f, 0.0f), 12.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 8.0f, 4.0f, 0.0f), 12.0f, SOUND_BOUMm, 0.45f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 13.0f, 0.0f), 20.0f)); + obj->CreateShadowCircle(18.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN17 ) // wheel | + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen17.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 31.0f, 0.0f), 31.0f, SOUND_BOUMm, 0.45f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 31.0f, 0.0f), 31.0f)); + obj->CreateShadowCircle(24.0f, 0.5f*fShadow); + } + + if ( type == OBJECT_TEEN18 ) // wheel / + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen18.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 31.0f, 0.0f), 31.0f, SOUND_BOUMm, 0.45f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 31.0f, 0.0f), 31.0f)); + obj->CreateShadowCircle(24.0f, 0.5f*fShadow); + } + + if ( type == OBJECT_TEEN19 ) // wheel = + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen19.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 10.0f, 0.0f), 32.0f, SOUND_BOUMm, 0.45f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 10.0f, 0.0f), 32.0f)); + obj->CreateShadowCircle(33.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN20 ) // wall with shelf + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen20.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-175.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-175.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -55.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -55.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -37.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -37.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 83.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 83.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + } + + if ( type == OBJECT_TEEN21 ) // wall with window + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen21.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + } + + if ( type == OBJECT_TEEN22 ) // wall with door and shelf + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen22.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-135.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-135.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -15.0f, 0.0f, -5.0f), 4.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( -15.0f, 0.0f, -35.0f), 4.0f, SOUND_BOUMm, 0.45f)); + } + + if ( type == OBJECT_TEEN23 ) // skateboard on wheels + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen23.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + if ( option == 1 ) // passage under the prohibited skateboard? + { + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 2.0f, 0.0f), 11.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 10.0f, 2.0f, 0.0f), 11.0f, SOUND_BOUMm, 0.45f)); + } + + obj->AddCrashSphere(CrashSphere(Math::Vector(-23.0f, 2.0f, 7.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-23.0f, 2.0f, 0.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-23.0f, 2.0f,-7.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 23.0f, 2.0f, 7.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 23.0f, 2.0f, 0.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 23.0f, 2.0f,-7.0f), 3.0f, SOUND_BOUMm, 0.45f)); + + obj->CreateShadowCircle(35.0f, 0.8f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN24 ) // skate / + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen24.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-12.0f, 0.0f, -3.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-12.0f, 0.0f, 3.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN25 ) // skate / + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen25.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-12.0f, 0.0f, -3.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-12.0f, 0.0f, 3.0f), 3.0f, SOUND_BOUMm, 0.45f)); + obj->CreateShadowCircle(20.0f, 0.2f*fShadow); + } + + if ( type == OBJECT_TEEN26 ) // ceiling lamp + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen26.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + obj->SetFloorHeight(0.0f); + + Math::Matrix* mat = obj->GetWorldMatrix(0); + pos = Math::Transform(*mat, Math::Vector(0.0f, 50.0f, 0.0f)); + m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(100.0f, 100.0f), Gfx::PARTISELY, 1.0f, 0.0f, 0.0f); + + /* TODO: ? + pos = Math::Transform(*mat, Math::Vector(0.0f, 50.0f, 0.0f)); + Gfx::Color color; + color.r = 4.0f; + color.g = 2.0f; + color.b = 0.0f; // yellow-orange + color.a = 0.0f; + m_main->CreateSpot(pos, color); + */ + } + + if ( type == OBJECT_TEEN27 ) // large plant? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen27.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 4.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(40.0f, 0.5f); + } + + if ( type == OBJECT_TEEN28 ) // bottle? + { + int rank = m_engine->CreateObject(); +//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen28.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 5.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(7.0f, 0.6f*fShadow); + } + + if ( type == OBJECT_TEEN29 ) // bridge? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen29.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + floorAdjust = false; + } + + if ( type == OBJECT_TEEN30 ) // jump? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen30.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 4.0f, 0.0f), 15.0f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 15.0f, 0.0f), 17.0f)); + obj->CreateShadowCircle(20.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN31 ) // basket? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen31.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-10.0f, 2.0f, 0.0f), 5.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 2.0f, 0.0f), 6.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 9.0f, 4.0f, 1.0f), 6.0f, SOUND_BOUM, 0.10f)); + + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 0.0f, 0.0f), 10.0f)); + obj->CreateShadowCircle(16.0f, 0.6f*fShadow); + } + + if ( type == OBJECT_TEEN32 ) // chair? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen32.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector( 17.5f, 1.0f, 17.5f), 3.5f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 17.5f, 1.0f, -17.5f), 3.5f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-17.5f, 1.0f, 17.5f), 3.5f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-17.5f, 1.0f, -17.5f), 3.5f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 0.0f, 0.0f), 26.0f)); + obj->CreateShadowCircle(35.0f, 0.3f*fShadow); + } + + if ( type == OBJECT_TEEN33 ) // panel? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen33.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 4.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(10.0f, 0.3f*fShadow); + } + + if ( type == OBJECT_TEEN34 ) // stone? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen34.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 4.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(3.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN35 ) // pipe? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen35.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(-40.0f, 5.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector(-20.0f, 5.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 0.0f, 5.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 20.0f, 5.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->AddCrashSphere(CrashSphere(Math::Vector( 40.0f, 5.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(40.0f, 0.8f*fShadow, Gfx::ENG_SHADOW_WORM); + } + + if ( type == OBJECT_TEEN36 ) // trunk? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen36.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + floorAdjust = false; + } + + if ( type == OBJECT_TEEN37 ) // boat? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen37.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + floorAdjust = false; + } + + if ( type == OBJECT_TEEN38 ) // fan? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen38a.mod", false, rank); + obj->SetPartPosition(0, pos); + obj->SetPartRotationY(0, angle); + + rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); + obj->SetObjectRank(1, rank); + obj->SetObjectParent(1, 0); + m_oldModelManager->AddModelReference("teen38b.mod", false, rank); // engine + obj->SetPartPosition(1, Math::Vector(0.0f, 30.0f, 0.0f)); + + rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT); + obj->SetObjectRank(2, rank); + obj->SetObjectParent(2, 1); + m_oldModelManager->AddModelReference("teen38c.mod", false, rank); // propeller + obj->SetPartPosition(2, Math::Vector(0.0f, 0.0f, 0.0f)); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 2.0f, 0.0f), 10.0f)); + obj->CreateShadowCircle(15.0f, 0.5f*fShadow); + } + + if ( type == OBJECT_TEEN39 ) // potted plant? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen39.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 8.5f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 2.0f, 0.0f), 8.5f)); + obj->CreateShadowCircle(10.0f, 1.0f*fShadow); + } + + if ( type == OBJECT_TEEN40 ) // balloon? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen40.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 5.0f, 0.0f), 11.0f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 14.0f, 0.0f), 15.0f)); + obj->CreateShadowCircle(15.0f, 0.7f*fShadow); + } + + if ( type == OBJECT_TEEN41 ) // fence? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen41.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + } + + if ( type == OBJECT_TEEN42 ) // clover? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen42.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 2.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(15.0f, 0.4f*fShadow); + } + + if ( type == OBJECT_TEEN43 ) // clover? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen43.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 2.0f, SOUND_BOUM, 0.10f)); + obj->CreateShadowCircle(15.0f, 0.4f*fShadow); + } + + if ( type == OBJECT_TEEN44 ) // car? + { + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); + obj->SetObjectRank(0, rank); + m_oldModelManager->AddModelReference("teen44.mod", false, rank); + obj->SetPosition(pos); + obj->SetRotationY(angle); + + obj->AddCrashSphere(CrashSphere(Math::Vector(0.0f, 10.0f, 0.0f), 55.0f, SOUND_BOUM, 0.10f)); + obj->SetCameraCollisionSphere(Math::Sphere(Math::Vector(0.0f, 10.0f, 0.0f), 55.0f)); + obj->CreateShadowCircle(55.0f, 1.0f*fShadow); + } + + pos = obj->GetPosition(); + obj->SetPosition(pos); // to display the shadows immediately + + if ( floorAdjust ) + { + obj->SetFloorHeight(0.0f); + obj->FloorAdjust(); + } + + AddObjectAuto(obj.get()); + + pos = obj->GetPosition(); + pos.y += height; + obj->SetPosition(pos); + + return std::move(obj); +} + // Creates a crystal placed on the ground. CObjectUPtr CObjectFactory::CreateQuartz(const ObjectCreateParams& params) @@ -1719,6 +2559,12 @@ void CObjectFactory::AddObjectAuto(COldObject* obj) { objAuto = MakeUnique(obj); } + if ( type == OBJECT_TEEN36 || // trunk? + type == OBJECT_TEEN37 || // boat? + type == OBJECT_TEEN38 ) // fan? + { + objAuto.reset(new CAutoKid(obj)); + } if (objAuto != nullptr) { diff --git a/src/object/object_factory.h b/src/object/object_factory.h index c48b06d5..eed5c818 100644 --- a/src/object/object_factory.h +++ b/src/object/object_factory.h @@ -62,6 +62,7 @@ private: CObjectUPtr CreateBarrier(const ObjectCreateParams& params); CObjectUPtr CreatePlant(const ObjectCreateParams& params); CObjectUPtr CreateMushroom(const ObjectCreateParams& params); + CObjectUPtr CreateTeen(const ObjectCreateParams& params); CObjectUPtr CreateQuartz(const ObjectCreateParams& params); CObjectUPtr CreateRoot(const ObjectCreateParams& params); CObjectUPtr CreateHome(const ObjectCreateParams& params); diff --git a/src/object/object_type.h b/src/object/object_type.h index ea4e8f3b..2186665f 100644 --- a/src/object/object_type.h +++ b/src/object/object_type.h @@ -165,6 +165,51 @@ enum ObjectType 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_QUARTZ0 = 700, //! < Quartz0 OBJECT_QUARTZ1 = 701, //! < Quartz1 OBJECT_QUARTZ2 = 702, //! < Quartz2 diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 2df77bb4..d327c7a1 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -732,7 +732,8 @@ void COldObject::SetType(ObjectType type) m_type == OBJECT_ANT || m_type == OBJECT_WORM || m_type == OBJECT_SPIDER || - m_type == OBJECT_BEE ) + m_type == OBJECT_BEE || + m_type == OBJECT_TEEN28 ) { m_implementedInterfaces[static_cast(ObjectInterfaceType::Damageable)] = true; m_implementedInterfaces[static_cast(ObjectInterfaceType::Destroyable)] = true; diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index 3b6e6ef3..f761dba8 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -363,11 +363,8 @@ bool CTaskTerraform::Terraform() type = pObj->GetType(); if ( type == OBJECT_NULL ) continue; - if ( false ) + if ( type == OBJECT_TEEN34 ) // stone? { - // This was used by Ceebot-Teen to destroy objects hit by the Thumper - // The old Teen objects are removed, but this code might be reused at some point, e.g. to add destruction of resources like empty batteries - dist = Math::Distance(m_terraPos, pObj->GetPosition()); if ( dist > 20.0f ) continue; diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index c01b0eca..dc491c55 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -54,6 +54,7 @@ const char* GetObjectName(ObjectType type) if ( type == OBJECT_TARGET2 ) return "Target2"; if ( type == OBJECT_START ) return "StartArea"; if ( type == OBJECT_END ) return "GoalArea"; + if ( type == OBJECT_TEEN34 ) return "Stone"; if ( type == OBJECT_STONE ) return "TitaniumOre"; if ( type == OBJECT_URANIUM ) return "UraniumOre"; if ( type == OBJECT_METAL ) return "Titanium"; diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 1e964040..c80c631d 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -619,6 +619,18 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo dim.x *= 1.4f; dim.y *= 1.4f; } + if ( type == OBJECT_TEEN28 ) // bottle? + { + dim.x *= 3.0f; + dim.y *= 3.0f; + bHilite = true; + } + if ( type == OBJECT_TEEN34 ) // stone? + { + dim.x *= 2.0f; + dim.y *= 2.0f; + bHilite = true; + } if ( color == MAPCOLOR_MOVE && bSelect ) { @@ -868,6 +880,8 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, if ( type == OBJECT_SPIDER ) icon = 31; if ( type == OBJECT_BEE ) icon = 31; if ( type == OBJECT_WORM ) icon = 31; + if ( type == OBJECT_TEEN28 ) icon = 48; // bottle + if ( type == OBJECT_TEEN34 ) icon = 48; // stone if ( icon == -1 ) return; m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); @@ -1187,7 +1201,9 @@ void CMap::UpdateObject(CObject* pObj) type == OBJECT_HUSTON || type == OBJECT_TARGET1 || type == OBJECT_START || - type == OBJECT_END ) // stationary object? + type == OBJECT_END || // stationary object? + type == OBJECT_TEEN28 || // bottle? + type == OBJECT_TEEN34 ) // stone? { color = MAPCOLOR_FIX; } @@ -1264,7 +1280,13 @@ void CMap::UpdateObject(CObject* pObj) if (!m_fixImage.empty() && !m_bDebug) // map with still image? { - if ( color != MAPCOLOR_MOVE ) return; + if ( (type == OBJECT_TEEN28 || + type == OBJECT_TEEN34 ) && + m_mode == 0 ) return; + + if ( type != OBJECT_TEEN28 && + type != OBJECT_TEEN34 && + color != MAPCOLOR_MOVE ) return; } if ( pObj->Implements(ObjectInterfaceType::Controllable) && dynamic_cast(pObj)->GetSelect() ) From 94b3f8298827d8474cc3f6a509055050d1207d1e Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 29 Sep 2015 20:55:51 +0200 Subject: [PATCH 019/360] Fix colobot-lint issues in restored code --- src/object/auto/autokid.cpp | 35 +++++++++++++++++++---------------- src/object/auto/autokid.h | 20 ++++++++------------ src/object/object_factory.cpp | 4 ++-- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/object/auto/autokid.cpp b/src/object/auto/autokid.cpp index 2cdf3238..7206d7bf 100644 --- a/src/object/auto/autokid.cpp +++ b/src/object/auto/autokid.cpp @@ -1,7 +1,7 @@ /* * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot * * 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 @@ -53,9 +53,9 @@ CAutoKid::~CAutoKid() // Destroys the object. -void CAutoKid::DeleteObject(bool bAll) +void CAutoKid::DeleteObject(bool all) { - CAuto::DeleteObject(bAll); + CAuto::DeleteObject(all); } @@ -63,22 +63,20 @@ void CAutoKid::DeleteObject(bool bAll) void CAutoKid::Init() { - Math::Vector pos; - m_speed = 1.0f/1.0f; m_progress = 0.0f; m_lastParticle = 0.0f; if ( m_type == OBJECT_TEEN36 ) // trunk ? { - pos = m_object->GetPosition(); + Math::Vector pos = m_object->GetPosition(); m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f)); m_progress = Math::Mod(pos.x/10.0f, 1.0f); } if ( m_type == OBJECT_TEEN37 ) // boat? { - pos = m_object->GetPosition(); + Math::Vector pos = m_object->GetPosition(); m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f))*2.5f; m_progress = Math::Mod(pos.x/10.0f, 1.0f); } @@ -88,7 +86,7 @@ void CAutoKid::Init() if ( m_soundChannel == -1 ) { //? m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 1.0f, 0.5f, true); - m_bSilent = false; + m_silent = false; } } } @@ -98,27 +96,24 @@ void CAutoKid::Init() bool CAutoKid::EventProcess(const Event &event) { - Math::Vector vib, pos, speed; - Math::Point dim; - CAuto::EventProcess(event); if ( m_soundChannel != -1 ) { if ( m_engine->GetPause() ) { - if ( !m_bSilent ) + if ( !m_silent ) { m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.1f, SOPER_CONTINUE); - m_bSilent = true; + m_silent = true; } } else { - if ( m_bSilent ) + if ( m_silent ) { m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 0.1f, SOPER_CONTINUE); - m_bSilent = false; + m_silent = false; } } } @@ -130,6 +125,7 @@ bool CAutoKid::EventProcess(const Event &event) if ( m_type == OBJECT_TEEN36 ) // trunk? { + Math::Vector vib; vib.x = 0.0f; vib.y = sinf(m_progress)*1.0f; vib.z = 0.0f; @@ -144,13 +140,16 @@ bool CAutoKid::EventProcess(const Event &event) { m_lastParticle = m_time; + Math::Vector pos; pos = m_object->GetPosition(); pos.y = m_water->GetLevel()+1.0f; pos.x += (Math::Rand()-0.5f)*50.0f; pos.z += (Math::Rand()-0.5f)*50.0f; + Math::Vector speed; speed.y = 0.0f; speed.x = 0.0f; speed.z = 0.0f; + Math::Point dim; dim.x = 50.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f); @@ -159,6 +158,7 @@ bool CAutoKid::EventProcess(const Event &event) if ( m_type == OBJECT_TEEN37 ) // boat? { + Math::Vector vib; vib.x = 0.0f; vib.y = sinf(m_progress)*1.0f; vib.z = 0.0f; @@ -173,13 +173,16 @@ bool CAutoKid::EventProcess(const Event &event) { m_lastParticle = m_time; + Math::Vector pos; pos = m_object->GetPosition(); pos.y = m_water->GetLevel()+1.0f; pos.x += (Math::Rand()-0.5f)*20.0f; pos.z += (Math::Rand()-0.5f)*20.0f; + Math::Vector speed; speed.y = 0.0f; speed.x = 0.0f; speed.z = 0.0f; + Math::Point dim; dim.x = 20.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f); diff --git a/src/object/auto/autokid.h b/src/object/auto/autokid.h index 605587c9..83927222 100644 --- a/src/object/auto/autokid.h +++ b/src/object/auto/autokid.h @@ -1,7 +1,7 @@ /* * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot * * 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 @@ -17,8 +17,6 @@ * along with this program. If not, see http://gnu.org/licenses */ -// autokid.h - #pragma once @@ -31,18 +29,16 @@ public: CAutoKid(COldObject* object); ~CAutoKid(); - void DeleteObject(bool bAll=false); + void DeleteObject(bool all = false); void Init(); bool EventProcess(const Event &event); Error GetError(); protected: - -protected: - float m_speed; - float m_progress; - float m_lastParticle; - int m_soundChannel; - bool m_bSilent; + float m_speed = 0.0f; + float m_progress = 0.0f; + float m_lastParticle = 0.0f; + int m_soundChannel = 0; + bool m_silent = false; }; diff --git a/src/object/object_factory.cpp b/src/object/object_factory.cpp index b8f86f4c..d39644a4 100644 --- a/src/object/object_factory.cpp +++ b/src/object/object_factory.cpp @@ -903,7 +903,7 @@ CObjectUPtr CObjectFactory::CreateTeen(const ObjectCreateParams& params) ObjectType type = params.type; int option = params.option; - COldObjectUPtr obj{new COldObject(params.id)}; + COldObjectUPtr obj = MakeUnique(params.id); obj->SetType(type); obj->SetOption(option); @@ -2563,7 +2563,7 @@ void CObjectFactory::AddObjectAuto(COldObject* obj) type == OBJECT_TEEN37 || // boat? type == OBJECT_TEEN38 ) // fan? { - objAuto.reset(new CAutoKid(obj)); + objAuto = MakeUnique(obj); } if (objAuto != nullptr) From 61a3ba2800c28557c1eefa8f2802788486a23edf Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 29 Sep 2015 21:35:29 +0200 Subject: [PATCH 020/360] Fix undefined function colobot-lint issues --- src/CBot/CBot.h | 6 ++---- src/app/system_linux.h | 2 ++ src/app/system_macosx.h | 3 +++ src/app/system_other.h | 2 ++ src/app/system_windows.h | 2 ++ src/common/singleton.h | 4 ++-- src/common/thread/resource_owning_thread.h | 1 + src/graphics/engine/water.h | 1 - src/object/task/taskgoto.h | 1 - src/script/scriptfunc.h | 1 - src/ui/mainmap.h | 3 --- src/ui/mainui.h | 1 - 12 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a45ead65..d86b2f35 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -224,7 +224,6 @@ public: bool GetRetVar(bool bRet); long GetVal(); - void SetStartError(int pos); void SetError(int n, CBotToken* token = nullptr); void SetPosError(CBotToken* token); void ResetError(int n, int start, int end); @@ -985,8 +984,8 @@ public: static CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false); private: - CBotBlock(); - CBotBlock(const CBotBlock &); + CBotBlock() = delete; + CBotBlock(const CBotBlock &) = delete; }; @@ -1071,7 +1070,6 @@ public: bool Execute(CBotStack* &pj) override; void RestoreState(CBotStack* &pj, bool bMain) override; bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); - bool Execute2Var(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep); void RestoreStateVar(CBotStack* &pj, bool bMain) override; }; diff --git a/src/app/system_linux.h b/src/app/system_linux.h index bc68e32e..bbecc9da 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -26,6 +26,7 @@ #include +//@colobot-lint-exclude UndefinedFunctionRule struct SystemTimeStamp { @@ -50,3 +51,4 @@ private: bool m_zenityAvailable = false; }; +//@end-colobot-lint-exclude diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h index 228c628d..ed27203e 100644 --- a/src/app/system_macosx.h +++ b/src/app/system_macosx.h @@ -25,6 +25,8 @@ #include "app/system.h" #include "app/system_other.h" +//@colobot-lint-exclude UndefinedFunctionRule + class CSystemUtilsMacOSX : public CSystemUtilsOther { public: @@ -41,3 +43,4 @@ private: std::string m_dataPath; }; +//@end-colobot-lint-exclude diff --git a/src/app/system_other.h b/src/app/system_other.h index 32437c44..03ba1965 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -28,6 +28,7 @@ #include +//@colobot-lint-exclude UndefinedFunctionRule struct SystemTimeStamp { @@ -51,3 +52,4 @@ public: void Usleep(int usec) override; }; +//@end-colobot-lint-exclude diff --git a/src/app/system_windows.h b/src/app/system_windows.h index 042b83c7..83c1e01c 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -24,6 +24,7 @@ #include "app/system.h" +//@colobot-lint-exclude UndefinedFunctionRule struct SystemTimeStamp { @@ -52,3 +53,4 @@ protected: long long m_counterFrequency = 0; }; +//@end-colobot-lint-exclude diff --git a/src/common/singleton.h b/src/common/singleton.h index 13c47228..9cda16da 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -69,7 +69,7 @@ public: #endif private: - CSingleton& operator=(const CSingleton &); - CSingleton(const CSingleton &); + CSingleton& operator=(const CSingleton &) = delete; + CSingleton(const CSingleton &) = delete; }; diff --git a/src/common/thread/resource_owning_thread.h b/src/common/thread/resource_owning_thread.h index d74755ca..b722043a 100644 --- a/src/common/thread/resource_owning_thread.h +++ b/src/common/thread/resource_owning_thread.h @@ -25,6 +25,7 @@ #include #include +#include /** * \class CResourceOwningThread diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 2be10447..38704378 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -75,7 +75,6 @@ public: CWater(CEngine* engine); virtual ~CWater(); - void SetDevice(CDevice* device); bool EventProcess(const Event &event); //! Removes all the water void Flush(); diff --git a/src/object/task/taskgoto.h b/src/object/task/taskgoto.h index 80536209..a2d9c348 100644 --- a/src/object/task/taskgoto.h +++ b/src/object/task/taskgoto.h @@ -106,7 +106,6 @@ protected: Error BeamExplore(const Math::Vector &prevPos, const Math::Vector &curPos, const Math::Vector &goalPos, float goalRadius, float angle, int nbDiv, float step, int i, int nbIter); Math::Vector BeamPoint(const Math::Vector &startPoint, const Math::Vector &goalPoint, float angle, float step); - void BitmapDebug(const Math::Vector &min, const Math::Vector &max, const Math::Vector &start, const Math::Vector &goal); bool BitmapTestLine(const Math::Vector &start, const Math::Vector &goal, float stepAngle, bool bSecond); void BitmapObject(); void BitmapTerrain(const Math::Vector &min, const Math::Vector &max); diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index b78b55fc..e01cf7a4 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -125,7 +125,6 @@ private: static bool rMove(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rTurn(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rGoto(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rFind(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rGrab(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDrop(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rSniff(CBotVar* var, CBotVar* result, int& exception, void* user); diff --git a/src/ui/mainmap.h b/src/ui/mainmap.h index b80e9a47..5f903c99 100644 --- a/src/ui/mainmap.h +++ b/src/ui/mainmap.h @@ -58,9 +58,6 @@ public: void SetToy(bool bToy); void SetFixParam(float zoom, float ox, float oy, float angle, int mode, bool bDebug); -protected: - void CenterMap(); - protected: CEventQueue* m_event; Gfx::CEngine* m_engine; diff --git a/src/ui/mainui.h b/src/ui/mainui.h index da41a1de..f2477f3a 100644 --- a/src/ui/mainui.h +++ b/src/ui/mainui.h @@ -64,7 +64,6 @@ class CMainUserInterface public: CMainUserInterface(); ~CMainUserInterface(); - void Create(); CMainDialog* GetDialog(); From 49ee00d90d01d63fc1baaf8596d589162e839034 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 28 Sep 2015 15:39:23 -0700 Subject: [PATCH 021/360] fix MacOSX install instruction and compilation Signed-off-by: Victor Vieux --- INSTALL-MacOSX.md | 2 +- src/common/config.h.cmake | 6 ------ src/ui/controls/edit.cpp | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/INSTALL-MacOSX.md b/INSTALL-MacOSX.md index de3b78b0..5d2b45c7 100644 --- a/INSTALL-MacOSX.md +++ b/INSTALL-MacOSX.md @@ -8,7 +8,7 @@ After installing Developer Command Line Tools, you should have basic tools like ``` And then: ```bash - brew install cmake sdl sdl_image sdl_ttf boost glew physfs flac libsndfile libvorbis vorbis-tools gettext libicns librsvg wget + brew install cmake sdl2 sdl2_image sdl2_ttf boost glew physfs flac libsndfile libvorbis vorbis-tools gettext libicns librsvg wget ``` Gettext is installed in separate directory without adding the files to system path, so in order to get it working normally, you should call also: ```bash diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 2d3dbe1e..a4bc9f22 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -16,13 +16,7 @@ #cmakedefine OPENAL_SOUND -#cmakedefine USE_SDL_MAIN @USE_SDL_MAIN@ - -#ifdef USE_SDL_MAIN -#define SDL_MAIN_FUNC SDL_main -#else #define SDL_MAIN_FUNC main -#endif #cmakedefine PORTABLE @PORTABLE@ diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index c2c67782..200a56b3 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -304,7 +304,7 @@ bool CEdit::EventProcess(const Event &event) { bShift = ( (event.kmodState & KEY_MOD(SHIFT) ) != 0 ); #if PLATFORM_MACOSX - bControl = ( (event.kmodState & KEY_MOD(META) ) != 0); + bControl = ( (event.kmodState & KEY_MOD(GUI) ) != 0); #else bControl = ( (event.kmodState & KEY_MOD(CTRL) ) != 0); #endif From 6e1504d7a515000a24c95ce01be1f2db860330c0 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 29 Sep 2015 22:39:08 +0200 Subject: [PATCH 022/360] Further cleanup USE_SDL_MAIN --- CMakeLists.txt | 3 --- cmake/msys.cmake | 1 - src/app/main.cpp | 2 +- src/common/config.h.cmake | 2 -- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 501982cc..a45ae6d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,8 +94,6 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") # Platform-dependent implementation of system.h set(SYSTEM_CPP_MODULE "system_macosx.cpp") - - set(USE_SDL_MAIN 1) # fixes SDL_main else() message(STATUS "Build for other system") set(PLATFORM_WINDOWS 0) @@ -291,7 +289,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") message(STATUS "Adding MSVC-specific options") set(CBOT_STATIC 1) # only this works for some reason - set(USE_SDL_MAIN 1) # fixes SDL_main set(WINGETOPT 1) # use wingetopt library endif() diff --git a/cmake/msys.cmake b/cmake/msys.cmake index 230ceb63..8a622335 100644 --- a/cmake/msys.cmake +++ b/cmake/msys.cmake @@ -7,5 +7,4 @@ if (MSYS AND (NOT MXE)) set(PLATFORM_OTHER 0) set(COLOBOT_CXX_FLAGS "${COLOBOT_CXX_FLAGS} -U__STRICT_ANSI__") # fixes putenv() - set(USE_SDL_MAIN 1) # fixes SDL_main endif() diff --git a/src/app/main.cpp b/src/app/main.cpp index cf0283ca..0845d5ad 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -89,7 +89,7 @@ The current layout is the following: extern "C" { -int SDL_MAIN_FUNC(int argc, char *argv[]) +int main(int argc, char *argv[]) { CLogger logger; // single instance of logger diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index a4bc9f22..b4767724 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -16,8 +16,6 @@ #cmakedefine OPENAL_SOUND -#define SDL_MAIN_FUNC main - #cmakedefine PORTABLE @PORTABLE@ #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" From 3a7aa4ae9cbd61981a8a2d8f455f83753eef8ebc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Sep 2015 18:14:53 +0200 Subject: [PATCH 023/360] Restored CreateSpot code in Teen objects --- data | 2 +- src/object/object_factory.cpp | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/data b/data index d90d0da9..68682ab0 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit d90d0da944ad77e461dbc7b623491016f952fc21 +Subproject commit 68682ab0c8c5918b41577e8713c63a6cf90293ef diff --git a/src/object/object_factory.cpp b/src/object/object_factory.cpp index d39644a4..090d0092 100644 --- a/src/object/object_factory.cpp +++ b/src/object/object_factory.cpp @@ -1136,14 +1136,12 @@ CObjectUPtr CObjectFactory::CreateTeen(const ObjectCreateParams& params) m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(20.0f, 20.0f), Gfx::PARTISELY, 1.0f, 0.0f, 0.0f); pos = Math::Transform(*mat, Math::Vector(-65.0f, 40.0f, 0.0f)); - /* TODO: ? Gfx::Color color; color.r = 4.0f; color.g = 2.0f; color.b = 0.0f; // yellow-orange color.a = 0.0f; - m_main->CreateSpot(pos, color); - */ + CRobotMain::GetInstancePointer()->CreateSpot(pos, color); // TODO: Don't use singleton } if ( type == OBJECT_TEEN12 ) // coke @@ -1399,15 +1397,13 @@ CObjectUPtr CObjectFactory::CreateTeen(const ObjectCreateParams& params) pos = Math::Transform(*mat, Math::Vector(0.0f, 50.0f, 0.0f)); m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(100.0f, 100.0f), Gfx::PARTISELY, 1.0f, 0.0f, 0.0f); - /* TODO: ? pos = Math::Transform(*mat, Math::Vector(0.0f, 50.0f, 0.0f)); Gfx::Color color; color.r = 4.0f; color.g = 2.0f; color.b = 0.0f; // yellow-orange color.a = 0.0f; - m_main->CreateSpot(pos, color); - */ + CRobotMain::GetInstancePointer()->CreateSpot(pos, color); // TODO: Don't use singleton } if ( type == OBJECT_TEEN27 ) // large plant? From 2f0ec3fe75a22ccf7af9c8c8979981439e06fa33 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Sep 2015 20:21:25 +0200 Subject: [PATCH 024/360] Fixed lava particle effects (#659) --- data | 2 +- src/graphics/engine/water.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/data b/data index 68682ab0..bbfc7d0e 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 68682ab0c8c5918b41577e8713c63a6cf90293ef +Subproject commit bbfc7d0ea4e90b9d9694a3812874afeabc7bbbfb diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 4fd94755..28b64f8f 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -135,7 +135,10 @@ void CWater::LavaFrame(float rTime) void CWater::VaporFlush() { - m_vapors.clear(); + for (int i = 0; i < static_cast( m_vapors.size() ); i++) + { + m_vapors[i].used = false; + } } bool CWater::VaporCreate(ParticleType type, Math::Vector pos, float delay) From 95f1e3f19af3dba078e8ce69fdeebe9890513aef Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Sep 2015 20:31:09 +0200 Subject: [PATCH 025/360] Fixed water/lava moving and waves (#659) --- src/graphics/engine/water.cpp | 1 - src/level/robotmain.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index 28b64f8f..84bc9694 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -45,7 +45,6 @@ namespace Gfx namespace { const int WATERLINE_PREALLOCATE_COUNT = 500; -// TODO: remove the limit? const int VAPOR_SIZE = 10; } // anonymous namespace diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 98da4e84..ba182b56 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -3222,8 +3222,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (line->GetCommand() == "TerrainWater" && !resetObject) { Math::Vector pos; - pos.x = line->GetParam("moxeX")->AsFloat(0.0f); - pos.y = line->GetParam("moxeY")->AsFloat(0.0f); + pos.x = line->GetParam("moveX")->AsFloat(0.0f); + pos.y = line->GetParam("moveY")->AsFloat(0.0f); pos.z = pos.x; m_water->Create(line->GetParam("air")->AsWaterType(Gfx::WATER_TT), line->GetParam("water")->AsWaterType(Gfx::WATER_TT), From d03ce19fbe085cc38a74f80034ea0bf1c8844519 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Sep 2015 20:54:36 +0200 Subject: [PATCH 026/360] Fixed #639 --- src/object/old_object.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index d327c7a1..ca68afee 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -286,6 +286,22 @@ void COldObject::DeleteObject(bool bAll) } } + if (!bAll) + { + if (m_power != nullptr) + { + if (m_power->Implements(ObjectInterfaceType::Old)) + dynamic_cast(m_power)->DeleteObject(bAll); + m_power = nullptr; + } + if (m_cargo != nullptr) + { + if (m_cargo->Implements(ObjectInterfaceType::Old)) + dynamic_cast(m_cargo)->DeleteObject(bAll); + m_cargo = nullptr; + } + } + if ( !bAll ) m_main->CreateShortcuts(); } @@ -536,19 +552,6 @@ void COldObject::DestroyObject(DestructionType type) m_team = 0; // Back to neutral on destruction - if (m_power != nullptr) - { - if (m_power->Implements(ObjectInterfaceType::Old)) - dynamic_cast(m_power)->m_transporter = nullptr; - m_power = nullptr; - } - if (m_cargo != nullptr) - { - if (m_cargo->Implements(ObjectInterfaceType::Old)) - dynamic_cast(m_cargo)->m_transporter = nullptr; - m_cargo = nullptr; - } - if ( m_botVar != nullptr ) { if ( Implements(ObjectInterfaceType::Transportable) ) // (*) From 58035f3cd1ef6d5f89ae2cd116d487ba065007a5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Wed, 30 Sep 2015 21:41:00 +0200 Subject: [PATCH 027/360] Fixed rendering camera overlay color, closes #157 --- src/graphics/engine/engine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index daa0f39d..f5a6dc21 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -4580,6 +4580,7 @@ void CEngine::DrawOverColor() m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); VertexCol vertex[4] = { From 3815ef0bd627347c99abf86ccaf3bbae0e7291aa Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 1 Oct 2015 18:55:41 +0200 Subject: [PATCH 028/360] Refactored CPauseManager (again) --- src/app/pausemanager.cpp | 84 +++++++++++++++------------------- src/app/pausemanager.h | 57 ++++++++++++++++------- src/graphics/engine/engine.cpp | 16 +++---- src/graphics/engine/engine.h | 13 ++++-- src/level/robotmain.cpp | 71 ++++++++++++++-------------- src/level/robotmain.h | 6 +-- src/ui/displayinfo.cpp | 4 +- src/ui/mainshort.cpp | 7 ++- src/ui/studio.cpp | 28 ++++++------ src/ui/studio.h | 1 + 10 files changed, 150 insertions(+), 137 deletions(-) diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index 1ee2b9cd..ba867a69 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -29,31 +29,32 @@ CPauseManager::CPauseManager() -{} +{ + m_main = CRobotMain::GetInstancePointer(); +} CPauseManager::~CPauseManager() {} -ActivePause* CPauseManager::ActivatePause(PauseType type) +ActivePause* CPauseManager::ActivatePause(PauseType type, PauseMusic music) { - assert(type != PAUSE_NONE); - GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); - auto pause = std::unique_ptr(new ActivePause(type)); // TODO: Can't use MakeUnique here because the constructor is private + //GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); + auto pause = std::unique_ptr(new ActivePause(type, music)); // TODO: Can't use MakeUnique here because the constructor is private ActivePause* ptr = pause.get(); m_activePause.push_back(std::move(pause)); - UpdatePause(); + Update(); return ptr; } void CPauseManager::DeactivatePause(ActivePause* pause) { if (pause == nullptr) return; - GetLogger()->Debug("Deactivated pause mode - %s\n", GetPauseName(pause->type).c_str()); + //GetLogger()->Debug("Deactivated pause mode - %s\n", GetPauseName(pause->type).c_str()); m_activePause.erase(std::remove_if( m_activePause.begin(), m_activePause.end(), [&](const std::unique_ptr& x) { return x.get() == pause; }) ); - UpdatePause(); + Update(); } void CPauseManager::FlushPause() @@ -61,49 +62,38 @@ void CPauseManager::FlushPause() m_activePause.clear(); } -bool CPauseManager::IsPause() +PauseType CPauseManager::GetPause() { - return m_activePause.size() > 0; -} - -PauseType CPauseManager::GetPauseType() -{ - if (m_activePause.size() > 0) - return m_activePause[m_activePause.size()-1]->type; - return PAUSE_NONE; -} - -void CPauseManager::UpdatePause() -{ - PauseType type = GetPauseType(); - - if (type != PAUSE_NONE) + PauseType current = PAUSE_NONE; + for(auto& pause : m_activePause) { - GetLogger()->Info("Game paused - %s\n", GetPauseName(type).c_str()); + current |= pause->type; } - else - { - GetLogger()->Info("Game resumed\n"); - } - - CRobotMain::GetInstancePointer()->UpdatePause(type); + return current; } -std::string CPauseManager::GetPauseName(PauseType pause) +bool CPauseManager::IsPauseType(PauseType type) { - switch(pause) - { - 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"; - case PAUSE_CODE_BATTLE_LOCK: return "Code battle lock"; - default: assert(false); // Should never happen - } - return "?"; + PauseType current = GetPause(); + return (current & type) == type; +} + +void CPauseManager::Update() +{ + m_main->UpdatePause(GetPause()); //TODO + + PauseMusic music = PAUSE_MUSIC_NONE; + for(int i = m_activePause.size()-1; i >= 0; i--) + { + if (m_activePause[i]->music != PAUSE_MUSIC_NONE) + { + music = m_activePause[i]->music; + break; + } + } + if (music != m_lastPauseMusic) + { + m_main->UpdatePauseMusic(music); + m_lastPauseMusic = music; + } } diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h index 581d74a5..b6c261ff 100644 --- a/src/app/pausemanager.h +++ b/src/app/pausemanager.h @@ -27,19 +27,40 @@ #include #include +class CRobotMain; + enum PauseType { PAUSE_NONE = 0, - PAUSE_USER, - PAUSE_SATCOM, - PAUSE_SATCOMMOVIE, - PAUSE_DIALOG, - PAUSE_EDITOR, - PAUSE_VISIT, - PAUSE_CHEAT, - PAUSE_PHOTO, - PAUSE_CODE_BATTLE_LOCK + PAUSE_ENGINE = (1<<0), //!< pause all the CEngine classes + PAUSE_HIDE_SHORTCUTS = (1<<1), //!< hide the shortcuts + PAUSE_PHOTO = (1<<2), //!< photo mode, TODO: remove + PAUSE_OBJECT_UPDATES = (1<<3), //!< do not send events to objects + PAUSE_MUTE_SOUND = (1<<4), //!< mute sound +}; +inline PauseType& operator|=(PauseType& a, const PauseType& b) +{ + return a = static_cast(static_cast(a) | static_cast(b)); +} +inline PauseType operator|(PauseType a, const PauseType& b) +{ + return a |= b; +} +inline PauseType& operator&=(PauseType& a, const PauseType& b) +{ + return a = static_cast(static_cast(a) & static_cast(b)); +} +inline PauseType operator&(PauseType a, const PauseType& b) +{ + return a &= b; +} + +enum PauseMusic +{ + PAUSE_MUSIC_NONE = 0, + PAUSE_MUSIC_EDITOR = 1, + PAUSE_MUSIC_SATCOM = 2, }; struct ActivePause @@ -47,14 +68,16 @@ struct ActivePause private: friend class CPauseManager; - explicit ActivePause(PauseType type) + explicit ActivePause(PauseType type, PauseMusic music = PAUSE_MUSIC_NONE) : type(type) + , music(music) {} ActivePause(const ActivePause&) = delete; ActivePause& operator=(const ActivePause&) = delete; PauseType type; + PauseMusic music; }; class CPauseManager @@ -63,19 +86,21 @@ public: CPauseManager(); ~CPauseManager(); - ActivePause* ActivatePause(PauseType type); + ActivePause* ActivatePause(PauseType type, PauseMusic music = PAUSE_MUSIC_NONE); void DeactivatePause(ActivePause* pause); void FlushPause(); - bool IsPause(); - PauseType GetPauseType(); + PauseType GetPause(); + bool IsPauseType(PauseType type); private: - void UpdatePause(); - - static std::string GetPauseName(PauseType pause); + //static std::string GetPauseName(PauseType pause); + void Update(); private: + CRobotMain* m_main; + std::vector> m_activePause; + PauseMusic m_lastPauseMusic = PAUSE_MUSIC_NONE; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index f5a6dc21..51eddf0d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -22,7 +22,6 @@ #include "app/app.h" #include "app/input.h" -#include "app/pausemanager.h" #include "app/system.h" #include "common/image.h" @@ -89,7 +88,6 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_planet = nullptr; m_sound = nullptr; m_terrain = nullptr; - m_pause = nullptr; m_showStats = false; @@ -272,11 +270,6 @@ CCloud* CEngine::GetCloud() return m_cloud.get(); } -CPauseManager* CEngine::GetPauseManager() -{ - return m_pause.get(); -} - void CEngine::SetTerrain(CTerrain* terrain) { m_terrain = terrain; @@ -303,7 +296,6 @@ bool CEngine::Create() m_cloud = MakeUnique(this); m_lightning = MakeUnique(this); m_planet = MakeUnique(this); - m_pause = MakeUnique(); m_lightMan->SetDevice(m_device); m_particle->SetDevice(m_device); @@ -353,7 +345,6 @@ void CEngine::Destroy() m_shadowMap = Texture(); } - m_pause.reset(); m_lightMan.reset(); m_text.reset(); m_particle.reset(); @@ -491,9 +482,14 @@ void CEngine::WriteScreenShotThread(std::unique_ptr data) CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_WRITE_SCENE_FINISHED)); } +void CEngine::SetPause(bool pause) +{ + m_pause = pause; +} + bool CEngine::GetPause() { - return m_pause->IsPause(); + return m_pause; } void CEngine::SetShowStats(bool show) diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 67f2c408..c95dcb8d 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -645,8 +645,6 @@ public: CPlanet* GetPlanet(); //! Returns the fog manager CCloud* GetCloud(); - //! Returns the pause manager - CPauseManager* GetPauseManager(); //! Sets the terrain object void SetTerrain(CTerrain* terrain); @@ -676,8 +674,11 @@ public: void WriteScreenShot(const std::string& fileName); - //! Get pause mode - TEST_VIRTUAL bool GetPause(); + //@{ + //! Management of animation pause mode + void SetPause(bool pause); + bool GetPause(); + //@} //@{ //! Management of displaying statistic information @@ -1287,7 +1288,6 @@ protected: std::unique_ptr m_cloud; std::unique_ptr m_lightning; std::unique_ptr m_planet; - std::unique_ptr m_pause; std::unique_ptr m_pyroManager; //! Last encountered error @@ -1465,6 +1465,9 @@ protected: std::string m_timerText; std::unordered_map m_staticMeshBaseObjects; + + //! Pause the animation updates + bool m_pause = false; }; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index ba182b56..9e086e8d 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -135,11 +135,11 @@ CRobotMain::CRobotMain() m_cloud = m_engine->GetCloud(); m_lightning = m_engine->GetLightning(); m_planet = m_engine->GetPlanet(); - m_pause = m_engine->GetPauseManager(); m_input = CInput::GetInstancePointer(); m_modelManager = MakeUnique(); m_settings = MakeUnique(); + m_pause = MakeUnique(); m_interface = MakeUnique(); m_terrain = MakeUnique(); m_camera = MakeUnique(); @@ -193,7 +193,6 @@ CRobotMain::CRobotMain() m_editLock = false; m_editFull = false; m_hilite = false; - m_freePhoto = false; m_selectInsect = false; m_showSoluce = false; @@ -294,6 +293,11 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() return m_displayText.get(); } +CPauseManager* CRobotMain::GetPauseManager() +{ + return m_pause.get(); +} + void CRobotMain::ResetAfterVideoConfigChanged() { // Recreate the interface (needed if the aspect ratio changes) @@ -431,11 +435,12 @@ void CRobotMain::ChangePhase(Phase phase) m_movieLock = false; m_satComLock = false; m_editLock = false; - m_freePhoto = false; m_resetCreate = false; m_infoObject = nullptr; m_pause->FlushPause(); + m_freePhotoPause = nullptr; + m_userPause = nullptr; FlushDisplayInfo(); m_engine->SetRankView(0); m_terrain->FlushRelief(); @@ -713,7 +718,7 @@ bool CRobotMain::ProcessEvent(Event &event) if (pe == nullptr) return false; pe->SetState(Ui::STATE_VISIBLE); m_interface->SetFocus(pe); - if (m_phase == PHASE_SIMUL) m_cmdEditPause = m_pause->ActivatePause(PAUSE_CHEAT); + if (m_phase == PHASE_SIMUL) m_cmdEditPause = m_pause->ActivatePause(PAUSE_ENGINE); m_cmdEdit = true; } return false; @@ -847,9 +852,9 @@ bool CRobotMain::ProcessEvent(Event &event) { if (m_userPause == nullptr) { - if (!m_pause->IsPause()) + if (!m_pause->IsPauseType(PAUSE_ENGINE)) { - m_userPause = m_pause->ActivatePause(PAUSE_USER); + m_userPause = m_pause->ActivatePause(PAUSE_ENGINE); } } else @@ -1190,11 +1195,10 @@ void CRobotMain::ExecuteCmd(char *cmd) if (strcmp(cmd, "photo1") == 0) { - m_freePhoto = !m_freePhoto; - if (m_freePhoto) + if (m_freePhotoPause == nullptr) { m_camera->SetType(Gfx::CAM_TYPE_FREE); - m_freePhotoPause = m_pause->ActivatePause(PAUSE_PHOTO); + m_freePhotoPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_PHOTO|PAUSE_OBJECT_UPDATES); } else { @@ -1207,12 +1211,11 @@ void CRobotMain::ExecuteCmd(char *cmd) if (strcmp(cmd, "photo2") == 0) { - m_freePhoto = !m_freePhoto; - if (m_freePhoto) + if (m_freePhotoPause == nullptr) { m_camera->SetType(Gfx::CAM_TYPE_FREE); DeselectAll(); // removes the control buttons - m_freePhotoPause = m_pause->ActivatePause(PAUSE_PHOTO); + m_freePhotoPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_PHOTO|PAUSE_OBJECT_UPDATES); m_map->ShowMap(false); m_displayText->HideText(true); } @@ -1450,7 +1453,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) { m_movieInfoIndex = index; m_movie->Start(MM_SATCOMopen, 2.5f); - m_satcomMoviePause = m_pause->ActivatePause(PAUSE_SATCOMMOVIE); + m_satcomMoviePause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS); m_infoObject = DeselectAll(); // removes the control buttons m_displayText->HideText(true); return; @@ -1546,7 +1549,7 @@ void CRobotMain::StartSuspend() { m_sound->MuteAll(true); ClearInterface(); - m_suspend = m_pause->ActivatePause(PAUSE_DIALOG); + m_suspend = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND); m_engine->SetOverFront(false); // over flat behind CreateShortcuts(); @@ -1674,7 +1677,7 @@ void CRobotMain::StartDisplayVisit(EventType event) m_camera->StartVisit(m_displayText->GetVisitGoal(event), m_displayText->GetVisitDist(event)); m_displayText->SetVisit(event); - m_visitPause = m_pause->ActivatePause(PAUSE_VISIT); + m_visitPause = m_pause->ActivatePause(PAUSE_ENGINE); } //! Move the arrow to visit @@ -2408,16 +2411,16 @@ bool CRobotMain::EventFrame(const Event &event) } m_time += event.rTime; - if (!m_movieLock && !m_pause->IsPause()) + if (!m_movieLock && !m_pause->IsPauseType(PAUSE_ENGINE)) { m_gameTime += event.rTime; m_gameTimeAbsolute += m_app->GetRealRelTime() / 1e9f; } - if (!m_movieLock && !m_pause->IsPause() && m_missionTimerStarted) + if (!m_movieLock && !m_pause->IsPauseType(PAUSE_ENGINE) && m_missionTimerStarted) m_missionTimer += event.rTime; - if (!m_pause->IsPause() && m_autosave && m_gameTimeAbsolute >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) + if (!m_pause->IsPauseType(PAUSE_ENGINE) && m_autosave && m_gameTimeAbsolute >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) { if (m_levelCategory == LevelCategory::Missions || m_levelCategory == LevelCategory::FreeGame || @@ -2449,7 +2452,7 @@ bool CRobotMain::EventFrame(const Event &event) } CObject* toto = nullptr; - if (!m_freePhoto) + if (!m_pause->IsPauseType(PAUSE_OBJECT_UPDATES)) { // Advances all the robots, but not toto. for (CObject* obj : m_objMan->GetAllObjects()) @@ -2539,7 +2542,7 @@ bool CRobotMain::EventFrame(const Event &event) } // Moves edition indicator. - if (m_editLock || m_pause->IsPause()) // edition in progress? + if (m_editLock || m_pause->IsPauseType(PAUSE_ENGINE)) // edition in progress? { Ui::CControl* pc = m_interface->SearchControl(EVENT_OBJECT_EDITLOCK); if (pc != nullptr) @@ -2646,7 +2649,7 @@ bool CRobotMain::EventFrame(const Event &event) { // NOTE: It's important to do this AFTER the first update event finished processing // because otherwise all robot parts are misplaced - m_userPause = m_pause->ActivatePause(PAUSE_CODE_BATTLE_LOCK); + m_userPause = m_pause->ActivatePause(PAUSE_ENGINE); m_codeBattleInit = true; // Will start on resume } @@ -2696,7 +2699,7 @@ void CRobotMain::ShowSaveIndicator(bool show) //! Makes the event for all robots bool CRobotMain::EventObject(const Event &event) { - if (m_freePhoto) return true; + if (m_pause->IsPauseType(PAUSE_OBJECT_UPDATES)) return true; m_resetCreate = false; @@ -5516,12 +5519,6 @@ bool CRobotMain::GetEditFull() } -bool CRobotMain::GetFreePhoto() -{ - return m_freePhoto; -} - - //! Indicates whether mouse is on an friend object, on which we should not shoot void CRobotMain::SetFriendAim(bool friendAim) { @@ -5558,29 +5555,29 @@ void CRobotMain::StartMusic() void CRobotMain::UpdatePause(PauseType pause) { - m_sound->MuteAll(pause != PAUSE_NONE); + m_engine->SetPause(pause & PAUSE_ENGINE); + m_sound->MuteAll(pause & PAUSE_MUTE_SOUND); CreateShortcuts(); if (pause != PAUSE_NONE) HiliteClear(); +} - switch (pause) +void CRobotMain::UpdatePauseMusic(PauseMusic music) +{ + switch (music) { - case PAUSE_NONE: + case PAUSE_MUSIC_NONE: m_sound->StopPauseMusic(); break; - case PAUSE_EDITOR: + case PAUSE_MUSIC_EDITOR: if (m_editorTrack != "") m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); break; - case PAUSE_SATCOM: + case PAUSE_MUSIC_SATCOM: if (m_satcomTrack != "") m_sound->PlayPauseMusic(m_satcomTrack, m_satcomRepeat); break; - - default: - // Don't change music - break; } } diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 9ce4a1b7..9f943231 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -159,6 +159,7 @@ public: Gfx::CTerrain* GetTerrain(); Ui::CInterface* GetInterface(); Ui::CDisplayText* GetDisplayText(); + CPauseManager* GetPauseManager(); void CreateConfigFile(); void LoadConfigFile(); @@ -182,7 +183,6 @@ public: bool GetEditLock(); void SetEditFull(bool full); bool GetEditFull(); - bool GetFreePhoto(); void SetFriendAim(bool friendAim); bool GetFriendAim(); @@ -258,6 +258,7 @@ public: void StartMusic(); void UpdatePause(PauseType pause); + void UpdatePauseMusic(PauseMusic music); void ClearInterface(); void ChangeColor(); @@ -436,10 +437,10 @@ protected: Gfx::COldModelManager* m_oldModelManager = nullptr; Gfx::CLightManager* m_lightMan = nullptr; CSoundInterface* m_sound = nullptr; - CPauseManager* m_pause = nullptr; CInput* m_input = nullptr; std::unique_ptr m_objMan; std::unique_ptr m_movie; + std::unique_ptr m_pause; std::unique_ptr m_modelManager; std::unique_ptr m_terrain; std::unique_ptr m_camera; @@ -477,7 +478,6 @@ protected: ActivePause* m_userPause = nullptr; int m_cameraRank = 0; Gfx::Color m_color; - bool m_freePhoto = false; ActivePause* m_freePhotoPause = nullptr; bool m_cmdEdit = false; ActivePause* m_cmdEditPause = nullptr; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 5c394d80..6df5e9e7 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -69,7 +69,7 @@ CDisplayInfo::CDisplayInfo() m_main = CRobotMain::GetInstancePointer(); m_interface = m_main->GetInterface(); m_camera = m_main->GetCamera(); - m_pause = m_engine->GetPauseManager(); + m_pause = m_main->GetPauseManager(); m_bInfoMaximized = true; m_bInfoMinimized = false; @@ -363,7 +363,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_main->SetEditLock(true, false); m_main->SetEditFull(false); - m_satcomPause = m_pause->ActivatePause(PAUSE_SATCOM); + m_satcomPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_HIDE_SHORTCUTS|PAUSE_MUTE_SOUND, PAUSE_MUSIC_SATCOM); m_infoCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_INFO); diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index 13b111a4..29d6e2ea 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -106,19 +106,18 @@ bool CMainShort::CreateShortcuts() m_interface->CreateShortcut(pos, dim, 128+7, EVENT_OBJECT_MOVIELOCK); return true; } - if ( !m_main->GetFreePhoto() && + if ( !m_main->GetPauseManager()->IsPauseType(PAUSE_PHOTO) && (m_main->GetEditLock() || m_engine->GetPause()) ) // hangs during edition? { m_interface->CreateShortcut(pos, dim, 128+6, EVENT_OBJECT_EDITLOCK); } - if (m_main->GetFreePhoto() && m_main->GetSelect() == nullptr) + if (m_main->GetPauseManager()->IsPauseType(PAUSE_PHOTO) && m_main->GetSelect() == nullptr) { return true; } - PauseType pauseType = m_engine->GetPauseManager()->GetPauseType(); - if (pauseType == PAUSE_SATCOM || pauseType == PAUSE_EDITOR || pauseType == PAUSE_DIALOG) + if (m_main->GetPauseManager()->IsPauseType(PAUSE_HIDE_SHORTCUTS)) return true; // Create new shortcuts diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 31f4bc6e..b5da62f7 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -82,7 +82,7 @@ CStudio::CStudio() m_main = CRobotMain::GetInstancePointer(); m_interface = m_main->GetInterface(); m_camera = m_main->GetCamera(); - m_pause = m_engine->GetPauseManager(); + m_pause = m_main->GetPauseManager(); m_settings = CSettings::GetInstancePointer(); m_program = nullptr; @@ -356,17 +356,17 @@ bool CStudio::EventFrame(const Event &event) if (m_script->IsRunning() && (!m_script->GetStepMode() || m_script->IsContinue())) { - if (m_editorPause != nullptr) + if (m_runningPause != nullptr) { - m_pause->DeactivatePause(m_editorPause); - m_editorPause = nullptr; + m_pause->DeactivatePause(m_runningPause); + m_runningPause = nullptr; } } else { - if (m_editorPause == nullptr) + if (m_runningPause == nullptr) { - m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); + m_runningPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_MUTE_SOUND); } } @@ -578,6 +578,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra m_main->SetSpeed(1.0f); m_editCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_EDIT); + m_editorPause = m_pause->ActivatePause(PAUSE_HIDE_SHORTCUTS, PAUSE_MUSIC_EDITOR); m_bRunning = m_script->IsRunning(); m_bRealTime = m_bRunning; @@ -914,7 +915,8 @@ bool CStudio::StopEditScript(bool bCancel) m_pause->DeactivatePause(m_editorPause); m_editorPause = nullptr; - m_sound->MuteAll(false); + m_pause->DeactivatePause(m_runningPause); + m_runningPause = nullptr; m_main->SetEditLock(false, true); m_camera->SetType(m_editCamera); return true; @@ -984,22 +986,22 @@ void CStudio::UpdateFlux() { if ( m_bRealTime ) // run? { - m_pause->DeactivatePause(m_editorPause); - m_editorPause = nullptr; + m_pause->DeactivatePause(m_runningPause); + m_runningPause = nullptr; } else // step by step? { - if (m_editorPause == nullptr) + if (m_runningPause == nullptr) { - m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); + m_runningPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_MUTE_SOUND); } } } else // stop? { - if (m_editorPause == nullptr) + if (m_runningPause == nullptr) { - m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); + m_runningPause = m_pause->ActivatePause(PAUSE_ENGINE|PAUSE_MUTE_SOUND); } } } diff --git a/src/ui/studio.h b/src/ui/studio.h index cdb8cf08..3127100d 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -114,6 +114,7 @@ protected: bool m_bRunning; bool m_bRealTime; ActivePause* m_editorPause = nullptr; + ActivePause* m_runningPause = nullptr; std::string m_helpFilename; StudioDialog m_dialog; From b5e98dd6e9b67b92175e83b072d101d3392495d2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 1 Oct 2015 19:19:40 +0200 Subject: [PATCH 029/360] Removed CSettings access through CRobotMain --- src/level/robotmain.cpp | 15 --------------- src/level/robotmain.h | 3 --- src/object/old_object.cpp | 3 ++- src/ui/controls/control.cpp | 4 +++- src/ui/controls/control.h | 2 ++ 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 9e086e8d..de186d8c 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -5279,21 +5279,6 @@ char* CRobotMain::GetScriptFile() } -bool CRobotMain::GetInterfaceGlint() -{ - return m_settings->GetInterfaceGlint(); -} - -bool CRobotMain::GetSoluce4() -{ - return m_settings->GetSoluce4(); -} - -bool CRobotMain::GetMovies() -{ - return m_settings->GetMovies(); -} - bool CRobotMain::GetShowSoluce() { return m_showSoluce; diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 9f943231..a78ca4fa 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -234,9 +234,6 @@ public: char* GetScriptFile(); bool GetTrainerPilot(); bool GetFixScene(); - bool GetInterfaceGlint(); - bool GetSoluce4(); - bool GetMovies(); bool GetShowSoluce(); bool GetSceneSoluce(); bool GetShowAll(); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index ca68afee..1939f655 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -26,6 +26,7 @@ #include "common/global.h" #include "common/make_unique.h" +#include "common/settings.h" #include "common/stringutils.h" #include "graphics/engine/lightman.h" @@ -1118,7 +1119,7 @@ void COldObject::Read(CLevelParserLine* line) int i = line->GetParam("run")->AsInt(-1); if (i != -1) { - if (i != PARAM_FIXSCENE && !m_main->GetMovies()) i = 0; + if (i != PARAM_FIXSCENE && !CSettings::GetInstancePointer()->GetMovies()) i = 0; m_auto->Start(i); // starts the film } } diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index 992c43c8..3e442c28 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -23,6 +23,7 @@ #include "app/app.h" #include "common/restext.h" +#include "common/settings.h" #include "level/robotmain.h" @@ -38,6 +39,7 @@ CControl::CControl() m_engine = Gfx::CEngine::GetInstancePointer(); m_main = CRobotMain::GetInstancePointer(); m_particle = m_engine->GetParticle(); + m_settings = CSettings::GetInstancePointer(); m_eventType = EVENT_NULL; m_state = STATE_ENABLE|STATE_VISIBLE|STATE_GLINT; m_fontSize = Gfx::FONT_SIZE_SMALL; @@ -420,7 +422,7 @@ void CControl::GlintFrame(const Event &event) (m_state & STATE_ENABLE ) == 0 || (m_state & STATE_VISIBLE) == 0 ) return; - if ( !m_main->GetInterfaceGlint() ) return; + if ( !m_settings->GetInterfaceGlint() ) return; m_glintProgress += event.rTime; diff --git a/src/ui/controls/control.h b/src/ui/controls/control.h index 287d68ca..1b1bdf07 100644 --- a/src/ui/controls/control.h +++ b/src/ui/controls/control.h @@ -27,6 +27,7 @@ class CRobotMain; class CSoundInterface; +class CSettings; namespace Gfx { @@ -120,6 +121,7 @@ protected: CEventQueue* m_event; CRobotMain* m_main; CSoundInterface* m_sound; + CSettings* m_settings; Math::Point m_pos; // corner upper / left Math::Point m_dim; // dimensions From 2c7deea6a9d3c3ec629213b31e568bc4ff9c8807 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 1 Oct 2015 19:37:31 +0200 Subject: [PATCH 030/360] Removed some unused functions from CRobotMain --- src/level/robotmain.cpp | 42 +++++++------------------------------ src/level/robotmain.h | 15 ++++--------- src/script/script.cpp | 8 +++---- src/ui/object_interface.cpp | 5 ++--- src/ui/object_interface.h | 2 +- 5 files changed, 18 insertions(+), 54 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index de186d8c..0fd4439c 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2842,12 +2842,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_engine->SetSecondTexture(""); m_engine->SetForegroundName(""); - sprintf(m_title, "%s %d.%d", GetLevelCategoryDir(m_levelCategory).c_str(), m_levelChap, m_levelRank); - sprintf(m_resume, "%s %d.%d", GetLevelCategoryDir(m_levelCategory).c_str(), m_levelChap, m_levelRank); - std::string scriptNameStr; - GetResource(RES_TEXT, RT_SCRIPT_NEW, scriptNameStr); - strcpy(m_scriptName, scriptNameStr.c_str()); - m_scriptFile[0] = 0; + GetResource(RES_TEXT, RT_SCRIPT_NEW, m_scriptName); + m_scriptFile = ""; m_missionType = MISSION_NORMAL; m_codeBattleInit = false; @@ -2890,25 +2886,25 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) { if (line->GetCommand() == "Title" && !resetObject) { - strcpy(m_title, line->GetParam("text")->AsString().c_str()); + //strcpy(m_title, line->GetParam("text")->AsString().c_str()); continue; } if (line->GetCommand() == "Resume" && !resetObject) { - strcpy(m_resume, line->GetParam("text")->AsString().c_str()); + //strcpy(m_resume, line->GetParam("text")->AsString().c_str()); continue; } if (line->GetCommand() == "ScriptName" && !resetObject) { - strcpy(m_scriptName, line->GetParam("text")->AsString().c_str()); + m_scriptName = line->GetParam("text")->AsString(); continue; } if (line->GetCommand() == "ScriptFile" && !resetObject) { - strcpy(m_scriptFile, line->GetParam("name")->AsString().c_str()); + m_scriptFile = line->GetParam("name")->AsString(); continue; } @@ -5258,22 +5254,12 @@ bool CRobotMain::GetFixScene() } -char* CRobotMain::GetTitle() -{ - return m_title; -} - -char* CRobotMain::GetResume() -{ - return m_resume; -} - -char* CRobotMain::GetScriptName() +const std::string& CRobotMain::GetScriptName() { return m_scriptName; } -char* CRobotMain::GetScriptFile() +const std::string& CRobotMain::GetScriptFile() { return m_scriptFile; } @@ -5516,18 +5502,6 @@ bool CRobotMain::GetFriendAim() } -//! Management of the precision of drawing the ground -void CRobotMain::SetTracePrecision(float factor) -{ - m_engine->SetTracePrecision(factor); -} - -float CRobotMain::GetTracePrecision() -{ - return m_engine->GetTracePrecision(); -} - - //! Starts music with a mission void CRobotMain::StartMusic() { diff --git a/src/level/robotmain.h b/src/level/robotmain.h index a78ca4fa..5baf78d1 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -186,9 +186,6 @@ public: void SetFriendAim(bool friendAim); bool GetFriendAim(); - void SetTracePrecision(float factor); - float GetTracePrecision(); - void SetSpeed(float speed); float GetSpeed(); @@ -228,10 +225,8 @@ public: float GetGameTime(); - char* GetTitle(); - char* GetResume(); - char* GetScriptName(); - char* GetScriptFile(); + const std::string& GetScriptName(); + const std::string& GetScriptFile(); bool GetTrainerPilot(); bool GetFixScene(); bool GetShowSoluce(); @@ -523,10 +518,8 @@ protected: int m_infoUsed = 0; ActivePause* m_satcomMoviePause = nullptr; - char m_title[100] = {}; - char m_resume[500] = {}; - char m_scriptName[100] = {}; - char m_scriptFile[100] = {}; + std::string m_scriptName = ""; + std::string m_scriptFile = ""; int m_endingWinRank = 0; int m_endingLostRank = 0; bool m_winTerminate = false; diff --git a/src/script/script.cpp b/src/script/script.cpp index 8d01412d..c44746b8 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -848,7 +848,6 @@ void CScript::New(Ui::CEdit* edit, const char* name) char text[100]; char script[500]; char buffer[500]; - char *sf; int cursor1, cursor2, len, i, j; std::string resStr; @@ -883,12 +882,11 @@ void CScript::New(Ui::CEdit* edit, const char* name) edit->ShowSelect(); m_interface->SetFocus(edit); - sf = m_main->GetScriptFile(); - if ( sf[0] != 0 ) // Load an empty program specific? + std::string sf = m_main->GetScriptFile(); + if ( !sf.empty() ) // Load an empty program specific? { - std::string filename = sf; CInputStream stream; - stream.open(filename); + stream.open(sf); if (stream.is_open()) { diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 4a29ac5d..0b045a82 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -288,8 +288,7 @@ bool CObjectInterface::EventProcess(const Event &event) } SetSelScript(m_selScript); - char text[] = ""; - StartEditScript(newProgram, text); + StartEditScript(newProgram, ""); std::string res; GetResource(RES_TEXT, RT_STUDIO_CLONED, res); @@ -729,7 +728,7 @@ bool CObjectInterface::EventFrame(const Event &event) // Start editing a program. -void CObjectInterface::StartEditScript(Program* program, char* name) +void CObjectInterface::StartEditScript(Program* program, std::string name) { CreateInterface(false); // removes the control buttons diff --git a/src/ui/object_interface.h b/src/ui/object_interface.h index 2e991d76..7d892592 100644 --- a/src/ui/object_interface.h +++ b/src/ui/object_interface.h @@ -64,7 +64,7 @@ public: protected: bool EventFrame(const Event &event); - void StartEditScript(Program* program, char* name); + void StartEditScript(Program* program, std::string name); void StopEditScript(bool bCancel); void GroundFlat(); From 2111c6d1772d638a6d5fdaba6d1d9a59f4a5e868 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 1 Oct 2015 20:10:52 +0200 Subject: [PATCH 031/360] More CRobotMain cleanup --- src/level/robotmain.cpp | 38 +------------------------------------- src/level/robotmain.h | 6 ------ src/ui/displayinfo.cpp | 6 +----- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 0fd4439c..3d25495e 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -1431,10 +1431,8 @@ void CRobotMain::FlushDisplayInfo() for (int i = 0; i < SATCOM_MAX; i++) { m_infoFilename[i][0] = 0; - m_infoPos[i] = 0; } strcpy(m_infoFilename[SATCOM_OBJECT], "objects.txt"); - m_infoIndex = 0; } //! Beginning of the displaying of instructions. @@ -1491,10 +1489,7 @@ void CRobotMain::StartDisplayInfo(const std::string& filename, int index) m_displayInfo = MakeUnique(); m_displayInfo->StartDisplayInfo(filename, index, soluce); - - m_infoIndex = index; - if (index != -1) - m_displayInfo->SetPosition(m_infoPos[index]); + m_displayInfo->SetPosition(0); } //! End of displaying of instructions @@ -1505,9 +1500,6 @@ void CRobotMain::StopDisplayInfo() if (m_movieInfoIndex != -1) // film to read the SatCom? m_movie->Start(MM_SATCOMclose, 2.0f); - if (m_infoIndex != -1) - m_infoPos[m_infoIndex] = m_displayInfo->GetPosition(); - m_displayInfo->StopDisplayInfo(); m_displayInfo.reset(); @@ -1531,18 +1523,6 @@ char* CRobotMain::GetDisplayInfoName(int index) return m_infoFilename[index]; } -//! Returns the name of the text display -int CRobotMain::GetDisplayInfoPosition(int index) -{ - return m_infoPos[index]; -} - -//! Returns the name of the text display -void CRobotMain::SetDisplayInfoPosition(int index, int pos) -{ - m_infoPos[index] = pos; -} - //! Beginning of a dialogue during the game void CRobotMain::StartSuspend() @@ -1951,11 +1931,6 @@ CObject* CRobotMain::GetSelect() return nullptr; } -CObject* CRobotMain::SearchObject(ObjectType type) -{ - return m_objMan->FindNearest(nullptr, type); -} - //! Detects the object aimed by the mouse CObject* CRobotMain::DetectObject(Math::Point pos) { @@ -2718,16 +2693,6 @@ bool CRobotMain::EventObject(const Event &event) } -//! Calculates the point of arrival of the camera -Math::Vector CRobotMain::LookatPoint(Math::Vector eye, float angleH, float angleV, - float length) -{ - Math::Vector lookat = eye; - lookat.z += length; - - RotatePoint(eye, angleH, angleV, lookat); - return lookat; -} //! Load the scene for the character void CRobotMain::ScenePerso() @@ -5976,7 +5941,6 @@ void CRobotMain::DestroyCodeBattleInterface() void CRobotMain::SetCodeBattleSpectatorMode(bool mode) { - // Deselect object, but keep camera attached to it CObject* obj = DeselectAll(); if (m_codeBattleSpectator) diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 5baf78d1..3544ed36 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -217,8 +217,6 @@ public: void StartDisplayInfo(const std::string& filename, int index); void StopDisplayInfo(); char* GetDisplayInfoName(int index); - int GetDisplayInfoPosition(int index); - void SetDisplayInfoPosition(int index, int pos); void StartSuspend(); void StopSuspend(); @@ -381,7 +379,6 @@ protected: void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST); - Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); int CreateLight(Math::Vector direction, Gfx::Color color); void HiliteClear(); void HiliteObject(Math::Point pos); @@ -398,7 +395,6 @@ protected: bool DeselectObject(); void DeleteAllObjects(); void UpdateInfoText(); - CObject* SearchObject(ObjectType type); void StartDisplayVisit(EventType event); void FrameVisit(float rTime); void StopDisplayVisit(); @@ -513,8 +509,6 @@ protected: char m_infoFilename[SATCOM_MAX][100] = {}; // names of text files CObject* m_infoObject = nullptr; - int m_infoIndex = 0; - int m_infoPos[SATCOM_MAX] = {}; int m_infoUsed = 0; ActivePause* m_satcomMoviePause = nullptr; diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 6df5e9e7..6e28d744 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -664,10 +664,6 @@ void CDisplayInfo::ChangeIndexButton(int index) pw = static_cast(m_interface->SearchControl(EVENT_WINDOW4)); if ( pw == nullptr ) return; - if ( m_index != -1 ) - { - m_main->SetDisplayInfoPosition(m_index, GetPosition()); - } m_index = index; edit = static_cast(pw->SearchControl(EVENT_EDIT1)); @@ -676,7 +672,7 @@ void CDisplayInfo::ChangeIndexButton(int index) filename = m_main->GetDisplayInfoName(m_index); edit->ReadText(filename); edit->HyperHome(std::string(filename)); - SetPosition(m_main->GetDisplayInfoPosition(m_index)); + SetPosition(0); } UpdateIndexButton(); From 883e07ad6a060cbcbebe553a7e6c51f1f1e505fc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 1 Oct 2015 20:22:44 +0200 Subject: [PATCH 032/360] Fixed mouse scroll on lists going out of range, closes #660 --- src/ui/controls/list.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 102e34bc..7ed77b7e 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -281,10 +281,10 @@ bool CList::EventProcess(const Event &event) { auto data = event.GetData(); m_firstLine -= data->y; - if (m_firstLine < 0) - m_firstLine = 0; if (m_firstLine > m_totalLine - m_displayLine) m_firstLine = m_totalLine - m_displayLine; + if (m_firstLine < 0) + m_firstLine = 0; UpdateScroll(); UpdateButton(); From d11ebc891ccd433cbc478c3312612eb826523026 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 3 Oct 2015 22:05:14 +0200 Subject: [PATCH 033/360] Bring to zero some types of issues reported by colobot-lint --- src/CBot/CBotClass.cpp | 4 + src/CBot/CBotDll.h | 4 + src/CBot/CBotVar.cpp | 5 + src/app/app.cpp | 9 +- src/app/input.cpp | 10 +- src/app/input.h | 2 +- src/app/main.cpp | 2 +- src/app/pausemanager.cpp | 16 ++- src/app/pausemanager.h | 19 +-- src/app/signal_handlers.cpp | 7 +- src/app/system.cpp | 5 +- src/common/logger.cpp | 4 +- src/common/regex_utils.cpp | 4 +- src/common/regex_utils.h | 6 +- src/graphics/engine/camera.cpp | 4 +- src/graphics/engine/camera.h | 2 +- src/graphics/engine/cloud.h | 2 +- src/graphics/engine/engine.cpp | 6 +- src/graphics/engine/engine.h | 11 +- src/graphics/engine/lightman.cpp | 8 +- src/graphics/engine/lightman.h | 6 +- src/graphics/engine/pyro.h | 2 +- src/graphics/engine/terrain.cpp | 26 ++-- src/graphics/engine/terrain.h | 2 +- src/graphics/engine/text.cpp | 4 +- src/graphics/engine/text.h | 4 +- src/graphics/model/model_input.cpp | 4 +- src/level/parser/parser.h | 3 +- src/level/robotmain.cpp | 40 +++--- src/level/robotmain.h | 22 ++-- src/level/scene_conditions.cpp | 4 +- src/object/auto/auto.cpp | 8 +- src/object/auto/auto.h | 5 +- src/object/auto/autobase.cpp | 2 - src/object/auto/autobase.h | 2 +- src/object/auto/autoconvert.cpp | 8 +- src/object/auto/autoconvert.h | 2 +- src/object/auto/autoderrick.cpp | 2 - src/object/auto/autoderrick.h | 2 +- src/object/auto/autodestroyer.cpp | 2 - src/object/auto/autoegg.cpp | 2 +- src/object/auto/autoegg.h | 2 +- src/object/auto/autofactory.cpp | 6 +- src/object/auto/autofactory.h | 2 +- src/object/auto/autolabo.cpp | 4 +- src/object/auto/autonest.h | 2 +- src/object/auto/autonuclearplant.cpp | 4 +- src/object/auto/autonuclearplant.h | 2 +- src/object/auto/autopowercaptor.cpp | 4 +- src/object/auto/autopowerplant.h | 2 +- src/object/auto/autoresearch.h | 2 +- .../implementation/program_storage_impl.cpp | 2 +- src/object/implementation/programmable_impl.h | 7 +- src/object/interface/trace_drawing_object.h | 4 +- src/object/object.cpp | 4 +- src/object/old_object.h | 13 +- src/object/subclass/base_alien.cpp | 4 +- src/object/subclass/base_building.cpp | 2 +- src/object/subclass/base_robot.cpp | 4 +- src/object/subclass/shielder.cpp | 2 +- src/object/task/taskgoto.cpp | 2 +- src/object/task/taskpen.h | 5 +- src/object/task/taskterraform.cpp | 4 +- src/script/scriptfunc.cpp | 10 +- src/sound/oalsound/alsound.cpp | 118 +++++++----------- src/sound/oalsound/alsound.h | 16 +-- src/sound/oalsound/buffer.cpp | 21 ++-- src/sound/oalsound/buffer.h | 6 +- src/sound/oalsound/channel.cpp | 114 ++++++----------- src/sound/oalsound/channel.h | 12 +- src/sound/sound.cpp | 2 +- src/ui/controls/button.cpp | 4 +- src/ui/controls/button.h | 2 +- src/ui/controls/list.cpp | 4 +- src/ui/controls/list.h | 2 +- src/ui/controls/slider.h | 2 +- src/ui/controls/target.h | 2 +- src/ui/displaytext.h | 2 +- src/ui/maindialog.cpp | 4 +- src/ui/mainui.cpp | 12 +- src/ui/object_interface.h | 2 +- src/ui/screen/screen.cpp | 4 +- src/ui/screen/screen_io.cpp | 6 +- src/ui/screen/screen_io_read.cpp | 2 +- src/ui/screen/screen_io_write.cpp | 2 +- src/ui/screen/screen_player_select.cpp | 13 +- src/ui/studio.cpp | 6 +- test/unit/app/app_test.cpp | 48 +++---- test/unit/app/system_linux_test.cpp | 4 +- test/unit/app/system_windows_test.cpp | 4 +- test/unit/common/config_file_test.cpp | 3 +- test/unit/graphics/engine/lightman_test.cpp | 32 ++--- 92 files changed, 383 insertions(+), 441 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index be44e1a5..3e1e0077 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -72,6 +72,10 @@ CBotClass::~CBotClass() delete m_next; // releases all of them on this level } +CBotClass* CBotClass::Create(const char* name, CBotClass* parent, bool intrinsic) +{ + return new CBotClass(name, parent, intrinsic); +} void CBotClass::Free() { diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 37972560..bcb02d18 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -610,6 +610,8 @@ virtual ~CBotVar( ); // destructor static CBotVar* Create( CBotVar* pVar ); + static void Destroy(CBotVar* var); + void SetUserPtr(void* pUser); // associate a user pointer to an instance @@ -807,6 +809,8 @@ public: ~CBotClass( ); // destructor + static CBotClass* Create(const char* name, CBotClass* parent, bool intrinsic = false); + bool AddFunction(const char* name, bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 5deb935f..da5119f8 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -444,6 +444,11 @@ CBotVar* CBotVar::Create( const char* name, CBotClass* pClass) return pVar; } +void CBotVar::Destroy(CBotVar* var) +{ + delete var; +} + CBotTypResult CBotVar::GetTypResult(int mode) { CBotTypResult r = m_type; diff --git a/src/app/app.cpp b/src/app/app.cpp index b83a45f4..5c124083 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -19,8 +19,6 @@ #include "app/app.h" -#include "common/version.h" - #include "app/controller.h" #include "app/input.h" #include "app/system.h" @@ -32,6 +30,7 @@ #include "common/make_unique.h" #include "common/pathman.h" #include "common/stringutils.h" +#include "common/version.h" #include "common/resources/resourcemanager.h" @@ -39,10 +38,10 @@ #include "graphics/opengl/glutil.h" -#include "object/object_manager.h" - #include "level/robotmain.h" +#include "object/object_manager.h" + #ifdef OPENAL_SOUND #include "sound/oalsound/alsound.h" #endif @@ -479,7 +478,7 @@ bool CApplication::Create() #ifdef OPENAL_SOUND if (!m_headless) { - m_sound = MakeUnique(); + m_sound = MakeUnique(); } else { diff --git a/src/app/input.cpp b/src/app/input.cpp index ff75d917..228b5e9e 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -404,19 +404,19 @@ InputSlot CInput::SearchKeyById(std::string id) return INPUT_SLOT_MAX; } -std::string CInput::GetKeysString(InputBinding b) +std::string CInput::GetKeysString(InputBinding binding) { std::ostringstream ss; - if ( b.primary != KEY_INVALID ) + if ( binding.primary != KEY_INVALID ) { std::string iNameStr; - if ( GetResource(RES_KEY, b.primary, iNameStr) ) + if ( GetResource(RES_KEY, binding.primary, iNameStr) ) { ss << iNameStr; - if ( b.secondary != KEY_INVALID ) + if ( binding.secondary != KEY_INVALID ) { - if ( GetResource(RES_KEY, b.secondary, iNameStr) ) + if ( GetResource(RES_KEY, binding.secondary, iNameStr) ) { std::string textStr; GetResource(RES_TEXT, RT_KEY_OR, textStr); diff --git a/src/app/input.h b/src/app/input.h index 771267b8..e9e3b035 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -131,7 +131,7 @@ public: //@} //! Seeks a InputSlot by id. Returns INPUT_SLOT_MAX if not found - InputSlot SearchKeyById(std::string name); + InputSlot SearchKeyById(std::string id); //! Returns string describing keys to be pressed //@{ diff --git a/src/app/main.cpp b/src/app/main.cpp index 0845d5ad..7d3e6656 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,7 +23,6 @@ */ #include "common/config.h" -#include "common/version.h" #include "app/app.h" #include "app/signal_handlers.h" @@ -35,6 +34,7 @@ #include "common/logger.h" #include "common/make_unique.h" #include "common/restext.h" +#include "common/version.h" #include "common/resources/resourcemanager.h" diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index ba867a69..64a0b9df 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -27,6 +27,20 @@ #include +struct ActivePause +{ + explicit ActivePause(PauseType type, PauseMusic music = PAUSE_MUSIC_NONE) + : type(type), + music(music) + {} + + ActivePause(const ActivePause&) = delete; + ActivePause& operator=(const ActivePause&) = delete; + + PauseType type; + PauseMusic music; +}; + CPauseManager::CPauseManager() { @@ -39,7 +53,7 @@ CPauseManager::~CPauseManager() ActivePause* CPauseManager::ActivatePause(PauseType type, PauseMusic music) { //GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); - auto pause = std::unique_ptr(new ActivePause(type, music)); // TODO: Can't use MakeUnique here because the constructor is private + auto pause = MakeUnique(type, music); ActivePause* ptr = pause.get(); m_activePause.push_back(std::move(pause)); Update(); diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h index b6c261ff..d5ba1d7c 100644 --- a/src/app/pausemanager.h +++ b/src/app/pausemanager.h @@ -23,6 +23,8 @@ */ #pragma once +#include "common/make_unique.h" + #include #include #include @@ -63,22 +65,7 @@ enum PauseMusic PAUSE_MUSIC_SATCOM = 2, }; -struct ActivePause -{ -private: - friend class CPauseManager; - - explicit ActivePause(PauseType type, PauseMusic music = PAUSE_MUSIC_NONE) - : type(type) - , music(music) - {} - - ActivePause(const ActivePause&) = delete; - ActivePause& operator=(const ActivePause&) = delete; - - PauseType type; - PauseMusic music; -}; +struct ActivePause; class CPauseManager { diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index f00a8d84..618f323d 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -19,13 +19,12 @@ #include "app/signal_handlers.h" -#include "common/version.h" - -#include "common/resources/resourcemanager.h" - #include "app/system.h" #include "common/stringutils.h" +#include "common/version.h" + +#include "common/resources/resourcemanager.h" #include "level/robotmain.h" diff --git a/src/app/system.cpp b/src/app/system.cpp index e0ea2ba0..01450c4a 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -22,9 +22,6 @@ #include "common/config.h" -#include "common/make_unique.h" - - #if defined(PLATFORM_WINDOWS) #include "app/system_windows.h" #elif defined(PLATFORM_LINUX) @@ -35,6 +32,8 @@ #include "app/system_other.h" #endif +#include "common/make_unique.h" + #include #include diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 2217f5e3..2d3f9b7d 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -151,9 +151,9 @@ bool CLogger::IsOpened() return m_file != nullptr; } -void CLogger::SetLogLevel(LogLevel type) +void CLogger::SetLogLevel(LogLevel level) { - m_logLevel = type; + m_logLevel = level; } bool CLogger::ParseLogLevel(const std::string& str, LogLevel& logLevel) diff --git a/src/common/regex_utils.cpp b/src/common/regex_utils.cpp index 27086ca2..1796cd0c 100644 --- a/src/common/regex_utils.cpp +++ b/src/common/regex_utils.cpp @@ -25,7 +25,7 @@ std::string FormatAssertRegexMatchError(const std::string& text, return "Text \"" + text + "\" did not match regex \"" + pattern + "\""; } -RegexUtils::AssertRegexMatchError::AssertRegexMatchError( +RegexUtils::CAssertRegexMatchError::CAssertRegexMatchError( const std::string& text, const std::string& pattern) NOEXCEPT : std::runtime_error(FormatAssertRegexMatchError(text, pattern)) { @@ -37,7 +37,7 @@ boost::smatch RegexUtils::AssertRegexMatch(const std::string& text, const std::s boost::smatch matches; bool ok = boost::regex_match(text, matches, regex); if (!ok) - throw AssertRegexMatchError(text, pattern); + throw CAssertRegexMatchError(text, pattern); return matches; } diff --git a/src/common/regex_utils.h b/src/common/regex_utils.h index 5c0e100c..7f5b83f6 100644 --- a/src/common/regex_utils.h +++ b/src/common/regex_utils.h @@ -26,11 +26,11 @@ namespace RegexUtils { -class AssertRegexMatchError : public std::runtime_error +class CAssertRegexMatchError : public std::runtime_error { public: - explicit AssertRegexMatchError(const std::string& text, - const std::string& pattern) NOEXCEPT; + explicit CAssertRegexMatchError(const std::string& text, + const std::string& pattern) NOEXCEPT; }; //! Match string with regex and return list of matches; throw exception on mismatch diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 62e6edb9..a1dc6989 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -859,8 +859,8 @@ void CCamera::FixCamera() } void CCamera::SetViewTime(const Math::Vector &eyePt, - const Math::Vector &lookatPt, - float rTime) + const Math::Vector &lookatPt, + float rTime) { Math::Vector eye, lookat; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 453f9947..72c6f29c 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -249,7 +249,7 @@ protected: bool EventFrameScript(const Event &event); //! Specifies the location and direction of view to the 3D engine - void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime); + void SetViewTime(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime); //! Avoid the obstacles bool IsCollision(Math::Vector &eye, Math::Vector lookat); //! Avoid the obstacles diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 06e82ea9..89299ffe 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -74,7 +74,7 @@ public: //! Management of clouds //@{ - void SetEnabled(bool enable); + void SetEnabled(bool enabled); bool GetEnabled(); //@} diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 51eddf0d..29c6f927 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -4932,11 +4932,11 @@ int CEngine::GetEngineState(const ModelTriangle& triangle) return state; } -void CEngine::UpdateObjectShadowSpotNormal(int rank) +void CEngine::UpdateObjectShadowSpotNormal(int objRank) { - assert(rank >= 0 && rank < static_cast( m_objects.size() )); + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); - int shadowRank = m_objects[rank].shadowRank; + int shadowRank = m_objects[objRank].shadowRank; if (shadowRank == -1) return; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index c95dcb8d..9aebe83f 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -48,7 +48,6 @@ class CApplication; class CSoundInterface; class CImage; -class CPauseManager; class CSystemUtils; struct SystemTimeStamp; struct Event; @@ -717,7 +716,7 @@ public: //@} //! Increments the triangle counter for the current frame - void AddStatisticTriangle(int nb); + void AddStatisticTriangle(int count); //! Returns the number of triangles in current frame int GetStatisticTriangle(); @@ -778,7 +777,7 @@ public: // Objects //! Print debug info about an object - void DebugObject(int rank); + void DebugObject(int objRank); //! Creates a new object and returns its rank int CreateObject(); @@ -942,7 +941,7 @@ public: void SetTexture(const Texture& tex, int stage = 0); //! Deletes the given texture, unloading it and removing from cache - void DeleteTexture(const std::string& name); + void DeleteTexture(const std::string& texName); //! Deletes the given texture, unloading it and removing from cache void DeleteTexture(const Texture& tex); @@ -1215,7 +1214,7 @@ protected: //! Draws the mouse cursor void DrawMouse(); //! Draw part of mouse cursor sprite - void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon); + void DrawMouseSprite(Math::Point pos, Math::Point size, int icon); //! Draw statistic texts void DrawStats(); //! Draw mission timer @@ -1225,7 +1224,7 @@ protected: EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name); //! Creates a new tier 3 object (data) EngineBaseObjDataTier& AddLevel3(EngineBaseObjTexTier &p3, EngineTriangleType type, - const Material& mat, int state); + const Material& material, int state); //! Create texture and add it to cache Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 60f8c1ca..15b0335d 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -448,7 +448,7 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) m_lightMap[i] = -1; std::vector sortedLights = m_dynLights; - LightsComparator lightsComparator(m_engine->GetEyePt(), type); + CLightsComparator lightsComparator(m_engine->GetEyePt(), type); std::sort(sortedLights.begin(), sortedLights.end(), lightsComparator); int lightMapIndex = 0; @@ -497,13 +497,13 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) // ----------- -CLightManager::LightsComparator::LightsComparator(Math::Vector eyePos, EngineObjectType objectType) +CLightManager::CLightsComparator::CLightsComparator(Math::Vector eyePos, EngineObjectType objectType) { m_eyePos = eyePos; m_objectType = objectType; } -float CLightManager::LightsComparator::GetLightWeight(const DynamicLight& dynLight) +float CLightManager::CLightsComparator::GetLightWeight(const DynamicLight& dynLight) { if (dynLight.priority == LIGHT_PRI_HIGHEST) return -1.0f; @@ -519,7 +519,7 @@ float CLightManager::LightsComparator::GetLightWeight(const DynamicLight& dynLig return enabled ? ( (dynLight.light.position - m_eyePos).Length() * dynLight.priority ) : 10000.0f; } -bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const DynamicLight& right) +bool CLightManager::CLightsComparator::operator()(const DynamicLight& left, const DynamicLight& right) { float leftWeight = GetLightWeight(left); float rightWeight = GetLightWeight(right); diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 9d1eb5ea..ebf42d9d 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -168,7 +168,7 @@ public: //! Returns the light parameters for given dynamic light bool GetLight(int lightRank, Light &light); //! Enables/disables the given dynamic light - bool SetLightEnabled(int lightRank, bool enable); + bool SetLightEnabled(int lightRank, bool enabled); //! Changes the light priority bool SetLightPriority(int lightRank, LightPriority priority); @@ -212,10 +212,10 @@ public: void UpdateDeviceLights(EngineObjectType type); protected: - class LightsComparator + class CLightsComparator { public: - LightsComparator(Math::Vector eyePos, EngineObjectType objectType); + CLightsComparator(Math::Vector eyePos, EngineObjectType objectType); bool operator()(const DynamicLight& left, const DynamicLight& right); diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 2289b78f..e98bf96d 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -93,7 +93,7 @@ protected: void DeleteObject(bool primary, bool secondary); //! Creates an explosion with triangular form of particles - void CreateTriangle(CObject* obj, ObjectType type, int part); + void CreateTriangle(CObject* obj, ObjectType oType, int part); //! Starts the explosion of a vehicle void ExploStart(); diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 0d36a382..ae82c8fb 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -247,13 +247,13 @@ bool CTerrain::LoadResources(const std::string& fileName) return true; } -TerrainRes CTerrain::GetResource(const Math::Vector &p) +TerrainRes CTerrain::GetResource(const Math::Vector &pos) { if (m_resources.empty()) return TR_NULL; - int x = static_cast((p.x + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); - int y = static_cast((p.z + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); + int x = static_cast((pos.x + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); + int y = static_cast((pos.z + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) @@ -1677,16 +1677,16 @@ bool CTerrain::DeleteBuildingLevel(Math::Vector center) return false; } -float CTerrain::GetBuildingFactor(const Math::Vector &p) +float CTerrain::GetBuildingFactor(const Math::Vector &pos) { for (int i = 0; i < static_cast( m_buildingLevels.size() ); i++) { - if ( p.x < m_buildingLevels[i].bboxMinX || - p.x > m_buildingLevels[i].bboxMaxX || - p.z < m_buildingLevels[i].bboxMinZ || - p.z > m_buildingLevels[i].bboxMaxZ ) continue; + if ( pos.x < m_buildingLevels[i].bboxMinX || + pos.x > m_buildingLevels[i].bboxMaxX || + pos.z < m_buildingLevels[i].bboxMinZ || + pos.z > m_buildingLevels[i].bboxMaxZ ) continue; - float dist = Math::DistanceProjected(p, m_buildingLevels[i].center); + float dist = Math::DistanceProjected(pos, m_buildingLevels[i].center); if (dist <= m_buildingLevels[i].max) return m_buildingLevels[i].factor; @@ -1730,9 +1730,9 @@ void CTerrain::AdjustBuildingLevel(Math::Vector &p) } } -float CTerrain::GetHardness(const Math::Vector &p) +float CTerrain::GetHardness(const Math::Vector &pos) { - float factor = GetBuildingFactor(p); + float factor = GetBuildingFactor(pos); if (factor != 1.0f) return 1.0f; // on building level if (m_materialPoints.empty()) return m_defaultHardness; @@ -1741,8 +1741,8 @@ float CTerrain::GetHardness(const Math::Vector &p) int x, y; - x = static_cast((p.x+dim)/m_brickSize); - y = static_cast((p.z+dim)/m_brickSize); + x = static_cast((pos.x+dim)/m_brickSize); + y = static_cast((pos.z+dim)/m_brickSize); if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) return m_defaultHardness; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 3235f401..8c489c85 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -157,7 +157,7 @@ public: //! Clears all terrain materials void FlushMaterials(); //! Adds a terrain material the names of textures to use for the land - void AddMaterial(int id, const std::string& baseName, const Math::Point& uv, + void AddMaterial(int id, const std::string& texName, const Math::Point& uv, int up, int right, int down, int left, float hardness); //! Initializes all the ground with one material bool InitMaterials(int id); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index d1003443..f5028d11 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -22,14 +22,14 @@ #include "app/app.h" -#include "graphics/engine/engine.h" - #include "common/image.h" #include "common/logger.h" #include "common/stringutils.h" #include "common/resources/resourcemanager.h" +#include "graphics/engine/engine.h" + #include "math/func.h" #include diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 6ce6be33..6f79320a 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -27,8 +27,8 @@ #include "graphics/core/color.h" -#include "math/point.h" #include "math/intpoint.h" +#include "math/point.h" #include #include @@ -309,7 +309,7 @@ public: CharTexture GetCharTexture(UTF8Char ch, FontType font, float size); protected: - CachedFont* GetOrOpenFont(FontType type, float size); + CachedFont* GetOrOpenFont(FontType font, float size); CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); void DrawString(const std::string &text, std::vector::iterator format, diff --git a/src/graphics/model/model_input.cpp b/src/graphics/model/model_input.cpp index a29e0420..c71c88f0 100644 --- a/src/graphics/model/model_input.cpp +++ b/src/graphics/model/model_input.cpp @@ -59,8 +59,8 @@ namespace ModelInput VertexTex2 ReadBinaryVertexTex2(std::istream& stream); Material ReadBinaryMaterial(std::istream& stream); - std::string ReadLineString(std::istream& stream, const std::string& prefix); - void ReadValuePrefix(std::istream& stream, const std::string& prefix); + std::string ReadLineString(std::istream& stream, const std::string& expectedPrefix); + void ReadValuePrefix(std::istream& stream, const std::string& expectedPrefix); VertexTex2 ParseVertexTex2(const std::string& text); Material ParseMaterial(const std::string& text); Math::Vector ParseVector(const std::string& text); diff --git a/src/level/parser/parser.h b/src/level/parser/parser.h index f3eb1286..4d78c59d 100644 --- a/src/level/parser/parser.h +++ b/src/level/parser/parser.h @@ -24,10 +24,9 @@ #pragma once -#include "level/level_category.h" - #include "common/make_unique.h" +#include "level/level_category.h" #include "level/robotmain.h" #include "level/parser/parserexceptions.h" diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 3d25495e..6290075e 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -502,15 +502,21 @@ void CRobotMain::ChangePhase(Phase phase) if (CResourceManager::DirectoryExists("crashsave")) { GetLogger()->Info("Pre-crash save found!\n"); - m_ui->GetDialog()->StartQuestion("Your game seems to have crashed. Do you want to restore pre-crash state?", false, false, false, [&]() { - GetLogger()->Info("Trying to restore pre-crash state...\n"); - assert(m_playerProfile != nullptr); - m_playerProfile->LoadScene("../../crashsave"); - CResourceManager::RemoveDirectory("crashsave"); - }, [&]() { - GetLogger()->Info("Not restoring pre-crash state\n"); - CResourceManager::RemoveDirectory("crashsave"); - }); + m_ui->GetDialog()->StartQuestion( + "Your game seems to have crashed. Do you want to restore pre-crash state?", false, false, false, + [&]() + { + GetLogger()->Info("Trying to restore pre-crash state...\n"); + assert(m_playerProfile != nullptr); + m_playerProfile->LoadScene("../../crashsave"); + CResourceManager::RemoveDirectory("crashsave"); + }, + [&]() + { + GetLogger()->Info("Not restoring pre-crash state\n"); + CResourceManager::RemoveDirectory("crashsave"); + } + ); } } @@ -1018,9 +1024,13 @@ bool CRobotMain::ProcessEvent(Event &event) break; case EVENT_OBJECT_DELETE: - m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, false, [&]() { - DestroySelectedObject(); - }); + m_ui->GetDialog()->StartQuestion( + RT_DIALOG_DELOBJ, true, false, false, + [&]() + { + DestroySelectedObject(); + } + ); break; case EVENT_OBJECT_BHELP: @@ -2256,9 +2266,9 @@ void CRobotMain::ChangeCamera() } //! Remote control the camera using the arrow keys -void CRobotMain::KeyCamera(EventType type, InputSlot key) +void CRobotMain::KeyCamera(EventType event, InputSlot key) { - if (type == EVENT_KEY_UP) + if (event == EVENT_KEY_UP) { if (key == INPUT_SLOT_LEFT) { @@ -2290,7 +2300,7 @@ void CRobotMain::KeyCamera(EventType type, InputSlot key) assert(obj->Implements(ObjectInterfaceType::Controllable)); if (!dynamic_cast(obj)->GetTrainer()) return; - if (type == EVENT_KEY_DOWN) + if (event == EVENT_KEY_DOWN) { if (key == INPUT_SLOT_LEFT) { diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 3544ed36..30adec1f 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -30,14 +30,14 @@ #include "common/event.h" #include "common/singleton.h" +#include "graphics/engine/camera.h" +#include "graphics/engine/particle.h" + #include "level/build_type.h" #include "level/level_category.h" #include "level/mainmovie.h" #include "level/research_type.h" -#include "graphics/engine/camera.h" -#include "graphics/engine/particle.h" - #include "object/drive_type.h" #include "object/mission_type.h" #include "object/object_type.h" @@ -193,8 +193,8 @@ public: void SelectHuman(); CObject* SearchHuman(); CObject* SearchToto(); - CObject* SearchNearest(Math::Vector pos, CObject* pExclu); - bool SelectObject(CObject* pObj, bool displayError=true); + CObject* SearchNearest(Math::Vector pos, CObject* exclu); + bool SelectObject(CObject* obj, bool displayError=true); CObject* GetSelectObject(); CObject* DeselectAll(); @@ -259,15 +259,15 @@ public: void HideDropZone(CObject* metal); void ShowDropZone(CObject* metal, CObject* transporter); void FlushShowLimit(int i); - void SetShowLimit(int i, Gfx::ParticleType parti, CObject *pObj, Math::Vector pos, + void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, Math::Vector pos, float radius, float duration=SHOWLIMITTIME); void StartShowLimit(); void FrameShowLimit(float rTime); void SaveAllScript(); - void SaveOneScript(CObject *pObj); - bool SaveFileStack(CObject *pObj, FILE *file, int objRank); - bool ReadFileStack(CObject *pObj, FILE *file, int objRank); + void SaveOneScript(CObject *obj); + bool SaveFileStack(CObject *obj, FILE *file, int objRank); + bool ReadFileStack(CObject *obj, FILE *file, int objRank); void FlushNewScriptName(); void AddNewScriptName(ObjectType type, const std::string& name); @@ -365,7 +365,7 @@ public: void StartDetectEffect(COldObject* object, CObject* target); - bool IsSelectable(CObject* pObj); + bool IsSelectable(CObject* obj); protected: bool EventFrame(const Event &event); @@ -390,7 +390,7 @@ protected: void RemoteCamera(float pan, float zoom, float rTime); void KeyCamera(EventType event, InputSlot key); void AbortMovie(); - void SelectOneObject(CObject* pObj, bool displayError=true); + void SelectOneObject(CObject* obj, bool displayError=true); void HelpObject(); bool DeselectObject(); void DeleteAllObjects(); diff --git a/src/level/scene_conditions.cpp b/src/level/scene_conditions.cpp index b4cb886e..2228fba1 100644 --- a/src/level/scene_conditions.cpp +++ b/src/level/scene_conditions.cpp @@ -19,10 +19,10 @@ #include "level/scene_conditions.h" -#include "math/geometry.h" - #include "level/parser/parserline.h" +#include "math/geometry.h" + #include "object/object.h" #include "object/object_manager.h" diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index 29d7d240..6c72d67f 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -32,12 +32,12 @@ #include "object/old_object.h" +#include "sound/sound.h" + #include "ui/controls/gauge.h" #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - // Object's constructor. @@ -372,9 +372,9 @@ bool CAuto::GetBusy() return m_bBusy; } -void CAuto::SetBusy(bool bBusy) +void CAuto::SetBusy(bool busy) { - m_bBusy = bBusy; + m_bBusy = busy; } void CAuto::InitProgressTotal(float total) diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index c685e261..b3df5b9a 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -19,9 +19,8 @@ #pragma once - -#include "common/event.h" #include "common/error.h" +#include "common/event.h" #include "object/object_type.h" @@ -75,7 +74,7 @@ public: virtual Error GetError(); virtual bool GetBusy(); - virtual void SetBusy(bool bBuse); + virtual void SetBusy(bool busy); virtual void InitProgressTotal(float total); virtual void EventProgress(float rTime); diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index cb9e8510..6e5061dc 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -41,8 +41,6 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - const float BASE_LAND_TIME = 7.5f; // hard landing diff --git a/src/object/auto/autobase.h b/src/object/auto/autobase.h index ab0cec8c..04ebc076 100644 --- a/src/object/auto/autobase.h +++ b/src/object/auto/autobase.h @@ -86,7 +86,7 @@ public: protected: void UpdateInterface(); - void FreezeCargo(bool bFreeze); + void FreezeCargo(bool freeze); void MoveCargo(); Error CheckCloseDoor(); void BeginTransit(); diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index d1853e0a..e7803848 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -22,11 +22,11 @@ #include "common/make_unique.h" +#include "level/robotmain.h" + #include "level/parser/parserline.h" #include "level/parser/parserparam.h" -#include "level/robotmain.h" - #include "math/geometry.h" #include "object/object_manager.h" @@ -34,11 +34,11 @@ #include "object/interface/transportable_object.h" +#include "sound/sound.h" + #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - // Object's constructor. diff --git a/src/object/auto/autoconvert.h b/src/object/auto/autoconvert.h index 15c94f00..ba0505ea 100644 --- a/src/object/auto/autoconvert.h +++ b/src/object/auto/autoconvert.h @@ -42,7 +42,7 @@ public: CAutoConvert(COldObject* object); ~CAutoConvert(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index bc1ced20..ab4a22ef 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -37,8 +37,6 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - const float DERRICK_DELAY = 10.0f; // duration of the extraction diff --git a/src/object/auto/autoderrick.h b/src/object/auto/autoderrick.h index ea7d23d3..08d2515b 100644 --- a/src/object/auto/autoderrick.h +++ b/src/object/auto/autoderrick.h @@ -42,7 +42,7 @@ public: CAutoDerrick(COldObject* object); ~CAutoDerrick(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index 24b8e162..66df64ee 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -37,8 +37,6 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - #include diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index 0c61b1d3..0aab0264 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -32,8 +32,8 @@ #include "object/object_manager.h" #include "object/old_object.h" -#include "object/interface/programmable_object.h" #include "object/interface/program_storage_object.h" +#include "object/interface/programmable_object.h" #include "object/interface/transportable_object.h" diff --git a/src/object/auto/autoegg.h b/src/object/auto/autoegg.h index 8a82e1a4..9c8e29da 100644 --- a/src/object/auto/autoegg.h +++ b/src/object/auto/autoegg.h @@ -42,7 +42,7 @@ public: CAutoEgg(COldObject* object); ~CAutoEgg(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; void Start(int param) override; diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 952805ea..2c62fce3 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -22,20 +22,20 @@ #include "common/make_unique.h" -#include "math/geometry.h" - #include "level/robotmain.h" #include "level/parser/parser.h" #include "level/parser/parserline.h" #include "level/parser/parserparam.h" +#include "math/geometry.h" + #include "object/object_create_params.h" #include "object/object_manager.h" #include "object/old_object.h" -#include "object/interface/programmable_object.h" #include "object/interface/program_storage_object.h" +#include "object/interface/programmable_object.h" #include "object/interface/transportable_object.h" #include "physics/physics.h" diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h index 5e339ff0..ead937fa 100644 --- a/src/object/auto/autofactory.h +++ b/src/object/auto/autofactory.h @@ -43,7 +43,7 @@ public: CAutoFactory(COldObject* object); ~CAutoFactory(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index b8e69921..550a82ab 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -35,11 +35,11 @@ #include "object/interface/powered_object.h" +#include "sound/sound.h" + #include "ui/controls/interface.h" #include "ui/controls/window.h" -#include "sound/sound.h" - const float LABO_DELAY = 20.0f; // duration of the analysis diff --git a/src/object/auto/autonest.h b/src/object/auto/autonest.h index 4eed1769..d516e223 100644 --- a/src/object/auto/autonest.h +++ b/src/object/auto/autonest.h @@ -39,7 +39,7 @@ public: CAutoNest(COldObject* object); ~CAutoNest(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autonuclearplant.cpp b/src/object/auto/autonuclearplant.cpp index 15d0bb32..b034f4cf 100644 --- a/src/object/auto/autonuclearplant.cpp +++ b/src/object/auto/autonuclearplant.cpp @@ -22,13 +22,13 @@ #include "common/make_unique.h" -#include "math/geometry.h" - #include "level/robotmain.h" #include "level/parser/parserline.h" #include "level/parser/parserparam.h" +#include "math/geometry.h" + #include "object/object_manager.h" #include "object/old_object.h" diff --git a/src/object/auto/autonuclearplant.h b/src/object/auto/autonuclearplant.h index fc1e7804..5d8c4cd2 100644 --- a/src/object/auto/autonuclearplant.h +++ b/src/object/auto/autonuclearplant.h @@ -42,7 +42,7 @@ public: CAutoNuclearPlant(COldObject* object); ~CAutoNuclearPlant(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autopowercaptor.cpp b/src/object/auto/autopowercaptor.cpp index 0779bcaf..55c83c1d 100644 --- a/src/object/auto/autopowercaptor.cpp +++ b/src/object/auto/autopowercaptor.cpp @@ -22,11 +22,11 @@ #include "common/make_unique.h" -#include "math/geometry.h" - #include "level/parser/parserline.h" #include "level/parser/parserparam.h" +#include "math/geometry.h" + #include "object/object_manager.h" #include "object/old_object.h" diff --git a/src/object/auto/autopowerplant.h b/src/object/auto/autopowerplant.h index dbc4f3ef..92e700ec 100644 --- a/src/object/auto/autopowerplant.h +++ b/src/object/auto/autopowerplant.h @@ -43,7 +43,7 @@ public: CAutoPowerPlant(COldObject* object); ~CAutoPowerPlant(); - void DeleteObject(bool bAll=false) override; + void DeleteObject(bool all=false) override; void Init() override; bool EventProcess(const Event &event) override; diff --git a/src/object/auto/autoresearch.h b/src/object/auto/autoresearch.h index 55a8d946..eaeae3de 100644 --- a/src/object/auto/autoresearch.h +++ b/src/object/auto/autoresearch.h @@ -42,7 +42,7 @@ public: void DeleteObject(bool bAll=false) override; void Init() override; - Error StartAction(int result) override; + Error StartAction(int param) override; bool EventProcess(const Event &event) override; Error GetError() override; diff --git a/src/object/implementation/program_storage_impl.cpp b/src/object/implementation/program_storage_impl.cpp index 11142742..2ef4e8cc 100644 --- a/src/object/implementation/program_storage_impl.cpp +++ b/src/object/implementation/program_storage_impl.cpp @@ -17,7 +17,7 @@ * along with this program. If not, see http://gnu.org/licenses */ -#include "object/implementation/programmable_impl.h" +#include "object/implementation/program_storage_impl.h" #include "common/global.h" #include "common/logger.h" diff --git a/src/object/implementation/programmable_impl.h b/src/object/implementation/programmable_impl.h index f92b3128..b8e3125c 100644 --- a/src/object/implementation/programmable_impl.h +++ b/src/object/implementation/programmable_impl.h @@ -19,12 +19,13 @@ #pragma once -#include "object/interface/interactive_object.h" #include "object/interface/programmable_object.h" -#include "object/interface/trace_drawing_object.h" #include "math/vector.h" +#include "object/interface/interactive_object.h" +#include "object/interface/trace_drawing_object.h" + #include class CObject; @@ -64,7 +65,7 @@ public: void TraceRecordStop() override; bool IsTraceRecord() override; - void SetActivity(bool bMode) override; + void SetActivity(bool activity) override; bool GetActivity() override; void SetCmdLine(unsigned int rank, float value); diff --git a/src/object/interface/trace_drawing_object.h b/src/object/interface/trace_drawing_object.h index a5be3fd6..ee8c52b3 100644 --- a/src/object/interface/trace_drawing_object.h +++ b/src/object/interface/trace_drawing_object.h @@ -53,9 +53,9 @@ enum class TraceColor Max, }; //! Convert TraceColor to a std::string -std::string TraceColorName(TraceColor c); +std::string TraceColorName(TraceColor color); //! Return Gfx::Color for this TraceColor constants -Gfx::Color TraceColorColor(TraceColor c); +Gfx::Color TraceColorColor(TraceColor color); /** * \class CTraceDrawingObject diff --git a/src/object/object.cpp b/src/object/object.cpp index 0a597749..85688796 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -23,13 +23,13 @@ #include "common/restext.h" #include "common/stringutils.h" +#include "graphics/model/model_crash_sphere.h" + #include "level/robotmain.h" #include "level/parser/parserline.h" #include "level/parser/parserparam.h" -#include "graphics/model/model_crash_sphere.h" - #include "script/scriptfunc.h" #include diff --git a/src/object/old_object.h b/src/object/old_object.h index a44458b4..152d870d 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -28,6 +28,11 @@ #include "object/object.h" +#include "object/implementation/power_container_impl.h" +#include "object/implementation/program_storage_impl.h" +#include "object/implementation/programmable_impl.h" +#include "object/implementation/task_executor_impl.h" + #include "object/interface/carrier_object.h" #include "object/interface/controllable_object.h" #include "object/interface/flying_object.h" @@ -44,11 +49,6 @@ #include "object/interface/trace_drawing_object.h" #include "object/interface/transportable_object.h" -#include "object/implementation/power_container_impl.h" -#include "object/implementation/program_storage_impl.h" -#include "object/implementation/programmable_impl.h" -#include "object/implementation/task_executor_impl.h" - // The father of all parts must always be the part number zero! const int OBJECTMAXPART = 40; @@ -101,7 +101,7 @@ protected: void SetMovable(std::unique_ptr motion, std::unique_ptr physics); void SetAuto(std::unique_ptr automat); void SetOption(int option); - void SetJostlingSphere(const Math::Sphere& sphere); + void SetJostlingSphere(const Math::Sphere& jostlingSphere); public: @@ -360,7 +360,6 @@ protected: float m_cameraDist; bool m_bCameraLock; float m_magnifyDamage; - float m_param; Math::Sphere m_jostlingSphere; float m_shieldRadius; diff --git a/src/object/subclass/base_alien.cpp b/src/object/subclass/base_alien.cpp index 796d0dc1..350fd800 100644 --- a/src/object/subclass/base_alien.cpp +++ b/src/object/subclass/base_alien.cpp @@ -24,8 +24,6 @@ #include "level/parser/parserline.h" #include "level/parser/parserparam.h" -#include "graphics/engine/oldmodelmanager.h" - #include "object/object_create_params.h" #include "object/motion/motionant.h" @@ -87,7 +85,7 @@ std::unique_ptr CBaseAlien::Create( obj->SetProgrammable(); obj->SetMovable(std::move(motion), std::move(physics)); - return std::move(obj); + return obj; } void CBaseAlien::SetFixed(bool fixed) diff --git a/src/object/subclass/base_building.cpp b/src/object/subclass/base_building.cpp index 6f1a09a6..3a5700a6 100644 --- a/src/object/subclass/base_building.cpp +++ b/src/object/subclass/base_building.cpp @@ -889,5 +889,5 @@ std::unique_ptr CBaseBuilding::Create( obj->UpdateMapping(); - return std::move(obj); + return obj; } diff --git a/src/object/subclass/base_robot.cpp b/src/object/subclass/base_robot.cpp index 53423f08..7cf23c5e 100644 --- a/src/object/subclass/base_robot.cpp +++ b/src/object/subclass/base_robot.cpp @@ -55,7 +55,7 @@ std::unique_ptr CBaseRobot::Create( auto motion = MakeUnique(obj.get()); motion->Create(params.pos, params.angle, params.type, 1.0f, modelManager); obj->SetMovable(std::move(motion), nullptr); - return std::move(obj); + return obj; } if ( params.type == OBJECT_HUMAN || @@ -95,5 +95,5 @@ std::unique_ptr CBaseRobot::Create( obj->SetProgrammable(); obj->SetMovable(std::move(motion), std::move(physics)); - return std::move(obj); + return obj; } diff --git a/src/object/subclass/shielder.cpp b/src/object/subclass/shielder.cpp index 9b74ad55..df5f4a78 100644 --- a/src/object/subclass/shielder.cpp +++ b/src/object/subclass/shielder.cpp @@ -66,7 +66,7 @@ std::unique_ptr CShielder::Create( obj->SetProgrammable(); obj->SetMovable(std::move(motion), std::move(physics)); - return std::move(obj); + return obj; } void CShielder::SetShieldRadius(float shieldRadius) diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 455e82d5..49484d32 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -20,8 +20,8 @@ #include "object/task/taskgoto.h" -#include "common/global.h" #include "common/event.h" +#include "common/global.h" #include "common/make_unique.h" #include "graphics/engine/terrain.h" diff --git a/src/object/task/taskpen.h b/src/object/task/taskpen.h index 08de3610..525a298e 100644 --- a/src/object/task/taskpen.h +++ b/src/object/task/taskpen.h @@ -19,13 +19,12 @@ #pragma once - #include "object/task/task.h" -#include "object/interface/trace_drawing_object.h" - #include "math/vector.h" +#include "object/interface/trace_drawing_object.h" + enum TaskPenPhase { diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index f761dba8..f1adf4ab 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -23,10 +23,10 @@ #include "graphics/engine/pyro_manager.h" #include "graphics/engine/terrain.h" -#include "math/geometry.h" - #include "level/robotmain.h" +#include "math/geometry.h" + #include "object/object_manager.h" #include "object/old_object.h" diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 4a0214a9..3b55bb23 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -3680,14 +3680,14 @@ void CScriptFunctions::Init() CBotClass* bc; // Add the class Point. - bc = new CBotClass("point", nullptr, true); // intrinsic class + bc = CBotClass::Create("point", nullptr, true); // intrinsic class bc->AddItem("x", CBotTypFloat); bc->AddItem("y", CBotTypFloat); bc->AddItem("z", CBotTypFloat); bc->AddFunction("point", CScriptFunctions::rPointConstructor, CScriptFunctions::cPointConstructor); // Adds the class Object. - bc = new CBotClass("object", nullptr); + bc = CBotClass::Create("object", nullptr); bc->AddItem("category", CBotTypResult(CBotTypInt), PR_READ); bc->AddItem("position", CBotTypResult(CBotTypClass, "point"), PR_READ); bc->AddItem("orientation", CBotTypResult(CBotTypFloat), PR_READ); @@ -3718,7 +3718,7 @@ void CScriptFunctions::Init() // canal.close(); // close the file // create the class FILE - bc = new CBotClass("file", nullptr); + bc = CBotClass::Create("file", nullptr); // adds the component ".filename" bc->AddItem("filename", CBotTypString); // adds the component ".handle" @@ -3991,6 +3991,6 @@ void CScriptFunctions::DestroyObjectVar(CBotVar* botVar, bool permanent) if ( botVar == nullptr ) return; botVar->SetUserPtr(OBJECTDELETED); - if(permanent) - delete botVar; + if (permanent) + CBotVar::Destroy(botVar); } diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 029327cf..a94e279c 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -27,7 +27,7 @@ #include -ALSound::ALSound() +CALSound::CALSound() : m_enabled(false), m_audioVolume(1.0f), m_musicVolume(1.0f), @@ -37,14 +37,12 @@ ALSound::ALSound() { } - -ALSound::~ALSound() +CALSound::~CALSound() { CleanUp(); } - -void ALSound::CleanUp() +void CALSound::CleanUp() { if (m_enabled) { @@ -71,8 +69,7 @@ void ALSound::CleanUp() } } - -bool ALSound::Create() +bool CALSound::Create() { CleanUp(); @@ -102,20 +99,17 @@ bool ALSound::Create() return true; } - -bool ALSound::GetEnable() +bool CALSound::GetEnable() { return m_enabled; } - -void ALSound::SetAudioVolume(int volume) +void CALSound::SetAudioVolume(int volume) { m_audioVolume = static_cast(volume) / MAXVOLUME; } - -int ALSound::GetAudioVolume() +int CALSound::GetAudioVolume() { if ( !m_enabled ) return 0; @@ -123,8 +117,7 @@ int ALSound::GetAudioVolume() return m_audioVolume * MAXVOLUME; } - -void ALSound::SetMusicVolume(int volume) +void CALSound::SetMusicVolume(int volume) { m_musicVolume = static_cast(volume) / MAXVOLUME; if (m_currentMusic) @@ -133,8 +126,7 @@ void ALSound::SetMusicVolume(int volume) } } - -int ALSound::GetMusicVolume() +int CALSound::GetMusicVolume() { if ( !m_enabled ) return 0.0f; @@ -142,10 +134,9 @@ int ALSound::GetMusicVolume() return m_musicVolume * MAXVOLUME; } - -bool ALSound::Cache(SoundType sound, const std::string &filename) +bool CALSound::Cache(SoundType sound, const std::string &filename) { - auto buffer = MakeUnique(); + auto buffer = MakeUnique(); if (buffer->LoadFromFile(filename, sound)) { m_sounds[sound] = std::move(buffer); @@ -154,11 +145,11 @@ bool ALSound::Cache(SoundType sound, const std::string &filename) return false; } -bool ALSound::CacheMusic(const std::string &filename) +bool CALSound::CacheMusic(const std::string &filename) { if (m_music.find(filename) == m_music.end()) { - auto buffer = MakeUnique(); + auto buffer = MakeUnique(); if (buffer->LoadFromFile(filename, static_cast(-1))) { m_music[filename] = std::move(buffer); @@ -168,17 +159,17 @@ bool ALSound::CacheMusic(const std::string &filename) return false; } -bool ALSound::IsCached(SoundType sound) +bool CALSound::IsCached(SoundType sound) { return m_sounds.find(sound) != m_sounds.end(); } -bool ALSound::IsCachedMusic(const std::string &filename) +bool CALSound::IsCachedMusic(const std::string &filename) { return m_music.find(filename) != m_music.end(); } -int ALSound::GetPriority(SoundType sound) +int CALSound::GetPriority(SoundType sound) { if ( sound == SOUND_FLYh || sound == SOUND_FLY || @@ -226,8 +217,7 @@ int ALSound::GetPriority(SoundType sound) return 10; } - -bool ALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoaded) +bool CALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoaded) { int priority = GetPriority(sound); @@ -253,7 +243,7 @@ bool ALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoade // just add a new channel if we dont have any if (m_channels.size() == 0) { - auto chn = MakeUnique(); + auto chn = MakeUnique(); // check if we channel ready to play music, if not report error if (chn->IsReady()) { @@ -278,7 +268,7 @@ bool ALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoade { if (m_channels.find(i) == m_channels.end()) { - auto chn = MakeUnique(); + auto chn = MakeUnique(); // check if channel is ready to play music, if not destroy it and seek free one if (chn->IsReady()) { @@ -321,14 +311,12 @@ bool ALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoade return false; } - -int ALSound::Play(SoundType sound, float amplitude, float frequency, bool loop) +int CALSound::Play(SoundType sound, float amplitude, float frequency, bool loop) { return Play(sound, m_eye, amplitude, frequency, loop); } - -int ALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop) +int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop) { if (!m_enabled) { @@ -356,7 +344,7 @@ int ALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, flo } } - Channel* chn = m_channels[channel].get(); + CChannel* chn = m_channels[channel].get(); chn->SetPosition(pos); chn->SetVolumeAtrib(1.0f); @@ -382,8 +370,7 @@ int ALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, flo return channel | ((chn->GetId() & 0xffff) << 16); } - -bool ALSound::FlushEnvelope(int channel) +bool CALSound::FlushEnvelope(int channel) { if (!CheckChannel(channel)) { @@ -394,8 +381,7 @@ bool ALSound::FlushEnvelope(int channel) return true; } - -bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) +bool CALSound::AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) { if (!CheckChannel(channel)) { @@ -413,8 +399,7 @@ bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float t return true; } - -bool ALSound::Position(int channel, const Math::Vector &pos) +bool CALSound::Position(int channel, const Math::Vector &pos) { if (!CheckChannel(channel)) { @@ -425,8 +410,7 @@ bool ALSound::Position(int channel, const Math::Vector &pos) return true; } - -bool ALSound::Frequency(int channel, float frequency) +bool CALSound::Frequency(int channel, float frequency) { if (!CheckChannel(channel)) { @@ -438,7 +422,7 @@ bool ALSound::Frequency(int channel, float frequency) return true; } -bool ALSound::Stop(int channel) +bool CALSound::Stop(int channel) { if (!CheckChannel(channel)) { @@ -451,8 +435,7 @@ bool ALSound::Stop(int channel) return true; } - -bool ALSound::StopAll() +bool CALSound::StopAll() { if (!m_enabled) { @@ -468,8 +451,7 @@ bool ALSound::StopAll() return true; } - -bool ALSound::MuteAll(bool mute) +bool CALSound::MuteAll(bool mute) { if (!m_enabled) { @@ -487,8 +469,7 @@ bool ALSound::MuteAll(bool mute) return true; } - -void ALSound::FrameMove(float delta) +void CALSound::FrameMove(float rTime) { if (!m_enabled) { @@ -513,7 +494,7 @@ void ALSound::FrameMove(float delta) continue; SoundOper &oper = it.second->GetEnvelope(); - oper.currentTime += delta; + oper.currentTime += rTime; progress = oper.currentTime / oper.totalTime; progress = std::min(progress, 1.0f); @@ -560,7 +541,7 @@ void ALSound::FrameMove(float delta) } else { - it->currentTime += delta; + it->currentTime += rTime; it->music->SetVolume(((it->fadeTime-it->currentTime) / it->fadeTime) * m_musicVolume); ++it; } @@ -574,14 +555,13 @@ void ALSound::FrameMove(float delta) } else { - m_previousMusic.currentTime += delta; + m_previousMusic.currentTime += rTime; m_previousMusic.music->SetVolume(((m_previousMusic.fadeTime-m_previousMusic.currentTime) / m_previousMusic.fadeTime) * m_musicVolume); } } } - -void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) +void CALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) { m_eye = eye; m_lookat = lookat; @@ -593,15 +573,14 @@ void ALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat) alListenerfv(AL_ORIENTATION, orientation); } - -bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime) +bool CALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime) { if (!m_enabled) { return false; } - Buffer *buffer = nullptr; + CBuffer *buffer = nullptr; // check if we have music in cache if (m_music.find(filename) == m_music.end()) @@ -613,7 +592,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime return false; } */ - auto newBuffer = MakeUnique(); + auto newBuffer = MakeUnique(); buffer = newBuffer.get(); if (!newBuffer->LoadFromFile(filename, static_cast(-1))) { @@ -636,7 +615,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime m_oldMusic.push_back(std::move(old)); } - m_currentMusic = MakeUnique(); + m_currentMusic = MakeUnique(); m_currentMusic->SetBuffer(buffer); m_currentMusic->SetVolume(m_musicVolume); m_currentMusic->SetLoop(repeat); @@ -645,8 +624,7 @@ bool ALSound::PlayMusic(const std::string &filename, bool repeat, float fadeTime return true; } - -bool ALSound::PlayPauseMusic(const std::string &filename, bool repeat) +bool CALSound::PlayPauseMusic(const std::string &filename, bool repeat) { if (m_previousMusic.fadeTime > 0.0f) { @@ -671,8 +649,7 @@ bool ALSound::PlayPauseMusic(const std::string &filename, bool repeat) return PlayMusic(filename, repeat); } - -void ALSound::StopPauseMusic() +void CALSound::StopPauseMusic() { if (m_previousMusic.fadeTime > 0.0f) { @@ -691,8 +668,7 @@ void ALSound::StopPauseMusic() } } - -bool ALSound::RestartMusic() +bool CALSound::RestartMusic() { if (!m_enabled || m_currentMusic == nullptr) { @@ -704,8 +680,7 @@ bool ALSound::RestartMusic() return true; } - -void ALSound::StopMusic(float fadeTime) +void CALSound::StopMusic(float fadeTime) { if (!m_enabled || m_currentMusic == nullptr) { @@ -719,8 +694,7 @@ void ALSound::StopMusic(float fadeTime) m_oldMusic.push_back(std::move(old)); } - -bool ALSound::IsPlayingMusic() +bool CALSound::IsPlayingMusic() { if (!m_enabled || m_currentMusic == nullptr) { @@ -730,8 +704,7 @@ bool ALSound::IsPlayingMusic() return m_currentMusic->IsPlaying(); } - -void ALSound::SuspendMusic() +void CALSound::SuspendMusic() { if (!m_enabled || m_currentMusic == nullptr) { @@ -741,8 +714,7 @@ void ALSound::SuspendMusic() m_currentMusic->Stop(); } - -bool ALSound::CheckChannel(int &channel) +bool CALSound::CheckChannel(int &channel) { int id = (channel >> 16) & 0xffff; channel &= 0xffff; diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 39ad905b..a03a08db 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -60,7 +60,7 @@ struct OldMusic return *this; } - std::unique_ptr music; + std::unique_ptr music; float fadeTime = 0.0f; float currentTime = 0.0f; @@ -75,11 +75,11 @@ struct OldMusic } }; -class ALSound : public CSoundInterface +class CALSound : public CSoundInterface { public: - ALSound(); - ~ALSound(); + CALSound(); + ~CALSound(); bool Create() override; bool Cache(SoundType, const std::string &) override; @@ -126,10 +126,10 @@ private: unsigned int m_channelsLimit; ALCdevice* m_device; ALCcontext* m_context; - std::map> m_sounds; - std::map> m_music; - std::map> m_channels; - std::unique_ptr m_currentMusic; + std::map> m_sounds; + std::map> m_music; + std::map> m_channels; + std::unique_ptr m_currentMusic; std::list m_oldMusic; OldMusic m_previousMusic; Math::Vector m_eye; diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index 7f6b6700..c48da360 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -28,15 +28,14 @@ #include -Buffer::Buffer() +CBuffer::CBuffer() : m_buffer(), m_sound(), m_loaded(false), m_duration(0.0f) {} - -Buffer::~Buffer() +CBuffer::~CBuffer() { if (m_loaded) { @@ -46,8 +45,7 @@ Buffer::~Buffer() } } - -bool Buffer::LoadFromFile(std::string filename, SoundType sound) +bool CBuffer::LoadFromFile(std::string filename, SoundType sound) { m_sound = sound; GetLogger()->Debug("Loading audio file: %s\n", filename.c_str()); @@ -92,27 +90,22 @@ bool Buffer::LoadFromFile(std::string filename, SoundType sound) return true; } - -SoundType Buffer::GetSoundType() +SoundType CBuffer::GetSoundType() { return m_sound; } - -ALuint Buffer::GetBuffer() +ALuint CBuffer::GetBuffer() { return m_buffer; } - -bool Buffer::IsLoaded() +bool CBuffer::IsLoaded() { return m_loaded; } - -float Buffer::GetDuration() +float CBuffer::GetDuration() { return m_duration; } - diff --git a/src/sound/oalsound/buffer.h b/src/sound/oalsound/buffer.h index b45ce3bc..379fafb6 100644 --- a/src/sound/oalsound/buffer.h +++ b/src/sound/oalsound/buffer.h @@ -32,11 +32,11 @@ #include -class Buffer +class CBuffer { public: - Buffer(); - ~Buffer(); + CBuffer(); + ~CBuffer(); bool LoadFromFile(std::string, SoundType); bool IsLoaded(); diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 4b3b5593..fb506e42 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -22,7 +22,7 @@ #include "sound/oalsound/buffer.h" -Channel::Channel() +CChannel::CChannel() : m_buffer(nullptr), m_source(0), m_priority(0), @@ -49,8 +49,7 @@ Channel::Channel() } } - -Channel::~Channel() +CChannel::~CChannel() { if (m_ready) { @@ -62,8 +61,7 @@ Channel::~Channel() } } - -bool Channel::Play() +bool CChannel::Play() { if (!m_ready || m_buffer == nullptr) { @@ -81,7 +79,7 @@ bool Channel::Play() return true; } -bool Channel::Pause() +bool CChannel::Pause() { if (!m_ready || !IsPlaying()) { @@ -96,8 +94,7 @@ bool Channel::Pause() return true; } - -bool Channel::SetPosition(const Math::Vector &pos) +bool CChannel::SetPosition(const Math::Vector &pos) { if (!m_ready || m_buffer == nullptr) { @@ -113,8 +110,7 @@ bool Channel::SetPosition(const Math::Vector &pos) return true; } - -bool Channel::SetFrequency(float freq) +bool CChannel::SetFrequency(float freq) { if (!m_ready || m_buffer == nullptr) { @@ -130,8 +126,7 @@ bool Channel::SetFrequency(float freq) return true; } - -float Channel::GetFrequency() +float CChannel::GetFrequency() { ALfloat freq; if (!m_ready || m_buffer == nullptr) @@ -149,8 +144,7 @@ float Channel::GetFrequency() return freq; } - -bool Channel::SetVolume(float vol) +bool CChannel::SetVolume(float vol) { if (!m_ready || vol < 0 || m_buffer == nullptr) { @@ -166,8 +160,7 @@ bool Channel::SetVolume(float vol) return true; } - -float Channel::GetVolume() +float CChannel::GetVolume() { ALfloat vol; if (!m_ready || m_buffer == nullptr) @@ -185,87 +178,72 @@ float Channel::GetVolume() return vol; } - -void Channel::SetVolumeAtrib(float volume) +void CChannel::SetVolumeAtrib(float volume) { m_volume = volume; } - -float Channel::GetVolumeAtrib() +float CChannel::GetVolumeAtrib() { return m_volume; } - - -int Channel::GetPriority() +int CChannel::GetPriority() { return m_priority; } - -void Channel::SetPriority(int pri) +void CChannel::SetPriority(int pri) { m_priority = pri; } - -void Channel::SetStartAmplitude(float gain) +void CChannel::SetStartAmplitude(float gain) { m_startAmplitude = gain; } - -void Channel::SetStartFrequency(float freq) +void CChannel::SetStartFrequency(float freq) { m_startFrequency = freq; } - -void Channel::SetChangeFrequency(float freq) +void CChannel::SetChangeFrequency(float freq) { m_changeFrequency = freq; } - -float Channel::GetStartAmplitude() +float CChannel::GetStartAmplitude() { return m_startAmplitude; } - -float Channel::GetStartFrequency() +float CChannel::GetStartFrequency() { return m_startFrequency; } - -float Channel::GetChangeFrequency() +float CChannel::GetChangeFrequency() { return m_changeFrequency; } - -float Channel::GetInitFrequency() +float CChannel::GetInitFrequency() { return m_initFrequency; } - -void Channel::AddOper(SoundOper oper) +void CChannel::AddOper(SoundOper oper) { m_oper.push_back(oper); } - -void Channel::ResetOper() +void CChannel::ResetOper() { m_oper.clear(); } - -SoundType Channel::GetSoundType() +SoundType CChannel::GetSoundType() { if (!m_ready || m_buffer == nullptr) { @@ -275,8 +253,7 @@ SoundType Channel::GetSoundType() return m_buffer->GetSoundType(); } - -bool Channel::SetBuffer(Buffer *buffer) +bool CChannel::SetBuffer(CBuffer *buffer) { if (!m_ready) return false; @@ -299,7 +276,7 @@ bool Channel::SetBuffer(Buffer *buffer) return true; } -bool Channel::IsPlaying() +bool CChannel::IsPlaying() { ALint status; if (!m_ready || m_buffer == nullptr) @@ -317,19 +294,17 @@ bool Channel::IsPlaying() return status == AL_PLAYING; } - -bool Channel::IsReady() +bool CChannel::IsReady() { return m_ready; } -bool Channel::IsLoaded() +bool CChannel::IsLoaded() { return m_buffer != nullptr; } - -bool Channel::Stop() +bool CChannel::Stop() { if (!m_ready || m_buffer == nullptr) { @@ -345,8 +320,7 @@ bool Channel::Stop() return true; } - -float Channel::GetCurrentTime() +float CChannel::GetCurrentTime() { if (!m_ready || m_buffer == nullptr) { @@ -363,8 +337,7 @@ float Channel::GetCurrentTime() return current; } - -void Channel::SetCurrentTime(float current) +void CChannel::SetCurrentTime(float current) { if (!m_ready || m_buffer == nullptr) { @@ -378,8 +351,7 @@ void Channel::SetCurrentTime(float current) } } - -float Channel::GetDuration() +float CChannel::GetDuration() { if (!m_ready || m_buffer == nullptr) { @@ -389,50 +361,42 @@ float Channel::GetDuration() return m_buffer->GetDuration(); } - -bool Channel::HasEnvelope() +bool CChannel::HasEnvelope() { return m_oper.size() > 0; } - -SoundOper& Channel::GetEnvelope() +SoundOper& CChannel::GetEnvelope() { return m_oper.front(); } - -void Channel::PopEnvelope() +void CChannel::PopEnvelope() { m_oper.pop_front(); } - -void Channel::SetLoop(bool loop) +void CChannel::SetLoop(bool loop) { m_loop = loop; } - -void Channel::Mute(bool mute) +void CChannel::Mute(bool mute) { m_mute = mute; } - -bool Channel::IsMuted() +bool CChannel::IsMuted() { return m_mute; } - -void Channel::Reset() +void CChannel::Reset() { m_id++; } - -int Channel::GetId() +int CChannel::GetId() { return m_id; } diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index b6050062..63b4362a 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -37,7 +37,7 @@ #include #include -class Buffer; +class CBuffer; struct SoundOper { @@ -49,11 +49,11 @@ struct SoundOper }; -class Channel +class CChannel { public: - Channel(); - ~Channel(); + CChannel(); + ~CChannel(); bool Play(); bool Pause(); @@ -77,7 +77,7 @@ public: bool IsReady(); bool IsLoaded(); - bool SetBuffer(Buffer *buffer); + bool SetBuffer(CBuffer *buffer); bool HasEnvelope(); SoundOper& GetEnvelope(); @@ -106,7 +106,7 @@ public: int GetId(); private: - Buffer *m_buffer; + CBuffer *m_buffer; ALuint m_source; int m_priority; diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index 7afe9568..fb10d2f4 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -153,7 +153,7 @@ bool CSoundInterface::StopAll() return true; } -bool CSoundInterface::MuteAll(bool bMute) +bool CSoundInterface::MuteAll(bool mute) { return true; } diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 2f2a7b09..92ac3f5d 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -208,9 +208,9 @@ void CButton::Draw() // Management of immediate mode, which sends the event "press" // before the mouse button is released. -void CButton::SetImmediat(bool bImmediat) +void CButton::SetImmediat(bool immediat) { - m_bImmediat = bImmediat; + m_bImmediat = immediat; } bool CButton::GetImmediat() diff --git a/src/ui/controls/button.h b/src/ui/controls/button.h index c4cc7e81..a5966621 100644 --- a/src/ui/controls/button.h +++ b/src/ui/controls/button.h @@ -38,7 +38,7 @@ public: void Draw() override; - void SetImmediat(bool bRepeat); + void SetImmediat(bool immediat); bool GetImmediat(); void SetRepeat(bool bRepeat); diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 7ed77b7e..be2301cd 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -699,12 +699,12 @@ bool CList::GetCheck(int i) // Specifies the bit "enable" for a box. -void CList::SetEnable(int i, bool bMode) +void CList::SetEnable(int i, bool enable) { if ( i < 0 || i >= m_totalLine ) return; - m_items[i].enable = bMode; + m_items[i].enable = enable; } // Returns the bit "enable" for a box. diff --git a/src/ui/controls/list.h b/src/ui/controls/list.h index abf90b22..82671c25 100644 --- a/src/ui/controls/list.h +++ b/src/ui/controls/list.h @@ -77,7 +77,7 @@ public: void SetCheck(int i, bool bMode); bool GetCheck(int i); - void SetEnable(int i, bool bEnable); + void SetEnable(int i, bool enable); bool GetEnable(int i); void SetTabs(int i, float pos, Gfx::TextAlign justif=Gfx::TEXT_ALIGN_LEFT); diff --git a/src/ui/controls/slider.h b/src/ui/controls/slider.h index ce2d5b47..ca35c13d 100644 --- a/src/ui/controls/slider.h +++ b/src/ui/controls/slider.h @@ -34,7 +34,7 @@ public: CSlider(); ~CSlider(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; void SetPos(Math::Point pos) override; void SetDim(Math::Point dim) override; diff --git a/src/ui/controls/target.h b/src/ui/controls/target.h index b7d70494..4de48c1d 100644 --- a/src/ui/controls/target.h +++ b/src/ui/controls/target.h @@ -37,7 +37,7 @@ public: CTarget(); ~CTarget(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; void Draw() override; diff --git a/src/ui/displaytext.h b/src/ui/displaytext.h index 8db4e938..6c36607f 100644 --- a/src/ui/displaytext.h +++ b/src/ui/displaytext.h @@ -19,8 +19,8 @@ #pragma once -#include "common/event.h" #include "common/error.h" +#include "common/event.h" #include diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 31e5ebbb..662e0a2c 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -29,14 +29,14 @@ #include "common/make_unique.h" #include "common/settings.h" -#include "level/robotmain.h" #include "level/player_profile.h" +#include "level/robotmain.h" #include "sound/sound.h" #include "ui/controls/button.h" -#include "ui/controls/label.h" #include "ui/controls/interface.h" +#include "ui/controls/label.h" #include "ui/controls/window.h" #include "ui/screen/screen_setup.h" diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index c61dd033..2cc52979 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -35,6 +35,11 @@ #include "ui/maindialog.h" +#include "ui/controls/group.h" +#include "ui/controls/interface.h" +#include "ui/controls/label.h" +#include "ui/controls/window.h" + #include "ui/screen/screen.h" #include "ui/screen/screen_apperance.h" #include "ui/screen/screen_io_read.h" @@ -43,19 +48,14 @@ #include "ui/screen/screen_loading.h" #include "ui/screen/screen_main_menu.h" #include "ui/screen/screen_player_select.h" +#include "ui/screen/screen_quit.h" #include "ui/screen/screen_setup_controls.h" #include "ui/screen/screen_setup_display.h" #include "ui/screen/screen_setup_game.h" #include "ui/screen/screen_setup_graphics.h" #include "ui/screen/screen_setup_sound.h" -#include "ui/screen/screen_quit.h" #include "ui/screen/screen_welcome.h" -#include "ui/controls/interface.h" -#include "ui/controls/group.h" -#include "ui/controls/label.h" -#include "ui/controls/window.h" - namespace Ui { diff --git a/src/ui/object_interface.h b/src/ui/object_interface.h index 7d892592..fb5d7919 100644 --- a/src/ui/object_interface.h +++ b/src/ui/object_interface.h @@ -53,7 +53,7 @@ public: CObjectInterface(COldObject* object); ~CObjectInterface(); - void DeleteObject(bool bAll=false); + void DeleteObject(bool all=false); bool EventProcess(const Event &event); bool CreateInterface(bool bSelect); diff --git a/src/ui/screen/screen.cpp b/src/ui/screen/screen.cpp index 7adc5df8..fce3a073 100644 --- a/src/ui/screen/screen.cpp +++ b/src/ui/screen/screen.cpp @@ -19,10 +19,10 @@ #include "ui/screen/screen.h" -#include "common/version.h" - #include "app/app.h" +#include "common/version.h" + #include "graphics/engine/engine.h" #include "level/robotmain.h" diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index fbae0483..450990f4 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -31,15 +31,15 @@ #include "sound/sound.h" -#include "ui/screen/screen_level_list.h" - #include "ui/controls/button.h" #include "ui/controls/edit.h" -#include "ui/controls/interface.h" #include "ui/controls/image.h" +#include "ui/controls/interface.h" #include "ui/controls/list.h" #include "ui/controls/window.h" +#include "ui/screen/screen_level_list.h" + #include #include diff --git a/src/ui/screen/screen_io_read.cpp b/src/ui/screen/screen_io_read.cpp index 5ce9753e..3fd4b6b9 100644 --- a/src/ui/screen/screen_io_read.cpp +++ b/src/ui/screen/screen_io_read.cpp @@ -26,8 +26,8 @@ #include "level/robotmain.h" #include "ui/controls/button.h" -#include "ui/controls/interface.h" #include "ui/controls/image.h" +#include "ui/controls/interface.h" #include "ui/controls/list.h" #include "ui/controls/window.h" diff --git a/src/ui/screen/screen_io_write.cpp b/src/ui/screen/screen_io_write.cpp index f5dcaca2..b372670b 100644 --- a/src/ui/screen/screen_io_write.cpp +++ b/src/ui/screen/screen_io_write.cpp @@ -27,8 +27,8 @@ #include "ui/controls/button.h" #include "ui/controls/edit.h" -#include "ui/controls/interface.h" #include "ui/controls/image.h" +#include "ui/controls/interface.h" #include "ui/controls/label.h" #include "ui/controls/list.h" #include "ui/controls/window.h" diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 680af0c6..33aeaafd 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -21,13 +21,12 @@ #include "app/app.h" -#include "level/robotmain.h" - #include "common/logger.h" #include "common/misc.h" #include "common/stringutils.h" #include "level/player_profile.h" +#include "level/robotmain.h" #include "sound/sound.h" @@ -194,9 +193,13 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); gamer = pl->GetItemName(pl->GetSelect()); - m_dialog->StartQuestion(StrUtils::Format(name.c_str(), gamer), true, false, false, [&]() { - NameDelete(); - }); + m_dialog->StartQuestion( + StrUtils::Format(name.c_str(), gamer), true, false, false, + [&]() + { + NameDelete(); + } + ); break; default: diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index b5da62f7..033e57e0 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -32,12 +32,12 @@ #include "common/resources/resourcemanager.h" -#include "level/robotmain.h" -#include "level/player_profile.h" - #include "graphics/engine/camera.h" #include "graphics/engine/engine.h" +#include "level/player_profile.h" +#include "level/robotmain.h" + #include "object/object.h" #include "object/interface/program_storage_object.h" diff --git a/test/unit/app/app_test.cpp b/test/unit/app/app_test.cpp index 3aec8eff..6075e7cb 100644 --- a/test/unit/app/app_test.cpp +++ b/test/unit/app/app_test.cpp @@ -61,16 +61,16 @@ public: } }; -class ApplicationUT : public testing::Test +class CApplicationUT : public testing::Test { protected: - ApplicationUT() : + CApplicationUT() : m_systemUtils(nullptr), m_stampUid(0), m_currentTime(0) {} - ~ApplicationUT() NOEXCEPT + ~CApplicationUT() NOEXCEPT {} void SetUp() override; @@ -99,7 +99,7 @@ private: long long m_currentTime; }; -void ApplicationUT::SetUp() +void CApplicationUT::SetUp() { m_systemUtils = m_mocks.Mock(); @@ -107,21 +107,21 @@ void ApplicationUT::SetUp() m_mocks.OnCall(m_systemUtils, CSystemUtils::GetLangPath).Return(""); m_mocks.OnCall(m_systemUtils, CSystemUtils::GetSaveDir).Return(""); - m_mocks.OnCall(m_systemUtils, CSystemUtils::CreateTimeStamp).Do(std::bind(&ApplicationUT::CreateTimeStamp, this)); - m_mocks.OnCall(m_systemUtils, CSystemUtils::DestroyTimeStamp).Do(std::bind(&ApplicationUT::DestroyTimeStamp, this, ph::_1)); - m_mocks.OnCall(m_systemUtils, CSystemUtils::CopyTimeStamp).Do(std::bind(&ApplicationUT::CopyTimeStamp, this, ph::_1, ph::_2)); - m_mocks.OnCall(m_systemUtils, CSystemUtils::GetCurrentTimeStamp).Do(std::bind(&ApplicationUT::GetCurrentTimeStamp, this, ph::_1)); - m_mocks.OnCall(m_systemUtils, CSystemUtils::TimeStampExactDiff).Do(std::bind(&ApplicationUT::TimeStampExactDiff, this, ph::_1, ph::_2)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::CreateTimeStamp).Do(std::bind(&CApplicationUT::CreateTimeStamp, this)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::DestroyTimeStamp).Do(std::bind(&CApplicationUT::DestroyTimeStamp, this, ph::_1)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::CopyTimeStamp).Do(std::bind(&CApplicationUT::CopyTimeStamp, this, ph::_1, ph::_2)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::GetCurrentTimeStamp).Do(std::bind(&CApplicationUT::GetCurrentTimeStamp, this, ph::_1)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::TimeStampExactDiff).Do(std::bind(&CApplicationUT::TimeStampExactDiff, this, ph::_1, ph::_2)); m_app = MakeUnique(m_systemUtils); } -void ApplicationUT::TearDown() +void CApplicationUT::TearDown() { m_app.reset(); } -SystemTimeStamp* ApplicationUT::CreateTimeStamp() +SystemTimeStamp* CApplicationUT::CreateTimeStamp() { auto stamp = MakeUnique(++m_stampUid); auto stampPtr = stamp.get(); @@ -129,33 +129,33 @@ SystemTimeStamp* ApplicationUT::CreateTimeStamp() return stampPtr; } -void ApplicationUT::DestroyTimeStamp(SystemTimeStamp *stamp) +void CApplicationUT::DestroyTimeStamp(SystemTimeStamp *stamp) { } -void ApplicationUT::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src) +void CApplicationUT::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src) { *static_cast(dst) = *static_cast(src); } -void ApplicationUT::GetCurrentTimeStamp(SystemTimeStamp *stamp) +void CApplicationUT::GetCurrentTimeStamp(SystemTimeStamp *stamp) { static_cast(stamp)->time = m_currentTime; } -long long ApplicationUT::TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) +long long CApplicationUT::TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) { return static_cast(after)->time - static_cast(before)->time; } -void ApplicationUT::NextInstant(long long diff) +void CApplicationUT::NextInstant(long long diff) { m_currentTime += diff; } -void ApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact, - float relTime, float absTime, - long long relTimeReal, long long absTimeReal) +void CApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absTimeExact, + float relTime, float absTime, + long long relTimeReal, long long absTimeReal) { Event event = m_app->CreateUpdateEvent(); EXPECT_EQ(EVENT_FRAME, event.type); @@ -169,14 +169,14 @@ void ApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absT } -TEST_F(ApplicationUT, UpdateEventTimeCalculation_SimulationSuspended) +TEST_F(CApplicationUT, UpdateEventTimeCalculation_SimulationSuspended) { m_app->SuspendSimulation(); Event event = m_app->CreateUpdateEvent(); EXPECT_EQ(EVENT_NULL, event.type); } -TEST_F(ApplicationUT, UpdateEventTimeCalculation_NormalOperation) +TEST_F(CApplicationUT, UpdateEventTimeCalculation_NormalOperation) { // 1st update @@ -205,7 +205,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_NormalOperation) TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); } -TEST_F(ApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation) +TEST_F(CApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation) { // 1st update @@ -228,7 +228,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation) EXPECT_EQ(EVENT_NULL, event.type); } -TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) +TEST_F(CApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) { m_app->SetSimulationSpeed(2.0f); @@ -287,7 +287,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); } -TEST_F(ApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation) +TEST_F(CApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation) { // 1st update -- simulation enabled diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp index 1bd6db14..02a85a31 100644 --- a/test/unit/app/system_linux_test.cpp +++ b/test/unit/app/system_linux_test.cpp @@ -22,7 +22,7 @@ #include -class SystemUtilsLinuxUT : public testing::Test +class CSystemUtilsLinuxUT : public testing::Test { protected: static const long long SEC = 1000000000; @@ -31,7 +31,7 @@ protected: }; -TEST_F(SystemUtilsLinuxUT, TimeStampDiff) +TEST_F(CSystemUtilsLinuxUT, TimeStampDiff) { SystemTimeStamp before, after; diff --git a/test/unit/app/system_windows_test.cpp b/test/unit/app/system_windows_test.cpp index a517f478..6398db01 100644 --- a/test/unit/app/system_windows_test.cpp +++ b/test/unit/app/system_windows_test.cpp @@ -31,7 +31,7 @@ public: } }; -class SystemUtilsWindowsUT : public testing::Test +class CSystemUtilsWindowsUT : public testing::Test { protected: static const long long SEC = 1000000000; @@ -39,7 +39,7 @@ protected: CSystemUtilsWindowsWrapper m_systemUtils; }; -TEST_F(SystemUtilsWindowsUT, TimeStampDiff) +TEST_F(CSystemUtilsWindowsUT, TimeStampDiff) { m_systemUtils.SetFrequency(SEC); diff --git a/test/unit/common/config_file_test.cpp b/test/unit/common/config_file_test.cpp index 9af7d8f3..6af0ffe0 100644 --- a/test/unit/common/config_file_test.cpp +++ b/test/unit/common/config_file_test.cpp @@ -17,9 +17,10 @@ * along with this program. If not, see http://gnu.org/licenses */ +#include "app/system.h" + #include "common/config_file.h" #include "common/logger.h" -#include "app/system.h" #include #include diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp index 06ba4ec4..dcddc0a0 100644 --- a/test/unit/graphics/engine/lightman_test.cpp +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -17,12 +17,12 @@ * along with this program. If not, see http://gnu.org/licenses */ -#include "graphics/engine/lightman.h" - #include "common/make_unique.h" #include "graphics/core/device.h" +#include "graphics/engine/lightman.h" + #include #include @@ -33,15 +33,15 @@ using namespace Gfx; using namespace HippoMocks; namespace ph = std::placeholders; -class LightManagerUT : public testing::Test +class CLightManagerUT : public testing::Test { protected: - LightManagerUT() : + CLightManagerUT() : m_engine(nullptr), m_device(nullptr), m_maxLightsCount(0) {} - ~LightManagerUT() NOEXCEPT + ~CLightManagerUT() NOEXCEPT {} void SetUp() override; @@ -64,7 +64,7 @@ private: int m_maxLightsCount; }; -void LightManagerUT::SetUp() +void CLightManagerUT::SetUp() { m_engine = m_mocks.Mock(); m_device = m_mocks.Mock(); @@ -72,7 +72,7 @@ void LightManagerUT::SetUp() m_lightManager = MakeUnique(m_engine); } -void LightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos) +void CLightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos) { m_maxLightsCount = maxLights; @@ -80,12 +80,12 @@ void LightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos) m_lightManager->SetDevice(m_device); - m_mocks.OnCall(m_device, CDevice::SetLight).Do(std::bind(&LightManagerUT::CheckLight, this, ph::_1, ph::_2)); + m_mocks.OnCall(m_device, CDevice::SetLight).Do(std::bind(&CLightManagerUT::CheckLight, this, ph::_1, ph::_2)); m_mocks.OnCall(m_engine, CEngine::GetEyePt).Return(eyePos); } -void LightManagerUT::CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights) +void CLightManagerUT::CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights) { m_expectedLightTypes = expectedLights; @@ -105,14 +105,14 @@ void LightManagerUT::CheckLightSorting(EngineObjectType objectType, const std::v m_lightManager->UpdateDeviceLights(objectType); } -void LightManagerUT::CheckLight(int index, const Light& light) +void CLightManagerUT::CheckLight(int index, const Light& light) { ASSERT_TRUE(index >= 0 && index < static_cast( m_expectedLightTypes.size() )); ASSERT_EQ(m_expectedLightTypes[index], light.type); } -void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled, - Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType) +void CLightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled, + Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType) { int rank = m_lightManager->CreateLight(priority); @@ -129,7 +129,7 @@ void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool m_lightManager->DeleteLight(rank); } -TEST_F(LightManagerUT, LightSorting_UnusedOrDisabledAreSkipped) +TEST_F(CLightManagerUT, LightSorting_UnusedOrDisabledAreSkipped) { const int lightCount = 10; const Math::Vector eyePos(0.0f, 0.0f, 0.0f); @@ -143,7 +143,7 @@ TEST_F(LightManagerUT, LightSorting_UnusedOrDisabledAreSkipped) CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } -TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded) +TEST_F(CLightManagerUT, LightSorting_IncludeTypesAreIncluded) { const int lightCount = 10; const Math::Vector eyePos(0.0f, 0.0f, 0.0f); @@ -157,7 +157,7 @@ TEST_F(LightManagerUT, LightSorting_IncludeTypesAreIncluded) CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } -TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded) +TEST_F(CLightManagerUT, LightSorting_ExcludeTypesAreExcluded) { const int lightCount = 10; const Math::Vector eyePos(0.0f, 0.0f, 0.0f); @@ -171,7 +171,7 @@ TEST_F(LightManagerUT, LightSorting_ExcludeTypesAreExcluded) CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights); } -TEST_F(LightManagerUT, LightSorting_SortingAccordingToDistance) +TEST_F(CLightManagerUT, LightSorting_SortingAccordingToDistance) { const int lightCount = 3; const Math::Vector eyePos(0.0f, 0.0f, 0.0f); From 0aa97fe074ecfec6db2930b8443146a3430f1335 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 4 Oct 2015 18:13:13 +0200 Subject: [PATCH 034/360] Restored Ceebot-Teen toy sound --- data | 2 +- src/physics/physics.cpp | 4 ++-- src/sound/sound_type.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data b/data index bbfc7d0e..4ecbafd9 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit bbfc7d0ea4e90b9d9694a3812874afeabc7bbbfb +Subproject commit 4ecbafd960f3718dc166cbc1011f42deb51e11dd diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 01a40417..cd91f7d3 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -1903,7 +1903,7 @@ void CPhysics::SoundMotorFull(float rTime, ObjectType type) if ( m_object->GetToy() ) { - sound = SOUND_NONE; //SOUND_MOTORd; + sound = SOUND_MOTORd; amplitude = 1.0f; time = 0.1f; } @@ -2002,7 +2002,7 @@ void CPhysics::SoundMotorSlow(float rTime, ObjectType type) if ( m_object->GetToy() ) { - sound = SOUND_NONE; // SOUND_MOTORd; + sound = SOUND_MOTORd; amplitude = 0.0f; } diff --git a/src/sound/sound_type.h b/src/sound/sound_type.h index e345d30f..c9ba3f3e 100644 --- a/src/sound/sound_type.h +++ b/src/sound/sound_type.h @@ -110,7 +110,7 @@ enum SoundType SOUND_FIREp = 78, /*!< shooting with phazer */ SOUND_EXPLOg1 = 79, /*!< impact gun 1 */ SOUND_EXPLOg2 = 80, /*!< impact gun 2 */ -// SOUND_MOTORd = 81, /*!< engine friction */ + SOUND_MOTORd = 81, /*!< engine friction */ SOUND_MAX /** number of items in enum */ }; From 1b855f5dc342f3b38e6ee8f7afd4db12bca61886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Thu, 15 Oct 2015 17:40:15 +0200 Subject: [PATCH 035/360] Possible fix for issue #667 --- src/ui/controls/edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 200a56b3..eb5f8295 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -246,7 +246,7 @@ void CEdit::MoveAdjust() bool CEdit::EventProcess(const Event &event) { - bool bShift, bControl; + bool bShift = false, bControl = false; if ( (m_state & STATE_VISIBLE) == 0 ) return true; From 93c9391124fbd750e3788cd872a8f063ceff56aa Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 17 Oct 2015 17:43:30 +0200 Subject: [PATCH 036/360] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 4ecbafd9..e58534ab 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 4ecbafd960f3718dc166cbc1011f42deb51e11dd +Subproject commit e58534ab5a7ecb1e3648338df9c616ba82fd6f0c From 6a396e1522ee22526e85cf46889fedbb08dd3757 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 1 Nov 2015 17:03:30 +0100 Subject: [PATCH 037/360] Add unit tests for class CBotString. Add comments in class CBotString. Change existing comments in class CBotString to be compliant with doxygen. Add function "const char* CBotString::CStr() const". Add null pointer check in function "const CBotString& CBotString::operator+=(const CBotString& str)" Remove functions "CBotString CBotString::Mid(int nFirst, int nCount) const" and "CBotString CBotString::Mid(int nFirst) const" because they were doublons of function "CBotString CBotString::Mid(int nFirst, int lg) const" --- src/CBot/CBotDll.h | 167 ++++++++++-- src/CBot/CBotString.cpp | 96 +++---- test/unit/CBot/CBotString_test.cpp | 415 +++++++++++++++++++++++++++++ test/unit/CMakeLists.txt | 1 + 4 files changed, 590 insertions(+), 89 deletions(-) create mode 100644 test/unit/CBot/CBotString_test.cpp diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index bcb02d18..9027dfb0 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -250,37 +250,146 @@ private: //////////////////////////////////////////////////////////////////////// -// -// as part of MFC CString not used here. -// -// ( all functions are not implemented yet ) - -/** \brief CBotString Class used to work on strings */ +/** + * \brief CBotString Class used to work on strings + */ class CBotString { public: + + /** + * \brief CBotString Default constructor. + */ CBotString(); + + /** + * \brief CBotString + * \param p + */ CBotString(const char* p); + + /** + * \brief CBotString + * \param p + */ CBotString(const CBotString& p); + + /** + * \brief CBotString Destructor. + */ ~CBotString(); - void Empty(); - bool IsEmpty() const; - int GetLength(); - int Find(const char c); - int Find(const char* lpsz); - int ReverseFind(const char c); - int ReverseFind(const char* lpsz); - bool LoadString(unsigned int id); - CBotString Mid(int nFirst, int nCount) const; - CBotString Mid(int nFirst) const; - CBotString Mid(int start, int lg=-1); - CBotString Left(int nCount) const; - CBotString Right(int nCount) const; - int Compare(const char* lpsz) const; - void MakeUpper(); - void MakeLower(); + /** + * \brief Empty Clear the internal string. + */ + void Empty(); + /** + * \brief IsEmpty Check if the string is empty. + * \return True if the sting is empty false otherwise. + */ + bool IsEmpty() const; + + /** + * \brief GetLength Get the string length. + * \return The size of the string. + */ + int GetLength(); + + /** + * \brief Find Find the position of a character in a string starting from + * the beginning of the string. + * \param c The character to find. + * \return The position of the character or -1 if the character was not + * found. + * \see ReverseFind(const char c) + */ + int Find(const char c); + + /** + * \brief Find Find the position of a string in a string starting from the + * beginning of the string. + * \param lpsz The string to find. + * \return The position of the string or -1 if the string was not + * found. + * \see ReverseFind(const char* lpsz) + */ + int Find(const char* lpsz); + + /** + * \brief Find Find the position of a character in a string starting from + * the end of the string. + * \param c The character to find. + * \return The position of the character or -1 if the character was not + * found. + * \see Find(const char c) + */ + int ReverseFind(const char c); + + /** + * \brief Find Find the position of a string in a string starting from the + * end of the string. + * \param lpsz The string to find. + * \return The string of the character or -1 if the string was not + * found. + * \see Find(const char* lpsz) + */ + int ReverseFind(const char* lpsz); + + /** + * \brief LoadString Load the string associate with the id. + * \param id The id to load. + * \return True if the id exist false otherwise. + */ + bool LoadString(unsigned int id); + + /** + * \brief Mid Return a part of a string from a starting index and until + * the end of the string with a limited size. + * \param nFirst The start index of the character in the string. + * \param lg The size limit. Default value is 2000. + * \return The exctracted string. + */ + CBotString Mid(int start, int lg=-1); + + /** + * \brief Left Return a part of a string starting from the left. + * \param nCount The number of character to retreive. + * \return The exctracted string. + */ + CBotString Left(int nCount) const; + + /** + * \brief Right Return a part of a string starting from the right. + * \param nCount The number of character to retreive. + * \return The exctracted string. + */ + CBotString Right(int nCount) const; + + /** + * \brief Compare Compare a given string to an other. + * \param lpsz The string to compare. + * \return 0 if the two string matches. Less than 0 if the current + * string is less than lpsz. Greater than 0 if the current + * string is greater than lpsz. + */ + int Compare(const char* lpsz) const; + + /** + * \brief MakeUpper Uppercase the string. + */ + void MakeUpper(); + + /** + * \brief MakeLower Lowercase the string. + */ + void MakeLower(); + + /** + * @brief CStr Convert the CBotString to a C string. + * @return A C string string. + */ + const char* CStr() const; /** * \brief Overloaded oprators to work on CBotString classes @@ -311,19 +420,19 @@ public: private: - /** \brief Pointer to string */ + //! \brief Pointer to string char* m_ptr; - /** \brief Length of the string */ + //! \brief Length of the string int m_lg; - /** \brief Keeps the string corresponding to keyword ID */ - static const std::map s_keywordString; + //! \brief Keeps the string corresponding to keyword ID + static const std::map s_keywordString; /** - * \brief MapIdToString maps given ID to its string equivalent - * \param id Provided identifier - * \return string if found, else NullString + * \brief MapIdToString Maps given ID to its string equivalent. + * \param id Provided identifier. + * \return String if found, else NullString. */ static const char * MapIdToString(EID id); }; diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 5c58c963..a4240b98 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -209,48 +209,29 @@ CBotString CBotString::Right(int nCount) const return CBotString(chain); } -CBotString CBotString::Mid(int nFirst, int nCount) const +CBotString CBotString::Mid(int start, int lg) { - char chain[2000]; + CBotString res; - // clamps nFirst to correct value - if(nFirst < 0) nFirst = 0; - if(nFirst > m_lg) nFirst = m_lg; + if (lg == -1) lg = 2000; - // clamp nCount to correct value - int remaining = m_lg - nFirst; - if(nCount > remaining) nCount = remaining; - if(nCount < 0) nCount = 0; + // clamp start to correct value + if (start < 0) start = 0; + if (start >= m_lg) return res; - int i; - for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i) - { - chain[i] = m_ptr[i]; - } - chain[i] = 0 ; + int remaining = m_lg - start; + if (lg > remaining) lg = remaining; + if (lg < 0) lg = 0; - return CBotString(chain); + char* p = new char[m_lg+1]; + strcpy(p, m_ptr+start); + p[lg] = 0; + + res = p; + delete[] p; + return res; } -CBotString CBotString::Mid(int nFirst) const -{ - char chain[2000]; - - // clamp nFirst to correct value - if(nFirst < 0) nFirst = 0; - if(nFirst > m_lg) nFirst = m_lg; - - int i; - for (i = nFirst; i < m_lg && i < 1999 ; ++i) - { - chain[i] = m_ptr[i]; - } - chain[i] = 0 ; - - return CBotString(chain); -} - - int CBotString::Find(const char c) { for (int i = 0; i < m_lg; ++i) @@ -303,29 +284,6 @@ bad:; return -1; } -CBotString CBotString::Mid(int start, int lg) -{ - CBotString res; - - if (lg == -1) lg = 2000; - - // clamp start to correct value - if (start < 0) start = 0; - if (start >= m_lg) return res; - - int remaining = m_lg - start; - if (lg > remaining) lg = remaining; - if (lg < 0) lg = 0; - - char* p = new char[m_lg+1]; - strcpy(p, m_ptr+start); - p[lg] = 0; - - res = p; - delete[] p; - return res; -} - void CBotString::MakeUpper() { for (size_t i = 0; static_cast(i) < m_lg && static_cast(i) < 1999 ; ++i) @@ -453,9 +411,19 @@ const CBotString& CBotString::operator+=(const CBotString& str) { char* p = new char[m_lg+str.m_lg+1]; - strcpy(p, m_ptr); + //-- Check if the pointer is not null befor trying to copy it + if(m_ptr != nullptr) + { + strcpy(p, m_ptr); + } + char* pp = p + m_lg; - strcpy(pp, str.m_ptr); + + //-- Check if the pointer is not null befor trying to copy it + if(str.m_ptr != nullptr) + { + strcpy(pp, str.m_ptr); + } m_lg = m_lg + str.m_lg; @@ -546,6 +514,14 @@ CBotString::operator const char * () const return m_ptr; } +const char* CBotString::CStr() const +{ + if (this == nullptr || m_ptr == nullptr) + { + return emptyString; + } + return m_ptr; +} int CBotString::Compare(const char * lpsz) const { diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp new file mode 100644 index 00000000..22171c6a --- /dev/null +++ b/test/unit/CBot/CBotString_test.cpp @@ -0,0 +1,415 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBot/CBotDll.h" + +// Local include + +// Global include +#include + +/** + * @brief CBotString_Test.Empty Check Empty and IsEmpty functions of class + * CBotString_Test. + */ +TEST(CBotString_Test, Empty) +{ + CBotString str1; + EXPECT_EQ(true, str1.IsEmpty()); + + CBotString str2("qsexrdctfvygbuh"); + EXPECT_EQ(false, str2.IsEmpty()); + str2.Empty(); + EXPECT_EQ(true, str2.IsEmpty()); +} + +/** + * @brief CBotString_Test.Length Check GetLength function of class + * CBotString_Test. + */ +TEST(CBotString_Test, Length) +{ + CBotString str1; + EXPECT_EQ(0, str1.GetLength()); + + CBotString str2("a"); + EXPECT_EQ(1, str2.GetLength()); + + CBotString str3("aaaaa"); + EXPECT_EQ(5, str3.GetLength()); +} + +/** + * @brief CBotString_Test.Find Check find functions of class CBotString_Test + */ +TEST(CBotString_Test, Find) +{ + CBotString str1("a"); + EXPECT_EQ(0, str1.Find('a')); + + CBotString str2("b"); + EXPECT_EQ(-1, str2.Find('a')); + + CBotString str3("bbabb"); + EXPECT_EQ(2, str3.Find('a')); + + CBotString str4("bbAbb"); + EXPECT_EQ(-1, str4.Find('a')); + + CBotString str5("bbAbb"); + EXPECT_EQ(2, str5.Find('A')); + + CBotString str6("test"); + EXPECT_EQ(0, str6.Find("test")); + + CBotString str7("azazdazd"); + EXPECT_EQ(-1, str7.Find("test")); + + CBotString str8("bbtestbb"); + EXPECT_EQ(2, str8.Find("test")); + + CBotString str9("bbTestbb"); + EXPECT_EQ(-1, str9.Find("test")); + + CBotString str10("bbTestbb"); + EXPECT_EQ(2, str10.Find("Test")); +} + +/** + * @brief CBotString_Test.ReverseFind Check find functions of class + * CBotString_Test + */ +TEST(CBotString_Test, ReverseFind) +{ + CBotString str1("a"); + EXPECT_EQ(0, str1.ReverseFind('a')); + + CBotString str2("b"); + EXPECT_EQ(-1, str2.ReverseFind('a')); + + CBotString str3("bbabb"); + EXPECT_EQ(2, str3.ReverseFind('a')); + + CBotString str4("bbAbb"); + EXPECT_EQ(-1, str4.ReverseFind('a')); + + CBotString str5("bbAbb"); + EXPECT_EQ(2, str5.ReverseFind('A')); + + CBotString str6("test"); + EXPECT_EQ(0, str6.ReverseFind("test")); + + CBotString str7("azazdazd"); + EXPECT_EQ(-1, str7.ReverseFind("test")); + + CBotString str8("bbtestbb"); + EXPECT_EQ(2, str8.ReverseFind("test")); + + CBotString str9("bbTestbb"); + EXPECT_EQ(-1, str9.ReverseFind("test")); + + CBotString str10("bbTestbb"); + EXPECT_EQ(2, str10.ReverseFind("Test")); +} + +/** + * @brief CBotString_Test.Mid Check Mid functions of class CBotString_Test + */ +TEST(CBotString_Test, Mid) +{ + CBotString str1("aaaColobot"); + EXPECT_STREQ(str1.Mid(3).CStr(), "Colobot"); + + CBotString str2("aaaColobotaa"); + EXPECT_STREQ(str2.Mid(3,7).CStr(), "Colobot"); +} + +/** + * @brief CBotString_Test.Left Check Left function of class CBotString_Test + */ +TEST(CBotString_Test, Left) +{ + CBotString str1("Colobotaaa"); + EXPECT_STREQ(str1.Left(7).CStr(), "Colobot"); +} + +/** + * @brief CBotString_Test.Right Check Right function of class CBotString_Test + */ +TEST(CBotString_Test, Right) +{ + CBotString str1("aaaColobot"); + EXPECT_STREQ(str1.Right(7).CStr(), "Colobot"); +} + +/** + * @brief CBotString_Test.Compare Check Compare function of class + * CBotString_Test + */ +TEST(CBotString_Test, Compare) +{ + CBotString str1("colobot"); + EXPECT_EQ(0, str1.Compare("colobot")); + + CBotString str2("a"); + EXPECT_GT(0, str2.Compare("colobot")); + + CBotString str3("z"); + EXPECT_LT(0, str3.Compare("colobot")); +} + +/** + * @brief CBotString_Test.MakeUpper Check MakeUpper function of class + * CBotString_Test + */ +TEST(CBotString_Test, MakeUpper) +{ + CBotString str1("colobot"); + str1.MakeUpper(); + EXPECT_STREQ(str1.CStr(), "COLOBOT"); + + CBotString str2("Colobot"); + str2.MakeUpper(); + EXPECT_STREQ(str2.CStr(), "COLOBOT"); +} + +/** + * @brief CBotString_Test.MakeLower Check MakeLower function of class + * CBotString_Test + */ +TEST(CBotString_Test, MakeLower) +{ + CBotString str1("COLOBOT"); + str1.MakeLower(); + EXPECT_STREQ(str1.CStr(), "colobot"); + + CBotString str2("Colobot"); + str2.MakeLower(); + EXPECT_STREQ(str2.CStr(), "colobot"); +} + +/** + * @brief CBotString_Test.operatorEqual Check operator equal of class + * CBotString_Test + */ +TEST(CBotString_Test, operatorEqual) +{ + //-- CBotString + CBotString botStr1; + CBotString botStr2("Colobot"); + + //-- C Character + const char cStr1[2] = "C"; + + //-- C string + const char cStr2[8] = "Colobot"; + + //-- Compare with CBotString + botStr1 = botStr2; + EXPECT_STREQ(botStr1.CStr(), botStr2.CStr()); + + //-- Compare with C character + botStr1 = cStr1[0]; + EXPECT_STREQ(botStr1.CStr(), cStr1); + + //-- Compare with C string + botStr1 = cStr2; + EXPECT_STREQ(botStr1.CStr(), cStr2); + +} + +/** + * @brief CBotString_Test.operatorIsEqual Check operator is equal of class + * CBotString_Test + */ +TEST(CBotString_Test, operatorIsEqual) +{ + //-- CBotString + CBotString botStr1("C"); + CBotString botStr2("C"); + CBotString botStr3("Colobot"); + + //-- C string + const char cStr1[8] = "Colobot"; + const char cStr2[8] = "colobot"; + + EXPECT_EQ(true, (botStr1 == botStr2)); + EXPECT_EQ(false, (botStr1 == botStr3)); + + //-- Compare with C string + EXPECT_EQ(true, (botStr3 == cStr1)); + EXPECT_EQ(false, (botStr3 == cStr2)); +} + +/** + * @brief CBotString_Test.operatorAdd Check operator add of class + * CBotString_Test. + */ +TEST(CBotString_Test, operatorAdd) +{ + //-- CBotString + CBotString botStr1; + CBotString botStr2("C"); + CBotString botStr3("olobot"); + CBotString botStr4("Colobot"); + + //-- C string + const char cStr1[7] = "olobot"; + + botStr1 + botStr2; + botStr1 + botStr3; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); + + botStr1.Empty(); + botStr1 = botStr2 + cStr1; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); + + botStr1.Empty(); + botStr1 += botStr2; + botStr1 += botStr3; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); + + + botStr1.Empty(); + botStr1 += botStr2; + botStr1 += cStr1; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); +} + +/** + * @brief CBotString_Test.operatorDiff Check operator diff of class + * CBotString_Test. + */ +TEST(CBotString_Test, operatorDiff) +{ + //-- CBotString + CBotString botStr1("C"); + CBotString botStr2("C"); + CBotString botStr3("Colobot"); + + //-- C string + const char cStr1[8] = "Colobot"; + const char cStr2[8] = "colobot"; + + EXPECT_EQ(false, (botStr1 != botStr2)); + EXPECT_EQ(true, (botStr1 != botStr3)); + + //-- Compare with C string + EXPECT_EQ(false, (botStr3 != cStr1)); + EXPECT_EQ(true, (botStr3 != cStr2)); +} + +/** + * @brief CBotString_Test.operatorSuperior Check operator superior of class + * CBotString_Test. + */ +TEST(CBotString_Test, operatorSuperior) +{ + //-- CBotString + CBotString botStr1("a"); + CBotString botStr2("z"); + CBotString botStr3("colobot"); + + //-- C string + const char cStr1[2] = "a"; + const char cStr2[2] = "z"; + + EXPECT_EQ(true, (botStr3 > botStr1)); + EXPECT_EQ(false, (botStr3 > botStr2)); + + //-- Compare with C string + EXPECT_EQ(true, (botStr3 > cStr1)); + EXPECT_EQ(false, (botStr3 > cStr2)); +} + +/** + * @brief CBotString_Test.operatorSuperiorOrEqual Check operator superior or + * equa of class CBotString_Test. + */ +TEST(CBotString_Test, operatorSuperiorOrEqual) +{ + //-- CBotString + CBotString botStr1("a"); + CBotString botStr2("z"); + CBotString botStr3("colobot"); + + //-- C string + const char cStr1[2] = "a"; + const char cStr2[2] = "z"; + const char cStr3[8] = "colobot"; + + EXPECT_EQ(true, (botStr3 >= botStr1)); + EXPECT_EQ(false, (botStr3 >= botStr2)); + EXPECT_EQ(true, (botStr3 >= botStr3)); + + //-- Compare with C string + EXPECT_EQ(true, (botStr3 >= cStr1)); + EXPECT_EQ(false, (botStr3 >= cStr2)); + EXPECT_EQ(true, (botStr3 >= cStr3)); +} + +/** + * @brief CBotString_Test.operatorInferior Check operator Inferior of class + * CBotString_Test. + */ +TEST(CBotString_Test, operatorInferior) +{ + //-- CBotString + CBotString botStr1("a"); + CBotString botStr2("z"); + CBotString botStr3("colobot"); + + //-- C string + const char cStr1[2] = "a"; + const char cStr2[2] = "z"; + + EXPECT_EQ(false, (botStr3 < botStr1)); + EXPECT_EQ(true, (botStr3 < botStr2)); + + //-- Compare with C string + EXPECT_EQ(false, (botStr3 < cStr1)); + EXPECT_EQ(true, (botStr3 < cStr2)); +} + +/** + * @brief CBotString_Test.operatorInferiorOrEqual Check operator Inferior or + * equa of class CBotString_Test. + */ +TEST(CBotString_Test, operatorInferiorOrEqual) +{ + //-- CBotString + CBotString botStr1("a"); + CBotString botStr2("z"); + CBotString botStr3("colobot"); + + //-- C string + const char cStr1[2] = "a"; + const char cStr2[2] = "z"; + const char cStr3[8] = "colobot"; + + EXPECT_EQ(false, (botStr3 <= botStr1)); + EXPECT_EQ(true, (botStr3 <= botStr2)); + EXPECT_EQ(true, (botStr3 <= botStr3)); + + //-- Compare with C string + EXPECT_EQ(false, (botStr3 <= cStr1)); + EXPECT_EQ(true, (botStr3 <= cStr2)); + EXPECT_EQ(true, (botStr3 <= cStr3)); +} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index f12c3a22..5bdc38a4 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,6 +15,7 @@ set(UT_SOURCES math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp + CBot/CBotString_test.cpp ${PLATFORM_TESTS} ) From eeea31408b5c92a3677e9b65fe168dab1377344d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 2 Nov 2015 22:08:52 +0000 Subject: [PATCH 038/360] Fix operator+ semantics in CBotString --- src/CBot/CBotDll.h | 2 +- src/CBot/CBotString.cpp | 16 ++++------------ test/unit/CBot/CBotString_test.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 9027dfb0..c05e1a50 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -397,8 +397,8 @@ public: const CBotString& operator=(const CBotString& stringSrc); const CBotString& operator=(const char ch); const CBotString& operator=(const char* pString); - const CBotString& operator+(const CBotString& str); friend CBotString operator+(const CBotString& string, const char* lpsz); + CBotString operator+(const CBotString& str); const CBotString& operator+=(const char ch); const CBotString& operator+=(const CBotString& str); diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index a4240b98..5f7792c1 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -344,19 +344,11 @@ CBotString operator+(const CBotString& string, const char * lpsz) return s; } -const CBotString& CBotString::operator+(const CBotString& stringSrc) +CBotString CBotString::operator+(const CBotString& stringSrc) { - char* p = new char[m_lg+stringSrc.m_lg+1]; - - if (m_ptr!=nullptr) strcpy(p, m_ptr); - char* pp = p + m_lg; - if (stringSrc.m_ptr!=nullptr) strcpy(pp, stringSrc.m_ptr); - - delete[] m_ptr; - m_ptr = p; - m_lg += stringSrc.m_lg; - - return *this; + CBotString s(*this); + s += stringSrc; + return s; } const CBotString& CBotString::operator=(const char ch) diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index 22171c6a..ebec2024 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -271,10 +271,13 @@ TEST(CBotString_Test, operatorAdd) CBotString botStr4("Colobot"); //-- C string - const char cStr1[7] = "olobot"; + const char* cStr1 = "olobot"; - botStr1 + botStr2; - botStr1 + botStr3; + botStr1 = botStr1 + botStr2; + botStr1 = botStr1 + botStr3; + EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); + + botStr1 = "C" + botStr3; EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); botStr1.Empty(); From 13f01597050191b604e7cbbd33c8cdcdc503169b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 2 Nov 2015 22:17:53 +0000 Subject: [PATCH 039/360] Fix ambiguous overload resolution One operator+ for CBotString is enough --- src/CBot/CBotDll.h | 1 - src/CBot/CBotFunction.cpp | 2 +- src/CBot/CBotString.cpp | 7 ------- src/CBot/CBotVar.cpp | 2 +- test/unit/CBot/CBotString_test.cpp | 3 --- 5 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index c05e1a50..47dbb480 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -397,7 +397,6 @@ public: const CBotString& operator=(const CBotString& stringSrc); const CBotString& operator=(const char ch); const CBotString& operator=(const char* pString); - friend CBotString operator+(const CBotString& string, const char* lpsz); CBotString operator+(const CBotString& str); const CBotString& operator+=(const char ch); diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 4bc4303c..4ef40216 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -216,7 +216,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct if ( IsOfType(p, ID_NOT) ) { - CBotToken d("~" + p->GetString()); + CBotToken d(CBotString("~") + p->GetString()); func->m_token = d; } diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 5f7792c1..52e63a34 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -337,13 +337,6 @@ const CBotString& CBotString::operator=(const CBotString& stringSrc) return *this; } -CBotString operator+(const CBotString& string, const char * lpsz) -{ - CBotString s(string); - s += lpsz; - return s; -} - CBotString CBotString::operator+(const CBotString& stringSrc) { CBotString s(*this); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index da5119f8..2898a92a 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -1703,7 +1703,7 @@ void CBotVarClass::DecrementUse() pThis->SetPointer(this); CBotVar* pResult = nullptr; - CBotString nom = "~" + m_pClass->GetName(); + CBotString nom = CBotString("~") + m_pClass->GetName(); long ident = 0; while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index ebec2024..97576a99 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -277,9 +277,6 @@ TEST(CBotString_Test, operatorAdd) botStr1 = botStr1 + botStr3; EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); - botStr1 = "C" + botStr3; - EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); - botStr1.Empty(); botStr1 = botStr2 + cStr1; EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); From ad9915d1e44a1838c260cec38272e8a6bb73a1d0 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Tue, 3 Nov 2015 20:19:43 +0100 Subject: [PATCH 040/360] Update data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index e58534ab..a125f7ab 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit e58534ab5a7ecb1e3648338df9c616ba82fd6f0c +Subproject commit a125f7ab3f967466d1903bf8b16016036adaebd9 From ce480c1720a542fd9f2a0d77d11105791fd550d8 Mon Sep 17 00:00:00 2001 From: piotrwalkusz1 Date: Sun, 8 Nov 2015 19:03:35 +0100 Subject: [PATCH 041/360] Fix #670 --- src/level/robotmain.cpp | 57 ++++++++++++++++++++++++----------------- src/ui/displayinfo.cpp | 4 +-- src/ui/maindialog.cpp | 4 +-- src/ui/studio.cpp | 4 +-- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 6290075e..a68f5444 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -426,6 +426,12 @@ void CRobotMain::ChangePhase(Phase phase) } m_phase = phase; + + if (m_phase != PHASE_SIMUL) + { + Ui::CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); + if ( pw != nullptr ) pw->ClearState(Ui::STATE_VISIBLE | Ui::STATE_ENABLE); + } if (resetWorld) { @@ -5915,33 +5921,36 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) void CRobotMain::CreateCodeBattleInterface() { - Math::Point pos, ddim; + if(m_phase == PHASE_SIMUL) + { + Math::Point pos, ddim; - ddim.x = 100.0f/640.0f; - ddim.y = 100.0f/480.0f; - pos.x = 540.0f/640.0f; - pos.y = 100.0f/480.0f; - Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6); + ddim.x = 100.0f/640.0f; + ddim.y = 100.0f/480.0f; + pos.x = 540.0f/640.0f; + pos.y = 100.0f/480.0f; + Ui::CWindow* pw = m_interface->CreateWindows(pos, ddim, 3, EVENT_WINDOW6); - ddim.x = 100.0f/640.0f; - ddim.y = 16.0f/480.0f; - pos.x = 540.0f/640.0f; - pos.y = 178.0f/480.0f; - pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, "Code battle"); + ddim.x = 100.0f/640.0f; + ddim.y = 16.0f/480.0f; + pos.x = 540.0f/640.0f; + pos.y = 178.0f/480.0f; + pw->CreateLabel(pos, ddim, 0, EVENT_LABEL0, "Code battle"); - float titleBarSize = (11.0f/64.0f); // this is from the texture - ddim.x = 80.0f/640.0f; - ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f; - pos.x = 550.0f/640.0f; - pos.y = 110.0f/480.0f; - if (!m_codeBattleStarted) - { - pw->CreateButton(pos, ddim, 21, EVENT_CODE_BATTLE_START); - } - else - { - pw->CreateButton(pos, ddim, 13, EVENT_CODE_BATTLE_SPECTATOR); - } + float titleBarSize = (11.0f/64.0f); // this is from the texture + ddim.x = 80.0f/640.0f; + ddim.y = ((1-titleBarSize)*100.0f-20.0f)/480.0f; + pos.x = 550.0f/640.0f; + pos.y = 110.0f/480.0f; + if (!m_codeBattleStarted) + { + pw->CreateButton(pos, ddim, 21, EVENT_CODE_BATTLE_START); + } + else + { + pw->CreateButton(pos, ddim, 13, EVENT_CODE_BATTLE_SPECTATOR); + } + } } void CRobotMain::DestroyCodeBattleInterface() diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 6e28d744..04fec5c1 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -368,7 +368,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_camera->SetType(Gfx::CAM_TYPE_INFO); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if (pw != nullptr) pw->ClearState(STATE_VISIBLE); + if (pw != nullptr) pw->ClearState(STATE_VISIBLE | STATE_ENABLE); pos = m_infoActualPos = m_infoFinalPos; dim = m_infoActualDim = m_infoFinalDim; @@ -830,7 +830,7 @@ void CDisplayInfo::StopDisplayInfo() m_main->SetEditLock(false, false); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if (pw != nullptr) pw->SetState(STATE_VISIBLE); + if (pw != nullptr) pw->SetState(STATE_VISIBLE | STATE_ENABLE); } m_pause->DeactivatePause(m_satcomPause); m_satcomPause = nullptr; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 662e0a2c..f41fcdf9 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -371,7 +371,7 @@ void CMainDialog::StartDialog(Math::Point dim, bool fireParticles) if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->ClearState(STATE_VISIBLE); + if ( pw != nullptr ) pw->ClearState(STATE_VISIBLE | STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->ClearState(STATE_ENABLE); @@ -526,7 +526,7 @@ void CMainDialog::StopDialog() if ( pw != nullptr ) pw->SetState(STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if ( pw != nullptr ) pw->SetState(STATE_VISIBLE); + if ( pw != nullptr ) pw->SetState(STATE_VISIBLE | STATE_ENABLE); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW7)); if ( pw != nullptr ) pw->SetState(STATE_ENABLE); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 033e57e0..614a2888 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -585,7 +585,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra m_script->SetStepMode(!m_bRealTime); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if (pw != nullptr) pw->ClearState(STATE_VISIBLE); + if (pw != nullptr) pw->ClearState(STATE_VISIBLE | STATE_ENABLE); pos = m_editFinalPos = m_editActualPos = m_settings->GetWindowPos(); dim = m_editFinalDim = m_editActualDim = m_settings->GetWindowDim(); @@ -911,7 +911,7 @@ bool CStudio::StopEditScript(bool bCancel) m_interface->DeleteControl(EVENT_WINDOW3); pw = static_cast(m_interface->SearchControl(EVENT_WINDOW6)); - if (pw != nullptr) pw->SetState(STATE_VISIBLE); + if (pw != nullptr) pw->SetState(STATE_VISIBLE | STATE_ENABLE); m_pause->DeactivatePause(m_editorPause); m_editorPause = nullptr; From 2b03ed3a212eb8e9b16cecc3ecc4078c10d545b4 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sat, 21 Nov 2015 13:27:40 +0100 Subject: [PATCH 042/360] Fixed calling not overriden methods in CBot see #540 --- src/CBot/CBotClass.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 3e1e0077..bebd7692 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -366,6 +366,14 @@ bool CBotClass::ExecuteMethode(long& nIdent, const char* name, if (ret>=0) return ret; ret = m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, this); + if (ret >= 0) return ret; + + if (m_pParent != nullptr) + { + ret = m_pParent->m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken); + if (ret >= 0) return ret; + ret = m_pParent->m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, m_pParent); + } return ret; } From b0dbb11fac45f8c046fbb709def95cf0aa64119c Mon Sep 17 00:00:00 2001 From: melex750 Date: Sat, 21 Nov 2015 13:49:49 +0100 Subject: [PATCH 043/360] Fixed class declaration change see #540 --- src/CBot/CBotFunction.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 4ef40216..ff92ba48 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -1639,7 +1639,23 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) if ( IsOfType( p, ID_EXTENDS ) ) { - IsOfType(p, TokenTypVar); // necessarily + // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h + CBotString name = p->GetString(); + CBotClass* pPapa = CBotClass::Find(name); + + if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) + { + pStack->SetError( TX_NOCLASS, p ); + return nullptr; + } + pOld->m_pParent = pPapa; + } + else + { + if (pOld != nullptr) + { + pOld->m_pParent = nullptr; + } } IsOfType( p, ID_OPBLK); // necessarily From 2ed1494574c05b4b0ec11d5a75177b632579aaad Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 14:00:38 +0100 Subject: [PATCH 044/360] Syntax highlighting for "super" keyword, closes #680 --- src/CBot/CBotString.cpp | 1 - src/CBot/resource.h | 3 +-- src/script/script.cpp | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 52e63a34..24085baf 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -117,7 +117,6 @@ const std::map CBotString::s_keywordString = {ID_MODULO, "%"}, {ID_POWER, "**"}, {ID_ASSMODULO, "%="}, - {ID_SUPER, "super"}, {TX_UNDEF, "undefined"}, {TX_NAN, "not a number"} }; diff --git a/src/CBot/resource.h b/src/CBot/resource.h index 4e5bf556..3b0a1a89 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -112,8 +112,7 @@ enum EID ID_POWER, ID_ASSMODULO, TX_UNDEF = 4000, - TX_NAN, - ID_SUPER = 6000 + TX_NAN }; // TODO: refactor & change to enum! diff --git a/src/script/script.cpp b/src/script/script.cpp index c44746b8..9bfb1dac 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -666,7 +666,7 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd) { color = Gfx::FONT_HIGHLIGHT_TOKEN; } - else if (type == TokenTypVar && strcmp(token, "this") == 0) // this + else if (type == TokenTypVar && (strcmp(token, "this") == 0 || strcmp(token, "super") == 0)) // this, super { color = Gfx::FONT_HIGHLIGHT_THIS; } From 1838e7bfdefcc6c608356aa70a6060b3a890a8f7 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 14:44:48 +0100 Subject: [PATCH 045/360] Removed unused "final" keyword --- src/CBot/CBotString.cpp | 1 - src/CBot/resource.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 24085baf..bde3d0dc 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -54,7 +54,6 @@ const std::map CBotString::s_keywordString = {ID_NEW, "new"}, {ID_PUBLIC, "public"}, {ID_EXTERN, "extern"}, - {ID_FINAL, "final"}, {ID_STATIC, "static"}, {ID_PROTECTED, "protected"}, {ID_PRIVATE, "private"}, diff --git a/src/CBot/resource.h b/src/CBot/resource.h index 3b0a1a89..253bc14e 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -46,7 +46,6 @@ enum EID ID_NEW, ID_PUBLIC, ID_EXTERN, - ID_FINAL, ID_STATIC, ID_PROTECTED, ID_PRIVATE, From 7b96ae65cd28dcd89a6a374934726c32154c8f8f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 14:52:56 +0100 Subject: [PATCH 046/360] Removed unused CBot files Don't even ask what they were doing here. Just don't. :P --- src/CBot/CBot.h | 4 -- src/CBot/CBotAddExpr.cpp | 146 -------------------------------------- src/CBot/CBotCompExpr.cpp | 136 ----------------------------------- src/CBot/CBotProgram.cpp | 1 + 4 files changed, 1 insertion(+), 286 deletions(-) delete mode 100644 src/CBot/CBotAddExpr.cpp delete mode 100644 src/CBot/CBotCompExpr.cpp diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index d86b2f35..4437104a 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -39,10 +39,6 @@ ///////////////////////////////////////////////////////////////////// // forward declaration -class CBotCompExpr; // an expression like - // () <= () -class CBotAddExpr; // an expression like - // () + () class CBotParExpr; // basic type or instruction in parenthesis // Toto.truc // 12.5 diff --git a/src/CBot/CBotAddExpr.cpp b/src/CBot/CBotAddExpr.cpp deleted file mode 100644 index 80825ea1..00000000 --- a/src/CBot/CBotAddExpr.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -/////////////////////////////////////////////////// -// expressions of type Operand1 + Operand2 -// Operand1 - Operand2 - -#include "CBot.h" - -// various constructors - -CBotAddExpr::CBotAddExpr() -{ - m_leftop = - m_rightop = nullptr; // nullptr to be able to delete without further - name = "CBotAddExpr"; // debug -} - -CBotAddExpr::~CBotAddExpr() -{ - delete m_leftop; - delete m_rightop; -} - - -// compile une instruction de type A + B - -CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack) -{ - CBotStack* pStk = pStack->TokenStack(); // one end of stack please - - // looking statements that may be suitable to the left of the operation + or - - - CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left - if (left == nullptr) return pStack->Return(nullptr, pStk); // if error, transmit - - // do we have the token + or - next? - - if ( p->GetType() == ID_ADD || - p->GetType() == ID_SUB) // more or less - { - CBotAddExpr* inst = new CBotAddExpr(); // element for operation - inst->SetToken(p); // stores the operation - - int type1, type2; - type1 = pStack->GetType(); // what kind of the first operand? - - p = p->Next(); // skip the token of the operation - - // looking statements that may be suitable for right - - if ( nullptr != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth - { - // there is an acceptable second operand - - type2 = pStack->GetType(); // what kind of results? - - if ( type1 == type2 ) // are the results consistent ? - { - // ok so, saves the operand in the object - inst->m_leftop = left; - // and makes the object on demand - return pStack->Return(inst, pStk); - } - } - - // in case of error, free the elements - delete left; - delete inst; - // and transmits the error that is on the stack - return pStack->Return(nullptr, pStk); - } - - // if we are not dealing with an operation + or - - // goes to that requested, the operand (left) found - // place the object "addition" - return pStack->Return(left, pStk); -} - - - - -// operation is addition or subtraction - -bool CBotAddExpr::Execute(CBotStack* &pStack) -{ - CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack - // or is found in case of recovery -// if ( pSk1 == EOX ) return TRUE; - - - // according to recovery, it may be in one of two states - - if ( pStk1->GetState() == 0 && // first state, evaluates the left operand - !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here? - - // passes to the next step - pStk1->SetState(1); // ready for further - - // requires a little more stack to not touch the result of the left - // which is on the stack, precisely. - - CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack - // or is found in case of recovery - - // Second state, evaluates the right operand - if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here? - - int type1 = pStk1->GetType(); // what kind of results? - int type2 = pStk2->GetType(); - - // creates a temporary variable to put the result - CBotVar* result = new CBotVar( nullptr, MAX(type1, type2)); - - // is the operation as requested - switch (GetTokenType()) - { - case ID_ADD: - result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition - break; - case ID_SUB: - result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction - break; - } - pStk2->SetVar(result); // puts the result on the stack - - pStk1->Return(pStk2); // frees the stack - return pStack->Return(pStk1); // transmits the result -} - diff --git a/src/CBot/CBotCompExpr.cpp b/src/CBot/CBotCompExpr.cpp deleted file mode 100644 index adca89d8..00000000 --- a/src/CBot/CBotCompExpr.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -/////////////////////////////////////////////////// -// expression of type Opérande1 > Opérande2 -// Opérande1 != Opérande2 -// etc. - -#include "CBot.h" - -// various constructeurs - -CBotCompExpr::CBotCompExpr() -{ - m_leftop = - m_rightop = nullptr; - name = "CBotCompExpr"; -} - -CBotCompExpr::~CBotCompExpr() -{ - delete m_leftop; - delete m_rightop; -} - -fichier plus utilise; - -// compile instruction of type A < B - -CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->AddStack(); - - CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left - if (left == nullptr) return pStack->Return(nullptr, pStk); // error - - if ( p->GetType() == ID_HI || - p->GetType() == ID_LO || - p->GetType() == ID_HS || - p->GetType() == ID_LS || - p->GetType() == ID_EQ || - p->GetType() == ID_NE) // the various comparisons - { - CBotCompExpr* inst = new CBotCompExpr(); // element for operation - inst->SetToken(p); // stores the operation - - int type1, type2; - type1 = pStack->GetType(); - - p = p->Next(); - if ( nullptr != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right - { - type2 = pStack->GetType(); - // are the results compatible - if ( type1 == type2 ) - { - inst->m_leftop = left; - pStk->SetVar(new CBotVar(nullptr, CBotTypBoolean)); - // the result is a boolean - return pStack->Return(inst, pStk); - } - } - - delete left; - delete inst; - return pStack->Return(nullptr, pStk); - } - - return pStack->Return(left, pStk); -} - - -// perform the operation - -bool CBotCompExpr::Execute(CBotStack* &pStack) -{ - CBotStack* pStk1 = pStack->AddStack(this); -// if ( pStk1 == EOX ) return TRUE; - - if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ? - - pStk1->SetState(1); // finished - - // requires a little more stack to not touch the result of the left - CBotStack* pStk2 = pStk1->AddStack(); - - if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ? - - int type1 = pStk1->GetType(); - int type2 = pStk2->GetType(); - - CBotVar* result = new CBotVar( nullptr, CBotTypBoolean ); - - switch (GetTokenType()) - { - case ID_LO: - result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower - break; - case ID_HI: - result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher - break; - case ID_LS: - result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal - break; - case ID_HS: - result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal - break; - case ID_EQ: - result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal - break; - case ID_NE: - result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal - break; - } - pStk2->SetVar(result); // puts the result on the stack - - pStk1->Return(pStk2); // frees the stack - return pStack->Return(pStk1); // transmit the result -} - diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index c7bfffbb..305d9312 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -1042,6 +1042,7 @@ CBotTypResult cCBotDebug( CBotVar* &pVar, void* pUser ) } +// TODO: Refactor this - including .cpp files is bad #include "StringFunctions.cpp" void CBotProgram::Init() From 6590652d9e99f124b171ec78e83222efafd85949 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 16:31:22 +0100 Subject: [PATCH 047/360] Added commandline CBot interpreter (for testing purposes) --- .gitignore | 3 +- src/CBot/.gitignore | 1 - test/CMakeLists.txt | 3 + test/cbot/CMakeLists.txt | 1 + test/cbot/console/CMakeLists.txt | 22 ++++++++ test/cbot/console/main.cpp | 94 ++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 2 deletions(-) delete mode 100644 src/CBot/.gitignore create mode 100644 test/cbot/CMakeLists.txt create mode 100644 test/cbot/console/CMakeLists.txt create mode 100644 test/cbot/console/main.cpp diff --git a/.gitignore b/.gitignore index 885f5fe8..65c0087a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,10 +16,11 @@ Makefile # Ignore targets /colobot +/src/CBot/libCBot.so # Ignore local data /colobot.ini -/savegame +/saves # Standard build directory /build diff --git a/src/CBot/.gitignore b/src/CBot/.gitignore deleted file mode 100644 index 4c80252f..00000000 --- a/src/CBot/.gitignore +++ /dev/null @@ -1 +0,0 @@ -libCBot.so diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c30abe89..cd4c320b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,9 @@ set(CMAKE_CXX_FLAGS_DEBUG ${COLOBOT_CXX_FLAGS_DEBUG}) # Unit tests add_subdirectory(unit) +# CBot tests +add_subdirectory(cbot) + if(COLOBOT_LINT_BUILD) add_fake_header_sources("test") diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt new file mode 100644 index 00000000..d5de1f4e --- /dev/null +++ b/test/cbot/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(console) \ No newline at end of file diff --git a/test/cbot/console/CMakeLists.txt b/test/cbot/console/CMakeLists.txt new file mode 100644 index 00000000..e33a1085 --- /dev/null +++ b/test/cbot/console/CMakeLists.txt @@ -0,0 +1,22 @@ +# Sources +set(CBOT_CONSOLE_SOURCES + main.cpp +) + +# Includes +include_directories( + ${COLOBOT_LOCAL_INCLUDES} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +# Libraries +set(LIBS + CBot + colobotbase # Needed for error strings (TODO: why are they on Colobot side? :/) + ${COLOBOT_LIBS} # Needed for colobotbase +) +# Targets + +add_executable(CBot_console ${CBOT_CONSOLE_SOURCES}) +target_link_libraries(CBot_console ${LIBS}) \ No newline at end of file diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp new file mode 100644 index 00000000..83e06dea --- /dev/null +++ b/test/cbot/console/main.cpp @@ -0,0 +1,94 @@ +#include +#include + +#include "common/restext.h" +#include "CBot/CBotDll.h" + +CBotTypResult cMessage(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypString && + var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var == nullptr ) return CBotTypResult(CBotTypFloat); + return CBotTypResult(CBotErrOverParam); +} + +bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CBotString cbs = var->GetValString(); + const char* message = cbs; // Don't ask me why, but it doesn't work if you write it on a single line + + std::cout << message << std::endl; + + return true; +} + +int main(int argc, char* argv[]) +{ + // Read program code from stdin + std::string code = ""; + std::string line; + while (std::getline(std::cin, line)) + { + code += line; + code += "\n"; + } + + // Error message strings are stored on Colobot side (meh!) so let's initialize that + InitializeRestext(); + + // Initialize the CBot engine, add standard library functions + CBotProgram::AddFunction("message", rMessage, cMessage); + + // Compile the program + CBotStringArray externFunctions; + std::unique_ptr program{new CBotProgram(nullptr)}; + if (!program->Compile(code.c_str(), externFunctions, nullptr)) + { + int error, cursor1, cursor2; + program->GetError(error, cursor1, cursor2); + std::string errorStr; + GetResource(RES_CBOT, error, errorStr); + std::cerr << "COMPILE ERROR: " << errorStr << " (code: " << error << ") @ " << cursor1 << " - " << cursor2 << std::endl; + return 1; + } + + // Execute all compiled functions marked as "extern" + if (externFunctions.GetSize() == 0) + { + std::cerr << "NO EXTERN FUNCTIONS FOUND"; + return 2; + } + bool runErrors = false; + for (int i = 0; i < externFunctions.GetSize(); i++) + { + const char* func = externFunctions[i]; + if (!program->Start(func)) + { + std::cerr << "FAILED TO START: " << func << std::endl; + continue; + } + + std::cerr << "Running program: " << func << std::endl; + + while (!program->Run(nullptr)); // Run the program + + int error, cursor1, cursor2; + program->GetError(error, cursor1, cursor2); + if (error != 0) + { + std::string errorStr; + GetResource(RES_CBOT, error, errorStr); + std::cerr << "RUNTIME ERROR: " << errorStr << " (code: " << error << ") @ " << cursor1 << " - " << cursor2 << std::endl; + runErrors = true; + } + else + { + std::cerr << "Program finished." << std::endl; + } + } + + return runErrors ? 3 : 0; +} \ No newline at end of file From 9bea0355f0bc890938b7dde52bf4ff33b57d1c4e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 16:54:21 +0100 Subject: [PATCH 048/360] Removed some unused strings --- po/colobot.pot | 53 ------------------ po/de.po | 106 ++++++++++++++++++------------------ po/fr.po | 118 ++++++++++++++++++++--------------------- po/pl.po | 113 ++++++++++++++++++++------------------- po/ru.po | 108 ++++++++++++++++++------------------- src/CBot/resource.h | 13 ++--- src/common/restext.cpp | 18 ------- src/common/restext.h | 14 ----- 8 files changed, 227 insertions(+), 316 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 9a91b810..60ef1bad 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -20,9 +20,6 @@ msgstr "" msgid "Colobot rules!" msgstr "" -msgid "SatCom" -msgstr "" - msgid "Maximize" msgstr "" @@ -113,9 +110,6 @@ msgstr "" msgid " Summary:" msgstr "" -msgid " Drivers:" -msgstr "" - msgid " Resolution:" msgstr "" @@ -189,32 +183,6 @@ msgstr "" msgid "This is example code that cannot be run directly" msgstr "" -msgid "\\b;List of objects\n" -msgstr "" - -msgid "\\b;Robots\n" -msgstr "" - -msgid "\\b;Buildings\n" -msgstr "" - -msgid "\\b;Moveable objects\n" -msgstr "" - -msgid "\\b;Aliens\n" -msgstr "" - -msgid "\\c; (none)\\n;\n" -msgstr "" - -msgid "\\b;Error\n" -msgstr "" - -msgid "" -"The list is only available if a \\l;radar station\\u object\\radar; is " -"working.\n" -msgstr "" - msgid "Open" msgstr "" @@ -1675,9 +1643,6 @@ msgstr "" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "" -msgid "Instructions after the final closing brace" -msgstr "" - msgid "End of block missing" msgstr "" @@ -1768,9 +1733,6 @@ msgstr "" msgid "Bad argument for \"new\"" msgstr "" -msgid "\" [ \" expected" -msgstr "" - msgid "String missing" msgstr "" @@ -1792,9 +1754,6 @@ msgstr "" msgid "Negative value rejected by \"throw\"" msgstr "" -msgid "The function returned no value " -msgstr "" - msgid "No function running" msgstr "" @@ -1819,17 +1778,5 @@ msgstr "" msgid "Illegal object" msgstr "" -msgid "Can't open file" -msgstr "" - -msgid "File not open" -msgstr "" - -msgid "Read error" -msgstr "" - -msgid "Write error" -msgstr "" - msgid "Button %1" msgstr "" diff --git a/po/de.po b/po/de.po index 9a4ab2e7..476e5e0b 100644 --- a/po/de.po +++ b/po/de.po @@ -30,9 +30,6 @@ msgstr " Liste der Kapitel:" msgid " Custom levels:" msgstr " Userlevels:" -msgid " Drivers:" -msgstr " Driver:" - msgid " Exercises in the chapter:" msgstr " Liste der Übungen des Kapitels:" @@ -58,9 +55,6 @@ msgstr " Zusammenfassung:" msgid " or " msgstr " oder " -msgid "\" [ \" expected" -msgstr "Es fehlt eine offene eckige Klammer \" [ \"" - msgid "\" ] \" missing" msgstr "Es fehlt eine geschlossene eckige Klammer \" ] \"" @@ -364,9 +358,6 @@ msgstr "Das erforschte Objekt kann nicht produziert werden" msgid "Can not produce this object in this mission" msgstr "Das Objekt kann in dieser Mission nicht produziert werden" -msgid "Can't open file" -msgstr "Die Datei kann nicht geöffnet werden" - msgid "Cancel" msgstr "Abbrechen" @@ -566,9 +557,6 @@ msgstr "Brille:" msgid "Face type:" msgstr "Kopf:" -msgid "File not open" -msgstr "Die Datei wurde nicht geöffnet" - msgid "Filename:" msgstr "Dateiname:" @@ -751,9 +739,6 @@ msgstr "Anweisung \"else\" ohne vorhergehende Anweisung \"if\"" msgid "Instructions (\\key help;)" msgstr "Anweisungen (\\key help;)" -msgid "Instructions after the final closing brace" -msgstr "Hier ist eine Anweisung nach dem Ende des Programms" - msgid "Instructions for the mission (\\key help;)" msgstr "Anweisungen über die Mission(\\key help;)" @@ -1200,9 +1185,6 @@ msgstr "Mission verlassen\\Eine Mission oder Übung verlassen" msgid "Radar station" msgstr "Radar" -msgid "Read error" -msgstr "Fehler beim Lesezugriff" - msgid "Recorder" msgstr "Recorder" @@ -1305,9 +1287,6 @@ msgstr "Forschungsprogramm Kettenantrieb" msgid "Run research program for winged bots" msgstr "Forschungsprogramm Jetantrieb" -msgid "SatCom" -msgstr "SatCom" - msgid "Satellite report" msgstr "Satellitenbericht" @@ -1502,14 +1481,6 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Der Ausdruck muss einen boolschen Wert ergeben" -msgid "The function returned no value " -msgstr "Die Funktion hat kein Ergebnis zurückgegeben" - -msgid "" -"The list is only available if a \\l;radar station\\u object\\radar; is " -"working.\n" -msgstr "Die Liste ist ohne \\l;Radar\\u object\\radar; nicht verfügbar.\n" - msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1714,9 +1685,6 @@ msgstr "Wurm tödlich verwundet" msgid "Wreckage" msgstr "Roboterwrack" -msgid "Write error" -msgstr "Fehler beim Schreibzugriff" - msgid "Wrong type for the assignment" msgstr "Der Ausdruck ergibt einen falschen Typ für die Zuweisung" @@ -1837,27 +1805,6 @@ msgstr "\\Violette Fahne" msgid "\\Yellow flags" msgstr "\\Gelbe Fahne" -msgid "\\b;Aliens\n" -msgstr "\\b;Listes der Feinde\n" - -msgid "\\b;Buildings\n" -msgstr "\\b;Listes der Gebäude\n" - -msgid "\\b;Error\n" -msgstr "\\b;Fehler\n" - -msgid "\\b;List of objects\n" -msgstr "\\b;Liste der Objekte\n" - -msgid "\\b;Moveable objects\n" -msgstr "\\b;Listes der tragbaren Gegenstände\n" - -msgid "\\b;Robots\n" -msgstr "\\b;Liste der Roboter\n" - -msgid "\\c; (none)\\n;\n" -msgstr "\\c; (keine)\\n;\n" - msgid "www.colobot.info" msgstr "" @@ -1867,15 +1814,24 @@ msgstr "www.epsitec.com" #~ msgid " " #~ msgstr " " +#~ msgid " Drivers:" +#~ msgstr " Driver:" + #~ msgid " Missions on this level:" #~ msgstr " Missionen des Userlevels:" +#~ msgid "\" [ \" expected" +#~ msgstr "Es fehlt eine offene eckige Klammer \" [ \"" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Can't open file" +#~ msgstr "Die Datei kann nicht geöffnet werden" + #~ msgid "Cancel\\Keep current player name" #~ msgstr "Abbrechen\\Behält den bisherigen Spieler bei" @@ -1901,9 +1857,15 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Zurücksetzen \\Kleine Show beim Zurücksetzen in den Übungen" +#~ msgid "File not open" +#~ msgstr "Die Datei wurde nicht geöffnet" + #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Eigenbeschuss\\Ihre Einheiten werden von Ihren Waffen beschädigt" +#~ msgid "Instructions after the final closing brace" +#~ msgstr "Hier ist eine Anweisung nach dem Ende des Programms" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Hilfe über Begriff\\Hilfe über einen Begriff" @@ -1925,9 +1887,15 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Schließen\\COLOBOT schließen" +#~ msgid "Read error" +#~ msgstr "Fehler beim Lesezugriff" + #~ msgid "Robbie\\Your assistant" #~ msgstr "Robby\\Ihr Assistent" +#~ msgid "SatCom" +#~ msgstr "SatCom" + #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Himmel\\Himmel und Wolken" @@ -1940,8 +1908,40 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualität der Texturen\\Qualität der Anzeige" +#~ msgid "The function returned no value " +#~ msgstr "Die Funktion hat kein Ergebnis zurückgegeben" + +#~ msgid "" +#~ "The list is only available if a \\l;radar station\\u object\\radar; is " +#~ "working.\n" +#~ msgstr "Die Liste ist ohne \\l;Radar\\u object\\radar; nicht verfügbar.\n" + #~ msgid "User\\User levels" #~ msgstr "User\\Userlevels" +#~ msgid "Write error" +#~ msgstr "Fehler beim Schreibzugriff" + #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Zurück zu COLOBOT" + +#~ msgid "\\b;Aliens\n" +#~ msgstr "\\b;Listes der Feinde\n" + +#~ msgid "\\b;Buildings\n" +#~ msgstr "\\b;Listes der Gebäude\n" + +#~ msgid "\\b;Error\n" +#~ msgstr "\\b;Fehler\n" + +#~ msgid "\\b;List of objects\n" +#~ msgstr "\\b;Liste der Objekte\n" + +#~ msgid "\\b;Moveable objects\n" +#~ msgstr "\\b;Listes der tragbaren Gegenstände\n" + +#~ msgid "\\b;Robots\n" +#~ msgstr "\\b;Liste der Roboter\n" + +#~ msgid "\\c; (none)\\n;\n" +#~ msgstr "\\c; (keine)\\n;\n" diff --git a/po/fr.po b/po/fr.po index cbf01625..3293ab45 100644 --- a/po/fr.po +++ b/po/fr.po @@ -24,9 +24,6 @@ msgstr " Liste des chapitres :" msgid " Custom levels:" msgstr " Niveaux spéciaux :" -msgid " Drivers:" -msgstr " Pilotes :" - msgid " Exercises in the chapter:" msgstr " Liste des exercices du chapitre :" @@ -51,9 +48,6 @@ msgstr " Résumé :" msgid " or " msgstr " ou " -msgid "\" [ \" expected" -msgstr "\" [ \" attendu" - msgid "\" ] \" missing" msgstr "\" ] \" attendu" @@ -349,8 +343,8 @@ msgstr "Caméra à droite" msgid "Camera up\\Increase camera angle while visiting message origin" msgstr "" -"Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des " -"messages" +"Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine " +"des messages" msgid "Can not create this; there are too many objects" msgstr "Création impossible; il y a trop d'objets" @@ -361,9 +355,6 @@ msgstr "Impossible de créer un objet n'ayant pas été recherché" msgid "Can not produce this object in this mission" msgstr "Impossible de créer cet objet dans cette mission" -msgid "Can't open file" -msgstr "Ouverture du fichier impossible" - msgid "Cancel" msgstr "Annuler" @@ -561,9 +552,6 @@ msgstr "Lunettes :" msgid "Face type:" msgstr "Type de visage :" -msgid "File not open" -msgstr "Le fichier n'est pas ouvert" - msgid "Filename:" msgstr "Nom du fichier :" @@ -745,9 +733,6 @@ msgstr "Instruction \"else\" sans \"if\" correspondant" msgid "Instructions (\\key help;)" msgstr "Instructions (\\key help;)" -msgid "Instructions after the final closing brace" -msgstr "Instructions après la fin" - msgid "Instructions for the mission (\\key help;)" msgstr "Instructions sur la mission (\\key help;)" @@ -1180,9 +1165,7 @@ msgid "Quake at explosions\\The screen shakes at explosions" msgstr "Secousses lors d'explosions\\L'écran vibre lors d'une explosion" msgid "Quality dynamic shadows\\Enable shadow transparency and self shadowing" -msgstr "" -"Ombres projetées\\Active la transparence des ombres et " -"l'auto-ombrage" +msgstr "Ombres projetées\\Active la transparence des ombres et l'auto-ombrage" msgid "Quit\\Quit Colobot: Gold Edition" msgstr "Quitter\\Quitter Colobot : Édition Gold" @@ -1193,9 +1176,6 @@ msgstr "Quitter la mission en cours\\Terminer un exercice ou une mssion" msgid "Radar station" msgstr "Radar" -msgid "Read error" -msgstr "Erreur à la lecture" - msgid "Recorder" msgstr "Enregistreur" @@ -1295,9 +1275,6 @@ msgstr "Recherche les chenilles" msgid "Run research program for winged bots" msgstr "Recherche les robots volants" -msgid "SatCom" -msgstr "SatCom" - msgid "Satellite report" msgstr "Rapport du satellite" @@ -1329,8 +1306,8 @@ msgstr "Terminateur point-virgule non trouvé" msgid "Shadow resolution\\Higher means better range and quality, but slower" msgstr "" -"Résolution des ombres\\Plus grand implique une meilleure qulité et amplitude, " -"mais plus lent" +"Résolution des ombres\\Plus grand implique une meilleure qulité et " +"amplitude, mais plus lent" msgid "Shield level" msgstr "Niveau du bouclier" @@ -1489,14 +1466,6 @@ msgstr "Textures" msgid "The expression must return a boolean value" msgstr "L'expression doit ętre un boolean" -msgid "The function returned no value " -msgstr "La fonction n'a pas retourné de résultat" - -msgid "" -"The list is only available if a \\l;radar station\\u object\\radar; is " -"working.\n" -msgstr "Liste non disponible sans \\l;radar\\u object\\radar;.\n" - msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1702,9 +1671,6 @@ msgstr "Ver mortellement touché" msgid "Wreckage" msgstr "Epave de robot" -msgid "Write error" -msgstr "Erreur à l'écriture" - msgid "Wrong type for the assignment" msgstr "Mauvais type de résultat pour l'assignation" @@ -1826,27 +1792,6 @@ msgstr "\\Drapeaux violets" msgid "\\Yellow flags" msgstr "\\Drapeaux jaunes" -msgid "\\b;Aliens\n" -msgstr "\\b;Listes des ennemis\n" - -msgid "\\b;Buildings\n" -msgstr "\\b;Listes des bâtiments\n" - -msgid "\\b;Error\n" -msgstr "\\b;Erreur\n" - -msgid "\\b;List of objects\n" -msgstr "\\b;Listes des objets\n" - -msgid "\\b;Moveable objects\n" -msgstr "\\b;Listes des objets transportables\n" - -msgid "\\b;Robots\n" -msgstr "\\b;Listes des robots\n" - -msgid "\\c; (none)\\n;\n" -msgstr "\\c; (aucun)\\n;\n" - msgid "www.colobot.info" msgstr "www.colobot.info" @@ -1856,15 +1801,24 @@ msgstr "www.epsitec.com" #~ msgid " " #~ msgstr " " +#~ msgid " Drivers:" +#~ msgstr " Pilotes :" + #~ msgid " Missions on this level:" #~ msgstr " Missions du niveau :" +#~ msgid "\" [ \" expected" +#~ msgstr "\" [ \" attendu" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Bruitages 3D\\Positionnement sonore dans l'espace" #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Can't open file" +#~ msgstr "Ouverture du fichier impossible" + #~ msgid "Cancel\\Keep current player name" #~ msgstr "Annuler\\Conserver le joueur actuel" @@ -1890,9 +1844,15 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Retour animé\\Retour animé dans les exercices" +#~ msgid "File not open" +#~ msgstr "Le fichier n'est pas ouvert" + #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Dégâts à soi-même\\Vos tirs infligent des dommages à vos unités" +#~ msgid "Instructions after the final closing brace" +#~ msgstr "Instructions après la fin" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Instructions mot-clé\\Explication sur le mot-clé" @@ -1914,9 +1874,15 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Quitter\\Quitter COLOBOT" +#~ msgid "Read error" +#~ msgstr "Erreur à la lecture" + #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Votre assistant" +#~ msgid "SatCom" +#~ msgstr "SatCom" + #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Ciel\\Ciel et nuages" @@ -1929,8 +1895,40 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualité des textures\\Qualité des images" +#~ msgid "The function returned no value " +#~ msgstr "La fonction n'a pas retourné de résultat" + +#~ msgid "" +#~ "The list is only available if a \\l;radar station\\u object\\radar; is " +#~ "working.\n" +#~ msgstr "Liste non disponible sans \\l;radar\\u object\\radar;.\n" + #~ msgid "User\\User levels" #~ msgstr "Suppl.\\Niveaux supplémentaires" +#~ msgid "Write error" +#~ msgstr "Erreur à l'écriture" + #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Retourner dans COLOBOT" + +#~ msgid "\\b;Aliens\n" +#~ msgstr "\\b;Listes des ennemis\n" + +#~ msgid "\\b;Buildings\n" +#~ msgstr "\\b;Listes des bâtiments\n" + +#~ msgid "\\b;Error\n" +#~ msgstr "\\b;Erreur\n" + +#~ msgid "\\b;List of objects\n" +#~ msgstr "\\b;Listes des objets\n" + +#~ msgid "\\b;Moveable objects\n" +#~ msgstr "\\b;Listes des objets transportables\n" + +#~ msgid "\\b;Robots\n" +#~ msgstr "\\b;Listes des robots\n" + +#~ msgid "\\c; (none)\\n;\n" +#~ msgstr "\\c; (aucun)\\n;\n" diff --git a/po/pl.po b/po/pl.po index c82cc71a..a88c90f5 100644 --- a/po/pl.po +++ b/po/pl.po @@ -30,9 +30,6 @@ msgstr " Rozdziały:" msgid " Custom levels:" msgstr " Własne poziomy:" -msgid " Drivers:" -msgstr " Sterowniki:" - msgid " Exercises in the chapter:" msgstr " Ćwiczenia w tym rozdziale:" @@ -57,9 +54,6 @@ msgstr " Streszczenie:" msgid " or " msgstr " lub " -msgid "\" [ \" expected" -msgstr "Oczekiwane \" [ \"" - msgid "\" ] \" missing" msgstr "Brak \" ] \"" @@ -367,9 +361,6 @@ msgstr "Nie można wyprodukować nie wynalezionego obiektu" msgid "Can not produce this object in this mission" msgstr "Nie można utworzyć tego obiektu w tej misji" -msgid "Can't open file" -msgstr "Nie można otworzyć pliku" - msgid "Cancel" msgstr "Anuluj" @@ -413,7 +404,8 @@ msgid "Code battles" msgstr "Programobitwy" msgid "Code battles\\Program your robot to be the best of them all!" -msgstr "Programobitwy\\Zaprogramuj swego robota by był najlepszy ze wszystkich!" +msgstr "" +"Programobitwy\\Zaprogramuj swego robota by był najlepszy ze wszystkich!" msgid "Colobot rules!" msgstr "Colobot rządzi!" @@ -566,9 +558,6 @@ msgstr "Okulary:" msgid "Face type:" msgstr "Rodzaj twarzy:" -msgid "File not open" -msgstr "Plik nie jest otwarty" - msgid "Filename:" msgstr "Nazwa pliku:" @@ -751,9 +740,6 @@ msgstr "Polecenie \"else\" bez wystąpienia \"if\" " msgid "Instructions (\\key help;)" msgstr "Rozkazy (\\key help;)" -msgid "Instructions after the final closing brace" -msgstr "Polecenie po końcowej klamrze zamykającej" - msgid "Instructions for the mission (\\key help;)" msgstr "Rozkazy dotyczące misji (\\key help;)" @@ -1198,9 +1184,6 @@ msgstr "Zakończ\\Kończy bieżącą misję lub ćwiczenie" msgid "Radar station" msgstr "Stacja radarowa" -msgid "Read error" -msgstr "Błąd odczytu" - msgid "Recorder" msgstr "Nagrywanie" @@ -1300,9 +1283,6 @@ msgstr "Rozpocznij prace badawcze nad transporterem na gąsienicach" msgid "Run research program for winged bots" msgstr "Rozpocznij prace badawcze nad transporterem latającym" -msgid "SatCom" -msgstr "SatCom" - msgid "Satellite report" msgstr "Raport z satelity" @@ -1494,16 +1474,6 @@ msgstr "Tekstury" msgid "The expression must return a boolean value" msgstr "Wyrażenie musi zwrócić wartość logiczną" -msgid "The function returned no value " -msgstr "Funkcja nie zwróciła żadnej wartości " - -msgid "" -"The list is only available if a \\l;radar station\\u object\\radar; is " -"working.\n" -msgstr "" -"Lista jest dostępna jedynie gdy działa \\l;stacja radarowa\\u object" -"\\radar;.\n" - msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Misja nie jest wypełniona (naciśnij \\key help; aby uzyskać szczegóły)" @@ -1706,9 +1676,6 @@ msgstr "Robal śmiertelnie raniony" msgid "Wreckage" msgstr "Wrak" -msgid "Write error" -msgstr "Błąd zapisu" - msgid "Wrong type for the assignment" msgstr "Zły typ dla przypisania" @@ -1829,36 +1796,24 @@ msgstr "\\Fioletowe flagi" msgid "\\Yellow flags" msgstr "\\Żółte flagi" -msgid "\\b;Aliens\n" -msgstr "\\b;Obcy\n" - -msgid "\\b;Buildings\n" -msgstr "\\b;Budynki\n" - -msgid "\\b;Error\n" -msgstr "\\b;Błąd\n" - -msgid "\\b;List of objects\n" -msgstr "\\b;Lista obiektów\n" - -msgid "\\b;Moveable objects\n" -msgstr "\\b;Obiekty ruchome\n" - -msgid "\\b;Robots\n" -msgstr "\\b;Roboty\n" - -msgid "\\c; (none)\\n;\n" -msgstr "\\c; (brak)\\n;\n" - msgid "www.colobot.info" msgstr "" msgid "www.epsitec.com" msgstr "www.epsitec.com" +#~ msgid " Drivers:" +#~ msgstr " Sterowniki:" + +#~ msgid "\" [ \" expected" +#~ msgstr "Oczekiwane \" [ \"" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" +#~ msgid "Can't open file" +#~ msgstr "Nie można otworzyć pliku" + #~ msgid "Cancel\\Keep current player name" #~ msgstr "Anuluj\\Zachowuje bieżące imię gracza" @@ -1880,9 +1835,15 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Końcowy film\\Film na zakończenie ćwiczeń" +#~ msgid "File not open" +#~ msgstr "Plik nie jest otwarty" + #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Przyjacielski ogień\\Własne strzały uszkadzają Twoje obiekty" +#~ msgid "Instructions after the final closing brace" +#~ msgstr "Polecenie po końcowej klamrze zamykającej" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "" #~ "Pomoc dot. słów kluczowych\\Dokładniejsza pomoc na temat słów kluczowych" @@ -1906,9 +1867,15 @@ msgstr "www.epsitec.com" #~ msgid "Quit the mission?" #~ msgstr "Opuścić misję?" +#~ msgid "Read error" +#~ msgstr "Błąd odczytu" + #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Twój asystent" +#~ msgid "SatCom" +#~ msgstr "SatCom" + #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Niebo\\Chmury i mgławice" @@ -1917,3 +1884,37 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Tekstury\\Jakość tekstur " + +#~ msgid "The function returned no value " +#~ msgstr "Funkcja nie zwróciła żadnej wartości " + +#~ msgid "" +#~ "The list is only available if a \\l;radar station\\u object\\radar; is " +#~ "working.\n" +#~ msgstr "" +#~ "Lista jest dostępna jedynie gdy działa \\l;stacja radarowa\\u object" +#~ "\\radar;.\n" + +#~ msgid "Write error" +#~ msgstr "Błąd zapisu" + +#~ msgid "\\b;Aliens\n" +#~ msgstr "\\b;Obcy\n" + +#~ msgid "\\b;Buildings\n" +#~ msgstr "\\b;Budynki\n" + +#~ msgid "\\b;Error\n" +#~ msgstr "\\b;Błąd\n" + +#~ msgid "\\b;List of objects\n" +#~ msgstr "\\b;Lista obiektów\n" + +#~ msgid "\\b;Moveable objects\n" +#~ msgstr "\\b;Obiekty ruchome\n" + +#~ msgid "\\b;Robots\n" +#~ msgstr "\\b;Roboty\n" + +#~ msgid "\\c; (none)\\n;\n" +#~ msgstr "\\c; (brak)\\n;\n" diff --git a/po/ru.po b/po/ru.po index ec41616b..a1d01eb7 100644 --- a/po/ru.po +++ b/po/ru.po @@ -28,9 +28,6 @@ msgstr " Разделы:" msgid " Custom levels:" msgstr " Пользовательские уровни:" -msgid " Drivers:" -msgstr " Драйверы:" - msgid " Exercises in the chapter:" msgstr " Упражнения в разделе:" @@ -56,9 +53,6 @@ msgstr " Итог:" msgid " or " msgstr " или " -msgid "\" [ \" expected" -msgstr "Ожидалось \" [ \"" - msgid "\" ] \" missing" msgstr "Отсутствует \"]\" " @@ -359,9 +353,6 @@ msgstr "" msgid "Can not produce this object in this mission" msgstr "" -msgid "Can't open file" -msgstr "Невозможно открыть файл" - msgid "Cancel" msgstr "Отмена" @@ -560,9 +551,6 @@ msgstr "Очки:" msgid "Face type:" msgstr "Лицо:" -msgid "File not open" -msgstr "Файл не открыт" - msgid "Filename:" msgstr "Имя файла:" @@ -744,9 +732,6 @@ msgstr "Инструкция \"else\" без \"if\" " msgid "Instructions (\\key help;)" msgstr "Инструкции (\\key help;)" -msgid "Instructions after the final closing brace" -msgstr "Инструкция после последней закрывающей фигурной скобки" - msgid "Instructions for the mission (\\key help;)" msgstr "Инструкции для миссии (\\key help;)" @@ -1196,9 +1181,6 @@ msgstr "Выход\\Выход из текущей миссии" msgid "Radar station" msgstr "Радар" -msgid "Read error" -msgstr "Ошибка чтения" - msgid "Recorder" msgstr "Запись" @@ -1300,9 +1282,6 @@ msgstr "Начать исследование программы для гусе msgid "Run research program for winged bots" msgstr "Начать исследование программы для летающего бота" -msgid "SatCom" -msgstr "SatCom" - msgid "Satellite report" msgstr "Спутниковый отчет" @@ -1494,15 +1473,6 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Выражение должно возвращать логическое значение" -msgid "The function returned no value " -msgstr "Функция не возвратила значения" - -msgid "" -"The list is only available if a \\l;radar station\\u object\\radar; is " -"working.\n" -msgstr "" -"Список доступен только если \\l;radar station\\u object\\radar; работают\n" - msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1706,9 +1676,6 @@ msgstr "Червь смертельно ранен" msgid "Wreckage" msgstr "Обломки" -msgid "Write error" -msgstr "Ошибка записи" - msgid "Wrong type for the assignment" msgstr "Неверный тип для назначения" @@ -1829,27 +1796,6 @@ msgstr "\\Фиолетовый флаг" msgid "\\Yellow flags" msgstr "\\Желтый флаг" -msgid "\\b;Aliens\n" -msgstr "\\b;Чужаки\n" - -msgid "\\b;Buildings\n" -msgstr "\\b;Здания\n" - -msgid "\\b;Error\n" -msgstr "\\b;Ошибка\n" - -msgid "\\b;List of objects\n" -msgstr "\\b;Список объектов\n" - -msgid "\\b;Moveable objects\n" -msgstr "\\b;Подвижные объекты\n" - -msgid "\\b;Robots\n" -msgstr "\\b;Роботы\n" - -msgid "\\c; (none)\\n;\n" -msgstr "\\c; (нет)\\n;\n" - msgid "www.colobot.info" msgstr "" @@ -1859,15 +1805,24 @@ msgstr "www.epsitec.com" #~ msgid " " #~ msgstr " " +#~ msgid " Drivers:" +#~ msgstr " Драйверы:" + #~ msgid " Missions on this level:" #~ msgstr " Миссии на этом уровне:" +#~ msgid "\" [ \" expected" +#~ msgstr "Ожидалось \" [ \"" + #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-звук\\Стерео звук" #~ msgid "COLOBOT" #~ msgstr "КОЛОБОТ" +#~ msgid "Can't open file" +#~ msgstr "Невозможно открыть файл" + #~ msgid "Cancel\\Keep current player name" #~ msgstr "Отмена\\Отмена" @@ -1893,9 +1848,15 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Ролик при выходе\\Ролик во время выхода из упражнения" +#~ msgid "File not open" +#~ msgstr "Файл не открыт" + #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Огонь по своим\\Вы можете повредить собственные объекты" +#~ msgid "Instructions after the final closing brace" +#~ msgstr "Инструкция после последней закрывающей фигурной скобки" + #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Помощь по командам\\Более подробная справку по командам" @@ -1917,9 +1878,15 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Выход\\Выход из COLOBOT" +#~ msgid "Read error" +#~ msgstr "Ошибка чтения" + #~ msgid "Robbie\\Your assistant" #~ msgstr "Робби\\Ваш помощник" +#~ msgid "SatCom" +#~ msgstr "SatCom" + #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Небо\\Облака и туманности" @@ -1932,8 +1899,41 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Текстуры\\Качество текстур " +#~ msgid "The function returned no value " +#~ msgstr "Функция не возвратила значения" + +#~ msgid "" +#~ "The list is only available if a \\l;radar station\\u object\\radar; is " +#~ "working.\n" +#~ msgstr "" +#~ "Список доступен только если \\l;radar station\\u object\\radar; работают\n" + #~ msgid "User\\User levels" #~ msgstr "Польз.\\Пользовательские уровни" +#~ msgid "Write error" +#~ msgstr "Ошибка записи" + #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Вернуться в COLOBOT" + +#~ msgid "\\b;Aliens\n" +#~ msgstr "\\b;Чужаки\n" + +#~ msgid "\\b;Buildings\n" +#~ msgstr "\\b;Здания\n" + +#~ msgid "\\b;Error\n" +#~ msgstr "\\b;Ошибка\n" + +#~ msgid "\\b;List of objects\n" +#~ msgstr "\\b;Список объектов\n" + +#~ msgid "\\b;Moveable objects\n" +#~ msgstr "\\b;Подвижные объекты\n" + +#~ msgid "\\b;Robots\n" +#~ msgstr "\\b;Роботы\n" + +#~ msgid "\\c; (none)\\n;\n" +#~ msgstr "\\c; (нет)\\n;\n" diff --git a/src/CBot/resource.h b/src/CBot/resource.h index 253bc14e..4bb008a8 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -116,6 +116,7 @@ enum EID // TODO: refactor & change to enum! +// Compile errors #define TX_OPENPAR 5000 #define TX_CLOSEPAR 5001 #define TX_NOTBOOL 5002 @@ -123,7 +124,6 @@ enum EID #define TX_BADLEFT 5004 #define TX_ENDOF 5005 #define TX_OUTCASE 5006 -#define TX_NOTERM 5007 #define TX_CLOSEBLK 5008 #define TX_ELSEWITHOUTIF 5009 #define TX_OPENBLK 5010 @@ -154,15 +154,15 @@ enum EID #define TX_CLBRK 5035 #define TX_RESERVED 5036 #define TX_BADNEW 5037 -#define TX_OPBRK 5038 #define TX_BADSTRING 5039 #define TX_BADINDEX 5040 #define TX_PRIVATE 5041 #define TX_NOPUBLIC 5042 + +// Runtime errors #define TX_DIVZERO 6000 #define TX_NOTINIT 6001 #define TX_BADTHROW 6002 -#define TX_NORETVAL 6003 #define TX_NORUN 6004 #define TX_NOCALL 6005 #define TX_NOCLASS 6006 @@ -171,9 +171,6 @@ enum EID #define TX_OUTARRAY 6009 #define TX_STACKOVER 6010 #define TX_DELETEDPT 6011 -#define TX_FILEOPEN 6012 -#define TX_NOTOPEN 6013 -#define TX_ERRREAD 6014 -#define TX_ERRWRITE 6015 -#define TX_MAX 6016 +// Max errors +#define TX_MAX 6012 diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c1b8a311..abba791b 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -53,7 +53,6 @@ const char* stringsCbot[TX_MAX] = { nullptr }; void InitializeRestext() { - stringsText[RT_DISINFO_TITLE] = TR("SatCom"); stringsText[RT_WINDOW_MAXIMIZED] = TR("Maximize"); stringsText[RT_WINDOW_MINIMIZED] = TR("Minimize"); stringsText[RT_WINDOW_STANDARD] = TR("Normal size"); @@ -88,7 +87,6 @@ void InitializeRestext() stringsText[RT_PLAY_LIST_FREEGAME] = TR(" Free game on this planet:"); stringsText[RT_PLAY_RESUME] = TR(" Summary:"); - stringsText[RT_SETUP_DEVICE] = TR(" Drivers:"); stringsText[RT_SETUP_MODE] = TR(" Resolution:"); stringsText[RT_SETUP_KEY1] = TR("1) First click on the key you want to redefine."); stringsText[RT_SETUP_KEY2] = TR("2) Then press the key you want to use instead."); @@ -118,15 +116,6 @@ void InitializeRestext() stringsText[RT_PROGRAM_READONLY] = TR("This program is read-only, clone it to edit"); stringsText[RT_PROGRAM_EXAMPLE] = TR("This is example code that cannot be run directly"); - stringsText[RT_SATCOM_LIST] = TR("\\b;List of objects\n"); - stringsText[RT_SATCOM_BOT] = TR("\\b;Robots\n"); - stringsText[RT_SATCOM_BUILDING] = TR("\\b;Buildings\n"); - stringsText[RT_SATCOM_FRET] = TR("\\b;Moveable objects\n"); - stringsText[RT_SATCOM_ALIEN] = TR("\\b;Aliens\n"); - stringsText[RT_SATCOM_NULL] = TR("\\c; (none)\\n;\n"); - stringsText[RT_SATCOM_ERROR1] = TR("\\b;Error\n"); - stringsText[RT_SATCOM_ERROR2] = TR("The list is only available if a \\l;radar station\\u object\\radar; is working.\n"); - stringsText[RT_IO_OPEN] = TR("Open"); stringsText[RT_IO_SAVE] = TR("Save"); stringsText[RT_IO_LIST] = TR("Folder: %s"); @@ -700,7 +689,6 @@ void InitializeRestext() stringsCbot[TX_BADLEFT] = TR("Assignment impossible"); stringsCbot[TX_ENDOF] = TR("Semicolon terminator missing"); stringsCbot[TX_OUTCASE] = TR("Instruction \"case\" outside a block \"switch\""); - stringsCbot[TX_NOTERM] = TR("Instructions after the final closing brace"); stringsCbot[TX_CLOSEBLK] = TR("End of block missing"); stringsCbot[TX_ELSEWITHOUTIF] = TR("Instruction \"else\" without corresponding \"if\" "); stringsCbot[TX_OPENBLK] = TR("Opening brace missing "); @@ -731,7 +719,6 @@ void InitializeRestext() stringsCbot[TX_CLBRK] = TR("\" ] \" missing"); stringsCbot[TX_RESERVED] = TR("Reserved keyword of CBOT language"); stringsCbot[TX_BADNEW] = TR("Bad argument for \"new\""); - stringsCbot[TX_OPBRK] = TR("\" [ \" expected"); stringsCbot[TX_BADSTRING] = TR("String missing"); stringsCbot[TX_BADINDEX] = TR("Incorrect index type"); stringsCbot[TX_PRIVATE] = TR("Private element"); @@ -739,7 +726,6 @@ void InitializeRestext() stringsCbot[TX_DIVZERO] = TR("Dividing by zero"); stringsCbot[TX_NOTINIT] = TR("Variable not initialized"); stringsCbot[TX_BADTHROW] = TR("Negative value rejected by \"throw\""); - stringsCbot[TX_NORETVAL] = TR("The function returned no value "); stringsCbot[TX_NORUN] = TR("No function running"); stringsCbot[TX_NOCALL] = TR("Calling an unknown function"); stringsCbot[TX_NOCLASS] = TR("This class does not exist"); @@ -748,10 +734,6 @@ void InitializeRestext() stringsCbot[TX_OUTARRAY] = TR("Access beyond array limit"); stringsCbot[TX_STACKOVER] = TR("Stack overflow"); stringsCbot[TX_DELETEDPT] = TR("Illegal object"); - stringsCbot[TX_FILEOPEN] = TR("Can't open file"); - stringsCbot[TX_NOTOPEN] = TR("File not open"); - stringsCbot[TX_ERRREAD] = TR("Read error"); - stringsCbot[TX_ERRWRITE] = TR("Write error"); } diff --git a/src/common/restext.h b/src/common/restext.h index 30067cce..58709eff 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -48,7 +48,6 @@ enum ResType */ enum ResTextType { - RT_DISINFO_TITLE = 2, RT_WINDOW_MAXIMIZED = 3, RT_WINDOW_MINIMIZED = 4, RT_WINDOW_STANDARD = 5, @@ -83,7 +82,6 @@ enum ResTextType RT_PLAY_LIST_FREEGAME = 67, RT_PLAY_RESUME = 68, - RT_SETUP_DEVICE = 80, RT_SETUP_MODE = 81, RT_SETUP_KEY1 = 82, RT_SETUP_KEY2 = 83, @@ -113,15 +111,6 @@ enum ResTextType RT_PROGRAM_READONLY = 130, RT_PROGRAM_EXAMPLE = 131, - RT_SATCOM_LIST = 140, - RT_SATCOM_BOT = 141, - RT_SATCOM_BUILDING = 142, - RT_SATCOM_FRET = 143, - RT_SATCOM_ALIEN = 144, - RT_SATCOM_NULL = 145, - RT_SATCOM_ERROR1 = 146, - RT_SATCOM_ERROR2 = 147, - RT_IO_OPEN = 150, RT_IO_SAVE = 151, RT_IO_LIST = 152, @@ -137,9 +126,6 @@ enum ResTextType RT_INTERFACE_REC = 180, - RT_MESSAGE_WIN = 200, - RT_MESSAGE_LOST = 201, - RT_LOADING_INIT = 210, RT_LOADING_PROCESSING = 211, RT_LOADING_LEVEL_SETTINGS = 212, From 6f91442db11d76d012e5c22dc0ec6a4c963b3082 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 17:10:14 +0100 Subject: [PATCH 049/360] Removed some more unused strings --- po/colobot.pot | 29 ++++-------------------- po/de.po | 42 +++++++++++++++++------------------ po/fr.po | 42 +++++++++++++++++------------------ po/pl.po | 42 +++++++++++++++++------------------ po/ru.po | 42 +++++++++++++++++------------------ src/common/error.h | 12 ---------- src/common/restext.cpp | 12 ---------- src/object/task/taskbuild.cpp | 20 ++--------------- src/object/task/taskbuild.h | 2 +- src/object/task/tasktake.cpp | 2 +- src/ui/displaytext.cpp | 1 - 11 files changed, 92 insertions(+), 154 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 60ef1bad..453930ac 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -1356,9 +1356,6 @@ msgstr "" msgid "Place occupied" msgstr "" -msgid "No other robot" -msgstr "" - msgid "You can not carry a radioactive object" msgstr "" @@ -1371,9 +1368,6 @@ msgstr "" msgid "Impossible under water" msgstr "" -msgid "Not enough energy" -msgstr "" - msgid "Titanium too far away" msgstr "" @@ -1401,13 +1395,7 @@ msgstr "" msgid "Can not produce not researched object" msgstr "" -msgid "Ground inappropriate" -msgstr "" - -msgid "Building too close" -msgstr "" - -msgid "Object too close" +msgid "Not enough energy" msgstr "" msgid "Nothing to recycle" @@ -1419,9 +1407,6 @@ msgstr "" msgid "Error in instruction move" msgstr "" -msgid "Object not found" -msgstr "" - msgid "Goto: inaccessible destination" msgstr "" @@ -1470,9 +1455,6 @@ msgstr "" msgid "Analysis already performed" msgstr "" -msgid "Not yet enough energy" -msgstr "" - msgid "No uranium to transform" msgstr "" @@ -1482,6 +1464,9 @@ msgstr "" msgid "No titanium" msgstr "" +msgid "Object too close" +msgstr "" + msgid "No information exchange post within range" msgstr "" @@ -1522,9 +1507,6 @@ msgstr "" msgid "Building destroyed" msgstr "" -msgid "Can not create this; there are too many objects" -msgstr "" - msgid "Unable to control enemy objects" msgstr "" @@ -1601,9 +1583,6 @@ msgstr "" msgid "Current mission saved" msgstr "" -msgid "Checkpoint crossed" -msgstr "" - msgid "Alien Queen killed" msgstr "" diff --git a/po/de.po b/po/de.po index 476e5e0b..ce9cf97a 100644 --- a/po/de.po +++ b/po/de.po @@ -313,9 +313,6 @@ msgstr "Gebäude fertiggestellt" msgid "Building destroyed" msgstr "Gebäude zerstört" -msgid "Building too close" -msgstr "Gebäude zu nahe" - msgid "Button %1" msgstr "Knopf %1" @@ -349,9 +346,6 @@ msgstr "Kamera rechts" msgid "Camera up\\Increase camera angle while visiting message origin" msgstr "" -msgid "Can not create this; there are too many objects" -msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" - msgid "Can not produce not researched object" msgstr "Das erforschte Objekt kann nicht produziert werden" @@ -379,9 +373,6 @@ msgstr "Anderer Spieler\\Spielername ändern" msgid "Checkpoint" msgstr "Checkpoint" -msgid "Checkpoint crossed" -msgstr "Checkpoint erreicht" - msgid "Climb\\Increases the power of the jet" msgstr "Steigen\\Leistung des Triebwerks steigern" @@ -660,9 +651,6 @@ msgstr "Grün" msgid "Green flag" msgstr "Grüne Fahne" -msgid "Ground inappropriate" -msgstr "Boden ungeeignet" - msgid "Ground not flat enough" msgstr "Boden nicht eben genug" @@ -917,9 +905,6 @@ msgstr "Keine Energie mehr" msgid "No ore in the subsoil" msgstr "Keine unterirdische Erzlagerstätte" -msgid "No other robot" -msgstr "Kein anderer Roboter" - msgid "No power cell" msgstr "Keine Batterie" @@ -959,9 +944,6 @@ msgstr "Noch nicht genug Energie" msgid "Not found anything to destroy" msgstr "Nichts zum Zerstampfen gefunden" -msgid "Not yet enough energy" -msgstr "Noch nicht genug Energie" - msgid "Nothing to analyze" msgstr "Nichts zu analysieren" @@ -1001,9 +983,6 @@ msgstr "OK\\Spieler auswählen" msgid "OK\\Close program editor and return to game" msgstr "OK\\Programm kompilieren" -msgid "Object not found" -msgstr "Das Objekt existiert nicht" - msgid "Object too close" msgstr "Gegenstand zu nahe" @@ -1826,15 +1805,24 @@ msgstr "www.epsitec.com" #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" +#~ msgid "Building too close" +#~ msgstr "Gebäude zu nahe" + #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Can not create this; there are too many objects" +#~ msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" + #~ msgid "Can't open file" #~ msgstr "Die Datei kann nicht geöffnet werden" #~ msgid "Cancel\\Keep current player name" #~ msgstr "Abbrechen\\Behält den bisherigen Spieler bei" +#~ msgid "Checkpoint crossed" +#~ msgstr "Checkpoint erreicht" + #~ msgid "Compass" #~ msgstr "Kompass" @@ -1863,6 +1851,9 @@ msgstr "www.epsitec.com" #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Eigenbeschuss\\Ihre Einheiten werden von Ihren Waffen beschädigt" +#~ msgid "Ground inappropriate" +#~ msgstr "Boden ungeeignet" + #~ msgid "Instructions after the final closing brace" #~ msgstr "Hier ist eine Anweisung nach dem Ende des Programms" @@ -1875,9 +1866,18 @@ msgstr "www.epsitec.com" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Schatten unter der Maus\\Ein Schatten erscheint unter der Maus" +#~ msgid "No other robot" +#~ msgstr "Kein anderer Roboter" + +#~ msgid "Not yet enough energy" +#~ msgstr "Noch nicht genug Energie" + #~ msgid "Num of decorative objects\\Number of purely ornamental objects" #~ msgstr "Anzahl Ziergegenstände\\Anzahl Gegenstände ohne Funktion" +#~ msgid "Object not found" +#~ msgstr "Das Objekt existiert nicht" + #~ msgid "Planets and stars\\Astronomical objects in the sky" #~ msgstr "Planeten und Sterne\\Kreisende Planeten und Sterne" diff --git a/po/fr.po b/po/fr.po index 3293ab45..ed5d83d4 100644 --- a/po/fr.po +++ b/po/fr.po @@ -306,9 +306,6 @@ msgstr "Bâtiment terminé" msgid "Building destroyed" msgstr "Bâtiment détruit" -msgid "Building too close" -msgstr "Bâtiment trop proche" - msgid "Button %1" msgstr "Bouton %1" @@ -346,9 +343,6 @@ msgstr "" "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine " "des messages" -msgid "Can not create this; there are too many objects" -msgstr "Création impossible; il y a trop d'objets" - msgid "Can not produce not researched object" msgstr "Impossible de créer un objet n'ayant pas été recherché" @@ -376,9 +370,6 @@ msgstr "Autre joueur\\Choix du nom du joueur" msgid "Checkpoint" msgstr "Indicateur" -msgid "Checkpoint crossed" -msgstr "Indicateur atteint" - msgid "Climb\\Increases the power of the jet" msgstr "Monter\\Augmenter la puissance du réacteur" @@ -655,9 +646,6 @@ msgstr "Vert" msgid "Green flag" msgstr "Drapeau vert" -msgid "Ground inappropriate" -msgstr "Terrain inadapté" - msgid "Ground not flat enough" msgstr "Sol pas assez plat" @@ -909,9 +897,6 @@ msgstr "Plus d'énergie" msgid "No ore in the subsoil" msgstr "Pas de minerai en sous-sol" -msgid "No other robot" -msgstr "Pas d'autre robot" - msgid "No power cell" msgstr "Pas de pile" @@ -951,9 +936,6 @@ msgstr "Pas encore assez d'énergie" msgid "Not found anything to destroy" msgstr "Rien trouvé à détruire" -msgid "Not yet enough energy" -msgstr "Pas encore assez d'énergie" - msgid "Nothing to analyze" msgstr "Rien à analyser" @@ -993,9 +975,6 @@ msgstr "D'accord\\Choisir le joueur" msgid "OK\\Close program editor and return to game" msgstr "D'accord\\Compiler le programme" -msgid "Object not found" -msgstr "Objet n'existe pas" - msgid "Object too close" msgstr "Objet trop proche" @@ -1813,15 +1792,24 @@ msgstr "www.epsitec.com" #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Bruitages 3D\\Positionnement sonore dans l'espace" +#~ msgid "Building too close" +#~ msgstr "Bâtiment trop proche" + #~ msgid "COLOBOT" #~ msgstr "COLOBOT" +#~ msgid "Can not create this; there are too many objects" +#~ msgstr "Création impossible; il y a trop d'objets" + #~ msgid "Can't open file" #~ msgstr "Ouverture du fichier impossible" #~ msgid "Cancel\\Keep current player name" #~ msgstr "Annuler\\Conserver le joueur actuel" +#~ msgid "Checkpoint crossed" +#~ msgstr "Indicateur atteint" + #~ msgid "Compass" #~ msgstr "Boussole" @@ -1850,6 +1838,9 @@ msgstr "www.epsitec.com" #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Dégâts à soi-même\\Vos tirs infligent des dommages à vos unités" +#~ msgid "Ground inappropriate" +#~ msgstr "Terrain inadapté" + #~ msgid "Instructions after the final closing brace" #~ msgstr "Instructions après la fin" @@ -1862,9 +1853,18 @@ msgstr "www.epsitec.com" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Souris ombrée\\Jolie souris avec une ombre" +#~ msgid "No other robot" +#~ msgstr "Pas d'autre robot" + +#~ msgid "Not yet enough energy" +#~ msgstr "Pas encore assez d'énergie" + #~ msgid "Num of decorative objects\\Number of purely ornamental objects" #~ msgstr "Nb d'objets décoratifs\\Qualité d'objets non indispensables" +#~ msgid "Object not found" +#~ msgstr "Objet n'existe pas" + #~ msgid "Planets and stars\\Astronomical objects in the sky" #~ msgstr "Planètes et étoiles\\Motifs mobiles dans le ciel" diff --git a/po/pl.po b/po/pl.po index a88c90f5..d4572786 100644 --- a/po/pl.po +++ b/po/pl.po @@ -316,9 +316,6 @@ msgstr "Budowa zakończona" msgid "Building destroyed" msgstr "Budynek zniszczony" -msgid "Building too close" -msgstr "Budynek za blisko" - msgid "Button %1" msgstr "Przycisk %1" @@ -352,9 +349,6 @@ msgstr "Camera to right" msgid "Camera up\\Increase camera angle while visiting message origin" msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości" -msgid "Can not create this; there are too many objects" -msgstr "Nie można tego utworzyć, za dużo obiektów" - msgid "Can not produce not researched object" msgstr "Nie można wyprodukować nie wynalezionego obiektu" @@ -382,9 +376,6 @@ msgstr "Zmień gracza\\Zmień gracza" msgid "Checkpoint" msgstr "Punkt kontrolny" -msgid "Checkpoint crossed" -msgstr "Przekroczono punkt kontrolny" - msgid "Climb\\Increases the power of the jet" msgstr "W górę\\Zwiększa moc silnika" @@ -661,9 +652,6 @@ msgstr "Zielony" msgid "Green flag" msgstr "Zielona flaga" -msgid "Ground inappropriate" -msgstr "Nieodpowiedni teren" - msgid "Ground not flat enough" msgstr "Powierzchnia nie jest wystarczająco płaska" @@ -915,9 +903,6 @@ msgstr "Nie ma więcej energii" msgid "No ore in the subsoil" msgstr "W ziemi nie ma żadnej rudy" -msgid "No other robot" -msgstr "Brak innego robota" - msgid "No power cell" msgstr "Brak ogniwa elektrycznego" @@ -957,9 +942,6 @@ msgstr "Wciąż za mało energii" msgid "Not found anything to destroy" msgstr "Nie znaleziono nic do zniszczenia" -msgid "Not yet enough energy" -msgstr "Wciąż za mało energii" - msgid "Nothing to analyze" msgstr "Nie ma niczego do zanalizowania" @@ -999,9 +981,6 @@ msgstr "OK\\Wybiera zaznaczonego gracza" msgid "OK\\Close program editor and return to game" msgstr "OK\\Zamyka edytor programu i powraca do gry" -msgid "Object not found" -msgstr "Obiekt nieznany" - msgid "Object too close" msgstr "Obiekt za blisko" @@ -1811,12 +1790,21 @@ msgstr "www.epsitec.com" #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" +#~ msgid "Building too close" +#~ msgstr "Budynek za blisko" + +#~ msgid "Can not create this; there are too many objects" +#~ msgstr "Nie można tego utworzyć, za dużo obiektów" + #~ msgid "Can't open file" #~ msgstr "Nie można otworzyć pliku" #~ msgid "Cancel\\Keep current player name" #~ msgstr "Anuluj\\Zachowuje bieżące imię gracza" +#~ msgid "Checkpoint crossed" +#~ msgstr "Przekroczono punkt kontrolny" + #~ msgid "Compass" #~ msgstr "Kompas" @@ -1841,6 +1829,9 @@ msgstr "www.epsitec.com" #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Przyjacielski ogień\\Własne strzały uszkadzają Twoje obiekty" +#~ msgid "Ground inappropriate" +#~ msgstr "Nieodpowiedni teren" + #~ msgid "Instructions after the final closing brace" #~ msgstr "Polecenie po końcowej klamrze zamykającej" @@ -1857,10 +1848,19 @@ msgstr "www.epsitec.com" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Cień kursora myszy\\Dodaje cień kursorowi myszy" +#~ msgid "No other robot" +#~ msgstr "Brak innego robota" + +#~ msgid "Not yet enough energy" +#~ msgstr "Wciąż za mało energii" + #~ msgid "Num of decorative objects\\Number of purely ornamental objects" #~ msgstr "" #~ "Ilość elementów dekoracyjnych \\Ilość elementów czysto dekoracyjnych" +#~ msgid "Object not found" +#~ msgstr "Obiekt nieznany" + #~ msgid "Planets and stars\\Astronomical objects in the sky" #~ msgstr "Planety i gwiazdy\\Obiekty astronomiczne na niebie" diff --git a/po/ru.po b/po/ru.po index a1d01eb7..dad69058 100644 --- a/po/ru.po +++ b/po/ru.po @@ -308,9 +308,6 @@ msgstr "Здание построено" msgid "Building destroyed" msgstr "Здание разрушено" -msgid "Building too close" -msgstr "Здание слишком близко" - msgid "Button %1" msgstr "Кнопка %1" @@ -344,9 +341,6 @@ msgstr "Камеру вправо" msgid "Camera up\\Increase camera angle while visiting message origin" msgstr "" -msgid "Can not create this; there are too many objects" -msgstr "Не удается это создать, слишком много объектов" - msgid "Can not produce not researched object" msgstr "" @@ -374,9 +368,6 @@ msgstr "Новый игрок\\Выберите имя для игрока" msgid "Checkpoint" msgstr "Контрольная точка" -msgid "Checkpoint crossed" -msgstr "Вы прошли контрольную точку" - msgid "Climb\\Increases the power of the jet" msgstr "Взлет и подъем\\Увеличивает мощность реактивного двигателя" @@ -654,9 +645,6 @@ msgstr "Зеленый" msgid "Green flag" msgstr "Зеленый флаг" -msgid "Ground inappropriate" -msgstr "Земля не подходит" - msgid "Ground not flat enough" msgstr "Земля недостаточно плоская" @@ -910,9 +898,6 @@ msgstr "Нет энергии" msgid "No ore in the subsoil" msgstr "" -msgid "No other robot" -msgstr "Нет робота" - msgid "No power cell" msgstr "Нет батареи" @@ -952,9 +937,6 @@ msgstr "Не хватает энергии" msgid "Not found anything to destroy" msgstr "" -msgid "Not yet enough energy" -msgstr "Не хватает энергии" - msgid "Nothing to analyze" msgstr "Нечего анализировать" @@ -994,9 +976,6 @@ msgstr "ОК\\Выбрать игрока" msgid "OK\\Close program editor and return to game" msgstr "ОК\\Закрыть редактор программ и вернуться к игре" -msgid "Object not found" -msgstr "Объект не найден" - msgid "Object too close" msgstr "Объект слишком близок" @@ -1817,15 +1796,24 @@ msgstr "www.epsitec.com" #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-звук\\Стерео звук" +#~ msgid "Building too close" +#~ msgstr "Здание слишком близко" + #~ msgid "COLOBOT" #~ msgstr "КОЛОБОТ" +#~ msgid "Can not create this; there are too many objects" +#~ msgstr "Не удается это создать, слишком много объектов" + #~ msgid "Can't open file" #~ msgstr "Невозможно открыть файл" #~ msgid "Cancel\\Keep current player name" #~ msgstr "Отмена\\Отмена" +#~ msgid "Checkpoint crossed" +#~ msgstr "Вы прошли контрольную точку" + #~ msgid "Compass" #~ msgstr "Компас" @@ -1854,6 +1842,9 @@ msgstr "www.epsitec.com" #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Огонь по своим\\Вы можете повредить собственные объекты" +#~ msgid "Ground inappropriate" +#~ msgstr "Земля не подходит" + #~ msgid "Instructions after the final closing brace" #~ msgstr "Инструкция после последней закрывающей фигурной скобки" @@ -1866,9 +1857,18 @@ msgstr "www.epsitec.com" #~ msgid "Mouse shadow\\Gives the mouse a shadow" #~ msgstr "Тень мыши\\Мышь отбрасывает тень" +#~ msgid "No other robot" +#~ msgstr "Нет робота" + +#~ msgid "Not yet enough energy" +#~ msgstr "Не хватает энергии" + #~ msgid "Num of decorative objects\\Number of purely ornamental objects" #~ msgstr "Количество декораций\\Количество декоративных объектов" +#~ msgid "Object not found" +#~ msgstr "Объект не найден" + #~ msgid "Planets and stars\\Astronomical objects in the sky" #~ msgstr "Планеты и звезды\\Астрономические объекты в небе" diff --git a/src/common/error.h b/src/common/error.h index f638a06d..d7352980 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -36,13 +36,11 @@ enum Error 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 @@ -57,17 +55,12 @@ enum Error ERR_SEARCH_FLY = 140, //! < not possible in flight ERR_SEARCH_MOTOR = 142, //! < impossible in movement 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_ENERGY = 161, //! < not enough energy - ERR_FIRE_FLY = 162, //! < not possible in flight ERR_RECOVER_ENERGY = 171, //! < not enough energy ERR_RECOVER_NULL = 172, //! < lack of ruin ERR_CONVERT_EMPTY = 180, //! < no stone was transformed 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 @@ -88,13 +81,10 @@ enum Error 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 @@ -112,7 +102,6 @@ enum Error ERR_MISSION_NOTERM = 600, //! < Mission not completed ERR_DELETEMOBILE = 700, //! < vehicle destroyed ERR_DELETEBUILDING = 701, //! < building destroyed - ERR_TOOMANY = 702, //! < too many objects ERR_ENEMY_OBJECT = 703, //! < can't control enemy object ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited @@ -147,7 +136,6 @@ enum Error 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 diff --git a/src/common/restext.cpp b/src/common/restext.cpp index abba791b..67ac2158 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -563,13 +563,11 @@ void InitializeRestext() stringsErr[ERR_MANIP_NIL] = TR("Nothing to grab"); stringsErr[ERR_MANIP_MOTOR] = TR("Impossible when moving"); stringsErr[ERR_MANIP_OCC] = TR("Place occupied"); - stringsErr[ERR_MANIP_FRIEND] = TR("No other robot"); stringsErr[ERR_MANIP_RADIO] = TR("You can not carry a radioactive object"); stringsErr[ERR_MANIP_WATER] = TR("You can not carry an object under water"); stringsErr[ERR_MANIP_EMPTY] = TR("Nothing to drop"); stringsErr[ERR_BUILD_FLY] = TR("Impossible when flying"); stringsErr[ERR_BUILD_WATER] = TR("Impossible under water"); - stringsErr[ERR_BUILD_ENERGY] = TR("Not enough energy"); stringsErr[ERR_BUILD_METALAWAY] = TR("Titanium too far away"); stringsErr[ERR_BUILD_METALNEAR] = TR("Titanium too close"); stringsErr[ERR_BUILD_METALINEX] = TR("No titanium around"); @@ -584,19 +582,14 @@ void InitializeRestext() stringsErr[ERR_BUILD_RESEARCH] = TR("Can not produce not researched object"); stringsErr[ERR_SEARCH_MOTOR] = TR("Impossible when moving"); stringsErr[ERR_TERRA_ENERGY] = TR("Not enough energy"); - stringsErr[ERR_TERRA_FLOOR] = TR("Ground inappropriate"); - stringsErr[ERR_TERRA_BUILDING] = TR("Building too close"); - stringsErr[ERR_TERRA_OBJECT] = TR("Object too close"); stringsErr[ERR_RECOVER_ENERGY] = TR("Not enough energy"); stringsErr[ERR_RECOVER_NULL] = TR("Nothing to recycle"); stringsErr[ERR_SHIELD_ENERGY] = TR("No more energy"); stringsErr[ERR_MOVE_IMPOSSIBLE] = TR("Error in instruction move"); - stringsErr[ERR_FIND_IMPOSSIBLE] = TR("Object not found"); stringsErr[ERR_GOTO_IMPOSSIBLE] = TR("Goto: inaccessible destination"); stringsErr[ERR_GOTO_ITER] = TR("Goto: inaccessible destination"); stringsErr[ERR_GOTO_BUSY] = TR("Goto: destination occupied"); stringsErr[ERR_FIRE_ENERGY] = TR("Not enough energy"); - stringsErr[ERR_FIRE_FLY] = TR("Impossible when flying"); stringsErr[ERR_CONVERT_EMPTY] = TR("No titanium ore to convert"); stringsErr[ERR_DERRICK_NULL] = TR("No ore in the subsoil"); stringsErr[ERR_STATION_NULL] = TR("No energy in the subsoil"); @@ -615,13 +608,10 @@ void InitializeRestext() stringsErr[ERR_LABO_NULL] = TR("Nothing to analyze"); stringsErr[ERR_LABO_BAD] = TR("Analyzes only organic matter"); stringsErr[ERR_LABO_ALREADY] = TR("Analysis already performed"); - stringsErr[ERR_NUCLEAR_NULL] = TR("No energy in the subsoil"); - stringsErr[ERR_NUCLEAR_LOW] = TR("Not yet enough energy"); stringsErr[ERR_NUCLEAR_EMPTY] = TR("No uranium to transform"); stringsErr[ERR_NUCLEAR_BAD] = TR("Transforms only uranium"); stringsErr[ERR_FACTORY_NULL] = TR("No titanium"); stringsErr[ERR_FACTORY_NEAR] = TR("Object too close"); - stringsErr[ERR_RESET_NEAR] = TR("Place occupied"); stringsErr[ERR_INFO_NULL] = TR("No information exchange post within range"); stringsErr[ERR_VEH_VIRUS] = TR("Program infected by a virus"); stringsErr[ERR_BAT_VIRUS] = TR("Infected by a virus; temporarily out of order"); @@ -639,7 +629,6 @@ void InitializeRestext() stringsErr[ERR_MISSION_NOTERM] = TR("The mission is not accomplished yet (press \\key help; for more details)"); stringsErr[ERR_DELETEMOBILE] = TR("Bot destroyed"); stringsErr[ERR_DELETEBUILDING] = TR("Building destroyed"); - stringsErr[ERR_TOOMANY] = TR("Can not create this; there are too many objects"); stringsErr[ERR_ENEMY_OBJECT] = TR("Unable to control enemy objects"); stringsErr[ERR_OBLIGATORYTOKEN] = TR("\"%s\" missing in this exercise"); stringsErr[ERR_PROHIBITEDTOKEN] = TR("Do not use in this exercise"); @@ -672,7 +661,6 @@ void InitializeRestext() stringsErr[INFO_LOST] = TR("<<< Sorry; mission failed >>>"); stringsErr[INFO_LOSTq] = TR("<<< Sorry; mission failed >>>"); stringsErr[INFO_WRITEOK] = TR("Current mission saved"); - stringsErr[INFO_DELETEPATH] = TR("Checkpoint crossed"); stringsErr[INFO_DELETEMOTHER] = TR("Alien Queen killed"); stringsErr[INFO_DELETEANT] = TR("Ant fatally wounded"); stringsErr[INFO_DELETEBEE] = TR("Wasp fatally wounded"); diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index 7f2ebce4..75851827 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -86,7 +86,7 @@ CTaskBuild::~CTaskBuild() // Creates a building. -bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) +void CTaskBuild::CreateBuilding(Math::Vector pos, float angle) { ObjectCreateParams params; params.pos = pos; @@ -117,7 +117,6 @@ bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle) m_buildingPos = m_building->GetPosition(); m_buildingPos.y -= m_buildingHeight; m_building->SetPosition(m_buildingPos); - return true; } // Creates lights for the effects. @@ -280,22 +279,7 @@ bool CTaskBuild::EventProcess(const Event &event) pos = m_metal->GetPosition(); a = m_object->GetRotationY(); - if ( !CreateBuilding(pos, a+Math::PI) ) - { - m_metal->SetLock(false); // usable again - m_motion->SetAction(-1); - if (m_object->GetType() == OBJECT_HUMAN) - { - m_object->SetObjectParent(14, 0); - m_object->SetPartPosition(14, Math::Vector(-1.5f, 0.3f, -1.35f)); - m_object->SetPartRotationZ(14, Math::PI); - } - m_camera->FlushEffect(); - Abort(); - m_bError = true; - m_main->DisplayError(ERR_TOOMANY, m_object->GetPosition()); - return false; - } + CreateBuilding(pos, a+Math::PI); CreateLight(); } diff --git a/src/object/task/taskbuild.h b/src/object/task/taskbuild.h index 65a19d88..618eb57c 100644 --- a/src/object/task/taskbuild.h +++ b/src/object/task/taskbuild.h @@ -61,7 +61,7 @@ public: protected: Error FlatFloor(); - bool CreateBuilding(Math::Vector pos, float angle); + void CreateBuilding(Math::Vector pos, float angle); void CreateLight(); void BlackLight(); CObject* SearchMetalObject(float &angle, float dMin, float dMax, float aLimit, Error &err); diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index 2945ec6b..635ae15d 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -136,7 +136,7 @@ Error CTaskTake::Start() CObject* power = dynamic_cast(other)->GetPower(); type = power->GetType(); if ( type == OBJECT_URANIUM ) return ERR_MANIP_RADIO; - if ( !power->Implements(ObjectInterfaceType::Transportable) ) return ERR_MANIP_FRIEND; // TODO: This makes no sense, probably redundant + assert(power->Implements(ObjectInterfaceType::Transportable)); //? m_camera->StartCentering(m_object, Math::PI*0.3f, -Math::PI*0.1f, 0.0f, 0.8f); m_arm = TTA_FRIEND; } diff --git a/src/ui/displaytext.cpp b/src/ui/displaytext.cpp index 6a04ab65..12154ee3 100644 --- a/src/ui/displaytext.cpp +++ b/src/ui/displaytext.cpp @@ -145,7 +145,6 @@ void CDisplayText::DisplayError(Error err, Math::Vector goal, float height, err == ERR_VEH_VIRUS || err == ERR_DELETEMOBILE || err == ERR_DELETEBUILDING || - err == ERR_TOOMANY || err == INFO_LOST ) { type = TT_ERROR; From 955e2b4a04e242ccf533d9ed65b2c4593636de0c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 17:11:22 +0100 Subject: [PATCH 050/360] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index a125f7ab..827c18d1 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit a125f7ab3f967466d1903bf8b16016036adaebd9 +Subproject commit 827c18d17395ed886e999967551b50e2a5079ac4 From 0c21631c9c0a5775552bca036f9f61c539508f37 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 17:26:56 +0100 Subject: [PATCH 051/360] Updated constants for "catch" * removed compile-time errors since they cannot be caught anyway * added missing runtime errors --- src/CBot/CBotProgram.cpp | 82 ++++++---------------------------------- 1 file changed, 12 insertions(+), 70 deletions(-) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 305d9312..2603fff6 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -1023,85 +1023,27 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser ) } -CBotString CBotProgram::m_DebugVarStr = ""; - -bool rCBotDebug( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - pResult->SetValString( CBotProgram::m_DebugVarStr ); - - return true; -} - -CBotTypResult cCBotDebug( CBotVar* &pVar, void* pUser ) -{ - // no parameter - if ( pVar != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // function returns a result "string" - return CBotTypResult( CBotTypString ); -} - - // TODO: Refactor this - including .cpp files is bad #include "StringFunctions.cpp" void CBotProgram::Init() { - CBotToken::DefineNum( "CBotErrOpenPar", 5000) ; // missing the opening parenthesis - CBotToken::DefineNum( "CBotErrClosePar", 5001) ; // missing the closing parenthesis - CBotToken::DefineNum( "CBotErrNotBoolean", 5002) ; // expression must be a boolean - CBotToken::DefineNum( "CBotErrUndefVar", 5003) ; // undeclared variable - CBotToken::DefineNum( "CBotErrBadLeft", 5004) ; // impossible assignment (5 = ...) - CBotToken::DefineNum( "CBotErrNoTerminator", 5005) ;// semicolon expected - CBotToken::DefineNum( "CBotErrCaseOut", 5006) ; // case outside a switch - CBotToken::DefineNum( "CBotErrCloseBlock", 5008) ; // missing " } " - CBotToken::DefineNum( "CBotErrElseWhitoutIf", 5009) ;// else without matching if - CBotToken::DefineNum( "CBotErrOpenBlock", 5010) ; // missing " { " - CBotToken::DefineNum( "CBotErrBadType1", 5011) ; // wrong type for the assignment - CBotToken::DefineNum( "CBotErrRedefVar", 5012) ; // redefinition of the variable - CBotToken::DefineNum( "CBotErrBadType2", 5013) ; // two operands are incompatible - CBotToken::DefineNum( "CBotErrUndefCall", 5014) ; // routine unknown - CBotToken::DefineNum( "CBotErrNoDoubleDots", 5015) ;// " : " expected - CBotToken::DefineNum( "CBotErrBreakOutside", 5017) ;// break outside of a loop - CBotToken::DefineNum( "CBotErrUndefLabel", 5019) ; // unknown label - CBotToken::DefineNum( "CBotErrLabel", 5018) ; // label can not get here - CBotToken::DefineNum( "CBotErrNoCase", 5020) ; // missing " case " - CBotToken::DefineNum( "CBotErrBadNum", 5021) ; // expected number - CBotToken::DefineNum( "CBotErrVoid", 5022) ; // " void " not possble here - CBotToken::DefineNum( "CBotErrNoType", 5023) ; // type declaration expected - CBotToken::DefineNum( "CBotErrNoVar", 5024) ; // variable name expected - CBotToken::DefineNum( "CBotErrNoFunc", 5025) ; // expected function name - CBotToken::DefineNum( "CBotErrOverParam", 5026) ; // too many parameters - CBotToken::DefineNum( "CBotErrRedefFunc", 5027) ; // this function already exists - CBotToken::DefineNum( "CBotErrLowParam", 5028) ; // not enough parameters - CBotToken::DefineNum( "CBotErrBadParam", 5029) ; // mauvais types de paramètres - CBotToken::DefineNum( "CBotErrNbParam", 5030) ; // wrong number of parameters - CBotToken::DefineNum( "CBotErrUndefItem", 5031) ; // element does not exist in the class - CBotToken::DefineNum( "CBotErrUndefClass", 5032) ; // variable is not a class - CBotToken::DefineNum( "CBotErrNoConstruct", 5033) ; // no appropriate constructor - CBotToken::DefineNum( "CBotErrRedefClass", 5034) ; // Class already exists - CBotToken::DefineNum( "CBotErrCloseIndex", 5035) ; // " ] " expected - CBotToken::DefineNum( "CBotErrReserved", 5036) ; // reserved word (for a DefineNum) - -// Here are the list of errors that can be returned by the module -// for the execution - - CBotToken::DefineNum( "CBotErrZeroDiv", 6000) ; // division by zero - CBotToken::DefineNum( "CBotErrNotInit", 6001) ; // uninitialized variable - CBotToken::DefineNum( "CBotErrBadThrow", 6002) ; // throw a negative value - CBotToken::DefineNum( "CBotErrNoRetVal", 6003) ; // function did not return results - CBotToken::DefineNum( "CBotErrNoRun", 6004) ; // active Run () without a function - CBotToken::DefineNum( "CBotErrUndefFunc", 6005) ; // Calling a function that no longer exists + CBotToken::DefineNum("CBotErrZeroDiv", TX_DIVZERO); // division by zero + CBotToken::DefineNum("CBotErrNotInit", TX_NOTINIT); // uninitialized variable + CBotToken::DefineNum("CBotErrBadThrow", TX_BADTHROW); // throw a negative value + //CBotToken::DefineNum("CBotErrNoRetVal", 6003); // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P + CBotToken::DefineNum("CBotErrNoRun", TX_NORUN); // active Run () without a function // TODO: Is this actually a runtime error? + CBotToken::DefineNum("CBotErrUndefFunc", TX_NOCALL); // Calling a function that no longer exists + CBotToken::DefineNum("CBotErrUndefClass", TX_NOCLASS); // Class no longer exists + CBotToken::DefineNum("CBotErrNullPointer", TX_NULLPT); // Attempted to use a null pointer + CBotToken::DefineNum("CBotErrNan", TX_OPNAN); // Can't do operations on nan + CBotToken::DefineNum("CBotErrOutOfBounds", TX_OUTARRAY); // Attempted access out of bounds of an array + CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER); // Stack overflow + CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT); // Attempted to use deleted object CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); InitStringFunctions(); - - // just a function for various debug - CBotProgram::AddFunction("CBOTDEBUGDD", rCBotDebug, cCBotDebug); - //TODO implement this deletion - // DeleteFile("CbotDebug.txt"); - } void CBotProgram::Free() From 8a160961fc134f0e052e348cfb4018f57eadf9f8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 21 Nov 2015 17:33:48 +0100 Subject: [PATCH 052/360] Removed STARTDEBUGDD --- src/CBot/CBot.cpp | 3 --- src/CBot/CBot.h | 13 ------------- src/CBot/CBotDll.h | 2 -- src/CBot/CBotProgram.cpp | 2 -- src/CBot/CBotString.cpp | 1 - src/CBot/CBotWhile.cpp | 32 -------------------------------- src/CBot/resource.h | 1 - 7 files changed, 54 deletions(-) diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 38288645..f4727d33 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -225,9 +225,6 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) case ID_THROW: return CBotThrow::Compile(p, pStack); - case ID_DEBUGDD: - return CBotStartDebugDD::Compile(p, pStack); - case ID_INT: return CBotInt::Compile(p, pStack); diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 4437104a..6f37b8b5 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -627,19 +627,6 @@ public: }; -class CBotStartDebugDD : public CBotInstr -{ -private: - -public: - CBotStartDebugDD(); - ~CBotStartDebugDD(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; -}; - - class CBotIf : public CBotInstr { private: diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 47dbb480..57ee15b7 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -487,8 +487,6 @@ private: long m_Ident; // associated identifier public: - static CBotString m_DebugVarStr; // end of a debug - bool m_bDebugDD; // idem déclanchable par robot \TODO ??? bool m_bCompileClass; public: diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 2603fff6..cda190ce 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -33,7 +33,6 @@ CBotProgram::CBotProgram() m_ErrorCode = 0; m_Ident = 0; - m_bDebugDD = 0; } CBotProgram::CBotProgram(CBotVar* pInstance) @@ -46,7 +45,6 @@ CBotProgram::CBotProgram(CBotVar* pInstance) m_ErrorCode = 0; m_Ident = 0; - m_bDebugDD = 0; } diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index bde3d0dc..1f31f7f2 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -57,7 +57,6 @@ const std::map CBotString::s_keywordString = {ID_STATIC, "static"}, {ID_PROTECTED, "protected"}, {ID_PRIVATE, "private"}, - {ID_DEBUGDD, "STARTDEBUGDD"}, {ID_INT, "int"}, {ID_FLOAT, "float"}, {ID_BOOLEAN, "boolean"}, diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index c7272c7c..09cdc2cd 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -1259,35 +1259,3 @@ void CBotThrow :: RestoreState(CBotStack* &pj, bool bMain) } - -//////////////////////////////////////////////////////////// - - -CBotStartDebugDD::CBotStartDebugDD() -{ - name = "CBotStartDebugDD"; // debug -} - -CBotStartDebugDD::~CBotStartDebugDD() -{ -} - -CBotInstr* CBotStartDebugDD::Compile(CBotToken* &p, CBotCStack* pStack) -{ - - if (!IsOfType(p, ID_DEBUGDD)) return nullptr; // should never happen - - return new CBotStartDebugDD(); // creates the object - -} - -// execution of instruction "throw" - -bool CBotStartDebugDD :: Execute(CBotStack* &pj) -{ - CBotProgram* p = pj->GetBotCall(); - p->m_bDebugDD = true; - - return true; -} - diff --git a/src/CBot/resource.h b/src/CBot/resource.h index 4bb008a8..5c204f83 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -49,7 +49,6 @@ enum EID ID_STATIC, ID_PROTECTED, ID_PRIVATE, - ID_DEBUGDD, ID_INT, ID_FLOAT, ID_BOOLEAN, From 6492908cefa7b93fe0f06df89b2017fecba7f0be Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 22 Nov 2015 14:10:45 +0100 Subject: [PATCH 053/360] Added radarall() (#624) --- src/object/object_manager.cpp | 71 ++++++++++++++++++++-------- src/object/object_manager.h | 43 +++++++++++++++++ src/script/cbottoken.cpp | 11 +++-- src/script/scriptfunc.cpp | 88 ++++++++++++++++++++++++----------- src/script/scriptfunc.h | 2 + 5 files changed, 166 insertions(+), 49 deletions(-) diff --git a/src/object/object_manager.cpp b/src/object/object_manager.cpp index 3c43c757..1ca47aad 100644 --- a/src/object/object_manager.cpp +++ b/src/object/object_manager.cpp @@ -230,15 +230,15 @@ int CObjectManager::CountObjectsImplementing(ObjectInterfaceType interface) return count; } -CObject* CObjectManager::Radar(CObject* pThis, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { std::vector types; if (type != OBJECT_NULL) types.push_back(type); - return Radar(pThis, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return RadarAll(pThis, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); } -CObject* CObjectManager::Radar(CObject* pThis, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { Math::Vector iPos; float iAngle; @@ -253,22 +253,22 @@ CObject* CObjectManager::Radar(CObject* pThis, std::vector type, flo iPos = Math::Vector(); iAngle = 0.0f; } - return Radar(pThis, iPos, iAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return RadarAll(pThis, iPos, iAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); } -CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { std::vector types; if (type != OBJECT_NULL) types.push_back(type); - return Radar(pThis, thisPosition, thisAngle, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return RadarAll(pThis, thisPosition, thisAngle, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); } -CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +std::vector CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) { - CObject *pObj, *pBest; + CObject *pObj; Math::Vector iPos, oPos; - float best, iAngle, d, a; + float iAngle, d, a; ObjectType oType; minDist *= g_unit; @@ -282,9 +282,7 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float RadarFilter filter_flying = static_cast(filter & (FILTER_ONLYLANDING | FILTER_ONLYFLYING)); RadarFilter filter_enemy = static_cast(filter & (FILTER_FRIENDLY | FILTER_ENEMY | FILTER_NEUTRAL)); - if ( !furthest ) best = 100000.0f; - else best = 0.0f; - pBest = nullptr; + std::map best; for ( auto it = m_objects.begin() ; it != m_objects.end() ; ++it ) { pObj = it->second.get(); @@ -359,16 +357,51 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW ! if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) || focus >= Math::PI*2.0f ) { - if ( (!furthest && d < best) || - (furthest && d > best) ) - { - best = d; - pBest = pObj; - } + best[d] = pObj; } } - return pBest; + std::vector sortedBest; + if (!furthest) + { + for (auto it = best.begin(); it != best.end(); ++it) + { + sortedBest.push_back(it->second); + } + } + else + { + for (auto it = best.rbegin(); it != best.rend(); ++it) + { + sortedBest.push_back(it->second); + } + } + + return sortedBest; +} + +CObject* CObjectManager::Radar(CObject* pThis, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +{ + std::vector best = RadarAll(pThis, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return best.size() > 0 ? best[0] : nullptr; +} + +CObject* CObjectManager::Radar(CObject* pThis, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +{ + std::vector best = RadarAll(pThis, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return best.size() > 0 ? best[0] : nullptr; +} + +CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +{ + std::vector best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return best.size() > 0 ? best[0] : nullptr; +} + +CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) +{ + std::vector best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); + return best.size() > 0 ? best[0] : nullptr; } CObject* CObjectManager::FindNearest(CObject* pThis, ObjectType type, float maxDist, bool cbotTypes) diff --git a/src/object/object_manager.h b/src/object/object_manager.h index 080a25bc..cd2bde5b 100644 --- a/src/object/object_manager.h +++ b/src/object/object_manager.h @@ -192,6 +192,49 @@ public: return CObjectContainerProxy(m_objects, m_activeObjectIterators); } + //! Finds an object, like radar() in CBot + //@{ + std::vector RadarAll(CObject* pThis, + ObjectType type = OBJECT_NULL, + float angle = 0.0f, + float focus = Math::PI*2.0f, + float minDist = 0.0f, + float maxDist = 1000.0f, + bool furthest = false, + RadarFilter filter = FILTER_NONE, + bool cbotTypes = false); + std::vector RadarAll(CObject* pThis, + std::vector type = std::vector(), + float angle = 0.0f, + float focus = Math::PI*2.0f, + float minDist = 0.0f, + float maxDist = 1000.0f, + bool furthest = false, + RadarFilter filter = FILTER_NONE, + bool cbotTypes = false); + std::vector RadarAll(CObject* pThis, + Math::Vector thisPosition, + float thisAngle, + ObjectType type = OBJECT_NULL, + float angle = 0.0f, + float focus = Math::PI*2.0f, + float minDist = 0.0f, + float maxDist = 1000.0f, + bool furthest = false, + RadarFilter filter = FILTER_NONE, + bool cbotTypes = false); + std::vector RadarAll(CObject* pThis, + Math::Vector thisPosition, + float thisAngle, + std::vector type = std::vector(), + float angle = 0.0f, + float focus = Math::PI*2.0f, + float minDist = 0.0f, + float maxDist = 1000.0f, + bool furthest = false, + RadarFilter filter = FILTER_NONE, + bool cbotTypes = false); + //@} //! Finds an object, like radar() in CBot //@{ CObject* Radar(CObject* pThis, diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index dc491c55..535265c1 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -272,6 +272,7 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "destroy" ) == 0 ) helpfile = "cbot/destroy"; if ( strcmp(token, "search" ) == 0 ) helpfile = "cbot/search"; if ( strcmp(token, "radar" ) == 0 ) helpfile = "cbot/radar"; + if ( strcmp(token, "radarall" ) == 0 ) helpfile = "cbot/radarall"; if ( strcmp(token, "direction" ) == 0 ) helpfile = "cbot/direct"; if ( strcmp(token, "distance" ) == 0 ) helpfile = "cbot/dist"; if ( strcmp(token, "distance2d" ) == 0 ) helpfile = "cbot/dist2d"; @@ -421,6 +422,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "destroy" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; + if ( strcmp(token, "radarall" ) == 0 ) return true; if ( strcmp(token, "detect" ) == 0 ) return true; if ( strcmp(token, "direction" ) == 0 ) return true; if ( strcmp(token, "distance" ) == 0 ) return true; @@ -522,6 +524,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );"; if ( strcmp(token, "search" ) == 0 ) return "search ( cat, pos );"; if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens, filter );"; + if ( strcmp(token, "radarall" ) == 0 ) return "radarall ( cat, angle, focus, min, max, sens, filter );"; if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );"; if ( strcmp(token, "direction" ) == 0 ) return "direction ( position );"; if ( strcmp(token, "distance2d") == 0 ) return "distance2d ( p1, p2 );"; @@ -566,10 +569,10 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "strfind" ) == 0 ) return "strfind ( string, substring );"; if ( strcmp(token, "strlower" ) == 0 ) return "strlower ( string );"; if ( strcmp(token, "strupper" ) == 0 ) return "strupper ( string );"; - if ( strcmp(token, "open" ) == 0 ) return "open ( filename, mode );"; - if ( strcmp(token, "close" ) == 0 ) return "close ( );"; - if ( strcmp(token, "writeln" ) == 0 ) return "writeln ( string );"; - if ( strcmp(token, "readln" ) == 0 ) return "readln ( );"; + if ( strcmp(token, "open" ) == 0 ) return "file.open ( filename, mode );"; + if ( strcmp(token, "close" ) == 0 ) return "file.close ( );"; + if ( strcmp(token, "writeln" ) == 0 ) return "file.writeln ( string );"; + if ( strcmp(token, "readln" ) == 0 ) return "file.readln ( );"; if ( strcmp(token, "eof" ) == 0 ) return "eof ( );"; if ( strcmp(token, "deletefile") == 0 ) return "deletefile ( filename );"; if ( strcmp(token, "openfile" ) == 0 ) return "openfile ( filename, mode );"; diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 3b55bb23..a49dc9c1 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -1027,51 +1027,56 @@ bool CScriptFunctions::rSearch(CBotVar* var, CBotVar* result, int& exception, vo } -// Compilation of instruction "radar(type, angle, focus, min, max, sens)". - -CBotTypResult CScriptFunctions::cRadar(CBotVar* &var, void* user) +CBotTypResult compileRadar(CBotVar* &var, void* user, CBotTypResult returnValue) { CBotVar* array; - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() == CBotTypArrayPointer ) { array = var->GetItemList(); - if ( array == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( array == nullptr ) return returnValue; if ( array->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // type } else if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // type var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // angle var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // focus var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // min var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // max var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // sense var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); // filter var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult(CBotTypPointer, "object"); + if ( var == nullptr ) return returnValue; return CBotTypResult(CBotErrOverParam); } -// Instruction "radar(type, angle, focus, min, max, sens, filter)". - -bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) +CBotTypResult CScriptFunctions::cRadarAll(CBotVar* &var, void* user) +{ + return compileRadar(var, user, CBotTypResult(CBotTypArrayPointer, CBotTypResult(CBotTypPointer, "object"))); +} + +// Compilation of instruction "radar(type, angle, focus, min, max, sens)". + +CBotTypResult CScriptFunctions::cRadar(CBotVar* &var, void* user) +{ + return compileRadar(var, user, CBotTypResult(CBotTypPointer, "object")); +} + +bool runRadar(CBotVar* var, std::function, float, float, float, float, bool, RadarFilter)> code) { - CObject* pThis = static_cast(user)->m_object; - CObject *pBest; CBotVar* array; - Math::Vector oPos; RadarFilter filter; float minDist, maxDist, sens, angle, focus; int type; @@ -1153,17 +1158,47 @@ bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, voi } } - pBest = CObjectManager::GetInstancePointer()->Radar(pThis, type_v, angle, focus, minDist, maxDist, sens < 0, filter, true); //TODO: why is "sens" done like that? + return code(type_v, angle, focus, minDist, maxDist, sens < 0, filter); +} - if ( pBest == nullptr ) +// Instruction "radar(type, angle, focus, min, max, sens, filter)". + +bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + return runRadar(var, [&result, user](std::vector types, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter) { - result->SetPointer(nullptr); - } - else + CObject* pThis = static_cast(user)->m_object; + CObject* best = CObjectManager::GetInstancePointer()->Radar(pThis, types, angle, focus, minDist, maxDist, furthest, filter, true); + + if (best == nullptr) + { + result->SetPointer(nullptr); + } + else + { + result->SetPointer(best->GetBotVar()); + } + + return true; + }); +} + +bool CScriptFunctions::rRadarAll(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + return runRadar(var, [&result, user](std::vector types, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter) { - result->SetPointer(pBest->GetBotVar()); - } - return true; + CObject* pThis = static_cast(user)->m_object; + std::vector best = CObjectManager::GetInstancePointer()->RadarAll(pThis, types, angle, focus, minDist, maxDist, furthest, filter, true); + + int i = 0; + result->SetInit(CBotVar::InitType::DEF); + for (CObject* obj : best) + { + result->GetItem(i++, true)->SetPointer(obj->GetBotVar()); + } + + return true; + }); } @@ -3779,6 +3814,7 @@ void CScriptFunctions::Init() CBotProgram::AddFunction("delete", rDelete, CScriptFunctions::cDelete); CBotProgram::AddFunction("search", rSearch, CScriptFunctions::cSearch); CBotProgram::AddFunction("radar", rRadar, CScriptFunctions::cRadar); + CBotProgram::AddFunction("radarall", rRadarAll, CScriptFunctions::cRadarAll); CBotProgram::AddFunction("detect", rDetect, CScriptFunctions::cDetect); CBotProgram::AddFunction("direction", rDirection, CScriptFunctions::cDirection); CBotProgram::AddFunction("produce", rProduce, CScriptFunctions::cProduce); diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index e01cf7a4..9428879a 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -58,6 +58,7 @@ private: static CBotTypResult cDelete(CBotVar* &var, void* user); static CBotTypResult cSearch(CBotVar* &var, void* user); static CBotTypResult cRadar(CBotVar* &var, void* user); + static CBotTypResult cRadarAll(CBotVar* &var, void* user); static CBotTypResult cDetect(CBotVar* &var, void* user); static CBotTypResult cDirection(CBotVar* &var, void* user); static CBotTypResult cProduce(CBotVar* &var, void* user); @@ -108,6 +109,7 @@ private: static bool rDelete(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rSearch(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rRadar(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rRadarAll(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDetect(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDirection(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user); From b42c1376e5efa8def4c6e3621f6a69714102c5b9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 17:49:25 +0100 Subject: [PATCH 054/360] Move CBotToken class in its own header and source files. --- src/CBot/CBotDll.h | 152 +--------------------- src/CBot/CBotToken.cpp | 78 ++++++------ src/CBot/CBotToken.h | 276 +++++++++++++++++++++++++++++++++++++--- src/CBot/CMakeLists.txt | 22 ++-- src/script/script.cpp | 1 + 5 files changed, 310 insertions(+), 219 deletions(-) diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 57ee15b7..dbeaf8f8 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -26,8 +26,13 @@ #pragma once -#include +// Modules inlcude #include "resource.h" + +// Local include + +// Global include +#include #include #include @@ -990,151 +995,6 @@ public: }; -#define MAXDEFNUM 1000 // limited number of DefineNum - -///////////////////////////////////////////////////////////////////////////////////// -// Token management (tokens) - -#define TokenTypKeyWord 1 // a keyword of the language (see TokenKeyWord) -#define TokenTypNum 2 // number -#define TokenTypString 3 // string -#define TokenTypVar 4 // a variable name -#define TokenTypDef 5 // value according DefineNum - -#define TokenKeyWord 2000 // keywords of the language -#define TokenKeyDeclare 2100 // keywords of declarations (int, float,..) -#define TokenKeyVal 2200 // keywords representing the value (true, false, null, nan) -#define TokenKeyOp 2300 // operators - -/** - * \class CBotToken - * Responsible for token management - */ -class CBotToken -{ -private: - static - CBotStringArray m_ListKeyWords; // list of keywords of language - static - int m_ListIdKeyWords[200]; // the corresponding codes - - static - CBotStringArray m_ListKeyDefine; // names defined by a DefineNum - static - long m_ListKeyNums[MAXDEFNUM]; // the ​​associated values - -private: - CBotToken* m_next; // following in the list - CBotToken* m_prev; - int m_type; // type of Token - long m_IdKeyWord; // number of the keyword if it is a - // or value of the "define" - - CBotString m_Text; // word found as token - CBotString m_Sep; // following separators - - int m_start; // position in the original text (program) - int m_end; // the same for the end of the token - - /** - * \brief Check whether given parameter is a keyword - */ - static - int GetKeyWords(const char* w); // is it a keyword? - static - bool GetKeyDefNum(const char* w, CBotToken* &token); - - /** - * \brief Loads the list of keywords - */ - static - void LoadKeyWords(); - -public: - /** - * \brief Constructors - */ - CBotToken(); - CBotToken(const CBotToken* pSrc); - CBotToken(const CBotString& mot, const CBotString& sep, int start=0, int end=0); - CBotToken(const char* mot, const char* sep = nullptr); - - /** - * \brief Destructor - */ - ~CBotToken(); - /** - * \brief Returns the type of token - */ - int GetType(); - - /** - * \brief makes the string corresponding to this token - */ - CBotString& GetString(); - - /** - * \brief makes the following separator token - */ - CBotString& GetSep(); - - /** - * \brief position of the beginning in the text - */ - int GetStart(); - /** - * \brief end position in the text - */ - int GetEnd(); - - /** - * \brief gives the next token in the list - */ - CBotToken* GetNext(); - /** - * \brief gives the previous token in a list - */ - CBotToken* GetPrev(); - - /** - * \brief transforms the entire program - */ - static - CBotToken* CompileTokens(const char* p, int& error); - - /** - * \brief releases the list - */ - static - void Delete(CBotToken* pToken); // libère la liste - - - // fonctions non utiles en export - static - bool DefineNum(const char* name, long val); - void SetString(const char* name); - - void SetPos(int start, int end); - long GetIdKey(); - /** - * \brief adds a token (a copy) - */ - void AddNext(CBotToken* p); - - /** - * finds the next token - */ - static - CBotToken* NextToken(char* &program, int& error, bool first = false); - - const CBotToken& - operator=(const CBotToken& src); - - static - void Free(); -}; - - /* //////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index 12529467..2b06c0ff 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -17,24 +17,21 @@ * along with this program. If not, see http://gnu.org/licenses */ - -////////////////////////////////////////////////////////////////// -// Managing Tokens -// the text of a program is first transformed -// into a sequence of tokens for easy interpretation -// it will only treat the case as an error -// where there is an illegal character in a string - - +// Modules inlcude #include "CBot.h" + +// Local include + +// Global include #include +//////////////////////////////////////////////////////////////////////////////// CBotStringArray CBotToken::m_ListKeyWords; int CBotToken::m_ListIdKeyWords[200]; CBotStringArray CBotToken::m_ListKeyDefine; long CBotToken::m_ListKeyNums[MAXDEFNUM]; -//! contructors +//////////////////////////////////////////////////////////////////////////////// CBotToken::CBotToken() { m_next = nullptr; @@ -43,6 +40,7 @@ CBotToken::CBotToken() m_IdKeyWord = -1; } +//////////////////////////////////////////////////////////////////////////////// CBotToken::CBotToken(const CBotToken* pSrc) { m_next = nullptr; @@ -71,6 +69,7 @@ CBotToken::CBotToken(const CBotToken* pSrc) } } +//////////////////////////////////////////////////////////////////////////////// CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, int end) { m_Text = mot; // word (mot) found as token @@ -95,17 +94,20 @@ CBotToken::CBotToken(const char* mot, const char* sep) m_IdKeyWord = -1; } +//////////////////////////////////////////////////////////////////////////////// CBotToken::~CBotToken() { delete m_next; // recursive m_next = nullptr; } +//////////////////////////////////////////////////////////////////////////////// void CBotToken::Free() { m_ListKeyDefine.SetSize(0); } +//////////////////////////////////////////////////////////////////////////////// const CBotToken& CBotToken::operator=(const CBotToken& src) { delete m_next; @@ -123,7 +125,7 @@ const CBotToken& CBotToken::operator=(const CBotToken& src) return *this; } - +//////////////////////////////////////////////////////////////////////////////// int CBotToken::GetType() { if (this == nullptr) return 0; @@ -131,69 +133,66 @@ int CBotToken::GetType() return m_type; } +//////////////////////////////////////////////////////////////////////////////// long CBotToken::GetIdKey() { return m_IdKeyWord; } +//////////////////////////////////////////////////////////////////////////////// CBotToken* CBotToken::GetNext() { if (this == nullptr) return nullptr; return m_next; } +//////////////////////////////////////////////////////////////////////////////// CBotToken* CBotToken::GetPrev() { if (this == nullptr) return nullptr; return m_prev; } -void CBotToken::AddNext(CBotToken* p) -{ - CBotToken* n = new CBotToken(p); - CBotToken* pt = this; - - while ( pt->m_next != nullptr ) pt = pt->m_next; - - pt->m_next = n; - n->m_prev = pt; -} - - -CBotString& CBotToken::GetString() +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotToken::GetString() { return m_Text; } -CBotString& CBotToken::GetSep() +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotToken::GetSep() { return m_Sep; } +//////////////////////////////////////////////////////////////////////////////// void CBotToken::SetString(const char* name) { m_Text = name; } - +//////////////////////////////////////////////////////////////////////////////// int CBotToken::GetStart() { if (this == nullptr) return -1; return m_start; } +//////////////////////////////////////////////////////////////////////////////// int CBotToken::GetEnd() { if (this == nullptr) return -1; return m_end; } +//////////////////////////////////////////////////////////////////////////////// void CBotToken::SetPos(int start, int end) { m_start = start; m_end = end; } +//////////////////////////////////////////////////////////////////////////////// bool CharInList(const char c, const char* list) { int i = 0; @@ -205,6 +204,7 @@ bool CharInList(const char c, const char* list) } } +//////////////////////////////////////////////////////////////////////////////// bool Char2InList(const char c, const char cc, const char* list) { int i = 0; @@ -225,11 +225,7 @@ static char num[] = "0123456789"; // point (single) i static char hexnum[] = "0123456789ABCDEFabcdef"; static char nch[] = "\"\r\n\t"; // forbidden in chains -//static char* duo = "+=-=*=/===!=<=>=++--///**/||&&"; // double operators - -// looking for the next token in a sentence -// do not start with separators -// which are made in the previous token +//////////////////////////////////////////////////////////////////////////////// CBotToken* CBotToken::NextToken(char* &program, int& error, bool first) { CBotString mot; // the word which is found @@ -389,6 +385,7 @@ bis: } } +//////////////////////////////////////////////////////////////////////////////// CBotToken* CBotToken::CompileTokens(const char* program, int& error) { CBotToken *nxt, *prv, *tokenbase; @@ -431,14 +428,13 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error) return tokenbase; } +//////////////////////////////////////////////////////////////////////////////// void CBotToken::Delete(CBotToken* pToken) { delete pToken; } - -// search if a word is part of the keywords - +//////////////////////////////////////////////////////////////////////////////// int CBotToken::GetKeyWords(const char* w) { int i; @@ -458,6 +454,7 @@ int CBotToken::GetKeyWords(const char* w) return -1; } +//////////////////////////////////////////////////////////////////////////////// bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) { int i; @@ -476,12 +473,7 @@ bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) return false; } - -/// \todo Fixme Figure out how this should work. - -// recreates the list of keywords and its IDs basing on some resources -// defines of TokenKey.. are in CBotDll.h - +//////////////////////////////////////////////////////////////////////////////// void CBotToken::LoadKeyWords() { CBotString s; @@ -517,6 +509,7 @@ void CBotToken::LoadKeyWords() } } +//////////////////////////////////////////////////////////////////////////////// bool CBotToken::DefineNum(const char* name, long val) { int i; @@ -533,6 +526,7 @@ bool CBotToken::DefineNum(const char* name, long val) return true; } +//////////////////////////////////////////////////////////////////////////////// bool IsOfType(CBotToken* &p, int type1, int type2) { if (p->GetType() == type1 || @@ -543,8 +537,8 @@ bool IsOfType(CBotToken* &p, int type1, int type2) } return false; } -// Same with any number of arguments -// There must be a zero as the last argument + +//////////////////////////////////////////////////////////////////////////////// bool IsOfTypeList(CBotToken* &p, int type1, ...) { int i = type1; diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index 3e0269ec..b82cdfea 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -17,28 +17,264 @@ * along with this program. If not, see http://gnu.org/licenses */ - -// interpreter of the lanuage CBot for game COLOBOT -// writing a program is first transformed into a list of tokens -// before tackling the compiler itself -// for example -// int var = 3 * ( pos.y + x ) -// is decomposed into (each line is a token) -// int -// var -// = -// 3 -// * -// ( -// pos.y -// + -// x -// ) - #pragma once -class CBotToken; +// Modules inlcude +#include "CBotDll.h" +// Local include + +// Global include + +///////////////////////////////////////////////////////////////////////////////////// +// Token management (tokens) + +#define TokenTypKeyWord 1 // a keyword of the language (see TokenKeyWord) +#define TokenTypNum 2 // number +#define TokenTypString 3 // string +#define TokenTypVar 4 // a variable name +#define TokenTypDef 5 // value according DefineNum + +#define TokenKeyWord 2000 // keywords of the language +#define TokenKeyDeclare 2100 // keywords of declarations (int, float,..) +#define TokenKeyVal 2200 // keywords representing the value (true, false, null, nan) +#define TokenKeyOp 2300 // operators + +#define MAXDEFNUM 1000 // limited number of DefineNum + +/** + * \class CBotToken + * Responsible for token management. A CBot program is a text string. This string + * is first transformed into a list of token. It will only treat the case as an + * error where there is an illegal character in a string. + * For example : + * int var = 3 * ( pos.y + x ) + * is decomposed into (each line is a token) + * int + * var + * = + * 3 + * * + * ( + * pos.y + * + + * x + * ) + */ + +class CBotToken +{ + +public: + + /*! + * \brief CBotToken Default Constructor. + */ + CBotToken(); + CBotToken(const CBotToken* pSrc); + CBotToken(const CBotString& mot, + const CBotString& sep, + int start=0, + int end=0); + CBotToken(const char* mot, const char* sep = nullptr); + + /*! + * \brief ~CBotToken Destructor. Be careful when you delete a CBotToken that + * is in a linked list all the following CBotToken will be deleted too. + */ + ~CBotToken(); + + /*! + * \brief GetType Return the token type or the keyword id. + * \return The token type or the keyword id. + */ + int GetType(); + + /*! + * \brief GetString Return the token string. + * \return The token string if a string has been set. An empty string + * otherwise. + */ + CBotString GetString(); + + /*! + * \brief SetString Set the token string. + * \param [in] name The new string to set. + */ + void SetString(const char* name); + + /*! + * \brief GetSep Return the token separator. + * \return The token separator a separator has been set. An empty separator + * otherwise. + */ + CBotString GetSep(); + + /*! + * \brief GetStart Return the start position of the string token in the + * original CBotProgram. + * \return The start position of the string token or -1 if no string has + * been set. + */ + int GetStart(); + + /*! + * \brief GetEnd Return the end position of the string token in the + * original CBotProgram. + * \return The start position of the string token or -1 if no string has + * been set. + */ + int GetEnd(); + + /*! + * \brief GetNext Gives the next CBotToken in the list. + * \return The next CBotToken if set nullptr otherwise. + */ + CBotToken* GetNext(); + + /*! + * \brief GetPrev Gives the previous CBotToken in the list. + * \return The previous CBotToken if set nullptr otherwise. + */ + CBotToken* GetPrev(); + + /*! + * \brief SetPos Set the token position in the CBot program. + * \param [in] start The start position of the token. + * \param [in] end The end position of the token. + */ + void SetPos(int start, int end); + + /*! + * \brief GetIdKey Get the token id key. + * \return The id key. + */ + long GetIdKey(); + + /*! + * \brief operator = + * \param [in] src The CBotToken to copy. + * \return The CBotToken with the copied value. + */ + const CBotToken& operator=(const CBotToken& src); + + /*! + * \brief CompileTokens This function will transform the entire CBot program + * in CBotToken. If an error occured during the processing an error number + * will be set. Each CBotToken will be linked with the previous one and the + * next one. + * \param [in] p The program string. + * \param [out] error The error code. + * \return The first token of the linked liste. + * \todo Replace the error code by an enum. + */ + static CBotToken* CompileTokens(const char* p, int& error); + + /*! + * \brief NextToken Looking for the next token in the string. The string must + * not start with separators. The separator is part of the previous token. + * \param [in] program The program string. + * \param [out] error The error code. + * \param [in] first True if this is the first call false othewise. + * \return A CBotTOken. + */ + static CBotToken* NextToken(char* &program, int& error, bool first = false); + + /** + * \brief Delete Releases the CBotToken linked list. + * \deprecated This function is deprecated because it only delete a pointer. + * \todo Remove this function. + */ + static void Delete(CBotToken* pToken); + + /*! + * \brief DefineNum This function define a language keyword with an associated + * number. + * \param [in] name The new word to define. + * \param [in] val The number associated with the keyword. + * \return Ture if the number is available false oterhwise. + */ + static bool DefineNum(const char* name, long val); + + /*! + * \brief Free Free the array created with DefineNum. + * \see DefineNum + */ + static void Free(); + +private: + + //! The next token in the linked list + CBotToken* m_next; // following in the list + //! The previous token in the linked list + CBotToken* m_prev; + //! The token type + int m_type; // type of Token + //! The id of the keyword + long m_IdKeyWord; + + //! The token string + CBotString m_Text; + //! The token separator + CBotString m_Sep; + + //! The strat position of the token in the CBotProgram + int m_start; + //! The end position of the token in the CBotProgram + int m_end; + + /*! + * \brief GetKeyWords Check if the word is a keyword. + * \param w The word to compare. + * \return -1 if this is not a keyword the keyword number otherwise. + */ + static int GetKeyWords(const char* w); // is it a keyword? + + /*! + * \brief GetKeyDefNum Check if this is a defined word and set the defined + * word type in a CBotToken. + * \param [in] w The word to compaire. + * \param [out] token The token in which the type will be set. + * \return True if the defined word is found false otherwise. + */ + static bool GetKeyDefNum(const char* w, CBotToken* &token); + + /*! + * \brief LoadKeyWords Loads the list of keywords. The list of keyword is + * CBotString::s_keywordString. This keywords are keywords languages (if, +, + * for, while, case, extern ...) + * \todo Fixme Figure out how this should work. + */ + static void LoadKeyWords(); + + //! List of keywords of the CBot language (if, +, for, while, case, extern ...) + static CBotStringArray m_ListKeyWords; + //! List of id correponding to the keywords of the CBot language + static int m_ListIdKeyWords[200]; + + //! List of CBot language error and list of colobot specific keywords + //! This keywords are defined in : + //! - void CScriptFunctions::Init() + //! - void CBotProgram::Init() + static CBotStringArray m_ListKeyDefine; + //! List of id correponding to the defined words + static long m_ListKeyNums[MAXDEFNUM]; + +}; + +/*! + * \brief IsOfType This function tell if a token is of a specific type. + * \param [in] p The token to compare. + * \param [in] type1 First token type to comapre to the token. + * \param [in] type2 Second token type to comapre to the token. + * \return True if the type of the token match one of a parameter. + */ extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1); -extern bool IsOfTypeList(CBotToken* &p, int type1, ...); +/*! + * \brief IsOfType This function tell if a token is of a specific type. + * \param [in] p The token to compare. + * \param [in] type1 The list of token type to comapre to the token. + * \return True if the type of the token match one of a parameter. + */ +extern bool IsOfTypeList(CBotToken* &p, int type1, ...); diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 8bb8a5cf..dc7707f7 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,15 +1,15 @@ set(SOURCES -CBot.cpp -CBotClass.cpp -CBotFunction.cpp -CBotIf.cpp -CBotProgram.cpp -CBotStack.cpp -CBotString.cpp -CBotToken.cpp -CBotTwoOpExpr.cpp -CBotVar.cpp -CBotWhile.cpp + CBot.cpp + CBotClass.cpp + CBotFunction.cpp + CBotIf.cpp + CBotProgram.cpp + CBotStack.cpp + CBotString.cpp + CBotToken.cpp + CBotTwoOpExpr.cpp + CBotVar.cpp + CBotWhile.cpp ) if(CBOT_STATIC) diff --git a/src/script/script.cpp b/src/script/script.cpp index 9bfb1dac..4ba1f173 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -42,6 +42,7 @@ #include "ui/controls/interface.h" #include "ui/controls/list.h" +#include "CBot/CBotToken.h" const int CBOT_IPF = 100; // CBOT: default number of instructions / frame From 573e1152e339f5d018464a473340980a3d8dbb8b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 18:11:42 +0100 Subject: [PATCH 055/360] Moving CBOT enumerated in a separate file called CBotEnum.h --- src/CBot/CBotDll.h | 33 +----------------------- src/CBot/CBotEnums.h | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 src/CBot/CBotEnums.h diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index dbeaf8f8..deec62cb 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -28,6 +28,7 @@ // Modules inlcude #include "resource.h" +#include "CBotEnums.h" // Local include @@ -59,29 +60,6 @@ class CBotCStack; // stack //////////////////////////////////////////////////////////////////////// // Variables management //////////////////////////////////////////////////////////////////////// - -/** \brief CBotType Defines known types. This types are modeled on Java types. Do not change the order of elements */ -enum CBotType -{ - CBotTypVoid = 0, - CBotTypByte = 1, //n - CBotTypShort = 2, //n - CBotTypChar = 3, //n - CBotTypInt = 4, - CBotTypLong = 5, //n - CBotTypFloat = 6, - CBotTypDouble = 7, //n - CBotTypBoolean = 8, - CBotTypString = 9, - - CBotTypArrayPointer = 10, // array of variables - CBotTypArrayBody = 11, // same but creates an instance - - CBotTypPointer = 12, // pointer to an instance - CBotTypNullPointer = 13, // null pointer is special - CBotTypClass = 15, - CBotTypIntrinsic = 16 // instance of a class intrinsic -}; //n = not implemented yet // for SetUserPtr when deleting an object @@ -462,15 +440,6 @@ public: CBotString& ElementAt(int nIndex); }; -// different modes for GetPosition -enum CBotGet -{ - GetPosExtern = 1, - GetPosNom = 2, - GetPosParam = 3, - GetPosBloc = 4 -}; - //////////////////////////////////////////////////////////////////// // main class managing CBot program // diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h new file mode 100644 index 00000000..524f00c1 --- /dev/null +++ b/src/CBot/CBotEnums.h @@ -0,0 +1,60 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + +/*! \brief CBotType Defines known types. This types are modeled on Java types. + * Do not change the order of elements + */ +enum CBotType +{ + CBotTypVoid = 0, + CBotTypByte = 1, //n + CBotTypShort = 2, //n + CBotTypChar = 3, //n + CBotTypInt = 4, + CBotTypLong = 5, //n + CBotTypFloat = 6, + CBotTypDouble = 7, //n + CBotTypBoolean = 8, + CBotTypString = 9, + + CBotTypArrayPointer = 10, // array of variables + CBotTypArrayBody = 11, // same but creates an instance + + CBotTypPointer = 12, // pointer to an instance + CBotTypNullPointer = 13, // null pointer is special + CBotTypClass = 15, + CBotTypIntrinsic = 16 // instance of a class intrinsic +}; + +//! \brief CBotGet Different modes for GetPosition. +enum CBotGet +{ + GetPosExtern = 1, + GetPosNom = 2, + GetPosParam = 3, + GetPosBloc = 4 +}; From 1694776ab62658b589df0f89ef4b8192b9b64802 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 18:29:02 +0100 Subject: [PATCH 056/360] Move CBotDo class in its own header and source files. --- src/CBot/CBot.cpp | 6 +- src/CBot/CBot.h | 16 ---- src/CBot/CBotInstr/CBotDo.cpp | 154 ++++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotDo.h | 73 ++++++++++++++++ src/CBot/CBotWhile.cpp | 134 ----------------------------- src/CBot/CMakeLists.txt | 9 ++ 6 files changed, 241 insertions(+), 151 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotDo.cpp create mode 100644 src/CBot/CBotInstr/CBotDo.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index f4727d33..375c1f39 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -34,9 +34,13 @@ // the error is then on the stack CBotCStack :: Isok () is false - +// Modules inlcude #include "CBot.h" +#include "CBotInstr/CBotDo.h" +// Local include + +// Global include #include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 6f37b8b5..60e1d88c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -483,22 +483,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotDo : public CBotInstr -{ -private: - CBotInstr* m_Block; // instruction - CBotInstr* m_Condition; // conditions - CBotString m_label; // a label if there is - -public: - CBotDo(); - ~CBotDo(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - class CBotFor : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp new file mode 100644 index 00000000..a24e5dbe --- /dev/null +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -0,0 +1,154 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotDo.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotDo::CBotDo() +{ + m_Condition = + m_Block = nullptr; // nullptr so that delete is not possible further + name = "CBotDo"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotDo::~CBotDo() +{ + delete m_Condition; // frees the condition + delete m_Block; // frees the instruction block +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotDo* inst = new CBotDo(); // creates the object + + CBotToken* pp = p; // preserves at the ^ token (starting position) + + if ( IsOfType( p, TokenTypVar ) && + IsOfType( p, ID_DOTS ) ) + { + inst->m_label = pp->GetString(); // register the name of label + } + + inst->SetToken(p); + if (!IsOfType(p, ID_DO)) return nullptr; // should never happen + + CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp + + + // looking for a statement block after the do + IncLvl(inst->m_label); + inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); + DecLvl(); + + if ( pStk->IsOk() ) + { + if (IsOfType(p, ID_WHILE)) + { + if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) ) + { + // the condition exists + if (IsOfType(p, ID_SEP)) + { + return pStack->Return(inst, pStk); // return an object to the application + } + pStk->SetError(TX_ENDOF, p->GetStart()); + } + } + pStk->SetError(TX_WHILE, p->GetStart()); + } + + delete inst; // error, frees up + return pStack->Return(nullptr, pStk); // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotDo :: Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); // adds an item to the stack + // or find in case of recovery +// if ( pile == EOX ) return true; + + if ( pile->IfStep() ) return false; + + while( true ) switch( pile->GetState() ) // executes the loop + { // there are two possible states (depending on recovery) + case 0: + // evaluates the associated statement block + if ( m_Block != nullptr && + !m_Block->Execute(pile) ) + { + if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test + return pj->BreakReturn(pile, m_label); // sends the results and releases the stack + } + + // terminates if there is an error + if ( !pile->IsOk() ) + { + return pj->Return(pile); // sends the results and releases the stack + } + + if (!pile->SetState(1)) return false; // ready for further + + case 1: + // evaluates the condition + if ( !m_Condition->Execute(pile) ) return false; // interrupted here ? + + // the result of the condition is on the stack + + // terminates if an error or if the condition is false + if ( !pile->IsOk() || pile->GetVal() != true ) + { + return pj->Return(pile); // sends the results and releases the stack + } + + // returns to instruction block to start + if (!pile->SetState(0, 0)) return false; + continue; + } +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotDo :: RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack + if ( pile == nullptr ) return; + + switch( pile->GetState() ) + { // there are two possible states (depending on recovery) + case 0: + // restores the assosiated statement's block + if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain); + return; + + case 1: + // restores the condition + m_Condition->RestoreState(pile, bMain); + return; + } +} diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h new file mode 100644 index 00000000..670a0701 --- /dev/null +++ b/src/CBot/CBotInstr/CBotDo.h @@ -0,0 +1,73 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +class CBotDo : public CBotInstr +{ +public: + + /*! + * \brief CBotDo Default constructor. + */ + CBotDo(); + + /*! + * \brief ~CBotDo Destructor. + */ + ~CBotDo(); + + /*! + * \brief Compile Compile the instruction "do". + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Instruction + CBotInstr* m_Block; + //! Conditions + CBotInstr* m_Condition; + //! A label if there is + CBotString m_label; +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 09cdc2cd..9a653482 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,140 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } - -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compile the instruction "do" - -CBotDo::CBotDo() -{ - m_Condition = - m_Block = nullptr; // nullptr so that delete is not possible further - name = "CBotDo"; // debug -} - -CBotDo::~CBotDo() -{ - delete m_Condition; // frees the condition - delete m_Block; // frees the instruction block -} - -CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotDo* inst = new CBotDo(); // creates the object - - CBotToken* pp = p; // preserves at the ^ token (starting position) - - if ( IsOfType( p, TokenTypVar ) && - IsOfType( p, ID_DOTS ) ) - { - inst->m_label = pp->GetString(); // register the name of label - } - - inst->SetToken(p); - if (!IsOfType(p, ID_DO)) return nullptr; // should never happen - - CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp - - - // looking for a statement block after the do - IncLvl(inst->m_label); - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); - DecLvl(); - - if ( pStk->IsOk() ) - { - if (IsOfType(p, ID_WHILE)) - { - if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) ) - { - // the condition exists - if (IsOfType(p, ID_SEP)) - { - return pStack->Return(inst, pStk); // return an object to the application - } - pStk->SetError(TX_ENDOF, p->GetStart()); - } - } - pStk->SetError(TX_WHILE, p->GetStart()); - } - - delete inst; // error, frees up - return pStack->Return(nullptr, pStk); // no object, the error is on the stack -} - -// executes instruction "do" - -bool CBotDo :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); // adds an item to the stack - // or find in case of recovery -// if ( pile == EOX ) return true; - - if ( pile->IfStep() ) return false; - - while( true ) switch( pile->GetState() ) // executes the loop - { // there are two possible states (depending on recovery) - case 0: - // evaluates the associated statement block - if ( m_Block != nullptr && - !m_Block->Execute(pile) ) - { - if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test - return pj->BreakReturn(pile, m_label); // sends the results and releases the stack - } - - // terminates if there is an error - if ( !pile->IsOk() ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - if (!pile->SetState(1)) return false; // ready for further - - case 1: - // evaluates the condition - if ( !m_Condition->Execute(pile) ) return false; // interrupted here ? - - // the result of the condition is on the stack - - // terminates if an error or if the condition is false - if ( !pile->IsOk() || pile->GetVal() != true ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - // returns to instruction block to start - if (!pile->SetState(0, 0)) return false; - continue; - } -} - -void CBotDo :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack - if ( pile == nullptr ) return; - - switch( pile->GetState() ) - { // there are two possible states (depending on recovery) - case 0: - // restores the assosiated statement's block - if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain); - return; - - case 1: - // restores the condition - m_Condition->RestoreState(pile, bMain); - return; - } -} - - -/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// // compiles instruction "for" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index dc7707f7..27c283a9 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -10,8 +10,17 @@ set(SOURCES CBotTwoOpExpr.cpp CBotVar.cpp CBotWhile.cpp + CBotInstr/CBotDo.cpp ) +# Includes +set(LOCAL_INCLUDES + ${CMAKE_CURRENT_SOURCE_DIR} +) + +include_directories(${LOCAL_INCLUDES}) + + if(CBOT_STATIC) add_library(CBot STATIC ${SOURCES}) else() From 981f41d8a337097fe45376248098c071bc7b7a3b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 18:44:36 +0100 Subject: [PATCH 057/360] Move CBotFor class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 18 --- src/CBot/CBotInstr/CBotFor.cpp | 208 +++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotFor.h | 81 +++++++++++++ src/CBot/CBotWhile.cpp | 184 ----------------------------- src/CBot/CMakeLists.txt | 1 + 6 files changed, 291 insertions(+), 202 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotFor.cpp create mode 100644 src/CBot/CBotInstr/CBotFor.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 375c1f39..dad1cccf 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -37,6 +37,7 @@ // Modules inlcude #include "CBot.h" #include "CBotInstr/CBotDo.h" +#include "CBotInstr/CBotFor.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 60e1d88c..37d18673 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -483,24 +483,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotFor : public CBotInstr -{ -private: - CBotInstr* m_Init; // initial intruction - CBotInstr* m_Test; // test condition - CBotInstr* m_Incr; // instruction for increment - CBotInstr* m_Block; // instructions - CBotString m_label; // a label if there is - -public: - CBotFor(); - ~CBotFor(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - class CBotBreak : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp new file mode 100644 index 00000000..f920f0e0 --- /dev/null +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -0,0 +1,208 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotFor.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotFor::CBotFor() +{ + m_Init = + m_Test = + m_Incr = + m_Block = nullptr; // nullptr so that delete is not possible further + name = "CBotFor"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotFor::~CBotFor() +{ + delete m_Init; + delete m_Test; + delete m_Incr; + delete m_Block; // frees the instruction block +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotFor* inst = new CBotFor(); // creates the object + CBotToken* pp = p; // preserves at the ^ token (starting position) + + if ( IsOfType( p, TokenTypVar ) && + IsOfType( p, ID_DOTS ) ) + { + inst->m_label = pp->GetString(); // register the name of label + } + + inst->SetToken(p); + if (!IsOfType(p, ID_FOR)) return nullptr; // should never happen + + if ( !IsOfType(p, ID_OPENPAR)) // missing parenthesis ? + { + pStack->SetError(TX_OPENPAR, p->GetStart()); + return nullptr; + } + + CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp + + // compiles instructions for initialization + inst->m_Init = CBotListExpression::Compile( p, pStk ); + if ( pStk->IsOk() ) + { + if ( !IsOfType(p, ID_SEP)) // lack the semicolon? + { + pStack->SetError(TX_OPENPAR, p->GetStart()); + delete inst; + return pStack->Return(nullptr, pStk); // no object, the error is on the stack + } + inst->m_Test = CBotBoolExpr::Compile( p, pStk ); + if ( pStk->IsOk() ) + { + if ( !IsOfType(p, ID_SEP)) // lack the semicolon? + { + pStack->SetError(TX_OPENPAR, p->GetStart()); + delete inst; + return pStack->Return(nullptr, pStk); // no object, the error is on the stack + } + inst->m_Incr = CBotListExpression::Compile( p, pStk ); + if ( pStk->IsOk() ) + { + if ( IsOfType(p, ID_CLOSEPAR)) // missing parenthesis ? + { + IncLvl(inst->m_label); + inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); + DecLvl(); + if ( pStk->IsOk() ) + return pStack->Return(inst, pStk);; + } + pStack->SetError(TX_CLOSEPAR, p->GetStart()); + } + } + } + + delete inst; // error, frees up + return pStack->Return(nullptr, pStk); // no object, the error is on the stack +} + +// execution of instruction "for" +//////////////////////////////////////////////////////////////////////////////// +bool CBotFor :: Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this, true); // adds an item to the stack (variables locales) + // or find in case of recovery +// if ( pile == EOX ) return true; + + if ( pile->IfStep() ) return false; + + while( true ) switch( pile->GetState() ) // executes the loop + { // there are four possible states (depending on recovery) + case 0: + // initialize + if ( m_Init != nullptr && + !m_Init->Execute(pile) ) return false; // interrupted here ? + if (!pile->SetState(1)) return false; // ready for further + + case 1: + // evaluates the condition + if ( m_Test != nullptr ) // no strings attached? -> True! + { + if (!m_Test->Execute(pile) ) return false; // interrupted here ? + + // the result of the condition is on the stack + + // terminates if an error or if the condition is false + if ( !pile->IsOk() || pile->GetVal() != true ) + { + return pj->Return(pile); // sends the results and releases the stack + } + } + + // la condition est vrai, passe à la suite + if (!pile->SetState(2)) return false; // ready for further + + case 2: + // evaluates the associated statement block + if ( m_Block != nullptr && + !m_Block->Execute(pile) ) + { + if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation + return pj->BreakReturn(pile, m_label); // sends the results and releases the stack + } + + // terminates if there is an error + if ( !pile->IsOk() ) + { + return pj->Return(pile); // sends the results and releases the stack + } + + if (!pile->SetState(3)) return false; // ready for further + + case 3: + // evalutate the incrementation + if ( m_Incr != nullptr && + !m_Incr->Execute(pile) ) return false; // interrupted here ? + + // returns to the test again + if (!pile->SetState(1, 0)) return false; // returns to the test + continue; + } +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotFor :: RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack (variables locales) + if ( pile == nullptr ) return; + + switch( pile->GetState() ) + { // there are four possible states (depending on recovery) + case 0: + // initialize + if ( m_Init != nullptr ) m_Init->RestoreState(pile, true); // interrupted here ! + return; + + case 1: + if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variables definitions + + // evaluates the condition + if ( m_Test != nullptr ) m_Test->RestoreState(pile, true); // interrupted here ! + return; + + case 2: + if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions + + // evaluates the associated statement block + if ( m_Block != nullptr ) m_Block->RestoreState(pile, true); + return; + + case 3: + if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions + + // evaluate the incrementation + if ( m_Incr != nullptr ) m_Incr->RestoreState(pile, true); // interrupted here ! + return; + } +} diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h new file mode 100644 index 00000000..01edc666 --- /dev/null +++ b/src/CBot/CBotInstr/CBotFor.h @@ -0,0 +1,81 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotFor class + */ +class CBotFor : public CBotInstr +{ +public: + + /*! + * \brief CBotFor + */ + CBotFor(); + + /*! + * \brief CBotFor + */ + ~CBotFor(); + + /*! + * \brief Compile Compiles instruction "for" + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! Initial intruction + CBotInstr* m_Init; + //! Test Condition + CBotInstr* m_Test; + //! instruction for increment + CBotInstr* m_Incr; + //! Instructions + CBotInstr* m_Block; + //! A label if there is + CBotString m_label; +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 9a653482..d58dc546 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,188 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "for" - -CBotFor::CBotFor() -{ - m_Init = - m_Test = - m_Incr = - m_Block = nullptr; // nullptr so that delete is not possible further - name = "CBotFor"; // debug -} - -CBotFor::~CBotFor() -{ - delete m_Init; - delete m_Test; - delete m_Incr; - delete m_Block; // frees the instruction block -} - -CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotFor* inst = new CBotFor(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - if ( IsOfType( p, TokenTypVar ) && - IsOfType( p, ID_DOTS ) ) - { - inst->m_label = pp->GetString(); // register the name of label - } - - inst->SetToken(p); - if (!IsOfType(p, ID_FOR)) return nullptr; // should never happen - - if ( !IsOfType(p, ID_OPENPAR)) // missing parenthesis ? - { - pStack->SetError(TX_OPENPAR, p->GetStart()); - return nullptr; - } - - CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp - - // compiles instructions for initialization - inst->m_Init = CBotListExpression::Compile( p, pStk ); - if ( pStk->IsOk() ) - { - if ( !IsOfType(p, ID_SEP)) // lack the semicolon? - { - pStack->SetError(TX_OPENPAR, p->GetStart()); - delete inst; - return pStack->Return(nullptr, pStk); // no object, the error is on the stack - } - inst->m_Test = CBotBoolExpr::Compile( p, pStk ); - if ( pStk->IsOk() ) - { - if ( !IsOfType(p, ID_SEP)) // lack the semicolon? - { - pStack->SetError(TX_OPENPAR, p->GetStart()); - delete inst; - return pStack->Return(nullptr, pStk); // no object, the error is on the stack - } - inst->m_Incr = CBotListExpression::Compile( p, pStk ); - if ( pStk->IsOk() ) - { - if ( IsOfType(p, ID_CLOSEPAR)) // missing parenthesis ? - { - IncLvl(inst->m_label); - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); - DecLvl(); - if ( pStk->IsOk() ) - return pStack->Return(inst, pStk);; - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - } - } - } - - delete inst; // error, frees up - return pStack->Return(nullptr, pStk); // no object, the error is on the stack -} - -// execution of instruction "for" - -bool CBotFor :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this, true); // adds an item to the stack (variables locales) - // or find in case of recovery -// if ( pile == EOX ) return true; - - if ( pile->IfStep() ) return false; - - while( true ) switch( pile->GetState() ) // executes the loop - { // there are four possible states (depending on recovery) - case 0: - // initialize - if ( m_Init != nullptr && - !m_Init->Execute(pile) ) return false; // interrupted here ? - if (!pile->SetState(1)) return false; // ready for further - - case 1: - // evaluates the condition - if ( m_Test != nullptr ) // no strings attached? -> True! - { - if (!m_Test->Execute(pile) ) return false; // interrupted here ? - - // the result of the condition is on the stack - - // terminates if an error or if the condition is false - if ( !pile->IsOk() || pile->GetVal() != true ) - { - return pj->Return(pile); // sends the results and releases the stack - } - } - - // la condition est vrai, passe à la suite - if (!pile->SetState(2)) return false; // ready for further - - case 2: - // evaluates the associated statement block - if ( m_Block != nullptr && - !m_Block->Execute(pile) ) - { - if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation - return pj->BreakReturn(pile, m_label); // sends the results and releases the stack - } - - // terminates if there is an error - if ( !pile->IsOk() ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - if (!pile->SetState(3)) return false; // ready for further - - case 3: - // evalutate the incrementation - if ( m_Incr != nullptr && - !m_Incr->Execute(pile) ) return false; // interrupted here ? - - // returns to the test again - if (!pile->SetState(1, 0)) return false; // returns to the test - continue; - } -} - -void CBotFor :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack (variables locales) - if ( pile == nullptr ) return; - - switch( pile->GetState() ) - { // there are four possible states (depending on recovery) - case 0: - // initialize - if ( m_Init != nullptr ) m_Init->RestoreState(pile, true); // interrupted here ! - return; - - case 1: - if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variables definitions - - // evaluates the condition - if ( m_Test != nullptr ) m_Test->RestoreState(pile, true); // interrupted here ! - return; - - case 2: - if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions - - // evaluates the associated statement block - if ( m_Block != nullptr ) m_Block->RestoreState(pile, true); - return; - - case 3: - if ( m_Init != nullptr ) m_Init->RestoreState(pile, false); // variable definitions - - // evaluate the incrementation - if ( m_Incr != nullptr ) m_Incr->RestoreState(pile, true); // interrupted here ! - return; - } -} - ////////////////////////////////////////////////////////////////////////////////////// // compiles a list of expressions // is used only in "for" statement @@ -434,8 +252,6 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain) } } -/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// // compiles instruction "switch" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 27c283a9..34782a01 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -11,6 +11,7 @@ set(SOURCES CBotVar.cpp CBotWhile.cpp CBotInstr/CBotDo.cpp + CBotInstr/CBotFor.cpp ) # Includes From dd6f6e29c227a3d5a348bbb7da2189535627c3f8 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 18:54:49 +0100 Subject: [PATCH 058/360] Moving CBotListExpression class in its own header and source files. --- src/CBot/CBot.h | 14 --- src/CBot/CBotInstr/CBotFor.cpp | 1 + src/CBot/CBotInstr/CBotListExpression.cpp | 123 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotListExpression.h | 72 +++++++++++++ src/CBot/CBotWhile.cpp | 95 ----------------- src/CBot/CMakeLists.txt | 1 + 6 files changed, 197 insertions(+), 109 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotListExpression.cpp create mode 100644 src/CBot/CBotInstr/CBotListExpression.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 37d18673..4d701326 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -835,20 +835,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotListExpression : public CBotInstr -{ -private: - CBotInstr* m_Expr; // the first expression to be evaluated - -public: - CBotListExpression(); - ~CBotListExpression(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - class CBotLogicExpr : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index f920f0e0..7dc07d4a 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotFor.h" +#include "CBotListExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp new file mode 100644 index 00000000..66f7eafc --- /dev/null +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -0,0 +1,123 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotListExpression.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +/// Seeks a declaration of variable or expression +static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack) +{ + CBotInstr* i = CBotInt::Compile( p, pStack, false, true ); // Is this a declaration of an integer? + if ( i== nullptr ) i = CBotFloat::Compile( p, pStack, false, true ); // or a real number? + if ( i== nullptr ) i = CBotBoolean::Compile( p, pStack, false, true ); // or a boolean? + if ( i== nullptr ) i = CBotIString::Compile( p, pStack, false, true ); // ar a string? + if ( i== nullptr ) i = CBotExpression::Compile( p, pStack ); // compiles an expression + return i; +} +//////////////////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////////////////// +CBotListExpression::CBotListExpression() +{ + m_Expr = nullptr; + name = "CBotListExpression"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotListExpression::~CBotListExpression() +{ + delete m_Expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotListExpression* inst = new CBotListExpression(); + + inst->m_Expr = CompileInstrOrDefVar( p, pStack ); // compile the first expression in a list + if (pStack->IsOk()) + { + while ( IsOfType(p, ID_COMMA) ) // more instructions? + { + CBotInstr* i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer? + inst->m_Expr->AddNext(i); // added after + if ( !pStack->IsOk() ) + { + delete inst; + return nullptr; // no object, the error is on the stack + } + } + return inst; + } + delete inst; + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotListExpression::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(); // essential + CBotInstr* p = m_Expr; // the first expression + + int state = pile->GetState(); + while (state-->0) p = p->GetNext(); // returns to the interrupted operation + + if ( p != nullptr ) while (true) + { + if ( !p->Execute(pile) ) return false; + p = p->GetNext(); + if ( p == nullptr ) break; + if (!pile->IncState()) return false; // ready for next + } + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + int state = 0x7000; + + if ( bMain ) + { + pile = pj->RestoreStack(); + if ( pile == nullptr ) return; + state = pile->GetState(); + } + + CBotInstr* p = m_Expr; // the first expression + + while (p != nullptr && state-->0) + { + p->RestoreState(pile, false); + p = p->GetNext(); // returns to the interrupted operation + } + + if ( p != nullptr ) + { + p->RestoreState(pile, bMain); + } +} diff --git a/src/CBot/CBotInstr/CBotListExpression.h b/src/CBot/CBotInstr/CBotListExpression.h new file mode 100644 index 00000000..c4e67115 --- /dev/null +++ b/src/CBot/CBotInstr/CBotListExpression.h @@ -0,0 +1,72 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotListExpression class. Compiles a list of expressions is used + * only in "for" statement in incrementing and intitialisation. + */ +class CBotListExpression : public CBotInstr +{ +public: + + /*! + * \brief CBotListExpression + */ + CBotListExpression(); + + /*! + * \brief CBotListExpression + */ + ~CBotListExpression(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! The first expression to be evaluated + CBotInstr* m_Expr; +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index d58dc546..a691c5a2 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,101 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } -////////////////////////////////////////////////////////////////////////////////////// -// compiles a list of expressions -// is used only in "for" statement -// in incrementing and intitialisation - -CBotListExpression::CBotListExpression() -{ - m_Expr = nullptr; - name = "CBotListExpression"; -} - -CBotListExpression::~CBotListExpression() -{ - delete m_Expr; -} - -// seeks a declaration of variable or expression - -static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack) -{ - CBotInstr* i = CBotInt::Compile( p, pStack, false, true ); // Is this a declaration of an integer? - if ( i== nullptr ) i = CBotFloat::Compile( p, pStack, false, true ); // or a real number? - if ( i== nullptr ) i = CBotBoolean::Compile( p, pStack, false, true ); // or a boolean? - if ( i== nullptr ) i = CBotIString::Compile( p, pStack, false, true ); // ar a string? - if ( i== nullptr ) i = CBotExpression::Compile( p, pStack ); // compiles an expression - return i; -} - -CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotListExpression* inst = new CBotListExpression(); - - inst->m_Expr = CompileInstrOrDefVar( p, pStack ); // compile the first expression in a list - if (pStack->IsOk()) - { - while ( IsOfType(p, ID_COMMA) ) // more instructions? - { - CBotInstr* i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer? - inst->m_Expr->AddNext(i); // added after - if ( !pStack->IsOk() ) - { - delete inst; - return nullptr; // no object, the error is on the stack - } - } - return inst; - } - delete inst; - return nullptr; -} - -bool CBotListExpression::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(); // essential - CBotInstr* p = m_Expr; // the first expression - - int state = pile->GetState(); - while (state-->0) p = p->GetNext(); // returns to the interrupted operation - - if ( p != nullptr ) while (true) - { - if ( !p->Execute(pile) ) return false; - p = p->GetNext(); - if ( p == nullptr ) break; - if (!pile->IncState()) return false; // ready for next - } - return pj->Return(pile); -} - -void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - int state = 0x7000; - - if ( bMain ) - { - pile = pj->RestoreStack(); - if ( pile == nullptr ) return; - state = pile->GetState(); - } - - CBotInstr* p = m_Expr; // the first expression - - while (p != nullptr && state-->0) - { - p->RestoreState(pile, false); - p = p->GetNext(); // returns to the interrupted operation - } - - if ( p != nullptr ) - { - p->RestoreState(pile, bMain); - } -} - /////////////////////////////////////////////////////////////////////////// // compiles instruction "switch" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 34782a01..030c4de5 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp + CBotInstr/CBotListExpression.cpp ) # Includes From 5629bce950470348f293e49250eb54299d80cfb4 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:04:49 +0100 Subject: [PATCH 059/360] Moving CBotSwitch class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 17 --- src/CBot/CBotInstr/CBotSwitch.cpp | 214 ++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotSwitch.h | 76 +++++++++++ src/CBot/CBotWhile.cpp | 188 -------------------------- src/CBot/CMakeLists.txt | 1 + 6 files changed, 292 insertions(+), 205 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotSwitch.cpp create mode 100644 src/CBot/CBotInstr/CBotSwitch.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index dad1cccf..97bcc776 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -38,6 +38,7 @@ #include "CBot.h" #include "CBotInstr/CBotDo.h" #include "CBotInstr/CBotFor.h" +#include "CBotInstr/CBotSwitch.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 4d701326..01a874db 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -511,23 +511,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -class CBotSwitch : public CBotInstr -{ -private: - CBotInstr* m_Value; // value to seek - CBotInstr* m_Block; // instructions - -public: - CBotSwitch(); - ~CBotSwitch(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - class CBotCase : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp new file mode 100644 index 00000000..f9510d9d --- /dev/null +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -0,0 +1,214 @@ + + +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotSwitch.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotSwitch::CBotSwitch() +{ + m_Value = + m_Block = nullptr; // nullptr so that delete is not possible further + name = "CBotSwitch"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotSwitch::~CBotSwitch() +{ + delete m_Value; // frees the value + delete m_Block; // frees the instruction block +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotSwitch* inst = new CBotSwitch(); // creates the object + CBotToken* pp = p; // preserves at the ^ token (starting position) + + inst->SetToken(p); + if (!IsOfType(p, ID_SWITCH)) return nullptr; // should never happen + + CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp + + if ( IsOfType(p, ID_OPENPAR ) ) + { + if ( nullptr != (inst->m_Value = CBotExpression::Compile( p, pStk )) ) + { + if ( pStk->GetType() < CBotTypLong ) + { + if ( IsOfType(p, ID_CLOSEPAR ) ) + { + if ( IsOfType(p, ID_OPBLK ) ) + { + IncLvl(); + + while( !IsOfType( p, ID_CLBLK ) ) + { + if ( p->GetType() == ID_CASE || p->GetType() == ID_DEFAULT) + { + CBotCStack* pStk2 = pStk->TokenStack(p); // un petit bout de pile svp + + CBotInstr* i = CBotCase::Compile( p, pStk2 ); + if (i == nullptr) + { + delete inst; + return pStack->Return(nullptr, pStk2); + } + delete pStk2; + if ( inst->m_Block == nullptr ) inst->m_Block = i; + else inst->m_Block->AddNext(i); + continue; + } + + if ( inst->m_Block == nullptr ) + { + pStk->SetError(TX_NOCASE, p->GetStart()); + delete inst; + return pStack->Return(nullptr, pStk); + } + + CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk, true ); + if ( !pStk->IsOk() ) + { + delete inst; + return pStack->Return(nullptr, pStk); + } + inst->m_Block->AddNext(i); + + if ( p == nullptr ) + { + pStk->SetError(TX_CLOSEBLK, -1); + delete inst; + return pStack->Return(nullptr, pStk); + } + } + DecLvl(); + + if ( inst->m_Block == nullptr ) + { + pStk->SetError(TX_NOCASE, p->GetStart()); + delete inst; + return pStack->Return(nullptr, pStk); + } + // the statement block is ok + return pStack->Return(inst, pStk); // return an object to the application + } + pStk->SetError( TX_OPENBLK, p->GetStart() ); + } + pStk->SetError( TX_CLOSEPAR, p->GetStart() ); + } + pStk->SetError( TX_BADTYPE, p->GetStart() ); + } + } + pStk->SetError( TX_OPENPAR, p->GetStart()); + + delete inst; // error, frees up + return pStack->Return(nullptr, pStk); // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotSwitch :: Execute(CBotStack* &pj) +{ + CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack +// if ( pile1 == EOX ) return true; + + CBotInstr* p = m_Block; // first expression + + int state = pile1->GetState(); + if (state == 0) + { + if ( !m_Value->Execute(pile1) ) return false; + pile1->SetState(state = -1); + } + + if ( pile1->IfStep() ) return false; + + if ( state == -1 ) + { + state = 0; + int val = pile1->GetVal(); // result of the value + + CBotStack* pile2 = pile1->AddStack(); + while ( p != nullptr ) // search for the corresponding case in a list + { + state++; + if ( p->CompCase( pile2, val ) ) break; // found the case + p = p->GetNext(); + } + pile2->Delete(); + + if ( p == nullptr ) return pj->Return(pile1); // completed if nothing + + if ( !pile1->SetState(state) ) return false; + } + + p = m_Block; // returns to the beginning + while (state-->0) p = p->GetNext(); // advance in the list + + while( p != nullptr ) + { + if ( !p->Execute(pile1) ) return pj->BreakReturn(pile1); + if ( !pile1->IncState() ) return false; + p = p->GetNext(); + } + return pj->Return(pile1); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack + if ( pile1 == nullptr ) return; + + CBotInstr* p = m_Block; // first expression + + int state = pile1->GetState(); + if (state == 0) + { + m_Value->RestoreState(pile1, bMain); + return; + } + + if ( state == -1 ) + { + return; + } + +// p = m_Block; // returns to the beginning + while ( p != nullptr && state-- > 0 ) + { + p->RestoreState(pile1, false); + p = p->GetNext(); // advance in the list + } + + if( p != nullptr ) + { + p->RestoreState(pile1, true); + return; + } +} diff --git a/src/CBot/CBotInstr/CBotSwitch.h b/src/CBot/CBotInstr/CBotSwitch.h new file mode 100644 index 00000000..c3f5e02c --- /dev/null +++ b/src/CBot/CBotInstr/CBotSwitch.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotSwitch class. Compiles instruction "switch" + */ +class CBotSwitch : public CBotInstr +{ +public: + + /*! + * \brief CBotSwitch + */ + CBotSwitch(); + + /*! + * \brief CBotSwitch + */ + ~CBotSwitch(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Executes instruction "switch". + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! Value to seek + CBotInstr* m_Value; + //! Instructions + CBotInstr* m_Block; + +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index a691c5a2..3f77dbe2 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,194 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "switch" - -CBotSwitch::CBotSwitch() -{ - m_Value = - m_Block = nullptr; // nullptr so that delete is not possible further - name = "CBotSwitch"; // debug -} - -CBotSwitch::~CBotSwitch() -{ - delete m_Value; // frees the value - delete m_Block; // frees the instruction block -} - - -CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotSwitch* inst = new CBotSwitch(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - inst->SetToken(p); - if (!IsOfType(p, ID_SWITCH)) return nullptr; // should never happen - - CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp - - if ( IsOfType(p, ID_OPENPAR ) ) - { - if ( nullptr != (inst->m_Value = CBotExpression::Compile( p, pStk )) ) - { - if ( pStk->GetType() < CBotTypLong ) - { - if ( IsOfType(p, ID_CLOSEPAR ) ) - { - if ( IsOfType(p, ID_OPBLK ) ) - { - IncLvl(); - - while( !IsOfType( p, ID_CLBLK ) ) - { - if ( p->GetType() == ID_CASE || p->GetType() == ID_DEFAULT) - { - CBotCStack* pStk2 = pStk->TokenStack(p); // un petit bout de pile svp - - CBotInstr* i = CBotCase::Compile( p, pStk2 ); - if (i == nullptr) - { - delete inst; - return pStack->Return(nullptr, pStk2); - } - delete pStk2; - if ( inst->m_Block == nullptr ) inst->m_Block = i; - else inst->m_Block->AddNext(i); - continue; - } - - if ( inst->m_Block == nullptr ) - { - pStk->SetError(TX_NOCASE, p->GetStart()); - delete inst; - return pStack->Return(nullptr, pStk); - } - - CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk, true ); - if ( !pStk->IsOk() ) - { - delete inst; - return pStack->Return(nullptr, pStk); - } - inst->m_Block->AddNext(i); - - if ( p == nullptr ) - { - pStk->SetError(TX_CLOSEBLK, -1); - delete inst; - return pStack->Return(nullptr, pStk); - } - } - DecLvl(); - - if ( inst->m_Block == nullptr ) - { - pStk->SetError(TX_NOCASE, p->GetStart()); - delete inst; - return pStack->Return(nullptr, pStk); - } - // the statement block is ok - return pStack->Return(inst, pStk); // return an object to the application - } - pStk->SetError( TX_OPENBLK, p->GetStart() ); - } - pStk->SetError( TX_CLOSEPAR, p->GetStart() ); - } - pStk->SetError( TX_BADTYPE, p->GetStart() ); - } - } - pStk->SetError( TX_OPENPAR, p->GetStart()); - - delete inst; // error, frees up - return pStack->Return(nullptr, pStk); // no object, the error is on the stack -} - -// executes instruction "switch" - -bool CBotSwitch :: Execute(CBotStack* &pj) -{ - CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack -// if ( pile1 == EOX ) return true; - - CBotInstr* p = m_Block; // first expression - - int state = pile1->GetState(); - if (state == 0) - { - if ( !m_Value->Execute(pile1) ) return false; - pile1->SetState(state = -1); - } - - if ( pile1->IfStep() ) return false; - - if ( state == -1 ) - { - state = 0; - int val = pile1->GetVal(); // result of the value - - CBotStack* pile2 = pile1->AddStack(); - while ( p != nullptr ) // search for the corresponding case in a list - { - state++; - if ( p->CompCase( pile2, val ) ) break; // found the case - p = p->GetNext(); - } - pile2->Delete(); - - if ( p == nullptr ) return pj->Return(pile1); // completed if nothing - - if ( !pile1->SetState(state) ) return false; - } - - p = m_Block; // returns to the beginning - while (state-->0) p = p->GetNext(); // advance in the list - - while( p != nullptr ) - { - if ( !p->Execute(pile1) ) return pj->BreakReturn(pile1); - if ( !pile1->IncState() ) return false; - p = p->GetNext(); - } - return pj->Return(pile1); -} - -void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack - if ( pile1 == nullptr ) return; - - CBotInstr* p = m_Block; // first expression - - int state = pile1->GetState(); - if (state == 0) - { - m_Value->RestoreState(pile1, bMain); - return; - } - - if ( state == -1 ) - { - return; - } - -// p = m_Block; // returns to the beginning - while ( p != nullptr && state-- > 0 ) - { - p->RestoreState(pile1, false); - p = p->GetNext(); // advance in the list - } - - if( p != nullptr ) - { - p->RestoreState(pile1, true); - return; - } -} - -/////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // compiles instruction "case" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 030c4de5..212a6dc3 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp CBotInstr/CBotListExpression.cpp + CBotInstr/CBotSwitch.cpp ) # Includes From 6d2fbf3ea4107ccdd6f80e8edae110ce3db189fb Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:12:03 +0100 Subject: [PATCH 060/360] Moving CBotCase class in its own header and source files. --- src/CBot/CBot.h | 15 ------ src/CBot/CBotInstr/CBotCase.cpp | 88 +++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotCase.h | 83 +++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotSwitch.cpp | 1 + src/CBot/CBotWhile.cpp | 70 ------------------------ src/CBot/CMakeLists.txt | 1 + 6 files changed, 173 insertions(+), 85 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotCase.cpp create mode 100644 src/CBot/CBotInstr/CBotCase.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 01a874db..45260f29 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -511,21 +511,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotCase : public CBotInstr -{ -private: - CBotInstr* m_Value; // value to compare - -public: - CBotCase(); - ~CBotCase(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; - bool CompCase(CBotStack* &pj, int val) override; -}; - class CBotCatch : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp new file mode 100644 index 00000000..ac311039 --- /dev/null +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -0,0 +1,88 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotCase.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotCase::CBotCase() +{ + m_Value = nullptr; // nullptr so that delete is not possible further + name = "CBotCase"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCase::~CBotCase() +{ + delete m_Value; // frees the value +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCase* inst = new CBotCase(); // creates the object + CBotToken* pp = p; // preserves at the ^ token (starting position) + + inst->SetToken(p); + if (!IsOfType(p, ID_CASE, ID_DEFAULT)) return nullptr; // should never happen + + if ( pp->GetType() == ID_CASE ) + { + pp = p; + inst->m_Value = CBotExprNum::Compile(p, pStack); + if ( inst->m_Value == nullptr ) + { + pStack->SetError( TX_BADNUM, pp ); + delete inst; + return nullptr; + } + } + if ( !IsOfType( p, ID_DOTS )) + { + pStack->SetError( TX_MISDOTS, p->GetStart() ); + delete inst; + return nullptr; + } + + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCase::Execute(CBotStack* &pj) +{ + return true; // the "case" statement does nothing! +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCase::RestoreState(CBotStack* &pj, bool bMain) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCase::CompCase(CBotStack* &pile, int val) +{ + if ( m_Value == nullptr ) return true; // "default" case + + while (!m_Value->Execute(pile)); // puts the value on the correspondent stack (without interruption) + return (pile->GetVal() == val); // compared with the given value +} diff --git a/src/CBot/CBotInstr/CBotCase.h b/src/CBot/CBotInstr/CBotCase.h new file mode 100644 index 00000000..9ba1b86f --- /dev/null +++ b/src/CBot/CBotInstr/CBotCase.h @@ -0,0 +1,83 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotCase class Compiles instruction "case" we are bound to the + * statement block "switch". + */ +class CBotCase : public CBotInstr +{ + +public: + + /*! + * \brief CBotCase + */ + CBotCase(); + + /*! + * \brief ~CBotCase + */ + ~CBotCase(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execution of instruction "case". + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + + /*! + * \brief CompCase Routine to find the entry point of "case" corresponding + * to the value seen. + * \param pj + * \param val + * \return + */ + bool CompCase(CBotStack* &pj, int val) override; + +private: + //! Value to compare. + CBotInstr* m_Value; +}; diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index f9510d9d..c0c79975 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -21,6 +21,7 @@ // Modules inlcude #include "CBotSwitch.h" +#include "CBotCase.h" // Local include diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 3f77dbe2..680dd716 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,76 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } - -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "case" -// we are bound to the statement block "switch" - -CBotCase::CBotCase() -{ - m_Value = nullptr; // nullptr so that delete is not possible further - name = "CBotCase"; // debug -} - -CBotCase::~CBotCase() -{ - delete m_Value; // frees the value -} - - -CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCase* inst = new CBotCase(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - inst->SetToken(p); - if (!IsOfType(p, ID_CASE, ID_DEFAULT)) return nullptr; // should never happen - - if ( pp->GetType() == ID_CASE ) - { - pp = p; - inst->m_Value = CBotExprNum::Compile(p, pStack); - if ( inst->m_Value == nullptr ) - { - pStack->SetError( TX_BADNUM, pp ); - delete inst; - return nullptr; - } - } - if ( !IsOfType( p, ID_DOTS )) - { - pStack->SetError( TX_MISDOTS, p->GetStart() ); - delete inst; - return nullptr; - } - - return inst; -} - -// execution of instruction "case" - -bool CBotCase::Execute(CBotStack* &pj) -{ - return true; // the "case" statement does nothing! -} - -void CBotCase::RestoreState(CBotStack* &pj, bool bMain) -{ -} - -// routine to find the entry point of "case" -// corresponding to the value seen - -bool CBotCase::CompCase(CBotStack* &pile, int val) -{ - if ( m_Value == nullptr ) return true; // "default" case - - while (!m_Value->Execute(pile)); // puts the value on the correspondent stack (without interruption) - return (pile->GetVal() == val); // compared with the given value -} - -/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// // compiles instruction "break" or "continu" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 212a6dc3..ac39e660 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -14,6 +14,7 @@ set(SOURCES CBotInstr/CBotFor.cpp CBotInstr/CBotListExpression.cpp CBotInstr/CBotSwitch.cpp + CBotInstr/CBotCase.cpp ) # Includes From 8da5c675a4e2cdff852bcbfcf1860f4ef0a4ce0c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:20:06 +0100 Subject: [PATCH 061/360] Moving CBotBreak class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 14 ----- src/CBot/CBotInstr/CBotBreak.cpp | 93 ++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotBreak.h | 75 ++++++++++++++++++++++++++ src/CBot/CBotWhile.cpp | 67 ----------------------- src/CBot/CMakeLists.txt | 1 + 6 files changed, 170 insertions(+), 81 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotBreak.cpp create mode 100644 src/CBot/CBotInstr/CBotBreak.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 97bcc776..9b1083e8 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -39,6 +39,7 @@ #include "CBotInstr/CBotDo.h" #include "CBotInstr/CBotFor.h" #include "CBotInstr/CBotSwitch.h" +#include "CBotInstr/CBotBreak.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 45260f29..cb337af9 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -483,20 +483,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotBreak : public CBotInstr -{ -private: - CBotString m_label; // a label if there is - -public: - CBotBreak(); - ~CBotBreak(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - class CBotReturn : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp new file mode 100644 index 00000000..06f53ae2 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -0,0 +1,93 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotBreak.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotBreak::CBotBreak() +{ + name = "CBotBreak"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotBreak::~CBotBreak() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; // preserves at the ^ token (starting position) + int type = p->GetType(); + + if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen + + if ( !ChkLvl(CBotString(), type ) ) + { + pStack->SetError(TX_BREAK, pp); + return nullptr; // no object, the error is on the stack + } + + CBotBreak* inst = new CBotBreak(); // creates the object + inst->SetToken(pp); // keeps the operation + + pp = p; + if ( IsOfType( p, TokenTypVar ) ) + { + inst->m_label = pp->GetString(); // register the name of label + if ( !ChkLvl(inst->m_label, type ) ) + { + delete inst; + pStack->SetError(TX_NOLABEL, pp); + return nullptr; // no object, the error is on the stack + } + } + + if (IsOfType(p, ID_SEP)) + { + return inst; // return what it wants + } + delete inst; + + pStack->SetError(TX_ENDOF, p->GetStart()); + return nullptr; // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotBreak :: Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; + + if ( pile->IfStep() ) return false; + + pile->SetBreak(m_token.GetType()==ID_BREAK ? 1 : 2, m_label); + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotBreak :: RestoreState(CBotStack* &pj, bool bMain) +{ + if ( bMain ) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h new file mode 100644 index 00000000..0ad39408 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBreak.h @@ -0,0 +1,75 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotBreak class Compiles instruction "break" or "continu". + */ +class CBotBreak : public CBotInstr +{ + +public: + + /*! + * \brief CBotBreak + */ + CBotBreak(); + + /*! + * \brief CBotBreak + */ + ~CBotBreak(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execution of statement "break" or "continu" + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + + +private: + //! A label if there is + CBotString m_label; + +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 680dd716..42b024b1 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,73 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "break" or "continu" - -CBotBreak::CBotBreak() -{ - name = "CBotBreak"; // debug -} - -CBotBreak::~CBotBreak() -{ -} - -CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; // preserves at the ^ token (starting position) - int type = p->GetType(); - - if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen - - if ( !ChkLvl(CBotString(), type ) ) - { - pStack->SetError(TX_BREAK, pp); - return nullptr; // no object, the error is on the stack - } - - CBotBreak* inst = new CBotBreak(); // creates the object - inst->SetToken(pp); // keeps the operation - - pp = p; - if ( IsOfType( p, TokenTypVar ) ) - { - inst->m_label = pp->GetString(); // register the name of label - if ( !ChkLvl(inst->m_label, type ) ) - { - delete inst; - pStack->SetError(TX_NOLABEL, pp); - return nullptr; // no object, the error is on the stack - } - } - - if (IsOfType(p, ID_SEP)) - { - return inst; // return what it wants - } - delete inst; - - pStack->SetError(TX_ENDOF, p->GetStart()); - return nullptr; // no object, the error is on the stack -} - -// execution of statement "break" or "continu" - -bool CBotBreak :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - - if ( pile->IfStep() ) return false; - - pile->SetBreak(m_token.GetType()==ID_BREAK ? 1 : 2, m_label); - return pj->Return(pile); -} - -void CBotBreak :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( bMain ) pj->RestoreStack(this); -} /////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index ac39e660..07564cb6 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -15,6 +15,7 @@ set(SOURCES CBotInstr/CBotListExpression.cpp CBotInstr/CBotSwitch.cpp CBotInstr/CBotCase.cpp + CBotInstr/CBotBreak.cpp ) # Includes From 179ca18c584db0d63f9e9204ba1fb4d9c837e2f5 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:27:58 +0100 Subject: [PATCH 062/360] Moving CBotTry class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 16 --- src/CBot/CBotInstr/CBotTry.cpp | 223 +++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotTry.h | 76 +++++++++++ src/CBot/CBotWhile.cpp | 206 ------------------------------ src/CBot/CMakeLists.txt | 1 + 6 files changed, 301 insertions(+), 222 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotTry.cpp create mode 100644 src/CBot/CBotInstr/CBotTry.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 9b1083e8..b46a29db 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -40,6 +40,7 @@ #include "CBotInstr/CBotFor.h" #include "CBotInstr/CBotSwitch.h" #include "CBotInstr/CBotBreak.h" +#include "CBotInstr/CBotTry.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index cb337af9..901edad8 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -516,22 +516,6 @@ public: void RestoreCondState(CBotStack* &pj, bool bMain); }; -class CBotTry : public CBotInstr -{ -private: - CBotInstr* m_Block; // instructions - CBotCatch* m_ListCatch; // catches - CBotInstr* m_FinalInst; // final instruction - -public: - CBotTry(); - ~CBotTry(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - class CBotThrow : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp new file mode 100644 index 00000000..c2b2901a --- /dev/null +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -0,0 +1,223 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotTry.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotTry::CBotTry() +{ + m_ListCatch = nullptr; + m_FinalInst = + m_Block = nullptr; // nullptr so that delete is not possible further + name = "CBotTry"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTry::~CBotTry() +{ + delete m_ListCatch; // frees the list + delete m_Block; // frees the instruction block + delete m_FinalInst; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotTry* inst = new CBotTry(); // creates the object + CBotToken* pp = p; // preserves at the ^ token (starting position) + + inst->SetToken(p); + if (!IsOfType(p, ID_TRY)) return nullptr; // should never happen + + CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp + + inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk ); + CBotCatch** pn = &inst->m_ListCatch; + + while (pStk->IsOk() && p->GetType() == ID_CATCH) + { + CBotCatch* i = CBotCatch::Compile(p, pStk); + *pn = i; + pn = &i->m_next; + } + + if (pStk->IsOk() && IsOfType( p, ID_FINALLY) ) + { + inst->m_FinalInst = CBotBlock::CompileBlkOrInst( p, pStk ); + } + + if (pStk->IsOk()) + { + return pStack->Return(inst, pStk); // return an object to the application + } + + delete inst; // error, frees up + return pStack->Return(nullptr, pStk); // no object, the error is on the stack +} + + +//////////////////////////////////////////////////////////////////////////////// +bool CBotTry::Execute(CBotStack* &pj) +{ + int val; + + CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack +// if ( pile1 == EOX ) return true; + + if ( pile1->IfStep() ) return false; + // or find in case of recovery + CBotStack* pile0 = pj->AddStack2(); // adds an element to the secondary stack + CBotStack* pile2 = pile0->AddStack(); + + if ( pile1->GetState() == 0 ) + { + if ( m_Block->Execute(pile1) ) + { + if ( m_FinalInst == nullptr ) return pj->Return(pile1); + pile1->SetState(-2); // passes final + } + + val = pile1->GetError(); + if ( val == 0 && CBotStack::m_initimer == 0 ) // mode step? + return false; // does not make the catch + + pile1->IncState(); + pile2->SetState(val); // stores the error number + pile1->SetError(0); // for now there is are more errors! + + if ( val == 0 && CBotStack::m_initimer < 0 ) // mode step? + return false; // does not make the catch + } + + // there was an interruption + // see what it returns + + CBotCatch* pc = m_ListCatch; + int state = static_cast(pile1->GetState()); // where were we? + val = pile2->GetState(); // what error? + pile0->SetState(1); // marking the GetRunPos + + if ( val >= 0 && state > 0 ) while ( pc != nullptr ) + { + if ( --state <= 0 ) + { + // request to the catch block if they feel concerned + // demande au bloc catch s'il se sent concerné + if ( !pc->TestCatch(pile2, val) ) return false; // suspend ! + pile1->IncState(); + } + if ( --state <= 0 ) + { + if ( pile2->GetVal() == true ) + { +// pile0->SetState(1); + + if ( !pc->Execute(pile2) ) return false; // performs the operation + if ( m_FinalInst == nullptr ) + return pj->Return(pile2); // ends the try + + pile1->SetState(-2); // passes final + break; + } + pile1->IncState(); + } + pc = pc->m_next; + } + if ( m_FinalInst != nullptr && + pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final + + if (pile1->GetState() <= -1) + { +// pile0->SetState(1); + + if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false; + if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception + pile2->SetError(pile1->GetState()==-1 ? val : 0); // gives the initial error + return pj->Return(pile2); + } + + pile1->SetState(0); // returns to the evaluation + pile0->SetState(0); // returns to the evaluation + if ( val != 0 && m_ListCatch == nullptr && m_FinalInst == nullptr ) + return pj->Return(pile2); // ends the try without exception + + pile1->SetError(val); // gives the error + return false; // it's not for us +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTry::RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + int val; + CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack + if ( pile1 == nullptr ) return; + // or find in case of recovery + CBotStack* pile0 = pj->AddStack2(); // adds an item to the secondary stack + if ( pile0 == nullptr ) return; + + CBotStack* pile2 = pile0->RestoreStack(); + if ( pile2 == nullptr ) return; + + m_Block->RestoreState(pile1, bMain); + if ( pile0->GetState() == 0 ) + { + return; + } + + // there was an interruption + // see what it returns + + CBotCatch* pc = m_ListCatch; + int state = pile1->GetState(); // where were we ? + val = pile2->GetState(); // what error ? + + if ( val >= 0 && state > 0 ) while ( pc != nullptr ) + { + if ( --state <= 0 ) + { + // request to the catch block if they feel concerned + // demande au bloc catch s'il se sent concerné + pc->RestoreCondState(pile2, bMain); // suspend ! + return; + } + if ( --state <= 0 ) + { + if ( pile2->GetVal() == true ) + { + pc->RestoreState(pile2, bMain); // execute the operation + return; + } + } + pc = pc->m_next; + } + + if (pile1->GetState() <= -1) + { + m_FinalInst->RestoreState(pile2, bMain); + return; + } +} diff --git a/src/CBot/CBotInstr/CBotTry.h b/src/CBot/CBotInstr/CBotTry.h new file mode 100644 index 00000000..f12de20f --- /dev/null +++ b/src/CBot/CBotInstr/CBotTry.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotTry class Compiles instruction "try" + */ +class CBotTry : public CBotInstr +{ +public: + + /*! + * \brief CBotTry + */ + CBotTry(); + + /*! + * \brief ~CBotTry + */ + ~CBotTry(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execution of instruction Try manages the return of + * exceptions stops (judgements) by suspension and "finally" + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Instructions + CBotInstr* m_Block; + //! Catches + CBotCatch* m_ListCatch; + //! Final instruction + CBotInstr* m_FinalInst; + +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 42b024b1..c3084be3 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,212 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } - - -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "try" - -CBotTry::CBotTry() -{ - m_ListCatch = nullptr; - m_FinalInst = - m_Block = nullptr; // nullptr so that delete is not possible further - name = "CBotTry"; // debug -} - -CBotTry::~CBotTry() -{ - delete m_ListCatch; // frees the list - delete m_Block; // frees the instruction block - delete m_FinalInst; -} - -CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotTry* inst = new CBotTry(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - inst->SetToken(p); - if (!IsOfType(p, ID_TRY)) return nullptr; // should never happen - - CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp - - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk ); - CBotCatch** pn = &inst->m_ListCatch; - - while (pStk->IsOk() && p->GetType() == ID_CATCH) - { - CBotCatch* i = CBotCatch::Compile(p, pStk); - *pn = i; - pn = &i->m_next; - } - - if (pStk->IsOk() && IsOfType( p, ID_FINALLY) ) - { - inst->m_FinalInst = CBotBlock::CompileBlkOrInst( p, pStk ); - } - - if (pStk->IsOk()) - { - return pStack->Return(inst, pStk); // return an object to the application - } - - delete inst; // error, frees up - return pStack->Return(nullptr, pStk); // no object, the error is on the stack -} - -// execution of instruction Try -// manages the return of exceptions -// stops (judgements) by suspension -// and "finally" - -bool CBotTry :: Execute(CBotStack* &pj) -{ - int val; - - CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack -// if ( pile1 == EOX ) return true; - - if ( pile1->IfStep() ) return false; - // or find in case of recovery - CBotStack* pile0 = pj->AddStack2(); // adds an element to the secondary stack - CBotStack* pile2 = pile0->AddStack(); - - if ( pile1->GetState() == 0 ) - { - if ( m_Block->Execute(pile1) ) - { - if ( m_FinalInst == nullptr ) return pj->Return(pile1); - pile1->SetState(-2); // passes final - } - - val = pile1->GetError(); - if ( val == 0 && CBotStack::m_initimer == 0 ) // mode step? - return false; // does not make the catch - - pile1->IncState(); - pile2->SetState(val); // stores the error number - pile1->SetError(0); // for now there is are more errors! - - if ( val == 0 && CBotStack::m_initimer < 0 ) // mode step? - return false; // does not make the catch - } - - // there was an interruption - // see what it returns - - CBotCatch* pc = m_ListCatch; - int state = static_cast(pile1->GetState()); // where were we? - val = pile2->GetState(); // what error? - pile0->SetState(1); // marking the GetRunPos - - if ( val >= 0 && state > 0 ) while ( pc != nullptr ) - { - if ( --state <= 0 ) - { - // request to the catch block if they feel concerned - // demande au bloc catch s'il se sent concerné - if ( !pc->TestCatch(pile2, val) ) return false; // suspend ! - pile1->IncState(); - } - if ( --state <= 0 ) - { - if ( pile2->GetVal() == true ) - { -// pile0->SetState(1); - - if ( !pc->Execute(pile2) ) return false; // performs the operation - if ( m_FinalInst == nullptr ) - return pj->Return(pile2); // ends the try - - pile1->SetState(-2); // passes final - break; - } - pile1->IncState(); - } - pc = pc->m_next; - } - if ( m_FinalInst != nullptr && - pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final - - if (pile1->GetState() <= -1) - { -// pile0->SetState(1); - - if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false; - if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception - pile2->SetError(pile1->GetState()==-1 ? val : 0); // gives the initial error - return pj->Return(pile2); - } - - pile1->SetState(0); // returns to the evaluation - pile0->SetState(0); // returns to the evaluation - if ( val != 0 && m_ListCatch == nullptr && m_FinalInst == nullptr ) - return pj->Return(pile2); // ends the try without exception - - pile1->SetError(val); // gives the error - return false; // it's not for us -} - - -void CBotTry :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - int val; - CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack - if ( pile1 == nullptr ) return; - // or find in case of recovery - CBotStack* pile0 = pj->AddStack2(); // adds an item to the secondary stack - if ( pile0 == nullptr ) return; - - CBotStack* pile2 = pile0->RestoreStack(); - if ( pile2 == nullptr ) return; - - m_Block->RestoreState(pile1, bMain); - if ( pile0->GetState() == 0 ) - { - return; - } - - // there was an interruption - // see what it returns - - CBotCatch* pc = m_ListCatch; - int state = pile1->GetState(); // where were we ? - val = pile2->GetState(); // what error ? - - if ( val >= 0 && state > 0 ) while ( pc != nullptr ) - { - if ( --state <= 0 ) - { - // request to the catch block if they feel concerned - // demande au bloc catch s'il se sent concerné - pc->RestoreCondState(pile2, bMain); // suspend ! - return; - } - if ( --state <= 0 ) - { - if ( pile2->GetVal() == true ) - { - pc->RestoreState(pile2, bMain); // execute the operation - return; - } - } - pc = pc->m_next; - } - - if (pile1->GetState() <= -1) - { - m_FinalInst->RestoreState(pile2, bMain); - return; - } -} - -/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// // compiles instruction "catch" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 07564cb6..3d1244d6 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -16,6 +16,7 @@ set(SOURCES CBotInstr/CBotSwitch.cpp CBotInstr/CBotCase.cpp CBotInstr/CBotBreak.cpp + CBotInstr/CBotTry.cpp ) # Includes From 18739d135bac873783980a4acb7c29bd98030ec3 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:44:56 +0100 Subject: [PATCH 063/360] Moving CBotCatch class in its own header and source files. --- src/CBot/CBot.h | 19 ------ src/CBot/CBotInstr/CBotCatch.cpp | 107 +++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotCatch.h | 93 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotTry.h | 1 + src/CBot/CBotWhile.cpp | 84 ------------------------ src/CBot/CMakeLists.txt | 1 + 6 files changed, 202 insertions(+), 103 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotCatch.cpp create mode 100644 src/CBot/CBotInstr/CBotCatch.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 901edad8..baebe04c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -497,25 +497,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotCatch : public CBotInstr -{ -private: - CBotInstr* m_Block; // instructions - CBotInstr* m_Cond; //condition - CBotCatch* m_next; //following catch - friend class CBotTry; - -public: - CBotCatch(); - ~CBotCatch(); - static - CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack); - bool TestCatch(CBotStack* &pj, int val); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; - void RestoreCondState(CBotStack* &pj, bool bMain); -}; - class CBotThrow : public CBotInstr { private: diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp new file mode 100644 index 00000000..4c63e029 --- /dev/null +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -0,0 +1,107 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotCatch.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotCatch::CBotCatch() +{ + m_Cond = + m_Block = nullptr; // nullptr so that delete is not possible further + m_next = nullptr; + + name = "CBotCatch"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCatch::~CBotCatch() +{ + delete m_Cond; // frees the list + delete m_Block; // frees the instruction block + delete m_next; // and subsequent +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCatch* inst = new CBotCatch(); // creates the object + pStack->SetStartError(p->GetStart()); + + inst->SetToken(p); + if (!IsOfType(p, ID_CATCH)) return nullptr; // should never happen + + if (IsOfType(p, ID_OPENPAR)) + { + inst->m_Cond = CBotExpression::Compile(p, pStack); + if (( pStack->GetType() < CBotTypLong || + pStack->GetTypResult().Eq(CBotTypBoolean) )&& pStack->IsOk() ) + { + if (IsOfType(p, ID_CLOSEPAR)) + { + inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStack ); + if ( pStack->IsOk() ) + return inst; // return an object to the application + } + pStack->SetError(TX_CLOSEPAR, p->GetStart()); + } + pStack->SetError(TX_BADTYPE, p->GetStart()); + } + pStack->SetError(TX_OPENPAR, p->GetStart()); + delete inst; // error, frees up + return nullptr; // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCatch :: Execute(CBotStack* &pj) +{ + if ( m_Block == nullptr ) return true; + return m_Block->Execute(pj); // executes the associated block +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCatch :: RestoreState(CBotStack* &pj, bool bMain) +{ + if ( bMain && m_Block != nullptr ) m_Block->RestoreState(pj, bMain); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCatch :: RestoreCondState(CBotStack* &pj, bool bMain) +{ + m_Cond->RestoreState(pj, bMain); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCatch :: TestCatch(CBotStack* &pile, int val) +{ + if ( !m_Cond->Execute(pile) ) return false; + + if ( val > 0 || pile->GetType() != CBotTypBoolean ) + { + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); + var->SetValInt( pile->GetVal() == val ); + pile->SetVar(var); // calls on the stack + } + + return true; +} diff --git a/src/CBot/CBotInstr/CBotCatch.h b/src/CBot/CBotInstr/CBotCatch.h new file mode 100644 index 00000000..9756c8b8 --- /dev/null +++ b/src/CBot/CBotInstr/CBotCatch.h @@ -0,0 +1,93 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotCatch class. Compiles instruction "catch". + */ +class CBotCatch : public CBotInstr +{ +public: + + /*! + * \brief CBotCatch + */ + CBotCatch(); + + /*! + * \brief CBotCatch + */ + ~CBotCatch(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief TestCatch Routine to see if the catch is to do or not. + * \param pj + * \param val + * \return + */ + bool TestCatch(CBotStack* &pj, int val); + + /*! + * \brief Execute Execution of "catch". + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + + /*! + * \brief RestoreCondState + * \param pj + * \param bMain + */ + void RestoreCondState(CBotStack* &pj, bool bMain); + + +private: + //! Instructions + CBotInstr* m_Block; + //! Condition + CBotInstr* m_Cond; + //! Following catch + CBotCatch* m_next; + + friend class CBotTry; +}; diff --git a/src/CBot/CBotInstr/CBotTry.h b/src/CBot/CBotInstr/CBotTry.h index f12de20f..0a8d2b9a 100644 --- a/src/CBot/CBotInstr/CBotTry.h +++ b/src/CBot/CBotInstr/CBotTry.h @@ -19,6 +19,7 @@ // Modules inlcude #include "CBot.h" +#include "CBotCatch.h" // Local include diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index c3084be3..89647e2a 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -157,90 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } } -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "catch" - -CBotCatch::CBotCatch() -{ - m_Cond = - m_Block = nullptr; // nullptr so that delete is not possible further - m_next = nullptr; - - name = "CBotCatch"; // debug -} - -CBotCatch::~CBotCatch() -{ - delete m_Cond; // frees the list - delete m_Block; // frees the instruction block - delete m_next; // and subsequent -} - -CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCatch* inst = new CBotCatch(); // creates the object - pStack->SetStartError(p->GetStart()); - - inst->SetToken(p); - if (!IsOfType(p, ID_CATCH)) return nullptr; // should never happen - - if (IsOfType(p, ID_OPENPAR)) - { - inst->m_Cond = CBotExpression::Compile(p, pStack); - if (( pStack->GetType() < CBotTypLong || - pStack->GetTypResult().Eq(CBotTypBoolean) )&& pStack->IsOk() ) - { - if (IsOfType(p, ID_CLOSEPAR)) - { - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStack ); - if ( pStack->IsOk() ) - return inst; // return an object to the application - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - } - pStack->SetError(TX_BADTYPE, p->GetStart()); - } - pStack->SetError(TX_OPENPAR, p->GetStart()); - delete inst; // error, frees up - return nullptr; // no object, the error is on the stack -} - -// execution of "catch" - -bool CBotCatch :: Execute(CBotStack* &pj) -{ - if ( m_Block == nullptr ) return true; - return m_Block->Execute(pj); // executes the associated block -} - -void CBotCatch :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( bMain && m_Block != nullptr ) m_Block->RestoreState(pj, bMain); -} - -void CBotCatch :: RestoreCondState(CBotStack* &pj, bool bMain) -{ - m_Cond->RestoreState(pj, bMain); -} - -// routine to see if the catch is to do or not - -bool CBotCatch :: TestCatch(CBotStack* &pile, int val) -{ - if ( !m_Cond->Execute(pile) ) return false; - - if ( val > 0 || pile->GetType() != CBotTypBoolean ) - { - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); - var->SetValInt( pile->GetVal() == val ); - pile->SetVar(var); // calls on the stack - } - - return true; -} - -/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// // compiles instruction "throw" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 3d1244d6..cd17d7ba 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -17,6 +17,7 @@ set(SOURCES CBotInstr/CBotCase.cpp CBotInstr/CBotBreak.cpp CBotInstr/CBotTry.cpp + CBotInstr/CBotCatch.cpp ) # Includes From a80245b012b8a85e5d01a6eb80d732f03fa2dd43 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 19:53:30 +0100 Subject: [PATCH 064/360] Moving CBotThrow class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 13 ----- src/CBot/CBotInstr/CBotThrow.cpp | 99 ++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotThrow.h | 73 +++++++++++++++++++++++ src/CBot/CBotWhile.cpp | 75 ------------------------ src/CBot/CMakeLists.txt | 1 + 6 files changed, 174 insertions(+), 88 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotThrow.cpp create mode 100644 src/CBot/CBotInstr/CBotThrow.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index b46a29db..6fda6766 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -41,6 +41,7 @@ #include "CBotInstr/CBotSwitch.h" #include "CBotInstr/CBotBreak.h" #include "CBotInstr/CBotTry.h" +#include "CBotInstr/CBotThrow.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index baebe04c..c331ff4d 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -497,19 +497,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotThrow : public CBotInstr -{ -private: - CBotInstr* m_Value; // the value to send - -public: - CBotThrow(); - ~CBotThrow(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; class CBotIf : public CBotInstr diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp new file mode 100644 index 00000000..14e61f07 --- /dev/null +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -0,0 +1,99 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotThrow.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotThrow::CBotThrow() +{ + m_Value = nullptr; // nullptr so that delete is not possible further + + name = "CBotThrow"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotThrow::~CBotThrow() +{ + delete m_Value; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack) +{ + pStack->SetStartError(p->GetStart()); + + CBotThrow* inst = new CBotThrow(); // creates the object + inst->SetToken(p); + + CBotToken* pp = p; // preserves at the ^ token (starting position) + + if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen + + inst->m_Value = CBotExpression::Compile( p, pStack ); + + if (pStack->GetType() < CBotTypLong && pStack->IsOk()) + { + return inst; // return an object to the application + } + pStack->SetError(TX_BADTYPE, pp); + + delete inst; // error, frees up + return nullptr; // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotThrow::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; + + if ( pile->GetState() == 0 ) + { + if ( !m_Value->Execute(pile) ) return false; + pile->IncState(); + } + + if ( pile->IfStep() ) return false; + + int val = pile->GetVal(); + if ( val < 0 ) val = TX_BADTHROW; + pile->SetError( val, &m_token ); + return pj->Return( pile ); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotThrow::RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pile = pj->RestoreStack(this); + if ( pile == nullptr ) return; + + if ( pile->GetState() == 0 ) + { + m_Value->RestoreState(pile, bMain); + return; + } +} diff --git a/src/CBot/CBotInstr/CBotThrow.h b/src/CBot/CBotInstr/CBotThrow.h new file mode 100644 index 00000000..997550aa --- /dev/null +++ b/src/CBot/CBotInstr/CBotThrow.h @@ -0,0 +1,73 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotThrow class Compiles instruction "throw". + */ +class CBotThrow : public CBotInstr +{ +public: + + /*! + * \brief CBotThrow + */ + CBotThrow(); + + /*! + * \brief ~CBotThrow + */ + ~CBotThrow(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execution of instruction "throw". + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! The value to send. + CBotInstr* m_Value; + +}; diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index 89647e2a..2891c607 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -156,78 +156,3 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) return; } } - -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "throw" - -CBotThrow::CBotThrow() -{ - m_Value = nullptr; // nullptr so that delete is not possible further - - name = "CBotThrow"; // debug -} - -CBotThrow::~CBotThrow() -{ - delete m_Value; -} - -CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack) -{ - pStack->SetStartError(p->GetStart()); - - CBotThrow* inst = new CBotThrow(); // creates the object - inst->SetToken(p); - - CBotToken* pp = p; // preserves at the ^ token (starting position) - - if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen - - inst->m_Value = CBotExpression::Compile( p, pStack ); - - if (pStack->GetType() < CBotTypLong && pStack->IsOk()) - { - return inst; // return an object to the application - } - pStack->SetError(TX_BADTYPE, pp); - - delete inst; // error, frees up - return nullptr; // no object, the error is on the stack -} - -// execution of instruction "throw" - -bool CBotThrow :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - - if ( pile->GetState() == 0 ) - { - if ( !m_Value->Execute(pile) ) return false; - pile->IncState(); - } - - if ( pile->IfStep() ) return false; - - int val = pile->GetVal(); - if ( val < 0 ) val = TX_BADTHROW; - pile->SetError( val, &m_token ); - return pj->Return( pile ); -} - -void CBotThrow :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pile = pj->RestoreStack(this); - if ( pile == nullptr ) return; - - if ( pile->GetState() == 0 ) - { - m_Value->RestoreState(pile, bMain); - return; - } -} - - diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index cd17d7ba..80b1303b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -18,6 +18,7 @@ set(SOURCES CBotInstr/CBotBreak.cpp CBotInstr/CBotTry.cpp CBotInstr/CBotCatch.cpp + CBotInstr/CBotThrow.cpp ) # Includes From 562752b653cfb06fe90d5590c60cf3ebf7538179 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 8 Nov 2015 20:01:45 +0100 Subject: [PATCH 065/360] Moving CBotWhile class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 14 ----- src/CBot/{ => CBotInstr}/CBotWhile.cpp | 32 ++++------- src/CBot/CBotInstr/CBotWhile.h | 79 ++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 2 +- 5 files changed, 92 insertions(+), 36 deletions(-) rename src/CBot/{ => CBotInstr}/CBotWhile.cpp (86%) create mode 100644 src/CBot/CBotInstr/CBotWhile.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 6fda6766..949ad2d5 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -42,6 +42,7 @@ #include "CBotInstr/CBotBreak.h" #include "CBotInstr/CBotTry.h" #include "CBotInstr/CBotThrow.h" +#include "CBotInstr/CBotWhile.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index c331ff4d..5fb3959c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -467,21 +467,7 @@ public: bool IsOfClass(CBotString name); }; -class CBotWhile : public CBotInstr -{ -private: - CBotInstr* m_Condition; // condition - CBotInstr* m_Block; // instructions - CBotString m_label; // a label if there is -public: - CBotWhile(); - ~CBotWhile(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; class CBotReturn : public CBotInstr { diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp similarity index 86% rename from src/CBot/CBotWhile.cpp rename to src/CBot/CBotInstr/CBotWhile.cpp index 2891c607..92b276db 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -17,26 +17,14 @@ * along with this program. If not, see http://gnu.org/licenses */ -/////////////////////////////////////////////////////////////////////// -// This file defined the following statements: -// CBotWhile "while (condition) {instructions}" -// CBotDo "do {instructions} while (condition)" -// CBotFor "for (init, condition, incr) {instructions}" -// CBotSwitch "switch (val) {instructions}" -// CBotCase "case val:" -// CBotBreak "break", "break label", "continu", "continu label" -// CBotTry "try {instructions}" -// CBotCatch "catch (condition) {instructions}" or "finally" -// CBotThrow "throw execption" +// Modules inlcude +#include "CBotWhile.h" +// Local include -#include "CBot.h" - -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compile an instruction "while" +// Global include +//////////////////////////////////////////////////////////////////////////////// CBotWhile::CBotWhile() { m_Condition = @@ -44,12 +32,14 @@ CBotWhile::CBotWhile() name = "CBotWhile"; // debug } +//////////////////////////////////////////////////////////////////////////////// CBotWhile::~CBotWhile() { delete m_Condition; // frees the condition delete m_Block; // releases the block instruction } +//////////////////////////////////////////////////////////////////////////////// CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack) { CBotWhile* inst = new CBotWhile(); // creates the object @@ -88,9 +78,8 @@ CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(nullptr, pStk); // no object, the error is on the stack } -// executes a "while" instruction - -bool CBotWhile :: Execute(CBotStack* &pj) +//////////////////////////////////////////////////////////////////////////////// +bool CBotWhile::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); // adds an item to the stack // or find in case of recovery @@ -137,7 +126,8 @@ bool CBotWhile :: Execute(CBotStack* &pj) } } -void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) +//////////////////////////////////////////////////////////////////////////////// +void CBotWhile::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h new file mode 100644 index 00000000..5d63909a --- /dev/null +++ b/src/CBot/CBotInstr/CBotWhile.h @@ -0,0 +1,79 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotWhile class Compile an instruction "while". + */ +class CBotWhile : public CBotInstr +{ +public: + + /*! + * \brief CBotWhile + */ + CBotWhile(); + + /*! + * \brief ~CBotWhile + */ + ~CBotWhile(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + // executes a "while" instruction + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + + +private: + + //! Condition + CBotInstr* m_Condition; + //! Instructions + CBotInstr* m_Block; + //! A label if there is + CBotString m_label; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 80b1303b..af6a1e93 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -9,7 +9,7 @@ set(SOURCES CBotToken.cpp CBotTwoOpExpr.cpp CBotVar.cpp - CBotWhile.cpp + CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp CBotInstr/CBotListExpression.cpp From a0c2c90c9c08e2a4df5e6ca726d0508b868659ed Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:24:37 +0100 Subject: [PATCH 066/360] Moving CBotExprAlpha class in its own header and source files. --- src/CBot/CBot.cpp | 58 +-------------------- src/CBot/CBot.h | 16 ------ src/CBot/CBotInstr/CBotExprAlpha.cpp | 77 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprAlpha.h | 67 ++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 146 insertions(+), 73 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprAlpha.cpp create mode 100644 src/CBot/CBotInstr/CBotExprAlpha.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 949ad2d5..8332a1ba 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -43,6 +43,7 @@ #include "CBotInstr/CBotTry.h" #include "CBotInstr/CBotThrow.h" #include "CBotInstr/CBotWhile.h" +#include "CBotInstr/CBotExprAlpha.h" // Local include @@ -2871,63 +2872,6 @@ void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) if (bMain) pj->RestoreStack(this); } -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compile a token representing a string - -CBotExprAlpha::CBotExprAlpha() -{ - name = "CBotExprAlpha"; -} - -CBotExprAlpha::~CBotExprAlpha() -{ -} - -CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->TokenStack(); - - CBotExprAlpha* inst = new CBotExprAlpha(); - - inst->SetToken(p); - p = p->GetNext(); - - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypString); - pStk->SetVar(var); - - return pStack->Return(inst, pStk); -} - -// execute, returns the corresponding string - -bool CBotExprAlpha::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypString); - - CBotString chaine = m_token.GetString(); - chaine = chaine.Mid(1, chaine.GetLength()-2); // removes the quotes - - var->SetValString(chaine); // value of the number - - pile->SetVar(var); // put on the stack - - return pj->Return(pile); -} - -void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // compile a token representing true or false diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 5fb3959c..cc1436aa 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -1026,22 +1026,6 @@ public: -// expression representing a string - -class CBotExprAlpha : public CBotInstr -{ -private: - -public: - CBotExprAlpha(); - ~CBotExprAlpha(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp new file mode 100644 index 00000000..c412ac02 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -0,0 +1,77 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprAlpha.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotExprAlpha::CBotExprAlpha() +{ + name = "CBotExprAlpha"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprAlpha::~CBotExprAlpha() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCStack* pStk = pStack->TokenStack(); + + CBotExprAlpha* inst = new CBotExprAlpha(); + + inst->SetToken(p); + p = p->GetNext(); + + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypString); + pStk->SetVar(var); + + return pStack->Return(inst, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprAlpha::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypString); + + CBotString chaine = m_token.GetString(); + chaine = chaine.Mid(1, chaine.GetLength()-2); // removes the quotes + + var->SetValString(chaine); // value of the number + + pile->SetVar(var); // put on the stack + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotExprAlpha.h b/src/CBot/CBotInstr/CBotExprAlpha.h new file mode 100644 index 00000000..3f820607 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprAlpha.h @@ -0,0 +1,67 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotExprAlpha class Expression representing a string. + */ +class CBotExprAlpha : public CBotInstr +{ +public: + + /*! + * \brief CBotExprAlpha + */ + CBotExprAlpha(); + + /*! + * \brief CBotExprAlpha + */ + ~CBotExprAlpha(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execute, returns the corresponding string. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index af6a1e93..60363d30 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -19,6 +19,7 @@ set(SOURCES CBotInstr/CBotTry.cpp CBotInstr/CBotCatch.cpp CBotInstr/CBotThrow.cpp + CBotInstr/CBotExprAlpha.cpp ) # Includes From f8778e8c03b9b98b9c012543fdafdc6e18220ef1 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:35:09 +0100 Subject: [PATCH 067/360] Moving CBotExprNum class in its own header and source files. --- src/CBot/CBot.cpp | 188 +------------------------- src/CBot/CBot.h | 19 --- src/CBot/CBotInstr/CBotCase.cpp | 1 + src/CBot/CBotInstr/CBotExprNum.cpp | 210 +++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprNum.h | 78 +++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 291 insertions(+), 206 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprNum.cpp create mode 100644 src/CBot/CBotInstr/CBotExprNum.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 8332a1ba..bc3d5c54 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -44,6 +44,7 @@ #include "CBotInstr/CBotThrow.h" #include "CBotInstr/CBotWhile.h" #include "CBotInstr/CBotExprAlpha.h" +#include "CBotInstr/CBotExprNum.h" // Local include @@ -2686,193 +2687,6 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) m_next3->RestoreStateVar(pile, bMain); } -////////////////////////////////////////////////////////////////////////////////////////// - -// converts a string into integer -// may be of the form 0xabc123 - -long GetNumInt(const char* p) -{ - long num = 0; - while (*p >= '0' && *p <= '9') - { - num = num * 10 + *p - '0'; - p++; - } - if (*p == 'x' || *p == 'X') - { - while (*++p != 0) - { - if (*p >= '0' && *p <= '9') - { - num = num * 16 + *p - '0'; - continue; - } - if (*p >= 'A' && *p <= 'F') - { - num = num * 16 + *p - 'A' + 10; - continue; - } - if (*p >= 'a' && *p <= 'f') - { - num = num * 16 + *p - 'a' + 10; - continue; - } - break; - } - } - return num; -} - -// converts a string into a float number -extern float GetNumFloat(const char* p) -{ - double num = 0; - double div = 10; - bool bNeg = false; - - if (*p == '-') - { - bNeg = true; - p++; - } - while (*p >= '0' && *p <= '9') - { - num = num * 10. + (*p - '0'); - p++; - } - - if (*p == '.') - { - p++; - while (*p >= '0' && *p <= '9') - { - num = num + (*p - '0') / div; - div = div * 10; - p++; - } - } - - int exp = 0; - if (*p == 'e' || *p == 'E') - { - char neg = 0; - p++; - if (*p == '-' || *p == '+') neg = *p++; - - while (*p >= '0' && *p <= '9') - { - exp = exp * 10 + (*p - '0'); - p++; - } - if (neg == '-') exp = -exp; - } - - while (exp > 0) - { - num *= 10.0; - exp--; - } - - while (exp < 0) - { - num /= 10.0; - exp++; - } - - if (bNeg) num = -num; - return static_cast(num); -} - -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compiles a token representing a number -CBotExprNum::CBotExprNum() -{ - name = "CBotExprNum"; -} - -CBotExprNum::~CBotExprNum() -{ -} - -CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->TokenStack(); - - CBotExprNum* inst = new CBotExprNum(); - - inst->SetToken(p); - CBotString s = p->GetString(); - - inst->m_numtype = CBotTypInt; - if (p->GetType() == TokenTypDef) - { - inst->m_valint = p->GetIdKey(); - } - else - { - if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) )) - { - inst->m_numtype = CBotTypFloat; - inst->m_valfloat = GetNumFloat(s); - } - else - { - inst->m_valint = GetNumInt(s); - } - } - - if (pStk->NextToken(p)) - { - CBotVar* var = CBotVar::Create(static_cast(nullptr), inst->m_numtype); - pStk->SetVar(var); - - return pStack->Return(inst, pStk); - } - delete inst; - return pStack->Return(nullptr, pStk); -} - -// execute, returns the corresponding number - -bool CBotExprNum::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - - CBotVar* var = CBotVar::Create(static_cast(nullptr), m_numtype); - - CBotString nombre ; - if (m_token.GetType() == TokenTypDef) - { - nombre = m_token.GetString(); - } - - switch (m_numtype) - { - case CBotTypShort: - case CBotTypInt: - var->SetValInt(m_valint, nombre); - break; - case CBotTypFloat: - var->SetValFloat(m_valfloat); - break; - } - pile->SetVar(var); // place on the stack - - return pj->Return(pile); // it's ok -} - -void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - - ////////////////////////////////////////////////////////////////////////////////////// // compile a token representing true or false diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index cc1436aa..6fc404af 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -1006,25 +1006,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -// expression representing a number - -class CBotExprNum : public CBotInstr -{ -private: - int m_numtype; // et the type of number - long m_valint; // value for an int - float m_valfloat; // value for a float - -public: - CBotExprNum(); - ~CBotExprNum(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index ac311039..a2b68c4f 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotCase.h" +#include "CBotExprNum.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp new file mode 100644 index 00000000..61cf3eaa --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -0,0 +1,210 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprNum.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +// converts a string into integer +// may be of the form 0xabc123 +long GetNumInt(const char* p) +{ + long num = 0; + while (*p >= '0' && *p <= '9') + { + num = num * 10 + *p - '0'; + p++; + } + if (*p == 'x' || *p == 'X') + { + while (*++p != 0) + { + if (*p >= '0' && *p <= '9') + { + num = num * 16 + *p - '0'; + continue; + } + if (*p >= 'A' && *p <= 'F') + { + num = num * 16 + *p - 'A' + 10; + continue; + } + if (*p >= 'a' && *p <= 'f') + { + num = num * 16 + *p - 'a' + 10; + continue; + } + break; + } + } + return num; +} + +//////////////////////////////////////////////////////////////////////////////// +// converts a string into a float number +extern float GetNumFloat(const char* p) +{ + double num = 0; + double div = 10; + bool bNeg = false; + + if (*p == '-') + { + bNeg = true; + p++; + } + while (*p >= '0' && *p <= '9') + { + num = num * 10. + (*p - '0'); + p++; + } + + if (*p == '.') + { + p++; + while (*p >= '0' && *p <= '9') + { + num = num + (*p - '0') / div; + div = div * 10; + p++; + } + } + + int exp = 0; + if (*p == 'e' || *p == 'E') + { + char neg = 0; + p++; + if (*p == '-' || *p == '+') neg = *p++; + + while (*p >= '0' && *p <= '9') + { + exp = exp * 10 + (*p - '0'); + p++; + } + if (neg == '-') exp = -exp; + } + + while (exp > 0) + { + num *= 10.0; + exp--; + } + + while (exp < 0) + { + num /= 10.0; + exp++; + } + + if (bNeg) num = -num; + return static_cast(num); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNum::CBotExprNum() +{ + name = "CBotExprNum"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNum::~CBotExprNum() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCStack* pStk = pStack->TokenStack(); + + CBotExprNum* inst = new CBotExprNum(); + + inst->SetToken(p); + CBotString s = p->GetString(); + + inst->m_numtype = CBotTypInt; + if (p->GetType() == TokenTypDef) + { + inst->m_valint = p->GetIdKey(); + } + else + { + if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) )) + { + inst->m_numtype = CBotTypFloat; + inst->m_valfloat = GetNumFloat(s); + } + else + { + inst->m_valint = GetNumInt(s); + } + } + + if (pStk->NextToken(p)) + { + CBotVar* var = CBotVar::Create(static_cast(nullptr), inst->m_numtype); + pStk->SetVar(var); + + return pStack->Return(inst, pStk); + } + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprNum::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + + CBotVar* var = CBotVar::Create(static_cast(nullptr), m_numtype); + + CBotString nombre ; + if (m_token.GetType() == TokenTypDef) + { + nombre = m_token.GetString(); + } + + switch (m_numtype) + { + case CBotTypShort: + case CBotTypInt: + var->SetValInt(m_valint, nombre); + break; + case CBotTypFloat: + var->SetValFloat(m_valfloat); + break; + } + pile->SetVar(var); // place on the stack + + return pj->Return(pile); // it's ok +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} + diff --git a/src/CBot/CBotInstr/CBotExprNum.h b/src/CBot/CBotInstr/CBotExprNum.h new file mode 100644 index 00000000..dc213319 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNum.h @@ -0,0 +1,78 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotExprNum class Expression representing a number. + */ +class CBotExprNum : public CBotInstr +{ + +public: + + /*! + * \brief CBotExprNum + */ + CBotExprNum(); + + /*! + * \brief ~CBotExprNum + */ + ~CBotExprNum(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execute, returns the corresponding number. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! The type of number. + int m_numtype; + //! Value for an int. + long m_valint; + //! Value for a float. + float m_valfloat; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 60363d30..b36e9b08 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -20,6 +20,7 @@ set(SOURCES CBotInstr/CBotCatch.cpp CBotInstr/CBotThrow.cpp CBotInstr/CBotExprAlpha.cpp + CBotInstr/CBotExprNum.cpp ) # Includes From d70527db66ace513da32ed9cda3ed8442c62754d Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:42:10 +0100 Subject: [PATCH 068/360] Moving CBotNew class in its own header and source files. --- src/CBot/CBot.cpp | 217 +---------------------------- src/CBot/CBot.h | 18 --- src/CBot/CBotClass.cpp | 1 + src/CBot/CBotInstr/CBotNew.cpp | 241 +++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotNew.h | 75 ++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 319 insertions(+), 234 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotNew.cpp create mode 100644 src/CBot/CBotInstr/CBotNew.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index bc3d5c54..4c705eb3 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -45,6 +45,7 @@ #include "CBotInstr/CBotWhile.h" #include "CBotInstr/CBotExprAlpha.h" #include "CBotInstr/CBotExprNum.h" +#include "CBotInstr/CBotNew.h" // Local include @@ -3394,222 +3395,6 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) return pj->Return(pile2); // release the entire stack } -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compile an instruction "new" - -CBotNew::CBotNew() -{ - name = "CBotNew"; - m_Parameters = nullptr; - m_nMethodeIdent = 0; -} - -CBotNew::~CBotNew() -{ -} - -CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; - if (!IsOfType(p, ID_NEW)) return nullptr; - - // verifies that the token is a class name - if (p->GetType() != TokenTypVar) return nullptr; - - CBotClass* pClass = CBotClass::Find(p); - if (pClass == nullptr) - { - pStack->SetError(TX_BADNEW, p); - return nullptr; - } - - CBotNew* inst = new CBotNew(); - inst->SetToken(pp); - - inst->m_vartoken = p; - p = p->GetNext(); - - // creates the object on the "job" - // with a pointer to the object - CBotVar* pVar = CBotVar::Create("", pClass); - - // do the call of the creator - CBotCStack* pStk = pStack->TokenStack(); - { - // check if there are parameters - CBotVar* ppVars[1000]; - inst->m_Parameters = CompileParams(p, pStk, ppVars); - if (!pStk->IsOk()) goto error; - - // constructor exist? - CBotTypResult r = pClass->CompileMethode(pClass->GetName(), pVar, ppVars, pStk, inst->m_nMethodeIdent); - delete pStk->TokenStack(); // release extra stack - int typ = r.GetType(); - - // if there is no constructor, and no parameters either, it's ok - if (typ == TX_UNDEFCALL && inst->m_Parameters == nullptr) typ = 0; - pVar->SetInit(CBotVar::InitType::DEF); // mark the instance as init - - if (typ>20) - { - pStk->SetError(typ, inst->m_vartoken.GetEnd()); - goto error; - } - - // if the constructor does not exist, but there are parameters - if (typ<0 && inst->m_Parameters != nullptr) - { - pStk->SetError(TX_NOCONST, &inst->m_vartoken); - goto error; - } - - // makes pointer to the object on the stack - pStk->SetVar(pVar); - return pStack->Return(inst, pStk); - } -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes instruction "new" - -bool CBotNew::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); //main stack - - if (pile->IfStep()) return false; - - CBotStack* pile1 = pj->AddStack2(); //secondary stack - - CBotVar* pThis = nullptr; - - CBotToken* pt = &m_vartoken; - CBotClass* pClass = CBotClass::Find(pt); - - // create the variable "this" pointer type to the stack - - if ( pile->GetState()==0) - { - // create an instance of the requested class - // and initialize the pointer to that object - - - pThis = CBotVar::Create("this", pClass); - pThis->SetUniqNum(-2) ; - - pile1->SetVar(pThis); // place on stack1 - pile->IncState(); - } - - // fetch the this pointer if it was interrupted - if ( pThis == nullptr) - { - pThis = pile1->GetVar(); // find the pointer - } - - // is there an assignment or parameters (constructor) - if ( pile->GetState()==1) - { - // evaluates the constructor of the instance - - CBotVar* ppVars[1000]; - CBotStack* pile2 = pile; - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluate the parameters - // and places the values on the stack - // to be interrupted at any time - - if (p != nullptr) while ( true) - { - pile2 = pile2->AddStack(); // space on the stack for the result - if (pile2->GetState() == 0) - { - if (!p->Execute(pile2)) return false; // interrupted here? - pile2->SetState(1); - } - ppVars[i++] = pile2->GetVar(); - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - // create a variable for the result - CBotVar* pResult = nullptr; // constructos still void - - if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), - pThis, ppVars, - pResult, pile2, GetToken())) return false; // interrupt - - pThis->ConstructorSet(); // indicates that the constructor has been called - } - - return pj->Return(pile1); // passes below -} - -void CBotNew::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); //primary stack - if (pile == nullptr) return; - - CBotStack* pile1 = pj->AddStack2(); //secondary stack - - CBotToken* pt = &m_vartoken; - CBotClass* pClass = CBotClass::Find(pt); - - // create the variable "this" pointer type to the object - - if ( pile->GetState()==0) - { - return; - } - - CBotVar* pThis = pile1->GetVar(); // find the pointer - pThis->SetUniqNum(-2); - - // is ther an assignment or parameters (constructor) - if ( pile->GetState()==1) - { - // evaluates the constructor of the instance - - CBotVar* ppVars[1000]; - CBotStack* pile2 = pile; - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluate the parameters - // and places the values on the stack - // to be interrupted at any time - - if (p != nullptr) while ( true) - { - pile2 = pile2->RestoreStack(); // space on the stack for the result - if (pile2 == nullptr) return; - - if (pile2->GetState() == 0) - { - p->RestoreState(pile2, bMain); // interrupt here! - return; - } - ppVars[i++] = pile2->GetVar(); - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GetString(), pThis, - ppVars, pile2) ; // interrupt here! - } -} - ///////////////////////////////////////////////////////////// // check if two results are consistent to make an operation diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 6fc404af..76549b0f 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -988,24 +988,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotNew : public CBotInstr -{ -private: - CBotInstr* m_Parameters; // the parameters to be evaluated - long m_nMethodeIdent; -// long m_nThisIdent; - CBotToken m_vartoken; - -public: - CBotNew(); - ~CBotNew(); - - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index bebd7692..79030582 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -22,6 +22,7 @@ // #include "CBot.h" +#include "CBotInstr/CBotNew.h" CBotClass* CBotClass::m_ExClass = nullptr; diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp new file mode 100644 index 00000000..d89a8ca7 --- /dev/null +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -0,0 +1,241 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotNew.h" + +// Local include + +// Global include + + + +//////////////////////////////////////////////////////////////////////////////// +CBotNew::CBotNew() +{ + name = "CBotNew"; + m_Parameters = nullptr; + m_nMethodeIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotNew::~CBotNew() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; + if (!IsOfType(p, ID_NEW)) return nullptr; + + // verifies that the token is a class name + if (p->GetType() != TokenTypVar) return nullptr; + + CBotClass* pClass = CBotClass::Find(p); + if (pClass == nullptr) + { + pStack->SetError(TX_BADNEW, p); + return nullptr; + } + + CBotNew* inst = new CBotNew(); + inst->SetToken(pp); + + inst->m_vartoken = p; + p = p->GetNext(); + + // creates the object on the "job" + // with a pointer to the object + CBotVar* pVar = CBotVar::Create("", pClass); + + // do the call of the creator + CBotCStack* pStk = pStack->TokenStack(); + { + // check if there are parameters + CBotVar* ppVars[1000]; + inst->m_Parameters = CompileParams(p, pStk, ppVars); + if (!pStk->IsOk()) goto error; + + // constructor exist? + CBotTypResult r = pClass->CompileMethode(pClass->GetName(), pVar, ppVars, pStk, inst->m_nMethodeIdent); + delete pStk->TokenStack(); // release extra stack + int typ = r.GetType(); + + // if there is no constructor, and no parameters either, it's ok + if (typ == TX_UNDEFCALL && inst->m_Parameters == nullptr) typ = 0; + pVar->SetInit(CBotVar::InitType::DEF); // mark the instance as init + + if (typ>20) + { + pStk->SetError(typ, inst->m_vartoken.GetEnd()); + goto error; + } + + // if the constructor does not exist, but there are parameters + if (typ<0 && inst->m_Parameters != nullptr) + { + pStk->SetError(TX_NOCONST, &inst->m_vartoken); + goto error; + } + + // makes pointer to the object on the stack + pStk->SetVar(pVar); + return pStack->Return(inst, pStk); + } +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotNew::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); //main stack + + if (pile->IfStep()) return false; + + CBotStack* pile1 = pj->AddStack2(); //secondary stack + + CBotVar* pThis = nullptr; + + CBotToken* pt = &m_vartoken; + CBotClass* pClass = CBotClass::Find(pt); + + // create the variable "this" pointer type to the stack + + if ( pile->GetState()==0) + { + // create an instance of the requested class + // and initialize the pointer to that object + + + pThis = CBotVar::Create("this", pClass); + pThis->SetUniqNum(-2) ; + + pile1->SetVar(pThis); // place on stack1 + pile->IncState(); + } + + // fetch the this pointer if it was interrupted + if ( pThis == nullptr) + { + pThis = pile1->GetVar(); // find the pointer + } + + // is there an assignment or parameters (constructor) + if ( pile->GetState()==1) + { + // evaluates the constructor of the instance + + CBotVar* ppVars[1000]; + CBotStack* pile2 = pile; + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time + + if (p != nullptr) while ( true) + { + pile2 = pile2->AddStack(); // space on the stack for the result + if (pile2->GetState() == 0) + { + if (!p->Execute(pile2)) return false; // interrupted here? + pile2->SetState(1); + } + ppVars[i++] = pile2->GetVar(); + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + // create a variable for the result + CBotVar* pResult = nullptr; // constructos still void + + if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), + pThis, ppVars, + pResult, pile2, GetToken())) return false; // interrupt + + pThis->ConstructorSet(); // indicates that the constructor has been called + } + + return pj->Return(pile1); // passes below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotNew::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); //primary stack + if (pile == nullptr) return; + + CBotStack* pile1 = pj->AddStack2(); //secondary stack + + CBotToken* pt = &m_vartoken; + CBotClass* pClass = CBotClass::Find(pt); + + // create the variable "this" pointer type to the object + + if ( pile->GetState()==0) + { + return; + } + + CBotVar* pThis = pile1->GetVar(); // find the pointer + pThis->SetUniqNum(-2); + + // is ther an assignment or parameters (constructor) + if ( pile->GetState()==1) + { + // evaluates the constructor of the instance + + CBotVar* ppVars[1000]; + CBotStack* pile2 = pile; + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time + + if (p != nullptr) while ( true) + { + pile2 = pile2->RestoreStack(); // space on the stack for the result + if (pile2 == nullptr) return; + + if (pile2->GetState() == 0) + { + p->RestoreState(pile2, bMain); // interrupt here! + return; + } + ppVars[i++] = pile2->GetVar(); + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GetString(), pThis, + ppVars, pile2) ; // interrupt here! + } +} diff --git a/src/CBot/CBotInstr/CBotNew.h b/src/CBot/CBotInstr/CBotNew.h new file mode 100644 index 00000000..77e2b2c6 --- /dev/null +++ b/src/CBot/CBotInstr/CBotNew.h @@ -0,0 +1,75 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotNew class Compile an instruction "new". + */ +class CBotNew : public CBotInstr +{ +public: + + /*! + * \brief CBotNew + */ + CBotNew(); + + /*! + * \brief ~CBotNew + */ + ~CBotNew(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Executes instruction "new". + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! The parameters to be evaluated + CBotInstr* m_Parameters; + long m_nMethodeIdent; + CBotToken m_vartoken; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index b36e9b08..6b2aeab5 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -21,6 +21,7 @@ set(SOURCES CBotInstr/CBotThrow.cpp CBotInstr/CBotExprAlpha.cpp CBotInstr/CBotExprNum.cpp + CBotInstr/CBotNew.cpp ) # Includes From 85756b4da15386af93c1d69c450018bb9767e978 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:47:44 +0100 Subject: [PATCH 069/360] Moving CBotExprNan class in its own header and source files. --- src/CBot/CBot.cpp | 33 +---------------- src/CBot/CBot.h | 12 ------ src/CBot/CBotInstr/CBotExprNan.cpp | 55 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprNan.h | 59 ++++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 116 insertions(+), 44 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprNan.cpp create mode 100644 src/CBot/CBotInstr/CBotExprNan.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 4c705eb3..b69af068 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -46,6 +46,7 @@ #include "CBotInstr/CBotExprAlpha.h" #include "CBotInstr/CBotExprNum.h" #include "CBotInstr/CBotNew.h" +#include "CBotInstr/CBotExprNan.h" // Local include @@ -2773,38 +2774,6 @@ void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) if (bMain) pj->RestoreStack(this); } -////////////////////////////////////////////////////////////////////////////////////////// - -// management of the operand "nan" - -CBotExprNan::CBotExprNan() -{ - name = "CBotExprNan"; -} - -CBotExprNan::~CBotExprNan() -{ -} - -// executes, returns null pointer - -bool CBotExprNan::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypInt); - - var->SetInit(CBotVar::InitType::IS_NAN); // nan - pile->SetVar(var); // put on the stack - return pj->Return(pile); // forward below -} - -void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - ////////////////////////////////////////////////////////////////////////////////////// // compile a variable name // check that it is known on the stack diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 76549b0f..1e0f91e1 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -976,18 +976,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotExprNan : public CBotInstr -{ -private: - -public: - CBotExprNan(); - ~CBotExprNan(); - - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp new file mode 100644 index 00000000..3eebb74a --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNan.cpp @@ -0,0 +1,55 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprNan.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNan::CBotExprNan() +{ + name = "CBotExprNan"; +} +//////////////////////////////////////////////////////////////////////////////// +CBotExprNan::~CBotExprNan() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprNan::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypInt); + + var->SetInit(CBotVar::InitType::IS_NAN); // nan + pile->SetVar(var); // put on the stack + return pj->Return(pile); // forward below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotExprNan.h b/src/CBot/CBotInstr/CBotExprNan.h new file mode 100644 index 00000000..0d6bbf6f --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNan.h @@ -0,0 +1,59 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotExprNan class Management of the operand "nan". + */ +class CBotExprNan : public CBotInstr +{ +public: + + /*! + * \brief CBotExprNan + */ + CBotExprNan(); + + /*! + * \brief ~CBotExprNan + */ + ~CBotExprNan(); + + /*! + * \brief Execute Executes, returns null pointer. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 6b2aeab5..c45dd1c4 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -22,6 +22,7 @@ set(SOURCES CBotInstr/CBotExprAlpha.cpp CBotInstr/CBotExprNum.cpp CBotInstr/CBotNew.cpp + CBotInstr/CBotExprNan.cpp ) # Includes From 27a2c0b55aade64c57e59e8cc280ab91ce089a7d Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:52:41 +0100 Subject: [PATCH 070/360] Moving CBotExprNull class in its own header and source files. --- src/CBot/CBot.cpp | 33 +--------------- src/CBot/CBot.h | 14 ------- src/CBot/CBotInstr/CBotExprNull.cpp | 56 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprNull.h | 60 +++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 118 insertions(+), 46 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprNull.cpp create mode 100644 src/CBot/CBotInstr/CBotExprNull.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index b69af068..25efe2bd 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -47,6 +47,7 @@ #include "CBotInstr/CBotExprNum.h" #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotExprNan.h" +#include "CBotInstr/CBotExprNull.h" // Local include @@ -2742,38 +2743,6 @@ void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) if (bMain) pj->RestoreStack(this); } -////////////////////////////////////////////////////////////////////////////////////////// - -// management of the operand "null" - -CBotExprNull::CBotExprNull() -{ - name = "CBotExprNull"; -} - -CBotExprNull::~CBotExprNull() -{ -} - -// executes, returns an empty pointer - -bool CBotExprNull::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypNullPointer); - - var->SetInit(CBotVar::InitType::DEF); // null pointer valid - pile->SetVar(var); // place on the stack - return pj->Return(pile); // forwards below -} - -void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - ////////////////////////////////////////////////////////////////////////////////////// // compile a variable name // check that it is known on the stack diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 1e0f91e1..e860c4a6 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -963,20 +963,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -class CBotExprNull : public CBotInstr -{ -private: - -public: - CBotExprNull(); - ~CBotExprNull(); - - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprNull.cpp b/src/CBot/CBotInstr/CBotExprNull.cpp new file mode 100644 index 00000000..0324d50b --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNull.cpp @@ -0,0 +1,56 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprNull.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNull::CBotExprNull() +{ + name = "CBotExprNull"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprNull::~CBotExprNull() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprNull::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypNullPointer); + + var->SetInit(CBotVar::InitType::DEF); // null pointer valid + pile->SetVar(var); // place on the stack + return pj->Return(pile); // forwards below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotExprNull.h b/src/CBot/CBotInstr/CBotExprNull.h new file mode 100644 index 00000000..187cb261 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprNull.h @@ -0,0 +1,60 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotExprNull class Management of the operand "null". + */ +class CBotExprNull : public CBotInstr +{ +public: + + /*! + * \brief CBotExprNull + */ + CBotExprNull(); + + /*! + * \brief ~CBotExprNull + */ + ~CBotExprNull(); + + /*! + * \brief Execute Executes, returns an empty pointer. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index c45dd1c4..5701d39b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES CBotInstr/CBotExprNum.cpp CBotInstr/CBotNew.cpp CBotInstr/CBotExprNan.cpp + CBotInstr/CBotExprNull.cpp ) # Includes From 2f52520421b3972d9d5bf14ad5caa1b9fcf6894f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 17:59:50 +0100 Subject: [PATCH 071/360] Moving CBotExprBool class in its own header and source files. --- src/CBot/CBot.cpp | 54 +------------------- src/CBot/CBot.h | 15 ------ src/CBot/CBotInstr/CBotExprBool.cpp | 79 +++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprBool.h | 68 +++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 149 insertions(+), 68 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprBool.cpp create mode 100644 src/CBot/CBotInstr/CBotExprBool.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 25efe2bd..df2db443 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -48,6 +48,7 @@ #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotExprNan.h" #include "CBotInstr/CBotExprNull.h" +#include "CBotInstr/CBotExprBool.h" // Local include @@ -2690,59 +2691,6 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) m_next3->RestoreStateVar(pile, bMain); } -////////////////////////////////////////////////////////////////////////////////////// -// compile a token representing true or false - -CBotExprBool::CBotExprBool() -{ - name = "CBotExprBool"; -} - -CBotExprBool::~CBotExprBool() -{ -} - -CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->TokenStack(); - CBotExprBool* inst = nullptr; - - if ( p->GetType() == ID_TRUE || - p->GetType() == ID_FALSE ) - { - inst = new CBotExprBool(); - inst->SetToken(p); // stores the operation false or true - p = p->GetNext(); - - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); - pStk->SetVar(var); - } - - return pStack->Return(inst, pStk); -} - -// executes, returns true or false - -bool CBotExprBool::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - - CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); - - if (GetTokenType() == ID_TRUE) var->SetValInt(1); - else var->SetValInt(0); - - pile->SetVar(var); // put on the stack - return pj->Return(pile); // forwards below -} - -void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) pj->RestoreStack(this); -} - ////////////////////////////////////////////////////////////////////////////////////// // compile a variable name // check that it is known on the stack diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e860c4a6..eebdb95b 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -948,21 +948,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -class CBotExprBool : public CBotInstr -{ -private: - -public: - CBotExprBool(); - ~CBotExprBool(); - - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp new file mode 100644 index 00000000..17c09e55 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -0,0 +1,79 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprBool.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprBool::CBotExprBool() +{ + name = "CBotExprBool"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprBool::~CBotExprBool() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCStack* pStk = pStack->TokenStack(); + CBotExprBool* inst = nullptr; + + if ( p->GetType() == ID_TRUE || + p->GetType() == ID_FALSE ) + { + inst = new CBotExprBool(); + inst->SetToken(p); // stores the operation false or true + p = p->GetNext(); + + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); + pStk->SetVar(var); + } + + return pStack->Return(inst, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprBool::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + + CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypBoolean); + + if (GetTokenType() == ID_TRUE) var->SetValInt(1); + else var->SetValInt(0); + + pile->SetVar(var); // put on the stack + return pj->Return(pile); // forwards below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) pj->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotExprBool.h b/src/CBot/CBotInstr/CBotExprBool.h new file mode 100644 index 00000000..a2609e26 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprBool.h @@ -0,0 +1,68 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotExprBool class Compile a token representing true or false. + */ +class CBotExprBool : public CBotInstr +{ +public: + + /*! + * \brief CBotExprBool + */ + CBotExprBool(); + + /*! + * \brief ~CBotExprBool + */ + ~CBotExprBool(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Executes, returns true or false. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 5701d39b..104e2b1e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -24,6 +24,7 @@ set(SOURCES CBotInstr/CBotNew.cpp CBotInstr/CBotExprNan.cpp CBotInstr/CBotExprNull.cpp + CBotInstr/CBotExprBool.cpp ) # Includes From a878b0d2527ebc74abdf6c6910c3108039985d27 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 18:07:11 +0100 Subject: [PATCH 072/360] Moving CBotLeftExprVar class in its own header and source files. --- src/CBot/CBot.cpp | 63 +------------------ src/CBot/CBot.h | 18 ------ src/CBot/CBotClass.cpp | 2 +- src/CBot/CBotInstr/CBotLeftExprVar.cpp | 83 ++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotLeftExprVar.h | 75 +++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 161 insertions(+), 81 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotLeftExprVar.cpp create mode 100644 src/CBot/CBotInstr/CBotLeftExprVar.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index df2db443..eff35498 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -49,6 +49,7 @@ #include "CBotInstr/CBotExprNan.h" #include "CBotInstr/CBotExprNull.h" #include "CBotInstr/CBotExprBool.h" +#include "CBotInstr/CBotLeftExprVar.h" // Local include @@ -498,68 +499,6 @@ void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) if (p != nullptr) p->RestoreState(pile, true); } -////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// compilation of an element to the left of an assignment - -CBotLeftExprVar::CBotLeftExprVar() -{ - name = "CBotLeftExprVar"; - m_typevar = -1; - m_nIdent = 0; -} - -CBotLeftExprVar::~CBotLeftExprVar() -{ -} - -CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) -{ - // verifies that the token is a variable name - if (p->GetType() != TokenTypVar) - { - pStack->SetError( TX_NOVAR, p->GetStart()); - return nullptr; - } - - CBotLeftExprVar* inst = new CBotLeftExprVar(); - inst->SetToken(p); - p = p->GetNext(); - - return inst; -} - -// creates a variable and assigns the result to the stack -bool CBotLeftExprVar::Execute(CBotStack* &pj) -{ - CBotVar* var1; - CBotVar* var2; - - var1 = CBotVar::Create(m_token.GetString(), m_typevar); - var1->SetUniqNum(m_nIdent); // with the unique identifier - pj->AddVar(var1); // place it on the stack - - var2 = pj->GetVar(); // result on the stack - if (var2) var1->SetVal(var2); // do the assignment - - return true; -} - -void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotVar* var1; - - var1 = pj->FindVar(m_token.GetString()); - if (var1 == nullptr) assert(0); - - var1->SetUniqNum(m_nIdent); // with the unique identifier -} - -////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // defining an array of any type // int a[12]; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index eebdb95b..00e766e7 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -930,24 +930,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -class CBotLeftExprVar : public CBotInstr -{ -private: -public: - CBotTypResult - m_typevar; // type of variable declared - long m_nIdent; // unique identifier for that variable - -public: - CBotLeftExprVar(); - ~CBotLeftExprVar(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 79030582..b7aeb937 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -23,7 +23,7 @@ #include "CBot.h" #include "CBotInstr/CBotNew.h" - +#include "CBotInstr/CBotLeftExprVar.h" CBotClass* CBotClass::m_ExClass = nullptr; diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp new file mode 100644 index 00000000..43ed496d --- /dev/null +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -0,0 +1,83 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotLeftExprVar.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotLeftExprVar::CBotLeftExprVar() +{ + name = "CBotLeftExprVar"; + m_typevar = -1; + m_nIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotLeftExprVar::~CBotLeftExprVar() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) +{ + // verifies that the token is a variable name + if (p->GetType() != TokenTypVar) + { + pStack->SetError( TX_NOVAR, p->GetStart()); + return nullptr; + } + + CBotLeftExprVar* inst = new CBotLeftExprVar(); + inst->SetToken(p); + p = p->GetNext(); + + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotLeftExprVar::Execute(CBotStack* &pj) +{ + CBotVar* var1; + CBotVar* var2; + + var1 = CBotVar::Create(m_token.GetString(), m_typevar); + var1->SetUniqNum(m_nIdent); // with the unique identifier + pj->AddVar(var1); // place it on the stack + + var2 = pj->GetVar(); // result on the stack + if (var2) var1->SetVal(var2); // do the assignment + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotVar* var1; + + var1 = pj->FindVar(m_token.GetString()); + if (var1 == nullptr) assert(0); + + var1->SetUniqNum(m_nIdent); // with the unique identifier +} diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.h b/src/CBot/CBotInstr/CBotLeftExprVar.h new file mode 100644 index 00000000..a264dbae --- /dev/null +++ b/src/CBot/CBotInstr/CBotLeftExprVar.h @@ -0,0 +1,75 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotLeftExprVar class Compilation of an element to the left of an assignment. + */ +class CBotLeftExprVar : public CBotInstr +{ +public: + + /*! + * \brief CBotLeftExprVar + */ + CBotLeftExprVar(); + + /*! + * \brief ~CBotLeftExprVar + */ + ~CBotLeftExprVar(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Creates a variable and assigns the result to the stack. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +public: + + //! Type of variable declared. + CBotTypResult m_typevar; + //! Unique identifier for that variable. + long m_nIdent; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 104e2b1e..5f2a0208 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -25,6 +25,7 @@ set(SOURCES CBotInstr/CBotExprNan.cpp CBotInstr/CBotExprNull.cpp CBotInstr/CBotExprBool.cpp + CBotInstr/CBotLeftExprVar.cpp ) # Includes From 605b1b244aeaedbc219ac0bd313de865a0555013 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 18:16:49 +0100 Subject: [PATCH 073/360] Moving CBotPreIncExpr class in its own header and source files. --- src/CBot/CBot.cpp | 66 +------------------ src/CBot/CBot.h | 15 ----- src/CBot/CBotInstr/CBotPreIncExpr.cpp | 92 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotPreIncExpr.h | 65 +++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 159 insertions(+), 80 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotPreIncExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotPreIncExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index eff35498..f6c11ca8 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -50,6 +50,7 @@ #include "CBotInstr/CBotExprNull.h" #include "CBotInstr/CBotExprBool.h" #include "CBotInstr/CBotLeftExprVar.h" +#include "CBotInstr/CBotPreIncExpr.h" // Local include @@ -2001,17 +2002,6 @@ CBotPostIncExpr::~CBotPostIncExpr() delete m_Instr; } -CBotPreIncExpr::CBotPreIncExpr() -{ - m_Instr = nullptr; - name = "CBotPreIncExpr"; -} - -CBotPreIncExpr::~CBotPreIncExpr() -{ - delete m_Instr; -} - bool CBotPostIncExpr::Execute(CBotStack* &pj) { CBotStack* pile1 = pj->AddStack(this); @@ -2056,60 +2046,6 @@ void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain) if (pile1 != nullptr) pile1->RestoreStack(this); } -bool CBotPreIncExpr::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->IfStep()) return false; - - CBotVar* var1; - - if (pile->GetState() == 0) - { - CBotStack* pile2 = pile; - // retrieves the variable fields and indexes according - // pile2 is modified on return - if (!(static_cast(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false; - - if (var1->IsNAN()) - { - pile->SetError(TX_OPNAN, &m_token); - return pj->Return(pile); // operation performed - } - - if (!var1->IsDefined()) - { - pile->SetError(TX_NOTINIT, &m_token); - return pj->Return(pile); // operation performed - } - - if (GetTokenType() == ID_INC) var1->Inc(); - else var1->Dec(); // ((CBotVarInt*)var1)->m_val - - pile->IncState(); - } - - if (!m_Instr->Execute(pile)) return false; - return pj->Return(pile); // operation performed -} - - -void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if (pile->GetState() == 0) - { - return; - } - - m_Instr->RestoreState(pile, bMain); -} - - ////////////////////////////////////////////////////////////////////////////////////// // compile an unary expression // + diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 00e766e7..814183b9 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -915,21 +915,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotPreIncExpr : public CBotInstr -{ -private: - CBotInstr* m_Instr; - friend class CBotParExpr; - -public: - CBotPreIncExpr(); - ~CBotPreIncExpr(); -// static -// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp new file mode 100644 index 00000000..700bbffa --- /dev/null +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotPreIncExpr.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotPreIncExpr::CBotPreIncExpr() +{ + m_Instr = nullptr; + name = "CBotPreIncExpr"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotPreIncExpr::~CBotPreIncExpr() +{ + delete m_Instr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotPreIncExpr::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->IfStep()) return false; + + CBotVar* var1; + + if (pile->GetState() == 0) + { + CBotStack* pile2 = pile; + // retrieves the variable fields and indexes according + // pile2 is modified on return + if (!(static_cast(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false; + + if (var1->IsNAN()) + { + pile->SetError(TX_OPNAN, &m_token); + return pj->Return(pile); // operation performed + } + + if (!var1->IsDefined()) + { + pile->SetError(TX_NOTINIT, &m_token); + return pj->Return(pile); // operation performed + } + + if (GetTokenType() == ID_INC) var1->Inc(); + else var1->Dec(); // ((CBotVarInt*)var1)->m_val + + pile->IncState(); + } + + if (!m_Instr->Execute(pile)) return false; + return pj->Return(pile); // operation performed +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if (pile->GetState() == 0) + { + return; + } + + m_Instr->RestoreState(pile, bMain); +} diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.h b/src/CBot/CBotInstr/CBotPreIncExpr.h new file mode 100644 index 00000000..ede694d4 --- /dev/null +++ b/src/CBot/CBotInstr/CBotPreIncExpr.h @@ -0,0 +1,65 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotPreIncExpr class Management of pre increment. There is no + * routine Compiles, the object is created directly. Compiles in CBotParExpr + */ +class CBotPreIncExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotPreIncExpr + */ + CBotPreIncExpr(); + + /*! + * \brief ~CBotPreIncExpr + */ + ~CBotPreIncExpr(); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + CBotInstr* m_Instr; + friend class CBotParExpr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 5f2a0208..b7c63490 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -26,6 +26,7 @@ set(SOURCES CBotInstr/CBotExprNull.cpp CBotInstr/CBotExprBool.cpp CBotInstr/CBotLeftExprVar.cpp + CBotInstr/CBotPreIncExpr.cpp ) # Includes From 5343c15d603096493189812b6d645440dc34e02d Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 18:22:04 +0100 Subject: [PATCH 074/360] Moving CBotPostIncExpr class in its own header and source files. --- src/CBot/CBot.cpp | 63 +------------------ src/CBot/CBot.h | 15 ----- src/CBot/CBotInstr/CBotPostIncExpr.cpp | 85 ++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotPostIncExpr.h | 69 +++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 156 insertions(+), 77 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotPostIncExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotPostIncExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index f6c11ca8..b7c8287b 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -51,6 +51,7 @@ #include "CBotInstr/CBotExprBool.h" #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotPreIncExpr.h" +#include "CBotInstr/CBotPostIncExpr.h" // Local include @@ -1983,68 +1984,6 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(nullptr, pStk); } -////////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// Management of pre-and post increment / decrement -// There is no routine Compiles, the object is created directly -// Compiles in CBotParExpr :: - - -CBotPostIncExpr::CBotPostIncExpr() -{ - m_Instr = nullptr; - name = "CBotPostIncExpr"; -} - -CBotPostIncExpr::~CBotPostIncExpr() -{ - delete m_Instr; -} - -bool CBotPostIncExpr::Execute(CBotStack* &pj) -{ - CBotStack* pile1 = pj->AddStack(this); - CBotStack* pile2 = pile1; - - CBotVar* var1 = nullptr; - - // retrieves the variable fields and indexes according - if (!(static_cast(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false; - - pile1->SetState(1); - pile1->SetCopyVar(var1); // places the result (before incrementation); - - CBotStack* pile3 = pile2->AddStack(this); - if (pile3->IfStep()) return false; - - if (var1->IsNAN()) - { - pile1->SetError(TX_OPNAN, &m_token); - } - - if (!var1->IsDefined()) - { - pile1->SetError(TX_NOTINIT, &m_token); - } - - if (GetTokenType() == ID_INC) var1->Inc(); - else var1->Dec(); - - return pj->Return(pile1); // operation done, result on pile2 -} - -void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile1 = pj->RestoreStack(this); - if (pile1 == nullptr) return; - - (static_cast(m_Instr))->RestoreStateVar(pile1, bMain); - - if (pile1 != nullptr) pile1->RestoreStack(this); -} ////////////////////////////////////////////////////////////////////////////////////// // compile an unary expression diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 814183b9..6b27e563 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -900,21 +900,6 @@ public: void RestoreStateVar(CBotStack* &pj, bool bMain) override; }; -class CBotPostIncExpr : public CBotInstr -{ -private: - CBotInstr* m_Instr; - friend class CBotParExpr; - -public: - CBotPostIncExpr(); - ~CBotPostIncExpr(); -// static -// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp new file mode 100644 index 00000000..a0b24fc0 --- /dev/null +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -0,0 +1,85 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotPostIncExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotPostIncExpr::CBotPostIncExpr() +{ + m_Instr = nullptr; + name = "CBotPostIncExpr"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotPostIncExpr::~CBotPostIncExpr() +{ + delete m_Instr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotPostIncExpr::Execute(CBotStack* &pj) +{ + CBotStack* pile1 = pj->AddStack(this); + CBotStack* pile2 = pile1; + + CBotVar* var1 = nullptr; + + // retrieves the variable fields and indexes according + if (!(static_cast(m_Instr))->ExecuteVar(var1, pile2, nullptr, true)) return false; + + pile1->SetState(1); + pile1->SetCopyVar(var1); // places the result (before incrementation); + + CBotStack* pile3 = pile2->AddStack(this); + if (pile3->IfStep()) return false; + + if (var1->IsNAN()) + { + pile1->SetError(TX_OPNAN, &m_token); + } + + if (!var1->IsDefined()) + { + pile1->SetError(TX_NOTINIT, &m_token); + } + + if (GetTokenType() == ID_INC) var1->Inc(); + else var1->Dec(); + + return pj->Return(pile1); // operation done, result on pile2 +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile1 = pj->RestoreStack(this); + if (pile1 == nullptr) return; + + (static_cast(m_Instr))->RestoreStateVar(pile1, bMain); + + if (pile1 != nullptr) pile1->RestoreStack(this); +} diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.h b/src/CBot/CBotInstr/CBotPostIncExpr.h new file mode 100644 index 00000000..5a3240c8 --- /dev/null +++ b/src/CBot/CBotInstr/CBotPostIncExpr.h @@ -0,0 +1,69 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +////////////////////////////////////////////////////////////////////////////////////// +// Management of pre-and post increment / decrement +// There is no routine Compiles, the object is created directly +// Compiles in CBotParExpr :: + +/*! + * \brief The CBotPostIncExpr class + */ +class CBotPostIncExpr : public CBotInstr +{ + +public: + + /*! + * \brief CBotPostIncExpr + */ + CBotPostIncExpr(); + + /*! + * \brief ~CBotPostIncExpr + */ + ~CBotPostIncExpr(); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + CBotInstr* m_Instr; + friend class CBotParExpr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index b7c63490..158478b9 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -27,6 +27,7 @@ set(SOURCES CBotInstr/CBotExprBool.cpp CBotInstr/CBotLeftExprVar.cpp CBotInstr/CBotPreIncExpr.cpp + CBotInstr/CBotPostIncExpr.cpp ) # Includes From d708be50e736722c53abb257cf779d35ed2cb7f3 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 18:31:31 +0100 Subject: [PATCH 075/360] Moving CBotExprVar class in its own header and source files. --- src/CBot/CBot.cpp | 282 +---------------------- src/CBot/CBot.h | 23 -- src/CBot/CBotInstr/CBotExprVar.cpp | 301 +++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprVar.h | 101 +++++++++ src/CBot/CBotInstr/CBotPostIncExpr.cpp | 1 + src/CBot/CBotInstr/CBotPreIncExpr.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 7 files changed, 406 insertions(+), 304 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprVar.cpp create mode 100644 src/CBot/CBotInstr/CBotExprVar.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index b7c8287b..9dc07208 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -52,6 +52,7 @@ #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotPreIncExpr.h" #include "CBotInstr/CBotPostIncExpr.h" +#include "CBotInstr/CBotExprVar.h" // Local include @@ -2505,287 +2506,6 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) m_next3->RestoreStateVar(pile, bMain); } -////////////////////////////////////////////////////////////////////////////////////// -// compile a variable name -// check that it is known on the stack -// and it has been initialized - -CBotExprVar::CBotExprVar() -{ - name = "CBotExprVar"; - m_nIdent = 0; -} - -CBotExprVar::~CBotExprVar() -{ -} - -CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) -{ -// CBotToken* pDebut = p; - CBotCStack* pStk = pStack->TokenStack(); - - pStk->SetStartError(p->GetStart()); - - // is it a variable? - if (p->GetType() == TokenTypVar) - { - CBotInstr* inst = new CBotExprVar(); // create the object - - inst->SetToken(p); - - CBotVar* var; - - if (nullptr != (var = pStk->FindVar(p))) // seek if known variable - { - int ident = var->GetUniqNum(); - (static_cast(inst))->m_nIdent = ident; // identifies variable by its number - - if (ident > 0 && ident < 9000) - { - if ( var->IsPrivate(privat) && - !pStk->GetBotCall()->m_bCompileClass) - { - pStk->SetError(TX_PRIVATE, p); - goto err; - } - - // This is an element of the current class - // ads the equivalent of this. before - CBotToken token("this"); - inst->SetToken(&token); - (static_cast(inst))->m_nIdent = -2; // identificator for this - - CBotFieldExpr* i = new CBotFieldExpr(); // new element - i->SetToken(p); // keeps the name of the token - i->SetUniqNum(ident); - inst->AddNext3(i); // added after - } - - p = p->GetNext(); // next token - - while (true) - { - if (var->GetType() == CBotTypArrayPointer) - { - if (IsOfType( p, ID_OPBRK )) // check if there is an aindex - { - CBotIndexExpr* i = new CBotIndexExpr(); - i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula - inst->AddNext3(i); // add to the chain - - var = (static_cast(var))->GetItem(0,true); // gets the component [0] - - if (i->m_expr == nullptr) - { - pStk->SetError(TX_BADINDEX, p->GetStart()); - goto err; - } - if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto err; - } - continue; - } - } - if (var->GetType(1) == CBotTypPointer) // for classes - { - if (IsOfType(p, ID_DOT)) - { - CBotToken* pp = p; - - if (p->GetType() == TokenTypVar) // must be a name - { - if (p->GetNext()->GetType() == ID_OPENPAR) // a method call? - { - CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var); - if (!pStk->IsOk()) goto err; - inst->AddNext3(i); // added after - return pStack->Return(inst, pStk); - } - else - { - CBotFieldExpr* i = new CBotFieldExpr(); // new element - i->SetToken(pp); // keeps the name of the token - inst->AddNext3(i); // add after - var = var->GetItem(p->GetString()); // get item correspondent - if (var != nullptr) - { - i->SetUniqNum(var->GetUniqNum()); - if ( var->IsPrivate() && - !pStk->GetBotCall()->m_bCompileClass) - { - pStk->SetError(TX_PRIVATE, pp); - goto err; - } - } - } - - - if (var != nullptr) - { - p = p->GetNext(); // skips the name - continue; - } - pStk->SetError(TX_NOITEM, p); - goto err; - } - pStk->SetError(TX_DOT, p->GetStart()); - goto err; - } - } - - break; - } - - pStk->SetCopyVar(var); // place the copy of the variable on the stack (for type) - if (pStk->IsOk()) return pStack->Return(inst, pStk); - } - pStk->SetError(TX_UNDEFVAR, p); -err: - delete inst; - return pStack->Return(nullptr, pStk); - } - - return pStack->Return(nullptr, pStk); -} - -CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; - CBotCStack* pStk = pStack->TokenStack(); - - pStk->SetStartError(pp->GetStart()); - - // is it a variable ? - if (pp->GetType() == TokenTypVar) - { - CBotToken pthis("this"); - CBotVar* var = pStk->FindVar(pthis); - if (var == nullptr) return pStack->Return(nullptr, pStk); - - CBotInstr* inst = new CBotExprVar(); - - // this is an element of the current class - // adds the equivalent of this. before - - inst->SetToken(&pthis); - (static_cast(inst))->m_nIdent = -2; // ident for this - - CBotToken* pp = p; - - if (pp->GetType() == TokenTypVar) - { - if (pp->GetNext()->GetType() == ID_OPENPAR) // a method call? - { - CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var); - if (pStk->IsOk()) - { - inst->AddNext3(i); // add after - p = pp; // previous instruction - return pStack->Return(inst, pStk); - } - pStk->SetError(0,0); // the error is not adressed here - } - } - delete inst; - } - return pStack->Return(nullptr, pStk); -} - - -// execute, making the value of a variable - -bool CBotExprVar::Execute(CBotStack* &pj) -{ - CBotVar* pVar = nullptr; - CBotStack* pile = pj->AddStack(this); - - CBotStack* pile1 = pile; - - if (pile1->GetState() == 0) - { - if (!ExecuteVar(pVar, pile, nullptr, true)) return false; // Get the variable fields and indexes according - - if (pVar) pile1->SetCopyVar(pVar); // place a copy on the stack - else - { - return pj->Return(pile1); - } - pile1->IncState(); - } - - pVar = pile1->GetVar(); - - if (pVar == nullptr) - { - return pj->Return(pile1); - } - - if (pVar->IsUndefined()) - { - CBotToken* pt = &m_token; - while (pt->GetNext() != nullptr) pt = pt->GetNext(); - pile1->SetError(TX_NOTINIT, pt); - return pj->Return(pile1); - } - return pj->Return(pile1); // operation completed -} - -void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - CBotStack* pile1 = pile; - - if (pile1->GetState() == 0) - { - RestoreStateVar(pile, bMain); // retrieves the variable fields and indexes according - return; - } -} - -// fetch a variable at runtime - -bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep) -{ - CBotStack* pile = pj; - pj = pj->AddStack(this); - - if (bStep && m_nIdent>0 && pj->IfStep()) return false; - - pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary - if (pVar == nullptr) - { -#ifdef _DEBUG - assert(0); -#endif - pj->SetError(1, &m_token); - return false; - } - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, false) ) - return false; // field of an instance, table, methode - - return pile->ReturnKeep(pj); // does not put on stack but get the result if a method was called -} - - -// fetch variable at runtime - -void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain) -{ - pj = pj->RestoreStack(this); - if (pj == nullptr) return; - - if (m_next3 != nullptr) - m_next3->RestoreStateVar(pj, bMain); -} - ////////////////////////////////////////////////////////////////////////////////////////// // compile a list of parameters diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 6b27e563..ffd2273b 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -877,29 +877,6 @@ public: void RestoreStateVar(CBotStack* &pj, bool bMain) override; }; -// expression for the variable name - -class CBotExprVar : public CBotInstr -{ -private: - long m_nIdent; - friend class CBotPostIncExpr; - friend class CBotPreIncExpr; - -public: - CBotExprVar(); - ~CBotExprVar(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT); - static - CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack); - - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); - void RestoreStateVar(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp new file mode 100644 index 00000000..5e0c5683 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -0,0 +1,301 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprVar.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotExprVar::CBotExprVar() +{ + name = "CBotExprVar"; + m_nIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprVar::~CBotExprVar() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) +{ +// CBotToken* pDebut = p; + CBotCStack* pStk = pStack->TokenStack(); + + pStk->SetStartError(p->GetStart()); + + // is it a variable? + if (p->GetType() == TokenTypVar) + { + CBotInstr* inst = new CBotExprVar(); // create the object + + inst->SetToken(p); + + CBotVar* var; + + if (nullptr != (var = pStk->FindVar(p))) // seek if known variable + { + int ident = var->GetUniqNum(); + (static_cast(inst))->m_nIdent = ident; // identifies variable by its number + + if (ident > 0 && ident < 9000) + { + if ( var->IsPrivate(privat) && + !pStk->GetBotCall()->m_bCompileClass) + { + pStk->SetError(TX_PRIVATE, p); + goto err; + } + + // This is an element of the current class + // ads the equivalent of this. before + CBotToken token("this"); + inst->SetToken(&token); + (static_cast(inst))->m_nIdent = -2; // identificator for this + + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(p); // keeps the name of the token + i->SetUniqNum(ident); + inst->AddNext3(i); // added after + } + + p = p->GetNext(); // next token + + while (true) + { + if (var->GetType() == CBotTypArrayPointer) + { + if (IsOfType( p, ID_OPBRK )) // check if there is an aindex + { + CBotIndexExpr* i = new CBotIndexExpr(); + i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula + inst->AddNext3(i); // add to the chain + + var = (static_cast(var))->GetItem(0,true); // gets the component [0] + + if (i->m_expr == nullptr) + { + pStk->SetError(TX_BADINDEX, p->GetStart()); + goto err; + } + if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto err; + } + continue; + } + } + if (var->GetType(1) == CBotTypPointer) // for classes + { + if (IsOfType(p, ID_DOT)) + { + CBotToken* pp = p; + + if (p->GetType() == TokenTypVar) // must be a name + { + if (p->GetNext()->GetType() == ID_OPENPAR) // a method call? + { + CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var); + if (!pStk->IsOk()) goto err; + inst->AddNext3(i); // added after + return pStack->Return(inst, pStk); + } + else + { + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(pp); // keeps the name of the token + inst->AddNext3(i); // add after + var = var->GetItem(p->GetString()); // get item correspondent + if (var != nullptr) + { + i->SetUniqNum(var->GetUniqNum()); + if ( var->IsPrivate() && + !pStk->GetBotCall()->m_bCompileClass) + { + pStk->SetError(TX_PRIVATE, pp); + goto err; + } + } + } + + + if (var != nullptr) + { + p = p->GetNext(); // skips the name + continue; + } + pStk->SetError(TX_NOITEM, p); + goto err; + } + pStk->SetError(TX_DOT, p->GetStart()); + goto err; + } + } + + break; + } + + pStk->SetCopyVar(var); // place the copy of the variable on the stack (for type) + if (pStk->IsOk()) return pStack->Return(inst, pStk); + } + pStk->SetError(TX_UNDEFVAR, p); +err: + delete inst; + return pStack->Return(nullptr, pStk); + } + + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; + CBotCStack* pStk = pStack->TokenStack(); + + pStk->SetStartError(pp->GetStart()); + + // is it a variable ? + if (pp->GetType() == TokenTypVar) + { + CBotToken pthis("this"); + CBotVar* var = pStk->FindVar(pthis); + if (var == nullptr) return pStack->Return(nullptr, pStk); + + CBotInstr* inst = new CBotExprVar(); + + // this is an element of the current class + // adds the equivalent of this. before + + inst->SetToken(&pthis); + (static_cast(inst))->m_nIdent = -2; // ident for this + + CBotToken* pp = p; + + if (pp->GetType() == TokenTypVar) + { + if (pp->GetNext()->GetType() == ID_OPENPAR) // a method call? + { + CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var); + if (pStk->IsOk()) + { + inst->AddNext3(i); // add after + p = pp; // previous instruction + return pStack->Return(inst, pStk); + } + pStk->SetError(0,0); // the error is not adressed here + } + } + delete inst; + } + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprVar::Execute(CBotStack* &pj) +{ + CBotVar* pVar = nullptr; + CBotStack* pile = pj->AddStack(this); + + CBotStack* pile1 = pile; + + if (pile1->GetState() == 0) + { + if (!ExecuteVar(pVar, pile, nullptr, true)) return false; // Get the variable fields and indexes according + + if (pVar) pile1->SetCopyVar(pVar); // place a copy on the stack + else + { + return pj->Return(pile1); + } + pile1->IncState(); + } + + pVar = pile1->GetVar(); + + if (pVar == nullptr) + { + return pj->Return(pile1); + } + + if (pVar->IsUndefined()) + { + CBotToken* pt = &m_token; + while (pt->GetNext() != nullptr) pt = pt->GetNext(); + pile1->SetError(TX_NOTINIT, pt); + return pj->Return(pile1); + } + return pj->Return(pile1); // operation completed +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + CBotStack* pile1 = pile; + + if (pile1->GetState() == 0) + { + RestoreStateVar(pile, bMain); // retrieves the variable fields and indexes according + return; + } +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep) +{ + CBotStack* pile = pj; + pj = pj->AddStack(this); + + if (bStep && m_nIdent>0 && pj->IfStep()) return false; + + pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary + if (pVar == nullptr) + { +#ifdef _DEBUG + assert(0); +#endif + pj->SetError(1, &m_token); + return false; + } + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, false) ) + return false; // field of an instance, table, methode + + return pile->ReturnKeep(pj); // does not put on stack but get the result if a method was called +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain) +{ + pj = pj->RestoreStack(this); + if (pj == nullptr) return; + + if (m_next3 != nullptr) + m_next3->RestoreStateVar(pj, bMain); +} diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h new file mode 100644 index 00000000..46017e51 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprVar.h @@ -0,0 +1,101 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotExprVar class Expression for the variable name. Compile a + * variable name check that it is known on the stack and it has been initialized. + */ +class CBotExprVar : public CBotInstr +{ +public: + + /*! + * \brief CBotExprVar + */ + CBotExprVar(); + + /*! + * \brief ~CBotExprVar + */ + ~CBotExprVar(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param privat + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT); + + /*! + * \brief CompileMethode + * \param p + * \param pStack + * \return + */ + static CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execute, making the value of a variable. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + + /*! + * \brief ExecuteVar Fetch a variable at runtime. + * \param pVar + * \param pile + * \param prevToken + * \param bStep + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); + + /*! + * \brief RestoreStateVar Fetch variable at runtime. + * \param pj + * \param bMain + */ + void RestoreStateVar(CBotStack* &pj, bool bMain) override; + +private: + long m_nIdent; + friend class CBotPostIncExpr; + friend class CBotPreIncExpr; + +}; diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp index a0b24fc0..cb146ca4 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotPostIncExpr.h" +#include "CBotExprVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp index 700bbffa..073e0d4a 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotPreIncExpr.h" +#include "CBotExprVar.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 158478b9..2908c5e2 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -28,6 +28,7 @@ set(SOURCES CBotInstr/CBotLeftExprVar.cpp CBotInstr/CBotPreIncExpr.cpp CBotInstr/CBotPostIncExpr.cpp + CBotInstr/CBotExprVar.cpp ) # Includes From 631621fb7e20ebfa759af0f89cb4a36b2ed54055 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 18:39:04 +0100 Subject: [PATCH 076/360] Moving CBotInstrMethode class in its own header and source files. --- src/CBot/CBot.cpp | 250 ---------------------- src/CBot/CBot.h | 26 --- src/CBot/CBotInstr/CBotExprVar.cpp | 1 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 273 ++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstrMethode.h | 92 ++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 367 insertions(+), 276 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInstrMethode.cpp create mode 100644 src/CBot/CBotInstr/CBotInstrMethode.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 9dc07208..b60bb7df 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -2565,256 +2565,6 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) return ret; } -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compile a method call - -CBotInstrMethode::CBotInstrMethode() -{ - m_Parameters = nullptr; - m_MethodeIdent = 0; - name = "CBotInstrMethode"; -} - -CBotInstrMethode::~CBotInstrMethode() -{ - delete m_Parameters; -} - -CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* var) -{ - CBotInstrMethode* inst = new CBotInstrMethode(); - inst->SetToken(p); // corresponding token - - if (nullptr != var) - { - CBotToken* pp = p; - p = p->GetNext(); - - if (p->GetType() == ID_OPENPAR) - { - inst->m_NomMethod = pp->GetString(); - - // compiles the list of parameters - CBotVar* ppVars[1000]; - inst->m_Parameters = CompileParams(p, pStack, ppVars); - - if (pStack->IsOk()) - { - CBotClass* pClass = var->GetClass(); // pointer to the class - inst->m_ClassName = pClass->GetName(); // name of the class - CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars, - pStack, inst->m_MethodeIdent); - delete pStack->TokenStack(); // release parameters on the stack - inst->m_typRes = r; - - if (inst->m_typRes.GetType() > 20) - { - pStack->SetError(inst->m_typRes.GetType(), pp); - delete inst; - return nullptr; - } - // put the result on the stack to have something - if (inst->m_typRes.GetType() > 0) - { - CBotVar* pResult = CBotVar::Create("", inst->m_typRes); - if (inst->m_typRes.Eq(CBotTypClass)) - { - pResult->SetClass(inst->m_typRes.GetClass()); - } - pStack->SetVar(pResult); - } - return inst; - } - delete inst; - return nullptr; - } - } - pStack->SetError(1234, p); - delete inst; - return nullptr; -} - -// execute the method call - -bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) -{ - CBotVar* ppVars[1000]; - CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This - - if (pVar->GetPointer() == nullptr) - { - pj->SetError(TX_NULLPT, prevToken); - } - - if (pile1->IfStep()) return false; - - CBotStack* pile2 = pile1->AddStack(); // for the next parameters - - if ( pile1->GetState() == 0) - { - CBotVar* pThis = CBotVar::Create(pVar); - pThis->Copy(pVar); - // this value should be taken before the evaluation parameters - // Test.Action (Test = Other); - // action must act on the value before test = Other! - - pThis->SetName("this"); - pThis->SetUniqNum(-2); - pile1->AddVar(pThis); - pile1->IncState(); - } - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluate the parameters - // and places the values on the stack - // to be interrupted at any time - - if (p != nullptr) while ( true) - { - if (pile2->GetState() == 0) - { - if (!p->Execute(pile2)) return false; // interrupted here? - if (!pile2->SetState(1)) return false; // special mark to recognize parameters - } - ppVars[i++] = pile2->GetVar(); // construct the list of pointers - pile2 = pile2->AddStack(); // space on the stack for the result - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - CBotClass* pClass = CBotClass::Find(m_ClassName); - CBotVar* pThis = pile1->FindVar(-2); - CBotVar* pResult = nullptr; - if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes); - if (m_typRes.Eq(CBotTypClass)) - { - pResult->SetClass(m_typRes.GetClass()); - } - CBotVar* pRes = pResult; - - if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, - pResult, pile2, GetToken())) return false; - if (pRes != pResult) delete pRes; - - pVar = nullptr; // does not return value for this - return pj->Return(pile2); // release the entire stack -} - -void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) -{ - if (!bMain) return; - - CBotVar* ppVars[1000]; - CBotStack* pile1 = pile->RestoreStack(this); // place for the copy of This - if (pile1 == nullptr) return; - - CBotStack* pile2 = pile1->RestoreStack(); // and for the parameters coming - if (pile2 == nullptr) return; - - CBotVar* pThis = pile1->FindVar("this"); - pThis->SetUniqNum(-2); - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluate the parameters - // and places the values on the stack - // to be interrupted at any time - - if (p != nullptr) while ( true) - { - if (pile2->GetState() == 0) - { - p->RestoreState(pile2, true); // interrupted here! - return; - } - ppVars[i++] = pile2->GetVar(); // construct the list of pointers - pile2 = pile2->RestoreStack(); - if (pile2 == nullptr) return; - - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - CBotClass* pClass = CBotClass::Find(m_ClassName); -// CBotVar* pResult = nullptr; - -// CBotVar* pRes = pResult; - - pClass->RestoreMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, pile2); -} - - -bool CBotInstrMethode::Execute(CBotStack* &pj) -{ - CBotVar* ppVars[1000]; - CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This - - if (pile1->IfStep()) return false; - - CBotStack* pile2 = pile1->AddStack(); // and for the parameters coming - - if ( pile1->GetState() == 0) - { - CBotVar* pThis = pile1->CopyVar(m_token); - // this value should be taken before the evaluation parameters - // Test.Action (Test = Other); - // Action must act on the value before test = Other! - pThis->SetName("this"); - pile1->AddVar(pThis); - pile1->IncState(); - } - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluate the parameters - // and places the values on the stack - // to be interrupted at any time - if (p != nullptr) while ( true) - { - if (pile2->GetState() == 0) - { - if (!p->Execute(pile2)) return false; // interrupted here? - if (!pile2->SetState(1)) return false; // special mark to recognize parameters - } - ppVars[i++] = pile2->GetVar(); // construct the list of pointers - pile2 = pile2->AddStack(); // space on the stack for the results - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - CBotClass* pClass = CBotClass::Find(m_ClassName); - CBotVar* pThis = pile1->FindVar("this"); - CBotVar* pResult = nullptr; - if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes); - if (m_typRes.Eq(CBotTypClass)) - { - pResult->SetClass(m_typRes.GetClass()); - } - CBotVar* pRes = pResult; - - if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, - pResult, pile2, GetToken())) return false; // interupted - - // set the new value of this in place of the old variable - CBotVar* old = pile1->FindVar(m_token); - old->Copy(pThis, false); - - if (pRes != pResult) delete pRes; - - return pj->Return(pile2); // release the entire stack -} - ///////////////////////////////////////////////////////////// // check if two results are consistent to make an operation diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index ffd2273b..41d961f4 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -851,32 +851,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -// a call of method - -class CBotInstrMethode : public CBotInstr -{ -private: - CBotInstr* m_Parameters; // the parameters to be evaluated -// int m_typeRes; // type of the result -// CBotString m_RetClassName; // class of the result - CBotTypResult - m_typRes; // complete type of the result - - CBotString m_NomMethod; // name of the method - long m_MethodeIdent; // identifier of the method -// long m_nThisIdent; // identifier for "this" - CBotString m_ClassName; // name of the class - -public: - CBotInstrMethode(); - ~CBotInstrMethode(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar); - bool Execute(CBotStack* &pj) override; - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) override; - void RestoreStateVar(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 5e0c5683..57b2b431 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotExprVar.h" +#include "CBotInstrMethode.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp new file mode 100644 index 00000000..e35c0f25 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -0,0 +1,273 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInstrMethode.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstrMethode::CBotInstrMethode() +{ + m_Parameters = nullptr; + m_MethodeIdent = 0; + name = "CBotInstrMethode"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstrMethode::~CBotInstrMethode() +{ + delete m_Parameters; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* var) +{ + CBotInstrMethode* inst = new CBotInstrMethode(); + inst->SetToken(p); // corresponding token + + if (nullptr != var) + { + CBotToken* pp = p; + p = p->GetNext(); + + if (p->GetType() == ID_OPENPAR) + { + inst->m_NomMethod = pp->GetString(); + + // compiles the list of parameters + CBotVar* ppVars[1000]; + inst->m_Parameters = CompileParams(p, pStack, ppVars); + + if (pStack->IsOk()) + { + CBotClass* pClass = var->GetClass(); // pointer to the class + inst->m_ClassName = pClass->GetName(); // name of the class + CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars, + pStack, inst->m_MethodeIdent); + delete pStack->TokenStack(); // release parameters on the stack + inst->m_typRes = r; + + if (inst->m_typRes.GetType() > 20) + { + pStack->SetError(inst->m_typRes.GetType(), pp); + delete inst; + return nullptr; + } + // put the result on the stack to have something + if (inst->m_typRes.GetType() > 0) + { + CBotVar* pResult = CBotVar::Create("", inst->m_typRes); + if (inst->m_typRes.Eq(CBotTypClass)) + { + pResult->SetClass(inst->m_typRes.GetClass()); + } + pStack->SetVar(pResult); + } + return inst; + } + delete inst; + return nullptr; + } + } + pStack->SetError(1234, p); + delete inst; + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) +{ + CBotVar* ppVars[1000]; + CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This + + if (pVar->GetPointer() == nullptr) + { + pj->SetError(TX_NULLPT, prevToken); + } + + if (pile1->IfStep()) return false; + + CBotStack* pile2 = pile1->AddStack(); // for the next parameters + + if ( pile1->GetState() == 0) + { + CBotVar* pThis = CBotVar::Create(pVar); + pThis->Copy(pVar); + // this value should be taken before the evaluation parameters + // Test.Action (Test = Other); + // action must act on the value before test = Other! + + pThis->SetName("this"); + pThis->SetUniqNum(-2); + pile1->AddVar(pThis); + pile1->IncState(); + } + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time + + if (p != nullptr) while ( true) + { + if (pile2->GetState() == 0) + { + if (!p->Execute(pile2)) return false; // interrupted here? + if (!pile2->SetState(1)) return false; // special mark to recognize parameters + } + ppVars[i++] = pile2->GetVar(); // construct the list of pointers + pile2 = pile2->AddStack(); // space on the stack for the result + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + CBotClass* pClass = CBotClass::Find(m_ClassName); + CBotVar* pThis = pile1->FindVar(-2); + CBotVar* pResult = nullptr; + if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes); + if (m_typRes.Eq(CBotTypClass)) + { + pResult->SetClass(m_typRes.GetClass()); + } + CBotVar* pRes = pResult; + + if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, + pThis, ppVars, + pResult, pile2, GetToken())) return false; + if (pRes != pResult) delete pRes; + + pVar = nullptr; // does not return value for this + return pj->Return(pile2); // release the entire stack +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) +{ + if (!bMain) return; + + CBotVar* ppVars[1000]; + CBotStack* pile1 = pile->RestoreStack(this); // place for the copy of This + if (pile1 == nullptr) return; + + CBotStack* pile2 = pile1->RestoreStack(); // and for the parameters coming + if (pile2 == nullptr) return; + + CBotVar* pThis = pile1->FindVar("this"); + pThis->SetUniqNum(-2); + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time + + if (p != nullptr) while ( true) + { + if (pile2->GetState() == 0) + { + p->RestoreState(pile2, true); // interrupted here! + return; + } + ppVars[i++] = pile2->GetVar(); // construct the list of pointers + pile2 = pile2->RestoreStack(); + if (pile2 == nullptr) return; + + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + CBotClass* pClass = CBotClass::Find(m_ClassName); +// CBotVar* pResult = nullptr; + +// CBotVar* pRes = pResult; + + pClass->RestoreMethode(m_MethodeIdent, m_NomMethod, + pThis, ppVars, pile2); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstrMethode::Execute(CBotStack* &pj) +{ + CBotVar* ppVars[1000]; + CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This + + if (pile1->IfStep()) return false; + + CBotStack* pile2 = pile1->AddStack(); // and for the parameters coming + + if ( pile1->GetState() == 0) + { + CBotVar* pThis = pile1->CopyVar(m_token); + // this value should be taken before the evaluation parameters + // Test.Action (Test = Other); + // Action must act on the value before test = Other! + pThis->SetName("this"); + pile1->AddVar(pThis); + pile1->IncState(); + } + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time + if (p != nullptr) while ( true) + { + if (pile2->GetState() == 0) + { + if (!p->Execute(pile2)) return false; // interrupted here? + if (!pile2->SetState(1)) return false; // special mark to recognize parameters + } + ppVars[i++] = pile2->GetVar(); // construct the list of pointers + pile2 = pile2->AddStack(); // space on the stack for the results + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + CBotClass* pClass = CBotClass::Find(m_ClassName); + CBotVar* pThis = pile1->FindVar("this"); + CBotVar* pResult = nullptr; + if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes); + if (m_typRes.Eq(CBotTypClass)) + { + pResult->SetClass(m_typRes.GetClass()); + } + CBotVar* pRes = pResult; + + if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, + pThis, ppVars, + pResult, pile2, GetToken())) return false; // interupted + + // set the new value of this in place of the old variable + CBotVar* old = pile1->FindVar(m_token); + old->Copy(pThis, false); + + if (pRes != pResult) delete pRes; + + return pj->Return(pile2); // release the entire stack +} diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h new file mode 100644 index 00000000..ca4ad90b --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrMethode.h @@ -0,0 +1,92 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotInstrMethode class A call of method. Compile a method call. + */ +class CBotInstrMethode : public CBotInstr +{ +public: + + /*! + * \brief CBotInstrMethode + */ + CBotInstrMethode(); + + /*! + * \brief ~CBotInstrMethode + */ + ~CBotInstrMethode(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param pVar + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief ExecuteVar Execute the method call. + * \param pVar + * \param pj + * \param prevToken + * \param bStep + * \param bExtend + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) override; + + /*! + * \brief RestoreStateVar + * \param pj + * \param bMain + */ + void RestoreStateVar(CBotStack* &pj, bool bMain) override; + +private: + //! The parameters to be evaluated. + CBotInstr *m_Parameters; + //! Complete type of the result. + CBotTypResult m_typRes; + //! Name of the method. + CBotString m_NomMethod; + //! Identifier of the method. + long m_MethodeIdent; + //! Name of the class. + CBotString m_ClassName; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 2908c5e2..bca48c36 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -29,6 +29,7 @@ set(SOURCES CBotInstr/CBotPreIncExpr.cpp CBotInstr/CBotPostIncExpr.cpp CBotInstr/CBotExprVar.cpp + CBotInstr/CBotInstrMethode.cpp ) # Includes From 0216359445f44395183282cf12ace51d06716515 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 19:14:45 +0100 Subject: [PATCH 077/360] Moving CBotInstrCall class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 18 --- src/CBot/CBotFunction.cpp | 173 ----------------------- src/CBot/CBotInstr/CBotInstrCall.cpp | 201 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstrCall.h | 76 ++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 279 insertions(+), 191 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInstrCall.cpp create mode 100644 src/CBot/CBotInstr/CBotInstrCall.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index b60bb7df..8eb59b8e 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -53,6 +53,7 @@ #include "CBotInstr/CBotPreIncExpr.h" #include "CBotInstr/CBotPostIncExpr.h" #include "CBotInstr/CBotExprVar.h" +#include "CBotInstr/CBotInstrCall.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 41d961f4..809617e5 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -832,24 +832,6 @@ public: }; -class CBotInstrCall : public CBotInstr -{ -private: - CBotInstr* m_Parameters; // the parameters to be evaluated -// int m_typeRes; // type of the result -// CBotString m_RetClassName; // class of the result - CBotTypResult - m_typRes; // complete type of the result - long m_nFuncIdent; // id of a function - -public: - CBotInstrCall(); - ~CBotInstrCall(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index ff92ba48..226add20 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -1186,179 +1186,6 @@ void CBotReturn::RestoreState(CBotStack* &pj, bool bMain) } } -//////////////////////////////////////////////////////////////////////////////// -// Calls of these functions - -CBotInstrCall::CBotInstrCall() -{ - m_Parameters = nullptr; - m_nFuncIdent = 0; - name = "CBotInstrCall"; -} - -CBotInstrCall::~CBotInstrCall() -{ - delete m_Parameters; -} - -CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotVar* ppVars[1000]; - - int i = 0; - - CBotToken* pp = p; - p = p->GetNext(); - - pStack->SetStartError(p->GetStart()); - CBotCStack* pile = pStack; - - if ( IsOfType(p, ID_OPENPAR) ) - { - int start, end; - CBotInstrCall* inst = new CBotInstrCall(); - inst->SetToken(pp); - - // compile la list of parameters - if (!IsOfType(p, ID_CLOSEPAR)) while (true) - { - start = p->GetStart(); - pile = pile->TokenStack(); // keeps the results on the stack - - CBotInstr* param = CBotExpression::Compile(p, pile); - end = p->GetStart(); - if ( inst->m_Parameters == nullptr ) inst->m_Parameters = param; - else inst->m_Parameters->AddNext(param); // constructs the list - - if ( !pile->IsOk() ) - { - delete inst; - return pStack->Return(nullptr, pile); - } - - if ( param != nullptr ) - { - if ( pile->GetTypResult().Eq(99) ) - { - delete pStack->TokenStack(); - pStack->SetError(TX_VOID, p->GetStart()); - delete inst; - return nullptr; - } - ppVars[i] = pile->GetVar(); - ppVars[i]->GetToken()->SetPos(start, end); - i++; - - if (IsOfType(p, ID_COMMA)) continue; // skips the comma - if (IsOfType(p, ID_CLOSEPAR)) break; - } - - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - delete pStack->TokenStack(); - delete inst; - return nullptr; - } - ppVars[i] = nullptr; - - // the routine is known? -// CBotClass* pClass = nullptr; - inst->m_typRes = pStack->CompileCall(pp, ppVars, inst->m_nFuncIdent); - if ( inst->m_typRes.GetType() >= 20 ) - { -// if (pVar2!=nullptr) pp = pVar2->RetToken(); - pStack->SetError( inst->m_typRes.GetType(), pp ); - delete pStack->TokenStack(); - delete inst; - return nullptr; - } - - delete pStack->TokenStack(); - if ( inst->m_typRes.GetType() > 0 ) - { - CBotVar* pRes = CBotVar::Create("", inst->m_typRes); - pStack->SetVar(pRes); // for knowing the type of the result - } - else pStack->SetVar(nullptr); // routine returns void - - return inst; - } - p = pp; - delete pStack->TokenStack(); - return nullptr; -} - -bool CBotInstrCall::Execute(CBotStack* &pj) -{ - CBotVar* ppVars[1000]; - CBotStack* pile = pj->AddStack(this); - if ( pile->StackOver() ) return pj->Return( pile ); - -// CBotStack* pile1 = pile; - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluates parameters - // and places the values ​​on the stack - // for allow of interruption at any time - if ( p != nullptr) while ( true ) - { - pile = pile->AddStack(); // place on the stack for the results - if ( pile->GetState() == 0 ) - { - if (!p->Execute(pile)) return false; // interrupted here? - pile->SetState(1); // mark as special for reknowed parameters \TODO marque spéciale pour reconnaîre parameters - } - ppVars[i++] = pile->GetVar(); - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - CBotStack* pile2 = pile->AddStack(); - if ( pile2->IfStep() ) return false; - - if ( !pile2->ExecuteCall(m_nFuncIdent, GetToken(), ppVars, m_typRes)) return false; // interrupt - - return pj->Return(pile2); // release the entire stack -} - -void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pile = pj->RestoreStack(this); - if ( pile == nullptr ) return; - -// CBotStack* pile1 = pile; - - int i = 0; - CBotVar* ppVars[1000]; - CBotInstr* p = m_Parameters; - // evaluate parameters - // and place the values on the stack - // for allow of interruption at any time - if ( p != nullptr) while ( true ) - { - pile = pile->RestoreStack(); // place on the stack for the results - if ( pile == nullptr ) return; - if ( pile->GetState() == 0 ) - { - p->RestoreState(pile, bMain); // interrupt here! - return; - } - ppVars[i++] = pile->GetVar(); // constructs the list of parameters - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - CBotStack* pile2 = pile->RestoreStack(); - if ( pile2 == nullptr ) return; - - pile2->RestoreCall(m_nFuncIdent, GetToken(), ppVars); -} - ////////////////////////////////////////////////////////////////////////////// // statement of user classes diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp new file mode 100644 index 00000000..66a48e34 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -0,0 +1,201 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInstrCall.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstrCall::CBotInstrCall() +{ + m_Parameters = nullptr; + m_nFuncIdent = 0; + name = "CBotInstrCall"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstrCall::~CBotInstrCall() +{ + delete m_Parameters; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotVar* ppVars[1000]; + + int i = 0; + + CBotToken* pp = p; + p = p->GetNext(); + + pStack->SetStartError(p->GetStart()); + CBotCStack* pile = pStack; + + if ( IsOfType(p, ID_OPENPAR) ) + { + int start, end; + CBotInstrCall* inst = new CBotInstrCall(); + inst->SetToken(pp); + + // compile la list of parameters + if (!IsOfType(p, ID_CLOSEPAR)) while (true) + { + start = p->GetStart(); + pile = pile->TokenStack(); // keeps the results on the stack + + CBotInstr* param = CBotExpression::Compile(p, pile); + end = p->GetStart(); + if ( inst->m_Parameters == nullptr ) inst->m_Parameters = param; + else inst->m_Parameters->AddNext(param); // constructs the list + + if ( !pile->IsOk() ) + { + delete inst; + return pStack->Return(nullptr, pile); + } + + if ( param != nullptr ) + { + if ( pile->GetTypResult().Eq(99) ) + { + delete pStack->TokenStack(); + pStack->SetError(TX_VOID, p->GetStart()); + delete inst; + return nullptr; + } + ppVars[i] = pile->GetVar(); + ppVars[i]->GetToken()->SetPos(start, end); + i++; + + if (IsOfType(p, ID_COMMA)) continue; // skips the comma + if (IsOfType(p, ID_CLOSEPAR)) break; + } + + pStack->SetError(TX_CLOSEPAR, p->GetStart()); + delete pStack->TokenStack(); + delete inst; + return nullptr; + } + ppVars[i] = nullptr; + + // the routine is known? +// CBotClass* pClass = nullptr; + inst->m_typRes = pStack->CompileCall(pp, ppVars, inst->m_nFuncIdent); + if ( inst->m_typRes.GetType() >= 20 ) + { +// if (pVar2!=nullptr) pp = pVar2->RetToken(); + pStack->SetError( inst->m_typRes.GetType(), pp ); + delete pStack->TokenStack(); + delete inst; + return nullptr; + } + + delete pStack->TokenStack(); + if ( inst->m_typRes.GetType() > 0 ) + { + CBotVar* pRes = CBotVar::Create("", inst->m_typRes); + pStack->SetVar(pRes); // for knowing the type of the result + } + else pStack->SetVar(nullptr); // routine returns void + + return inst; + } + p = pp; + delete pStack->TokenStack(); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstrCall::Execute(CBotStack* &pj) +{ + CBotVar* ppVars[1000]; + CBotStack* pile = pj->AddStack(this); + if ( pile->StackOver() ) return pj->Return( pile ); + +// CBotStack* pile1 = pile; + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluates parameters + // and places the values ​​on the stack + // for allow of interruption at any time + if ( p != nullptr) while ( true ) + { + pile = pile->AddStack(); // place on the stack for the results + if ( pile->GetState() == 0 ) + { + if (!p->Execute(pile)) return false; // interrupted here? + pile->SetState(1); // mark as special for reknowed parameters \TODO marque spéciale pour reconnaîre parameters + } + ppVars[i++] = pile->GetVar(); + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + CBotStack* pile2 = pile->AddStack(); + if ( pile2->IfStep() ) return false; + + if ( !pile2->ExecuteCall(m_nFuncIdent, GetToken(), ppVars, m_typRes)) return false; // interrupt + + return pj->Return(pile2); // release the entire stack +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pile = pj->RestoreStack(this); + if ( pile == nullptr ) return; + +// CBotStack* pile1 = pile; + + int i = 0; + CBotVar* ppVars[1000]; + CBotInstr* p = m_Parameters; + // evaluate parameters + // and place the values on the stack + // for allow of interruption at any time + if ( p != nullptr) while ( true ) + { + pile = pile->RestoreStack(); // place on the stack for the results + if ( pile == nullptr ) return; + if ( pile->GetState() == 0 ) + { + p->RestoreState(pile, bMain); // interrupt here! + return; + } + ppVars[i++] = pile->GetVar(); // constructs the list of parameters + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + CBotStack* pile2 = pile->RestoreStack(); + if ( pile2 == nullptr ) return; + + pile2->RestoreCall(m_nFuncIdent, GetToken(), ppVars); +} diff --git a/src/CBot/CBotInstr/CBotInstrCall.h b/src/CBot/CBotInstr/CBotInstrCall.h new file mode 100644 index 00000000..7e194f8a --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrCall.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotInstrCall class Calls of these functions. + */ +class CBotInstrCall : public CBotInstr +{ +public: + + /*! + * \brief CBotInstrCall + */ + CBotInstrCall(); + + /*! + * \brief ~CBotInstrCall + */ + ~CBotInstrCall(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! The parameters to be evaluated. + CBotInstr* m_Parameters; + //! Complete type of the result. + CBotTypResult m_typRes; + //! Id of a function. + long m_nFuncIdent; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index bca48c36..0ba14397 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -30,6 +30,7 @@ set(SOURCES CBotInstr/CBotPostIncExpr.cpp CBotInstr/CBotExprVar.cpp CBotInstr/CBotInstrMethode.cpp + CBotInstr/CBotInstrCall.cpp ) # Includes From 840da007a9e0075e77dc53187b45bee7bd5ee50c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 19:25:12 +0100 Subject: [PATCH 078/360] Moving CBotListInstr class in its own header and source files. --- src/CBot/CBot.cpp | 96 +--------------------- src/CBot/CBot.h | 18 ----- src/CBot/CBotInstr/CBotListInstr.cpp | 117 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotListInstr.h | 74 +++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 193 insertions(+), 113 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotListInstr.cpp create mode 100644 src/CBot/CBotInstr/CBotListInstr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 8eb59b8e..98e04d9c 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -54,6 +54,7 @@ #include "CBotInstr/CBotPostIncExpr.h" #include "CBotInstr/CBotExprVar.h" #include "CBotInstr/CBotInstrCall.h" +#include "CBotInstr/CBotListInstr.h" // Local include @@ -408,101 +409,6 @@ CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool b // where the variable x is known only in the block following the if -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compiles a list of instructions separated by semicolons - -CBotListInstr::CBotListInstr() -{ - m_Instr = nullptr; - name = "CBotListInstr"; -} - -CBotListInstr::~CBotListInstr() -{ - delete m_Instr; -} - -CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) -{ - CBotCStack* pStk = pStack->TokenStack(p, bLocal); // variables are local - - CBotListInstr* inst = new CBotListInstr(); - - while (true) - { - if (p == nullptr) break; - - if (IsOfType(p, ID_SEP)) continue; // empty statement ignored - if (p->GetType() == ID_CLBLK) break; - - if (IsOfType(p, 0)) - { - pStack->SetError(TX_CLOSEBLK, p->GetStart()); - delete inst; - return pStack->Return(nullptr, pStk); - } - - CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk); // compiles next - - if (!pStk->IsOk()) - { - delete inst; - return pStack->Return(nullptr, pStk); - } - - if (inst->m_Instr == nullptr) inst->m_Instr = i; - else inst->m_Instr->AddNext(i); // added a result - } - return pStack->Return(inst, pStk); -} - -// executes a set of instructions - -bool CBotListInstr::Execute(CBotStack* &pj) -{ - - CBotStack* pile = pj->AddStack(this, true); //needed for SetState() - if (pile->StackOver() ) return pj->Return( pile); - - - CBotInstr* p = m_Instr; // the first expression - - int state = pile->GetState(); - while (state-->0) p = p->GetNext(); // returns to the interrupted operation - - if (p != nullptr) while (true) - { - if (!p->Execute(pile)) return false; - p = p->GetNext(); - if (p == nullptr) break; - (void)pile->IncState(); // ready for next - } - - return pj->Return(pile); -} - -void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - CBotInstr* p = m_Instr; // the first expression - - int state = pile->GetState(); - while ( p != nullptr && state-- > 0) - { - p->RestoreState(pile, false); - p = p->GetNext(); // returns to the interrupted operation - } - - if (p != nullptr) p->RestoreState(pile, true); -} - ////////////////////////////////////////////////////////////////////////////////////// // defining an array of any type // int a[12]; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 809617e5..326a79ec 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -815,24 +815,6 @@ private: CBotBlock(const CBotBlock &) = delete; }; - -// the content of a block of instructions ... ; ... ; ... ; ... ; -class CBotListInstr : public CBotInstr -{ -private: - CBotInstr* m_Instr; // instructions to do - -public: - CBotListInstr(); - ~CBotListInstr(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp new file mode 100644 index 00000000..3d1d9c57 --- /dev/null +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -0,0 +1,117 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotListInstr.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotListInstr::CBotListInstr() +{ + m_Instr = nullptr; + name = "CBotListInstr"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotListInstr::~CBotListInstr() +{ + delete m_Instr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) +{ + CBotCStack* pStk = pStack->TokenStack(p, bLocal); // variables are local + + CBotListInstr* inst = new CBotListInstr(); + + while (true) + { + if (p == nullptr) break; + + if (IsOfType(p, ID_SEP)) continue; // empty statement ignored + if (p->GetType() == ID_CLBLK) break; + + if (IsOfType(p, 0)) + { + pStack->SetError(TX_CLOSEBLK, p->GetStart()); + delete inst; + return pStack->Return(nullptr, pStk); + } + + CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk); // compiles next + + if (!pStk->IsOk()) + { + delete inst; + return pStack->Return(nullptr, pStk); + } + + if (inst->m_Instr == nullptr) inst->m_Instr = i; + else inst->m_Instr->AddNext(i); // added a result + } + return pStack->Return(inst, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotListInstr::Execute(CBotStack* &pj) +{ + + CBotStack* pile = pj->AddStack(this, true); //needed for SetState() + if (pile->StackOver() ) return pj->Return( pile); + + + CBotInstr* p = m_Instr; // the first expression + + int state = pile->GetState(); + while (state-->0) p = p->GetNext(); // returns to the interrupted operation + + if (p != nullptr) while (true) + { + if (!p->Execute(pile)) return false; + p = p->GetNext(); + if (p == nullptr) break; + (void)pile->IncState(); // ready for next + } + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + CBotInstr* p = m_Instr; // the first expression + + int state = pile->GetState(); + while ( p != nullptr && state-- > 0) + { + p->RestoreState(pile, false); + p = p->GetNext(); // returns to the interrupted operation + } + + if (p != nullptr) p->RestoreState(pile, true); +} diff --git a/src/CBot/CBotInstr/CBotListInstr.h b/src/CBot/CBotInstr/CBotListInstr.h new file mode 100644 index 00000000..763c3a88 --- /dev/null +++ b/src/CBot/CBotInstr/CBotListInstr.h @@ -0,0 +1,74 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotListInstr class Compiles a list of instructions separated by + * semicolons eg : ... ; ... ; ... ; ... ; + */ +class CBotListInstr : public CBotInstr +{ +public: + + /*! + * \brief CBotListInstr + */ + CBotListInstr(); + + /*! + * \brief ~CBotListInstr + */ + ~CBotListInstr(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param bLocal + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); + + /*! + * \brief Execute Executes a set of instructions. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Instructions to do. + CBotInstr* m_Instr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 0ba14397..30e717be 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCES CBotInstr/CBotExprVar.cpp CBotInstr/CBotInstrMethode.cpp CBotInstr/CBotInstrCall.cpp + CBotInstr/CBotListInstr.cpp ) # Includes From 8eff62a78cf9ee1c45e226112844118e073773f1 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 19:53:00 +0100 Subject: [PATCH 079/360] Moving CBotBlock class in its own header and source files. --- src/CBot/CBot.cpp | 52 --------------------- src/CBot/CBot.h | 16 ------- src/CBot/CBotFunction.cpp | 2 + src/CBot/CBotIf.cpp | 2 + src/CBot/CBotInstr/CBotBlock.cpp | 69 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotBlock.h | 64 ++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotCatch.cpp | 1 + src/CBot/CBotInstr/CBotDo.cpp | 1 + src/CBot/CBotInstr/CBotFor.cpp | 1 + src/CBot/CBotInstr/CBotListInstr.cpp | 1 + src/CBot/CBotInstr/CBotSwitch.cpp | 1 + src/CBot/CBotInstr/CBotTry.cpp | 1 + src/CBot/CBotInstr/CBotWhile.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 14 files changed, 145 insertions(+), 68 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotBlock.cpp create mode 100644 src/CBot/CBotInstr/CBotBlock.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 98e04d9c..042e4c74 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -357,58 +357,6 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val) return false; } -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compiles a statement block " { i ; i ; } " - -// this class have no constructor because there is never an instance of this -// class -// the object returned by Compile is usually of type CBotListInstr - - -CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) -{ - pStack->SetStartError(p->GetStart()); - - if (IsOfType(p, ID_OPBLK)) - { - CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal); - - if (IsOfType(p, ID_CLBLK)) - { - return inst; - } - - pStack->SetError(TX_CLOSEBLK, p->GetStart()); // missing parenthesis - delete inst; - return nullptr; - } - - pStack->SetError(TX_OPENBLK, p->GetStart()); - return nullptr; -} - -CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal) -{ - // is this a new block - if (p->GetType() == ID_OPBLK) return CBotBlock::Compile(p, pStack); - - // otherwise, look for a single statement instead - - // to handle the case with local definition instruction (*) - CBotCStack* pStk = pStack->TokenStack(p, bLocal); - - return pStack->Return( CBotInstr::Compile(p, pStk), // a single instruction - pStk); -} - -// (*) is the case in the following statement -// if (1 == 1) int x = 0; -// where the variable x is known only in the block following the if - - ////////////////////////////////////////////////////////////////////////////////////// // defining an array of any type // int a[12]; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 326a79ec..32cdb695 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -799,22 +799,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - - - -// an instruction block { .... } -class CBotBlock : public CBotInstr -{ -public: - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); - static - CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false); -private: - CBotBlock() = delete; - CBotBlock(const CBotBlock &) = delete; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 226add20..6ebad172 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -23,6 +23,8 @@ #include "CBot.h" +#include "CBotInstr/CBotBlock.h" + #include diff --git a/src/CBot/CBotIf.cpp b/src/CBot/CBotIf.cpp index 15770af4..781ec12c 100644 --- a/src/CBot/CBotIf.cpp +++ b/src/CBot/CBotIf.cpp @@ -22,6 +22,8 @@ #include "CBot.h" +#include "CBotInstr/CBotBlock.h" + // various constructors / destructors CBotIf::CBotIf() { diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp new file mode 100644 index 00000000..ed87b53b --- /dev/null +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -0,0 +1,69 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotBlock.h" +#include "CBotListInstr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) +{ + pStack->SetStartError(p->GetStart()); + + if (IsOfType(p, ID_OPBLK)) + { + CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal); + + if (IsOfType(p, ID_CLBLK)) + { + return inst; + } + + pStack->SetError(TX_CLOSEBLK, p->GetStart()); // missing parenthesis + delete inst; + return nullptr; + } + + pStack->SetError(TX_OPENBLK, p->GetStart()); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal) +{ + // is this a new block + if (p->GetType() == ID_OPBLK) return CBotBlock::Compile(p, pStack); + + // otherwise, look for a single statement instead + + // to handle the case with local definition instruction (*) + CBotCStack* pStk = pStack->TokenStack(p, bLocal); + + return pStack->Return( CBotInstr::Compile(p, pStk), // a single instruction + pStk); +} + +// (*) is the case in the following statement +// if (1 == 1) int x = 0; +// where the variable x is known only in the block following the if diff --git a/src/CBot/CBotInstr/CBotBlock.h b/src/CBot/CBotInstr/CBotBlock.h new file mode 100644 index 00000000..f413e756 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBlock.h @@ -0,0 +1,64 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotBlock class An instruction block { .... }. + */ +class CBotBlock : public CBotInstr +{ +public: + + /*! + * \brief Compile Compiles a statement block " { i ; i ; } " + * \param p + * \param pStack + * \param bLocal + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); + + /*! + * \brief CompileBlkOrInst + * \param p + * \param pStack + * \param bLocal + * \return + */ + static CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false); + +private: + + /*! + * \brief CBotBlock This class have no constructor because there is never an + * instance of this class the object returned by Compile is usually of type + * CBotListInstr + */ + CBotBlock() = delete; + CBotBlock(const CBotBlock &) = delete; +}; diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index 4c63e029..e4a5571e 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotCatch.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index a24e5dbe..94c281d4 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotDo.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 7dc07d4a..32caa3c5 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotFor.h" #include "CBotListExpression.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index 3d1d9c57..b2fcf49c 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotListInstr.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index c0c79975..70fd8033 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -22,6 +22,7 @@ // Modules inlcude #include "CBotSwitch.h" #include "CBotCase.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index c2b2901a..89b689ea 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotTry.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index 92b276db..340cc239 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotWhile.h" +#include "CBotBlock.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 30e717be..ac6a0c09 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -32,6 +32,7 @@ set(SOURCES CBotInstr/CBotInstrMethode.cpp CBotInstr/CBotInstrCall.cpp CBotInstr/CBotListInstr.cpp + CBotInstr/CBotBlock.cpp ) # Includes From f6cc7d2c9c91baf08bd53b9616590f18737fc814 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 20:15:42 +0100 Subject: [PATCH 080/360] Moving CBotExprUnaire class in its own header and source files. --- src/CBot/CBot.cpp | 100 +--------------------- src/CBot/CBot.h | 14 --- src/CBot/CBotInstr/CBotExprUnaire.cpp | 118 ++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprUnaire.h | 73 ++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 193 insertions(+), 113 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExprUnaire.cpp create mode 100644 src/CBot/CBotInstr/CBotExprUnaire.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 042e4c74..de9f730b 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -55,6 +55,7 @@ #include "CBotInstr/CBotExprVar.h" #include "CBotInstr/CBotInstrCall.h" #include "CBotInstr/CBotListInstr.h" +#include "CBotInstr/CBotExprUnaire.h" // Local include @@ -1840,105 +1841,6 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(nullptr, pStk); } - -////////////////////////////////////////////////////////////////////////////////////// -// compile an unary expression -// + -// - -// not -// ! -// ~ - -CBotExprUnaire::CBotExprUnaire() -{ - m_Expr = nullptr; - name = "CBotExprUnaire"; -} - -CBotExprUnaire::~CBotExprUnaire() -{ - delete m_Expr; -} - -CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) -{ - int op = p->GetType(); - CBotToken* pp = p; - if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return nullptr; - - CBotCStack* pStk = pStack->TokenStack(pp); - - CBotExprUnaire* inst = new CBotExprUnaire(); - inst->SetToken(pp); - - if (nullptr != (inst->m_Expr = CBotParExpr::Compile( p, pStk ))) - { - if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number - return pStack->Return(inst, pStk); - if (op == ID_SUB && pStk->GetType() < CBotTypBoolean) // only with the numer - return pStack->Return(inst, pStk); - if (op == ID_NOT && pStk->GetType() < CBotTypFloat) // only with an integer - return pStack->Return(inst, pStk); - if (op == ID_LOG_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean - return pStack->Return(inst, pStk); - if (op == ID_TXT_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean - return pStack->Return(inst, pStk); - - pStk->SetError(TX_BADTYPE, &inst->m_token); - } - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes unary expression - -bool CBotExprUnaire::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->GetState() == 0) - { - if (!m_Expr->Execute(pile)) return false; // interrupted ? - pile->IncState(); - } - - CBotStack* pile2 = pile->AddStack(); - if (pile2->IfStep()) return false; - - CBotVar* var = pile->GetVar(); // get the result on the stack - - switch (GetTokenType()) - { - case ID_ADD: - break; - case ID_SUB: - var->Neg(); // change the sign - break; - case ID_NOT: - case ID_LOG_NOT: - case ID_TXT_NOT: - var->Not(); - break; - } - return pj->Return(pile); // forwards below -} - -void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); - if ( pile == nullptr) return; - - if (pile->GetState() == 0) - { - m_Expr->RestoreState(pile, bMain); // interrupted here! - return; - } -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // index management for arrays // array [ expression ] diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 32cdb695..6ae6885f 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -769,20 +769,6 @@ public: CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; -// unary expression -class CBotExprUnaire : public CBotInstr -{ -private: - CBotInstr* m_Expr; // expression to be evaluated -public: - CBotExprUnaire(); - ~CBotExprUnaire(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - // all operations with two operands class CBotTwoOpExpr : public CBotInstr diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp new file mode 100644 index 00000000..1d63f1dd --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -0,0 +1,118 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExprUnaire.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprUnaire::CBotExprUnaire() +{ + m_Expr = nullptr; + name = "CBotExprUnaire"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprUnaire::~CBotExprUnaire() +{ + delete m_Expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) +{ + int op = p->GetType(); + CBotToken* pp = p; + if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return nullptr; + + CBotCStack* pStk = pStack->TokenStack(pp); + + CBotExprUnaire* inst = new CBotExprUnaire(); + inst->SetToken(pp); + + if (nullptr != (inst->m_Expr = CBotParExpr::Compile( p, pStk ))) + { + if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number + return pStack->Return(inst, pStk); + if (op == ID_SUB && pStk->GetType() < CBotTypBoolean) // only with the numer + return pStack->Return(inst, pStk); + if (op == ID_NOT && pStk->GetType() < CBotTypFloat) // only with an integer + return pStack->Return(inst, pStk); + if (op == ID_LOG_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean + return pStack->Return(inst, pStk); + if (op == ID_TXT_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean + return pStack->Return(inst, pStk); + + pStk->SetError(TX_BADTYPE, &inst->m_token); + } + delete inst; + return pStack->Return(nullptr, pStk); +} + +// executes unary expression +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprUnaire::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->GetState() == 0) + { + if (!m_Expr->Execute(pile)) return false; // interrupted ? + pile->IncState(); + } + + CBotStack* pile2 = pile->AddStack(); + if (pile2->IfStep()) return false; + + CBotVar* var = pile->GetVar(); // get the result on the stack + + switch (GetTokenType()) + { + case ID_ADD: + break; + case ID_SUB: + var->Neg(); // change the sign + break; + case ID_NOT: + case ID_LOG_NOT: + case ID_TXT_NOT: + var->Not(); + break; + } + return pj->Return(pile); // forwards below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); + if ( pile == nullptr) return; + + if (pile->GetState() == 0) + { + m_Expr->RestoreState(pile, bMain); // interrupted here! + return; + } +} diff --git a/src/CBot/CBotInstr/CBotExprUnaire.h b/src/CBot/CBotInstr/CBotExprUnaire.h new file mode 100644 index 00000000..25d21251 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprUnaire.h @@ -0,0 +1,73 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotExprUnaire class Unary expression. Compile an unary expression + * eg : (+, * -, not, !, ~) + */ +class CBotExprUnaire : public CBotInstr +{ +public: + + /*! + * \brief CBotExprUnaire + */ + CBotExprUnaire(); + + /*! + * \brief ~CBotExprUnaire + */ + ~CBotExprUnaire(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Expression to be evaluated. + CBotInstr* m_Expr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index ac6a0c09..4cff8efd 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -33,6 +33,7 @@ set(SOURCES CBotInstr/CBotInstrCall.cpp CBotInstr/CBotListInstr.cpp CBotInstr/CBotBlock.cpp + CBotInstr/CBotExprUnaire.cpp ) # Includes From 75f5126dddb81f6fba5c8ada95ade7bb12e80e9f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 20:36:47 +0100 Subject: [PATCH 081/360] Moving CBotParExpr class in its own header and source files. --- src/CBot/CBot.cpp | 168 ----------------------- src/CBot/CBot.h | 14 -- src/CBot/CBotInstr/CBotExprUnaire.cpp | 1 + src/CBot/CBotInstr/CBotParExpr.cpp | 188 ++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotParExpr.h | 62 +++++++++ src/CBot/CBotTwoOpExpr.cpp | 2 + src/CBot/CMakeLists.txt | 1 + 7 files changed, 254 insertions(+), 182 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotParExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotParExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index de9f730b..93642bcb 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -1673,174 +1673,6 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } -////////////////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////////////// -// compile either: -// instruction in parentheses (...) -// a unary expression (negative, not) -// variable name -// variables pre and post-incremented or decremented -// a given number DefineNum -// a constant -// procedure call -// new statement -// -// this class has no constructor, because there is never an instance of this class -// the object returned by Compile is the class corresponding to the instruction - - -CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->TokenStack(); - - pStk->SetStartError(p->GetStart()); - - // is it an expression in parentheses? - if (IsOfType(p, ID_OPENPAR)) - { - CBotInstr* inst = CBotExpression::Compile(p, pStk); - - if (nullptr != inst) - { - if (IsOfType(p, ID_CLOSEPAR)) - { - return pStack->Return(inst, pStk); - } - pStk->SetError(TX_CLOSEPAR, p->GetStart()); - } - delete inst; - return pStack->Return(nullptr, pStk); - } - - // is this a unary operation? - CBotInstr* inst = CBotExprUnaire::Compile(p, pStk); - if (inst != nullptr || !pStk->IsOk()) - return pStack->Return(inst, pStk); - - // is it a variable name? - if (p->GetType() == TokenTypVar) - { - // this may be a method call without the "this." before - inst = CBotExprVar::CompileMethode(p, pStk); - if (inst != nullptr) return pStack->Return(inst, pStk); - - - // is it a procedure call? - inst = CBotInstrCall::Compile(p, pStk); - if (inst != nullptr || !pStk->IsOk()) - return pStack->Return(inst, pStk); - - - CBotToken* pvar = p; - // no, it an "ordinaty" variable - inst = CBotExprVar::Compile(p, pStk); - - CBotToken* pp = p; - // post incremented or decremented? - if (IsOfType(p, ID_INC, ID_DEC)) - { - if (pStk->GetType() >= CBotTypBoolean) - { - pStk->SetError(TX_BADTYPE, pp); - delete inst; - return pStack->Return(nullptr, pStk); - } - - // recompile the variable for read-only - delete inst; - p = pvar; - inst = CBotExprVar::Compile(p, pStk, PR_READ); - p = p->GetNext(); - - CBotPostIncExpr* i = new CBotPostIncExpr(); - i->SetToken(pp); - i->m_Instr = inst; // associated statement - return pStack->Return(i, pStk); - } - return pStack->Return(inst, pStk); - } - - // pre increpemted or pre decremented? - CBotToken* pp = p; - if (IsOfType(p, ID_INC, ID_DEC)) - { - CBotPreIncExpr* i = new CBotPreIncExpr(); - i->SetToken(pp); - - if (p->GetType() == TokenTypVar) - { - if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ))) - { - if (pStk->GetType() >= CBotTypBoolean) - { - pStk->SetError(TX_BADTYPE, pp); - delete inst; - return pStack->Return(nullptr, pStk); - } - return pStack->Return(i, pStk); - } - delete i; - return pStack->Return(nullptr, pStk); - } - } - - // is it a number or DefineNum? - if (p->GetType() == TokenTypNum || - p->GetType() == TokenTypDef ) - { - CBotInstr* inst = CBotExprNum::Compile(p, pStk); - return pStack->Return(inst, pStk); - } - - // is this a chaine? - if (p->GetType() == TokenTypString) - { - CBotInstr* inst = CBotExprAlpha::Compile(p, pStk); - return pStack->Return(inst, pStk); - } - - // is a "true" or "false" - if (p->GetType() == ID_TRUE || - p->GetType() == ID_FALSE ) - { - CBotInstr* inst = CBotExprBool::Compile(p, pStk); - return pStack->Return(inst, pStk); - } - - // is an object to be created with new - if (p->GetType() == ID_NEW) - { - CBotInstr* inst = CBotNew::Compile(p, pStk); - return pStack->Return(inst, pStk); - } - - // is a null pointer - if (IsOfType(p, ID_NULL)) - { - CBotInstr* inst = new CBotExprNull (); - inst->SetToken(pp); - CBotVar* var = CBotVar::Create("", CBotTypNullPointer); - pStk->SetVar(var); - return pStack->Return(inst, pStk); - } - - // is a number nan - if (IsOfType(p, ID_NAN)) - { - CBotInstr* inst = new CBotExprNan (); - inst->SetToken(pp); - CBotVar* var = CBotVar::Create("", CBotTypInt); - var->SetInit(CBotVar::InitType::IS_NAN); - pStk->SetVar(var); - return pStack->Return(inst, pStk); - } - - - return pStack->Return(nullptr, pStk); -} - ////////////////////////////////////////////////////////////////////////////////////// // index management for arrays // array [ expression ] diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 6ae6885f..7fc2a71e 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -755,20 +755,6 @@ public: CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; - - -// possibly an expression in parentheses ( ... ) -// there is never an instance of this class -// being the object returned inside the parenthesis -class CBotParExpr : public CBotInstr -{ -private: - -public: - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); -}; - // all operations with two operands class CBotTwoOpExpr : public CBotInstr diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 1d63f1dd..e1a18e7f 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotExprUnaire.h" +#include "CBotParExpr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp new file mode 100644 index 00000000..1e9e53ec --- /dev/null +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -0,0 +1,188 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotParExpr.h" +#include "CBotExprUnaire.h" +#include "CBotExprVar.h" +#include "CBotInstrCall.h" +#include "CBotPostIncExpr.h" +#include "CBotPreIncExpr.h" +#include "CBotExprNum.h" +#include "CBotExprAlpha.h" +#include "CBotExprBool.h" +#include "CBotNew.h" +#include "CBotExprNull.h" +#include "CBotExprNan.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCStack* pStk = pStack->TokenStack(); + + pStk->SetStartError(p->GetStart()); + + // is it an expression in parentheses? + if (IsOfType(p, ID_OPENPAR)) + { + CBotInstr* inst = CBotExpression::Compile(p, pStk); + + if (nullptr != inst) + { + if (IsOfType(p, ID_CLOSEPAR)) + { + return pStack->Return(inst, pStk); + } + pStk->SetError(TX_CLOSEPAR, p->GetStart()); + } + delete inst; + return pStack->Return(nullptr, pStk); + } + + // is this a unary operation? + CBotInstr* inst = CBotExprUnaire::Compile(p, pStk); + if (inst != nullptr || !pStk->IsOk()) + return pStack->Return(inst, pStk); + + // is it a variable name? + if (p->GetType() == TokenTypVar) + { + // this may be a method call without the "this." before + inst = CBotExprVar::CompileMethode(p, pStk); + if (inst != nullptr) return pStack->Return(inst, pStk); + + + // is it a procedure call? + inst = CBotInstrCall::Compile(p, pStk); + if (inst != nullptr || !pStk->IsOk()) + return pStack->Return(inst, pStk); + + + CBotToken* pvar = p; + // no, it an "ordinaty" variable + inst = CBotExprVar::Compile(p, pStk); + + CBotToken* pp = p; + // post incremented or decremented? + if (IsOfType(p, ID_INC, ID_DEC)) + { + if (pStk->GetType() >= CBotTypBoolean) + { + pStk->SetError(TX_BADTYPE, pp); + delete inst; + return pStack->Return(nullptr, pStk); + } + + // recompile the variable for read-only + delete inst; + p = pvar; + inst = CBotExprVar::Compile(p, pStk, PR_READ); + p = p->GetNext(); + + CBotPostIncExpr* i = new CBotPostIncExpr(); + i->SetToken(pp); + i->m_Instr = inst; // associated statement + return pStack->Return(i, pStk); + } + return pStack->Return(inst, pStk); + } + + // pre increpemted or pre decremented? + CBotToken* pp = p; + if (IsOfType(p, ID_INC, ID_DEC)) + { + CBotPreIncExpr* i = new CBotPreIncExpr(); + i->SetToken(pp); + + if (p->GetType() == TokenTypVar) + { + if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ))) + { + if (pStk->GetType() >= CBotTypBoolean) + { + pStk->SetError(TX_BADTYPE, pp); + delete inst; + return pStack->Return(nullptr, pStk); + } + return pStack->Return(i, pStk); + } + delete i; + return pStack->Return(nullptr, pStk); + } + } + + // is it a number or DefineNum? + if (p->GetType() == TokenTypNum || + p->GetType() == TokenTypDef ) + { + CBotInstr* inst = CBotExprNum::Compile(p, pStk); + return pStack->Return(inst, pStk); + } + + // is this a chaine? + if (p->GetType() == TokenTypString) + { + CBotInstr* inst = CBotExprAlpha::Compile(p, pStk); + return pStack->Return(inst, pStk); + } + + // is a "true" or "false" + if (p->GetType() == ID_TRUE || + p->GetType() == ID_FALSE ) + { + CBotInstr* inst = CBotExprBool::Compile(p, pStk); + return pStack->Return(inst, pStk); + } + + // is an object to be created with new + if (p->GetType() == ID_NEW) + { + CBotInstr* inst = CBotNew::Compile(p, pStk); + return pStack->Return(inst, pStk); + } + + // is a null pointer + if (IsOfType(p, ID_NULL)) + { + CBotInstr* inst = new CBotExprNull (); + inst->SetToken(pp); + CBotVar* var = CBotVar::Create("", CBotTypNullPointer); + pStk->SetVar(var); + return pStack->Return(inst, pStk); + } + + // is a number nan + if (IsOfType(p, ID_NAN)) + { + CBotInstr* inst = new CBotExprNan (); + inst->SetToken(pp); + CBotVar* var = CBotVar::Create("", CBotTypInt); + var->SetInit(CBotVar::InitType::IS_NAN); + pStk->SetVar(var); + return pStack->Return(inst, pStk); + } + + + return pStack->Return(nullptr, pStk); +} diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h new file mode 100644 index 00000000..de0df458 --- /dev/null +++ b/src/CBot/CBotInstr/CBotParExpr.h @@ -0,0 +1,62 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +// possibly an expression in parentheses ( ... ) +// there is never an instance of this class +// being the object returned inside the parenthesis +//////////////////////////////////////////////////////////////////////////////// +// compile either: +// instruction in parentheses (...) +// a unary expression (negative, not) +// variable name +// variables pre and post-incremented or decremented +// a given number DefineNum +// a constant +// procedure call +// new statement +// +// this class has no constructor, because there is never an instance of this class +// the object returned by Compile is the class corresponding to the instruction +//////////////////////////////////////////////////////////////////////////////// + +/*! + * \brief The CBotParExpr class + */ +class CBotParExpr : public CBotInstr +{ +public: + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); +}; diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotTwoOpExpr.cpp index bc3ebdfa..9f4cb2c5 100644 --- a/src/CBot/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotTwoOpExpr.cpp @@ -23,6 +23,8 @@ #include "CBot.h" +#include "CBotInstr/CBotParExpr.h" + #include namespace diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 4cff8efd..dc6f7461 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -34,6 +34,7 @@ set(SOURCES CBotInstr/CBotListInstr.cpp CBotInstr/CBotBlock.cpp CBotInstr/CBotExprUnaire.cpp + CBotInstr/CBotParExpr.cpp ) # Includes From 4cd7a7a03111c365eba2f9d5cb460986a0165f80 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 20:44:38 +0100 Subject: [PATCH 082/360] Moving CBotBoolExpr class in its own header and source files. --- src/CBot/CBot.cpp | 30 +----------------- src/CBot/CBot.h | 8 ----- src/CBot/CBotInstr/CBotBoolExpr.cpp | 47 +++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotBoolExpr.h | 47 +++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotFor.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 97 insertions(+), 37 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotBoolExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotBoolExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 93642bcb..93eec5f6 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -56,6 +56,7 @@ #include "CBotInstr/CBotInstrCall.h" #include "CBotInstr/CBotListInstr.h" #include "CBotInstr/CBotExprUnaire.h" +#include "CBotInstr/CBotBoolExpr.h" // Local include @@ -1644,35 +1645,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } - -////////////////////////////////////////////////////////////////////////////////////// -// compile a statement such as "(condition)" -// the condition must be Boolean -// -// this class has no constructor, because there is never an instance of this -// class -// the object returned by Compile is usually type CBotExpression -// - -CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) -{ - pStack->SetStartError(p->GetStart()); - - CBotInstr* inst = CBotTwoOpExpr::Compile(p, pStack); - - if (nullptr != inst) - { - if (pStack->GetTypResult().Eq(CBotTypBoolean)) - { - return inst; - } - pStack->SetError(TX_NOTBOOL, p->GetStart()); // is not a boolean - } - - delete inst; - return nullptr; -} - ////////////////////////////////////////////////////////////////////////////////////// // index management for arrays // array [ expression ] diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 7fc2a71e..1ad497e4 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -746,14 +746,6 @@ public: -class CBotBoolExpr : public CBotInstr -{ -private: - -public: - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); -}; // all operations with two operands diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp new file mode 100644 index 00000000..4fd4d7b6 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -0,0 +1,47 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotBoolExpr.h" + +// Local include + +// Global include + + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) +{ + pStack->SetStartError(p->GetStart()); + + CBotInstr* inst = CBotTwoOpExpr::Compile(p, pStack); + + if (nullptr != inst) + { + if (pStack->GetTypResult().Eq(CBotTypBoolean)) + { + return inst; + } + pStack->SetError(TX_NOTBOOL, p->GetStart()); // is not a boolean + } + + delete inst; + return nullptr; +} diff --git a/src/CBot/CBotInstr/CBotBoolExpr.h b/src/CBot/CBotInstr/CBotBoolExpr.h new file mode 100644 index 00000000..df7354ee --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolExpr.h @@ -0,0 +1,47 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotBoolExpr class Compile a statement such as "(condition)" + * the condition must be Boolean. This class has no constructor, because there + * is never an instance of this class the object returned by Compile is usually + * type CBotExpression + */ +class CBotBoolExpr : public CBotInstr +{ +public: + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); +}; diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 32caa3c5..d83650cb 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -21,6 +21,7 @@ #include "CBotFor.h" #include "CBotListExpression.h" #include "CBotBlock.h" +#include "CBotBoolExpr.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index dc6f7461..697dd019 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -35,6 +35,7 @@ set(SOURCES CBotInstr/CBotBlock.cpp CBotInstr/CBotExprUnaire.cpp CBotInstr/CBotParExpr.cpp + CBotInstr/CBotBoolExpr.cpp ) # Includes From 8ee0b7df5687f03a5224172f5108fa4002324a7f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 21:03:16 +0100 Subject: [PATCH 083/360] Moving CBotLogicExpr class in its own header and source files. --- src/CBot/CBot.h | 19 ------ src/CBot/CBotInstr/CBotLogicExpr.cpp | 92 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotLogicExpr.h | 70 +++++++++++++++++++++ src/CBot/CBotTwoOpExpr.cpp | 65 +------------------- src/CBot/CMakeLists.txt | 1 + 5 files changed, 164 insertions(+), 83 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotLogicExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotLogicExpr.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 1ad497e4..976789cf 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -727,25 +727,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotLogicExpr : public CBotInstr -{ -private: - CBotInstr* m_condition; // test to evaluate - CBotInstr* m_op1; // left element - CBotInstr* m_op2; // right element - friend class CBotTwoOpExpr; - -public: - CBotLogicExpr(); - ~CBotLogicExpr(); -// static -// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - - // all operations with two operands diff --git a/src/CBot/CBotInstr/CBotLogicExpr.cpp b/src/CBot/CBotInstr/CBotLogicExpr.cpp new file mode 100644 index 00000000..bfa6af1a --- /dev/null +++ b/src/CBot/CBotInstr/CBotLogicExpr.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotLogicExpr.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotLogicExpr::CBotLogicExpr() +{ + m_condition = + m_op1 = + m_op2 = nullptr; // nullptr to be able to delete without other + name = "CBotLogicExpr"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotLogicExpr::~CBotLogicExpr() +{ + delete m_condition; + delete m_op1; + delete m_op2; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotLogicExpr::Execute(CBotStack* &pStack) +{ + CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack + // or return in case of recovery +// if ( pStk1 == EOX ) return true; + + if ( pStk1->GetState() == 0 ) + { + if ( !m_condition->Execute(pStk1) ) return false; + if (!pStk1->SetState(1)) return false; + } + + if ( pStk1->GetVal() == true ) + { + if ( !m_op1->Execute(pStk1) ) return false; + } + else + { + if ( !m_op2->Execute(pStk1) ) return false; + } + + return pStack->Return(pStk1); // transmits the result +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain) +{ + if ( !bMain ) return; + + CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack + if ( pStk1 == nullptr ) return; + + if ( pStk1->GetState() == 0 ) + { + m_condition->RestoreState(pStk1, bMain); + return; + } + + if ( pStk1->GetVal() == true ) + { + m_op1->RestoreState(pStk1, bMain); + } + else + { + m_op2->RestoreState(pStk1, bMain); + } +} + diff --git a/src/CBot/CBotInstr/CBotLogicExpr.h b/src/CBot/CBotInstr/CBotLogicExpr.h new file mode 100644 index 00000000..2bffc243 --- /dev/null +++ b/src/CBot/CBotInstr/CBotLogicExpr.h @@ -0,0 +1,70 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotLogicExpr class + */ +class CBotLogicExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotLogicExpr + */ + CBotLogicExpr(); + + /*! + * \brief ~CBotLogicExpr + */ + ~CBotLogicExpr(); + + /*! + * \brief Execute + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! Test to evaluate + CBotInstr* m_condition; + //! Left element + CBotInstr* m_op1; + //! Right element + CBotInstr* m_op2; + friend class CBotTwoOpExpr; +}; diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotTwoOpExpr.cpp index 9f4cb2c5..d9173d60 100644 --- a/src/CBot/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotTwoOpExpr.cpp @@ -24,6 +24,7 @@ #include "CBot.h" #include "CBotInstr/CBotParExpr.h" +#include "CBotInstr/CBotLogicExpr.h" #include @@ -50,22 +51,6 @@ CBotTwoOpExpr::~CBotTwoOpExpr() delete m_rightop; } -CBotLogicExpr::CBotLogicExpr() -{ - m_condition = - m_op1 = - m_op2 = nullptr; // nullptr to be able to delete without other - name = "CBotLogicExpr"; // debug -} - -CBotLogicExpr::~CBotLogicExpr() -{ - delete m_condition; - delete m_op1; - delete m_op2; -} - - // type of operands accepted by operations #define ENTIER ((1<AddStack(this); // adds an item to the stack - // or return in case of recovery -// if ( pStk1 == EOX ) return true; - - if ( pStk1->GetState() == 0 ) - { - if ( !m_condition->Execute(pStk1) ) return false; - if (!pStk1->SetState(1)) return false; - } - - if ( pStk1->GetVal() == true ) - { - if ( !m_op1->Execute(pStk1) ) return false; - } - else - { - if ( !m_op2->Execute(pStk1) ) return false; - } - - return pStack->Return(pStk1); // transmits the result -} - -void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain) -{ - if ( !bMain ) return; - - CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack - if ( pStk1 == nullptr ) return; - - if ( pStk1->GetState() == 0 ) - { - m_condition->RestoreState(pStk1, bMain); - return; - } - - if ( pStk1->GetVal() == true ) - { - m_op1->RestoreState(pStk1, bMain); - } - else - { - m_op2->RestoreState(pStk1, bMain); - } -} - #if 0 void t() { diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 697dd019..150724a9 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -36,6 +36,7 @@ set(SOURCES CBotInstr/CBotExprUnaire.cpp CBotInstr/CBotParExpr.cpp CBotInstr/CBotBoolExpr.cpp + CBotInstr/CBotLogicExpr.cpp ) # Includes From d44df45d26e1ae02206ba2d32a4e2fc078ce44b0 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 21:27:56 +0100 Subject: [PATCH 084/360] Moving CBotTwoOpExpr class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 17 ----- src/CBot/CBotClass.cpp | 1 + src/CBot/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotBoolExpr.cpp | 1 + src/CBot/{ => CBotInstr}/CBotTwoOpExpr.cpp | 55 +++++---------- src/CBot/CBotInstr/CBotTwoOpExpr.h | 78 ++++++++++++++++++++++ src/CBot/CMakeLists.txt | 2 +- 8 files changed, 99 insertions(+), 57 deletions(-) rename src/CBot/{ => CBotInstr}/CBotTwoOpExpr.cpp (96%) create mode 100644 src/CBot/CBotInstr/CBotTwoOpExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 93eec5f6..78bf8ca0 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -57,6 +57,7 @@ #include "CBotInstr/CBotListInstr.h" #include "CBotInstr/CBotExprUnaire.h" #include "CBotInstr/CBotBoolExpr.h" +#include "CBotInstr/CBotTwoOpExpr.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 976789cf..31edd2a9 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -727,23 +727,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -// all operations with two operands - -class CBotTwoOpExpr : public CBotInstr -{ -private: - CBotInstr* m_leftop; // left element - CBotInstr* m_rightop; // right element -public: - CBotTwoOpExpr(); - ~CBotTwoOpExpr(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index b7aeb937..11f93a1f 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -24,6 +24,7 @@ #include "CBot.h" #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotLeftExprVar.h" +#include "CBotInstr/CBotTwoOpExpr.h" CBotClass* CBotClass::m_ExClass = nullptr; diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 6ebad172..838c8de1 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -24,6 +24,7 @@ #include "CBot.h" #include "CBotInstr/CBotBlock.h" +#include "CBotInstr/CBotTwoOpExpr.h" #include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index 4fd4d7b6..2815c8ed 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotBoolExpr.h" +#include "CBotTwoOpExpr.h" // Local include diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp similarity index 96% rename from src/CBot/CBotTwoOpExpr.cpp rename to src/CBot/CBotInstr/CBotTwoOpExpr.cpp index d9173d60..b381ca46 100644 --- a/src/CBot/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -17,27 +17,18 @@ * along with this program. If not, see http://gnu.org/licenses */ -/////////////////////////////////////////////////// -// expression of type Opérande1 + Opérande2 -// Opérande1 > Opérande2 - +// Modules inlcude +#include "CBotTwoOpExpr.h" +#include "CBotParExpr.h" +#include "CBotLogicExpr.h" #include "CBot.h" -#include "CBotInstr/CBotParExpr.h" -#include "CBotInstr/CBotLogicExpr.h" +// Local include +// Global include #include -namespace -{ -bool VarIsNAN(const CBotVar* var) -{ - return var->GetInit() > CBotVar::InitType::DEF; -} -} - -// various constructors - +//////////////////////////////////////////////////////////////////////////////// CBotTwoOpExpr::CBotTwoOpExpr() { m_leftop = @@ -45,6 +36,7 @@ CBotTwoOpExpr::CBotTwoOpExpr() name = "CBotTwoOpExpr"; // debug } +//////////////////////////////////////////////////////////////////////////////// CBotTwoOpExpr::~CBotTwoOpExpr() { delete m_leftop; @@ -116,8 +108,7 @@ bool TypeOk( int type, int test ) } } -// compiles a instruction of type A op B - +//////////////////////////////////////////////////////////////////////////////// CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations) { int typemasque; @@ -281,6 +272,11 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera } +bool VarIsNAN(const CBotVar* var) +{ + return var->GetInit() > CBotVar::InitType::DEF; +} + bool IsNan(CBotVar* left, CBotVar* right, int* err = nullptr) { if ( VarIsNAN(left) || VarIsNAN(right) ) @@ -291,9 +287,7 @@ bool IsNan(CBotVar* left, CBotVar* right, int* err = nullptr) return false; } - -// performes the operation on two operands - +//////////////////////////////////////////////////////////////////////////////// bool CBotTwoOpExpr::Execute(CBotStack* &pStack) { CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack @@ -477,6 +471,7 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack) return pStack->Return(pStk2); // transmits the result } +//////////////////////////////////////////////////////////////////////////////// void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain) { if ( !bMain ) return; @@ -501,21 +496,3 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain) return; } } - -#if 0 -void t() -{ - int x,y; - 1>0 ? x = 0 : y = 0; -} -#endif - -#if 0 -void t(bool t) -{ - int x; - x = 1 + t ? 1 : 3 + 4 * 2 ; - t ? 0 : "test"; -} -#endif - diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.h b/src/CBot/CBotInstr/CBotTwoOpExpr.h new file mode 100644 index 00000000..1bcc2f8f --- /dev/null +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.h @@ -0,0 +1,78 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotTwoOpExpr class All operations with two operands. + * eg : + * - Opérande1 + Opérande2 + * - Opérande1 > Opérande2 + */ +class CBotTwoOpExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotTwoOpExpr + */ + CBotTwoOpExpr(); + + /*! + * \brief ~CBotTwoOpExpr + */ + ~CBotTwoOpExpr(); + + /*! + * \brief Compile Compiles a instruction of type A op B. + * \param p + * \param pStack + * \param pOperations + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr); + + /*! + * \brief Execute Performes the operation on two operands. + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Left element + CBotInstr* m_leftop; + //! Right element + CBotInstr* m_rightop; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 150724a9..ba8f1a2b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -7,7 +7,6 @@ set(SOURCES CBotStack.cpp CBotString.cpp CBotToken.cpp - CBotTwoOpExpr.cpp CBotVar.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp @@ -37,6 +36,7 @@ set(SOURCES CBotInstr/CBotParExpr.cpp CBotInstr/CBotBoolExpr.cpp CBotInstr/CBotLogicExpr.cpp + CBotInstr/CBotTwoOpExpr.cpp ) # Includes From 3c1296b4b931b7338e014c5dbf84f958896e96b1 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 21:43:56 +0100 Subject: [PATCH 085/360] Moving CBotExpression class in its own header and source files. --- src/CBot/CBot.cpp | 271 +------------------- src/CBot/CBot.h | 19 -- src/CBot/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotCatch.cpp | 1 + src/CBot/CBotInstr/CBotExprVar.cpp | 1 + src/CBot/CBotInstr/CBotExpression.cpp | 290 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotExpression.h | 85 +++++++ src/CBot/CBotInstr/CBotInstrCall.cpp | 1 + src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CBotInstr/CBotParExpr.cpp | 1 + src/CBot/CBotInstr/CBotSwitch.cpp | 1 + src/CBot/CBotInstr/CBotThrow.cpp | 1 + src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 14 files changed, 386 insertions(+), 289 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotExpression.cpp create mode 100644 src/CBot/CBotInstr/CBotExpression.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 78bf8ca0..c2b392b8 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -58,6 +58,7 @@ #include "CBotInstr/CBotExprUnaire.h" #include "CBotInstr/CBotBoolExpr.h" #include "CBotInstr/CBotTwoOpExpr.h" +#include "CBotInstr/CBotExpression.h" // Local include @@ -1345,276 +1346,6 @@ void CBotIString::RestoreState(CBotStack* &pj, bool bMain) m_next2b->RestoreState(pile, bMain); } -////////////////////////////////////////////////////////////////////////////////////////// - - - -////////////////////////////////////////////////////////////////////////////////////// -// compiles a statement such as " x = 123 " ou " z * 5 + 4 " -// with or without assignment - -CBotExpression::CBotExpression() -{ - m_leftop = nullptr; - m_rightop = nullptr; - name = "CBotExpression"; -} - -CBotExpression::~CBotExpression() -{ - delete m_leftop; - delete m_rightop; -} - -CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; - - CBotExpression* inst = new CBotExpression(); - - inst->m_leftop = CBotLeftExpr::Compile(p, pStack); - - inst->SetToken(p); - int OpType = p->GetType(); - - if ( pStack->IsOk() && - IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO, - ID_ASSAND, ID_ASSXOR, ID_ASSOR, - ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 )) - { - if (inst->m_leftop == nullptr) - { - pStack->SetError(TX_BADLEFT, p->GetEnd()); - delete inst; - return nullptr; - } - - inst->m_rightop = CBotExpression::Compile(p, pStack); - if (inst->m_rightop == nullptr) - { - delete inst; - return nullptr; - } - - CBotTypResult type1 = pStack->GetTypResult(); - - // get the variable assigned to mark - CBotVar* var = nullptr; - inst->m_leftop->ExecuteVar(var, pStack); - if (var == nullptr) - { - delete inst; - return nullptr; - } - - if (OpType != ID_ASS && !var->IsDefined()) - { - pStack->SetError(TX_NOTINIT, pp); - delete inst; - return nullptr; - } - - CBotTypResult type2 = var->GetTypResult(); - - // what types are acceptable? - switch (OpType) - { - case ID_ASS: - // if (type2 == CBotTypClass) type2 = -1; - if ((type1.Eq(CBotTypPointer) && type2.Eq(CBotTypPointer)) || - (type1.Eq(CBotTypClass) && type2.Eq(CBotTypClass) ) ) - { -/* CBotClass* c1 = type1.GetClass(); - CBotClass* c2 = type2.GetClass(); - if (!c1->IsChildOf(c2)) type2.SetType(-1); -//- if (!type1.Eq(CBotTypClass)) var->SetPointer(pStack->GetVar()->GetPointer());*/ - var->SetInit(CBotVar::InitType::IS_POINTER); - } - else - var->SetInit(CBotVar::InitType::DEF); - - break; - case ID_ASSADD: - if (type2.Eq(CBotTypBoolean) || - type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings - break; - case ID_ASSSUB: - case ID_ASSMUL: - case ID_ASSDIV: - case ID_ASSMODULO: - if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only - break; - } - - if (!TypeCompatible(type1, type2, OpType)) - { - pStack->SetError(TX_BADTYPE, &inst->m_token); - delete inst; - return nullptr; - } - - return inst; // compatible type? - } - - delete inst; - int start, end, error = pStack->GetError(start, end); - - p = pp; // returns to the top - pStack->SetError(0,0); // forget the error - - CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment - if (i != nullptr && error == TX_PRIVATE && p->GetType() == ID_ASS) - pStack->ResetError(error, start, end); - return i; -} - -// executes an expression with assignment - -bool CBotExpression::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - -// CBotToken* pToken = m_leftop->GetToken(); - - CBotVar* pVar = nullptr; - - CBotStack* pile1 = pile; - - CBotVar::InitType initKind = CBotVar::InitType::DEF; - CBotVar* result = nullptr; - - // must be done before any indexes (stack can be changed) - if (!m_leftop->ExecuteVar(pVar, pile, nullptr, false)) return false; // variable before accessing the value on the right - - if ( pile1->GetState()==0) - { - pile1->SetCopyVar(pVar); // keeps the copy on the stack (if interrupted) - pile1->IncState(); - } - - CBotStack* pile2 = pile->AddStack(); - - if ( pile2->GetState()==0) - { - if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? - pile2->IncState(); - } - - if (pile1->GetState() == 1) - { - if (m_token.GetType() != ID_ASS) - { - pVar = pile1->GetVar(); // recovers if interrupted - initKind = pVar->GetInit(); - if (initKind == CBotVar::InitType::IS_NAN) - { - pile2->SetError(TX_OPNAN, m_leftop->GetToken()); - return pj->Return(pile2); - } - result = CBotVar::Create("", pVar->GetTypResult(2)); - } - - switch (m_token.GetType()) - { - case ID_ASS: - break; - case ID_ASSADD: - result->Add(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSSUB: - result->Sub(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSMUL: - result->Mul(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSDIV: - if (initKind != CBotVar::InitType::UNDEF && - result->Div(pile1->GetVar(), pile2->GetVar())) - pile2->SetError(TX_DIVZERO, &m_token); - pile2->SetVar(result); - break; - case ID_ASSMODULO: - if (initKind != CBotVar::InitType::UNDEF && - result->Modulo(pile1->GetVar(), pile2->GetVar())) - pile2->SetError(TX_DIVZERO, &m_token); - pile2->SetVar(result); - break; - case ID_ASSAND: - result->And(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSXOR: - result->XOr(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSOR: - result->Or(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSSL: - result->SL(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSSR: - result->SR(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - case ID_ASSASR: - result->ASR(pile1->GetVar(), pile2->GetVar()); - pile2->SetVar(result); - break; - default: - assert(0); - } - if (initKind == CBotVar::InitType::UNDEF) - pile2->SetError(TX_NOTINIT, m_leftop->GetToken()); - - pile1->IncState(); - } - - if (!m_leftop->Execute( pile2, pile1 )) - return false; - - return pj->Return(pile2); -} - - -void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) - { -// CBotToken* pToken = m_leftop->GetToken(); -// CBotVar* pVar = nullptr; - - CBotStack* pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - CBotStack* pile1 = pile; - - if ( pile1->GetState()==0) - { - m_leftop->RestoreStateVar(pile, true); - return; - } - - m_leftop->RestoreStateVar(pile, false); - - CBotStack* pile2 = pile->RestoreStack(); - if (pile2 == nullptr) return; - - if ( pile2->GetState()==0) - { - if (m_rightop) m_rightop->RestoreState(pile2, bMain); - return; - } - } -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // compile a statement such as "(condition)" diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 31edd2a9..1709ba11 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -708,25 +708,6 @@ public: void RestoreStateVar(CBotStack* &pj, bool bMain) override; }; -// expressions like -// x = a; -// x * y + 3; - -class CBotExpression : public CBotInstr -{ -private: - CBotLeftExpr* m_leftop; // left operand - CBotInstr* m_rightop; // right operant - -public: - CBotExpression(); - ~CBotExpression(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 838c8de1..b672f32a 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -25,6 +25,7 @@ #include "CBotInstr/CBotBlock.h" #include "CBotInstr/CBotTwoOpExpr.h" +#include "CBotInstr/CBotExpression.h" #include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index e4a5571e..e4d9bb4c 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotCatch.h" #include "CBotBlock.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 57b2b431..0101fcba 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotExprVar.h" #include "CBotInstrMethode.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp new file mode 100644 index 00000000..cb47103b --- /dev/null +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -0,0 +1,290 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotExpression.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include +#include + + +////////////////////////////////////////////////////////////////////////////////////// +CBotExpression::CBotExpression() +{ + m_leftop = nullptr; + m_rightop = nullptr; + name = "CBotExpression"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExpression::~CBotExpression() +{ + delete m_leftop; + delete m_rightop; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; + + CBotExpression* inst = new CBotExpression(); + + inst->m_leftop = CBotLeftExpr::Compile(p, pStack); + + inst->SetToken(p); + int OpType = p->GetType(); + + if ( pStack->IsOk() && + IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO, + ID_ASSAND, ID_ASSXOR, ID_ASSOR, + ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 )) + { + if (inst->m_leftop == nullptr) + { + pStack->SetError(TX_BADLEFT, p->GetEnd()); + delete inst; + return nullptr; + } + + inst->m_rightop = CBotExpression::Compile(p, pStack); + if (inst->m_rightop == nullptr) + { + delete inst; + return nullptr; + } + + CBotTypResult type1 = pStack->GetTypResult(); + + // get the variable assigned to mark + CBotVar* var = nullptr; + inst->m_leftop->ExecuteVar(var, pStack); + if (var == nullptr) + { + delete inst; + return nullptr; + } + + if (OpType != ID_ASS && !var->IsDefined()) + { + pStack->SetError(TX_NOTINIT, pp); + delete inst; + return nullptr; + } + + CBotTypResult type2 = var->GetTypResult(); + + // what types are acceptable? + switch (OpType) + { + case ID_ASS: + // if (type2 == CBotTypClass) type2 = -1; + if ((type1.Eq(CBotTypPointer) && type2.Eq(CBotTypPointer)) || + (type1.Eq(CBotTypClass) && type2.Eq(CBotTypClass) ) ) + { +/* CBotClass* c1 = type1.GetClass(); + CBotClass* c2 = type2.GetClass(); + if (!c1->IsChildOf(c2)) type2.SetType(-1); +//- if (!type1.Eq(CBotTypClass)) var->SetPointer(pStack->GetVar()->GetPointer());*/ + var->SetInit(CBotVar::InitType::IS_POINTER); + } + else + var->SetInit(CBotVar::InitType::DEF); + + break; + case ID_ASSADD: + if (type2.Eq(CBotTypBoolean) || + type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings + break; + case ID_ASSSUB: + case ID_ASSMUL: + case ID_ASSDIV: + case ID_ASSMODULO: + if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only + break; + } + + if (!TypeCompatible(type1, type2, OpType)) + { + pStack->SetError(TX_BADTYPE, &inst->m_token); + delete inst; + return nullptr; + } + + return inst; // compatible type? + } + + delete inst; + int start, end, error = pStack->GetError(start, end); + + p = pp; // returns to the top + pStack->SetError(0,0); // forget the error + + CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment + if (i != nullptr && error == TX_PRIVATE && p->GetType() == ID_ASS) + pStack->ResetError(error, start, end); + return i; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotExpression::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + +// CBotToken* pToken = m_leftop->GetToken(); + + CBotVar* pVar = nullptr; + + CBotStack* pile1 = pile; + + CBotVar::InitType initKind = CBotVar::InitType::DEF; + CBotVar* result = nullptr; + + // must be done before any indexes (stack can be changed) + if (!m_leftop->ExecuteVar(pVar, pile, nullptr, false)) return false; // variable before accessing the value on the right + + if ( pile1->GetState()==0) + { + pile1->SetCopyVar(pVar); // keeps the copy on the stack (if interrupted) + pile1->IncState(); + } + + CBotStack* pile2 = pile->AddStack(); + + if ( pile2->GetState()==0) + { + if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? + pile2->IncState(); + } + + if (pile1->GetState() == 1) + { + if (m_token.GetType() != ID_ASS) + { + pVar = pile1->GetVar(); // recovers if interrupted + initKind = pVar->GetInit(); + if (initKind == CBotVar::InitType::IS_NAN) + { + pile2->SetError(TX_OPNAN, m_leftop->GetToken()); + return pj->Return(pile2); + } + result = CBotVar::Create("", pVar->GetTypResult(2)); + } + + switch (m_token.GetType()) + { + case ID_ASS: + break; + case ID_ASSADD: + result->Add(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSSUB: + result->Sub(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSMUL: + result->Mul(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSDIV: + if (initKind != CBotVar::InitType::UNDEF && + result->Div(pile1->GetVar(), pile2->GetVar())) + pile2->SetError(TX_DIVZERO, &m_token); + pile2->SetVar(result); + break; + case ID_ASSMODULO: + if (initKind != CBotVar::InitType::UNDEF && + result->Modulo(pile1->GetVar(), pile2->GetVar())) + pile2->SetError(TX_DIVZERO, &m_token); + pile2->SetVar(result); + break; + case ID_ASSAND: + result->And(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSXOR: + result->XOr(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSOR: + result->Or(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSSL: + result->SL(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSSR: + result->SR(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + case ID_ASSASR: + result->ASR(pile1->GetVar(), pile2->GetVar()); + pile2->SetVar(result); + break; + default: + assert(0); + } + if (initKind == CBotVar::InitType::UNDEF) + pile2->SetError(TX_NOTINIT, m_leftop->GetToken()); + + pile1->IncState(); + } + + if (!m_leftop->Execute( pile2, pile1 )) + return false; + + return pj->Return(pile2); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) + { +// CBotToken* pToken = m_leftop->GetToken(); +// CBotVar* pVar = nullptr; + + CBotStack* pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + CBotStack* pile1 = pile; + + if ( pile1->GetState()==0) + { + m_leftop->RestoreStateVar(pile, true); + return; + } + + m_leftop->RestoreStateVar(pile, false); + + CBotStack* pile2 = pile->RestoreStack(); + if (pile2 == nullptr) return; + + if ( pile2->GetState()==0) + { + if (m_rightop) m_rightop->RestoreState(pile2, bMain); + return; + } + } +} diff --git a/src/CBot/CBotInstr/CBotExpression.h b/src/CBot/CBotInstr/CBotExpression.h new file mode 100644 index 00000000..b47e9e24 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExpression.h @@ -0,0 +1,85 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotExpression class Compiles a statement with or without + * assignment. + * eg : + * - x = a; + * - x * y + 3; + * - x = 123 + * - z * 5 + 4 + */ + + +// compiles a statement such as " " ou " z * 5 + 4 " +// + +class CBotExpression : public CBotInstr +{ +public: + + /*! + * \brief CBotExpression + */ + CBotExpression(); + + /*! + * \brief ~CBotExpression + */ + ~CBotExpression(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Executes an expression with assignment. + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Left operand + CBotLeftExpr* m_leftop; + //! Right operand + CBotInstr* m_rightop; +}; diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index 66a48e34..615f041a 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotInstrCall.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 66f7eafc..c631e762 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotListExpression.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index 1e9e53ec..5d2839e8 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -30,6 +30,7 @@ #include "CBotNew.h" #include "CBotExprNull.h" #include "CBotExprNan.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index 70fd8033..45558dc1 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -23,6 +23,7 @@ #include "CBotSwitch.h" #include "CBotCase.h" #include "CBotBlock.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index 14e61f07..a4a1831e 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotThrow.h" +#include "CBotExpression.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index b381ca46..275730a6 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -21,6 +21,7 @@ #include "CBotTwoOpExpr.h" #include "CBotParExpr.h" #include "CBotLogicExpr.h" +#include "CBotExpression.h" #include "CBot.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index ba8f1a2b..ce4f6d75 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -37,6 +37,7 @@ set(SOURCES CBotInstr/CBotBoolExpr.cpp CBotInstr/CBotLogicExpr.cpp CBotInstr/CBotTwoOpExpr.cpp + CBotInstr/CBotExpression.cpp ) # Includes From d0cfdfb998d15818d9e5ef31869cd836434e7dfe Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 21:55:02 +0100 Subject: [PATCH 086/360] Moving CBotIndexExpr class in its own header and source files. --- src/CBot/CBot.cpp | 98 +---------------------- src/CBot/CBot.h | 17 ---- src/CBot/CBotInstr/CBotExprVar.cpp | 1 + src/CBot/CBotInstr/CBotIndexExpr.cpp | 115 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotIndexExpr.h | 81 +++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 199 insertions(+), 114 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotIndexExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotIndexExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index c2b392b8..d0a1239e 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -59,6 +59,7 @@ #include "CBotInstr/CBotBoolExpr.h" #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotExpression.h" +#include "CBotInstr/CBotIndexExpr.h" // Local include @@ -1377,103 +1378,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } -////////////////////////////////////////////////////////////////////////////////////// -// index management for arrays -// array [ expression ] - - -CBotIndexExpr::CBotIndexExpr() -{ - m_expr = nullptr; - name = "CBotIndexExpr"; -} - -CBotIndexExpr::~CBotIndexExpr() -{ - delete m_expr; -} - -// finds a field from the instance at compile time - -bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) -{ - if (pVar->GetType(1) != CBotTypArrayPointer) - assert(0); - - pVar = (static_cast(pVar))->GetItem(0, false); // at compile time makes the element [0] - if (pVar == nullptr) - { - pile->SetError(TX_OUTARRAY, m_token.GetEnd()); - return false; - } - if (m_next3 != nullptr) return m_next3->ExecuteVar(pVar, pile); - return true; -} - -// attention, changes the pointer to the stack intentionally -// place the index calculated on the additional stack - - -bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) -{ - CBotStack* pj = pile; - - if (pVar->GetType(1) != CBotTypArrayPointer) - assert(0); - - pile = pile->AddStack(); - - if (pile->GetState() == 0) - { - if (!m_expr->Execute(pile)) return false; - pile->IncState(); - } - // handles array - - CBotVar* p = pile->GetVar(); // result on the stack - - if (p == nullptr || p->GetType() > CBotTypDouble) - { - pile->SetError(TX_BADINDEX, prevToken); - return pj->Return(pile); - } - - int n = p->GetValInt(); // position in the table - - pVar = (static_cast(pVar))->GetItem(n, bExtend); - if (pVar == nullptr) - { - pile->SetError(TX_OUTARRAY, prevToken); - return pj->Return(pile); - } - - pVar->Maj(pile->GetPUser(), true); - - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false; - - // does not release the stack - // to avoid recalculation of the index twice where appropriate - return true; -} - -void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain) -{ - pile = pile->RestoreStack(); - if (pile == nullptr) return; - - if (bMain && pile->GetState() == 0) - { - m_expr->RestoreState(pile, true); - return; - } - - if (m_next3) - m_next3->RestoreStateVar(pile, bMain); -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // field management in an instance (dot operator) // toto.x diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 1709ba11..995e5c6d 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -689,24 +689,7 @@ public: void RestoreStateVar(CBotStack* &pj, bool bMain) override; }; -// management of indices of the tables -class CBotIndexExpr : public CBotInstr -{ -private: - CBotInstr* m_expr; // expression for calculating the index - friend class CBotLeftExpr; - friend class CBotExprVar; - -public: - CBotIndexExpr(); - ~CBotIndexExpr(); -// static -// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override; - void RestoreStateVar(CBotStack* &pj, bool bMain) override; -}; #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 0101fcba..93ffeecf 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -21,6 +21,7 @@ #include "CBotExprVar.h" #include "CBotInstrMethode.h" #include "CBotExpression.h" +#include "CBotIndexExpr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp new file mode 100644 index 00000000..2d3d6d2a --- /dev/null +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotIndexExpr.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotIndexExpr::CBotIndexExpr() +{ + m_expr = nullptr; + name = "CBotIndexExpr"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotIndexExpr::~CBotIndexExpr() +{ + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +{ + if (pVar->GetType(1) != CBotTypArrayPointer) + assert(0); + + pVar = (static_cast(pVar))->GetItem(0, false); // at compile time makes the element [0] + if (pVar == nullptr) + { + pile->SetError(TX_OUTARRAY, m_token.GetEnd()); + return false; + } + if (m_next3 != nullptr) return m_next3->ExecuteVar(pVar, pile); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) +{ + CBotStack* pj = pile; + + if (pVar->GetType(1) != CBotTypArrayPointer) + assert(0); + + pile = pile->AddStack(); + + if (pile->GetState() == 0) + { + if (!m_expr->Execute(pile)) return false; + pile->IncState(); + } + // handles array + + CBotVar* p = pile->GetVar(); // result on the stack + + if (p == nullptr || p->GetType() > CBotTypDouble) + { + pile->SetError(TX_BADINDEX, prevToken); + return pj->Return(pile); + } + + int n = p->GetValInt(); // position in the table + + pVar = (static_cast(pVar))->GetItem(n, bExtend); + if (pVar == nullptr) + { + pile->SetError(TX_OUTARRAY, prevToken); + return pj->Return(pile); + } + + pVar->Maj(pile->GetPUser(), true); + + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false; + + // does not release the stack + // to avoid recalculation of the index twice where appropriate + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain) +{ + pile = pile->RestoreStack(); + if (pile == nullptr) return; + + if (bMain && pile->GetState() == 0) + { + m_expr->RestoreState(pile, true); + return; + } + + if (m_next3) + m_next3->RestoreStateVar(pile, bMain); +} diff --git a/src/CBot/CBotInstr/CBotIndexExpr.h b/src/CBot/CBotInstr/CBotIndexExpr.h new file mode 100644 index 00000000..730a4de4 --- /dev/null +++ b/src/CBot/CBotInstr/CBotIndexExpr.h @@ -0,0 +1,81 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotIndexExpr class Index management for arrays + * eg : + * - array [ expression ] + */ +class CBotIndexExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotIndexExpr + */ + CBotIndexExpr(); + + /*! + * \brief ~CBotIndexExpr + */ + ~CBotIndexExpr(); + + /*! + * \brief ExecuteVar Finds a field from the instance at compile time. + * \param pVar + * \param pile + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; + + /*! + * \brief ExecuteVar Warning, changes the pointer to the stack intentionally + * place the index calculated on the additional stack. + * \param pVar + * \param pile + * \param prevToken + * \param bStep + * \param bExtend + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override; + + /*! + * \brief RestoreStateVar + * \param pj + * \param bMain + */ + void RestoreStateVar(CBotStack* &pj, bool bMain) override; + + +private: + //! Expression for calculating the index. + CBotInstr* m_expr; + friend class CBotLeftExpr; + friend class CBotExprVar; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index ce4f6d75..bb4d3256 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -38,6 +38,7 @@ set(SOURCES CBotInstr/CBotLogicExpr.cpp CBotInstr/CBotTwoOpExpr.cpp CBotInstr/CBotExpression.cpp + CBotInstr/CBotIndexExpr.cpp ) # Includes From 4b10358df767aa28a49a4b17b84da4ac98694604 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:02:17 +0100 Subject: [PATCH 087/360] Moving CBotFieldExpr class in its own header and source files. --- src/CBot/CBot.cpp | 103 +--------------------- src/CBot/CBot.h | 21 ----- src/CBot/CBotInstr/CBotExprVar.cpp | 1 + src/CBot/CBotInstr/CBotFieldExpr.cpp | 124 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotFieldExpr.h | 83 ++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 210 insertions(+), 123 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotFieldExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotFieldExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index d0a1239e..7511afa4 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -60,6 +60,7 @@ #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotExpression.h" #include "CBotInstr/CBotIndexExpr.h" +#include "CBotInstr/CBotFieldExpr.h" // Local include @@ -1378,108 +1379,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } -////////////////////////////////////////////////////////////////////////////////////// -// field management in an instance (dot operator) -// toto.x - - -CBotFieldExpr::CBotFieldExpr() -{ - name = "CBotFieldExpr"; - m_nIdent = 0; -} - -CBotFieldExpr::~CBotFieldExpr() -{ -} - -void CBotFieldExpr::SetUniqNum(int num) -{ - m_nIdent = num; -} - - -// find a field from the instance at compile - -bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) -{ - if (pVar->GetType(1) != CBotTypPointer) - assert(0); - - pVar = pVar->GetItemRef(m_nIdent); - if (pVar == nullptr) - { - pile->SetError(TX_NOITEM, &m_token); - return false; - } - - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pile) ) return false; - - return true; -} - -bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) -{ - CBotStack* pj = pile; - pile = pile->AddStack(this); // changes in output stack - if (pile == EOX) return true; - - - if (pVar->GetType(1) != CBotTypPointer) - assert(0); - - CBotVarClass* pItem = pVar->GetPointer(); - if (pItem == nullptr) - { - pile->SetError(TX_NULLPT, prevToken); - return pj->Return(pile); - } - if (pItem->GetUserPtr() == OBJECTDELETED) - { - pile->SetError(TX_DELETEDPT, prevToken); - return pj->Return(pile); - } - - if (bStep && pile->IfStep()) return false; - - pVar = pVar->GetItemRef(m_nIdent); - if (pVar == nullptr) - { - pile->SetError(TX_NOITEM, &m_token); - return pj->Return(pile); - } - - if (pVar->IsStatic()) - { - // for a static variable, takes it in the class itself - CBotClass* pClass = pItem->GetClass(); - pVar = pClass->GetItem(m_token.GetString()); - } - - // request the update of the element, if applicable - pVar->Maj(pile->GetPUser(), true); - - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false; - - // does not release the stack - // to maintain the state SetState () corresponding to step - - return true; -} - -void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain) -{ - pj = pj->RestoreStack(this); - if (pj == nullptr) return; - - if (m_next3 != nullptr) - m_next3->RestoreStateVar(pj, bMain); -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // compile a left operand for an assignment CBotLeftExpr::CBotLeftExpr() diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 995e5c6d..a0beb27a 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -670,27 +670,6 @@ public: }; -// management of the fields of an instance - -class CBotFieldExpr : public CBotInstr -{ -private: - friend class CBotExpression; - int m_nIdent; - -public: - CBotFieldExpr(); - ~CBotFieldExpr(); - void SetUniqNum(int num); -// static -// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override; - void RestoreStateVar(CBotStack* &pj, bool bMain) override; -}; - - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 93ffeecf..3c03da91 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -22,6 +22,7 @@ #include "CBotInstrMethode.h" #include "CBotExpression.h" #include "CBotIndexExpr.h" +#include "CBotFieldExpr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp new file mode 100644 index 00000000..6453bc3c --- /dev/null +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -0,0 +1,124 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotFieldExpr.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotFieldExpr::CBotFieldExpr() +{ + name = "CBotFieldExpr"; + m_nIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotFieldExpr::~CBotFieldExpr() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotFieldExpr::SetUniqNum(int num) +{ + m_nIdent = num; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +{ + if (pVar->GetType(1) != CBotTypPointer) + assert(0); + + pVar = pVar->GetItemRef(m_nIdent); + if (pVar == nullptr) + { + pile->SetError(TX_NOITEM, &m_token); + return false; + } + + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pile) ) return false; + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) +{ + CBotStack* pj = pile; + pile = pile->AddStack(this); // changes in output stack + if (pile == EOX) return true; + + + if (pVar->GetType(1) != CBotTypPointer) + assert(0); + + CBotVarClass* pItem = pVar->GetPointer(); + if (pItem == nullptr) + { + pile->SetError(TX_NULLPT, prevToken); + return pj->Return(pile); + } + if (pItem->GetUserPtr() == OBJECTDELETED) + { + pile->SetError(TX_DELETEDPT, prevToken); + return pj->Return(pile); + } + + if (bStep && pile->IfStep()) return false; + + pVar = pVar->GetItemRef(m_nIdent); + if (pVar == nullptr) + { + pile->SetError(TX_NOITEM, &m_token); + return pj->Return(pile); + } + + if (pVar->IsStatic()) + { + // for a static variable, takes it in the class itself + CBotClass* pClass = pItem->GetClass(); + pVar = pClass->GetItem(m_token.GetString()); + } + + // request the update of the element, if applicable + pVar->Maj(pile->GetPUser(), true); + + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false; + + // does not release the stack + // to maintain the state SetState () corresponding to step + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain) +{ + pj = pj->RestoreStack(this); + if (pj == nullptr) return; + + if (m_next3 != nullptr) + m_next3->RestoreStateVar(pj, bMain); +} diff --git a/src/CBot/CBotInstr/CBotFieldExpr.h b/src/CBot/CBotInstr/CBotFieldExpr.h new file mode 100644 index 00000000..13f9fc37 --- /dev/null +++ b/src/CBot/CBotInstr/CBotFieldExpr.h @@ -0,0 +1,83 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotFieldExpr class Management of the fields of an instance + * (dot operator) eg : toto.x + */ +class CBotFieldExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotFieldExpr + */ + CBotFieldExpr(); + + /*! + * \brief ~CBotFieldExpr + */ + ~CBotFieldExpr(); + + /*! + * \brief SetUniqNum + * \param num + */ + void SetUniqNum(int num); + + /*! + * \brief ExecuteVar Find a field from the instance at compile. + * \param pVar + * \param pile + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; + + /*! + * \brief ExecuteVar + * \param pVar + * \param pile + * \param prevToken + * \param bStep + * \param bExtend + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override; + + /*! + * \brief RestoreStateVar + * \param pj + * \param bMain + */ + void RestoreStateVar(CBotStack* &pj, bool bMain) override; + +private: + friend class CBotExpression; + int m_nIdent; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index bb4d3256..29380c32 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -39,6 +39,7 @@ set(SOURCES CBotInstr/CBotTwoOpExpr.cpp CBotInstr/CBotExpression.cpp CBotInstr/CBotIndexExpr.cpp + CBotInstr/CBotFieldExpr.cpp ) # Includes From d89fd629a265c3c3637e16600fee4cd23bde27f3 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:16:38 +0100 Subject: [PATCH 088/360] Moving CBotLeftExpr class in its own header and source files. --- src/CBot/CBot.cpp | 223 ------------------------- src/CBot/CBot.h | 22 --- src/CBot/CBotInstr/CBotExpression.h | 1 + src/CBot/CBotInstr/CBotLeftExpr.cpp | 242 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotLeftExpr.h | 101 ++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 345 insertions(+), 245 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotLeftExpr.cpp create mode 100644 src/CBot/CBotInstr/CBotLeftExpr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 7511afa4..c4ac2874 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -1379,229 +1379,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } -////////////////////////////////////////////////////////////////////////////////////// -// compile a left operand for an assignment -CBotLeftExpr::CBotLeftExpr() -{ - name = "CBotLeftExpr"; - m_nIdent = 0; -} - -CBotLeftExpr::~CBotLeftExpr() -{ -} - -// compiles an expression for a left-operand (left of an assignment) -// this can be -// toto -// toto[ 3 ] -// toto.x -// toto.pos.x -// toto[2].pos.x -// toto[1].pos[2].x -// toto[1][2][3] - -CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotCStack* pStk = pStack->TokenStack(); - - pStk->SetStartError(p->GetStart()); - - // is it a variable name? - if (p->GetType() == TokenTypVar) - { - CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object - - inst->SetToken(p); - - CBotVar* var; - - if (nullptr != (var = pStk->FindVar(p))) // seek if known variable - { - inst->m_nIdent = var->GetUniqNum(); - if (inst->m_nIdent > 0 && inst->m_nIdent < 9000) - { - if ( var->IsPrivate(PR_READ) && - !pStk->GetBotCall()->m_bCompileClass) - { - pStk->SetError(TX_PRIVATE, p); - goto err; - } - // this is an element of the current class - // adds the equivalent of this. before - CBotToken pthis("this"); - inst->SetToken(&pthis); - inst->m_nIdent = -2; // indent for this - - CBotFieldExpr* i = new CBotFieldExpr(); // new element - i->SetToken(p); // keeps the name of the token - inst->AddNext3(i); // add after - - var = pStk->FindVar(pthis); - var = var->GetItem(p->GetString()); - i->SetUniqNum(var->GetUniqNum()); - } - p = p->GetNext(); // next token - - while (true) - { - if (var->GetType() == CBotTypArrayPointer) - { - if (IsOfType( p, ID_OPBRK )) - { - CBotIndexExpr* i = new CBotIndexExpr(); - i->m_expr = CBotExpression::Compile(p, pStk); - inst->AddNext3(i); // add to the chain - - var = (static_cast(var))->GetItem(0,true); // gets the component [0] - - if (i->m_expr == nullptr) - { - pStk->SetError(TX_BADINDEX, p->GetStart()); - goto err; - } - - if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto err; - } - continue; - } - } - - if (var->GetType(1) == CBotTypPointer) // for classes - { - if (IsOfType(p, ID_DOT)) - { - CBotToken* pp = p; - - CBotFieldExpr* i = new CBotFieldExpr(); // new element - i->SetToken(pp); // keeps the name of the token - inst->AddNext3(i); // adds after - - if (p->GetType() == TokenTypVar) // must be a name - { - var = var->GetItem(p->GetString()); // get item correspondent - if (var != nullptr) - { - if ( var->IsPrivate(PR_READ) && - !pStk->GetBotCall()->m_bCompileClass) - { - pStk->SetError(TX_PRIVATE, pp); - goto err; - } - - i->SetUniqNum(var->GetUniqNum()); - p = p->GetNext(); // skips the name - continue; - } - pStk->SetError(TX_NOITEM, p); - } - pStk->SetError(TX_DOT, p->GetStart()); - goto err; - } - } - break; - } - - - if (pStk->IsOk()) return static_cast (pStack->Return(inst, pStk)); - } - pStk->SetError(TX_UNDEFVAR, p); -err: - delete inst; - return static_cast ( pStack->Return(nullptr, pStk)); - } - - return static_cast ( pStack->Return(nullptr, pStk)); -} - -// runs, is a variable and assigns the result to the stack -bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) -{ - CBotStack* pile = pj->AddStack(); - - CBotVar* var1 = nullptr; - CBotVar* var2 = nullptr; - // fetch a variable (not copy) - if (!ExecuteVar(var1, array, nullptr, false)) return false; - - if (pile->IfStep()) return false; - - if (var1) - { - var2 = pj->GetVar(); // result on the input stack - if (var2) - { - CBotTypResult t1 = var1->GetTypResult(); - CBotTypResult t2 = var2->GetTypResult(); - if (t2.Eq(CBotTypPointer)) - { - CBotClass* c1 = t1.GetClass(); - CBotClass* c2 = t2.GetClass(); - if ( !c2->IsChildOf(c1)) - { - CBotToken* pt = &m_token; - pile->SetError(TX_BADTYPE, pt); - return pj->Return(pile); // operation performed - } - } - var1->SetVal(var2); // do assignment - } - pile->SetCopyVar(var1); // replace the stack with the copy of the variable - // (for name) - } - - return pj->Return(pile); // operation performed -} - -// fetch a variable during compilation - -bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) -{ - pVar = pile->FindVar(m_token); - if (pVar == nullptr) return false; - - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pile) ) return false; - - return true; -} - -// fetch the variable at runtume - -bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep) -{ - pile = pile->AddStack(this); - - pVar = pile->FindVar(m_nIdent); - if (pVar == nullptr) - { -#ifdef _DEBUG - assert(0); -#endif - pile->SetError(2, &m_token); - return false; - } - - if (bStep && m_next3 == nullptr && pile->IfStep()) return false; - - if ( m_next3 != nullptr && - !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, true) ) return false; - - return true; -} - -void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) -{ - pile = pile->RestoreStack(this); - if (pile == nullptr) return; - - if (m_next3 != nullptr) - m_next3->RestoreStateVar(pile, bMain); -} - ////////////////////////////////////////////////////////////////////////////////////////// // compile a list of parameters diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a0beb27a..481335ec 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -648,28 +648,6 @@ public: CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; - -// left operand -// accept the expressions that be to the left of assignment - -class CBotLeftExpr : public CBotInstr -{ -private: - long m_nIdent; - -public: - CBotLeftExpr(); - ~CBotLeftExpr(); - static - CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack, CBotStack* array); - - bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); - void RestoreStateVar(CBotStack* &pile, bool bMain) override; -}; - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotExpression.h b/src/CBot/CBotInstr/CBotExpression.h index b47e9e24..d25fd39c 100644 --- a/src/CBot/CBotInstr/CBotExpression.h +++ b/src/CBot/CBotInstr/CBotExpression.h @@ -21,6 +21,7 @@ // Modules inlcude #include "CBot.h" +#include "CBotLeftExpr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp new file mode 100644 index 00000000..66e0dce5 --- /dev/null +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -0,0 +1,242 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotLeftExpr.h" +#include "CBotFieldExpr.h" +#include "CBotIndexExpr.h" +#include "CBotExpression.h" + +// Local include + +// Global include + + +////////////////////////////////////////////////////////////////////////////////////// +CBotLeftExpr::CBotLeftExpr() +{ + name = "CBotLeftExpr"; + m_nIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotLeftExpr::~CBotLeftExpr() +{ +} + +//////////////////////////////////////////////////////////////////////////////// +CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotCStack* pStk = pStack->TokenStack(); + + pStk->SetStartError(p->GetStart()); + + // is it a variable name? + if (p->GetType() == TokenTypVar) + { + CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object + + inst->SetToken(p); + + CBotVar* var; + + if (nullptr != (var = pStk->FindVar(p))) // seek if known variable + { + inst->m_nIdent = var->GetUniqNum(); + if (inst->m_nIdent > 0 && inst->m_nIdent < 9000) + { + if ( var->IsPrivate(PR_READ) && + !pStk->GetBotCall()->m_bCompileClass) + { + pStk->SetError(TX_PRIVATE, p); + goto err; + } + // this is an element of the current class + // adds the equivalent of this. before + CBotToken pthis("this"); + inst->SetToken(&pthis); + inst->m_nIdent = -2; // indent for this + + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(p); // keeps the name of the token + inst->AddNext3(i); // add after + + var = pStk->FindVar(pthis); + var = var->GetItem(p->GetString()); + i->SetUniqNum(var->GetUniqNum()); + } + p = p->GetNext(); // next token + + while (true) + { + if (var->GetType() == CBotTypArrayPointer) + { + if (IsOfType( p, ID_OPBRK )) + { + CBotIndexExpr* i = new CBotIndexExpr(); + i->m_expr = CBotExpression::Compile(p, pStk); + inst->AddNext3(i); // add to the chain + + var = (static_cast(var))->GetItem(0,true); // gets the component [0] + + if (i->m_expr == nullptr) + { + pStk->SetError(TX_BADINDEX, p->GetStart()); + goto err; + } + + if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto err; + } + continue; + } + } + + if (var->GetType(1) == CBotTypPointer) // for classes + { + if (IsOfType(p, ID_DOT)) + { + CBotToken* pp = p; + + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(pp); // keeps the name of the token + inst->AddNext3(i); // adds after + + if (p->GetType() == TokenTypVar) // must be a name + { + var = var->GetItem(p->GetString()); // get item correspondent + if (var != nullptr) + { + if ( var->IsPrivate(PR_READ) && + !pStk->GetBotCall()->m_bCompileClass) + { + pStk->SetError(TX_PRIVATE, pp); + goto err; + } + + i->SetUniqNum(var->GetUniqNum()); + p = p->GetNext(); // skips the name + continue; + } + pStk->SetError(TX_NOITEM, p); + } + pStk->SetError(TX_DOT, p->GetStart()); + goto err; + } + } + break; + } + + + if (pStk->IsOk()) return static_cast (pStack->Return(inst, pStk)); + } + pStk->SetError(TX_UNDEFVAR, p); +err: + delete inst; + return static_cast ( pStack->Return(nullptr, pStk)); + } + + return static_cast ( pStack->Return(nullptr, pStk)); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) +{ + CBotStack* pile = pj->AddStack(); + + CBotVar* var1 = nullptr; + CBotVar* var2 = nullptr; + // fetch a variable (not copy) + if (!ExecuteVar(var1, array, nullptr, false)) return false; + + if (pile->IfStep()) return false; + + if (var1) + { + var2 = pj->GetVar(); // result on the input stack + if (var2) + { + CBotTypResult t1 = var1->GetTypResult(); + CBotTypResult t2 = var2->GetTypResult(); + if (t2.Eq(CBotTypPointer)) + { + CBotClass* c1 = t1.GetClass(); + CBotClass* c2 = t2.GetClass(); + if ( !c2->IsChildOf(c1)) + { + CBotToken* pt = &m_token; + pile->SetError(TX_BADTYPE, pt); + return pj->Return(pile); // operation performed + } + } + var1->SetVal(var2); // do assignment + } + pile->SetCopyVar(var1); // replace the stack with the copy of the variable + // (for name) + } + + return pj->Return(pile); // operation performed +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +{ + pVar = pile->FindVar(m_token); + if (pVar == nullptr) return false; + + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pile) ) return false; + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep) +{ + pile = pile->AddStack(this); + + pVar = pile->FindVar(m_nIdent); + if (pVar == nullptr) + { +#ifdef _DEBUG + assert(0); +#endif + pile->SetError(2, &m_token); + return false; + } + + if (bStep && m_next3 == nullptr && pile->IfStep()) return false; + + if ( m_next3 != nullptr && + !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, true) ) return false; + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) +{ + pile = pile->RestoreStack(this); + if (pile == nullptr) return; + + if (m_next3 != nullptr) + m_next3->RestoreStateVar(pile, bMain); +} diff --git a/src/CBot/CBotInstr/CBotLeftExpr.h b/src/CBot/CBotInstr/CBotLeftExpr.h new file mode 100644 index 00000000..f0dba0b4 --- /dev/null +++ b/src/CBot/CBotInstr/CBotLeftExpr.h @@ -0,0 +1,101 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotLeftExpr class Accept the expressions that be to the left of + * assignment. + */ +class CBotLeftExpr : public CBotInstr +{ +public: + + /*! + * \brief CBotLeftExpr + */ + CBotLeftExpr(); + + /*! + * \brief ~CBotLeftExpr + */ + ~CBotLeftExpr(); + + /*! + * \brief Compile Compiles an expression for a left-operand + * (left of an assignment). + * eg : + * - toto + * - toto[ 3 ] + * - toto.x + * - toto.pos.x + * - toto[2].pos.x + * - toto[1].pos[2].x + * - toto[1][2][3] + * + * \param p + * \param pStack + * \return + */ + static CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Runs, is a variable and assigns the result to the stack. + * \param pStack + * \param array + * \return + */ + bool Execute(CBotStack* &pStack, CBotStack* array); + + /*! + * \brief ExecuteVar Fetch a variable during compilation. + * \param pVar + * \param pile + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override; + + /*! + * \brief ExecuteVar Fetch the variable at runtume. + * \param pVar + * \param pile + * \param prevToken + * \param bStep + * \return + */ + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); + + /*! + * \brief RestoreStateVar + * \param pile + * \param bMain + */ + void RestoreStateVar(CBotStack* &pile, bool bMain) override; + +private: + long m_nIdent; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 29380c32..028c4d8f 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -40,6 +40,7 @@ set(SOURCES CBotInstr/CBotExpression.cpp CBotInstr/CBotIndexExpr.cpp CBotInstr/CBotFieldExpr.cpp + CBotInstr/CBotLeftExpr.cpp ) # Includes From dc8a6b32739c47ccb51571f7c587a21cdb2137b8 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:24:37 +0100 Subject: [PATCH 089/360] Moving CBotCondition class in its own header and source files. --- src/CBot/CBot.cpp | 31 ----------------- src/CBot/CBot.h | 10 ------ src/CBot/CBotIf.cpp | 1 + src/CBot/CBotInstr/CBotCondition.cpp | 50 ++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotCondition.h | 46 +++++++++++++++++++++++++ src/CBot/CBotInstr/CBotDo.cpp | 1 + src/CBot/CBotInstr/CBotWhile.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 8 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotCondition.cpp create mode 100644 src/CBot/CBotInstr/CBotCondition.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index c4ac2874..7ad12b3f 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -1348,37 +1348,6 @@ void CBotIString::RestoreState(CBotStack* &pj, bool bMain) m_next2b->RestoreState(pile, bMain); } - -////////////////////////////////////////////////////////////////////////////////////// -// compile a statement such as "(condition)" -// the condition must be Boolean - -// this class has no constructor, because there is never an instance of this class -// the object returned by Compile is usually type CBotExpression - - -CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) -{ - pStack->SetStartError(p->GetStart()); - if (IsOfType(p, ID_OPENPAR)) - { - CBotInstr* inst = CBotBoolExpr::Compile(p, pStack); - if (nullptr != inst) - { - if (IsOfType(p, ID_CLOSEPAR)) - { - return inst; - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); // missing parenthesis - } - delete inst; - } - - pStack->SetError(TX_OPENPAR, p->GetStart()); // missing parenthesis - - return nullptr; -} - ////////////////////////////////////////////////////////////////////////////////////////// // compile a list of parameters diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 481335ec..1b038cb2 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -638,16 +638,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -class CBotCondition : public CBotInstr -{ -private: - -public: - - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotIf.cpp b/src/CBot/CBotIf.cpp index 781ec12c..551ecb18 100644 --- a/src/CBot/CBotIf.cpp +++ b/src/CBot/CBotIf.cpp @@ -23,6 +23,7 @@ #include "CBot.h" #include "CBotInstr/CBotBlock.h" +#include "CBotInstr/CBotCondition.h" // various constructors / destructors CBotIf::CBotIf() diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp new file mode 100644 index 00000000..d87c451b --- /dev/null +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -0,0 +1,50 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotCondition.h" +#include "CBotBoolExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) +{ + pStack->SetStartError(p->GetStart()); + if (IsOfType(p, ID_OPENPAR)) + { + CBotInstr* inst = CBotBoolExpr::Compile(p, pStack); + if (nullptr != inst) + { + if (IsOfType(p, ID_CLOSEPAR)) + { + return inst; + } + pStack->SetError(TX_CLOSEPAR, p->GetStart()); // missing parenthesis + } + delete inst; + } + + pStack->SetError(TX_OPENPAR, p->GetStart()); // missing parenthesis + + return nullptr; +} diff --git a/src/CBot/CBotInstr/CBotCondition.h b/src/CBot/CBotInstr/CBotCondition.h new file mode 100644 index 00000000..08996db1 --- /dev/null +++ b/src/CBot/CBotInstr/CBotCondition.h @@ -0,0 +1,46 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotCondition class This class has no constructor, because there + * is never an instance of this class the object returned by Compile is usually + * type CBotExpression + */ +class CBotCondition : public CBotInstr +{ +public: + + /*! + * \brief Compile Compile a statement such as "(condition)" the condition + * must be Boolean + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); +}; diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index 94c281d4..3bf3aefd 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotDo.h" #include "CBotBlock.h" +#include "CBotCondition.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index 340cc239..c24084b6 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotWhile.h" #include "CBotBlock.h" +#include "CBotCondition.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 028c4d8f..e94bf82b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -41,6 +41,7 @@ set(SOURCES CBotInstr/CBotIndexExpr.cpp CBotInstr/CBotFieldExpr.cpp CBotInstr/CBotLeftExpr.cpp + CBotInstr/CBotCondition.cpp ) # Includes From bbf2e48802082ff0fbd336b2f5a5eeb4200f818c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:36:18 +0100 Subject: [PATCH 090/360] Moving CBotClassInst class in its own header and source files. --- src/CBot/CBot.cpp | 2 + src/CBot/CBot.h | 20 -- src/CBot/CBotClass.cpp | 411 ------------------------- src/CBot/CBotInstr/CBotClassInst.cpp | 430 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotClassInst.h | 85 ++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 518 insertions(+), 431 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotClassInst.cpp create mode 100644 src/CBot/CBotInstr/CBotClassInst.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 7ad12b3f..9e4716ec 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -61,6 +61,8 @@ #include "CBotInstr/CBotExpression.h" #include "CBotInstr/CBotIndexExpr.h" #include "CBotInstr/CBotFieldExpr.h" +#include "CBotInstr/CBotClassInst.h" + // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 1b038cb2..a045dc37 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -617,26 +617,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -// definition of an element of any class - -class CBotClassInst : public CBotInstr -{ -private: - CBotInstr* m_var; // variable to initialise - CBotClass* m_pClass; // reference to the class - CBotInstr* m_Parameters; // parameters to be evaluated for the contructor - CBotInstr* m_expr; // a value to put, if there is - bool m_hasParams; // has it parameters? - long m_nMethodeIdent; - -public: - CBotClassInst(); - ~CBotClassInst(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 11f93a1f..f98eaaaa 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -463,417 +463,6 @@ bool CBotClass::RestoreStaticState(FILE* pf) return true; } - -///////////////////////////////////////////////////////////////////// - -CBotClassInst::CBotClassInst() -{ - m_next = nullptr; - m_var = nullptr; - m_Parameters = nullptr; - m_expr = nullptr; - m_hasParams = false; - m_nMethodeIdent = 0; - name = "CBotClassInst"; -} - -CBotClassInst::~CBotClassInst() -{ - delete m_var; -// delete m_next; // done by the destructor of the base class ~CBotInstr() -} - -// definition of pointer (s) to an object -// style -// CPoint A, B ; - -CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass) -{ - // seeks the corresponding classes - if ( pClass == nullptr ) - { - pStack->SetStartError(p->GetStart()); - pClass = CBotClass::Find(p); - if ( pClass == nullptr ) - { - // not found? is bizare - pStack->SetError(TX_NOCLASS, p); - return nullptr; - } - p = p->GetNext(); - } - - bool bIntrinsic = pClass->IsIntrinsic(); - CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass ); - CBotClassInst* inst = static_cast(CompileArray(p, pStack, type)); - if ( inst != nullptr || !pStack->IsOk() ) return inst; - - CBotCStack* pStk = pStack->TokenStack(); - - inst = new CBotClassInst(); - /// TODO Need to be revised and fixed after adding unit tests - CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd()); - inst->SetToken(&token); - CBotToken* vartoken = p; - - if ( nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) - { - (static_cast(inst->m_var))->m_typevar = type; - if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable - { - pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); - goto error; - } - - if (IsOfType(p, ID_OPBRK)) // with any clues? - { - delete inst; // is not type CBotInt - p = vartoken; // returns to the variable name - - // compiles declaration an array - - inst = static_cast(CBotInstArray::Compile( p, pStk, type )); - - if (!pStk->IsOk() ) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - goto suite; // no assignment, variable already created - } - - - CBotVar* var; - var = CBotVar::Create(vartoken->GetString(), type); // creates the instance -// var->SetClass(pClass); - var->SetUniqNum( - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - // its attribute a unique number - pStack->AddVar(var); // placed on the stack - - // look if there are parameters - inst->m_hasParams = (p->GetType() == ID_OPENPAR); - - CBotVar* ppVars[1000]; - inst->m_Parameters = CompileParams(p, pStk, ppVars); - if ( !pStk->IsOk() ) goto error; - - // if there are parameters, is the equivalent to the stament "new" - // CPoint A ( 0, 0 ) is equivalent to - // CPoint A = new CPoint( 0, 0 ) - -// if ( nullptr != inst->m_Parameters ) - if ( inst->m_hasParams ) - { - // the constructor is there? -// CBotString noname; - CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent); - delete pStk->TokenStack(); // releases the supplement stack - int typ = r.GetType(); - - if (typ == TX_UNDEFCALL) - { - // si le constructeur n'existe pas - if (inst->m_Parameters != nullptr) // with parameters - { - pStk->SetError(TX_NOCONST, vartoken); - goto error; - } - typ = 0; - } - - if (typ>20) - { - pStk->SetError(typ, vartoken->GetEnd()); - goto error; - } - - } - - if (IsOfType(p, ID_ASS)) // with a assignment? - { - if (inst->m_hasParams) - { - pStk->SetError(TX_ENDOF, p->GetStart()); - goto error; - } - - if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) - { - goto error; - } - CBotClass* result = pStk->GetClass(); - if ( !pStk->GetTypResult(1).Eq(CBotTypNullPointer) && - ( !pStk->GetTypResult(1).Eq(CBotTypPointer) || - ( result != nullptr && !pClass->IsChildOf(result) ))) // type compatible ? - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } -// if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer()); - if ( !bIntrinsic ) - { - // does not use the result on the stack, to impose the class - CBotVar* pvar = CBotVar::Create("", pClass); - var->SetPointer( pvar ); // variable already declared instance pointer - delete pvar; // removes the second pointer - } - var->SetInit(CBotVar::InitType::DEF); // marks the pointer as init - } - else if (inst->m_hasParams) - { - // creates the object on the "job" (\TODO "tas") - // with a pointer to the object - if ( !bIntrinsic ) - { - CBotVar* pvar = CBotVar::Create("", pClass); - var->SetPointer( pvar ); // variable already declared instance pointer - delete pvar; // removes the second pointer - } - var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init - } -suite: - if (IsOfType(p, ID_COMMA)) // several chained definitions - { - if ( nullptr != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) )) // compiles the following - { - return pStack->Return(inst, pStk); - } - } - - if (IsOfType(p, ID_SEP)) // complete instruction - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// declaration of the instance of a class, for example: -// CPoint A, B; - -bool CBotClassInst::Execute(CBotStack* &pj) -{ - CBotVar* pThis = nullptr; - - CBotStack* pile = pj->AddStack(this);//essential for SetState() -// if ( pile == EOX ) return true; - - CBotToken* pt = &m_token; - CBotClass* pClass = CBotClass::Find(pt); - - bool bIntrincic = pClass->IsIntrinsic(); - - // creates the variable of type pointer to the object - - if ( pile->GetState()==0) - { - CBotString name = m_var->m_token.GetString(); - if ( bIntrincic ) - { - pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass )); - } - else - { - pThis = CBotVar::Create(name, CBotTypResult( CBotTypPointer, pClass )); - } - - pThis->SetUniqNum((static_cast(m_var))->m_nIdent); // its attribute as unique number - pile->AddVar(pThis); // place on the stack - pile->IncState(); - } - - if ( pThis == nullptr ) pThis = pile->FindVar((static_cast(m_var))->m_nIdent); - - if ( pile->GetState()<3) - { - // ss there an assignment or parameters (contructor) - -// CBotVarClass* pInstance = nullptr; - - if ( m_expr != nullptr ) - { - // evaluates the expression for the assignment - if (!m_expr->Execute(pile)) return false; - - if ( bIntrincic ) - { - CBotVar* pv = pile->GetVar(); - if ( pv == nullptr || pv->GetPointer() == nullptr ) - { - pile->SetError(TX_NULLPT, &m_token); - return pj->Return(pile); - } - pThis->Copy(pile->GetVar(), false); - } - else - { - CBotVarClass* pInstance; - pInstance = (static_cast(pile->GetVar()))->GetPointer(); // value for the assignment - pThis->SetPointer(pInstance); - } - pThis->SetInit(CBotVar::InitType::DEF); - } - - else if ( m_hasParams ) - { - // evaluates the constructor of an instance - - if ( !bIntrincic && pile->GetState() == 1) - { - CBotToken* pt = &m_token; - CBotClass* pClass = CBotClass::Find(pt); - - // creates an instance of the requested class - - CBotVarClass* pInstance; - pInstance = static_cast(CBotVar::Create("", pClass)); - pThis->SetPointer(pInstance); - delete pInstance; - - pile->IncState(); - } - - CBotVar* ppVars[1000]; - CBotStack* pile2 = pile; - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluates the parameters - // and places the values ​​on the stack - // to (can) be interrupted (broken) at any time - - if ( p != nullptr) while ( true ) - { - pile2 = pile2->AddStack(); // place on the stack for the results - if ( pile2->GetState() == 0 ) - { - if (!p->Execute(pile2)) return false; // interrupted here? - pile2->SetState(1); - } - ppVars[i++] = pile2->GetVar(); - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - // creates a variable for the result - CBotVar* pResult = nullptr; // constructor still void - - if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), - pThis, ppVars, - pResult, pile2, GetToken())) return false; // interrupt - - pThis->SetInit(CBotVar::InitType::DEF); - pThis->ConstructorSet(); // indicates that the constructor has been called - pile->Return(pile2); // releases a piece of stack - -// pInstance = pThis->GetPointer(); - - } - -// if ( !bIntrincic ) pThis->SetPointer(pInstance); // a pointer to the instance - - pile->SetState(3); // finished this part - } - - if ( pile->IfStep() ) return false; - - if ( m_next2b != nullptr && - !m_next2b->Execute(pile)) return false; // other (s) definition (s) - - return pj->Return( pile ); // transmits below (further) -} - - - -void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotVar* pThis = nullptr; - - CBotStack* pile = pj; - if ( bMain ) pile = pj->RestoreStack(this); - if ( pile == nullptr ) return; - - // creates the variable of type pointer to the object - { - CBotString name = m_var->m_token.GetString(); - pThis = pile->FindVar(name); - pThis->SetUniqNum((static_cast(m_var))->m_nIdent); // its attribute a unique number - } - - CBotToken* pt = &m_token; - CBotClass* pClass = CBotClass::Find(pt); - bool bIntrincic = pClass->IsIntrinsic(); - - if ( bMain && pile->GetState()<3) - { - // is there an assignment or parameters (constructor) - -// CBotVarClass* pInstance = nullptr; - - if ( m_expr != nullptr ) - { - // evaluates the expression for the assignment - m_expr->RestoreState(pile, bMain); - return; - } - - else if ( m_hasParams ) - { - // evaluates the constructor of an instance - - if ( !bIntrincic && pile->GetState() == 1) - { - return; - } - - CBotVar* ppVars[1000]; - CBotStack* pile2 = pile; - - int i = 0; - - CBotInstr* p = m_Parameters; - // evaluates the parameters - // and the values an the stack - // for the ability to be interrupted at any time (\TODO pour pouvoir être interrompu n'importe quand) - - if ( p != nullptr) while ( true ) - { - pile2 = pile2->RestoreStack(); // place on the stack for the results - if ( pile2 == nullptr ) return; - - if ( pile2->GetState() == 0 ) - { - p->RestoreState(pile2, bMain); // interrupted here? - return; - } - ppVars[i++] = pile2->GetVar(); - p = p->GetNext(); - if ( p == nullptr) break; - } - ppVars[i] = nullptr; - - // creates a variable for the result -// CBotVar* pResult = nullptr; // constructor still void - - pClass->RestoreMethode(m_nMethodeIdent, pClass->GetName(), pThis, ppVars, pile2); - return; - } - } - - if ( m_next2b != nullptr ) - m_next2b->RestoreState(pile, bMain); // other(s) definition(s) -} - - // test if a procedure name is already defined somewhere bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp new file mode 100644 index 00000000..cf835df3 --- /dev/null +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -0,0 +1,430 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotClassInst.h" +#include "CBotLeftExprVar.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotClassInst::CBotClassInst() +{ + m_next = nullptr; + m_var = nullptr; + m_Parameters = nullptr; + m_expr = nullptr; + m_hasParams = false; + m_nMethodeIdent = 0; + name = "CBotClassInst"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClassInst::~CBotClassInst() +{ + delete m_var; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass) +{ + // seeks the corresponding classes + if ( pClass == nullptr ) + { + pStack->SetStartError(p->GetStart()); + pClass = CBotClass::Find(p); + if ( pClass == nullptr ) + { + // not found? is bizare + pStack->SetError(TX_NOCLASS, p); + return nullptr; + } + p = p->GetNext(); + } + + bool bIntrinsic = pClass->IsIntrinsic(); + CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass ); + CBotClassInst* inst = static_cast(CompileArray(p, pStack, type)); + if ( inst != nullptr || !pStack->IsOk() ) return inst; + + CBotCStack* pStk = pStack->TokenStack(); + + inst = new CBotClassInst(); + /// TODO Need to be revised and fixed after adding unit tests + CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd()); + inst->SetToken(&token); + CBotToken* vartoken = p; + + if ( nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) + { + (static_cast(inst->m_var))->m_typevar = type; + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable + { + pStk->SetStartError(vartoken->GetStart()); + pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + goto error; + } + + if (IsOfType(p, ID_OPBRK)) // with any clues? + { + delete inst; // is not type CBotInt + p = vartoken; // returns to the variable name + + // compiles declaration an array + + inst = static_cast(CBotInstArray::Compile( p, pStk, type )); + + if (!pStk->IsOk() ) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + goto suite; // no assignment, variable already created + } + + + CBotVar* var; + var = CBotVar::Create(vartoken->GetString(), type); // creates the instance +// var->SetClass(pClass); + var->SetUniqNum( + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + // its attribute a unique number + pStack->AddVar(var); // placed on the stack + + // look if there are parameters + inst->m_hasParams = (p->GetType() == ID_OPENPAR); + + CBotVar* ppVars[1000]; + inst->m_Parameters = CompileParams(p, pStk, ppVars); + if ( !pStk->IsOk() ) goto error; + + // if there are parameters, is the equivalent to the stament "new" + // CPoint A ( 0, 0 ) is equivalent to + // CPoint A = new CPoint( 0, 0 ) + +// if ( nullptr != inst->m_Parameters ) + if ( inst->m_hasParams ) + { + // the constructor is there? +// CBotString noname; + CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent); + delete pStk->TokenStack(); // releases the supplement stack + int typ = r.GetType(); + + if (typ == TX_UNDEFCALL) + { + // si le constructeur n'existe pas + if (inst->m_Parameters != nullptr) // with parameters + { + pStk->SetError(TX_NOCONST, vartoken); + goto error; + } + typ = 0; + } + + if (typ>20) + { + pStk->SetError(typ, vartoken->GetEnd()); + goto error; + } + + } + + if (IsOfType(p, ID_ASS)) // with a assignment? + { + if (inst->m_hasParams) + { + pStk->SetError(TX_ENDOF, p->GetStart()); + goto error; + } + + if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + { + goto error; + } + CBotClass* result = pStk->GetClass(); + if ( !pStk->GetTypResult(1).Eq(CBotTypNullPointer) && + ( !pStk->GetTypResult(1).Eq(CBotTypPointer) || + ( result != nullptr && !pClass->IsChildOf(result) ))) // type compatible ? + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } +// if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer()); + if ( !bIntrinsic ) + { + // does not use the result on the stack, to impose the class + CBotVar* pvar = CBotVar::Create("", pClass); + var->SetPointer( pvar ); // variable already declared instance pointer + delete pvar; // removes the second pointer + } + var->SetInit(CBotVar::InitType::DEF); // marks the pointer as init + } + else if (inst->m_hasParams) + { + // creates the object on the "job" (\TODO "tas") + // with a pointer to the object + if ( !bIntrinsic ) + { + CBotVar* pvar = CBotVar::Create("", pClass); + var->SetPointer( pvar ); // variable already declared instance pointer + delete pvar; // removes the second pointer + } + var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init + } +suite: + if (IsOfType(p, ID_COMMA)) // several chained definitions + { + if ( nullptr != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) )) // compiles the following + { + return pStack->Return(inst, pStk); + } + } + + if (IsOfType(p, ID_SEP)) // complete instruction + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotClassInst::Execute(CBotStack* &pj) +{ + CBotVar* pThis = nullptr; + + CBotStack* pile = pj->AddStack(this);//essential for SetState() +// if ( pile == EOX ) return true; + + CBotToken* pt = &m_token; + CBotClass* pClass = CBotClass::Find(pt); + + bool bIntrincic = pClass->IsIntrinsic(); + + // creates the variable of type pointer to the object + + if ( pile->GetState()==0) + { + CBotString name = m_var->m_token.GetString(); + if ( bIntrincic ) + { + pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass )); + } + else + { + pThis = CBotVar::Create(name, CBotTypResult( CBotTypPointer, pClass )); + } + + pThis->SetUniqNum((static_cast(m_var))->m_nIdent); // its attribute as unique number + pile->AddVar(pThis); // place on the stack + pile->IncState(); + } + + if ( pThis == nullptr ) pThis = pile->FindVar((static_cast(m_var))->m_nIdent); + + if ( pile->GetState()<3) + { + // ss there an assignment or parameters (contructor) + +// CBotVarClass* pInstance = nullptr; + + if ( m_expr != nullptr ) + { + // evaluates the expression for the assignment + if (!m_expr->Execute(pile)) return false; + + if ( bIntrincic ) + { + CBotVar* pv = pile->GetVar(); + if ( pv == nullptr || pv->GetPointer() == nullptr ) + { + pile->SetError(TX_NULLPT, &m_token); + return pj->Return(pile); + } + pThis->Copy(pile->GetVar(), false); + } + else + { + CBotVarClass* pInstance; + pInstance = (static_cast(pile->GetVar()))->GetPointer(); // value for the assignment + pThis->SetPointer(pInstance); + } + pThis->SetInit(CBotVar::InitType::DEF); + } + + else if ( m_hasParams ) + { + // evaluates the constructor of an instance + + if ( !bIntrincic && pile->GetState() == 1) + { + CBotToken* pt = &m_token; + CBotClass* pClass = CBotClass::Find(pt); + + // creates an instance of the requested class + + CBotVarClass* pInstance; + pInstance = static_cast(CBotVar::Create("", pClass)); + pThis->SetPointer(pInstance); + delete pInstance; + + pile->IncState(); + } + + CBotVar* ppVars[1000]; + CBotStack* pile2 = pile; + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluates the parameters + // and places the values ​​on the stack + // to (can) be interrupted (broken) at any time + + if ( p != nullptr) while ( true ) + { + pile2 = pile2->AddStack(); // place on the stack for the results + if ( pile2->GetState() == 0 ) + { + if (!p->Execute(pile2)) return false; // interrupted here? + pile2->SetState(1); + } + ppVars[i++] = pile2->GetVar(); + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + // creates a variable for the result + CBotVar* pResult = nullptr; // constructor still void + + if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), + pThis, ppVars, + pResult, pile2, GetToken())) return false; // interrupt + + pThis->SetInit(CBotVar::InitType::DEF); + pThis->ConstructorSet(); // indicates that the constructor has been called + pile->Return(pile2); // releases a piece of stack + +// pInstance = pThis->GetPointer(); + + } + +// if ( !bIntrincic ) pThis->SetPointer(pInstance); // a pointer to the instance + + pile->SetState(3); // finished this part + } + + if ( pile->IfStep() ) return false; + + if ( m_next2b != nullptr && + !m_next2b->Execute(pile)) return false; // other (s) definition (s) + + return pj->Return( pile ); // transmits below (further) +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotVar* pThis = nullptr; + + CBotStack* pile = pj; + if ( bMain ) pile = pj->RestoreStack(this); + if ( pile == nullptr ) return; + + // creates the variable of type pointer to the object + { + CBotString name = m_var->m_token.GetString(); + pThis = pile->FindVar(name); + pThis->SetUniqNum((static_cast(m_var))->m_nIdent); // its attribute a unique number + } + + CBotToken* pt = &m_token; + CBotClass* pClass = CBotClass::Find(pt); + bool bIntrincic = pClass->IsIntrinsic(); + + if ( bMain && pile->GetState()<3) + { + // is there an assignment or parameters (constructor) + +// CBotVarClass* pInstance = nullptr; + + if ( m_expr != nullptr ) + { + // evaluates the expression for the assignment + m_expr->RestoreState(pile, bMain); + return; + } + + else if ( m_hasParams ) + { + // evaluates the constructor of an instance + + if ( !bIntrincic && pile->GetState() == 1) + { + return; + } + + CBotVar* ppVars[1000]; + CBotStack* pile2 = pile; + + int i = 0; + + CBotInstr* p = m_Parameters; + // evaluates the parameters + // and the values an the stack + // for the ability to be interrupted at any time (\TODO pour pouvoir être interrompu n'importe quand) + + if ( p != nullptr) while ( true ) + { + pile2 = pile2->RestoreStack(); // place on the stack for the results + if ( pile2 == nullptr ) return; + + if ( pile2->GetState() == 0 ) + { + p->RestoreState(pile2, bMain); // interrupted here? + return; + } + ppVars[i++] = pile2->GetVar(); + p = p->GetNext(); + if ( p == nullptr) break; + } + ppVars[i] = nullptr; + + // creates a variable for the result +// CBotVar* pResult = nullptr; // constructor still void + + pClass->RestoreMethode(m_nMethodeIdent, pClass->GetName(), pThis, ppVars, pile2); + return; + } + } + + if ( m_next2b != nullptr ) + m_next2b->RestoreState(pile, bMain); // other(s) definition(s) +} diff --git a/src/CBot/CBotInstr/CBotClassInst.h b/src/CBot/CBotInstr/CBotClassInst.h new file mode 100644 index 00000000..370a46cd --- /dev/null +++ b/src/CBot/CBotInstr/CBotClassInst.h @@ -0,0 +1,85 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotClassInst class Definition of an element of any class. + */ +class CBotClassInst : public CBotInstr +{ + +public: + + /*! + * \brief CBotClassInst + */ + CBotClassInst(); + + /*! + * \brief ~CBotClassInst + */ + ~CBotClassInst(); + + /*! + * \brief Compile Definition of pointer (s) to an object style CPoint A, B ; + * \param p + * \param pStack + * \param pClass + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr); + + /*! + * \brief Execute Declaration of the instance of a class, for example: + * CPoint A, B; + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! Variable to initialise. + CBotInstr* m_var; + //! Reference to the class. + CBotClass* m_pClass; + //! Parameters to be evaluated for the contructor. + CBotInstr* m_Parameters; + //! A value to put, if there is. + CBotInstr* m_expr; + //! Has it parameters. + bool m_hasParams; + long m_nMethodeIdent; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index e94bf82b..7142723d 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -42,6 +42,7 @@ set(SOURCES CBotInstr/CBotFieldExpr.cpp CBotInstr/CBotLeftExpr.cpp CBotInstr/CBotCondition.cpp + CBotInstr/CBotClassInst.cpp ) # Includes From 13b82b7e8e60afc6d69e35efe4c90a8a665535e9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:45:27 +0100 Subject: [PATCH 091/360] Moving CBotIString class in its own header and source files. --- src/CBot/CBot.cpp | 133 +----------------- src/CBot/CBot.h | 17 --- src/CBot/CBotInstr/CBotIString.cpp | 156 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotIString.h | 76 +++++++++++ src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 235 insertions(+), 149 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotIString.cpp create mode 100644 src/CBot/CBotInstr/CBotIString.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 9e4716ec..072aa28f 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -62,6 +62,7 @@ #include "CBotInstr/CBotIndexExpr.h" #include "CBotInstr/CBotFieldExpr.h" #include "CBotInstr/CBotClassInst.h" +#include "CBotInstr/CBotIString.h" // Local include @@ -1220,138 +1221,6 @@ void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// define a string variable -// int a, b = "salut"; - -CBotIString::CBotIString() -{ - m_var = - m_expr = nullptr; - name = "CBotIString"; -} - -CBotIString::~CBotIString() -{ - delete m_var; - delete m_expr; -} - -CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) -{ - CBotToken* pp = cont ? nullptr : p; - - if (!cont && !IsOfType(p, ID_STRING)) return nullptr; - - CBotIString* inst = static_cast(CompileArray(p, pStack, CBotTypString)); - if (inst != nullptr || !pStack->IsOk()) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotIString(); - - inst->m_expr = nullptr; - - CBotToken* vartoken = p; - inst->SetToken(vartoken); - - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - (static_cast(inst->m_var))->m_typevar = CBotTypString; - if (pStk->CheckVarLocal(vartoken)) - { - pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); - goto error; - } - - if (IsOfType(p, ID_ASS)) - { - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } -/* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - }*/ - } - - CBotVar* var = CBotVar::Create(vartoken, CBotTypString); - var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); - var->SetUniqNum( - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); - - if (IsOfType(p, ID_COMMA)) - { - if (nullptr != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip))) - { - return pStack->Return(inst, pStk); - } - } - - if (noskip || IsOfType(p, ID_SEP)) - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes the definition of the string variable - -bool CBotIString::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if ( pile->GetState()==0) - { - if (m_expr && !m_expr->Execute(pile)) return false; - m_var->Execute(pile); - - if (!pile->SetState(1)) return false; - } - - if (pile->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile)) return false; - - return pj->Return(pile); -} - -void CBotIString::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - - if (bMain) - { - pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if ( pile->GetState()==0) - { - if (m_expr) m_expr->RestoreState(pile, bMain); - return; - } - } - - m_var->RestoreState(pile, bMain); - - if (m_next2b) - m_next2b->RestoreState(pile, bMain); -} - -////////////////////////////////////////////////////////////////////////////////////////// - // compile a list of parameters CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a045dc37..9c1a8e21 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -600,23 +600,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -// definition of an element string - -class CBotIString : public CBotInstr -{ -private: - CBotInstr* m_var; // variable to initialise - CBotInstr* m_expr; // a value to put, if there is - -public: - CBotIString(); - ~CBotIString(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp new file mode 100644 index 00000000..b0e8a6a3 --- /dev/null +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -0,0 +1,156 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotIString.h" +#include "CBotLeftExprVar.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotIString::CBotIString() +{ + m_var = + m_expr = nullptr; + name = "CBotIString"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotIString::~CBotIString() +{ + delete m_var; + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) +{ + CBotToken* pp = cont ? nullptr : p; + + if (!cont && !IsOfType(p, ID_STRING)) return nullptr; + + CBotIString* inst = static_cast(CompileArray(p, pStack, CBotTypString)); + if (inst != nullptr || !pStack->IsOk()) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotIString(); + + inst->m_expr = nullptr; + + CBotToken* vartoken = p; + inst->SetToken(vartoken); + + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + (static_cast(inst->m_var))->m_typevar = CBotTypString; + if (pStk->CheckVarLocal(vartoken)) + { + pStk->SetStartError(vartoken->GetStart()); + pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + goto error; + } + + if (IsOfType(p, ID_ASS)) + { + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } +/* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + }*/ + } + + CBotVar* var = CBotVar::Create(vartoken, CBotTypString); + var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); + var->SetUniqNum( + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); + + if (IsOfType(p, ID_COMMA)) + { + if (nullptr != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip))) + { + return pStack->Return(inst, pStk); + } + } + + if (noskip || IsOfType(p, ID_SEP)) + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotIString::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if ( pile->GetState()==0) + { + if (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); + + if (!pile->SetState(1)) return false; + } + + if (pile->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile)) return false; + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotIString::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + + if (bMain) + { + pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if ( pile->GetState()==0) + { + if (m_expr) m_expr->RestoreState(pile, bMain); + return; + } + } + + m_var->RestoreState(pile, bMain); + + if (m_next2b) + m_next2b->RestoreState(pile, bMain); +} diff --git a/src/CBot/CBotInstr/CBotIString.h b/src/CBot/CBotInstr/CBotIString.h new file mode 100644 index 00000000..1d91ea26 --- /dev/null +++ b/src/CBot/CBotInstr/CBotIString.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotIString class Define a string variable eg : int a, b = "salut"; + */ +class CBotIString : public CBotInstr +{ +public: + + /*! + * \brief CBotIString + */ + CBotIString(); + + /*! + * \brief ~CBotIString + */ + ~CBotIString(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param cont + * \param noskip + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); + + /*! + * \brief Execute Executes the definition of the string variable. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Variable to initialise. + CBotInstr* m_var; + //! A value to put, if there is. + CBotInstr* m_expr; +}; diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index c631e762..285c6161 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -20,6 +20,7 @@ // Modules inlcude #include "CBotListExpression.h" #include "CBotExpression.h" +#include "CBotIString.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 7142723d..a0b76fcd 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -43,6 +43,7 @@ set(SOURCES CBotInstr/CBotLeftExpr.cpp CBotInstr/CBotCondition.cpp CBotInstr/CBotClassInst.cpp + CBotInstr/CBotIString.cpp ) # Includes From ff72d1a77f2cfeffce46fbe1d5e73bd4aa32c72b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 22:54:10 +0100 Subject: [PATCH 092/360] Moving CBotFloat class in its own header and source files. --- src/CBot/CBot.cpp | 147 +------------------ src/CBot/CBot.h | 19 --- src/CBot/CBotInstr/CBotFloat.cpp | 170 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotFloat.h | 76 ++++++++++ src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 249 insertions(+), 165 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotFloat.cpp create mode 100644 src/CBot/CBotInstr/CBotFloat.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 072aa28f..5cb8cace 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -63,6 +63,7 @@ #include "CBotInstr/CBotFieldExpr.h" #include "CBotInstr/CBotClassInst.h" #include "CBotInstr/CBotIString.h" +#include "CBotInstr/CBotFloat.h" // Local include @@ -1075,152 +1076,6 @@ void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// definition of a real/float variable -// int a, b = 12.4; - -CBotFloat::CBotFloat() -{ - m_var = - m_expr = nullptr; - name = "CBotFloat"; -} - -CBotFloat::~CBotFloat() -{ - delete m_var; - delete m_expr; -} - -CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) -{ - CBotToken* pp = cont ? nullptr : p; - - if (!cont && !IsOfType(p, ID_FLOAT)) return nullptr; - - CBotFloat* inst = static_cast(CompileArray(p, pStack, CBotTypFloat)); - if (inst != nullptr || !pStack->IsOk()) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotFloat(); - - inst->m_expr = nullptr; - - CBotToken* vartoken = p; - CBotVar* var = nullptr; - inst->SetToken(vartoken); - - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - (static_cast(inst->m_var))->m_typevar = CBotTypFloat; - if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable - { - pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); - goto error; - } - - if (IsOfType(p, ID_OPBRK)) - { - delete inst; - p = vartoken; - inst = static_cast(CBotInstArray::Compile(p, pStk, CBotTypFloat)); - - if (!pStk->IsOk() ) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - goto suite; // no assignment, variable already created - } - - if (IsOfType(p, ID_ASS)) - { - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } - if (pStk->GetType() >= CBotTypBoolean) - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - } - - var = CBotVar::Create(vartoken, CBotTypFloat); - var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); - var->SetUniqNum( - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); -suite: - if (IsOfType(p, ID_COMMA)) - { - if (nullptr != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip))) - { - return pStack->Return(inst, pStk); - } - } - - if (noskip || IsOfType(p, ID_SEP)) - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes the definition of a real variable - -bool CBotFloat::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if ( pile->GetState()==0) - { - if (m_expr && !m_expr->Execute(pile)) return false; - m_var->Execute(pile); - - if (!pile->SetState(1)) return false; - } - - if (pile->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile)) return false; - - return pj->Return(pile); -} - -void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - if (bMain) - { - pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if ( pile->GetState()==0) - { - if (m_expr) m_expr->RestoreState(pile, bMain); - return; - } - } - - m_var->RestoreState(pile, bMain); - - if (m_next2b) - m_next2b->RestoreState(pile, bMain); -} - -////////////////////////////////////////////////////////////////////////////////////////// - // compile a list of parameters CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 9c1a8e21..8ae8e36d 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -582,25 +582,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -// definition of a real number - -class CBotFloat : public CBotInstr -{ -private: - CBotInstr* m_var; // variable to initialise - CBotInstr* m_expr; // a value to put, if there is - -public: - CBotFloat(); - ~CBotFloat(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp new file mode 100644 index 00000000..96c730be --- /dev/null +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -0,0 +1,170 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotFloat.h" +#include "CBotLeftExprVar.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotFloat::CBotFloat() +{ + m_var = + m_expr = nullptr; + name = "CBotFloat"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotFloat::~CBotFloat() +{ + delete m_var; + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) +{ + CBotToken* pp = cont ? nullptr : p; + + if (!cont && !IsOfType(p, ID_FLOAT)) return nullptr; + + CBotFloat* inst = static_cast(CompileArray(p, pStack, CBotTypFloat)); + if (inst != nullptr || !pStack->IsOk()) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotFloat(); + + inst->m_expr = nullptr; + + CBotToken* vartoken = p; + CBotVar* var = nullptr; + inst->SetToken(vartoken); + + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + (static_cast(inst->m_var))->m_typevar = CBotTypFloat; + if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable + { + pStk->SetStartError(vartoken->GetStart()); + pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + goto error; + } + + if (IsOfType(p, ID_OPBRK)) + { + delete inst; + p = vartoken; + inst = static_cast(CBotInstArray::Compile(p, pStk, CBotTypFloat)); + + if (!pStk->IsOk() ) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + goto suite; // no assignment, variable already created + } + + if (IsOfType(p, ID_ASS)) + { + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } + if (pStk->GetType() >= CBotTypBoolean) + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + } + + var = CBotVar::Create(vartoken, CBotTypFloat); + var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); + var->SetUniqNum( + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); +suite: + if (IsOfType(p, ID_COMMA)) + { + if (nullptr != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip))) + { + return pStack->Return(inst, pStk); + } + } + + if (noskip || IsOfType(p, ID_SEP)) + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotFloat::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if ( pile->GetState()==0) + { + if (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); + + if (!pile->SetState(1)) return false; + } + + if (pile->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile)) return false; + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + if (bMain) + { + pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if ( pile->GetState()==0) + { + if (m_expr) m_expr->RestoreState(pile, bMain); + return; + } + } + + m_var->RestoreState(pile, bMain); + + if (m_next2b) + m_next2b->RestoreState(pile, bMain); +} diff --git a/src/CBot/CBotInstr/CBotFloat.h b/src/CBot/CBotInstr/CBotFloat.h new file mode 100644 index 00000000..6223071c --- /dev/null +++ b/src/CBot/CBotInstr/CBotFloat.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotFloat class Definition of a real/float variable int a, b = 12.4; + */ +class CBotFloat : public CBotInstr +{ +public: + + /*! + * \brief CBotFloat + */ + CBotFloat(); + + /*! + * \brief ~CBotFloat + */ + ~CBotFloat(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param cont + * \param noskip + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); + + /*! + * \brief Execute Executes the definition of a real variable. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Variable to initialise. + CBotInstr* m_var; + //! A value to put, if there is. + CBotInstr* m_expr; +}; diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 285c6161..0d2ec838 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -21,6 +21,7 @@ #include "CBotListExpression.h" #include "CBotExpression.h" #include "CBotIString.h" +#include "CBotFloat.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index a0b76fcd..60045335 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -44,6 +44,7 @@ set(SOURCES CBotInstr/CBotCondition.cpp CBotInstr/CBotClassInst.cpp CBotInstr/CBotIString.cpp + CBotInstr/CBotFloat.cpp ) # Includes From 17cbae8e688a551ba225f9d646ec8137cacd9ad0 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Wed, 11 Nov 2015 23:03:32 +0100 Subject: [PATCH 093/360] Moving CBotBoolean class in its own header and source files. --- src/CBot/CBot.cpp | 149 +------------------ src/CBot/CBot.h | 17 --- src/CBot/CBotInstr/CBotBoolean.cpp | 172 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotBoolean.h | 76 ++++++++++ src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 251 insertions(+), 165 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotBoolean.cpp create mode 100644 src/CBot/CBotInstr/CBotBoolean.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 5cb8cace..d08e01e7 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -64,6 +64,7 @@ #include "CBotInstr/CBotClassInst.h" #include "CBotInstr/CBotIString.h" #include "CBotInstr/CBotFloat.h" +#include "CBotInstr/CBotBoolean.h" // Local include @@ -928,154 +929,6 @@ void CBotInt::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// defining a boolean variable -// int a, b = false; - -CBotBoolean::CBotBoolean() -{ - m_var = - m_expr = nullptr; - name = "CBotBoolean"; -} - -CBotBoolean::~CBotBoolean() -{ - delete m_var; - delete m_expr; -} - -CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) -{ - CBotToken* pp = cont ? nullptr : p; - - if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return nullptr; - - CBotBoolean* inst = static_cast(CompileArray(p, pStack, CBotTypBoolean)); - if (inst != nullptr || !pStack->IsOk()) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotBoolean(); - - inst->m_expr = nullptr; - - CBotToken* vartoken = p; - inst->SetToken(vartoken); - CBotVar* var = nullptr; - - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - (static_cast(inst->m_var))->m_typevar = CBotTypBoolean; - if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable - { - pStk->SetError(TX_REDEFVAR, vartoken); - goto error; - } - - if (IsOfType(p, ID_OPBRK)) - { - delete inst; // type is not CBotInt - p = vartoken; // resutns to the variable name - - // compiles an array declaration - - inst = static_cast(CBotInstArray::Compile(p, pStk, CBotTypBoolean)); - - if (!pStk->IsOk() ) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - goto suite; // no assignment, variable already created - } - - if (IsOfType(p, ID_ASS)) - { - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } - if (!pStk->GetTypResult().Eq(CBotTypBoolean)) - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - } - - var = CBotVar::Create(vartoken, CBotTypBoolean);// create the variable (evaluated after the assignment) - var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); - var->SetUniqNum( - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); -suite: - if (IsOfType(p, ID_COMMA)) - { - if (nullptr != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip))) - { - return pStack->Return(inst, pStk); - } - } - - if (noskip || IsOfType(p, ID_SEP)) - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes a boolean variable definition - -bool CBotBoolean::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this);//essential for SetState() - - if ( pile->GetState()==0) - { - if (m_expr && !m_expr->Execute(pile)) return false; - m_var->Execute(pile); - - if (!pile->SetState(1)) return false; - } - - if (pile->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile)) return false; - - return pj->Return(pile); -} - -void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - if (bMain) - { - pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if ( pile->GetState()==0) - { - if (m_expr) m_expr->RestoreState(pile, bMain); // initial value interrupted? - return; - } - } - - m_var->RestoreState(pile, bMain); - - if (m_next2b) - m_next2b->RestoreState(pile, bMain); // other(s) definition(s) -} - -////////////////////////////////////////////////////////////////////////////////////////// - // compile a list of parameters CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8ae8e36d..cc1cb2d8 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -565,23 +565,6 @@ class CBotEmpty : public CBotInstr void RestoreState(CBotStack* &pj, bool bMain) override; }; -// defininition of a boolean - -class CBotBoolean : public CBotInstr -{ -private: - CBotInstr* m_var; // variable to initialise - CBotInstr* m_expr; // a value to put, if there is - -public: - CBotBoolean(); - ~CBotBoolean(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp new file mode 100644 index 00000000..9e74fffe --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -0,0 +1,172 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotBoolean.h" +#include "CBotLeftExprVar.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotBoolean::CBotBoolean() +{ + m_var = + m_expr = nullptr; + name = "CBotBoolean"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotBoolean::~CBotBoolean() +{ + delete m_var; + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) +{ + CBotToken* pp = cont ? nullptr : p; + + if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return nullptr; + + CBotBoolean* inst = static_cast(CompileArray(p, pStack, CBotTypBoolean)); + if (inst != nullptr || !pStack->IsOk()) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotBoolean(); + + inst->m_expr = nullptr; + + CBotToken* vartoken = p; + inst->SetToken(vartoken); + CBotVar* var = nullptr; + + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + (static_cast(inst->m_var))->m_typevar = CBotTypBoolean; + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable + { + pStk->SetError(TX_REDEFVAR, vartoken); + goto error; + } + + if (IsOfType(p, ID_OPBRK)) + { + delete inst; // type is not CBotInt + p = vartoken; // resutns to the variable name + + // compiles an array declaration + + inst = static_cast(CBotInstArray::Compile(p, pStk, CBotTypBoolean)); + + if (!pStk->IsOk() ) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + goto suite; // no assignment, variable already created + } + + if (IsOfType(p, ID_ASS)) + { + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } + if (!pStk->GetTypResult().Eq(CBotTypBoolean)) + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + } + + var = CBotVar::Create(vartoken, CBotTypBoolean);// create the variable (evaluated after the assignment) + var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); + var->SetUniqNum( + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); +suite: + if (IsOfType(p, ID_COMMA)) + { + if (nullptr != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip))) + { + return pStack->Return(inst, pStk); + } + } + + if (noskip || IsOfType(p, ID_SEP)) + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotBoolean::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this);//essential for SetState() + + if ( pile->GetState()==0) + { + if (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); + + if (!pile->SetState(1)) return false; + } + + if (pile->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile)) return false; + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + if (bMain) + { + pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if ( pile->GetState()==0) + { + if (m_expr) m_expr->RestoreState(pile, bMain); // initial value interrupted? + return; + } + } + + m_var->RestoreState(pile, bMain); + + if (m_next2b) + m_next2b->RestoreState(pile, bMain); // other(s) definition(s) +} diff --git a/src/CBot/CBotInstr/CBotBoolean.h b/src/CBot/CBotInstr/CBotBoolean.h new file mode 100644 index 00000000..57674200 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolean.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotBoolean class Defining a boolean variable int a, b = false; + */ +class CBotBoolean : public CBotInstr +{ +public: + + /*! + * \brief CBotBoolean + */ + CBotBoolean(); + + /*! + * \brief ~CBotBoolean + */ + ~CBotBoolean(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param cont + * \param noskip + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); + + /*! + * \brief Execute Executes a boolean variable definition. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Variable to initialise. + CBotInstr* m_var; + //! A value to put, if there is. + CBotInstr* m_expr; +}; diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 0d2ec838..a6a58e5e 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotIString.h" #include "CBotFloat.h" +#include "CBotBoolean.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 60045335..a001e1d2 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -45,6 +45,7 @@ set(SOURCES CBotInstr/CBotClassInst.cpp CBotInstr/CBotIString.cpp CBotInstr/CBotFloat.cpp + CBotInstr/CBotBoolean.cpp ) # Includes From 14961dbc5779fed099c9e5e0ef626c8447e58010 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 11:40:51 +0100 Subject: [PATCH 094/360] Moving CBotEmpty class in its own header and source files. --- src/CBot/CBot.cpp | 14 +--------- src/CBot/CBot.h | 7 ----- src/CBot/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotEmpty.cpp | 40 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotEmpty.h | 47 ++++++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotEmpty.cpp create mode 100644 src/CBot/CBotInstr/CBotEmpty.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index d08e01e7..e9d41719 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -65,6 +65,7 @@ #include "CBotInstr/CBotIString.h" #include "CBotInstr/CBotFloat.h" #include "CBotInstr/CBotBoolean.h" +#include "CBotInstr/CBotEmpty.h" // Local include @@ -565,19 +566,6 @@ void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) if (m_next2b ) m_next2b->RestoreState( pile1, bMain); } -// special case for empty indexes -bool CBotEmpty :: Execute(CBotStack* &pj) -{ - CBotVar* pVar = CBotVar::Create("", CBotTypInt); - pVar->SetValInt(-1); - pj->SetVar(pVar); - return true; -} - -void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain) -{ -} - ////////////////////////////////////////////////////////////////////////////////////// // defining a list table initialization // int [ ] a [ ] = (( 1, 2, 3 ) , ( 3, 2, 1 )) ; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index cc1cb2d8..5197bd86 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -558,13 +558,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -class CBotEmpty : public CBotInstr -{ - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index b672f32a..f298f102 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -26,6 +26,7 @@ #include "CBotInstr/CBotBlock.h" #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotExpression.h" +#include "CBotInstr/CBotEmpty.h" #include diff --git a/src/CBot/CBotInstr/CBotEmpty.cpp b/src/CBot/CBotInstr/CBotEmpty.cpp new file mode 100644 index 00000000..4f3cb5ae --- /dev/null +++ b/src/CBot/CBotInstr/CBotEmpty.cpp @@ -0,0 +1,40 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotEmpty.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +bool CBotEmpty::Execute(CBotStack* &pj) +{ + CBotVar* pVar = CBotVar::Create("", CBotTypInt); + pVar->SetValInt(-1); + pj->SetVar(pVar); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotEmpty::RestoreState(CBotStack* &pj, bool bMain) +{ +} diff --git a/src/CBot/CBotInstr/CBotEmpty.h b/src/CBot/CBotInstr/CBotEmpty.h new file mode 100644 index 00000000..04f9fafd --- /dev/null +++ b/src/CBot/CBotInstr/CBotEmpty.h @@ -0,0 +1,47 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotEmpty class + */ +class CBotEmpty : public CBotInstr +{ + /*! + * \brief Execute Special case for empty indexes. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index a001e1d2..bc2a19eb 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -46,6 +46,7 @@ set(SOURCES CBotInstr/CBotIString.cpp CBotInstr/CBotFloat.cpp CBotInstr/CBotBoolean.cpp + CBotInstr/CBotEmpty.cpp ) # Includes From c0e2201c70756a22d590a8678fb3487c8a4b85b9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 11:51:15 +0100 Subject: [PATCH 095/360] Moving CBotReturn class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 18 ----- src/CBot/CBotFunction.cpp | 83 ---------------------- src/CBot/CBotInstr/CBotReturn.cpp | 110 ++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotReturn.h | 72 +++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 184 insertions(+), 101 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotReturn.cpp create mode 100644 src/CBot/CBotInstr/CBotReturn.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index e9d41719..4d6a14bd 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -66,6 +66,7 @@ #include "CBotInstr/CBotFloat.h" #include "CBotInstr/CBotBoolean.h" #include "CBotInstr/CBotEmpty.h" +#include "CBotInstr/CBotReturn.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 5197bd86..9707b607 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -467,24 +467,6 @@ public: bool IsOfClass(CBotString name); }; - - -class CBotReturn : public CBotInstr -{ -private: - CBotInstr* m_Instr; // paramter of return - -public: - CBotReturn(); - ~CBotReturn(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - - class CBotIf : public CBotInstr { private: diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index f298f102..090f28d4 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -1108,89 +1108,6 @@ CBotString CBotDefParam::GetParamString() return param; } - - -////////////////////////////////////////////////////////////////////////// -// return parameters - -CBotReturn::CBotReturn() -{ - m_Instr = nullptr; - name = "CBotReturn"; // debug -} - -CBotReturn::~CBotReturn() -{ - delete m_Instr; -} - -CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; - - if (!IsOfType(p, ID_RETURN)) return nullptr; // should never happen - - CBotReturn* inst = new CBotReturn(); // creates the object - inst->SetToken( pp ); - - CBotTypResult type = pStack->GetRetType(); - - if ( type.GetType() == 0 ) // returned void ? - { - if ( IsOfType( p, ID_SEP ) ) return inst; - pStack->SetError( TX_BADTYPE, pp ); - return nullptr; - } - - inst->m_Instr = CBotExpression::Compile(p, pStack); - if ( pStack->IsOk() ) - { - CBotTypResult retType = pStack->GetTypResult(2); - if (TypeCompatible(retType, type, ID_ASS)) - { - if ( IsOfType( p, ID_SEP ) ) - return inst; - - pStack->SetError(TX_ENDOF, p->GetStart()); - } - pStack->SetError(TX_BADTYPE, p->GetStart()); - } - - delete inst; - return nullptr; // no object, the error is on the stack -} - -bool CBotReturn::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - - if ( pile->GetState() == 0 ) - { - if ( m_Instr != nullptr && !m_Instr->Execute(pile) ) return false; // evaluate the result - // the result is on the stack - pile->IncState(); - } - - if ( pile->IfStep() ) return false; - - pile->SetBreak(3, CBotString()); - return pj->Return(pile); -} - -void CBotReturn::RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - CBotStack* pile = pj->RestoreStack(this); - if ( pile == nullptr ) return; - - if ( pile->GetState() == 0 ) - { - if ( m_Instr != nullptr ) m_Instr->RestoreState(pile, bMain); // evaluate the result - return; - } -} - ////////////////////////////////////////////////////////////////////////////// // statement of user classes diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp new file mode 100644 index 00000000..d64326c9 --- /dev/null +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -0,0 +1,110 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotReturn.h" +#include "CBotExpression.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotReturn::CBotReturn() +{ + m_Instr = nullptr; + name = "CBotReturn"; // debug +} + +//////////////////////////////////////////////////////////////////////////////// +CBotReturn::~CBotReturn() +{ + delete m_Instr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; + + if (!IsOfType(p, ID_RETURN)) return nullptr; // should never happen + + CBotReturn* inst = new CBotReturn(); // creates the object + inst->SetToken( pp ); + + CBotTypResult type = pStack->GetRetType(); + + if ( type.GetType() == 0 ) // returned void ? + { + if ( IsOfType( p, ID_SEP ) ) return inst; + pStack->SetError( TX_BADTYPE, pp ); + return nullptr; + } + + inst->m_Instr = CBotExpression::Compile(p, pStack); + if ( pStack->IsOk() ) + { + CBotTypResult retType = pStack->GetTypResult(2); + if (TypeCompatible(retType, type, ID_ASS)) + { + if ( IsOfType( p, ID_SEP ) ) + return inst; + + pStack->SetError(TX_ENDOF, p->GetStart()); + } + pStack->SetError(TX_BADTYPE, p->GetStart()); + } + + delete inst; + return nullptr; // no object, the error is on the stack +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotReturn::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; + + if ( pile->GetState() == 0 ) + { + if ( m_Instr != nullptr && !m_Instr->Execute(pile) ) return false; // evaluate the result + // the result is on the stack + pile->IncState(); + } + + if ( pile->IfStep() ) return false; + + pile->SetBreak(3, CBotString()); + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotReturn::RestoreState(CBotStack* &pj, bool bMain) +{ + if ( !bMain ) return; + CBotStack* pile = pj->RestoreStack(this); + if ( pile == nullptr ) return; + + if ( pile->GetState() == 0 ) + { + if ( m_Instr != nullptr ) m_Instr->RestoreState(pile, bMain); // evaluate the result + return; + } +} diff --git a/src/CBot/CBotInstr/CBotReturn.h b/src/CBot/CBotInstr/CBotReturn.h new file mode 100644 index 00000000..978c6c10 --- /dev/null +++ b/src/CBot/CBotInstr/CBotReturn.h @@ -0,0 +1,72 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + +/*! + * \brief The CBotReturn class. Return parameters + */ +class CBotReturn : public CBotInstr +{ +public: + + /*! + * \brief CBotReturn + */ + CBotReturn(); + + /*! + * \brief ~CBotReturn + */ + ~CBotReturn(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Parameter of return + CBotInstr *m_Instr; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index bc2a19eb..2d25fca4 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -47,6 +47,7 @@ set(SOURCES CBotInstr/CBotFloat.cpp CBotInstr/CBotBoolean.cpp CBotInstr/CBotEmpty.cpp + CBotInstr/CBotReturn.cpp ) # Includes From 8c04d7fc652728753f154c33a2e35d03d2419e1a Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 11:59:32 +0100 Subject: [PATCH 096/360] Moving CBotIf class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 17 ------- src/CBot/{ => CBotInstr}/CBotIf.cpp | 25 +++++----- src/CBot/CBotInstr/CBotIf.h | 77 +++++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 2 +- 5 files changed, 91 insertions(+), 31 deletions(-) rename src/CBot/{ => CBotInstr}/CBotIf.cpp (92%) create mode 100644 src/CBot/CBotInstr/CBotIf.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 4d6a14bd..03c6aabb 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -67,6 +67,7 @@ #include "CBotInstr/CBotBoolean.h" #include "CBotInstr/CBotEmpty.h" #include "CBotInstr/CBotReturn.h" +#include "CBotInstr/CBotIf.h" // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 9707b607..d1804741 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -467,23 +467,6 @@ public: bool IsOfClass(CBotString name); }; -class CBotIf : public CBotInstr -{ -private: - CBotInstr* m_Condition; // condition - CBotInstr* m_Block; // instructions - CBotInstr* m_BlockElse; // instructions - -public: - CBotIf(); - ~CBotIf(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - - // definition of an integer class CBotInt : public CBotInstr diff --git a/src/CBot/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp similarity index 92% rename from src/CBot/CBotIf.cpp rename to src/CBot/CBotInstr/CBotIf.cpp index 551ecb18..2ae5acf1 100644 --- a/src/CBot/CBotIf.cpp +++ b/src/CBot/CBotInstr/CBotIf.cpp @@ -17,15 +17,17 @@ * along with this program. If not, see http://gnu.org/licenses */ -/////////////////////////////////////////////////////////////////////// -// instruction if (condition) operation1 else operation2; - -#include "CBot.h" - +// Modules inlcude +#include "CBotIf.h" #include "CBotInstr/CBotBlock.h" #include "CBotInstr/CBotCondition.h" -// various constructors / destructors +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// CBotIf::CBotIf() { m_Condition = @@ -34,6 +36,7 @@ CBotIf::CBotIf() name = "CBotIf"; // debug } +//////////////////////////////////////////////////////////////////////////////// CBotIf::~CBotIf() { delete m_Condition; // frees the condition @@ -41,9 +44,7 @@ CBotIf::~CBotIf() delete m_BlockElse; // frees the block of instruction2 } -// compilation (static routine) -// called when the token "if" has been found - +//////////////////////////////////////////////////////////////////////////////// CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack) { CBotToken* pp = p; // preserves at the ^ token (starting instruction) @@ -89,9 +90,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(nullptr, pStk); } - -// execution of the instruction - +//////////////////////////////////////////////////////////////////////////////// bool CBotIf :: Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); // adds an item to the stack @@ -134,7 +133,7 @@ bool CBotIf :: Execute(CBotStack* &pj) return pj->Return(pile); } - +//////////////////////////////////////////////////////////////////////////////// void CBotIf :: RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; diff --git a/src/CBot/CBotInstr/CBotIf.h b/src/CBot/CBotInstr/CBotIf.h new file mode 100644 index 00000000..6ea6ee9c --- /dev/null +++ b/src/CBot/CBotInstr/CBotIf.h @@ -0,0 +1,77 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotIf class Instruction if (condition) operation1 else operation2; + */ +class CBotIf : public CBotInstr +{ +public: + + /*! + * \brief CBotIf + */ + CBotIf(); + + /*! + * \brief ~CBotIf + */ + ~CBotIf(); + + /*! + * \brief Compile Compilation (static routine) called when the token "if" + * has been found + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute Execution of the instruction. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Condition + CBotInstr* m_Condition; + //! Instruction + CBotInstr* m_Block; + //! Instruction + CBotInstr* m_BlockElse; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 2d25fca4..8469f468 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -2,7 +2,6 @@ set(SOURCES CBot.cpp CBotClass.cpp CBotFunction.cpp - CBotIf.cpp CBotProgram.cpp CBotStack.cpp CBotString.cpp @@ -48,6 +47,7 @@ set(SOURCES CBotInstr/CBotBoolean.cpp CBotInstr/CBotEmpty.cpp CBotInstr/CBotReturn.cpp + CBotInstr/CBotIf.cpp ) # Includes From ede0d03026292a8e30373f37eb250aa5bf459a33 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 12:07:17 +0100 Subject: [PATCH 097/360] Moving CBotListArray class in its own header and source files. --- src/CBot/CBot.cpp | 154 +---------------------- src/CBot/CBot.h | 18 --- src/CBot/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotListArray.cpp | 175 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotListArray.h | 76 ++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 254 insertions(+), 171 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotListArray.cpp create mode 100644 src/CBot/CBotInstr/CBotListArray.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 03c6aabb..bb40150f 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -68,6 +68,7 @@ #include "CBotInstr/CBotEmpty.h" #include "CBotInstr/CBotReturn.h" #include "CBotInstr/CBotIf.h" +#include "CBotInstr/CBotListArray.h" // Local include @@ -568,159 +569,6 @@ void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) if (m_next2b ) m_next2b->RestoreState( pile1, bMain); } -////////////////////////////////////////////////////////////////////////////////////// -// defining a list table initialization -// int [ ] a [ ] = (( 1, 2, 3 ) , ( 3, 2, 1 )) ; - - -CBotListArray::CBotListArray() -{ - m_expr = nullptr; - name = "CBotListArray"; -} - -CBotListArray::~CBotListArray() -{ - delete m_expr; -} - - -CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) -{ - CBotCStack* pStk = pStack->TokenStack(p); - - CBotToken* pp = p; - - if (IsOfType( p, ID_NULL )) - { - CBotInstr* inst = new CBotExprNull (); - inst->SetToken(pp); - return pStack->Return(inst, pStk); // ok with empty element - } - - CBotListArray* inst = new CBotListArray(); - - if (IsOfType( p, ID_OPENPAR )) - { - // each element takes the one after the other - if (type.Eq( CBotTypArrayPointer )) - { - type = type.GetTypElem(); - - pStk->SetStartError(p->GetStart()); - if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) )) - { - goto error; - } - - while (IsOfType( p, ID_COMMA )) // other elements? - { - pStk->SetStartError(p->GetStart()); - - CBotInstr* i = CBotListArray::Compile(p, pStk, type); - if (nullptr == i) - { - goto error; - } - - inst->m_expr->AddNext3(i); - } - } - else - { - pStk->SetStartError(p->GetStart()); - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } - CBotVar* pv = pStk->GetVar(); // result of the expression - - if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - - while (IsOfType( p, ID_COMMA )) // other elements? - { - pStk->SetStartError(p->GetStart()); - - CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ; - if (nullptr == i) - { - goto error; - } - - CBotVar* pv = pStk->GetVar(); // result of the expression - - if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - inst->m_expr->AddNext3(i); - } - } - - if (!IsOfType(p, ID_CLOSEPAR) ) - { - pStk->SetError(TX_CLOSEPAR, p->GetStart()); - goto error; - } - - return pStack->Return(inst, pStk); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - - -// executes the definition of an array - -bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) -{ - CBotStack* pile1 = pj->AddStack(); - CBotVar* pVar2; - - CBotInstr* p = m_expr; - - int n = 0; - - for (; p != nullptr ; n++, p = p->GetNext3()) - { - if (pile1->GetState() > n) continue; - - pVar2 = pVar->GetItem(n, true); - - if (!p->Execute(pile1, pVar2)) return false; // evaluate expression - - pile1->IncState(); - } - - return pj->Return(pile1); -} - -void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) -{ - if (bMain) - { - CBotStack* pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - CBotInstr* p = m_expr; - - int state = pile->GetState(); - - while(state-- > 0) p = p->GetNext3() ; - - p->RestoreState(pile, bMain); // size calculation //interrupted! - } -} - -////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // definition of an integer variable // int a, b = 12; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index d1804741..e663e8ec 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -505,24 +505,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; - -// definition of a assignment list for a table -// int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ; - -class CBotListArray : public CBotInstr -{ -private: - CBotInstr* m_expr; // an expression for an element - // others are linked with CBotInstr :: m_next3; -public: - CBotListArray(); - ~CBotListArray(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); - bool Execute(CBotStack* &pj, CBotVar* pVar) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 090f28d4..88bfabd8 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -27,6 +27,7 @@ #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotExpression.h" #include "CBotInstr/CBotEmpty.h" +#include "CBotInstr/CBotListArray.h" #include diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp new file mode 100644 index 00000000..8ab32079 --- /dev/null +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -0,0 +1,175 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotListArray.h" + +#include "CBotExprNull.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotListArray::CBotListArray() +{ + m_expr = nullptr; + name = "CBotListArray"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotListArray::~CBotListArray() +{ + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) +{ + CBotCStack* pStk = pStack->TokenStack(p); + + CBotToken* pp = p; + + if (IsOfType( p, ID_NULL )) + { + CBotInstr* inst = new CBotExprNull (); + inst->SetToken(pp); + return pStack->Return(inst, pStk); // ok with empty element + } + + CBotListArray* inst = new CBotListArray(); + + if (IsOfType( p, ID_OPENPAR )) + { + // each element takes the one after the other + if (type.Eq( CBotTypArrayPointer )) + { + type = type.GetTypElem(); + + pStk->SetStartError(p->GetStart()); + if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) )) + { + goto error; + } + + while (IsOfType( p, ID_COMMA )) // other elements? + { + pStk->SetStartError(p->GetStart()); + + CBotInstr* i = CBotListArray::Compile(p, pStk, type); + if (nullptr == i) + { + goto error; + } + + inst->m_expr->AddNext3(i); + } + } + else + { + pStk->SetStartError(p->GetStart()); + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } + CBotVar* pv = pStk->GetVar(); // result of the expression + + if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + + while (IsOfType( p, ID_COMMA )) // other elements? + { + pStk->SetStartError(p->GetStart()); + + CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ; + if (nullptr == i) + { + goto error; + } + + CBotVar* pv = pStk->GetVar(); // result of the expression + + if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + inst->m_expr->AddNext3(i); + } + } + + if (!IsOfType(p, ID_CLOSEPAR) ) + { + pStk->SetError(TX_CLOSEPAR, p->GetStart()); + goto error; + } + + return pStack->Return(inst, pStk); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) +{ + CBotStack* pile1 = pj->AddStack(); + CBotVar* pVar2; + + CBotInstr* p = m_expr; + + int n = 0; + + for (; p != nullptr ; n++, p = p->GetNext3()) + { + if (pile1->GetState() > n) continue; + + pVar2 = pVar->GetItem(n, true); + + if (!p->Execute(pile1, pVar2)) return false; // evaluate expression + + pile1->IncState(); + } + + return pj->Return(pile1); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) +{ + if (bMain) + { + CBotStack* pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + CBotInstr* p = m_expr; + + int state = pile->GetState(); + + while(state-- > 0) p = p->GetNext3() ; + + p->RestoreState(pile, bMain); // size calculation //interrupted! + } +} diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h new file mode 100644 index 00000000..921273d1 --- /dev/null +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -0,0 +1,76 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotListArray class Definition of a assignment list for a table + * int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ; + */ +class CBotListArray : public CBotInstr +{ + +public: + + /*! + * \brief CBotListArray + */ + CBotListArray(); + + /*! + * \brief ~CBotListArray + */ + ~CBotListArray(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param type + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); + + /*! + * \brief Execute Executes the definition of an array. + * \param pj + * \param pVar + * \return + */ + bool Execute(CBotStack* &pj, CBotVar* pVar) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! An expression for an element others are linked with CBotInstr :: m_next3; + CBotInstr* m_expr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 8469f468..64a97f67 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -48,6 +48,7 @@ set(SOURCES CBotInstr/CBotEmpty.cpp CBotInstr/CBotReturn.cpp CBotInstr/CBotIf.cpp + CBotInstr/CBotListArray.cpp ) # Includes From b01e2180d89c0a1b5cd3bc3ce7a24b6ac45f54a9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 12:18:34 +0100 Subject: [PATCH 098/360] Moving CBotInstArray class in its own header and source files. --- src/CBot/CBot.cpp | 198 +---------------------- src/CBot/CBot.h | 20 --- src/CBot/CBotInstr/CBotBoolean.cpp | 1 + src/CBot/CBotInstr/CBotClassInst.cpp | 1 + src/CBot/CBotInstr/CBotFloat.cpp | 1 + src/CBot/CBotInstr/CBotInstArray.cpp | 224 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstArray.h | 82 ++++++++++ src/CBot/CMakeLists.txt | 1 + 8 files changed, 311 insertions(+), 217 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInstArray.cpp create mode 100644 src/CBot/CBotInstr/CBotInstArray.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index bb40150f..84d73981 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -69,6 +69,7 @@ #include "CBotInstr/CBotReturn.h" #include "CBotInstr/CBotIf.h" #include "CBotInstr/CBotListArray.h" +#include "CBotInstr/CBotInstArray.h" // Local include @@ -372,203 +373,6 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val) return false; } -////////////////////////////////////////////////////////////////////////////////////// -// defining an array of any type -// int a[12]; -// point x[]; - -CBotInstArray::CBotInstArray() -{ - m_var = nullptr; - m_listass = nullptr; - name = "CBotInstArray"; -} - -CBotInstArray::~CBotInstArray() -{ - delete m_var; - delete m_listass; -} - - -CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) -{ - CBotCStack* pStk = pStack->TokenStack(p); - - CBotInstArray* inst = new CBotInstArray(); - - CBotToken* vartoken = p; - inst->SetToken(vartoken); - - // determinse the expression is valid for the item on the left side - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable? - { - pStk->SetError(TX_REDEFVAR, vartoken); - goto error; - } - - CBotInstr* i; - while (IsOfType(p, ID_OPBRK)) - { - if (p->GetType() != ID_CLBRK) - i = CBotExpression::Compile(p, pStk); // expression for the value - else - i = new CBotEmpty(); // if no special formula - - inst->AddNext3b(i); // construct a list - type = CBotTypResult(CBotTypArrayPointer, type); - - if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK )) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - } - - CBotVar* var = CBotVar::Create(vartoken, type); // create an instance - inst->m_typevar = type; - - var->SetUniqNum( - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); // place it on the stack - - if (IsOfType(p, ID_ASS)) // with an assignment - { - inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem()); - } - - if (pStk->IsOk()) return pStack->Return(inst, pStk); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - - -// executes the definition of an array - -bool CBotInstArray::Execute(CBotStack* &pj) -{ - CBotStack* pile1 = pj->AddStack(this); - - CBotStack* pile = pile1; - - if (pile1->GetState() == 0) - { - // seek the maximum dimension of the table - CBotInstr* p = GetNext3b(); // the different formulas - int nb = 0; - - while (p != nullptr) - { - pile = pile->AddStack(); // little room to work - nb++; - if (pile->GetState() == 0) - { - if (!p->Execute(pile)) return false; // size calculation //interrupted? - pile->IncState(); - } - p = p->GetNext3b(); - } - - p = GetNext3b(); - pile = pile1; // returns to the stack - int n = 0; - int max[100]; - - while (p != nullptr) - { - pile = pile->AddStack(); - CBotVar* v = pile->GetVar(); // result - max[n] = v->GetValInt(); // value - if (max[n]>MAXARRAYSIZE) - { - pile->SetError(TX_OUTARRAY, &m_token); - return pj->Return (pile); - } - n++; - p = p->GetNext3b(); - } - while (n<100) max[n++] = 0; - - m_typevar.SetArray(max); // store the limitations - - // create simply a nullptr pointer - CBotVar* var = CBotVar::Create(m_var->GetToken(), m_typevar); - var->SetPointer(nullptr); - var->SetUniqNum((static_cast(m_var))->m_nIdent); - pj->AddVar(var); - -#if STACKMEM - pile1->AddStack()->Delete(); -#else - delete pile1->AddStack(); // need more indices -#endif - pile1->IncState(); - } - - if (pile1->GetState() == 1) - { - if (m_listass != nullptr) // there is the assignment for this table - { - CBotVar* pVar = pj->FindVar((static_cast(m_var))->m_nIdent); - - if (!m_listass->Execute(pile1, pVar)) return false; - } - pile1->IncState(); - } - - if (pile1->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile1 )) return false; - - return pj->Return(pile1); -} - -void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile1 = pj; - - CBotVar* var = pj->FindVar(m_var->GetToken()->GetString()); - if (var != nullptr) var->SetUniqNum((static_cast(m_var))->m_nIdent); - - if (bMain) - { - pile1 = pj->RestoreStack(this); - CBotStack* pile = pile1; - if (pile == nullptr) return; - - if (pile1->GetState() == 0) - { - // seek the maximum dimension of the table - CBotInstr* p = GetNext3b(); - - while (p != nullptr) - { - pile = pile->RestoreStack(); - if (pile == nullptr) return; - if (pile->GetState() == 0) - { - p->RestoreState(pile, bMain); - return; - } - p = p->GetNext3b(); - } - } - if (pile1->GetState() == 1 && m_listass != nullptr) - { - m_listass->RestoreState(pile1, bMain); - } - - } - - if (m_next2b ) m_next2b->RestoreState( pile1, bMain); -} - ////////////////////////////////////////////////////////////////////////////////////// // definition of an integer variable // int a, b = 12; diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e663e8ec..4ccd6a90 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -485,26 +485,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain) override; }; -// definition of an array - -class CBotInstArray : public CBotInstr -{ -private: - CBotInstr* m_var; // the variables to initialize - CBotInstr* m_listass; // list of assignments for array - CBotTypResult - m_typevar; // type of elements -// CBotString m_ClassName; - -public: - CBotInstArray(); - ~CBotInstArray(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index 9e74fffe..e2d2ad2d 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -21,6 +21,7 @@ #include "CBotBoolean.h" #include "CBotLeftExprVar.h" #include "CBotTwoOpExpr.h" +#include "CBotInstArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index cf835df3..dfbd47b2 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -21,6 +21,7 @@ #include "CBotClassInst.h" #include "CBotLeftExprVar.h" #include "CBotTwoOpExpr.h" +#include "CBotInstArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index 96c730be..acc29ff9 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -21,6 +21,7 @@ #include "CBotFloat.h" #include "CBotLeftExprVar.h" #include "CBotTwoOpExpr.h" +#include "CBotInstArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp new file mode 100644 index 00000000..b97e2b54 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -0,0 +1,224 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInstArray.h" + +#include "CBotLeftExprVar.h" +#include "CBotExpression.h" +#include "CBotListArray.h" +#include "CBotEmpty.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInstArray::CBotInstArray() +{ + m_var = nullptr; + m_listass = nullptr; + name = "CBotInstArray"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstArray::~CBotInstArray() +{ + delete m_var; + delete m_listass; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type) +{ + CBotCStack* pStk = pStack->TokenStack(p); + + CBotInstArray* inst = new CBotInstArray(); + + CBotToken* vartoken = p; + inst->SetToken(vartoken); + + // determinse the expression is valid for the item on the left side + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable? + { + pStk->SetError(TX_REDEFVAR, vartoken); + goto error; + } + + CBotInstr* i; + while (IsOfType(p, ID_OPBRK)) + { + if (p->GetType() != ID_CLBRK) + i = CBotExpression::Compile(p, pStk); // expression for the value + else + i = new CBotEmpty(); // if no special formula + + inst->AddNext3b(i); // construct a list + type = CBotTypResult(CBotTypArrayPointer, type); + + if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK )) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + } + + CBotVar* var = CBotVar::Create(vartoken, type); // create an instance + inst->m_typevar = type; + + var->SetUniqNum( + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); // place it on the stack + + if (IsOfType(p, ID_ASS)) // with an assignment + { + inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem()); + } + + if (pStk->IsOk()) return pStack->Return(inst, pStk); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstArray::Execute(CBotStack* &pj) +{ + CBotStack* pile1 = pj->AddStack(this); + + CBotStack* pile = pile1; + + if (pile1->GetState() == 0) + { + // seek the maximum dimension of the table + CBotInstr* p = GetNext3b(); // the different formulas + int nb = 0; + + while (p != nullptr) + { + pile = pile->AddStack(); // little room to work + nb++; + if (pile->GetState() == 0) + { + if (!p->Execute(pile)) return false; // size calculation //interrupted? + pile->IncState(); + } + p = p->GetNext3b(); + } + + p = GetNext3b(); + pile = pile1; // returns to the stack + int n = 0; + int max[100]; + + while (p != nullptr) + { + pile = pile->AddStack(); + CBotVar* v = pile->GetVar(); // result + max[n] = v->GetValInt(); // value + if (max[n]>MAXARRAYSIZE) + { + pile->SetError(TX_OUTARRAY, &m_token); + return pj->Return (pile); + } + n++; + p = p->GetNext3b(); + } + while (n<100) max[n++] = 0; + + m_typevar.SetArray(max); // store the limitations + + // create simply a nullptr pointer + CBotVar* var = CBotVar::Create(m_var->GetToken(), m_typevar); + var->SetPointer(nullptr); + var->SetUniqNum((static_cast(m_var))->m_nIdent); + pj->AddVar(var); + +#if STACKMEM + pile1->AddStack()->Delete(); +#else + delete pile1->AddStack(); // need more indices +#endif + pile1->IncState(); + } + + if (pile1->GetState() == 1) + { + if (m_listass != nullptr) // there is the assignment for this table + { + CBotVar* pVar = pj->FindVar((static_cast(m_var))->m_nIdent); + + if (!m_listass->Execute(pile1, pVar)) return false; + } + pile1->IncState(); + } + + if (pile1->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile1 )) return false; + + return pj->Return(pile1); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile1 = pj; + + CBotVar* var = pj->FindVar(m_var->GetToken()->GetString()); + if (var != nullptr) var->SetUniqNum((static_cast(m_var))->m_nIdent); + + if (bMain) + { + pile1 = pj->RestoreStack(this); + CBotStack* pile = pile1; + if (pile == nullptr) return; + + if (pile1->GetState() == 0) + { + // seek the maximum dimension of the table + CBotInstr* p = GetNext3b(); + + while (p != nullptr) + { + pile = pile->RestoreStack(); + if (pile == nullptr) return; + if (pile->GetState() == 0) + { + p->RestoreState(pile, bMain); + return; + } + p = p->GetNext3b(); + } + } + if (pile1->GetState() == 1 && m_listass != nullptr) + { + m_listass->RestoreState(pile1, bMain); + } + + } + + if (m_next2b ) m_next2b->RestoreState( pile1, bMain); +} diff --git a/src/CBot/CBotInstr/CBotInstArray.h b/src/CBot/CBotInstr/CBotInstArray.h new file mode 100644 index 00000000..ca2cbe07 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstArray.h @@ -0,0 +1,82 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotInstArray class Definition of an array. + * Defining an array of any type + * int a[12]; + * point x[]; + */ +class CBotInstArray : public CBotInstr +{ +public: + + /*! + * \brief CBotInstArray + */ + CBotInstArray(); + + /*! + * \brief ~CBotInstArray + */ + ~CBotInstArray(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param type + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); + + /*! + * \brief Execute Executes the definition of an array. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! The variables to initialize. + CBotInstr* m_var; + //! List of assignments for array. + CBotInstr* m_listass; + //! Type of elements. + CBotTypResult m_typevar; + +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 64a97f67..baf7b8a1 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -49,6 +49,7 @@ set(SOURCES CBotInstr/CBotReturn.cpp CBotInstr/CBotIf.cpp CBotInstr/CBotListArray.cpp + CBotInstr/CBotInstArray.cpp ) # Includes From 0373692ea115309523b397af1dc0f9a4631781a2 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 12:27:59 +0100 Subject: [PATCH 099/360] Moving CBotInt class in its own header and source files. --- src/CBot/CBot.cpp | 157 +----------------- src/CBot/CBot.h | 18 --- src/CBot/CBotInstr/CBotInt.cpp | 185 ++++++++++++++++++++++ src/CBot/CBotInstr/CBotInt.h | 78 +++++++++ src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 266 insertions(+), 174 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInt.cpp create mode 100644 src/CBot/CBotInstr/CBotInt.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 84d73981..a7b8cc40 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -70,6 +70,7 @@ #include "CBotInstr/CBotIf.h" #include "CBotInstr/CBotListArray.h" #include "CBotInstr/CBotInstArray.h" +#include "CBotInstr/CBotInt.h" // Local include @@ -373,24 +374,6 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val) return false; } -////////////////////////////////////////////////////////////////////////////////////// -// definition of an integer variable -// int a, b = 12; - -CBotInt::CBotInt() -{ - m_next = nullptr; // for multiple definitions - m_var = - m_expr = nullptr; - name = "CBotInt"; -} - -CBotInt::~CBotInt() -{ - delete m_var; - delete m_expr; -} - CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first) { if (IsOfType(p, ID_OPBRK)) @@ -431,144 +414,6 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes return nullptr; } -CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) -{ - CBotToken* pp = cont ? nullptr : p; // no repetition of the token "int" - - if (!cont && !IsOfType(p, ID_INT)) return nullptr; - - CBotInt* inst = static_cast(CompileArray(p, pStack, CBotTypInt)); - if (inst != nullptr || !pStack->IsOk()) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotInt(); - - inst->m_expr = nullptr; - - CBotToken* vartoken = p; - inst->SetToken(vartoken); - - // determines the expression is valid for the item on the left side - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - (static_cast(inst->m_var))->m_typevar = CBotTypInt; - if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable - { - pStk->SetError(TX_REDEFVAR, vartoken); - goto error; - } - - if (IsOfType(p, ID_OPBRK)) - { - delete inst; // type is not CBotInt - p = vartoken; // returns the variable name - - // compiles an array declaration - - CBotInstr* inst2 = CBotInstArray::Compile(p, pStk, CBotTypInt); - - if (!pStk->IsOk() ) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - - if (IsOfType(p, ID_COMMA)) // several definition chained - { - if (nullptr != ( inst2->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile the next one - { - return pStack->Return(inst2, pStk); - } - } - inst = static_cast(inst2); - goto suite; // no assignment, variable already created - } - - if (IsOfType(p, ID_ASS)) // with an assignment? - { - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } - if (pStk->GetType() >= CBotTypBoolean) // compatible type ? - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - } - - { - CBotVar* var = CBotVar::Create(vartoken, CBotTypInt);// create the variable (evaluated after the assignment) - var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); // if initialized with assignment - var->SetUniqNum( //set it with a unique number - (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); // place it on the stack - } - - if (IsOfType(p, ID_COMMA)) // chained several definitions - { - if (nullptr != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile next one - { - return pStack->Return(inst, pStk); - } - } -suite: - if (noskip || IsOfType(p, ID_SEP)) // instruction is completed - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// execute the definition of the integer variable - -bool CBotInt::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); // essential for SetState() - - if ( pile->GetState()==0) - { - if (m_expr && !m_expr->Execute(pile)) return false; // initial value // interrupted? - m_var->Execute(pile); // creates and assign the result - - if (!pile->SetState(1)) return false; - } - - if (pile->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile)) return false; // other(s) definition(s) - - return pj->Return(pile); // forward below -} - -void CBotInt::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - if (bMain) - { - pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if ( pile->GetState()==0) - { - if (m_expr) m_expr->RestoreState(pile, bMain); // initial value // interrupted? - return; - } - } - - m_var->RestoreState(pile, bMain); - - if (m_next2b) m_next2b->RestoreState(pile, bMain); // other(s) definition(s) -} - ////////////////////////////////////////////////////////////////////////////////////////// // compile a list of parameters diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 4ccd6a90..db9c1098 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -467,24 +467,6 @@ public: bool IsOfClass(CBotString name); }; -// definition of an integer - -class CBotInt : public CBotInstr -{ -private: - CBotInstr* m_var; // the variable to initialize - CBotInstr* m_expr; // a value to put, if there is -/// CBotInstr* m_next; // several definitions chained - -public: - CBotInt(); - ~CBotInt(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp new file mode 100644 index 00000000..ed4dbdd4 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -0,0 +1,185 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInt.h" + +#include "CBotLeftExprVar.h" +#include "CBotInstArray.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotInt::CBotInt() +{ + m_next = nullptr; // for multiple definitions + m_var = + m_expr = nullptr; + name = "CBotInt"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInt::~CBotInt() +{ + delete m_var; + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) +{ + CBotToken* pp = cont ? nullptr : p; // no repetition of the token "int" + + if (!cont && !IsOfType(p, ID_INT)) return nullptr; + + CBotInt* inst = static_cast(CompileArray(p, pStack, CBotTypInt)); + if (inst != nullptr || !pStack->IsOk()) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotInt(); + + inst->m_expr = nullptr; + + CBotToken* vartoken = p; + inst->SetToken(vartoken); + + // determines the expression is valid for the item on the left side + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + (static_cast(inst->m_var))->m_typevar = CBotTypInt; + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable + { + pStk->SetError(TX_REDEFVAR, vartoken); + goto error; + } + + if (IsOfType(p, ID_OPBRK)) + { + delete inst; // type is not CBotInt + p = vartoken; // returns the variable name + + // compiles an array declaration + + CBotInstr* inst2 = CBotInstArray::Compile(p, pStk, CBotTypInt); + + if (!pStk->IsOk() ) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + + if (IsOfType(p, ID_COMMA)) // several definition chained + { + if (nullptr != ( inst2->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile the next one + { + return pStack->Return(inst2, pStk); + } + } + inst = static_cast(inst2); + goto suite; // no assignment, variable already created + } + + if (IsOfType(p, ID_ASS)) // with an assignment? + { + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } + if (pStk->GetType() >= CBotTypBoolean) // compatible type ? + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + } + + { + CBotVar* var = CBotVar::Create(vartoken, CBotTypInt);// create the variable (evaluated after the assignment) + var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); // if initialized with assignment + var->SetUniqNum( //set it with a unique number + (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); // place it on the stack + } + + if (IsOfType(p, ID_COMMA)) // chained several definitions + { + if (nullptr != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile next one + { + return pStack->Return(inst, pStk); + } + } +suite: + if (noskip || IsOfType(p, ID_SEP)) // instruction is completed + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInt::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); // essential for SetState() + + if ( pile->GetState()==0) + { + if (m_expr && !m_expr->Execute(pile)) return false; // initial value // interrupted? + m_var->Execute(pile); // creates and assign the result + + if (!pile->SetState(1)) return false; + } + + if (pile->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile)) return false; // other(s) definition(s) + + return pj->Return(pile); // forward below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInt::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + if (bMain) + { + pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if ( pile->GetState()==0) + { + if (m_expr) m_expr->RestoreState(pile, bMain); // initial value // interrupted? + return; + } + } + + m_var->RestoreState(pile, bMain); + + if (m_next2b) m_next2b->RestoreState(pile, bMain); // other(s) definition(s) +} diff --git a/src/CBot/CBotInstr/CBotInt.h b/src/CBot/CBotInstr/CBotInt.h new file mode 100644 index 00000000..702f5290 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInt.h @@ -0,0 +1,78 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotInt class Definition of an integer variable + * int a, b = 12; + */ +class CBotInt : public CBotInstr +{ +public: + + /*! + * \brief CBotInt + */ + CBotInt(); + + /*! + * \brief ~CBotInt + */ + ~CBotInt(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param cont + * \param noskip + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false); + + /*! + * \brief Execute Execute the definition of the integer variable. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + + //! The variable to initialize. + CBotInstr* m_var; + //! A value to put, if there is. + CBotInstr* m_expr; +}; diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index a6a58e5e..1c45ec1b 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -23,6 +23,7 @@ #include "CBotIString.h" #include "CBotFloat.h" #include "CBotBoolean.h" +#include "CBotInt.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index baf7b8a1..484d023c 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -50,6 +50,7 @@ set(SOURCES CBotInstr/CBotIf.cpp CBotInstr/CBotListArray.cpp CBotInstr/CBotInstArray.cpp + CBotInstr/CBotInt.cpp ) # Includes From e54d8f1ebc6baa2d2eedd3e5a4fe9954554c8d8b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sat, 14 Nov 2015 12:56:16 +0100 Subject: [PATCH 100/360] Moving CBotStack class in its own header and source files. --- src/CBot/CBot.cpp | 2 + src/CBot/CBot.h | 247 -------------------- src/CBot/CBotFunction.cpp | 2 + src/CBot/CBotInstr/CBotBoolean.cpp | 2 + src/CBot/CBotInstr/CBotBreak.cpp | 2 + src/CBot/CBotInstr/CBotCase.cpp | 2 + src/CBot/CBotInstr/CBotCatch.cpp | 2 + src/CBot/CBotInstr/CBotClassInst.cpp | 2 + src/CBot/CBotInstr/CBotDo.cpp | 2 + src/CBot/CBotInstr/CBotEmpty.cpp | 2 + src/CBot/CBotInstr/CBotExprAlpha.cpp | 2 + src/CBot/CBotInstr/CBotExprBool.cpp | 2 + src/CBot/CBotInstr/CBotExprNan.cpp | 2 + src/CBot/CBotInstr/CBotExprNull.cpp | 2 + src/CBot/CBotInstr/CBotExprNum.cpp | 2 + src/CBot/CBotInstr/CBotExprUnaire.cpp | 2 + src/CBot/CBotInstr/CBotExprVar.cpp | 2 + src/CBot/CBotInstr/CBotExpression.cpp | 2 + src/CBot/CBotInstr/CBotFieldExpr.cpp | 2 + src/CBot/CBotInstr/CBotFloat.cpp | 2 + src/CBot/CBotInstr/CBotFor.cpp | 2 + src/CBot/CBotInstr/CBotIString.cpp | 2 + src/CBot/CBotInstr/CBotIf.cpp | 2 + src/CBot/CBotInstr/CBotIndexExpr.cpp | 2 + src/CBot/CBotInstr/CBotInstArray.cpp | 2 + src/CBot/CBotInstr/CBotInstrCall.cpp | 2 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 2 + src/CBot/CBotInstr/CBotInt.cpp | 2 + src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 + src/CBot/CBotInstr/CBotLeftExprVar.cpp | 2 + src/CBot/CBotInstr/CBotListArray.cpp | 2 + src/CBot/CBotInstr/CBotListExpression.cpp | 2 + src/CBot/CBotInstr/CBotListInstr.cpp | 2 + src/CBot/CBotInstr/CBotLogicExpr.cpp | 2 + src/CBot/CBotInstr/CBotNew.cpp | 2 + src/CBot/CBotInstr/CBotParExpr.h | 2 + src/CBot/CBotInstr/CBotPostIncExpr.cpp | 2 + src/CBot/CBotInstr/CBotPreIncExpr.cpp | 2 + src/CBot/CBotInstr/CBotReturn.cpp | 2 + src/CBot/CBotInstr/CBotSwitch.cpp | 2 + src/CBot/CBotInstr/CBotThrow.cpp | 2 + src/CBot/CBotInstr/CBotTry.cpp | 2 + src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 3 +- src/CBot/CBotInstr/CBotWhile.cpp | 2 + src/CBot/CBotProgram.cpp | 3 + src/CBot/CBotStack.cpp | 145 ++++++++---- src/CBot/CBotStack.h | 270 ++++++++++++++++++++++ src/CBot/CBotVar.cpp | 2 + 48 files changed, 463 insertions(+), 291 deletions(-) create mode 100644 src/CBot/CBotStack.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index a7b8cc40..30f22461 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -72,6 +72,8 @@ #include "CBotInstr/CBotInstArray.h" #include "CBotInstr/CBotInt.h" +#include "CBotStack.h" + // Local include diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index db9c1098..15c870e4 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -53,254 +53,7 @@ class CBotDefParam; // paramerer list of a function -//////////////////////////////////////////////////////////////////////// -// Management of the execution stack -//////////////////////////////////////////////////////////////////////// -// actually, externally, the only thing it can do -// is to create an instance of a stack -// to use for routine CBotProgram :: Execute (CBotStack) - - -/**\class CBotStack - * \brief Management of the execution stack. - * \brief Actually the only thing it can do is to create an instance of a stack - * \brief to use for routine CBotProgram :: Execute(CBotStack)*/ -class CBotStack -{ -public: -#if STACKMEM - /** - * \brief FirstStack Allocate first stack - * \return pointer to created stack - */ - static CBotStack * FirstStack(); - - /** \brief Delete Remove current stack */ - void Delete(); -#endif - - /** - * \brief CBotStack Constructor of the stack - * \param ppapa Not used. - */ - CBotStack(CBotStack* ppapa); - - - /** \brief ~CBotStack Destructor */ - ~CBotStack(); - - /** - * \brief StackOver Check if end of stack is reached - * \return true if end of stack - */ - bool StackOver(); - - /** - * \brief GetError Get error number of the stack - * \param [out] start beginning of the stack - * \param [out] end end of stack - * \return error number - */ - int GetError(int& start, int& end); - - /** - * \brief GetError Get error number - * \return eror number - */ - int GetError();// rend le numéro d'erreur retourné - - /** - * \brief Reset Reset error at and set user - * \param [in] pUser User of stack - */ - void Reset(void* pUser); - - /** - * \brief SetType Determines the type. - * \param type Type of instruction on the stack. - */ - void SetType(CBotTypResult& type); - - /** - * \brief GetType Get the type of value on the stack. - * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic). - * \return Type number. - */ - int GetType(int mode = 0); - - /** - * \brief Getes the type of complete value on the stack. - * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic). - * \return Type of an element. - */ - CBotTypResult GetTypResult(int mode = 0); - - /** - * \brief Adds a local variable. - * \param [in] p Variable to be added. - */ - void AddVar(CBotVar* p); - - /** - * \brief Fetch a variable by its token. - * \brief This may be a composite variable - * \param [in] pToken Token upon which search is performed - * \param [in] bUpdate Not used. Probably need to be removed - * \param [in] bModif Not used. Probably need to be removed - * \return Found variable - */ - CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false, - bool bModif = false); - - /** - * \brief Fetch a variable by its token. - * \brief This may be a composite variable - * \param [in] pToken Token upon which search is performed - * \param [in] bUpdate Not used. Probably need to be removed - * \param [in] bModif Not used. Probably need to be removed - * \return Found variable - */ - CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false, - bool bModif = false); - - /** - * \brief Fetch variable by its name - * \param [in] name Name of variable to find - * \return Found variable - */ - CBotVar* FindVar(const char* name); - - /** - * \brief Fetch a variable on the stack according to its identification number - * \brief This is faster than comparing names - * \param [in] ident Identifier of a variable - * \param [in] bUpdate Not used. Probably need to be removed - * \param [in] bModif Not used. Probably need to be removed - * \return Found variable - */ - CBotVar* FindVar(long ident, bool bUpdate = false, - bool bModif = false); - - /** - * \brief Find variable by its token and returns a copy of it. - * \param Token Token upon which search is performed - * \param bUpdate Not used. - * \return Found variable, nullptr if not found - */ - CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false); - - - CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack - CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack - CBotStack* RestoreStack(CBotInstr* instr = nullptr); - CBotStack* RestoreStackEOX(CBotCall* instr = nullptr); - - CBotStack* AddStack2(bool bBlock = false); // extends the stack - bool Return(CBotStack* pFils); // transmits the result over - bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack - bool BreakReturn(CBotStack* pfils, const char* name = nullptr); - // in case of eventual break - bool IfContinue(int state, const char* name); - // or "continue" - - bool IsOk(); - - bool SetState(int n, int lim = -10); // select a state - int GetState(); // in what state am I? - bool IncState(int lim = -10); // passes to the next state - bool IfStep(); // do step by step - bool Execute(); - - void SetVar( CBotVar* var ); - void SetCopyVar( CBotVar* var ); - CBotVar* GetVar(); - CBotVar* GetCopyVar(); - CBotVar* GetPtVar(); - bool GetRetVar(bool bRet); - long GetVal(); - - void SetError(int n, CBotToken* token = nullptr); - void SetPosError(CBotToken* token); - void ResetError(int n, int start, int end); - void SetBreak(int val, const char* name); - - void SetBotCall(CBotProgram* p); - CBotProgram* GetBotCall(bool bFirst = false); - void* GetPUser(); - bool GetBlock(); - - - bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype); - void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar); - - bool SaveState(FILE* pf); - bool RestoreState(FILE* pf, CBotStack* &pStack); - - static - void SetTimer(int n); - - void GetRunPos(const char* &FunctionName, int &start, int &end); - CBotVar* GetStackVars(const char* &FunctionName, int level); - - int m_temp; - -private: - CBotStack* m_next; - CBotStack* m_next2; - CBotStack* m_prev; - friend class CBotInstArray; - -#ifdef _DEBUG - int m_index; -#endif - int m_state; - int m_step; - static int m_error; - static int m_start; - static int m_end; - static - CBotVar* m_retvar; // result of a return - - CBotVar* m_var; // result of the operations - CBotVar* m_listVar; // variables declared at this level - - bool m_bBlock; // is part of a block (variables are local to this block) - bool m_bOver; // stack limits? -// bool m_bDontDelete; // special, not to destroy the variable during delete - CBotProgram* m_prog; // user-defined functions - - static - int m_initimer; - static - int m_timer; - static - CBotString m_labelBreak; - static - void* m_pUser; - - CBotInstr* m_instr; // the corresponding instruction - bool m_bFunc; // an input of a function? - CBotCall* m_call; // recovery point in a extern call - friend class CBotTry; -}; - -// inline routinees must be declared in file.h - -inline bool CBotStack::IsOk() -{ - return (m_error == 0); -} - -inline int CBotStack::GetState() -{ - return m_state; -} - -inline int CBotStack::GetError() -{ - return m_error; -} //////////////////////////////////////////////////////////////////////// // Management of the stack of compilation diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 88bfabd8..64b85fdc 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -29,6 +29,8 @@ #include "CBotInstr/CBotEmpty.h" #include "CBotInstr/CBotListArray.h" +#include "CBotStack.h" + #include diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index e2d2ad2d..6fda2dbf 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -23,6 +23,8 @@ #include "CBotTwoOpExpr.h" #include "CBotInstArray.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index 06f53ae2..5879f0f8 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotBreak.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index a2b68c4f..f188f8ed 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -21,6 +21,8 @@ #include "CBotCase.h" #include "CBotExprNum.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index e4d9bb4c..77b5294d 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -22,6 +22,8 @@ #include "CBotBlock.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index dfbd47b2..e02328da 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -23,6 +23,8 @@ #include "CBotTwoOpExpr.h" #include "CBotInstArray.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index 3bf3aefd..9cfeddb3 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -22,6 +22,8 @@ #include "CBotBlock.h" #include "CBotCondition.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotEmpty.cpp b/src/CBot/CBotInstr/CBotEmpty.cpp index 4f3cb5ae..0f0ad7ce 100644 --- a/src/CBot/CBotInstr/CBotEmpty.cpp +++ b/src/CBot/CBotInstr/CBotEmpty.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotEmpty.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index c412ac02..d0edb1d2 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotExprAlpha.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp index 17c09e55..3a252676 100644 --- a/src/CBot/CBotInstr/CBotExprBool.cpp +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotExprBool.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp index 3eebb74a..7335219b 100644 --- a/src/CBot/CBotInstr/CBotExprNan.cpp +++ b/src/CBot/CBotInstr/CBotExprNan.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotExprNan.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNull.cpp b/src/CBot/CBotInstr/CBotExprNull.cpp index 0324d50b..d80ef035 100644 --- a/src/CBot/CBotInstr/CBotExprNull.cpp +++ b/src/CBot/CBotInstr/CBotExprNull.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotExprNull.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index 61cf3eaa..24ba0ac7 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotExprNum.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index e1a18e7f..2b7c0d6e 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -21,6 +21,8 @@ #include "CBotExprUnaire.h" #include "CBotParExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 3c03da91..0e531fae 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -24,6 +24,8 @@ #include "CBotIndexExpr.h" #include "CBotFieldExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index cb47103b..3637049b 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -21,6 +21,8 @@ #include "CBotExpression.h" #include "CBotTwoOpExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index 6453bc3c..ae8e583d 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotFieldExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index acc29ff9..70a2c97b 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -23,6 +23,8 @@ #include "CBotTwoOpExpr.h" #include "CBotInstArray.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index d83650cb..7cbca510 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -23,6 +23,8 @@ #include "CBotBlock.h" #include "CBotBoolExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index b0e8a6a3..91e1a925 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -22,6 +22,8 @@ #include "CBotLeftExprVar.h" #include "CBotTwoOpExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp index 2ae5acf1..b0cdbc88 100644 --- a/src/CBot/CBotInstr/CBotIf.cpp +++ b/src/CBot/CBotInstr/CBotIf.cpp @@ -22,6 +22,8 @@ #include "CBotInstr/CBotBlock.h" #include "CBotInstr/CBotCondition.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 2d3d6d2a..f4882c00 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotIndexExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index b97e2b54..e1327a58 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -25,6 +25,8 @@ #include "CBotListArray.h" #include "CBotEmpty.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index 615f041a..cec9810b 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -21,6 +21,8 @@ #include "CBotInstrCall.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index e35c0f25..1ec99067 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotInstrMethode.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index ed4dbdd4..f94d53c5 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -24,6 +24,8 @@ #include "CBotInstArray.h" #include "CBotTwoOpExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 66e0dce5..84c7b735 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -23,6 +23,8 @@ #include "CBotIndexExpr.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index 43ed496d..ff0bbf15 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotLeftExprVar.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 8ab32079..dc6e2b29 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -23,6 +23,8 @@ #include "CBotExprNull.h" #include "CBotTwoOpExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 1c45ec1b..afa5f877 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -25,6 +25,8 @@ #include "CBotBoolean.h" #include "CBotInt.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index b2fcf49c..fde2103c 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -21,6 +21,8 @@ #include "CBotListInstr.h" #include "CBotBlock.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLogicExpr.cpp b/src/CBot/CBotInstr/CBotLogicExpr.cpp index bfa6af1a..d332d18f 100644 --- a/src/CBot/CBotInstr/CBotLogicExpr.cpp +++ b/src/CBot/CBotInstr/CBotLogicExpr.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotLogicExpr.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index d89a8ca7..fef5c074 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotNew.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h index de0df458..60c09933 100644 --- a/src/CBot/CBotInstr/CBotParExpr.h +++ b/src/CBot/CBotInstr/CBotParExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp index cb146ca4..f7fbddab 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -21,6 +21,8 @@ #include "CBotPostIncExpr.h" #include "CBotExprVar.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp index 073e0d4a..5fe3d365 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -21,6 +21,8 @@ #include "CBotPreIncExpr.h" #include "CBotExprVar.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index d64326c9..3837b26c 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -21,6 +21,8 @@ #include "CBotReturn.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index 45558dc1..0a527d2f 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -25,6 +25,8 @@ #include "CBotBlock.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index a4a1831e..c02f2214 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -21,6 +21,8 @@ #include "CBotThrow.h" #include "CBotExpression.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index 89b689ea..2ac2ae64 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -21,6 +21,8 @@ #include "CBotTry.h" #include "CBotBlock.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 275730a6..816efefb 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -22,7 +22,8 @@ #include "CBotParExpr.h" #include "CBotLogicExpr.h" #include "CBotExpression.h" -#include "CBot.h" + +#include "CBotStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index c24084b6..bfc2061f 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -22,6 +22,8 @@ #include "CBotBlock.h" #include "CBotCondition.h" +#include "CBotStack.h" + // Local include // Global include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index cda190ce..f1862c1e 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -21,6 +21,9 @@ // database management of CBoT program #include "CBot.h" + +#include "CBotStack.h" + #include CBotProgram::CBotProgram() diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index bbc01d8b..b1715e15 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -17,11 +17,12 @@ * along with this program. If not, see http://gnu.org/licenses */ -//Management of the stack +// Modules inlcude +#include "CBotStack.h" +// Local include -#include "CBot.h" - +// Global include #include #include #include @@ -29,10 +30,6 @@ #define ITIMER 100 -//////////////////////////////////////////////////////////////////////////// -// management of a execution of a stack -//////////////////////////////////////////////////////////////////////////// - int CBotStack::m_initimer = ITIMER; int CBotStack::m_timer = 0; CBotVar* CBotStack::m_retvar = nullptr; @@ -44,6 +41,7 @@ void* CBotStack::m_pUser = nullptr; #if STACKMEM +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::FirstStack() { CBotStack* p; @@ -82,17 +80,20 @@ CBotStack* CBotStack::FirstStack() return p; } +//////////////////////////////////////////////////////////////////////////////// CBotStack::CBotStack(CBotStack* ppapa) { // constructor must exist or the destructor is never called! assert(0); } +//////////////////////////////////////////////////////////////////////////////// CBotStack::~CBotStack() { assert(0); // use Delete () instead } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::Delete() { if ( this == nullptr || this == EOX ) return; @@ -129,8 +130,8 @@ void CBotStack::Delete() free( this ); } - // routine improved +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { if (m_next != nullptr) @@ -163,6 +164,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { if (m_next != nullptr) @@ -180,6 +182,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::AddStack2(bool bBlock) { if (m_next2 != nullptr) @@ -203,11 +206,13 @@ CBotStack* CBotStack::AddStack2(bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::GetBlock() { return m_bBlock; } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::Return(CBotStack* pfils) { if ( pfils == this ) return true; // special @@ -222,6 +227,7 @@ bool CBotStack::Return(CBotStack* pfils) return (m_error == 0); // interrupted if error } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::ReturnKeep(CBotStack* pfils) { if ( pfils == this ) return true; // special @@ -233,6 +239,7 @@ bool CBotStack::ReturnKeep(CBotStack* pfils) return (m_error == 0); // interrupted if error } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::StackOver() { if (!m_bOver) return false; @@ -242,6 +249,7 @@ bool CBotStack::StackOver() #else +//////////////////////////////////////////////////////////////////////////////// CBotStack::CBotStack(CBotStack* ppapa) { m_next = nullptr; @@ -265,6 +273,7 @@ CBotStack::CBotStack(CBotStack* ppapa) m_bFunc = false; } +//////////////////////////////////////////////////////////////////////////////// // destructor CBotStack::~CBotStack() { @@ -277,6 +286,7 @@ CBotStack::~CBotStack() if ( !m_bDontDelete ) delete m_listVar; } +//////////////////////////////////////////////////////////////////////////////// // \TODO routine has/to optimize CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { @@ -293,6 +303,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { if (m_next != nullptr) @@ -314,6 +325,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::AddStack2(bool bBlock) { if (m_next2 != nullptr) @@ -331,6 +343,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock) return p; } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::Return(CBotStack* pfils) { if ( pfils == this ) return true; // special @@ -345,6 +358,7 @@ bool CBotStack::Return(CBotStack* pfils) return (m_error == 0); // interrupted if error } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::StackOver() { return false; // no overflow check in this version @@ -352,6 +366,7 @@ bool CBotStack::StackOver() #endif +//////////////////////////////////////////////////////////////////////////////// void CBotStack::Reset(void* pUser) { m_timer = m_initimer; // resets the timer @@ -362,9 +377,7 @@ void CBotStack::Reset(void* pUser) m_pUser = pUser; } - - - +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::RestoreStack(CBotInstr* instr) { if (m_next != nullptr) @@ -376,6 +389,7 @@ CBotStack* CBotStack::RestoreStack(CBotInstr* instr) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr) { CBotStack* p = RestoreStack(); @@ -383,8 +397,7 @@ CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr) return p; } - - +//////////////////////////////////////////////////////////////////////////////// // routine for execution step by step bool CBotStack::IfStep() { @@ -392,7 +405,7 @@ bool CBotStack::IfStep() return true; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::BreakReturn(CBotStack* pfils, const char* name) { if ( m_error>=0 ) return false; // normal output @@ -406,6 +419,7 @@ bool CBotStack::BreakReturn(CBotStack* pfils, const char* name) return Return(pfils); } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::IfContinue(int state, const char* name) { if ( m_error != -2 ) return false; @@ -420,6 +434,7 @@ bool CBotStack::IfContinue(int state, const char* name) return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetBreak(int val, const char* name) { m_error = -val; // reacts as an Exception @@ -432,7 +447,7 @@ void CBotStack::SetBreak(int val, const char* name) } // gives on the stack value calculated by the last CBotReturn - +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::GetRetVar(bool bRet) { if (m_error == -3) @@ -446,6 +461,7 @@ bool CBotStack::GetRetVar(bool bRet) return bRet; // interrupted by something other than return } +//////////////////////////////////////////////////////////////////////////////// int CBotStack::GetError(int& start, int& end) { start = m_start; @@ -453,26 +469,28 @@ int CBotStack::GetError(int& start, int& end) return m_error; } - +//////////////////////////////////////////////////////////////////////////////// int CBotStack::GetType(int mode) { if (m_var == nullptr) return -1; return m_var->GetType(mode); } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotStack::GetTypResult(int mode) { if (m_var == nullptr) return -1; return m_var->GetTypResult(mode); } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetType(CBotTypResult& type) { if (m_var == nullptr) return; m_var->SetType( type ); } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) { CBotStack* p = this; @@ -497,6 +515,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::FindVar(const char* name) { CBotStack* p = this; @@ -516,6 +535,7 @@ CBotVar* CBotStack::FindVar(const char* name) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif) { CBotStack* p = this; @@ -538,14 +558,14 @@ CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif) return nullptr; } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::FindVar(CBotToken& pToken, bool bUpdate, bool bModif) { CBotToken* pt = &pToken; return FindVar(pt, bUpdate, bModif); } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate) { CBotVar* pVar = FindVar( Token, bUpdate ); @@ -557,7 +577,7 @@ CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate) return pCopy; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::SetState(int n, int limite) { m_state = n; @@ -566,6 +586,7 @@ bool CBotStack::SetState(int n, int limite) return ( m_timer > limite ); // interrupted if timer pass } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::IncState(int limite) { m_state++; @@ -574,7 +595,7 @@ bool CBotStack::IncState(int limite) return ( m_timer > limite ); // interrupted if timer pass } - +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetError(int n, CBotToken* token) { if ( n!= 0 && m_error != 0) return; // does not change existing error @@ -586,6 +607,7 @@ void CBotStack::SetError(int n, CBotToken* token) } } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::ResetError(int n, int start, int end) { m_error = n; @@ -593,17 +615,20 @@ void CBotStack::ResetError(int n, int start, int end) m_end = end; } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetPosError(CBotToken* token) { m_start = token->GetStart(); m_end = token->GetEnd(); } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetTimer(int n) { m_initimer = n; } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::Execute() { CBotCall* instr = nullptr; // the most highest instruction @@ -637,6 +662,7 @@ bool CBotStack::Execute() } // puts on the stack pointer to a variable +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetVar( CBotVar* var ) { if (m_var) delete m_var; // replacement of a variable @@ -644,6 +670,7 @@ void CBotStack::SetVar( CBotVar* var ) } // puts on the stack a copy of a variable +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetCopyVar( CBotVar* var ) { if (m_var) delete m_var; // replacement of a variable @@ -652,11 +679,13 @@ void CBotStack::SetCopyVar( CBotVar* var ) m_var->Copy( var ); } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::GetVar() { return m_var; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::GetPtVar() { CBotVar* p = m_var; @@ -664,6 +693,7 @@ CBotVar* CBotStack::GetPtVar() return p; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::GetCopyVar() { if (m_var == nullptr) return nullptr; @@ -672,15 +702,14 @@ CBotVar* CBotStack::GetCopyVar() return v; } +//////////////////////////////////////////////////////////////////////////////// long CBotStack::GetVal() { if (m_var == nullptr) return 0; return m_var->GetValInt(); } - - - +//////////////////////////////////////////////////////////////////////////////// void CBotStack::AddVar(CBotVar* pVar) { CBotStack* p = this; @@ -702,19 +731,14 @@ void CBotStack::AddVar(CBotVar* pVar) #endif } -/*void CBotStack::RestoreVar(CBotVar* pVar) -{ - if ( !m_bDontDelete ) __asm int 3; - delete m_listVar; - m_listVar = pVar; // direct replacement -}*/ - +//////////////////////////////////////////////////////////////////////////////// void CBotStack::SetBotCall(CBotProgram* p) { m_prog = p; m_bFunc = true; } +//////////////////////////////////////////////////////////////////////////////// CBotProgram* CBotStack::GetBotCall(bool bFirst) { if ( ! bFirst ) return m_prog; @@ -723,12 +747,13 @@ CBotProgram* CBotStack::GetBotCall(bool bFirst) return p->m_prog; } +//////////////////////////////////////////////////////////////////////////////// void* CBotStack::GetPUser() { return m_pUser; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype) { CBotTypResult res; @@ -754,6 +779,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar) { if ( m_next == nullptr ) return; @@ -762,7 +788,7 @@ void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar) m_prog->GetFunctions()->RestoreCall(nIdent, token->GetString(), ppVar, this ); } - +//////////////////////////////////////////////////////////////////////////////// bool SaveVar(FILE* pf, CBotVar* pVar) { while ( true ) @@ -779,6 +805,7 @@ bool SaveVar(FILE* pf, CBotVar* pVar) } } +//////////////////////////////////////////////////////////////////////////////// void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) { CBotProgram* prog = m_prog; // Current program @@ -813,6 +840,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) end = t->GetEnd(); } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) { CBotProgram* prog = m_prog; // current program @@ -860,6 +888,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) return p->m_listVar; } +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::SaveState(FILE* pf) { if ( this == nullptr ) // end of the tree? @@ -888,7 +917,7 @@ bool CBotStack::SaveState(FILE* pf) return m_next->SaveState(pf); // saves the following } - +//////////////////////////////////////////////////////////////////////////////// bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) { unsigned short w; @@ -927,7 +956,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) return pStack->RestoreState(pf, pStack->m_next); } - +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Save0State(FILE* pf) { if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable? @@ -937,6 +966,7 @@ bool CBotVar::Save0State(FILE* pf) return WriteString(pf, m_token->GetString()); // and variable name } +//////////////////////////////////////////////////////////////////////////////// bool CBotVarInt::Save0State(FILE* pf) { if ( !m_defnum.IsEmpty() ) @@ -948,28 +978,31 @@ bool CBotVarInt::Save0State(FILE* pf) return CBotVar::Save0State(pf); } +//////////////////////////////////////////////////////////////////////////////// bool CBotVarInt::Save1State(FILE* pf) { return WriteWord(pf, m_val); // the value of the variable } +//////////////////////////////////////////////////////////////////////////////// bool CBotVarBoolean::Save1State(FILE* pf) { return WriteWord(pf, m_val); // the value of the variable } +//////////////////////////////////////////////////////////////////////////////// bool CBotVarFloat::Save1State(FILE* pf) { return WriteFloat(pf, m_val); // the value of the variable } +//////////////////////////////////////////////////////////////////////////////// bool CBotVarString::Save1State(FILE* pf) { return WriteString(pf, m_val); // the value of the variable } - - +//////////////////////////////////////////////////////////////////////////////// bool CBotVarClass::Save1State(FILE* pf) { if ( !WriteType(pf, m_type) ) return false; @@ -1004,6 +1037,7 @@ bool ParseInitType(int rawInitType, CBotVar::InitType* initType) } } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) { unsigned short w, wi, prv, st; @@ -1152,7 +1186,7 @@ int CBotCStack::m_end = 0; CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); //CBotToken* CBotCStack::m_retClass= nullptr; - +//////////////////////////////////////////////////////////////////////////////// CBotCStack::CBotCStack(CBotCStack* ppapa) { m_next = nullptr; @@ -1175,6 +1209,7 @@ CBotCStack::CBotCStack(CBotCStack* ppapa) m_var = nullptr; } +//////////////////////////////////////////////////////////////////////////////// // destructor CBotCStack::~CBotCStack() { @@ -1185,6 +1220,7 @@ CBotCStack::~CBotCStack() delete m_listVar; } +//////////////////////////////////////////////////////////////////////////////// // used only at compile CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) { @@ -1199,7 +1235,7 @@ CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) return p; } - +//////////////////////////////////////////////////////////////////////////////// CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) { if ( pfils == this ) return inst; @@ -1218,6 +1254,7 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) return inst; } +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) { if (m_var != nullptr) delete m_var; // value replaced? @@ -1234,6 +1271,7 @@ CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) return inst; } +//////////////////////////////////////////////////////////////////////////////// int CBotCStack::GetError(int& start, int& end) { start = m_start; @@ -1241,11 +1279,13 @@ int CBotCStack::GetError(int& start, int& end) return m_error; } +//////////////////////////////////////////////////////////////////////////////// int CBotCStack::GetError() { return m_error; } +//////////////////////////////////////////////////////////////////////////////// // type of instruction on the stack CBotTypResult CBotCStack::GetTypResult(int mode) { @@ -1254,6 +1294,7 @@ CBotTypResult CBotCStack::GetTypResult(int mode) return m_var->GetTypResult(mode); } +//////////////////////////////////////////////////////////////////////////////// // type of instruction on the stack int CBotCStack::GetType(int mode) { @@ -1262,6 +1303,7 @@ int CBotCStack::GetType(int mode) return m_var->GetType(mode); } +//////////////////////////////////////////////////////////////////////////////// // pointer on the stack is in what class? CBotClass* CBotCStack::GetClass() { @@ -1272,6 +1314,7 @@ CBotClass* CBotCStack::GetClass() return m_var->GetClass(); } +//////////////////////////////////////////////////////////////////////////////// // type of instruction on the stack void CBotCStack::SetType(CBotTypResult& type) { @@ -1282,7 +1325,7 @@ void CBotCStack::SetType(CBotTypResult& type) // seeks a variable on the stack // the token may be a result of TokenTypVar (object of a class) // or a pointer in the source - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotCStack::FindVar(CBotToken* &pToken) { CBotCStack* p = this; @@ -1304,12 +1347,14 @@ CBotVar* CBotCStack::FindVar(CBotToken* &pToken) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotCStack::FindVar(CBotToken& Token) { CBotToken* pt = &Token; return FindVar(pt); } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotCStack::CopyVar(CBotToken& Token) { CBotVar* pVar = FindVar( Token ); @@ -1321,18 +1366,20 @@ CBotVar* CBotCStack::CopyVar(CBotToken& Token) return pCopy; } +//////////////////////////////////////////////////////////////////////////////// bool CBotCStack::IsOk() { return (m_error == 0); } - +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetStartError( int pos ) { if ( m_error != 0) return; // does not change existing error m_start = pos; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetError(int n, int pos) { if ( n!= 0 && m_error != 0) return; // does not change existing error @@ -1340,6 +1387,7 @@ void CBotCStack::SetError(int n, int pos) m_end = pos; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetError(int n, CBotToken* p) { if (m_error) return; // does not change existing error @@ -1348,6 +1396,7 @@ void CBotCStack::SetError(int n, CBotToken* p) m_end = p->GetEnd(); } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::ResetError(int n, int start, int end) { m_error = n; @@ -1355,6 +1404,7 @@ void CBotCStack::ResetError(int n, int start, int end) m_end = end; } +//////////////////////////////////////////////////////////////////////////////// bool CBotCStack::NextToken(CBotToken* &p) { CBotToken* pp = p; @@ -1366,32 +1416,38 @@ bool CBotCStack::NextToken(CBotToken* &p) return false; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetBotCall(CBotProgram* p) { m_prog = p; } +//////////////////////////////////////////////////////////////////////////////// CBotProgram* CBotCStack::GetBotCall() { return m_prog; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetRetType(CBotTypResult& type) { m_retTyp = type; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotCStack::GetRetType() { return m_retTyp; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::SetVar( CBotVar* var ) { if (m_var) delete m_var; // replacement of a variable m_var = var; } +//////////////////////////////////////////////////////////////////////////////// // puts on the stack a copy of a variable void CBotCStack::SetCopyVar( CBotVar* var ) { @@ -1402,11 +1458,13 @@ void CBotCStack::SetCopyVar( CBotVar* var ) m_var->Copy( var ); } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotCStack::GetVar() { return m_var; } +//////////////////////////////////////////////////////////////////////////////// void CBotCStack::AddVar(CBotVar* pVar) { CBotCStack* p = this; @@ -1427,7 +1485,7 @@ void CBotCStack::AddVar(CBotVar* pVar) } // test whether a variable is already defined locally - +//////////////////////////////////////////////////////////////////////////////// bool CBotCStack::CheckVarLocal(CBotToken* &pToken) { CBotCStack* p = this; @@ -1448,6 +1506,7 @@ bool CBotCStack::CheckVarLocal(CBotToken* &pToken) return false; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) { nIdent = 0; @@ -1469,7 +1528,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId } // test if a procedure name is already defined somewhere - +//////////////////////////////////////////////////////////////////////////////// bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) { CBotString name = pToken->GetString(); diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h new file mode 100644 index 00000000..df69a0d4 --- /dev/null +++ b/src/CBot/CBotStack.h @@ -0,0 +1,270 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \class CBotStack + * \brief The CBotStack class Management of the execution stack. Actually the + * only thing it can do is to create an instance of a stack. To use for routine + * CBotProgram :: Execute(CBotStack) + */ +class CBotStack +{ +public: +#if STACKMEM + /** + * \brief FirstStack Allocate first stack + * \return pointer to created stack + */ + static CBotStack * FirstStack(); + + /** \brief Delete Remove current stack */ + void Delete(); +#endif + + /** + * \brief CBotStack Constructor of the stack + * \param ppapa Not used. + */ + CBotStack(CBotStack* ppapa); + + + /** \brief ~CBotStack Destructor */ + ~CBotStack(); + + /** + * \brief StackOver Check if end of stack is reached + * \return true if end of stack + */ + bool StackOver(); + + /** + * \brief GetError Get error number of the stack + * \param [out] start beginning of the stack + * \param [out] end end of stack + * \return error number + */ + int GetError(int& start, int& end); + + /** + * \brief GetError Get error number + * \return eror number + */ + int GetError();// rend le numéro d'erreur retourné + + /** + * \brief Reset Reset error at and set user + * \param [in] pUser User of stack + */ + void Reset(void* pUser); + + /** + * \brief SetType Determines the type. + * \param type Type of instruction on the stack. + */ + void SetType(CBotTypResult& type); + + /** + * \brief GetType Get the type of value on the stack. + * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic). + * \return Type number. + */ + int GetType(int mode = 0); + + /** + * \brief Getes the type of complete value on the stack. + * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic). + * \return Type of an element. + */ + CBotTypResult GetTypResult(int mode = 0); + + /** + * \brief Adds a local variable. + * \param [in] p Variable to be added. + */ + void AddVar(CBotVar* p); + + /** + * \brief Fetch a variable by its token. + * \brief This may be a composite variable + * \param [in] pToken Token upon which search is performed + * \param [in] bUpdate Not used. Probably need to be removed + * \param [in] bModif Not used. Probably need to be removed + * \return Found variable + */ + CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false, + bool bModif = false); + + /** + * \brief Fetch a variable by its token. + * \brief This may be a composite variable + * \param [in] pToken Token upon which search is performed + * \param [in] bUpdate Not used. Probably need to be removed + * \param [in] bModif Not used. Probably need to be removed + * \return Found variable + */ + CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false, + bool bModif = false); + + /** + * \brief Fetch variable by its name + * \param [in] name Name of variable to find + * \return Found variable + */ + CBotVar* FindVar(const char* name); + + /** + * \brief Fetch a variable on the stack according to its identification number + * \brief This is faster than comparing names + * \param [in] ident Identifier of a variable + * \param [in] bUpdate Not used. Probably need to be removed + * \param [in] bModif Not used. Probably need to be removed + * \return Found variable + */ + CBotVar* FindVar(long ident, bool bUpdate = false, + bool bModif = false); + + /** + * \brief Find variable by its token and returns a copy of it. + * \param Token Token upon which search is performed + * \param bUpdate Not used. + * \return Found variable, nullptr if not found + */ + CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false); + + + CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack + CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack + CBotStack* RestoreStack(CBotInstr* instr = nullptr); + CBotStack* RestoreStackEOX(CBotCall* instr = nullptr); + + CBotStack* AddStack2(bool bBlock = false); // extends the stack + bool Return(CBotStack* pFils); // transmits the result over + bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack + bool BreakReturn(CBotStack* pfils, const char* name = nullptr); + // in case of eventual break + bool IfContinue(int state, const char* name); + // or "continue" + + bool IsOk(); + + bool SetState(int n, int lim = -10); // select a state + int GetState(); // in what state am I? + bool IncState(int lim = -10); // passes to the next state + bool IfStep(); // do step by step + bool Execute(); + + void SetVar( CBotVar* var ); + void SetCopyVar( CBotVar* var ); + CBotVar* GetVar(); + CBotVar* GetCopyVar(); + CBotVar* GetPtVar(); + bool GetRetVar(bool bRet); + long GetVal(); + + void SetError(int n, CBotToken* token = nullptr); + void SetPosError(CBotToken* token); + void ResetError(int n, int start, int end); + void SetBreak(int val, const char* name); + + void SetBotCall(CBotProgram* p); + CBotProgram* GetBotCall(bool bFirst = false); + void* GetPUser(); + bool GetBlock(); + + + bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype); + void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar); + + bool SaveState(FILE* pf); + bool RestoreState(FILE* pf, CBotStack* &pStack); + + static + void SetTimer(int n); + + void GetRunPos(const char* &FunctionName, int &start, int &end); + CBotVar* GetStackVars(const char* &FunctionName, int level); + + int m_temp; + +private: + CBotStack* m_next; + CBotStack* m_next2; + CBotStack* m_prev; + friend class CBotInstArray; + +#ifdef _DEBUG + int m_index; +#endif + int m_state; + int m_step; + static int m_error; + static int m_start; + static int m_end; + static + CBotVar* m_retvar; // result of a return + + CBotVar* m_var; // result of the operations + CBotVar* m_listVar; // variables declared at this level + + bool m_bBlock; // is part of a block (variables are local to this block) + bool m_bOver; // stack limits? +// bool m_bDontDelete; // special, not to destroy the variable during delete + CBotProgram* m_prog; // user-defined functions + + static + int m_initimer; + static + int m_timer; + static + CBotString m_labelBreak; + static + void* m_pUser; + + CBotInstr* m_instr; // the corresponding instruction + bool m_bFunc; // an input of a function? + CBotCall* m_call; // recovery point in a extern call + friend class CBotTry; +}; + +// inline routinees must be declared in file.h + +inline bool CBotStack::IsOk() +{ + return (m_error == 0); +} + +inline int CBotStack::GetState() +{ + return m_state; +} + +inline int CBotStack::GetError() +{ + return m_error; +} diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 2898a92a..75e26e6c 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -25,6 +25,8 @@ #include "CBot.h" +#include "CBotStack.h" + #include #include #include From 394a49f5aa985e17cfc3653ff6963b83f4388f1f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 16:49:06 +0100 Subject: [PATCH 101/360] Moving CBotCall class in its own header and source files. --- src/CBot/CBot.h | 53 ------- src/CBot/CBotCall.cpp | 311 +++++++++++++++++++++++++++++++++++++++ src/CBot/CBotCall.h | 146 ++++++++++++++++++ src/CBot/CBotClass.cpp | 3 + src/CBot/CBotProgram.cpp | 305 +------------------------------------- src/CBot/CBotStack.cpp | 1 + src/CBot/CBotUtils.cpp | 50 +++++++ src/CBot/CBotUtils.h | 36 +++++ src/CBot/CMakeLists.txt | 2 + 9 files changed, 552 insertions(+), 355 deletions(-) create mode 100644 src/CBot/CBotCall.cpp create mode 100644 src/CBot/CBotCall.h create mode 100644 src/CBot/CBotUtils.cpp create mode 100644 src/CBot/CBotUtils.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 15c870e4..5e944d15 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -29,7 +29,6 @@ #include "CBotDll.h" // public definitions #include "CBotToken.h" // token management -#define STACKRUN 1 /// \def return execution directly on a suspended routine #define STACKMEM 1 /// \def preserve memory for the execution stack #define MAXSTACK 990 /// \def stack size reserved @@ -525,58 +524,6 @@ extern void DEBUG( const char* text, int val, CBotStack* pile ); #endif /////////////////////////////////////////// -// class for routine calls (external) - -class CBotCall -{ -private: - static - CBotCall* m_ListCalls; - static - void* m_pUser; - long m_nFuncIdent; - -private: - CBotString m_name; - bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser) ; - CBotTypResult - (*m_rComp) (CBotVar* &pVar, void* pUser) ; - CBotCall* m_next; - -public: - CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); - ~CBotCall(); - - static - bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); - - static - CBotTypResult - CompileCall(CBotToken* &p, CBotVar** ppVars, CBotCStack* pStack, long& nIdent); - static - bool CheckCall(const char* name); - -// static -// int DoCall(CBotToken* &p, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype); - static - int DoCall(long& nIdent, CBotToken* token, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype); -#if STACKRUN - bool Run(CBotStack* pStack); - static - bool RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack); -#endif - - CBotString GetName(); - CBotCall* Next(); - - static void SetPUser(void* pUser); - static void Free(); -}; - // class managing the methods declared by AddFunction on a class class CBotCallMethode diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp new file mode 100644 index 00000000..7796786a --- /dev/null +++ b/src/CBot/CBotCall.cpp @@ -0,0 +1,311 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotCall.h" + +#include "CBotToken.h" +#include "CBotStack.h" + +#include "CBotUtils.h" + +// Local include + +// Global include + + + +//////////////////////////////////////////////////////////////////////////////// + +CBotCall* CBotCall::m_ListCalls = nullptr; +void* CBotCall::m_pUser = nullptr; + +//////////////////////////////////////////////////////////////////////////////// +CBotCall::CBotCall(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) +{ + m_name = name; + m_rExec = rExec; + m_rComp = rCompile; + m_next = nullptr; + m_nFuncIdent = CBotVar::NextUniqNum(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCall::~CBotCall() +{ + if (m_next) delete m_next; + m_next = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCall::Free() +{ + delete CBotCall::m_ListCalls; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCall::AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) +{ + CBotCall* p = m_ListCalls; + CBotCall* pp = nullptr; + + if ( p != nullptr ) while ( p->m_next != nullptr ) + { + if ( p->GetName() == name ) + { + // frees redefined function + if ( pp ) pp->m_next = p->m_next; + else m_ListCalls = p->m_next; + pp = p; + p = p->m_next; + pp->m_next = nullptr; // not to destroy the following list + delete pp; + continue; + } + pp = p; // previous pointer + p = p->m_next; + } + + pp = new CBotCall(name, rExec, rCompile); + + if (p) p->m_next = pp; + else m_ListCalls = pp; + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack* pStack, long& nIdent) +{ + nIdent = 0; + CBotCall* pt = m_ListCalls; + CBotString name = p->GetString(); + + while ( pt != nullptr ) + { + if ( pt->m_name == name ) + { + CBotVar* pVar = MakeListVars(ppVar); + CBotVar* pVar2 = pVar; + CBotTypResult r = pt->m_rComp(pVar2, m_pUser); + int ret = r.GetType(); + + // if a class is returned, it is actually a pointer + if ( ret == CBotTypClass ) r.SetType( ret = CBotTypPointer ); + + if ( ret > 20 ) + { + if (pVar2) pStack->SetError(ret, p /*pVar2->GetToken()*/ ); + } + delete pVar; + nIdent = pt->m_nFuncIdent; + return r; + } + pt = pt->m_next; + } + return -1; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCall::SetPUser(void* pUser) +{ + m_pUser = pUser; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCall::CheckCall(const char* name) +{ + CBotCall* p = m_ListCalls; + + while ( p != nullptr ) + { + if ( name == p->GetName() ) return true; + p = p->m_next; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotCall::GetName() +{ + return m_name; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCall* CBotCall::Next() +{ + return m_next; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCall::DoCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack, CBotTypResult& rettype) +{ + CBotCall* pt = m_ListCalls; + + if ( nIdent ) while ( pt != nullptr ) + { + if ( pt->m_nFuncIdent == nIdent ) + { + goto fund; + } + pt = pt->m_next; + } + + pt = m_ListCalls; + + if ( token != nullptr ) + { + CBotString name = token->GetString(); + while ( pt != nullptr ) + { + if ( pt->m_name == name ) + { + nIdent = pt->m_nFuncIdent; + goto fund; + } + pt = pt->m_next; + } + } + + return -1; + +fund: +#if !STACKRUN + // lists the parameters depending on the contents of the stack (pStackVar) + + CBotVar* pVar = MakeListVars(ppVar, true); + CBotVar* pVarToDelete = pVar; + + // creates a variable to the result + CBotVar* pResult = rettype.Eq(0) ? nullptr : CBotVar::Create("", rettype); + + CBotVar* pRes = pResult; + int Exception = 0; + int res = pt->m_rExec(pVar, pResult, Exception, pStack->GetPUser()); + + if ( pResult != pRes ) delete pRes; // different result if made + delete pVarToDelete; + + if (res == false) + { + if (Exception!=0) + { + pStack->SetError(Exception, token); + } + delete pResult; + return false; + } + pStack->SetVar(pResult); + + if ( rettype.GetType() > 0 && pResult == nullptr ) + { + pStack->SetError(TX_NORETVAL, token); + } + nIdent = pt->m_nFuncIdent; + return true; + +#else + + CBotStack* pile = pStack->AddStackEOX(pt); + if ( pile == EOX ) return true; + + // lists the parameters depending on the contents of the stack (pStackVar) + + CBotVar* pVar = MakeListVars(ppVar, true); +// CBotVar* pVarToDelete = pVar; + + // creates a variable to the result + CBotVar* pResult = rettype.Eq(0) ? nullptr : CBotVar::Create("", rettype); + + pile->SetVar( pVar ); + + CBotStack* pile2 = pile->AddStack(); + pile2->SetVar( pResult ); + + pile->SetError(0, token); // for the position on error + away + return pt->Run( pStack ); + +#endif + +} + +#if STACKRUN + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack) +{ + CBotCall* pt = m_ListCalls; + + { + CBotString name = token->GetString(); + while ( pt != nullptr ) + { + if ( pt->m_name == name ) + { + nIdent = pt->m_nFuncIdent; + + CBotStack* pile = pStack->RestoreStackEOX(pt); + if ( pile == nullptr ) return true; + + // CBotStack* pile2 = pile->RestoreStack(); + pile->RestoreStack(); + return true; + } + pt = pt->m_next; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCall::Run(CBotStack* pStack) +{ + CBotStack* pile = pStack->AddStackEOX(this); + if ( pile == EOX ) return true; + CBotVar* pVar = pile->GetVar(); + + CBotStack* pile2 = pile->AddStack(); + CBotVar* pResult = pile2->GetVar(); + CBotVar* pRes = pResult; + + int Exception = 0; + int res = m_rExec(pVar, pResult, Exception, pStack->GetPUser()); + + if (res == false) + { + if (Exception!=0) + { + pStack->SetError(Exception); + } + if ( pResult != pRes ) delete pResult; // different result if made + return false; + } + + if ( pResult != nullptr ) pStack->SetCopyVar( pResult ); + if ( pResult != pRes ) delete pResult; // different result if made + + return true; +} + +#endif diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h new file mode 100644 index 00000000..79cab9a2 --- /dev/null +++ b/src/CBot/CBotCall.h @@ -0,0 +1,146 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + +#define STACKRUN 1 /// \def return execution directly on a suspended routine + +/*! + * \brief The CBotCall class. Class for routine calls (external). + */ +class CBotCall +{ +public: + + /*! + * \brief CBotCall + * \param name + * \param rExec + * \param rCompile + */ + CBotCall(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + + /*! + * \brief ~CBotCall + */ + ~CBotCall(); + + /*! + * \brief AddFunction + * \param name + * \param rExec + * \param rCompile + * \return + */ + static bool AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + + /*! + * \brief CompileCall Is acceptable by a call procedure name and given + * parameters. + * \param p + * \param ppVars + * \param pStack + * \param nIdent + * \return + */ + static CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, CBotCStack* pStack, long& nIdent); + + /*! + * \brief CheckCall + * \param name + * \return + */ + static bool CheckCall(const char* name); + + /*! + * \brief DoCall + * \param nIdent + * \param token + * \param ppVars + * \param pStack + * \param rettype + * \return + */ + static int DoCall(long& nIdent, CBotToken* token, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype); + +#if STACKRUN + + /*! + * \brief Run + * \param pStack + * \return + */ + bool Run(CBotStack* pStack); + + /*! + * \brief RestoreCall + * \param nIdent + * \param token + * \param ppVar + * \param pStack + * \return + */ + static bool RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack); +#endif + + /*! + * \brief GetName + * \return + */ + CBotString GetName(); + + /*! + * \brief Next + * \return + */ + CBotCall* Next(); + + /*! + * \brief SetPUser + * \param pUser + */ + static void SetPUser(void* pUser); + + /*! + * \brief Free + */ + static void Free(); + + +private: + static CBotCall* m_ListCalls; + static void* m_pUser; + long m_nFuncIdent; + + CBotString m_name; + bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser); + CBotTypResult (*m_rComp) (CBotVar* &pVar, void* pUser); + CBotCall* m_next; +}; diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index f98eaaaa..dc897977 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -22,6 +22,9 @@ // #include "CBot.h" + +#include "CBotCall.h" + #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotTwoOpExpr.h" diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index f1862c1e..a20531e7 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -22,8 +22,11 @@ #include "CBot.h" +#include "CBotCall.h" #include "CBotStack.h" +#include "CBotUtils.h" + #include CBotProgram::CBotProgram() @@ -556,308 +559,6 @@ int CBotProgram::GetVersion() } -////////////////////////////////////////////////////////////////////////////////////////////////////// - -CBotCall* CBotCall::m_ListCalls = nullptr; - -CBotCall::CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) -{ - m_name = name; - m_rExec = rExec; - m_rComp = rCompile; - m_next = nullptr; - m_nFuncIdent = CBotVar::NextUniqNum(); -} - -CBotCall::~CBotCall() -{ - if (m_next) delete m_next; - m_next = nullptr; -} - -void CBotCall::Free() -{ - delete CBotCall::m_ListCalls; -} - -bool CBotCall::AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) -{ - CBotCall* p = m_ListCalls; - CBotCall* pp = nullptr; - - if ( p != nullptr ) while ( p->m_next != nullptr ) - { - if ( p->GetName() == name ) - { - // frees redefined function - if ( pp ) pp->m_next = p->m_next; - else m_ListCalls = p->m_next; - pp = p; - p = p->m_next; - pp->m_next = nullptr; // not to destroy the following list - delete pp; - continue; - } - pp = p; // previous pointer - p = p->m_next; - } - - pp = new CBotCall(name, rExec, rCompile); - - if (p) p->m_next = pp; - else m_ListCalls = pp; - - return true; -} - - -// transforms the array of pointers to variables -// in a chained list of variables -CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal=false) -{ - int i = 0; - CBotVar* pVar = nullptr; - - while( true ) - { -// ppVars[i]; - if ( ppVars[i] == nullptr ) break; - - CBotVar* pp = CBotVar::Create(ppVars[i]); - if (bSetVal) pp->Copy(ppVars[i]); - else - if ( ppVars[i]->GetType() == CBotTypPointer ) - pp->SetClass( ppVars[i]->GetClass()); -// copy the pointer according to indirections - if (pVar == nullptr) pVar = pp; - else pVar->AddNext(pp); - i++; - } - return pVar; -} - -// is acceptable by a call procedure name -// and given parameters - -CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack* pStack, long& nIdent) -{ - nIdent = 0; - CBotCall* pt = m_ListCalls; - CBotString name = p->GetString(); - - while ( pt != nullptr ) - { - if ( pt->m_name == name ) - { - CBotVar* pVar = MakeListVars(ppVar); - CBotVar* pVar2 = pVar; - CBotTypResult r = pt->m_rComp(pVar2, m_pUser); - int ret = r.GetType(); - - // if a class is returned, it is actually a pointer - if ( ret == CBotTypClass ) r.SetType( ret = CBotTypPointer ); - - if ( ret > 20 ) - { - if (pVar2) pStack->SetError(ret, p /*pVar2->GetToken()*/ ); - } - delete pVar; - nIdent = pt->m_nFuncIdent; - return r; - } - pt = pt->m_next; - } - return -1; -} - -void* CBotCall::m_pUser = nullptr; - -void CBotCall::SetPUser(void* pUser) -{ - m_pUser = pUser; -} - -bool CBotCall::CheckCall(const char* name) -{ - CBotCall* p = m_ListCalls; - - while ( p != nullptr ) - { - if ( name == p->GetName() ) return true; - p = p->m_next; - } - return false; -} - - - -CBotString CBotCall::GetName() -{ - return m_name; -} - -CBotCall* CBotCall::Next() -{ - return m_next; -} - - -int CBotCall::DoCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack, CBotTypResult& rettype) -{ - CBotCall* pt = m_ListCalls; - - if ( nIdent ) while ( pt != nullptr ) - { - if ( pt->m_nFuncIdent == nIdent ) - { - goto fund; - } - pt = pt->m_next; - } - - pt = m_ListCalls; - - if ( token != nullptr ) - { - CBotString name = token->GetString(); - while ( pt != nullptr ) - { - if ( pt->m_name == name ) - { - nIdent = pt->m_nFuncIdent; - goto fund; - } - pt = pt->m_next; - } - } - - return -1; - -fund: -#if !STACKRUN - // lists the parameters depending on the contents of the stack (pStackVar) - - CBotVar* pVar = MakeListVars(ppVar, true); - CBotVar* pVarToDelete = pVar; - - // creates a variable to the result - CBotVar* pResult = rettype.Eq(0) ? nullptr : CBotVar::Create("", rettype); - - CBotVar* pRes = pResult; - int Exception = 0; - int res = pt->m_rExec(pVar, pResult, Exception, pStack->GetPUser()); - - if ( pResult != pRes ) delete pRes; // different result if made - delete pVarToDelete; - - if (res == false) - { - if (Exception!=0) - { - pStack->SetError(Exception, token); - } - delete pResult; - return false; - } - pStack->SetVar(pResult); - - if ( rettype.GetType() > 0 && pResult == nullptr ) - { - pStack->SetError(TX_NORETVAL, token); - } - nIdent = pt->m_nFuncIdent; - return true; - -#else - - CBotStack* pile = pStack->AddStackEOX(pt); - if ( pile == EOX ) return true; - - // lists the parameters depending on the contents of the stack (pStackVar) - - CBotVar* pVar = MakeListVars(ppVar, true); -// CBotVar* pVarToDelete = pVar; - - // creates a variable to the result - CBotVar* pResult = rettype.Eq(0) ? nullptr : CBotVar::Create("", rettype); - - pile->SetVar( pVar ); - - CBotStack* pile2 = pile->AddStack(); - pile2->SetVar( pResult ); - - pile->SetError(0, token); // for the position on error + away - return pt->Run( pStack ); - -#endif - -} - -#if STACKRUN - -bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack) -{ - CBotCall* pt = m_ListCalls; - - { - CBotString name = token->GetString(); - while ( pt != nullptr ) - { - if ( pt->m_name == name ) - { - nIdent = pt->m_nFuncIdent; - - CBotStack* pile = pStack->RestoreStackEOX(pt); - if ( pile == nullptr ) return true; - - // CBotStack* pile2 = pile->RestoreStack(); - pile->RestoreStack(); - return true; - } - pt = pt->m_next; - } - } - - return false; -} - -bool CBotCall::Run(CBotStack* pStack) -{ - CBotStack* pile = pStack->AddStackEOX(this); - if ( pile == EOX ) return true; - CBotVar* pVar = pile->GetVar(); - - CBotStack* pile2 = pile->AddStack(); - CBotVar* pResult = pile2->GetVar(); - CBotVar* pRes = pResult; - - int Exception = 0; - int res = m_rExec(pVar, pResult, Exception, pStack->GetPUser()); - - if (res == false) - { - if (Exception!=0) - { - pStack->SetError(Exception); - } - if ( pResult != pRes ) delete pResult; // different result if made - return false; - } - - if ( pResult != nullptr ) pStack->SetCopyVar( pResult ); - if ( pResult != pRes ) delete pResult; // different result if made - - return true; -} - -#endif - -/////////////////////////////////////////////////////////////////////////////////////// - CBotCallMethode::CBotCallMethode(const char* name, bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index b1715e15..0997f468 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotStack.h" +#include "CBotCall.h" // Local include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp new file mode 100644 index 00000000..5aba61c2 --- /dev/null +++ b/src/CBot/CBotUtils.cpp @@ -0,0 +1,50 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotUtils.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal) +{ + int i = 0; + CBotVar* pVar = nullptr; + + while( true ) + { +// ppVars[i]; + if ( ppVars[i] == nullptr ) break; + + CBotVar* pp = CBotVar::Create(ppVars[i]); + if (bSetVal) pp->Copy(ppVars[i]); + else + if ( ppVars[i]->GetType() == CBotTypPointer ) + pp->SetClass( ppVars[i]->GetClass()); +// copy the pointer according to indirections + if (pVar == nullptr) pVar = pp; + else pVar->AddNext(pp); + i++; + } + return pVar; +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h new file mode 100644 index 00000000..df8bb55d --- /dev/null +++ b/src/CBot/CBotUtils.h @@ -0,0 +1,36 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + +/*! + * \brief MakeListVars Transforms the array of pointers to variables in a + * chained list of variables + * \param ppVars + * \param bSetVal + * \return + */ +CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal=false); diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 484d023c..bf7deefc 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -7,6 +7,8 @@ set(SOURCES CBotString.cpp CBotToken.cpp CBotVar.cpp + CBotCall.cpp + CBotUtils.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp From 63ab9d730149bcd12e586321382e5437cd3d5c47 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 17:04:27 +0100 Subject: [PATCH 102/360] Moving CBotVarArray class in its own header and source files. --- src/CBot/CBot.h | 33 ------- src/CBot/CBotDefines.h | 28 ++++++ src/CBot/CBotInstr/CBotExprVar.cpp | 2 + src/CBot/CBotInstr/CBotIndexExpr.cpp | 2 + src/CBot/CBotInstr/CBotInstArray.cpp | 2 + src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 + src/CBot/CBotVar.cpp | 115 +--------------------- src/CBot/CBotVar/CBotVarArray.cpp | 140 +++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarArray.h | 102 +++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 10 files changed, 283 insertions(+), 144 deletions(-) create mode 100644 src/CBot/CBotDefines.h create mode 100644 src/CBot/CBotVar/CBotVarArray.cpp create mode 100644 src/CBot/CBotVar/CBotVarArray.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 5e944d15..c5fc9de8 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -468,39 +468,6 @@ public: bool Ne(CBotVar* left, CBotVar* right) override; }; - -// classe pour les tableaux - -#define MAXARRAYSIZE 9999 - -class CBotVarArray : public CBotVar -{ -private: - CBotVarClass* - m_pInstance; // instance manager of table - - friend class CBotVar; // my daddy is a buddy - -public: - CBotVarArray( const CBotToken* name, CBotTypResult& type ); - ~CBotVarArray(); - - void SetPointer(CBotVar* p) override; - CBotVarClass* - GetPointer() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - CBotVar* GetItem(int n, bool bGrow=false) override; // makes an element according to its numeric index - // enlarged the table if necessary if bExtend -// CBotVar* GetItem(const char* name); // makes a element by literal index - CBotVar* GetItemList() override; // gives the first item in the list - - CBotString GetValString() override; // gets the contents of the array into a string - - bool Save1State(FILE* pf) override; -}; - - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h new file mode 100644 index 00000000..2c6e34d7 --- /dev/null +++ b/src/CBot/CBotDefines.h @@ -0,0 +1,28 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + +#define MAXARRAYSIZE 9999 diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 0e531fae..344ce85c 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -26,6 +26,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVarArray.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index f4882c00..2bc37f1e 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVarArray.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index e1327a58..4bf2fd16 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -27,6 +27,8 @@ #include "CBotStack.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 84c7b735..0785dd27 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -25,6 +25,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVarArray.h" + // Local include // Global include diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 75e26e6c..490af3f4 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -27,6 +27,10 @@ #include "CBotStack.h" +#include "CBotVar/CBotVarArray.h" + +#include "CBotDefines.h" + #include #include #include @@ -1774,117 +1778,6 @@ bool CBotVarClass::Ne(CBotVar* left, CBotVar* right) return l != r; } -///////////////////////////////////////////////////////////////////////////// -// management of arrays - -CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type ) -{ - if ( !type.Eq(CBotTypArrayPointer) && - !type.Eq(CBotTypArrayBody)) assert(0); - - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - - m_type = type; - m_type.SetType(CBotTypArrayPointer); - m_binit = CBotVar::InitType::UNDEF; - - m_pInstance = nullptr; // the list of the array elements -} - -CBotVarArray::~CBotVarArray() -{ - if ( m_pInstance != nullptr ) m_pInstance->DecrementUse(); // the lowest reference -} - -// copy a variable into another -void CBotVarArray::Copy(CBotVar* pSrc, bool bName) -{ - if ( pSrc->GetType() != CBotTypArrayPointer ) - assert(0); - - CBotVarArray* p = static_cast(pSrc); - - if ( bName) *m_token = *p->m_token; - m_type = p->m_type; - m_pInstance = p->GetPointer(); - - if ( m_pInstance != nullptr ) - m_pInstance->IncrementUse(); // a reference increase - - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - -void CBotVarArray::SetPointer(CBotVar* pVarClass) -{ - m_binit = CBotVar::InitType::DEF; // init, even on a null pointer - - if ( m_pInstance == pVarClass) return; // Special, not decrement and reincrement - // because the decrement can destroy the object - - if ( pVarClass != nullptr ) - { - if ( pVarClass->GetType() == CBotTypArrayPointer ) - pVarClass = pVarClass->GetPointer(); // the real pointer to the object - - if ( !pVarClass->m_type.Eq(CBotTypClass) && - !pVarClass->m_type.Eq(CBotTypArrayBody)) - assert(0); - - (static_cast(pVarClass))->IncrementUse(); // incement the reference - } - - if ( m_pInstance != nullptr ) m_pInstance->DecrementUse(); - m_pInstance = static_cast(pVarClass); -} - - -CBotVarClass* CBotVarArray::GetPointer() -{ - if ( m_pInstance == nullptr ) return nullptr; - return m_pInstance->GetPointer(); -} - -CBotVar* CBotVarArray::GetItem(int n, bool bExtend) -{ - if ( m_pInstance == nullptr ) - { - if ( !bExtend ) return nullptr; - // creates an instance of the table - - CBotVarClass* instance = new CBotVarClass(nullptr, m_type); - SetPointer( instance ); - } - return m_pInstance->GetItem(n, bExtend); -} - -CBotVar* CBotVarArray::GetItemList() -{ - if ( m_pInstance == nullptr) return nullptr; - return m_pInstance->GetItemList(); -} - -CBotString CBotVarArray::GetValString() -{ - if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ; - return m_pInstance->GetValString(); -} - -bool CBotVarArray::Save1State(FILE* pf) -{ - if ( !WriteType(pf, m_type) ) return false; - return SaveVar(pf, m_pInstance); // saves the instance that manages the table -} - - ///////////////////////////////////////////////////////////////////////////// // gestion des pointeurs à une instance donnée // TODO management of pointers to a given instance diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp new file mode 100644 index 00000000..35f55a52 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -0,0 +1,140 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarArray.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type ) +{ + if ( !type.Eq(CBotTypArrayPointer) && + !type.Eq(CBotTypArrayBody)) assert(0); + + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + + m_type = type; + m_type.SetType(CBotTypArrayPointer); + m_binit = CBotVar::InitType::UNDEF; + + m_pInstance = nullptr; // the list of the array elements +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarArray::~CBotVarArray() +{ + if ( m_pInstance != nullptr ) m_pInstance->DecrementUse(); // the lowest reference +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarArray::Copy(CBotVar* pSrc, bool bName) +{ + if ( pSrc->GetType() != CBotTypArrayPointer ) + assert(0); + + CBotVarArray* p = static_cast(pSrc); + + if ( bName) *m_token = *p->m_token; + m_type = p->m_type; + m_pInstance = p->GetPointer(); + + if ( m_pInstance != nullptr ) + m_pInstance->IncrementUse(); // a reference increase + + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarArray::SetPointer(CBotVar* pVarClass) +{ + m_binit = CBotVar::InitType::DEF; // init, even on a null pointer + + if ( m_pInstance == pVarClass) return; // Special, not decrement and reincrement + // because the decrement can destroy the object + + if ( pVarClass != nullptr ) + { + if ( pVarClass->GetType() == CBotTypArrayPointer ) + pVarClass = pVarClass->GetPointer(); // the real pointer to the object + + if ( !pVarClass->m_type.Eq(CBotTypClass) && + !pVarClass->m_type.Eq(CBotTypArrayBody)) + assert(0); + + (static_cast(pVarClass))->IncrementUse(); // incement the reference + } + + if ( m_pInstance != nullptr ) m_pInstance->DecrementUse(); + m_pInstance = static_cast(pVarClass); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass* CBotVarArray::GetPointer() +{ + if ( m_pInstance == nullptr ) return nullptr; + return m_pInstance->GetPointer(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarArray::GetItem(int n, bool bExtend) +{ + if ( m_pInstance == nullptr ) + { + if ( !bExtend ) return nullptr; + // creates an instance of the table + + CBotVarClass* instance = new CBotVarClass(nullptr, m_type); + SetPointer( instance ); + } + return m_pInstance->GetItem(n, bExtend); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarArray::GetItemList() +{ + if ( m_pInstance == nullptr) return nullptr; + return m_pInstance->GetItemList(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarArray::GetValString() +{ + if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ; + return m_pInstance->GetValString(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarArray::Save1State(FILE* pf) +{ + if ( !WriteType(pf, m_type) ) return false; + return SaveVar(pf, m_pInstance); // saves the instance that manages the table +} diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h new file mode 100644 index 00000000..158cdf81 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -0,0 +1,102 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" +#include "CBotDefines.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarArray class Classe pour les tableaux. + */ +class CBotVarArray : public CBotVar +{ +public: + + /*! + * \brief CBotVarArray + * \param name + * \param type + */ + CBotVarArray( const CBotToken* name, CBotTypResult& type ); + + /*! + * \brief ~CBotVarArray + */ + ~CBotVarArray(); + + /*! + * \brief SetPointer + * \param p + */ + void SetPointer(CBotVar* p) override; + + /*! + * \brief GetPointer + * \return + */ + CBotVarClass* GetPointer() override; + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief GetItem Makes an element according to its numeric index enlarged + * the table if necessary if bExtend. + * \param n + * \param bGrow + * \return + */ + CBotVar* GetItem(int n, bool bGrow=false) override; + + /*! + * \brief GetItemList Gives the first item in the list. + * \return + */ + CBotVar* GetItemList() override; + + /*! + * \brief GetValString Gets the contents of the array into a string. + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! Instance manager of table. + CBotVarClass* m_pInstance; + //! My daddy is a buddy. + friend class CBotVar; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index bf7deefc..5bb6ad70 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -53,6 +53,7 @@ set(SOURCES CBotInstr/CBotListArray.cpp CBotInstr/CBotInstArray.cpp CBotInstr/CBotInt.cpp + CBotVar/CBotVarArray.cpp ) # Includes From 77d738634c5eeb8b4f33441191d28da7fe3f27f7 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 17:37:53 +0100 Subject: [PATCH 103/360] Moving CBotClass class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBotClass.cpp | 102 +++++--- src/CBot/CBotClass.h | 328 ++++++++++++++++++++++++ src/CBot/CBotDll.h | 118 --------- src/CBot/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotClassInst.cpp | 1 + src/CBot/CBotInstr/CBotFieldExpr.cpp | 1 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 1 + src/CBot/CBotInstr/CBotLeftExpr.cpp | 1 + src/CBot/CBotInstr/CBotNew.cpp | 1 + src/CBot/CBotProgram.cpp | 2 +- src/CBot/CBotVar.cpp | 1 + src/level/robotmain.cpp | 2 + src/script/scriptfunc.cpp | 3 + 14 files changed, 408 insertions(+), 155 deletions(-) create mode 100644 src/CBot/CBotClass.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 30f22461..76cfe2b5 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -73,6 +73,7 @@ #include "CBotInstr/CBotInt.h" #include "CBotStack.h" +#include "CBotClass.h" // Local include diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index dc897977..9c18f2c9 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -17,21 +17,27 @@ * along with this program. If not, see http://gnu.org/licenses */ -///////////////////////////////////////////////////////////////////// -// Management of variables of class type -// - -#include "CBot.h" - -#include "CBotCall.h" +// Modules inlcude +#include "CBotClass.h" #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotTwoOpExpr.h" +#include "CBotCall.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::m_ExClass = nullptr; -CBotClass::CBotClass(const char* name, CBotClass* pPapa, bool bIntrinsic) +//////////////////////////////////////////////////////////////////////////////// +CBotClass::CBotClass(const char* name, + CBotClass* pPapa, + bool bIntrinsic) { m_pParent = pPapa; m_name = name; @@ -60,6 +66,7 @@ CBotClass::CBotClass(const char* name, CBotClass* pPapa, bool bIntrinsic) } +//////////////////////////////////////////////////////////////////////////////// CBotClass::~CBotClass() { // removes the list of class @@ -77,11 +84,15 @@ CBotClass::~CBotClass() delete m_next; // releases all of them on this level } -CBotClass* CBotClass::Create(const char* name, CBotClass* parent, bool intrinsic) +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotClass::Create(const char* name, + CBotClass* parent, + bool intrinsic) { return new CBotClass(name, parent, intrinsic); } +//////////////////////////////////////////////////////////////////////////////// void CBotClass::Free() { while ( m_ExClass != nullptr ) @@ -90,6 +101,7 @@ void CBotClass::Free() } } +//////////////////////////////////////////////////////////////////////////////// void CBotClass::Purge() { if ( this == nullptr ) return; @@ -108,6 +120,7 @@ void CBotClass::Purge() m_next = nullptr; // no longer belongs to this chain } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::Lock(CBotProgram* p) { int i = m_cptLock++; @@ -144,6 +157,7 @@ bool CBotClass::Lock(CBotProgram* p) return false; } +//////////////////////////////////////////////////////////////////////////////// void CBotClass::Unlock() { if ( --m_cptOne > 0 ) return ; @@ -162,6 +176,7 @@ void CBotClass::Unlock() m_ProgInLock[i] = nullptr; } +//////////////////////////////////////////////////////////////////////////////// void CBotClass::FreeLock(CBotProgram* p) { CBotClass* pClass = m_ExClass; @@ -182,9 +197,10 @@ void CBotClass::FreeLock(CBotProgram* p) } } - - -bool CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate) +//////////////////////////////////////////////////////////////////////////////// +bool CBotClass::AddItem(CBotString name, + CBotTypResult type, + int mPrivate) { CBotToken token(name, CBotString()); CBotClass* pClass = type.GetClass(); @@ -207,7 +223,7 @@ bool CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate) return AddItem( pVar ); } - +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::AddItem(CBotVar* pVar) { pVar->SetUniqNum(++m_nbVar); @@ -218,6 +234,7 @@ bool CBotClass::AddItem(CBotVar* pVar) return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotClass::AddNext(CBotClass* pClass) { CBotClass* p = this; @@ -226,17 +243,20 @@ void CBotClass::AddNext(CBotClass* pClass) p->m_next = pClass; } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotClass::GetName() { return m_name; } +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::GetParent() { if ( this == nullptr ) return nullptr; return m_pParent; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::IsChildOf(CBotClass* pClass) { CBotClass* p = this; @@ -248,12 +268,13 @@ bool CBotClass::IsChildOf(CBotClass* pClass) return false; } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotClass::GetVar() { return m_pVar; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotClass::GetItem(const char* name) { CBotVar* p = m_pVar; @@ -267,6 +288,7 @@ CBotVar* CBotClass::GetItem(const char* name) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotClass::GetItemRef(int nIdent) { CBotVar* p = m_pVar; @@ -280,16 +302,19 @@ CBotVar* CBotClass::GetItemRef(int nIdent) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::IsIntrinsic() { return m_bIntrinsic; } +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Find(CBotToken* &pToken) { return Find(pToken->GetString()); } +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Find(const char* name) { CBotClass* p = m_ExClass; @@ -303,9 +328,10 @@ CBotClass* CBotClass::Find(const char* name) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) { // stores pointers to the two functions CBotCallMethode* p = m_pCalls; @@ -332,18 +358,19 @@ bool CBotClass::AddFunction(const char* name, return true; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ) { m_rMaj = rMaj; return true; } -// compiles a method associated with an instance of class -// the method can be declared by the user or AddFunction - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotClass::CompileMethode(const char* name, - CBotVar* pThis, CBotVar** ppParams, - CBotCStack* pStack, long& nIdent) + CBotVar* pThis, + CBotVar** ppParams, + CBotCStack* pStack, + long& nIdent) { nIdent = 0; // forget the previous one if necessary @@ -360,11 +387,13 @@ CBotTypResult CBotClass::CompileMethode(const char* name, return r; } -// executes a method - -bool CBotClass::ExecuteMethode(long& nIdent, const char* name, - CBotVar* pThis, CBotVar** ppParams, - CBotVar* &pResult, CBotStack* &pStack, +//////////////////////////////////////////////////////////////////////////////// +bool CBotClass::ExecuteMethode(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppParams, + CBotVar* &pResult, + CBotStack* &pStack, CBotToken* pToken) { int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken); @@ -382,17 +411,17 @@ bool CBotClass::ExecuteMethode(long& nIdent, const char* name, return ret; } -// restored the execution stack - -void CBotClass::RestoreMethode(long& nIdent, const char* name, CBotVar* pThis, - CBotVar** ppParams, CBotStack* &pStack) +//////////////////////////////////////////////////////////////////////////////// +void CBotClass::RestoreMethode(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppParams, + CBotStack* &pStack) { m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this); } - - - +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::SaveStaticState(FILE* pf) { if (!WriteWord( pf, CBOTVERSION*2)) return false; @@ -429,6 +458,7 @@ bool CBotClass::SaveStaticState(FILE* pf) return true; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::RestoreStaticState(FILE* pf) { CBotString ClassName, VarName; @@ -466,9 +496,9 @@ bool CBotClass::RestoreStaticState(FILE* pf) return true; } -// test if a procedure name is already defined somewhere - -bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) +//////////////////////////////////////////////////////////////////////////////// +bool CBotClass::CheckCall(CBotToken* &pToken, + CBotDefParam* pParam) { CBotString name = pToken->GetString(); diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h new file mode 100644 index 00000000..e2bc0006 --- /dev/null +++ b/src/CBot/CBotClass.h @@ -0,0 +1,328 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + +/*! + * \brief The CBotClass class Class to define new classes in the language CBOT + * for example to define the class CPoint (x, y). + */ +class CBotClass +{ +public: + //! Mark if is set or not + bool m_IsDef; + + /*! + * \brief CBotClass Constructor. Once a class is created, it is known around + * CBot intrinsic mode gives a class that is not managed by pointers. + * \param name + * \param pParent + * \param bIntrinsic + */ + CBotClass( const char* name, + CBotClass* pParent, + bool bIntrinsic = false ); + + /*! + * \brief CBotClass Destructor. + */ + ~CBotClass( ); + + /*! + * \brief Create + * \param name + * \param parent + * \param intrinsic + * \return + */ + static CBotClass* Create(const char* name, + CBotClass* parent, + bool intrinsic = false); + + /*! + * \brief AddFunction This call allows to add as external (**) new method + * used by the objects of this class. + * \param name + * \param rExec + * \param rCompile + * \return + */ + bool AddFunction(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); + + /*! + * \brief AddUpdateFunc Defines routine to be called to update the elements + * of the class. + * \param rMaj + * \return + */ + bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ); + // + + /*! + * \brief AddItem Adds an element to the class. + * \param name + * \param type + * \param mPrivate + * \return + */ + bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); + + /*! + * \brief AddItem Adds an item by passing the pointer to an instance of a + * variable the object is taken as is, so do not destroyed. + * \param pVar + * \return + */ + bool AddItem(CBotVar* pVar); + + /*! + * \brief AddNext + * \param pClass + */ + void AddNext(CBotClass* pClass); + + /*! + * \brief GetName Gives the name of the class. + * \return + */ + CBotString GetName(); + + /*! + * \brief GetParent Gives the parent class (or nullptr). + * \return + */ + CBotClass* GetParent(); + + /*! + * \brief IsChildOf True if a class is derived (Extends) of another. + * \param pClass + * \return true also if the classes are identical + */ + bool IsChildOf(CBotClass* pClass); + + /*! + * \brief Find Trouve une classe d'après son nom + * \param pToken + * \return A class by it's its name. + */ + static CBotClass* Find(CBotToken* &pToken); + + /*! + * \brief Find + * \param name + * \return + */ + static CBotClass* Find(const char* name); + + /*! + * \brief GetVar Return the list of variables. + * \return + */ + CBotVar* GetVar(); + /*! + * \brief GetItem One of the variables according to its name. + * \param name + * \return + */ + CBotVar* GetItem(const char* name); + + /*! + * \brief GetItemRef + * \param nIdent + * \return + */ + CBotVar* GetItemRef(int nIdent); + + /*! + * \brief CompileMethode Compiles a method associated with an instance of + * class the method can be declared by the user or AddFunction. + * \param name + * \param pThis + * \param ppParams + * \param pStack + * \param nIdent + * \return + */ + CBotTypResult CompileMethode(const char* name, + CBotVar* pThis, + CBotVar** ppParams, + CBotCStack* pStack, + long& nIdent); + + /*! + * \brief ExecuteMethode Executes a method. + * \param nIdent + * \param name + * \param pThis + * \param ppParams + * \param pResult + * \param pStack + * \param pToken + * \return + */ + bool ExecuteMethode(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppParams, + CBotVar* &pResult, + CBotStack* &pStack, + CBotToken* pToken); + + /*! + * \brief RestoreMethode Restored the execution stack. + * \param nIdent + * \param name + * \param pThis + * \param ppParams + * \param pStack + */ + void RestoreMethode(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppParams, + CBotStack* &pStack); + + /*! + * \brief Compile Compiles a class declared by the user. + * \param p + * \param pStack + * \return + */ + static CBotClass* Compile(CBotToken* &p, + CBotCStack* pStack); + + /*! + * \brief Compile1 + * \param p + * \param pStack + * \return + */ + static CBotClass* Compile1(CBotToken* &p, + CBotCStack* pStack); + + /*! + * \brief CompileDefItem + * \param p + * \param pStack + * \param bSecond + * \return + */ + bool CompileDefItem(CBotToken* &p, + CBotCStack* pStack, + bool bSecond); + + /*! + * \brief IsIntrinsic + * \return + */ + bool IsIntrinsic(); + + /*! + * \brief Purge + */ + void Purge(); + + /*! + * \brief Free + */ + static void Free(); + + /*! + * \brief SaveStaticState + * \param pf + * \return + */ + static bool SaveStaticState(FILE* pf); + + /*! + * \brief RestoreStaticState + * \param pf + * \return + */ + static bool RestoreStaticState(FILE* pf); + + /*! + * \brief Lock + * \param p + * \return + */ + bool Lock(CBotProgram* p); + + /*! + * \brief Unlock + */ + void Unlock(); + + /*! + * \brief FreeLock + * \param p + */ + static void FreeLock(CBotProgram* p); + + /*! + * \brief CheckCall Test if a procedure name is already defined somewhere. + * \param pToken + * \param pParam + * \return + */ + bool CheckCall(CBotToken* &pToken, + CBotDefParam* pParam); + +private: + //! List of classes existing at a given time. + static CBotClass* m_ExClass; + //! For this general list. + CBotClass* m_ExNext; + //! For this general list. + CBotClass* m_ExPrev; + //! Parent class. + CBotClass* m_pParent; + //! Name of this class. + CBotString m_name; + //! Number of variables in the chain. + int m_nbVar; + //! Content of the class. + CBotVar* m_pVar; + //! Intrinsic class. + bool m_bIntrinsic; + //! The string class. + CBotClass* m_next; + //! List of methods defined in external. + CBotCallMethode* m_pCalls; + //! Compiled list of methods. + CBotFunction* m_pMethod; + void (*m_rMaj) ( CBotVar* pThis, void* pUser ); + friend class CBotVarClass; + //! For Lock / UnLock. + int m_cptLock; + //! Lock for reentrancy. + int m_cptOne; + //! Processes waiting for sync. + CBotProgram* m_ProgInLock[5]; +}; diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index deec62cb..c1e8b69f 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -847,124 +847,6 @@ virtual ~CBotVar( ); // destructor */ - -//////////////////////////////////////////////////////////////////////// -// management of classes -//////////////////////////////////////////////////////////////////////// - -// class to define new classes in the language CBOT -// for example to define the class CPoint (x, y) - -class CBotClass -{ -private: - static - CBotClass* m_ExClass; // list of classes existing at a given time - CBotClass* m_ExNext; // for this general list - CBotClass* m_ExPrev; // for this general list - -private: - CBotClass* m_pParent; // parent class - CBotString m_name; // name of this class - int m_nbVar; // number of variables in the chain - CBotVar* m_pVar; // content of the class - bool m_bIntrinsic; // intrinsic class - CBotClass* m_next; // the string class - CBotCallMethode* m_pCalls; // list of methods defined in external - CBotFunction* m_pMethod; // compiled list of methods - void (*m_rMaj) ( CBotVar* pThis, void* pUser ); - friend class CBotVarClass; - int m_cptLock; // for Lock / UnLock - int m_cptOne; // Lock for reentrancy - CBotProgram* m_ProgInLock[5];// processes waiting for sync - -public: - bool m_IsDef; // mark if is set or not - - CBotClass( const char* name, - CBotClass* pParent, bool bIntrinsic = false ); // constructor - // Once a class is created, it is known - // around CBoT - // intrinsic mode gives a class that is not managed by pointers - - ~CBotClass( ); // destructor - - static CBotClass* Create(const char* name, CBotClass* parent, bool intrinsic = false); - - bool AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); - // this call allows to add as external (**) - // new method used by the objects of this class - - bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ); - // defines routine to be called to update the elements of the class - - bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); - // adds an element to the class -// bool AddItem(CBotString name, CBotClass* pClass); - // the same for elements belonging to pClass - bool AddItem(CBotVar* pVar); - // adds an item by passing the pointer to an instance of a variable - // the object is taken as is, so do not destroyed - - - - // adds an element by giving an element of type CBotVar - void AddNext(CBotClass* pClass); - - CBotString GetName(); // gives the name of the class - CBotClass* GetParent(); // gives the parent class (or nullptr) - - // true if a class is derived (Extends) of another - // return true also if the classes are identical - bool IsChildOf(CBotClass* pClass); - - static - CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom - // return a class by it's its name - static - CBotClass* Find(const char* name); - - CBotVar* GetVar(); // return the list of variables - CBotVar* GetItem(const char* name); // one of the variables according to its name - CBotVar* GetItemRef(int nIdent); - - CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams, - CBotCStack* pStack, long& nIdent); - - bool ExecuteMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken); - void RestoreMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotStack* &pStack); - - // compiles a class declared by the user - static - CBotClass* Compile(CBotToken* &p, CBotCStack* pStack); - static - CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack); - - bool CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond); - - bool IsIntrinsic(); - void Purge(); - static - void Free(); - - static - bool SaveStaticState(FILE* pf); - - static - bool RestoreStaticState(FILE* pf); - - bool Lock(CBotProgram* p); - void Unlock(); - static - void FreeLock(CBotProgram* p); - - bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); - -}; - - /* //////////////////////////////////////////////////////////////////////// // Examples of use diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 64b85fdc..61a98870 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -30,6 +30,7 @@ #include "CBotInstr/CBotListArray.h" #include "CBotStack.h" +#include "CBotClass.h" #include diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index e02328da..a78b4de9 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index ae8e583d..592d4a7e 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -21,6 +21,7 @@ #include "CBotFieldExpr.h" #include "CBotStack.h" +#include "CBotClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 1ec99067..a33207fb 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -21,6 +21,7 @@ #include "CBotInstrMethode.h" #include "CBotStack.h" +#include "CBotClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 0785dd27..468854a9 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -24,6 +24,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotClass.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index fef5c074..9da2a88e 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -21,6 +21,7 @@ #include "CBotNew.h" #include "CBotStack.h" +#include "CBotClass.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index a20531e7..27485f85 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -24,7 +24,7 @@ #include "CBotCall.h" #include "CBotStack.h" - +#include "CBotClass.h" #include "CBotUtils.h" #include diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 490af3f4..8808cb0f 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -30,6 +30,7 @@ #include "CBotVar/CBotVarArray.h" #include "CBotDefines.h" +#include "CBotClass.h" #include #include diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 483f0804..8ff82eee 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -20,6 +20,8 @@ #include "level/robotmain.h" #include "CBot/CBotDll.h" +// TODO must be replaced by CBot.h +#include "CBot/CBotClass.h" #include "app/app.h" #include "app/input.h" diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index a49dc9c1..7ff61714 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -19,6 +19,9 @@ #include "script/scriptfunc.h" +// TODO must be replaced by CBot.h +#include "CBot/CBotClass.h" + #include "app/app.h" #include "common/global.h" From 70dc6785f2fecd4b03e60c0f78e092e55842fb93 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 18:05:35 +0100 Subject: [PATCH 104/360] Moving CBotProgram class in its own header and source files. --- src/CBot/CBot.h | 1 + src/CBot/CBotClass.h | 2 + src/CBot/CBotDll.h | 128 ------------------- src/CBot/CBotProgram.cpp | 172 +++++++++++++++----------- src/CBot/CBotProgram.h | 260 +++++++++++++++++++++++++++++++++++++++ src/script/script.h | 2 + 6 files changed, 366 insertions(+), 199 deletions(-) create mode 100644 src/CBot/CBotProgram.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index c5fc9de8..e98a1c6c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -28,6 +28,7 @@ #include "resource.h" #include "CBotDll.h" // public definitions #include "CBotToken.h" // token management +#include "CBotProgram.h" #define STACKMEM 1 /// \def preserve memory for the execution stack #define MAXSTACK 990 /// \def stack size reserved diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index e2bc0006..3cc4f9f9 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotProgram.h" + // Local include // Global include diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index c1e8b69f..6bd16030 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -440,134 +440,6 @@ public: CBotString& ElementAt(int nIndex); }; -//////////////////////////////////////////////////////////////////// -// main class managing CBot program -// - -class CBotProgram -{ -private: - CBotFunction* m_Prog; // the user-defined functions - CBotFunction* m_pRun; // the basic function for the execution - CBotClass* m_pClass; // classes defined in this part - CBotStack* m_pStack; // execution stack - CBotVar* m_pInstance; // instance of the parent class - friend class CBotFunction; - - int m_ErrorCode; - int m_ErrorStart; - int m_ErrorEnd; - - long m_Ident; // associated identifier - -public: - bool m_bCompileClass; - -public: - static void Init(); - // initializes the module (defined keywords for errors) - // should be done once (and only one) at the beginning - static - void Free(); - // frees the static memory areas - - static - int GetVersion(); - // gives the version of the library CBOT - - - CBotProgram(); - CBotProgram(CBotVar* pInstance); - ~CBotProgram(); - - bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = nullptr); - // compiles the program given in text - // returns false if an error at compile - // see GetCompileError () to retrieve the error - // ListFonctions returns the names of functions declared as extern - // pUser can pass a pointer to routines defined by AddFunction - - void SetIdent(long n); - // associates an identifier with the instance CBotProgram - - long GetIdent(); - // gives the identifier - - int GetError(); - bool GetError(int& code, int& start, int& end); - bool GetError(int& code, int& start, int& end, CBotProgram* &pProg); - // if true - // gives the error found in the compilation - // or execution - // delimits the start and end block where the error - // pProg lets you know what "module" has produced runtime error - static CBotString GetErrorText(int code); - - - bool Start(const char* name); - // defines what function should be executed - // returns false if the funtion name is not found - // the program does nothing, we must call Run () for this - - bool Run(void* pUser = nullptr, int timer = -1); - // executes the program - // returns false if the program was suspended - // returns true if the program ended with or without error - // timer = 0 allows to advance step by step - - bool GetRunPos(const char* &FunctionName, int &start, int &end); - // gives the position in the executing program - // returns false if it is not running (program completion) - // FunctionName is a pointer made to the name of the function - // start and end position in the text of the token processing - - CBotVar* GetStackVars(const char* &FunctionName, int level); - // provides the pointer to the variables on the execution stack - // level is an input parameter, 0 for the last level, -1, -2, etc. for the other levels - // the return value (CBotVar *) is a variable list (or nullptr) - // that can be processed as the list of parameters received by a routine - // FunctionName gives the name of the function where are these variables - // FunctionName == nullptr means that is more in a program (depending on level) - - void Stop(); - // stops execution of the program - // therefore quits "suspend" mode - - static - void SetTimer(int n); - // defines the number of steps (parts of instructions) to done - // in Run() before rendering hand "false" \TODO avant de rendre la main "false" - - static - bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); - // call this to add externally (**) - // a new function used by the program CBoT - - static - bool DefineNum(const char* name, long val); - - bool SaveState(FILE* pf); - // backup the execution status in the file - // the file must have been opened with the fopen call this dll (\TODO this library??) - // if the system crashes - bool RestoreState(FILE* pf); - // restores the state of execution from file - // the compiled program must obviously be the same - - bool GetPosition(const char* name, int& start, int& stop, - CBotGet modestart = GetPosExtern, - CBotGet modestop = GetPosBloc); - // gives the position of a routine in the original text - // the user can select the item to find from the beginning to the end - // see the above modes in CBotGet - - - CBotFunction* GetFunctions(); -}; - - /////////////////////////////////////////////////////////////////////////////// // routines for file management (* FILE) FILE* fOpen(const char* name, const char* mode); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 27485f85..23752d5d 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -17,9 +17,7 @@ * along with this program. If not, see http://gnu.org/licenses */ -////////////////////////////////////////////////////////////////////// -// database management of CBoT program - +// Modules inlcude #include "CBot.h" #include "CBotCall.h" @@ -27,8 +25,14 @@ #include "CBotClass.h" #include "CBotUtils.h" +#include "StringFunctions.cpp" + +// Local include + +// Global include #include +//////////////////////////////////////////////////////////////////////////////// CBotProgram::CBotProgram() { m_Prog = nullptr; @@ -41,6 +45,7 @@ CBotProgram::CBotProgram() m_Ident = 0; } +//////////////////////////////////////////////////////////////////////////////// CBotProgram::CBotProgram(CBotVar* pInstance) { m_Prog = nullptr; @@ -53,7 +58,7 @@ CBotProgram::CBotProgram(CBotVar* pInstance) m_Ident = 0; } - +//////////////////////////////////////////////////////////////////////////////// CBotProgram::~CBotProgram() { // delete m_pClass; @@ -70,7 +75,7 @@ CBotProgram::~CBotProgram() #endif } - +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, void* pUser ) { int error = 0; @@ -165,7 +170,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, return (m_Prog != nullptr); } - +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::Start(const char* name) { #if STACKMEM @@ -199,6 +204,7 @@ bool CBotProgram::Start(const char* name) return true; // we are ready for Run () } +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop) { CBotFunction* p = m_Prog; @@ -214,6 +220,7 @@ bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet m return true; } +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::Run(void* pUser, int timer) { bool ok; @@ -268,6 +275,7 @@ error: return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotProgram::Stop() { #if STACKMEM @@ -279,8 +287,7 @@ void CBotProgram::Stop() m_pRun = nullptr; } - - +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end) { FunctionName = nullptr; @@ -291,6 +298,7 @@ bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end) return true; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level) { FunctionName = nullptr; @@ -299,26 +307,31 @@ CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level) return m_pStack->GetStackVars(FunctionName, level); } +//////////////////////////////////////////////////////////////////////////////// void CBotProgram::SetTimer(int n) { CBotStack::SetTimer( n ); } +//////////////////////////////////////////////////////////////////////////////// int CBotProgram::GetError() { return m_ErrorCode; } +//////////////////////////////////////////////////////////////////////////////// void CBotProgram::SetIdent(long n) { m_Ident = n; } +//////////////////////////////////////////////////////////////////////////////// long CBotProgram::GetIdent() { return m_Ident; } +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::GetError(int& code, int& start, int& end) { code = m_ErrorCode; @@ -327,6 +340,7 @@ bool CBotProgram::GetError(int& code, int& start, int& end) return code > 0; } +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) { code = m_ErrorCode; @@ -336,6 +350,7 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) return code > 0; } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotProgram::GetErrorText(int code) { CBotString TextError; @@ -350,12 +365,13 @@ CBotString CBotProgram::GetErrorText(int code) return TextError; } - +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotProgram::GetFunctions() { return m_Prog; } +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::AddFunction(const char* name, bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) @@ -364,7 +380,7 @@ bool CBotProgram::AddFunction(const char* name, return CBotCall::AddFunction(name, rExec, rCompile); } - +//////////////////////////////////////////////////////////////////////////////// bool WriteWord(FILE* pf, unsigned short w) { size_t lg; @@ -374,6 +390,7 @@ bool WriteWord(FILE* pf, unsigned short w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool ReadWord(FILE* pf, unsigned short& w) { size_t lg; @@ -383,6 +400,7 @@ bool ReadWord(FILE* pf, unsigned short& w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool WriteFloat(FILE* pf, float w) { size_t lg; @@ -392,6 +410,7 @@ bool WriteFloat(FILE* pf, float w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool ReadFloat(FILE* pf, float& w) { size_t lg; @@ -401,6 +420,7 @@ bool ReadFloat(FILE* pf, float& w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool WriteLong(FILE* pf, long w) { size_t lg; @@ -410,6 +430,7 @@ bool WriteLong(FILE* pf, long w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool ReadLong(FILE* pf, long& w) { size_t lg; @@ -419,6 +440,7 @@ bool ReadLong(FILE* pf, long& w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// bool WriteString(FILE* pf, CBotString s) { size_t lg1, lg2; @@ -430,6 +452,7 @@ bool WriteString(FILE* pf, CBotString s) return (lg1 == lg2); } +//////////////////////////////////////////////////////////////////////////////// bool ReadString(FILE* pf, CBotString& s) { unsigned short w; @@ -445,6 +468,7 @@ bool ReadString(FILE* pf, CBotString& s) return (lg1 == lg2); } +//////////////////////////////////////////////////////////////////////////////// bool WriteType(FILE* pf, CBotTypResult type) { int typ = type.GetType(); @@ -464,6 +488,7 @@ bool WriteType(FILE* pf, CBotTypResult type) return true; } +//////////////////////////////////////////////////////////////////////////////// bool ReadType(FILE* pf, CBotTypResult& type) { unsigned short w, ww; @@ -494,13 +519,40 @@ bool ReadType(FILE* pf, CBotTypResult& type) return true; } +//////////////////////////////////////////////////////////////////////////////// +bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) +{ + if ( pVar == nullptr ) return TX_LOWPARAM; + int i = 0; + pVar = pVar->GetItemList(); + + while ( pVar != nullptr ) + { + i++; + pVar = pVar->GetNext(); + } + + pResult->SetValInt(i); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser ) +{ + if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( pVar->GetType() != CBotTypArrayPointer ) + return CBotTypResult( TX_BADPARAM ); + return CBotTypResult( CBotTypInt ); +} + +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::DefineNum(const char* name, long val) { return CBotToken::DefineNum(name, val); } - +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::SaveState(FILE* pf) { if (!WriteWord( pf, CBOTVERSION)) return false; @@ -519,7 +571,7 @@ bool CBotProgram::SaveState(FILE* pf) return true; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotProgram::RestoreState(FILE* pf) { unsigned short w; @@ -553,12 +605,43 @@ bool CBotProgram::RestoreState(FILE* pf) return true; } +//////////////////////////////////////////////////////////////////////////////// int CBotProgram::GetVersion() { return CBOTVERSION; } +//////////////////////////////////////////////////////////////////////////////// +void CBotProgram::Init() +{ + CBotToken::DefineNum("CBotErrZeroDiv", TX_DIVZERO); // division by zero + CBotToken::DefineNum("CBotErrNotInit", TX_NOTINIT); // uninitialized variable + CBotToken::DefineNum("CBotErrBadThrow", TX_BADTHROW); // throw a negative value + //CBotToken::DefineNum("CBotErrNoRetVal", 6003); // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P + CBotToken::DefineNum("CBotErrNoRun", TX_NORUN); // active Run () without a function // TODO: Is this actually a runtime error? + CBotToken::DefineNum("CBotErrUndefFunc", TX_NOCALL); // Calling a function that no longer exists + CBotToken::DefineNum("CBotErrUndefClass", TX_NOCLASS); // Class no longer exists + CBotToken::DefineNum("CBotErrNullPointer", TX_NULLPT); // Attempted to use a null pointer + CBotToken::DefineNum("CBotErrNan", TX_OPNAN); // Can't do operations on nan + CBotToken::DefineNum("CBotErrOutOfBounds", TX_OUTARRAY); // Attempted access out of bounds of an array + CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER); // Stack overflow + CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT); // Attempted to use deleted object + CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); + + InitStringFunctions(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotProgram::Free() +{ + CBotToken::Free() ; + CBotCall ::Free() ; + CBotClass::Free() ; +} + + +//////////////////////////////////////////////////////////////////////////////// CBotCallMethode::CBotCallMethode(const char* name, bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) @@ -570,6 +653,7 @@ CBotCallMethode::CBotCallMethode(const char* name, m_nFuncIdent = CBotVar::NextUniqNum(); } +//////////////////////////////////////////////////////////////////////////////// CBotCallMethode::~CBotCallMethode() { delete m_next; @@ -578,7 +662,7 @@ CBotCallMethode::~CBotCallMethode() // is acceptable by a call procedure name // and given parameters - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis, CBotVar** ppVar, CBotCStack* pStack, long& nIdent) @@ -607,17 +691,19 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis, return CBotTypResult(-1); } - +//////////////////////////////////////////////////////////////////////////////// CBotString CBotCallMethode::GetName() { return m_name; } +//////////////////////////////////////////////////////////////////////////////// CBotCallMethode* CBotCallMethode::Next() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// void CBotCallMethode::AddNext(CBotCallMethode* pt) { CBotCallMethode* p = this; @@ -626,7 +712,7 @@ void CBotCallMethode::AddNext(CBotCallMethode* pt) p->m_next = pt; } - +//////////////////////////////////////////////////////////////////////////////// int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pToken) { CBotCallMethode* pt = this; @@ -698,59 +784,3 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot return -1; } - -bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) -{ - if ( pVar == nullptr ) return TX_LOWPARAM; - - int i = 0; - pVar = pVar->GetItemList(); - - while ( pVar != nullptr ) - { - i++; - pVar = pVar->GetNext(); - } - - pResult->SetValInt(i); - return true; -} - -CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser ) -{ - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - if ( pVar->GetType() != CBotTypArrayPointer ) - return CBotTypResult( TX_BADPARAM ); - return CBotTypResult( CBotTypInt ); -} - - -// TODO: Refactor this - including .cpp files is bad -#include "StringFunctions.cpp" - -void CBotProgram::Init() -{ - CBotToken::DefineNum("CBotErrZeroDiv", TX_DIVZERO); // division by zero - CBotToken::DefineNum("CBotErrNotInit", TX_NOTINIT); // uninitialized variable - CBotToken::DefineNum("CBotErrBadThrow", TX_BADTHROW); // throw a negative value - //CBotToken::DefineNum("CBotErrNoRetVal", 6003); // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P - CBotToken::DefineNum("CBotErrNoRun", TX_NORUN); // active Run () without a function // TODO: Is this actually a runtime error? - CBotToken::DefineNum("CBotErrUndefFunc", TX_NOCALL); // Calling a function that no longer exists - CBotToken::DefineNum("CBotErrUndefClass", TX_NOCLASS); // Class no longer exists - CBotToken::DefineNum("CBotErrNullPointer", TX_NULLPT); // Attempted to use a null pointer - CBotToken::DefineNum("CBotErrNan", TX_OPNAN); // Can't do operations on nan - CBotToken::DefineNum("CBotErrOutOfBounds", TX_OUTARRAY); // Attempted access out of bounds of an array - CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER); // Stack overflow - CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT); // Attempted to use deleted object - - CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); - - InitStringFunctions(); -} - -void CBotProgram::Free() -{ - CBotToken::Free() ; - CBotCall ::Free() ; - CBotClass::Free() ; -} diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h new file mode 100644 index 00000000..02aa5372 --- /dev/null +++ b/src/CBot/CBotProgram.h @@ -0,0 +1,260 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + + +/*! + * \brief The CBotProgram class Main class managing CBot program. + */ +class CBotProgram +{ +public: + + /*! + * \brief CBotProgram + */ + CBotProgram(); + + /*! + * \brief CBotProgram + * \param pInstance + */ + CBotProgram(CBotVar* pInstance); + + /*! + * \brief ~CBotProgram + */ + ~CBotProgram(); + + /*! + * \brief Init Initializes the module (defined keywords for errors) should + * be done once (and only one) at the beginning. + */ + static void Init(); + + /*! + * \brief Free Frees the static memory areas. + */ + static void Free(); + + /*! + * \brief GetVersion Gives the version of the library CBOT. + * \return + */ + static int GetVersion(); + + /*! + * \brief Compile compiles the program given in text. + * \param program + * \param ListFonctions Returns the names of functions declared as extern. + * \param pUser Can pass a pointer to routines defined by AddFunction. + * \return false if an error at compile. + * \see GetCompileError() to retrieve the error. + */ + bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = nullptr); + + /*! + * \brief SetIdent Associates an identifier with the instance CBotProgram. + * \param n + */ + void SetIdent(long n); + + /*! + * \brief GetIdent Gives the identifier. + * \return + */ + long GetIdent(); + + /*! + * \brief GetError + * \return + */ + int GetError(); + + /*! + * \brief GetError + * \param code + * \param start + * \param end + * \return + */ + bool GetError(int& code, int& start, int& end); + + /*! + * \brief GetError + * \param code + * \param start Delimits the start block where the error occured. + * \param end Delimits the end block where the error occured. + * \param pProg Lets you know what "module" has produced runtime error. + * \return If true gives the error found in the compilation or execution. + */ + bool GetError(int& code, int& start, int& end, CBotProgram* &pProg); + + /*! + * \brief GetErrorText + * \param code + * \return + */ + static CBotString GetErrorText(int code); + + /*! + * \brief Start Defines what function should be executed. The program does + * nothing, we must call Run () for this. + * \param name + * \return false if the funtion name is not found + */ + bool Start(const char* name); + + /*! + * \brief Run Executes the program. + * \param pUser + * \param timer timer = 0 allows to advance step by step. + * \return false if the program was suspended, true if the program ended + * with or without error. + */ + bool Run(void* pUser = nullptr, int timer = -1); + + /*! + * \brief GetRunPos Gives the position in the executing program + * \param FunctionName is a pointer made to the name of the function + * \param start start and end position in the text of the token processing + * \param end + * \return false if it is not running (program completion) + */ + bool GetRunPos(const char* &FunctionName, int &start, int &end); + + /*! + * \brief GetStackVars provides the pointer to the variables on the + * execution stack level is an input parameter, 0 for the last level, -1, + * -2, etc. for the other levels the return value (CBotVar *) is a variable. + * that can be processed as the list of parameters received by a routine + * list (or nullptr) + * \param FunctionName gives the name of the function where are these + * variables. FunctionName == nullptr means that is more in a program + * (depending on level) + * \param level + * \return + */ + CBotVar* GetStackVars(const char* &FunctionName, int level); + + /*! + * \brief Stop stops execution of the program therefore quits "suspend" mode + */ + void Stop(); + + /*! + * \brief SetTimer defines the number of steps (parts of instructions) to + * done in Run() before rendering hand "false" + * \TODO avant de rendre la main "false" + * \param n + */ + static void SetTimer(int n); + // + // + + /*! + * \brief AddFunction Call this to add externally (**) a new function used + * by the program CBoT. + * \param name + * \param rExec + * \param rCompile + * \return + */ + static bool AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + + /*! + * \brief DefineNum + * \param name + * \param val + * \return + */ + static bool DefineNum(const char* name, long val); + + /*! + * \brief SaveState Backup the execution status in the file the file must + * have been opened with the fopen call this dll (\TODO this library??) + * if the system crashes + * \param pf + * \return + */ + bool SaveState(FILE* pf); + + /*! + * \brief RestoreState Restores the state of execution from file the + * compiled program must obviously be the same. + * \param pf + * \return + */ + bool RestoreState(FILE* pf); + + /*! + * \brief GetPosition Gives the position of a routine in the original text + * the user can select the item to find from the beginning to the end + * see the above modes in CBotGet. + * \param name + * \param start + * \param stop + * \param modestart + * \param modestop + * \return + */ + bool GetPosition(const char* name, int& start, int& stop, + CBotGet modestart = GetPosExtern, + CBotGet modestop = GetPosBloc); + + /*! + * \brief GetFunctions + * \return + */ + CBotFunction* GetFunctions(); + + /*! + * \brief m_bCompileClass + */ + bool m_bCompileClass; + +private: + + //! The user-defined functions. + CBotFunction* m_Prog; + //! The basic function for the execution. + CBotFunction* m_pRun; + //! Classes defined in this part. + CBotClass* m_pClass; + //! Execution stack. + CBotStack* m_pStack; + //! Instance of the parent class. + CBotVar* m_pInstance; + friend class CBotFunction; + + int m_ErrorCode; + int m_ErrorStart; + int m_ErrorEnd; + //! Associated identifier. + long m_Ident; +}; diff --git a/src/script/script.h b/src/script/script.h index d57d2711..d4a42eb7 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -24,7 +24,9 @@ #pragma once +// TODO replace by CBot.h #include "CBot/CBotDll.h" +#include "CBot/CBotProgram.h" #include #include From 4712e0ef6a1d3512e3ac0097e325b3d97a879422 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 18:31:57 +0100 Subject: [PATCH 105/360] Moving CBotFunction class in its own header and source files. --- src/CBot/CBot.h | 67 ----- src/CBot/CBotClass.cpp | 1 + src/CBot/{ => CBotInstr}/CBotFunction.cpp | 73 +++--- src/CBot/CBotInstr/CBotFunction.h | 282 ++++++++++++++++++++++ src/CBot/CBotProgram.cpp | 2 + src/CBot/CBotStack.cpp | 2 + src/CBot/CMakeLists.txt | 2 +- 7 files changed, 331 insertions(+), 98 deletions(-) rename src/CBot/{ => CBotInstr}/CBotFunction.cpp (93%) create mode 100644 src/CBot/CBotInstr/CBotFunction.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e98a1c6c..33efc71f 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -550,70 +550,3 @@ public: CBotString GetParamString(); }; - - -// a function declaration - -class CBotFunction : CBotInstr -{ -private: - // management of list of (static) public functions - static - CBotFunction* m_listPublic; - CBotFunction* m_nextpublic; - CBotFunction* m_prevpublic; - friend class CBotCStack; -// long m_nThisIdent; - long m_nFuncIdent; - bool m_bSynchro; // synchronized method? - -private: - CBotDefParam* m_Param; // parameter list - CBotInstr* m_Block; // the instruction block - CBotFunction* m_next; - CBotToken m_retToken; // if returns CBotTypClass - CBotTypResult m_retTyp; // complete type of the result - - bool m_bPublic; // public function - bool m_bExtern; // extern function - CBotString m_MasterClass; // name of the class we derive - CBotProgram* m_pProg; - friend class CBotProgram; - friend class CBotClass; - - CBotToken m_extern; // for the position of the word "extern" - CBotToken m_openpar; - CBotToken m_closepar; - CBotToken m_openblk; - CBotToken m_closeblk; -public: - CBotFunction(); - ~CBotFunction(); - static - CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, bool bLocal = true); - static - CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass); - bool Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr); - void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr); - - void AddNext(CBotFunction* p); - CBotTypResult CompileCall(const char* name, CBotVar** ppVars, long& nIdent); - CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic = true); - - int DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken); - void RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack); - int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass); - void RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass); - bool CheckParam(CBotDefParam* pParam); - - static - void AddPublic(CBotFunction* pfunc); - - CBotString GetName(); - CBotString GetParams(); - bool IsPublic(); - bool IsExtern(); - CBotFunction* Next(); - - bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop); -}; diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 9c18f2c9..f37d55c5 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -23,6 +23,7 @@ #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotTwoOpExpr.h" +#include "CBotInstr/CBotFunction.h" #include "CBotCall.h" diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp similarity index 93% rename from src/CBot/CBotFunction.cpp rename to src/CBot/CBotInstr/CBotFunction.cpp index 61a98870..61428da4 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -17,9 +17,9 @@ * along with this program. If not, see http://gnu.org/licenses */ -/////////////////////////////////////////////////////////////////////// -// compilation of various functions declared by the user -// + +// Modules inlcude +#include "CBotFunction.h" #include "CBot.h" @@ -32,12 +32,13 @@ #include "CBotStack.h" #include "CBotClass.h" +// Local include + +// Global include #include -// various constructors / destructors -// \TODO translation:to liberate all according to esteblished tree -// pour libérer tout selon l'arbre établi +//////////////////////////////////////////////////////////////////////////////// CBotFunction::CBotFunction() { m_Param = nullptr; // empty parameter list @@ -53,8 +54,10 @@ CBotFunction::CBotFunction() m_bSynchro = false; } +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::m_listPublic = nullptr; +//////////////////////////////////////////////////////////////////////////////// CBotFunction::~CBotFunction() { delete m_Param; // empty parameter list @@ -80,16 +83,19 @@ CBotFunction::~CBotFunction() } } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::IsPublic() { return m_bPublic; } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::IsExtern() { return m_bExtern; } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop) { start = m_extern.GetStart(); @@ -131,7 +137,7 @@ bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet return true; } - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) { while ( IsOfType( p, ID_OPBRK ) ) @@ -146,6 +152,7 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) return type; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) { CBotClass* pClass = nullptr; @@ -183,9 +190,7 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) return CBotTypResult( -1 ); } -// compiles a new function -// bLocal allows of the declaration of parameters on the same level -// as the elements belonging to the class for methods +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal) { CBotToken* pp; @@ -298,7 +303,7 @@ bad: return pStack->ReturnFunc(nullptr, pStk); } -// pre-compile a new function +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass) { CBotFunction* func = new CBotFunction(); @@ -385,6 +390,7 @@ bad: static int xx = 0; #endif +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { CBotStack* pile = pj->AddStack(this, 2); // one end of stack local to this function @@ -434,7 +440,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) return pj->Return(pile); } - +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { CBotStack* pile = pj->RestoreStack(this); // one end of stack local to this function @@ -463,6 +469,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst m_Block->RestoreState(pile2, true); } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddNext(CBotFunction* p) { CBotFunction* pp = this; @@ -471,7 +478,7 @@ void CBotFunction::AddNext(CBotFunction* p) pp->m_next = p; } - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long& nIdent) { nIdent = 0; @@ -482,10 +489,7 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long return type; } - -// is a function according to its unique identifier -// if the identifier is not found, looking by name and parameters - +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic) { TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name @@ -638,9 +642,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB return nullptr; } - -// fait un appel à une fonction - +//////////////////////////////////////////////////////////////////////////////// int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) { CBotTypResult type; @@ -710,6 +712,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS return -1; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack) { CBotTypResult type; @@ -766,11 +769,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, } } - - -// makes call of a method -// note: this is already on the stack, the pointer pThis is just to simplify - +//////////////////////////////////////////////////////////////////////////////// int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass) { CBotTypResult type; @@ -851,6 +850,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar return -1; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass) { CBotTypResult type; @@ -883,7 +883,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, C } } -// see if the "signature" of parameters is identical +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::CheckParam(CBotDefParam* pParam) { CBotDefParam* pp = m_Param; @@ -898,11 +898,13 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam) return ( pp == nullptr && pParam == nullptr ); } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotFunction::GetName() { return m_token.GetString(); } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotFunction::GetParams() { if ( m_Param == nullptr ) return CBotString("()"); @@ -921,11 +923,13 @@ CBotString CBotFunction::GetParams() return params; } +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Next() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddPublic(CBotFunction* func) { if ( m_listPublic != nullptr ) @@ -941,19 +945,20 @@ void CBotFunction::AddPublic(CBotFunction* func) ///////////////////////////////////////////////////////////////////////// // management of parameters - +//////////////////////////////////////////////////////////////////////////////// CBotDefParam::CBotDefParam() { m_next = nullptr; m_nIdent = 0; } +//////////////////////////////////////////////////////////////////////////////// CBotDefParam::~CBotDefParam() { delete m_next; } - +//////////////////////////////////////////////////////////////////////////////// // compiles a list of parameters CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) { @@ -1014,6 +1019,7 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// void CBotDefParam::AddNext(CBotDefParam* p) { CBotDefParam* pp = this; @@ -1022,7 +1028,7 @@ void CBotDefParam::AddNext(CBotDefParam* p) pp->m_next = p; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) { int i = 0; @@ -1072,6 +1078,7 @@ bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) { // int i = 0; @@ -1086,21 +1093,25 @@ void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) } } +//////////////////////////////////////////////////////////////////////////////// int CBotDefParam::GetType() { return m_type.GetType(); } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotDefParam::GetTypResult() { return m_type; } +//////////////////////////////////////////////////////////////////////////////// CBotDefParam* CBotDefParam::GetNext() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotDefParam::GetParamString() { CBotString param; @@ -1118,6 +1129,7 @@ CBotString CBotDefParam::GetParamString() // pre-compile a new class // analysis is complete except the body of routines +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_PUBLIC) ) @@ -1173,6 +1185,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) { bool bStatic = false; @@ -1376,7 +1389,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) return pStack->IsOk(); } - +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h new file mode 100644 index 00000000..486ffff8 --- /dev/null +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -0,0 +1,282 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotFunction class A function declaration. Compilation of various + * functions declared by the user + */ +class CBotFunction : public CBotInstr +{ +public: + + /*! + * \brief CBotFunction + */ + CBotFunction(); + + /*! + * \brief ~CBotFunction + */ + ~CBotFunction(); + + /*! + * \brief Compile Compiles a new function + * \param p + * \param pStack + * \param pFunc + * \param bLocal allows of the declaration of parameters on the same level + * as the elements belonging to the class for methods. + * \return + */ + static CBotFunction* Compile(CBotToken* &p, + CBotCStack* pStack, + CBotFunction* pFunc, + bool bLocal = true); + + /*! + * \brief Compile1 Pre-compile a new function. + * \param p + * \param pStack + * \param pClass + * \return + */ + static CBotFunction* Compile1(CBotToken* &p, + CBotCStack* pStack, + CBotClass* pClass); + + /*! + * \brief Execute + * \param ppVars + * \param pj + * \param pInstance + * \return + */ + bool Execute(CBotVar** ppVars, + CBotStack* &pj, + CBotVar* pInstance = nullptr); + + /*! + * \brief RestoreState + * \param ppVars + * \param pj + * \param pInstance + */ + void RestoreState(CBotVar** ppVars, + CBotStack* &pj, + CBotVar* pInstance = nullptr); + + /*! + * \brief AddNext + * \param p + */ + void AddNext(CBotFunction* p); + + /*! + * \brief CompileCall + * \param name + * \param ppVars + * \param nIdent + * \return + */ + CBotTypResult CompileCall(const char* name, + CBotVar** ppVars, + long& nIdent); + + /*! + * \brief FindLocalOrPublic Is a function according to its unique identifier + * if the identifier is not found, looking by name and parameters. + * \param nIdent + * \param name + * \param ppVars + * \param TypeOrError + * \param bPublic + * \return + */ + CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, + CBotVar** ppVars, + CBotTypResult& TypeOrError, + bool bPublic = true); + + /*! + * \brief DoCall Fait un appel à une fonction. + * \param nIdent + * \param name + * \param ppVars + * \param pStack + * \param pToken + * \return + */ + + int DoCall(long& nIdent, + const char* name, + CBotVar** ppVars, + CBotStack* pStack, + CBotToken* pToken); + + /*! + * \brief RestoreCall + * \param nIdent + * \param name + * \param ppVars + * \param pStack + */ + void RestoreCall(long& nIdent, + const char* name, + CBotVar** ppVars, + CBotStack* pStack); + + /*! + * \brief DoCall Makes call of a method note: this is already on the stack, + * the pointer pThis is just to simplify. + * \param nIdent + * \param name + * \param pThis + * \param ppVars + * \param pStack + * \param pToken + * \param pClass + * \return + */ + int DoCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotStack* pStack, + CBotToken* pToken, + CBotClass* pClass); + + /*! + * \brief RestoreCall + * \param nIdent + * \param name + * \param pThis + * \param ppVars + * \param pStack + * \param pClass + */ + void RestoreCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotStack* pStack, + CBotClass* pClass); + + /*! + * \brief CheckParam See if the "signature" of parameters is identical. + * \param pParam + * \return + */ + bool CheckParam(CBotDefParam* pParam); + + /*! + * \brief AddPublic + * \param pfunc + */ + static void AddPublic(CBotFunction* pfunc); + + /*! + * \brief GetName + * \return + */ + CBotString GetName(); + + /*! + * \brief GetParams + * \return + */ + CBotString GetParams(); + + /*! + * \brief IsPublic + * \return + */ + bool IsPublic(); + + /*! + * \brief IsExtern + * \return + */ + bool IsExtern(); + + /*! + * \brief Next + * \return + */ + CBotFunction* Next(); + + /*! + * \brief GetPosition + * \param start + * \param stop + * \param modestart + * \param modestop + * \return + */ + bool GetPosition(int& start, int& stop, + CBotGet modestart, + CBotGet modestop); + +private: + CBotFunction* m_nextpublic; + CBotFunction* m_prevpublic; + long m_nFuncIdent; + //! Synchronized method. + bool m_bSynchro; + + //! Parameter list. + CBotDefParam* m_Param; + //! The instruction block. + CBotInstr* m_Block; + CBotFunction* m_next; + //! If returns CBotTypClass. + CBotToken m_retToken; + //! Complete type of the result. + CBotTypResult m_retTyp; + //! Public function. + bool m_bPublic; + //! Extern function. + bool m_bExtern; + //! Name of the class we derive. + CBotString m_MasterClass; + CBotProgram* m_pProg; + //! For the position of the word "extern". + CBotToken m_extern; + CBotToken m_openpar; + CBotToken m_closepar; + CBotToken m_openblk; + CBotToken m_closeblk; + + //! Management of list of (static) public functions. + static CBotFunction* m_listPublic; + + friend class CBotProgram; + friend class CBotClass; + friend class CBotCStack; + +}; diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 23752d5d..8e492bac 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -25,6 +25,8 @@ #include "CBotClass.h" #include "CBotUtils.h" +#include "CBotInstr/CBotFunction.h" + #include "StringFunctions.cpp" // Local include diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 0997f468..0a767135 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -21,6 +21,8 @@ #include "CBotStack.h" #include "CBotCall.h" +#include "CBotInstr/CBotFunction.h" + // Local include // Global include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 5bb6ad70..7aee901b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,7 +1,6 @@ set(SOURCES CBot.cpp CBotClass.cpp - CBotFunction.cpp CBotProgram.cpp CBotStack.cpp CBotString.cpp @@ -53,6 +52,7 @@ set(SOURCES CBotInstr/CBotListArray.cpp CBotInstr/CBotInstArray.cpp CBotInstr/CBotInt.cpp + CBotInstr/CBotFunction.cpp CBotVar/CBotVarArray.cpp ) From 0a1b7da2a80aaaf1fe31174371da746ccde51a7e Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 18:40:16 +0100 Subject: [PATCH 106/360] Moving CBotClass functions into CBotClass.cpp. Moving gloable function used by CBotClass and CBotFunction into CBotUtils.cpp. --- src/CBot/CBotClass.cpp | 313 +++++++++++++++++++++++ src/CBot/CBotInstr/CBotFunction.cpp | 370 +--------------------------- src/CBot/CBotUtils.cpp | 57 +++++ src/CBot/CBotUtils.h | 17 ++ 4 files changed, 389 insertions(+), 368 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index f37d55c5..d2d03e92 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -24,8 +24,13 @@ #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotFunction.h" +#include "CBotInstr/CBotExpression.h" +#include "CBotInstr/CBotListArray.h" +#include "CBotInstr/CBotEmpty.h" #include "CBotCall.h" +#include "CBotStack.h" +#include "CBotUtils.h" // Local include @@ -519,3 +524,311 @@ bool CBotClass::CheckCall(CBotToken* &pToken, return false; } + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) +{ + if ( !IsOfType(p, ID_PUBLIC) ) + { + pStack->SetError(TX_NOPUBLIC, p); + return nullptr; + } + + if ( !IsOfType(p, ID_CLASS) ) return nullptr; + + CBotString name = p->GetString(); + + CBotClass* pOld = CBotClass::Find(name); + if ( pOld != nullptr && pOld->m_IsDef ) + { + pStack->SetError( TX_REDEFCLASS, p ); + return nullptr; + } + + // a name of the class is there? + if (IsOfType(p, TokenTypVar)) + { + CBotClass* pPapa = nullptr; + if ( IsOfType( p, ID_EXTENDS ) ) + { + CBotString name = p->GetString(); + pPapa = CBotClass::Find(name); + + if (!IsOfType(p, TokenTypVar) || pPapa == nullptr ) + { + pStack->SetError( TX_NOCLASS, p ); + return nullptr; + } + } + CBotClass* classe = (pOld == nullptr) ? new CBotClass(name, pPapa) : pOld; + classe->Purge(); // emptythe old definitions + classe->m_IsDef = false; // current definition + + if ( !IsOfType( p, ID_OPBLK) ) + { + pStack->SetError(TX_OPENBLK, p); + return nullptr; + } + + while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) ) + { + classe->CompileDefItem(p, pStack, false); + } + + if (pStack->IsOk()) return classe; + } + pStack->SetError(TX_ENDOF, p); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) +{ + bool bStatic = false; + int mProtect = PR_PUBLIC; + bool bSynchro = false; + + while (IsOfType(p, ID_SEP)) ; + + CBotTypResult type( -1 ); + + if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true; + CBotToken* pBase = p; + + if ( IsOfType(p, ID_STATIC) ) bStatic = true; + if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC; + if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE; + if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT; + if ( IsOfType(p, ID_STATIC) ) bStatic = true; + +// CBotClass* pClass = nullptr; + type = TypeParam(p, pStack); // type of the result + + if ( type.Eq(-1) ) + { + pStack->SetError(TX_NOTYP, p); + return false; + } + + while (pStack->IsOk()) + { + CBotToken* pp = p; + IsOfType(p, ID_NOT); // skips ~ eventual (destructor) + + if (IsOfType(p, TokenTypVar)) + { + CBotInstr* limites = nullptr; + while ( IsOfType( p, ID_OPBRK ) ) // a table? + { + CBotInstr* i = nullptr; + + if ( p->GetType() != ID_CLBRK ) + i = CBotExpression::Compile( p, pStack ); // expression for the value + else + i = new CBotEmpty(); // special if not a formula + + type = CBotTypResult(CBotTypArrayPointer, type); + + if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) ) + { + pStack->SetError(TX_CLBRK, p->GetStart()); + return false; + } + +/* CBotVar* pv = pStack->GetVar(); + if ( pv->GetType()>= CBotTypBoolean ) + { + pStack->SetError(TX_BADTYPE, p->GetStart()); + return false; + }*/ + + if (limites == nullptr) limites = i; + else limites->AddNext3(i); + } + + if ( p->GetType() == ID_OPENPAR ) + { + if ( !bSecond ) + { + p = pBase; + CBotFunction* f = + CBotFunction::Compile1(p, pStack, this); + + if ( f == nullptr ) return false; + + if (m_pMethod == nullptr) m_pMethod = f; + else m_pMethod->AddNext(f); + } + else + { + // return a method precompiled in pass 1 + CBotFunction* pf = m_pMethod; + CBotFunction* prev = nullptr; + while ( pf != nullptr ) + { + if (pf->GetName() == pp->GetString()) break; + prev = pf; + pf = pf->Next(); + } + + bool bConstructor = (pp->GetString() == GetName()); + CBotCStack* pile = pStack->TokenStack(nullptr, true); + + // make "this" known + CBotToken TokenThis(CBotString("this"), CBotString()); + CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) ); + pThis->SetUniqNum(-2); + pile->AddVar(pThis); + + if ( m_pParent ) + { + // makes "super" known + CBotToken TokenSuper(CBotString("super"), CBotString()); + CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) ); + pThis->SetUniqNum(-3); + pile->AddVar(pThis); + } + +// int num = 1; + CBotClass* my = this; + while (my != nullptr) + { + // places a copy of variables of a class (this) on a stack + CBotVar* pv = my->m_pVar; + while (pv != nullptr) + { + CBotVar* pcopy = CBotVar::Create(pv); + CBotVar::InitType initType = CBotVar::InitType::UNDEF; + if (!bConstructor || pv->IsStatic()) + initType = CBotVar::InitType::DEF; + pcopy->SetInit(initType); + pcopy->SetUniqNum(pv->GetUniqNum()); + pile->AddVar(pcopy); + pv = pv->GetNext(); + } + my = my->m_pParent; + } + + // compiles a method + p = pBase; + CBotFunction* f = + CBotFunction::Compile(p, pile, nullptr/*, false*/); + + if ( f != nullptr ) + { + f->m_pProg = pStack->GetBotCall(); + f->m_bSynchro = bSynchro; + // replaces the element in the chain + f->m_next = pf->m_next; + pf->m_next = nullptr; + delete pf; + if (prev == nullptr) m_pMethod = f; + else prev->m_next = f; + } + pStack->Return(nullptr, pile); + } + + return pStack->IsOk(); + } + + // definition of an element + if (type.Eq(0)) + { + pStack->SetError(TX_ENDOF, p); + return false; + } + + CBotInstr* i = nullptr; + if ( IsOfType(p, ID_ASS ) ) + { + if ( type.Eq(CBotTypArrayPointer) ) + { + i = CBotListArray::Compile(p, pStack, type.GetTypElem()); + } + else + { + // it has an assignmet to calculate + i = CBotTwoOpExpr::Compile(p, pStack); + } + if ( !pStack->IsOk() ) return false; + } + + + if ( !bSecond ) + { + CBotVar* pv = CBotVar::Create(pp->GetString(), type); + pv -> SetStatic( bStatic ); + pv -> SetPrivate( mProtect ); + + AddItem( pv ); + + pv->m_InitExpr = i; + pv->m_LimExpr = limites; + + + if ( pv->IsStatic() && pv->m_InitExpr != nullptr ) + { + CBotStack* pile = CBotStack::FirstStack(); // independent stack + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer + pv->SetVal( pile->GetVar() ) ; + pile->Delete(); + } + } + else + delete i; + + if ( IsOfType(p, ID_COMMA) ) continue; + if ( IsOfType(p, ID_SEP) ) break; + } + pStack->SetError(TX_ENDOF, p); + } + return pStack->IsOk(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) +{ + if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; + if ( !IsOfType(p, ID_CLASS) ) return nullptr; + + CBotString name = p->GetString(); + + // a name for the class is there? + if (IsOfType(p, TokenTypVar)) + { + // the class was created by Compile1 + CBotClass* pOld = CBotClass::Find(name); + + if ( IsOfType( p, ID_EXTENDS ) ) + { + // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h + CBotString name = p->GetString(); + CBotClass* pPapa = CBotClass::Find(name); + + if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) + { + pStack->SetError( TX_NOCLASS, p ); + return nullptr; + } + pOld->m_pParent = pPapa; + } + else + { + if (pOld != nullptr) + { + pOld->m_pParent = nullptr; + } + } + IsOfType( p, ID_OPBLK); // necessarily + + while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) ) + { + pOld->CompileDefItem(p, pStack, true); + } + + pOld->m_IsDef = true; // complete definition + if (pStack->IsOk()) return pOld; + } + pStack->SetError(TX_ENDOF, p); + return nullptr; +} diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 61428da4..94df0e7a 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -32,6 +32,8 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotUtils.h" + // Local include // Global include @@ -137,59 +139,6 @@ bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) -{ - while ( IsOfType( p, ID_OPBRK ) ) - { - if ( !IsOfType( p, ID_CLBRK ) ) - { - pile->SetError(TX_CLBRK, p->GetStart()); - return CBotTypResult( -1 ); - } - type = CBotTypResult( CBotTypArrayPointer, type ); - } - return type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) -{ - CBotClass* pClass = nullptr; - - switch (p->GetType()) - { - case ID_INT: - p = p->GetNext(); - return ArrayType(p, pile, CBotTypResult( CBotTypInt )); - case ID_FLOAT: - p = p->GetNext(); - return ArrayType(p, pile, CBotTypResult( CBotTypFloat )); - case ID_BOOLEAN: - case ID_BOOL: - p = p->GetNext(); - return ArrayType(p, pile, CBotTypResult( CBotTypBoolean )); - case ID_STRING: - p = p->GetNext(); - return ArrayType(p, pile, CBotTypResult( CBotTypString )); - case ID_VOID: - p = p->GetNext(); - return CBotTypResult( 0 ); - - case TokenTypVar: - pClass = CBotClass::Find(p); - if ( pClass != nullptr) - { - p = p->GetNext(); - return ArrayType(p, pile, - pClass->IsIntrinsic() ? - CBotTypResult( CBotTypIntrinsic, pClass ) : - CBotTypResult( CBotTypPointer, pClass ) ); - } - } - return CBotTypResult( -1 ); -} - //////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal) { @@ -1122,318 +1071,3 @@ CBotString CBotDefParam::GetParamString() param += m_token.GetString(); return param; } - -////////////////////////////////////////////////////////////////////////////// -// statement of user classes - -// pre-compile a new class -// analysis is complete except the body of routines - -//////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) -{ - if ( !IsOfType(p, ID_PUBLIC) ) - { - pStack->SetError(TX_NOPUBLIC, p); - return nullptr; - } - - if ( !IsOfType(p, ID_CLASS) ) return nullptr; - - CBotString name = p->GetString(); - - CBotClass* pOld = CBotClass::Find(name); - if ( pOld != nullptr && pOld->m_IsDef ) - { - pStack->SetError( TX_REDEFCLASS, p ); - return nullptr; - } - - // a name of the class is there? - if (IsOfType(p, TokenTypVar)) - { - CBotClass* pPapa = nullptr; - if ( IsOfType( p, ID_EXTENDS ) ) - { - CBotString name = p->GetString(); - pPapa = CBotClass::Find(name); - - if (!IsOfType(p, TokenTypVar) || pPapa == nullptr ) - { - pStack->SetError( TX_NOCLASS, p ); - return nullptr; - } - } - CBotClass* classe = (pOld == nullptr) ? new CBotClass(name, pPapa) : pOld; - classe->Purge(); // emptythe old definitions - classe->m_IsDef = false; // current definition - - if ( !IsOfType( p, ID_OPBLK) ) - { - pStack->SetError(TX_OPENBLK, p); - return nullptr; - } - - while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) ) - { - classe->CompileDefItem(p, pStack, false); - } - - if (pStack->IsOk()) return classe; - } - pStack->SetError(TX_ENDOF, p); - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) -{ - bool bStatic = false; - int mProtect = PR_PUBLIC; - bool bSynchro = false; - - while (IsOfType(p, ID_SEP)) ; - - CBotTypResult type( -1 ); - - if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true; - CBotToken* pBase = p; - - if ( IsOfType(p, ID_STATIC) ) bStatic = true; - if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC; - if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE; - if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT; - if ( IsOfType(p, ID_STATIC) ) bStatic = true; - -// CBotClass* pClass = nullptr; - type = TypeParam(p, pStack); // type of the result - - if ( type.Eq(-1) ) - { - pStack->SetError(TX_NOTYP, p); - return false; - } - - while (pStack->IsOk()) - { - CBotToken* pp = p; - IsOfType(p, ID_NOT); // skips ~ eventual (destructor) - - if (IsOfType(p, TokenTypVar)) - { - CBotInstr* limites = nullptr; - while ( IsOfType( p, ID_OPBRK ) ) // a table? - { - CBotInstr* i = nullptr; - - if ( p->GetType() != ID_CLBRK ) - i = CBotExpression::Compile( p, pStack ); // expression for the value - else - i = new CBotEmpty(); // special if not a formula - - type = CBotTypResult(CBotTypArrayPointer, type); - - if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) ) - { - pStack->SetError(TX_CLBRK, p->GetStart()); - return false; - } - -/* CBotVar* pv = pStack->GetVar(); - if ( pv->GetType()>= CBotTypBoolean ) - { - pStack->SetError(TX_BADTYPE, p->GetStart()); - return false; - }*/ - - if (limites == nullptr) limites = i; - else limites->AddNext3(i); - } - - if ( p->GetType() == ID_OPENPAR ) - { - if ( !bSecond ) - { - p = pBase; - CBotFunction* f = - CBotFunction::Compile1(p, pStack, this); - - if ( f == nullptr ) return false; - - if (m_pMethod == nullptr) m_pMethod = f; - else m_pMethod->AddNext(f); - } - else - { - // return a method precompiled in pass 1 - CBotFunction* pf = m_pMethod; - CBotFunction* prev = nullptr; - while ( pf != nullptr ) - { - if (pf->GetName() == pp->GetString()) break; - prev = pf; - pf = pf->Next(); - } - - bool bConstructor = (pp->GetString() == GetName()); - CBotCStack* pile = pStack->TokenStack(nullptr, true); - - // make "this" known - CBotToken TokenThis(CBotString("this"), CBotString()); - CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) ); - pThis->SetUniqNum(-2); - pile->AddVar(pThis); - - if ( m_pParent ) - { - // makes "super" known - CBotToken TokenSuper(CBotString("super"), CBotString()); - CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) ); - pThis->SetUniqNum(-3); - pile->AddVar(pThis); - } - -// int num = 1; - CBotClass* my = this; - while (my != nullptr) - { - // places a copy of variables of a class (this) on a stack - CBotVar* pv = my->m_pVar; - while (pv != nullptr) - { - CBotVar* pcopy = CBotVar::Create(pv); - CBotVar::InitType initType = CBotVar::InitType::UNDEF; - if (!bConstructor || pv->IsStatic()) - initType = CBotVar::InitType::DEF; - pcopy->SetInit(initType); - pcopy->SetUniqNum(pv->GetUniqNum()); - pile->AddVar(pcopy); - pv = pv->GetNext(); - } - my = my->m_pParent; - } - - // compiles a method - p = pBase; - CBotFunction* f = - CBotFunction::Compile(p, pile, nullptr/*, false*/); - - if ( f != nullptr ) - { - f->m_pProg = pStack->GetBotCall(); - f->m_bSynchro = bSynchro; - // replaces the element in the chain - f->m_next = pf->m_next; - pf->m_next = nullptr; - delete pf; - if (prev == nullptr) m_pMethod = f; - else prev->m_next = f; - } - pStack->Return(nullptr, pile); - } - - return pStack->IsOk(); - } - - // definition of an element - if (type.Eq(0)) - { - pStack->SetError(TX_ENDOF, p); - return false; - } - - CBotInstr* i = nullptr; - if ( IsOfType(p, ID_ASS ) ) - { - if ( type.Eq(CBotTypArrayPointer) ) - { - i = CBotListArray::Compile(p, pStack, type.GetTypElem()); - } - else - { - // it has an assignmet to calculate - i = CBotTwoOpExpr::Compile(p, pStack); - } - if ( !pStack->IsOk() ) return false; - } - - - if ( !bSecond ) - { - CBotVar* pv = CBotVar::Create(pp->GetString(), type); - pv -> SetStatic( bStatic ); - pv -> SetPrivate( mProtect ); - - AddItem( pv ); - - pv->m_InitExpr = i; - pv->m_LimExpr = limites; - - - if ( pv->IsStatic() && pv->m_InitExpr != nullptr ) - { - CBotStack* pile = CBotStack::FirstStack(); // independent stack - while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer - pv->SetVal( pile->GetVar() ) ; - pile->Delete(); - } - } - else - delete i; - - if ( IsOfType(p, ID_COMMA) ) continue; - if ( IsOfType(p, ID_SEP) ) break; - } - pStack->SetError(TX_ENDOF, p); - } - return pStack->IsOk(); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) -{ - if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; - if ( !IsOfType(p, ID_CLASS) ) return nullptr; - - CBotString name = p->GetString(); - - // a name for the class is there? - if (IsOfType(p, TokenTypVar)) - { - // the class was created by Compile1 - CBotClass* pOld = CBotClass::Find(name); - - if ( IsOfType( p, ID_EXTENDS ) ) - { - // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h - CBotString name = p->GetString(); - CBotClass* pPapa = CBotClass::Find(name); - - if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) - { - pStack->SetError( TX_NOCLASS, p ); - return nullptr; - } - pOld->m_pParent = pPapa; - } - else - { - if (pOld != nullptr) - { - pOld->m_pParent = nullptr; - } - } - IsOfType( p, ID_OPBLK); // necessarily - - while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) ) - { - pOld->CompileDefItem(p, pStack, true); - } - - pOld->m_IsDef = true; // complete definition - if (pStack->IsOk()) return pOld; - } - pStack->SetError(TX_ENDOF, p); - return nullptr; -} - diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 5aba61c2..bb2b9409 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -20,6 +20,10 @@ // Modules inlcude #include "CBotUtils.h" +#include "CBotToken.h" +#include "CBotClass.h" +#include "CBotStack.h" + // Local include // Global include @@ -48,3 +52,56 @@ CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal) } return pVar; } + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) +{ + CBotClass* pClass = nullptr; + + switch (p->GetType()) + { + case ID_INT: + p = p->GetNext(); + return ArrayType(p, pile, CBotTypResult( CBotTypInt )); + case ID_FLOAT: + p = p->GetNext(); + return ArrayType(p, pile, CBotTypResult( CBotTypFloat )); + case ID_BOOLEAN: + case ID_BOOL: + p = p->GetNext(); + return ArrayType(p, pile, CBotTypResult( CBotTypBoolean )); + case ID_STRING: + p = p->GetNext(); + return ArrayType(p, pile, CBotTypResult( CBotTypString )); + case ID_VOID: + p = p->GetNext(); + return CBotTypResult( 0 ); + + case TokenTypVar: + pClass = CBotClass::Find(p); + if ( pClass != nullptr) + { + p = p->GetNext(); + return ArrayType(p, pile, + pClass->IsIntrinsic() ? + CBotTypResult( CBotTypIntrinsic, pClass ) : + CBotTypResult( CBotTypPointer, pClass ) ); + } + } + return CBotTypResult( -1 ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) +{ + while ( IsOfType( p, ID_OPBRK ) ) + { + if ( !IsOfType( p, ID_CLBRK ) ) + { + pile->SetError(TX_CLBRK, p->GetStart()); + return CBotTypResult( -1 ); + } + type = CBotTypResult( CBotTypArrayPointer, type ); + } + return type; +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index df8bb55d..9d452d85 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -34,3 +34,20 @@ * \return */ CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal=false); + +/*! + * \brief TypeParam + * \param p + * \param pile + * \return + */ +CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile); + +/*! + * \brief ArrayType + * \param p + * \param pile + * \param type + * \return + */ +CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type); From 6d340e80ab2197ca0850052a774e31c2a16e4a82 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 18:51:28 +0100 Subject: [PATCH 107/360] Moving CBotDefParam class in its own header and source files. --- src/CBot/CBot.h | 26 ---- src/CBot/CBotDefParam.cpp | 207 ++++++++++++++++++++++++++++ src/CBot/CBotDefParam.h | 115 ++++++++++++++++ src/CBot/CBotInstr/CBotFunction.cpp | 185 +------------------------ src/CBot/CMakeLists.txt | 1 + 5 files changed, 324 insertions(+), 210 deletions(-) create mode 100644 src/CBot/CBotDefParam.cpp create mode 100644 src/CBot/CBotDefParam.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 33efc71f..56e483c0 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -524,29 +524,3 @@ public: }; -// a list of parameters - -class CBotDefParam -{ -private: - CBotToken m_token; // name of the parameter - CBotString m_typename; // type name - CBotTypResult m_type; // type of paramteter - CBotDefParam* m_next; // next parameter - long m_nIdent; - -public: - CBotDefParam(); - ~CBotDefParam(); - static - CBotDefParam* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotVar** ppVars, CBotStack* &pj); - void RestoreState(CBotStack* &pj, bool bMain); - - void AddNext(CBotDefParam* p); - int GetType(); - CBotTypResult GetTypResult(); - CBotDefParam* GetNext(); - - CBotString GetParamString(); -}; diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp new file mode 100644 index 00000000..3a91f604 --- /dev/null +++ b/src/CBot/CBotDefParam.cpp @@ -0,0 +1,207 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotDefParam.h" + +#include "CBot.h" + +#include "CBotUtils.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotDefParam::CBotDefParam() +{ + m_next = nullptr; + m_nIdent = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotDefParam::~CBotDefParam() +{ + delete m_next; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) +{ + // mainly not pStack->TokenStack here + // declared variables must remain visible thereafter + + pStack->SetStartError(p->GetStart()); + + if (IsOfType(p, ID_OPENPAR)) + { + CBotDefParam* list = nullptr; + + while (!IsOfType(p, ID_CLOSEPAR)) + { + CBotDefParam* param = new CBotDefParam(); + if (list == nullptr) list = param; + else list->AddNext(param); // added to the list + +// CBotClass* pClass = nullptr;//= CBotClass::Find(p); + param->m_typename = p->GetString(); + CBotTypResult type = param->m_type = TypeParam(p, pStack); +// if ( type == CBotTypPointer ) type = CBotTypClass; // we must create a new object + + if (param->m_type.GetType() > 0) + { + CBotToken* pp = p; + param->m_token = *p; + if (pStack->IsOk() && IsOfType(p, TokenTypVar) ) + { + + // variable already declared? + if (pStack->CheckVarLocal(pp)) + { + pStack->SetError(TX_REDEFVAR, pp); + break; + } + + if ( type.Eq(CBotTypArrayPointer) ) type.SetType(CBotTypArrayBody); + CBotVar* var = CBotVar::Create(pp->GetString(), type); // creates the variable +// if ( pClass ) var->SetClass(pClass); + var->SetInit(CBotVar::InitType::IS_POINTER); // mark initialized + param->m_nIdent = CBotVar::NextUniqNum(); + var->SetUniqNum(param->m_nIdent); + pStack->AddVar(var); // place on the stack + + if (IsOfType(p, ID_COMMA) || p->GetType() == ID_CLOSEPAR) + continue; + } + pStack->SetError(TX_CLOSEPAR, p->GetStart()); + } + pStack->SetError(TX_NOTYP, p); + delete list; + return nullptr; + } + return list; + } + pStack->SetError(TX_OPENPAR, p->GetStart()); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotDefParam::AddNext(CBotDefParam* p) +{ + CBotDefParam* pp = this; + while (pp->m_next != nullptr) pp = pp->m_next; + + pp->m_next = p; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) +{ + int i = 0; + CBotDefParam* p = this; + + while ( p != nullptr ) + { + // creates a local variable on the stack + CBotVar* newvar = CBotVar::Create(p->m_token.GetString(), p->m_type); + + // serves to make the transformation of types: + if ( ppVars != nullptr && ppVars[i] != nullptr ) + { + switch (p->m_type.GetType()) + { + case CBotTypInt: + newvar->SetValInt(ppVars[i]->GetValInt()); + break; + case CBotTypFloat: + newvar->SetValFloat(ppVars[i]->GetValFloat()); + break; + case CBotTypString: + newvar->SetValString(ppVars[i]->GetValString()); + break; + case CBotTypBoolean: + newvar->SetValInt(ppVars[i]->GetValInt()); + break; + case CBotTypIntrinsic: + (static_cast(newvar))->Copy(ppVars[i], false); + break; + case CBotTypPointer: + case CBotTypArrayPointer: + { + newvar->SetPointer(ppVars[i]->GetPointer()); + } + break; + default: + assert(0); + } + } + newvar->SetUniqNum(p->m_nIdent); + pj->AddVar(newvar); // add a variable + p = p->m_next; + i++; + } + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) +{ +// int i = 0; + CBotDefParam* p = this; + + while ( p != nullptr ) + { + // creates a local variable on the stack + CBotVar* var = pj->FindVar(p->m_token.GetString()); + var->SetUniqNum(p->m_nIdent); + p = p->m_next; + } +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotDefParam::GetType() +{ + return m_type.GetType(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotDefParam::GetTypResult() +{ + return m_type; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotDefParam* CBotDefParam::GetNext() +{ + return m_next; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotDefParam::GetParamString() +{ + CBotString param; + + param = m_typename; + param += ' '; + + param += m_token.GetString(); + return param; +} diff --git a/src/CBot/CBotDefParam.h b/src/CBot/CBotDefParam.h new file mode 100644 index 00000000..705660e3 --- /dev/null +++ b/src/CBot/CBotDefParam.h @@ -0,0 +1,115 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" +#include "CBotToken.h" +#include "CBotStack.h" + +// Local include + +// Global include + +class CBotCStack; +class CBotStack; +class CBotVar; + +/*! + * \brief The CBotDefParam class A list of parameters. + */ +class CBotDefParam +{ +public: + + /*! + * \brief CBotDefParam + */ + CBotDefParam(); + + /*! + * \brief ~CBotDefParam + */ + ~CBotDefParam(); + + /*! + * \brief Compile Compiles a list of parameters. + * \param p + * \param pStack + * \return + */ + static CBotDefParam* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param ppVars + * \param pj + * \return + */ + bool Execute(CBotVar** ppVars, CBotStack* &pj); + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain); + + /*! + * \brief AddNext + * \param p + */ + void AddNext(CBotDefParam* p); + + /*! + * \brief GetType + * \return + */ + int GetType(); + + /*! + * \brief GetTypResult + * \return + */ + CBotTypResult GetTypResult(); + + /*! + * \brief GetNext + * \return + */ + CBotDefParam* GetNext(); + + /*! + * \brief GetParamString + * \return + */ + CBotString GetParamString(); + +private: + //! Name of the parameter. + CBotToken m_token; + //! Type name. + CBotString m_typename; + //! Type of paramteter. + CBotTypResult m_type; + //! Next parameter. + CBotDefParam* m_next; + long m_nIdent; +}; diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 94df0e7a..fd81a441 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -31,7 +31,7 @@ #include "CBotStack.h" #include "CBotClass.h" - +#include "CBotDefParam.h" #include "CBotUtils.h" // Local include @@ -888,186 +888,3 @@ void CBotFunction::AddPublic(CBotFunction* func) } m_listPublic = func; } - - - -///////////////////////////////////////////////////////////////////////// -// management of parameters - -//////////////////////////////////////////////////////////////////////////////// -CBotDefParam::CBotDefParam() -{ - m_next = nullptr; - m_nIdent = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotDefParam::~CBotDefParam() -{ - delete m_next; -} - -//////////////////////////////////////////////////////////////////////////////// -// compiles a list of parameters -CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) -{ - // mainly not pStack->TokenStack here - // declared variables must remain visible thereafter - - pStack->SetStartError(p->GetStart()); - - if (IsOfType(p, ID_OPENPAR)) - { - CBotDefParam* list = nullptr; - - while (!IsOfType(p, ID_CLOSEPAR)) - { - CBotDefParam* param = new CBotDefParam(); - if (list == nullptr) list = param; - else list->AddNext(param); // added to the list - -// CBotClass* pClass = nullptr;//= CBotClass::Find(p); - param->m_typename = p->GetString(); - CBotTypResult type = param->m_type = TypeParam(p, pStack); -// if ( type == CBotTypPointer ) type = CBotTypClass; // we must create a new object - - if (param->m_type.GetType() > 0) - { - CBotToken* pp = p; - param->m_token = *p; - if (pStack->IsOk() && IsOfType(p, TokenTypVar) ) - { - - // variable already declared? - if (pStack->CheckVarLocal(pp)) - { - pStack->SetError(TX_REDEFVAR, pp); - break; - } - - if ( type.Eq(CBotTypArrayPointer) ) type.SetType(CBotTypArrayBody); - CBotVar* var = CBotVar::Create(pp->GetString(), type); // creates the variable -// if ( pClass ) var->SetClass(pClass); - var->SetInit(CBotVar::InitType::IS_POINTER); // mark initialized - param->m_nIdent = CBotVar::NextUniqNum(); - var->SetUniqNum(param->m_nIdent); - pStack->AddVar(var); // place on the stack - - if (IsOfType(p, ID_COMMA) || p->GetType() == ID_CLOSEPAR) - continue; - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - } - pStack->SetError(TX_NOTYP, p); - delete list; - return nullptr; - } - return list; - } - pStack->SetError(TX_OPENPAR, p->GetStart()); - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotDefParam::AddNext(CBotDefParam* p) -{ - CBotDefParam* pp = this; - while (pp->m_next != nullptr) pp = pp->m_next; - - pp->m_next = p; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) -{ - int i = 0; - CBotDefParam* p = this; - - while ( p != nullptr ) - { - // creates a local variable on the stack - CBotVar* newvar = CBotVar::Create(p->m_token.GetString(), p->m_type); - - // serves to make the transformation of types: - if ( ppVars != nullptr && ppVars[i] != nullptr ) - { - switch (p->m_type.GetType()) - { - case CBotTypInt: - newvar->SetValInt(ppVars[i]->GetValInt()); - break; - case CBotTypFloat: - newvar->SetValFloat(ppVars[i]->GetValFloat()); - break; - case CBotTypString: - newvar->SetValString(ppVars[i]->GetValString()); - break; - case CBotTypBoolean: - newvar->SetValInt(ppVars[i]->GetValInt()); - break; - case CBotTypIntrinsic: - (static_cast(newvar))->Copy(ppVars[i], false); - break; - case CBotTypPointer: - case CBotTypArrayPointer: - { - newvar->SetPointer(ppVars[i]->GetPointer()); - } - break; - default: - assert(0); - } - } - newvar->SetUniqNum(p->m_nIdent); - pj->AddVar(newvar); // add a variable - p = p->m_next; - i++; - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) -{ -// int i = 0; - CBotDefParam* p = this; - - while ( p != nullptr ) - { - // creates a local variable on the stack - CBotVar* var = pj->FindVar(p->m_token.GetString()); - var->SetUniqNum(p->m_nIdent); - p = p->m_next; - } -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotDefParam::GetType() -{ - return m_type.GetType(); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotDefParam::GetTypResult() -{ - return m_type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotDefParam* CBotDefParam::GetNext() -{ - return m_next; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotString CBotDefParam::GetParamString() -{ - CBotString param; - - param = m_typename; - param += ' '; - - param += m_token.GetString(); - return param; -} diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 7aee901b..c2a953f6 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES CBotVar.cpp CBotCall.cpp CBotUtils.cpp + CBotDefParam.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp From 143eecd7918409af0b3e3b91545d5556bf68d1aa Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 18:59:15 +0100 Subject: [PATCH 108/360] Moving CBotCallMethode class in its own header and source files. --- src/CBot/CBot.h | 34 ------- src/CBot/CBotCallMethode.cpp | 179 +++++++++++++++++++++++++++++++++++ src/CBot/CBotCallMethode.h | 115 ++++++++++++++++++++++ src/CBot/CBotClass.cpp | 1 + src/CBot/CBotProgram.cpp | 145 ---------------------------- src/CBot/CMakeLists.txt | 1 + 6 files changed, 296 insertions(+), 179 deletions(-) create mode 100644 src/CBot/CBotCallMethode.cpp create mode 100644 src/CBot/CBotCallMethode.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 56e483c0..44b251be 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -490,37 +490,3 @@ extern float GetNumFloat( const char* p ); #if 0 extern void DEBUG( const char* text, int val, CBotStack* pile ); #endif - -/////////////////////////////////////////// -// class managing the methods declared by AddFunction on a class - -class CBotCallMethode -{ -private: - CBotString m_name; - bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - CBotTypResult - (*m_rComp) (CBotVar* pThis, CBotVar* &pVar); - CBotCallMethode* m_next; - friend class CBotClass; - long m_nFuncIdent; - -public: - CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); - ~CBotCallMethode(); - - CBotTypResult - CompileCall(const char* name, CBotVar* pThis, - CBotVar** ppVars, CBotCStack* pStack, - long& nIdent); - - int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pFunc); - - CBotString GetName(); - CBotCallMethode* Next(); - void AddNext(CBotCallMethode* p); - -}; - diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp new file mode 100644 index 00000000..6611129c --- /dev/null +++ b/src/CBot/CBotCallMethode.cpp @@ -0,0 +1,179 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotCallMethode.h" + +#include "CBotUtils.h" +#include "CBotStack.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotCallMethode::CBotCallMethode(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) +{ + m_name = name; + m_rExec = rExec; + m_rComp = rCompile; + m_next = nullptr; + m_nFuncIdent = CBotVar::NextUniqNum(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCallMethode::~CBotCallMethode() +{ + delete m_next; + m_next = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCallMethode::CompileCall(const char* name, + CBotVar* pThis, + CBotVar** ppVar, + CBotCStack* pStack, + long& nIdent) +{ + CBotCallMethode* pt = this; + nIdent = 0; + + while ( pt != nullptr ) + { + if ( pt->m_name == name ) + { + CBotVar* pVar = MakeListVars(ppVar, true); + CBotVar* pVar2 = pVar; + CBotTypResult r = pt->m_rComp(pThis, pVar2); + int ret = r.GetType(); + if ( ret > 20 ) + { + if (pVar2) pStack->SetError(ret, pVar2->GetToken()); + } + delete pVar; + nIdent = pt->m_nFuncIdent; + return r; + } + pt = pt->m_next; + } + return CBotTypResult(-1); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotCallMethode::GetName() +{ + return m_name; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCallMethode* CBotCallMethode::Next() +{ + return m_next; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCallMethode::AddNext(CBotCallMethode* pt) +{ + CBotCallMethode* p = this; + while ( p->m_next != nullptr ) p = p->m_next; + + p->m_next = pt; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCallMethode::DoCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotVar* &pResult, + CBotStack* pStack, + CBotToken* pToken) +{ + CBotCallMethode* pt = this; + + // search by the identifier + + if ( nIdent ) while ( pt != nullptr ) + { + if ( pt->m_nFuncIdent == nIdent ) + { + // lists the parameters depending on the contents of the stack (pStackVar) + + CBotVar* pVar = MakeListVars(ppVars, true); + CBotVar* pVarToDelete = pVar; + + // then calls the routine external to the module + + int Exception = 0; + int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); + pStack->SetVar(pResult); + + if (res == false) + { + if (Exception!=0) + { +// pStack->SetError(Exception, pVar->GetToken()); + pStack->SetError(Exception, pToken); + } + delete pVarToDelete; + return false; + } + delete pVarToDelete; + return true; + } + pt = pt->m_next; + } + + // search by name + + while ( pt != nullptr ) + { + if ( pt->m_name == name ) + { + // lists the parameters depending on the contents of the stack (pStackVar) + + CBotVar* pVar = MakeListVars(ppVars, true); + CBotVar* pVarToDelete = pVar; + + int Exception = 0; + int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); + pStack->SetVar(pResult); + + if (res == false) + { + if (Exception!=0) + { +// pStack->SetError(Exception, pVar->GetToken()); + pStack->SetError(Exception, pToken); + } + delete pVarToDelete; + return false; + } + delete pVarToDelete; + nIdent = pt->m_nFuncIdent; + return true; + } + pt = pt->m_next; + } + + return -1; +} diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h new file mode 100644 index 00000000..8ea40254 --- /dev/null +++ b/src/CBot/CBotCallMethode.h @@ -0,0 +1,115 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotCallMethode class Class managing the methods declared by + * AddFunction on a class. + */ +class CBotCallMethode +{ +public: + + /*! + * \brief CBotCallMethode + * \param name + * \param rExec + * \param rCompile + */ + CBotCallMethode(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); + + /*! + * \brief ~CBotCallMethode + */ + ~CBotCallMethode(); + + /*! + * \brief CompileCall Is acceptable by a call procedure name and given + * parameters. + * \param name + * \param pThis + * \param ppVars + * \param pStack + * \param nIdent + * \return + */ + CBotTypResult CompileCall(const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotCStack* pStack, + long& nIdent); + + /*! + * \brief DoCall + * \param nIdent + * \param name + * \param pThis + * \param ppVars + * \param pResult + * \param pStack + * \param pFunc + * \return + */ + int DoCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotVar* &pResult, + CBotStack* pStack, + CBotToken* pFunc); + + /*! + * \brief GetName + * \return + */ + CBotString GetName(); + + /*! + * \brief Next + * \return + */ + CBotCallMethode* Next(); + + /*! + * \brief AddNext + * \param p + */ + void AddNext(CBotCallMethode* p); + +private: + CBotString m_name; + bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); + CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar); + CBotCallMethode* m_next; + friend class CBotClass; + long m_nFuncIdent; + +}; + diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index d2d03e92..741dfb97 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -31,6 +31,7 @@ #include "CBotCall.h" #include "CBotStack.h" #include "CBotUtils.h" +#include "CBotCallMethode.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 8e492bac..c06cfbe0 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -641,148 +641,3 @@ void CBotProgram::Free() CBotCall ::Free() ; CBotClass::Free() ; } - - -//////////////////////////////////////////////////////////////////////////////// -CBotCallMethode::CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) -{ - m_name = name; - m_rExec = rExec; - m_rComp = rCompile; - m_next = nullptr; - m_nFuncIdent = CBotVar::NextUniqNum(); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotCallMethode::~CBotCallMethode() -{ - delete m_next; - m_next = nullptr; -} - -// is acceptable by a call procedure name -// and given parameters -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis, - CBotVar** ppVar, CBotCStack* pStack, - long& nIdent) -{ - CBotCallMethode* pt = this; - nIdent = 0; - - while ( pt != nullptr ) - { - if ( pt->m_name == name ) - { - CBotVar* pVar = MakeListVars(ppVar, true); - CBotVar* pVar2 = pVar; - CBotTypResult r = pt->m_rComp(pThis, pVar2); - int ret = r.GetType(); - if ( ret > 20 ) - { - if (pVar2) pStack->SetError(ret, pVar2->GetToken()); - } - delete pVar; - nIdent = pt->m_nFuncIdent; - return r; - } - pt = pt->m_next; - } - return CBotTypResult(-1); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotString CBotCallMethode::GetName() -{ - return m_name; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotCallMethode* CBotCallMethode::Next() -{ - return m_next; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCallMethode::AddNext(CBotCallMethode* pt) -{ - CBotCallMethode* p = this; - while ( p->m_next != nullptr ) p = p->m_next; - - p->m_next = pt; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pToken) -{ - CBotCallMethode* pt = this; - - // search by the identifier - - if ( nIdent ) while ( pt != nullptr ) - { - if ( pt->m_nFuncIdent == nIdent ) - { - // lists the parameters depending on the contents of the stack (pStackVar) - - CBotVar* pVar = MakeListVars(ppVars, true); - CBotVar* pVarToDelete = pVar; - - // then calls the routine external to the module - - int Exception = 0; - int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); - pStack->SetVar(pResult); - - if (res == false) - { - if (Exception!=0) - { -// pStack->SetError(Exception, pVar->GetToken()); - pStack->SetError(Exception, pToken); - } - delete pVarToDelete; - return false; - } - delete pVarToDelete; - return true; - } - pt = pt->m_next; - } - - // search by name - - while ( pt != nullptr ) - { - if ( pt->m_name == name ) - { - // lists the parameters depending on the contents of the stack (pStackVar) - - CBotVar* pVar = MakeListVars(ppVars, true); - CBotVar* pVarToDelete = pVar; - - int Exception = 0; - int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); - pStack->SetVar(pResult); - - if (res == false) - { - if (Exception!=0) - { -// pStack->SetError(Exception, pVar->GetToken()); - pStack->SetError(Exception, pToken); - } - delete pVarToDelete; - return false; - } - delete pVarToDelete; - nIdent = pt->m_nFuncIdent; - return true; - } - pt = pt->m_next; - } - - return -1; -} diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index c2a953f6..254bb665 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES CBotCall.cpp CBotUtils.cpp CBotDefParam.cpp + CBotCallMethode.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp From bd20f6303c86b8c9cd7071ef86a704a2fa01c1f2 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 19:11:57 +0100 Subject: [PATCH 109/360] Moving CBotVarPointer class in its own header and source files. --- src/CBot/CBot.h | 37 ---- src/CBot/CBotInstr/CBotClassInst.cpp | 2 + src/CBot/CBotStack.cpp | 2 + src/CBot/CBotVar.cpp | 209 +---------------------- src/CBot/CBotVar/CBotVarPointer.cpp | 242 +++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarPointer.h | 160 ++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 7 files changed, 408 insertions(+), 245 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarPointer.cpp create mode 100644 src/CBot/CBotVar/CBotVarPointer.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 44b251be..a2d083a1 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -432,43 +432,6 @@ public: void ConstructorSet() override; }; - -// class for the management of pointers to a class instances -class CBotVarPointer : public CBotVar -{ -private: - CBotVarClass* - m_pVarClass; // contents - CBotClass* m_pClass; // class provided for this pointer - friend class CBotVar; // my daddy is a buddy - -public: - CBotVarPointer( const CBotToken* name, CBotTypResult& type ); - ~CBotVarPointer(); - - void Copy(CBotVar* pSrc, bool bName=true) override; - void SetClass(CBotClass* pClass) override; - CBotClass* GetClass() override; - CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*) - CBotVar* GetItemRef(int nIdent) override; - CBotVar* GetItemList() override; - - CBotString GetValString() override; - void SetPointer(CBotVar* p) override; - CBotVarClass* - GetPointer() override; - - void SetIdent(long n) override; // associates an identification number (unique) - long GetIdent(); // gives the identification number associated with - void ConstructorSet() override; - - bool Save1State(FILE* pf) override; - void Maj(void* pUser, bool bContinue) override; - - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index a78b4de9..d4731885 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -26,6 +26,8 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotVar/CBotVarPointer.h" + // Local include // Global include diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 0a767135..5678c8fb 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -23,6 +23,8 @@ #include "CBotInstr/CBotFunction.h" +#include "CBotVar/CBotVarPointer.h" + // Local include // Global include diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 8808cb0f..ad736396 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -28,6 +28,7 @@ #include "CBotStack.h" #include "CBotVar/CBotVarArray.h" +#include "CBotVar/CBotVarPointer.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -1779,214 +1780,6 @@ bool CBotVarClass::Ne(CBotVar* left, CBotVar* right) return l != r; } -///////////////////////////////////////////////////////////////////////////// -// gestion des pointeurs à une instance donnée -// TODO management of pointers to a given instance - -CBotVarPointer::CBotVarPointer(const CBotToken* name, CBotTypResult& type ) -{ - if ( !type.Eq(CBotTypPointer) && - !type.Eq(CBotTypNullPointer) && - !type.Eq(CBotTypClass) && // for convenience accepts Class and Intrinsic - !type.Eq(CBotTypIntrinsic) ) assert(0); - - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - - m_type = type; - if ( !type.Eq(CBotTypNullPointer) ) - m_type.SetType(CBotTypPointer); // anyway, this is a pointer - m_binit = CBotVar::InitType::UNDEF; - m_pClass = nullptr; - m_pVarClass = nullptr; // will be defined by a SetPointer() - - SetClass(type.GetClass() ); -} - -CBotVarPointer::~CBotVarPointer() -{ - if ( m_pVarClass != nullptr ) m_pVarClass->DecrementUse(); // decrement reference -} - - -void CBotVarPointer::Maj(void* pUser, bool bContinu) -{ -/* if ( !bContinu && m_pMyThis != nullptr ) - m_pMyThis->Maj(pUser, false);*/ - - if ( m_pVarClass != nullptr) m_pVarClass->Maj(pUser, false); -} - -CBotVar* CBotVarPointer::GetItem(const char* name) -{ - if ( m_pVarClass == nullptr) // no existing instance? - return m_pClass->GetItem(name); // makes the pointer in the class itself - - return m_pVarClass->GetItem(name); -} - -CBotVar* CBotVarPointer::GetItemRef(int nIdent) -{ - if ( m_pVarClass == nullptr) // no existing instance? - return m_pClass->GetItemRef(nIdent);// makes the pointer to the class itself - - return m_pVarClass->GetItemRef(nIdent); -} - -CBotVar* CBotVarPointer::GetItemList() -{ - if ( m_pVarClass == nullptr) return nullptr; - return m_pVarClass->GetItemList(); -} - -CBotString CBotVarPointer::GetValString() -{ - CBotString s = "Pointer to "; - if ( m_pVarClass == nullptr ) s = "Null pointer" ; - else s += m_pVarClass->GetValString(); - return s; -} - - -void CBotVarPointer::ConstructorSet() -{ - if ( m_pVarClass != nullptr) m_pVarClass->ConstructorSet(); -} - -// initializes the pointer to the instance of a class - -void CBotVarPointer::SetPointer(CBotVar* pVarClass) -{ - m_binit = CBotVar::InitType::DEF; // init, even on a null pointer - - if ( m_pVarClass == pVarClass) return; // special, not decrement and reincrement - // because the decrement can destroy the object - - if ( pVarClass != nullptr ) - { - if ( pVarClass->GetType() == CBotTypPointer ) - pVarClass = pVarClass->GetPointer(); // the real pointer to the object - -// if ( pVarClass->GetType() != CBotTypClass ) - if ( !pVarClass->m_type.Eq(CBotTypClass) ) - assert(0); - - (static_cast(pVarClass))->IncrementUse(); // increment the reference - m_pClass = (static_cast(pVarClass))->m_pClass; - m_pUserPtr = pVarClass->m_pUserPtr; // not really necessary - m_type = CBotTypResult(CBotTypPointer, m_pClass); // what kind of a pointer - } - - if ( m_pVarClass != nullptr ) m_pVarClass->DecrementUse(); - m_pVarClass = static_cast(pVarClass); - -} - -CBotVarClass* CBotVarPointer::GetPointer() -{ - if ( m_pVarClass == nullptr ) return nullptr; - return m_pVarClass->GetPointer(); -} - -void CBotVarPointer::SetIdent(long n) -{ - if ( m_pVarClass == nullptr ) return; - m_pVarClass->SetIdent( n ); -} - -long CBotVarPointer::GetIdent() -{ - if ( m_pVarClass == nullptr ) return 0; - return m_pVarClass->m_ItemIdent; -} - - -void CBotVarPointer::SetClass(CBotClass* pClass) -{ -// int nIdent = 0; - m_type.m_pClass = m_pClass = pClass; - if ( m_pVarClass != nullptr ) m_pVarClass->SetClass(pClass); //, nIdent); -} - -CBotClass* CBotVarPointer::GetClass() -{ - if ( m_pVarClass != nullptr ) return m_pVarClass->GetClass(); - - return m_pClass; -} - - -bool CBotVarPointer::Save1State(FILE* pf) -{ - if ( m_pClass ) - { - if (!WriteString(pf, m_pClass->GetName())) return false; // name of the class - } - else - { - if (!WriteString(pf, "")) return false; - } - - if (!WriteLong(pf, GetIdent())) return false; // the unique reference - - // also saves the proceedings copies - return SaveVar(pf, GetPointer()); -} - -// copy a variable into another -void CBotVarPointer::Copy(CBotVar* pSrc, bool bName) -{ - if ( pSrc->GetType() != CBotTypPointer && - pSrc->GetType() != CBotTypNullPointer) - assert(0); - - CBotVarPointer* p = static_cast(pSrc); - - if ( bName) *m_token = *p->m_token; - m_type = p->m_type; -// m_pVarClass = p->m_pVarClass; - m_pVarClass = p->GetPointer(); - - if ( m_pVarClass != nullptr ) - m_pVarClass->IncrementUse(); // incerement the reference - - m_pClass = p->m_pClass; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - -bool CBotVarPointer::Eq(CBotVar* left, CBotVar* right) -{ - CBotVarClass* l = left->GetPointer(); - CBotVarClass* r = right->GetPointer(); - - if ( l == r ) return true; - if ( l == nullptr && r->GetUserPtr() == OBJECTDELETED ) return true; - if ( r == nullptr && l->GetUserPtr() == OBJECTDELETED ) return true; - return false; -} - -bool CBotVarPointer::Ne(CBotVar* left, CBotVar* right) -{ - CBotVarClass* l = left->GetPointer(); - CBotVarClass* r = right->GetPointer(); - - if ( l == r ) return false; - if ( l == nullptr && r->GetUserPtr() == OBJECTDELETED ) return false; - if ( r == nullptr && l->GetUserPtr() == OBJECTDELETED ) return false; - return true; -} - - - /////////////////////////////////////////////////////// // management of results types diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp new file mode 100644 index 00000000..c669a2a0 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -0,0 +1,242 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarPointer.h" +#include "CBotToken.h" +#include "CBot.h" +#include "CBotClass.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarPointer::CBotVarPointer(const CBotToken* name, CBotTypResult& type ) +{ + if ( !type.Eq(CBotTypPointer) && + !type.Eq(CBotTypNullPointer) && + !type.Eq(CBotTypClass) && // for convenience accepts Class and Intrinsic + !type.Eq(CBotTypIntrinsic) ) assert(0); + + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + + m_type = type; + if ( !type.Eq(CBotTypNullPointer) ) + m_type.SetType(CBotTypPointer); // anyway, this is a pointer + m_binit = CBotVar::InitType::UNDEF; + m_pClass = nullptr; + m_pVarClass = nullptr; // will be defined by a SetPointer() + + SetClass(type.GetClass() ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarPointer::~CBotVarPointer() +{ + if ( m_pVarClass != nullptr ) m_pVarClass->DecrementUse(); // decrement reference +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::Maj(void* pUser, bool bContinu) +{ +/* if ( !bContinu && m_pMyThis != nullptr ) + m_pMyThis->Maj(pUser, false);*/ + + if ( m_pVarClass != nullptr) m_pVarClass->Maj(pUser, false); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarPointer::GetItem(const char* name) +{ + if ( m_pVarClass == nullptr) // no existing instance? + return m_pClass->GetItem(name); // makes the pointer in the class itself + + return m_pVarClass->GetItem(name); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarPointer::GetItemRef(int nIdent) +{ + if ( m_pVarClass == nullptr) // no existing instance? + return m_pClass->GetItemRef(nIdent);// makes the pointer to the class itself + + return m_pVarClass->GetItemRef(nIdent); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarPointer::GetItemList() +{ + if ( m_pVarClass == nullptr) return nullptr; + return m_pVarClass->GetItemList(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarPointer::GetValString() +{ + CBotString s = "Pointer to "; + if ( m_pVarClass == nullptr ) s = "Null pointer" ; + else s += m_pVarClass->GetValString(); + return s; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::ConstructorSet() +{ + if ( m_pVarClass != nullptr) m_pVarClass->ConstructorSet(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::SetPointer(CBotVar* pVarClass) +{ + m_binit = CBotVar::InitType::DEF; // init, even on a null pointer + + if ( m_pVarClass == pVarClass) return; // special, not decrement and reincrement + // because the decrement can destroy the object + + if ( pVarClass != nullptr ) + { + if ( pVarClass->GetType() == CBotTypPointer ) + pVarClass = pVarClass->GetPointer(); // the real pointer to the object + +// if ( pVarClass->GetType() != CBotTypClass ) + if ( !pVarClass->m_type.Eq(CBotTypClass) ) + assert(0); + + (static_cast(pVarClass))->IncrementUse(); // increment the reference + m_pClass = (static_cast(pVarClass))->m_pClass; + m_pUserPtr = pVarClass->m_pUserPtr; // not really necessary + m_type = CBotTypResult(CBotTypPointer, m_pClass); // what kind of a pointer + } + + if ( m_pVarClass != nullptr ) m_pVarClass->DecrementUse(); + m_pVarClass = static_cast(pVarClass); + +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass* CBotVarPointer::GetPointer() +{ + if ( m_pVarClass == nullptr ) return nullptr; + return m_pVarClass->GetPointer(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::SetIdent(long n) +{ + if ( m_pVarClass == nullptr ) return; + m_pVarClass->SetIdent( n ); +} + +//////////////////////////////////////////////////////////////////////////////// +long CBotVarPointer::GetIdent() +{ + if ( m_pVarClass == nullptr ) return 0; + return m_pVarClass->m_ItemIdent; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::SetClass(CBotClass* pClass) +{ +// int nIdent = 0; + m_type.m_pClass = m_pClass = pClass; + if ( m_pVarClass != nullptr ) m_pVarClass->SetClass(pClass); //, nIdent); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotVarPointer::GetClass() +{ + if ( m_pVarClass != nullptr ) return m_pVarClass->GetClass(); + + return m_pClass; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarPointer::Save1State(FILE* pf) +{ + if ( m_pClass ) + { + if (!WriteString(pf, m_pClass->GetName())) return false; // name of the class + } + else + { + if (!WriteString(pf, "")) return false; + } + + if (!WriteLong(pf, GetIdent())) return false; // the unique reference + + // also saves the proceedings copies + return SaveVar(pf, GetPointer()); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarPointer::Copy(CBotVar* pSrc, bool bName) +{ + if ( pSrc->GetType() != CBotTypPointer && + pSrc->GetType() != CBotTypNullPointer) + assert(0); + + CBotVarPointer* p = static_cast(pSrc); + + if ( bName) *m_token = *p->m_token; + m_type = p->m_type; +// m_pVarClass = p->m_pVarClass; + m_pVarClass = p->GetPointer(); + + if ( m_pVarClass != nullptr ) + m_pVarClass->IncrementUse(); // incerement the reference + + m_pClass = p->m_pClass; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarPointer::Eq(CBotVar* left, CBotVar* right) +{ + CBotVarClass* l = left->GetPointer(); + CBotVarClass* r = right->GetPointer(); + + if ( l == r ) return true; + if ( l == nullptr && r->GetUserPtr() == OBJECTDELETED ) return true; + if ( r == nullptr && l->GetUserPtr() == OBJECTDELETED ) return true; + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarPointer::Ne(CBotVar* left, CBotVar* right) +{ + CBotVarClass* l = left->GetPointer(); + CBotVarClass* r = right->GetPointer(); + + if ( l == r ) return false; + if ( l == nullptr && r->GetUserPtr() == OBJECTDELETED ) return false; + if ( r == nullptr && l->GetUserPtr() == OBJECTDELETED ) return false; + return true; +} diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h new file mode 100644 index 00000000..dbb6ea39 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarPointer.h @@ -0,0 +1,160 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarPointer class Class for the management of pointers to a + * class instances. + */ +class CBotVarPointer : public CBotVar +{ +public: + + /*! + * \brief CBotVarPointer + * \param name + * \param type + */ + CBotVarPointer( const CBotToken* name, CBotTypResult& type ); + + /*! + * \brief ~CBotVarPointer + */ + ~CBotVarPointer(); + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief SetClass + * \param pClass + */ + void SetClass(CBotClass* pClass) override; + + /*! + * \brief GetClass + * \return + */ + CBotClass* GetClass() override; + + /*! + * \brief GetItem Return an element of a class according to its name (*). + * \param name + * \return + */ + CBotVar* GetItem(const char* name) override; + + /*! + * \brief GetItemRef + * \param nIdent + * \return + */ + CBotVar* GetItemRef(int nIdent) override; + + /*! + * \brief GetItemList + * \return + */ + CBotVar* GetItemList() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief SetPointer Initializes the pointer to the instance of a class. + * \param p + */ + void SetPointer(CBotVar* p) override; + + /*! + * \brief GetPointer + * \return + */ + CBotVarClass* GetPointer() override; + + /*! + * \brief SetIdent Associates an identification number (unique). + * \param n + */ + void SetIdent(long n) override; + + /*! + * \brief GetIdent Gives the identification number associated with. + * \return + */ + long GetIdent(); + + /*! + * \brief ConstructorSet + */ + void ConstructorSet() override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + + /*! + * \brief Maj + * \param pUser + * \param bContinue + */ + void Maj(void* pUser, bool bContinue) override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + +private: + //! Contents. + CBotVarClass* m_pVarClass; + //! Class provided for this pointer. + CBotClass* m_pClass; + friend class CBotVar; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 254bb665..a8ce7ac8 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -56,6 +56,7 @@ set(SOURCES CBotInstr/CBotInt.cpp CBotInstr/CBotFunction.cpp CBotVar/CBotVarArray.cpp + CBotVar/CBotVarPointer.cpp ) # Includes From c624d65649c24cf79958c92f7ee27cfc5bab588f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 19:25:35 +0100 Subject: [PATCH 110/360] Moving CBotVarClass class in its own header and source files. --- src/CBot/CBot.h | 59 -------- src/CBot/CBotDefParam.cpp | 2 + src/CBot/CBotInstr/CBotClassInst.cpp | 1 + src/CBot/CBotInstr/CBotFieldExpr.cpp | 2 + src/CBot/CBotStack.cpp | 1 + src/CBot/CBotVar.cpp | 92 +------------ src/CBot/CBotVar/CBotVarArray.cpp | 1 + src/CBot/CBotVar/CBotVarClass.cpp | 110 +++++++++++++++ src/CBot/CBotVar/CBotVarClass.h | 194 +++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarPointer.cpp | 2 +- src/CBot/CMakeLists.txt | 1 + 11 files changed, 314 insertions(+), 151 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarClass.cpp create mode 100644 src/CBot/CBotVar/CBotVarClass.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a2d083a1..8c5f4114 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -373,65 +373,6 @@ public: }; -// class management class instances -class CBotVarClass : public CBotVar -{ -private: - static - CBotVarClass* m_ExClass; // list of existing instances at some point - CBotVarClass* m_ExNext; // for this general list - CBotVarClass* m_ExPrev; // for this general list - -private: - CBotClass* m_pClass; // the class definition - CBotVarClass* m_pParent; // the instance of a parent class - CBotVar* m_pVar; // contents - friend class CBotVar; // my daddy is a buddy WHAT? :D(\TODO mon papa est un copain ) - friend class CBotVarPointer; // and also the pointer - int m_CptUse; // counter usage - long m_ItemIdent; // identifier (unique) of an instance - bool m_bConstructor; // set if a constructor has been called - -public: - CBotVarClass( const CBotToken* name, const CBotTypResult& type ); -// CBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent ); - ~CBotVarClass(); -// void InitCBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent ); - - void Copy(CBotVar* pSrc, bool bName=true) override; - void SetClass(CBotClass* pClass) override; //, int &nIdent); - CBotClass* GetClass() override; - CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*) - CBotVar* GetItemRef(int nIdent) override; - - CBotVar* GetItem(int n, bool bExtend) override; - CBotVar* GetItemList() override; - - CBotString GetValString() override; - - bool Save1State(FILE* pf) override; - void Maj(void* pUser, bool bContinue) override; - - void IncrementUse(); // a reference to incrementation - void DecrementUse(); // a reference to decrementation - - CBotVarClass* - GetPointer() override; - void SetItemList(CBotVar* pVar); - - void SetIdent(long n) override; - - static CBotVarClass* Find(long id); - - -// CBotVar* GetMyThis(); - - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - void ConstructorSet() override; -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 3a91f604..601e5676 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -24,6 +24,8 @@ #include "CBotUtils.h" +#include "CBotVar/CBotVarClass.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index d4731885..8426422b 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -27,6 +27,7 @@ #include "CBotClass.h" #include "CBotVar/CBotVarPointer.h" +#include "CBotVar/CBotVarClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index 592d4a7e..bad06d93 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotVar/CBotVarClass.h" + // Local include // Global include diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 5678c8fb..1a21dd2c 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -24,6 +24,7 @@ #include "CBotInstr/CBotFunction.h" #include "CBotVar/CBotVarPointer.h" +#include "CBotVar/CBotVarClass.h" // Local include diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index ad736396..dc2517d9 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -29,6 +29,7 @@ #include "CBotVar/CBotVarArray.h" #include "CBotVar/CBotVarPointer.h" +#include "CBotVar/CBotVarClass.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -117,97 +118,6 @@ CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) m_val = 0; } -CBotVarClass* CBotVarClass::m_ExClass = nullptr; - -CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type) -{ -/* -// int nIdent = 0; - InitCBotVarClass( name, type ) //, nIdent ); -} - -CBotVarClass::CBotVarClass( const CBotToken* name, CBotTypResult& type) //, int &nIdent ) -{ - InitCBotVarClass( name, type ); //, nIdent ); -} - -void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type ) //, int &nIdent ) -{*/ - if ( !type.Eq(CBotTypClass) && - !type.Eq(CBotTypIntrinsic) && // by convenience there accepts these types - !type.Eq(CBotTypPointer) && - !type.Eq(CBotTypArrayPointer) && - !type.Eq(CBotTypArrayBody)) assert(0); - - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = OBJECTCREATED;//nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_pVar = nullptr; - m_type = type; - if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody ); - else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass ); - // officel type for this object - - m_pClass = nullptr; - m_pParent = nullptr; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - m_bConstructor = false; - m_CptUse = 0; - m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum(); - - // se place tout seul dans la liste - // TODO stands alone in the list (stands only in a list) - if (m_ExClass) m_ExClass->m_ExPrev = this; - m_ExNext = m_ExClass; - m_ExPrev = nullptr; - m_ExClass = this; - - CBotClass* pClass = type.GetClass(); - CBotClass* pClass2 = pClass->GetParent(); - if ( pClass2 != nullptr ) - { - // also creates an instance of the parent class - m_pParent = new CBotVarClass(name, CBotTypResult(type.GetType(),pClass2) ); //, nIdent); - } - - SetClass( pClass ); //, nIdent ); - -} - -CBotVarClass::~CBotVarClass( ) -{ - if ( m_CptUse != 0 ) - assert(0); - - if ( m_pParent ) delete m_pParent; - m_pParent = nullptr; - - // frees the indirect object if necessary -// if ( m_Indirect != nullptr ) -// m_Indirect->DecrementUse(); - - // removes the class list - if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext; - else m_ExClass = m_ExNext; - - if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev; - m_ExPrev = nullptr; - m_ExNext = nullptr; - - delete m_pVar; -} - -void CBotVarClass::ConstructorSet() -{ - m_bConstructor = true; -} - - CBotVar::~CBotVar( ) { delete m_token; diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index 35f55a52..b030e7ae 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBotVarArray.h" +#include "CBotVarClass.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp new file mode 100644 index 00000000..73d14ac5 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -0,0 +1,110 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarClass.h" + +#include "CBotClass.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass* CBotVarClass::m_ExClass = nullptr; + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type) +{ + if ( !type.Eq(CBotTypClass) && + !type.Eq(CBotTypIntrinsic) && // by convenience there accepts these types + !type.Eq(CBotTypPointer) && + !type.Eq(CBotTypArrayPointer) && + !type.Eq(CBotTypArrayBody)) assert(0); + + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = OBJECTCREATED;//nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_pVar = nullptr; + m_type = type; + if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody ); + else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass ); + // officel type for this object + + m_pClass = nullptr; + m_pParent = nullptr; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + m_bConstructor = false; + m_CptUse = 0; + m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum(); + + // se place tout seul dans la liste + // TODO stands alone in the list (stands only in a list) + if (m_ExClass) m_ExClass->m_ExPrev = this; + m_ExNext = m_ExClass; + m_ExPrev = nullptr; + m_ExClass = this; + + CBotClass* pClass = type.GetClass(); + CBotClass* pClass2 = pClass->GetParent(); + if ( pClass2 != nullptr ) + { + // also creates an instance of the parent class + m_pParent = new CBotVarClass(name, CBotTypResult(type.GetType(),pClass2) ); //, nIdent); + } + + SetClass( pClass ); //, nIdent ); + +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass::~CBotVarClass( ) +{ + if ( m_CptUse != 0 ) + assert(0); + + if ( m_pParent ) delete m_pParent; + m_pParent = nullptr; + + // frees the indirect object if necessary +// if ( m_Indirect != nullptr ) +// m_Indirect->DecrementUse(); + + // removes the class list + if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext; + else m_ExClass = m_ExNext; + + if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev; + m_ExPrev = nullptr; + m_ExNext = nullptr; + + delete m_pVar; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::ConstructorSet() +{ + m_bConstructor = true; +} diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h new file mode 100644 index 00000000..b6a256ff --- /dev/null +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -0,0 +1,194 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarClass class Class management class instances. + */ +class CBotVarClass : public CBotVar +{ +public: + + /*! + * \brief CBotVarClass + * \param name + * \param type + */ + CBotVarClass( const CBotToken* name, const CBotTypResult& type ); + + /*! + * \brief ~CBotVarClass + */ + ~CBotVarClass(); + + /*! + * \brief Copy + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief SetClass + * \param pClass + */ + void SetClass(CBotClass* pClass) override; + + /*! + * \brief GetClass + * \return + */ + CBotClass* GetClass() override; + + /*! + * \brief GetItem Return an element of a class according to its name (*). + * \param name + * \return + */ + CBotVar* GetItem(const char* name) override; + + /*! + * \brief GetItemRef + * \param nIdent + * \return + */ + CBotVar* GetItemRef(int nIdent) override; + + /*! + * \brief GetItem + * \param n + * \param bExtend + * \return + */ + CBotVar* GetItem(int n, bool bExtend) override; + + /*! + * \brief GetItemList + * \return + */ + CBotVar* GetItemList() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + + /*! + * \brief Maj + * \param pUser + * \param bContinue + */ + void Maj(void* pUser, bool bContinue) override; + + /*! + * \brief IncrementUse A reference to incrementation. + */ + void IncrementUse(); + + /*! + * \brief DecrementUse A reference to decrementation. + */ + void DecrementUse(); + + /*! + * \brief GetPointer + * \return + */ + CBotVarClass* GetPointer() override; + + /*! + * \brief SetItemList + * \param pVar + */ + void SetItemList(CBotVar* pVar); + + /*! + * \brief SetIdent + * \param n + */ + void SetIdent(long n) override; + + /*! + * \brief Find + * \param id + * \return + */ + static CBotVarClass* Find(long id); + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief ConstructorSet + */ + void ConstructorSet() override; + +private: + //! List of existing instances at some point. + static CBotVarClass* m_ExClass; + //! For this general list. + CBotVarClass* m_ExNext; + //! For this general list. + CBotVarClass* m_ExPrev; + //! The class definition. + CBotClass* m_pClass; + //! The instance of a parent class. + CBotVarClass* m_pParent; + //! Contents. + CBotVar* m_pVar; + //! Counter usage. + int m_CptUse; + //! Identifier (unique) of an instance. + long m_ItemIdent; + //! Set if a constructor has been called. + bool m_bConstructor; + + friend class CBotVar; + friend class CBotVarPointer; +}; diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index c669a2a0..df333221 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -22,7 +22,7 @@ #include "CBotToken.h" #include "CBot.h" #include "CBotClass.h" - +#include "CBotVarClass.h" // Local include // Global include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index a8ce7ac8..098868ed 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -57,6 +57,7 @@ set(SOURCES CBotInstr/CBotFunction.cpp CBotVar/CBotVarArray.cpp CBotVar/CBotVarPointer.cpp + CBotVar/CBotVarClass.cpp ) # Includes From ade4aefb0e6855fa98f64515933b7883512e212c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 21:13:50 +0100 Subject: [PATCH 111/360] Moving CBotVarBoolean class in its own header and source files. --- src/CBot/CBot.h | 28 ----- src/CBot/CBotProgram.cpp | 10 -- src/CBot/CBotStack.cpp | 6 -- src/CBot/CBotUtils.cpp | 10 ++ src/CBot/CBotUtils.h | 8 ++ src/CBot/CBotVar.cpp | 115 +------------------- src/CBot/CBotVar/CBotVarBoolean.cpp | 156 ++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarBoolean.h | 133 ++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 9 files changed, 309 insertions(+), 158 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarBoolean.cpp create mode 100644 src/CBot/CBotVar/CBotVarBoolean.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8c5f4114..13a11918 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -344,34 +344,6 @@ public: bool Save1State(FILE* pf) override; }; -// class for the management of boolean -class CBotVarBoolean : public CBotVar -{ -private: - bool m_val; // the value - -public: - CBotVarBoolean( const CBotToken* name ); -// ~CBotVarBoolean(); - - void SetValInt(int val, const char* s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - CBotString GetValString() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - - void And(CBotVar* left, CBotVar* right) override; - void Or(CBotVar* left, CBotVar* right) override; - void XOr(CBotVar* left, CBotVar* right) override; - void Not() override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - bool Save1State(FILE* pf) override; -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index c06cfbe0..9817f370 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -382,16 +382,6 @@ bool CBotProgram::AddFunction(const char* name, return CBotCall::AddFunction(name, rExec, rCompile); } -//////////////////////////////////////////////////////////////////////////////// -bool WriteWord(FILE* pf, unsigned short w) -{ - size_t lg; - - lg = fwrite(&w, sizeof( unsigned short ), 1, pf ); - - return (lg == 1); -} - //////////////////////////////////////////////////////////////////////////////// bool ReadWord(FILE* pf, unsigned short& w) { diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 1a21dd2c..421bf5df 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -990,12 +990,6 @@ bool CBotVarInt::Save1State(FILE* pf) return WriteWord(pf, m_val); // the value of the variable } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarBoolean::Save1State(FILE* pf) -{ - return WriteWord(pf, m_val); // the value of the variable -} - //////////////////////////////////////////////////////////////////////////////// bool CBotVarFloat::Save1State(FILE* pf) { diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index bb2b9409..3fe76d06 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -105,3 +105,13 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) } return type; } + +//////////////////////////////////////////////////////////////////////////////// +bool WriteWord(FILE* pf, unsigned short w) +{ + size_t lg; + + lg = fwrite(&w, sizeof( unsigned short ), 1, pf ); + + return (lg == 1); +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 9d452d85..47a83d71 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -51,3 +51,11 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile); * \return */ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type); + +/*! + * \brief WriteWord + * \param pf + * \param w + * \return + */ +bool WriteWord(FILE* pf, unsigned short w); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index dc2517d9..ce0c5f06 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -30,6 +30,7 @@ #include "CBotVar/CBotVarArray.h" #include "CBotVar/CBotVarPointer.h" #include "CBotVar/CBotVarClass.h" +#include "CBotVar/CBotVarBoolean.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -102,22 +103,6 @@ CBotVarString::CBotVarString( const CBotToken* name ) m_val.Empty(); } -CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypBoolean; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - - m_val = 0; -} - CBotVar::~CBotVar( ) { delete m_token; @@ -1136,104 +1121,6 @@ bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) } -////////////////////////////////////////////////////////////////////////////////////// - -// copy a variable into another -void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarBoolean* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - - - - -void CBotVarBoolean::SetValInt(int val, const char* s) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::SetValFloat(float val) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarBoolean::GetValInt() -{ - return m_val; -} - -float CBotVarBoolean::GetValFloat() -{ - return static_cast(m_val); -} - -CBotString CBotVarBoolean::GetValString() -{ - CBotString ret; - - CBotString res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - res.LoadString(TX_UNDEF); - return res; - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - res.LoadString(TX_NAN); - return res; - } - - ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); - return ret; -} - -void CBotVarBoolean::And(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() && right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} -void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() || right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() ^ right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarBoolean::Not() -{ - m_val = m_val ? false : true ; -} - -bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() == right->GetValInt(); -} - -bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() != right->GetValInt(); -} - ////////////////////////////////////////////////////////////////////////////////////// // copy a variable into another diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp new file mode 100644 index 00000000..f1c59347 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -0,0 +1,156 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarBoolean.h" + +#include "CBotUtils.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) +{ + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_type = CBotTypBoolean; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + + m_val = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) +{ + CBotVarBoolean* p = static_cast(pSrc); + + if (bName) *m_token = *p->m_token; + m_type = p->m_type; + m_val = p->m_val; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::SetValInt(int val, const char* s) +{ + m_val = static_cast(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::SetValFloat(float val) +{ + m_val = static_cast(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarBoolean::GetValInt() +{ + return m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +float CBotVarBoolean::GetValFloat() +{ + return static_cast(m_val); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarBoolean::GetValString() +{ + CBotString ret; + + CBotString res; + + if ( m_binit == CBotVar::InitType::UNDEF ) + { + res.LoadString(TX_UNDEF); + return res; + } + if ( m_binit == CBotVar::InitType::IS_NAN ) + { + res.LoadString(TX_NAN); + return res; + } + + ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); + return ret; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::And(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() && right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() || right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() ^ right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarBoolean::Not() +{ + m_val = m_val ? false : true ; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() == right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() != right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarBoolean::Save1State(FILE* pf) +{ + return WriteWord(pf, m_val); // the value of the variable +} diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h new file mode 100644 index 00000000..e57c22f7 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -0,0 +1,133 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotToken.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarBoolean class Class for the management of boolean. + */ +class CBotVarBoolean : public CBotVar +{ +public: + + /*! + * \brief CBotVarBoolean + * \param name + */ + CBotVarBoolean( const CBotToken* name ); + + /*! + * \brief SetValInt + * \param val + * \param s + */ + void SetValInt(int val, const char* s = nullptr) override; + + /*! + * \brief SetValFloat + * \param val + */ + void SetValFloat(float val) override; + + /*! + * \brief GetValInt + * \return + */ + int GetValInt() override; + + /*! + * \brief GetValFloat + * \return + */ + float GetValFloat() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief And + * \param left + * \param right + */ + void And(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Or + * \param left + * \param right + */ + void Or(CBotVar* left, CBotVar* right) override; + + /*! + * \brief XOr + * \param left + * \param right + */ + void XOr(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Not + */ + void Not() override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! The value. + bool m_val; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 098868ed..283e01c8 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -58,6 +58,7 @@ set(SOURCES CBotVar/CBotVarArray.cpp CBotVar/CBotVarPointer.cpp CBotVar/CBotVarClass.cpp + CBotVar/CBotVarBoolean.cpp ) # Includes From 1b3b2ea5a1e4f3186f0e33f4f1eebce259e18f88 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 21:24:54 +0100 Subject: [PATCH 112/360] Moving CBotVarString class in its own header and source files. --- src/CBot/CBot.h | 29 ------ src/CBot/CBotProgram.cpp | 12 --- src/CBot/CBotStack.cpp | 6 -- src/CBot/CBotUtils.cpp | 12 +++ src/CBot/CBotUtils.h | 8 ++ src/CBot/CBotVar.cpp | 102 +-------------------- src/CBot/CBotVar/CBotVarString.cpp | 139 +++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarString.h | 127 ++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 9 files changed, 288 insertions(+), 148 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarString.cpp create mode 100644 src/CBot/CBotVar/CBotVarString.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 13a11918..2c23fa77 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -316,35 +316,6 @@ public: bool Save1State(FILE* pf) override; }; - -// class for management of strings (String) -class CBotVarString : public CBotVar -{ -private: - CBotString m_val; // the value - -public: - CBotVarString( const CBotToken* name ); -// ~CBotVarString(); - - void SetValString(const char* p) override; - CBotString GetValString() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - - void Add(CBotVar* left, CBotVar* right) override; // addition - - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - bool Save1State(FILE* pf) override; -}; - - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 9817f370..9ce35958 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -432,18 +432,6 @@ bool ReadLong(FILE* pf, long& w) return (lg == 1); } -//////////////////////////////////////////////////////////////////////////////// -bool WriteString(FILE* pf, CBotString s) -{ - size_t lg1, lg2; - - lg1 = s.GetLength(); - if (!WriteWord(pf, lg1)) return false; - - lg2 = fwrite(s, 1, lg1, pf ); - return (lg1 == lg2); -} - //////////////////////////////////////////////////////////////////////////////// bool ReadString(FILE* pf, CBotString& s) { diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 421bf5df..574c81cf 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -996,12 +996,6 @@ bool CBotVarFloat::Save1State(FILE* pf) return WriteFloat(pf, m_val); // the value of the variable } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarString::Save1State(FILE* pf) -{ - return WriteString(pf, m_val); // the value of the variable -} - //////////////////////////////////////////////////////////////////////////////// bool CBotVarClass::Save1State(FILE* pf) { diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 3fe76d06..4596b6f2 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -115,3 +115,15 @@ bool WriteWord(FILE* pf, unsigned short w) return (lg == 1); } + +//////////////////////////////////////////////////////////////////////////////// +bool WriteString(FILE* pf, CBotString s) +{ + size_t lg1, lg2; + + lg1 = s.GetLength(); + if (!WriteWord(pf, lg1)) return false; + + lg2 = fwrite(s, 1, lg1, pf ); + return (lg1 == lg2); +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 47a83d71..000c90af 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -59,3 +59,11 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type); * \return */ bool WriteWord(FILE* pf, unsigned short w); + +/*! + * \brief WriteString + * \param pf + * \param s + * \return + */ +bool WriteString(FILE* pf, CBotString s); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index ce0c5f06..b87f718d 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -31,6 +31,7 @@ #include "CBotVar/CBotVarPointer.h" #include "CBotVar/CBotVarClass.h" #include "CBotVar/CBotVarBoolean.h" +#include "CBotVar/CBotVarString.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -87,22 +88,6 @@ CBotVarFloat::CBotVarFloat( const CBotToken* name ) m_val = 0; } -CBotVarString::CBotVarString( const CBotToken* name ) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypString; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - - m_val.Empty(); -} - CBotVar::~CBotVar( ) { delete m_token; @@ -1120,91 +1105,6 @@ bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) return left->GetValFloat() != right->GetValFloat(); } - -////////////////////////////////////////////////////////////////////////////////////// - -// copy a variable into another -void CBotVarString::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarString* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - - -void CBotVarString::SetValString(const char* p) -{ - m_val = p; - m_binit = CBotVar::InitType::DEF; -} - -CBotString CBotVarString::GetValString() -{ - if ( m_binit == CBotVar::InitType::UNDEF ) - { - CBotString res; - res.LoadString(TX_UNDEF); - return res; - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - CBotString res; - res.LoadString(TX_NAN); - return res; - } - - return m_val; -} - - -void CBotVarString::Add(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValString() + right->GetValString(); - m_binit = CBotVar::InitType::DEF; -} - -bool CBotVarString::Eq(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -bool CBotVarString::Ne(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() != right->GetValString()); -} - - -bool CBotVarString::Lo(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -bool CBotVarString::Hi(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -bool CBotVarString::Ls(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - -bool CBotVarString::Hs(CBotVar* left, CBotVar* right) -{ - return (left->GetValString() == right->GetValString()); -} - - //////////////////////////////////////////////////////////////// // copy a variable into another diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp new file mode 100644 index 00000000..7b740147 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -0,0 +1,139 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarString.h" + +#include "CBotToken.h" + +#include "CBotUtils.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarString::CBotVarString( const CBotToken* name ) +{ + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_type = CBotTypString; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + + m_val.Empty(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarString::Copy(CBotVar* pSrc, bool bName) +{ + CBotVarString* p = static_cast(pSrc); + + if (bName) *m_token = *p->m_token; + m_type = p->m_type; + m_val = p->m_val; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarString::SetValString(const char* p) +{ + m_val = p; + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarString::GetValString() +{ + if ( m_binit == CBotVar::InitType::UNDEF ) + { + CBotString res; + res.LoadString(TX_UNDEF); + return res; + } + if ( m_binit == CBotVar::InitType::IS_NAN ) + { + CBotString res; + res.LoadString(TX_NAN); + return res; + } + + return m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarString::Add(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValString() + right->GetValString(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Eq(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() == right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Ne(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() != right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Lo(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() == right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Hi(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() == right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Ls(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() == right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Hs(CBotVar* left, CBotVar* right) +{ + return (left->GetValString() == right->GetValString()); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarString::Save1State(FILE* pf) +{ + return WriteString(pf, m_val); // the value of the variable +} diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h new file mode 100644 index 00000000..31c776e2 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarString.h @@ -0,0 +1,127 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarString class Class for management of strings (String). + */ +class CBotVarString : public CBotVar +{ +public: + + /*! + * \brief CBotVarString + * \param name + */ + CBotVarString( const CBotToken* name ); + + /*! + * \brief SetValString + * \param p + */ + void SetValString(const char* p) override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief Add + * \param left + * \param right + */ + void Add(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Lo + * \param left + * \param right + * \return + */ + bool Lo(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hi + * \param left + * \param right + * \return + */ + bool Hi(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ls + * \param left + * \param right + * \return + */ + bool Ls(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hs + * \param left + * \param right + * \return + */ + bool Hs(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! The value. + CBotString m_val; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 283e01c8..1dd05b8b 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -59,6 +59,7 @@ set(SOURCES CBotVar/CBotVarPointer.cpp CBotVar/CBotVarClass.cpp CBotVar/CBotVarBoolean.cpp + CBotVar/CBotVarString.cpp ) # Includes From 44021e91f7ae3a5f710c4f28840a390d59c35277 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 21:37:56 +0100 Subject: [PATCH 113/360] Moving CBotVarFloat class in its own header and source files. --- src/CBot/CBot.h | 40 ------ src/CBot/CBotProgram.cpp | 10 -- src/CBot/CBotStack.cpp | 6 - src/CBot/CBotUtils.cpp | 10 ++ src/CBot/CBotUtils.h | 8 ++ src/CBot/CBotVar.cpp | 178 +---------------------- src/CBot/CBotVar/CBotVarFloat.cpp | 226 ++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarFloat.h | 198 ++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 9 files changed, 444 insertions(+), 233 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarFloat.cpp create mode 100644 src/CBot/CBotVar/CBotVarFloat.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 2c23fa77..a742d47a 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -276,46 +276,6 @@ public: }; -// Class for managing real numbers (float) -class CBotVarFloat : public CBotVar -{ -private: - float m_val; // the value - -public: - CBotVarFloat( const CBotToken* name ); -// ~CBotVarFloat(); - - void SetValInt(int val, const char* s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - CBotString GetValString() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - - - void Add(CBotVar* left, CBotVar* right) override; // addition - void Sub(CBotVar* left, CBotVar* right) override; // substraction - void Mul(CBotVar* left, CBotVar* right) override; // multiplication - int Div(CBotVar* left, CBotVar* right) override; // division - int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division - void Power(CBotVar* left, CBotVar* right) override; // power - - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - void Neg() override; - void Inc() override; - void Dec() override; - - bool Save1State(FILE* pf) override; -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 9ce35958..44eaca50 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -392,16 +392,6 @@ bool ReadWord(FILE* pf, unsigned short& w) return (lg == 1); } -//////////////////////////////////////////////////////////////////////////////// -bool WriteFloat(FILE* pf, float w) -{ - size_t lg; - - lg = fwrite(&w, sizeof( float ), 1, pf ); - - return (lg == 1); -} - //////////////////////////////////////////////////////////////////////////////// bool ReadFloat(FILE* pf, float& w) { diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 574c81cf..e8310081 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -990,12 +990,6 @@ bool CBotVarInt::Save1State(FILE* pf) return WriteWord(pf, m_val); // the value of the variable } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarFloat::Save1State(FILE* pf) -{ - return WriteFloat(pf, m_val); // the value of the variable -} - //////////////////////////////////////////////////////////////////////////////// bool CBotVarClass::Save1State(FILE* pf) { diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 4596b6f2..eee71e44 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -127,3 +127,13 @@ bool WriteString(FILE* pf, CBotString s) lg2 = fwrite(s, 1, lg1, pf ); return (lg1 == lg2); } + +//////////////////////////////////////////////////////////////////////////////// +bool WriteFloat(FILE* pf, float w) +{ + size_t lg; + + lg = fwrite(&w, sizeof( float ), 1, pf ); + + return (lg == 1); +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 000c90af..354595b8 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -67,3 +67,11 @@ bool WriteWord(FILE* pf, unsigned short w); * \return */ bool WriteString(FILE* pf, CBotString s); + +/*! + * \brief WriteFloat + * \param pf + * \param w + * \return + */ +bool WriteFloat(FILE* pf, float w); diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index b87f718d..154405e1 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -32,6 +32,7 @@ #include "CBotVar/CBotVarClass.h" #include "CBotVar/CBotVarBoolean.h" #include "CBotVar/CBotVarString.h" +#include "CBotVar/CBotVarFloat.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -72,22 +73,6 @@ CBotVarInt::CBotVarInt( const CBotToken* name ) m_val = 0; } -CBotVarFloat::CBotVarFloat( const CBotToken* name ) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypFloat; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - - m_val = 0; -} - CBotVar::~CBotVar( ) { delete m_token; @@ -944,167 +929,6 @@ bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) return left->GetValInt() != right->GetValInt(); } - -////////////////////////////////////////////////////////////////////////////////////// - -// copy a variable into another -void CBotVarFloat::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarFloat* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_next = nullptr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_pUserPtr = p->m_pUserPtr; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; -} - - - - -void CBotVarFloat::SetValInt(int val, const char* s) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarFloat::SetValFloat(float val) -{ - m_val = val; - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarFloat::GetValInt() -{ - return static_cast(m_val); -} - -float CBotVarFloat::GetValFloat() -{ - return m_val; -} - -CBotString CBotVarFloat::GetValString() -{ - CBotString res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - res.LoadString(TX_UNDEF); - return res; - } - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - res.LoadString(TX_NAN); - return res; - } - - char buffer[300]; - sprintf(buffer, "%.2f", m_val); - res = buffer; - - return res; -} - - -void CBotVarFloat::Mul(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() * right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarFloat::Power(CBotVar* left, CBotVar* right) -{ - m_val = static_cast(pow( left->GetValFloat() , right->GetValFloat() )); - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarFloat::Div(CBotVar* left, CBotVar* right) -{ - float r = right->GetValFloat(); - if ( r != 0 ) - { - m_val = left->GetValFloat() / r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? TX_DIVZERO : 0 ); -} - -int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) -{ - float r = right->GetValFloat(); - if ( r != 0 ) - { - m_val = static_cast(fmod( left->GetValFloat() , r )); - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? TX_DIVZERO : 0 ); -} - -void CBotVarFloat::Add(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() + right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarFloat::Sub(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValFloat() - right->GetValFloat(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarFloat::Neg() -{ - m_val = -m_val; -} - -void CBotVarFloat::Inc() -{ - m_val++; -} - -void CBotVarFloat::Dec() -{ - m_val--; -} - - -bool CBotVarFloat::Lo(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() < right->GetValFloat(); -} - -bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() > right->GetValFloat(); -} - -bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() <= right->GetValFloat(); -} - -bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() >= right->GetValFloat(); -} - -bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() == right->GetValFloat(); -} - -bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValFloat() != right->GetValFloat(); -} - //////////////////////////////////////////////////////////////// // copy a variable into another diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp new file mode 100644 index 00000000..465c2940 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -0,0 +1,226 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarFloat.h" + +#include "CBotToken.h" + +#include "CBotUtils.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarFloat::CBotVarFloat( const CBotToken* name ) +{ + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_type = CBotTypFloat; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + + m_val = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Copy(CBotVar* pSrc, bool bName) +{ + CBotVarFloat* p = static_cast(pSrc); + + if (bName) *m_token = *p->m_token; + m_type = p->m_type; + m_val = p->m_val; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_next = nullptr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_pUserPtr = p->m_pUserPtr; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::SetValInt(int val, const char* s) +{ + m_val = static_cast(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::SetValFloat(float val) +{ + m_val = val; + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarFloat::GetValInt() +{ + return static_cast(m_val); +} + +//////////////////////////////////////////////////////////////////////////////// +float CBotVarFloat::GetValFloat() +{ + return m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarFloat::GetValString() +{ + CBotString res; + + if ( m_binit == CBotVar::InitType::UNDEF ) + { + res.LoadString(TX_UNDEF); + return res; + } + if ( m_binit == CBotVar::InitType::IS_NAN ) + { + res.LoadString(TX_NAN); + return res; + } + + char buffer[300]; + sprintf(buffer, "%.2f", m_val); + res = buffer; + + return res; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Mul(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValFloat() * right->GetValFloat(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Power(CBotVar* left, CBotVar* right) +{ + m_val = static_cast(pow( left->GetValFloat() , right->GetValFloat() )); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarFloat::Div(CBotVar* left, CBotVar* right) +{ + float r = right->GetValFloat(); + if ( r != 0 ) + { + m_val = left->GetValFloat() / r; + m_binit = CBotVar::InitType::DEF; + } + return ( r == 0 ? TX_DIVZERO : 0 ); +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) +{ + float r = right->GetValFloat(); + if ( r != 0 ) + { + m_val = static_cast(fmod( left->GetValFloat() , r )); + m_binit = CBotVar::InitType::DEF; + } + return ( r == 0 ? TX_DIVZERO : 0 ); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Add(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValFloat() + right->GetValFloat(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Sub(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValFloat() - right->GetValFloat(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Neg() +{ + m_val = -m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Inc() +{ + m_val++; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarFloat::Dec() +{ + m_val--; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Lo(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() < right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() > right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() <= right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() >= right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() == right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) +{ + return left->GetValFloat() != right->GetValFloat(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarFloat::Save1State(FILE* pf) +{ + return WriteFloat(pf, m_val); // the value of the variable +} diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h new file mode 100644 index 00000000..fb30cd49 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -0,0 +1,198 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarFloat class Class for managing real numbers (float). + */ +class CBotVarFloat : public CBotVar +{ +public: + + /*! + * \brief CBotVarFloat + * \param name + */ + CBotVarFloat( const CBotToken* name ); + + /*! + * \brief SetValInt + * \param val + * \param s + */ + void SetValInt(int val, const char* s = nullptr) override; + + /*! + * \brief SetValFloat + * \param val + */ + void SetValFloat(float val) override; + + /*! + * \brief GetValInt + * \return + */ + int GetValInt() override; + + /*! + * \brief GetValFloat + * \return + */ + float GetValFloat() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Copy Copy a variable into another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief Add Addition. + * \param left + * \param right + */ + void Add(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Sub Substraction. + * \param left + * \param right + */ + void Sub(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Mul Multiplication. + * \param left + * \param right + */ + void Mul(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Div Division. + * \param left + * \param right + * \return + */ + int Div(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Modulo Remainder of division. + * \param left + * \param right + * \return + */ + int Modulo(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Power + * \param left + * \param right + */ + void Power(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Lo + * \param left + * \param right + * \return + */ + bool Lo(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hi + * \param left + * \param right + * \return + */ + bool Hi(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ls + * \param left + * \param right + * \return + */ + bool Ls(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hs + * \param left + * \param right + * \return + */ + bool Hs(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Neg + */ + void Neg() override; + + /*! + * \brief Inc + */ + void Inc() override; + + /*! + * \brief Dec + */ + void Dec() override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! The value. + float m_val; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 1dd05b8b..33474db8 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -60,6 +60,7 @@ set(SOURCES CBotVar/CBotVarClass.cpp CBotVar/CBotVarBoolean.cpp CBotVar/CBotVarString.cpp + CBotVar/CBotVarFloat.cpp ) # Includes From a4f14650c6a6b1070f5d155b14daab33d43c525b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 21:52:05 +0100 Subject: [PATCH 114/360] Moving CBotVarInt class in its own header and source files. --- src/CBot/CBot.h | 54 ------ src/CBot/CBotStack.cpp | 18 -- src/CBot/CBotVar.cpp | 235 +------------------------ src/CBot/CBotVar/CBotVarInt.cpp | 295 ++++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarInt.h | 255 +++++++++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 6 files changed, 552 insertions(+), 306 deletions(-) create mode 100644 src/CBot/CBotVar/CBotVarInt.cpp create mode 100644 src/CBot/CBotVar/CBotVarInt.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a742d47a..98d3f9ce 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -222,60 +222,6 @@ public: #define MAX(a,b) ((a>b) ? a : b) - -// class for the management of integer numbers (int) -class CBotVarInt : public CBotVar -{ -private: - int m_val; // the value - CBotString m_defnum; // the name if given by DefineNum - friend class CBotVar; - -public: - CBotVarInt( const CBotToken* name ); -// ~CBotVarInt(); - - void SetValInt(int val, const char* s = nullptr) override; - void SetValFloat(float val) override; - int GetValInt() override; - float GetValFloat() override; - CBotString GetValString() override; - - void Copy(CBotVar* pSrc, bool bName=true) override; - - - void Add(CBotVar* left, CBotVar* right) override; // addition - void Sub(CBotVar* left, CBotVar* right) override; // substraction - void Mul(CBotVar* left, CBotVar* right) override; // multiplication - int Div(CBotVar* left, CBotVar* right) override; // division - int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division - void Power(CBotVar* left, CBotVar* right) override; // power - - bool Lo(CBotVar* left, CBotVar* right) override; - bool Hi(CBotVar* left, CBotVar* right) override; - bool Ls(CBotVar* left, CBotVar* right) override; - bool Hs(CBotVar* left, CBotVar* right) override; - bool Eq(CBotVar* left, CBotVar* right) override; - bool Ne(CBotVar* left, CBotVar* right) override; - - void XOr(CBotVar* left, CBotVar* right) override; - void Or(CBotVar* left, CBotVar* right) override; - void And(CBotVar* left, CBotVar* right) override; - - void SL(CBotVar* left, CBotVar* right) override; - void SR(CBotVar* left, CBotVar* right) override; - void ASR(CBotVar* left, CBotVar* right) override; - - void Neg() override; - void Not() override; - void Inc() override; - void Dec() override; - - bool Save0State(FILE* pf) override; - bool Save1State(FILE* pf) override; - -}; - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index e8310081..63ee21d4 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -972,24 +972,6 @@ bool CBotVar::Save0State(FILE* pf) return WriteString(pf, m_token->GetString()); // and variable name } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Save0State(FILE* pf) -{ - if ( !m_defnum.IsEmpty() ) - { - if(!WriteWord(pf, 200 )) return false; // special marker - if(!WriteString(pf, m_defnum)) return false; // name of the value - } - - return CBotVar::Save0State(pf); -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarInt::Save1State(FILE* pf) -{ - return WriteWord(pf, m_val); // the value of the variable -} - //////////////////////////////////////////////////////////////////////////////// bool CBotVarClass::Save1State(FILE* pf) { diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 154405e1..74bfb646 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -33,6 +33,7 @@ #include "CBotVar/CBotVarBoolean.h" #include "CBotVar/CBotVarString.h" #include "CBotVar/CBotVarFloat.h" +#include "CBotVar/CBotVarInt.h" #include "CBotDefines.h" #include "CBotClass.h" @@ -57,22 +58,6 @@ CBotVar::CBotVar( ) m_mPrivate = 0; } -CBotVarInt::CBotVarInt( const CBotToken* name ) -{ - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; - m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypInt; - m_binit = InitType::UNDEF; - m_bStatic = false; - m_mPrivate = 0; - - m_val = 0; -} - CBotVar::~CBotVar( ) { delete m_token; @@ -711,224 +696,6 @@ CBotClass* CBotVar::GetClass() return nullptr; } -/* -void CBotVar::SetIndirection(CBotVar* pVar) -{ - // nop, only CBotVarPointer::SetIndirection -} -*/ - -////////////////////////////////////////////////////////////////////////////////////// - -// copy a variable in to another -void CBotVarInt::Copy(CBotVar* pSrc, bool bName) -{ - CBotVarInt* p = static_cast(pSrc); - - if ( bName) *m_token = *p->m_token; - m_type = p->m_type; - m_val = p->m_val; - m_binit = p->m_binit; - m_pMyThis = nullptr; - m_pUserPtr = p->m_pUserPtr; - - // identificator is the same (by défaut) - if (m_ident == 0 ) m_ident = p->m_ident; - - m_defnum = p->m_defnum; -} - - - - -void CBotVarInt::SetValInt(int val, const char* defnum) -{ - m_val = val; - m_binit = CBotVar::InitType::DEF; - m_defnum = defnum; -} - - - -void CBotVarInt::SetValFloat(float val) -{ - m_val = static_cast(val); - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarInt::GetValInt() -{ - return m_val; -} - -float CBotVarInt::GetValFloat() -{ - return static_cast(m_val); -} - -CBotString CBotVarInt::GetValString() -{ - if ( !m_defnum.IsEmpty() ) return m_defnum; - - CBotString res; - - if ( m_binit == CBotVar::InitType::UNDEF ) - { - res.LoadString(TX_UNDEF); - return res; - } - - if ( m_binit == CBotVar::InitType::IS_NAN ) - { - res.LoadString(TX_NAN); - return res; - } - - char buffer[300]; - sprintf(buffer, "%d", m_val); - res = buffer; - - return res; -} - - -void CBotVarInt::Mul(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() * right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::Power(CBotVar* left, CBotVar* right) -{ - m_val = static_cast( pow( static_cast( left->GetValInt()) , static_cast( left->GetValInt()) )); - m_binit = CBotVar::InitType::DEF; -} - -int CBotVarInt::Div(CBotVar* left, CBotVar* right) -{ - int r = right->GetValInt(); - if ( r != 0 ) - { - m_val = left->GetValInt() / r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? TX_DIVZERO : 0 ); -} - -int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) -{ - int r = right->GetValInt(); - if ( r != 0 ) - { - m_val = left->GetValInt() % r; - m_binit = CBotVar::InitType::DEF; - } - return ( r == 0 ? TX_DIVZERO : 0 ); -} - -void CBotVarInt::Add(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() + right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::Sub(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() - right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::XOr(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() ^ right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::And(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() & right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::Or(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() | right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::SL(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() << right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::ASR(CBotVar* left, CBotVar* right) -{ - m_val = left->GetValInt() >> right->GetValInt(); - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::SR(CBotVar* left, CBotVar* right) -{ - int source = left->GetValInt(); - int shift = right->GetValInt(); - if (shift>=1) source &= 0x7fffffff; - m_val = source >> shift; - m_binit = CBotVar::InitType::DEF; -} - -void CBotVarInt::Neg() -{ - m_val = -m_val; -} - -void CBotVarInt::Not() -{ - m_val = ~m_val; -} - -void CBotVarInt::Inc() -{ - m_val++; - m_defnum.Empty(); -} - -void CBotVarInt::Dec() -{ - m_val--; - m_defnum.Empty(); -} - -bool CBotVarInt::Lo(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() < right->GetValInt(); -} - -bool CBotVarInt::Hi(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() > right->GetValInt(); -} - -bool CBotVarInt::Ls(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() <= right->GetValInt(); -} - -bool CBotVarInt::Hs(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() >= right->GetValInt(); -} - -bool CBotVarInt::Eq(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() == right->GetValInt(); -} - -bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) -{ - return left->GetValInt() != right->GetValInt(); -} - //////////////////////////////////////////////////////////////// // copy a variable into another diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp new file mode 100644 index 00000000..76f89c12 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -0,0 +1,295 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotVarInt.h" + +#include "CBotToken.h" + +#include "CBotUtils.h" + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +CBotVarInt::CBotVarInt( const CBotToken* name ) +{ + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; + m_InitExpr = nullptr; + m_LimExpr = nullptr; + m_type = CBotTypInt; + m_binit = InitType::UNDEF; + m_bStatic = false; + m_mPrivate = 0; + + m_val = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Copy(CBotVar* pSrc, bool bName) +{ + CBotVarInt* p = static_cast(pSrc); + + if ( bName) *m_token = *p->m_token; + m_type = p->m_type; + m_val = p->m_val; + m_binit = p->m_binit; + m_pMyThis = nullptr; + m_pUserPtr = p->m_pUserPtr; + + // identificator is the same (by défaut) + if (m_ident == 0 ) m_ident = p->m_ident; + + m_defnum = p->m_defnum; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::SetValInt(int val, const char* defnum) +{ + m_val = val; + m_binit = CBotVar::InitType::DEF; + m_defnum = defnum; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::SetValFloat(float val) +{ + m_val = static_cast(val); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarInt::GetValInt() +{ + return m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +float CBotVarInt::GetValFloat() +{ + return static_cast(m_val); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarInt::GetValString() +{ + if ( !m_defnum.IsEmpty() ) return m_defnum; + + CBotString res; + + if ( m_binit == CBotVar::InitType::UNDEF ) + { + res.LoadString(TX_UNDEF); + return res; + } + + if ( m_binit == CBotVar::InitType::IS_NAN ) + { + res.LoadString(TX_NAN); + return res; + } + + char buffer[300]; + sprintf(buffer, "%d", m_val); + res = buffer; + + return res; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Mul(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() * right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Power(CBotVar* left, CBotVar* right) +{ + m_val = static_cast( pow( static_cast( left->GetValInt()) , static_cast( left->GetValInt()) )); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarInt::Div(CBotVar* left, CBotVar* right) +{ + int r = right->GetValInt(); + if ( r != 0 ) + { + m_val = left->GetValInt() / r; + m_binit = CBotVar::InitType::DEF; + } + return ( r == 0 ? TX_DIVZERO : 0 ); +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) +{ + int r = right->GetValInt(); + if ( r != 0 ) + { + m_val = left->GetValInt() % r; + m_binit = CBotVar::InitType::DEF; + } + return ( r == 0 ? TX_DIVZERO : 0 ); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Add(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() + right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Sub(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() - right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::XOr(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() ^ right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::And(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() & right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Or(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() | right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::SL(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() << right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::ASR(CBotVar* left, CBotVar* right) +{ + m_val = left->GetValInt() >> right->GetValInt(); + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::SR(CBotVar* left, CBotVar* right) +{ + int source = left->GetValInt(); + int shift = right->GetValInt(); + if (shift>=1) source &= 0x7fffffff; + m_val = source >> shift; + m_binit = CBotVar::InitType::DEF; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Neg() +{ + m_val = -m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Not() +{ + m_val = ~m_val; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Inc() +{ + m_val++; + m_defnum.Empty(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarInt::Dec() +{ + m_val--; + m_defnum.Empty(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Lo(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() < right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Hi(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() > right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Ls(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() <= right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Hs(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() >= right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Eq(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() == right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) +{ + return left->GetValInt() != right->GetValInt(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Save0State(FILE* pf) +{ + if ( !m_defnum.IsEmpty() ) + { + if(!WriteWord(pf, 200 )) return false; // special marker + if(!WriteString(pf, m_defnum)) return false; // name of the value + } + + return CBotVar::Save0State(pf); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarInt::Save1State(FILE* pf) +{ + return WriteWord(pf, m_val); // the value of the variable +} diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h new file mode 100644 index 00000000..741fdc10 --- /dev/null +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -0,0 +1,255 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVarInt class Class for the management of integer numbers (int). + */ +class CBotVarInt : public CBotVar +{ +public: + + /*! + * \brief CBotVarInt + * \param name + */ + CBotVarInt( const CBotToken* name ); + + /*! + * \brief SetValInt + * \param val + * \param s + */ + void SetValInt(int val, const char* s = nullptr) override; + + /*! + * \brief SetValFloat + * \param val + */ + void SetValFloat(float val) override; + + /*! + * \brief GetValInt + * \return + */ + int GetValInt() override; + + /*! + * \brief GetValFloat + * \return + */ + float GetValFloat() override; + + /*! + * \brief GetValString + * \return + */ + CBotString GetValString() override; + + /*! + * \brief Copy Copy a variable in to another. + * \param pSrc + * \param bName + */ + void Copy(CBotVar* pSrc, bool bName=true) override; + + /*! + * \brief Add + * \param left + * \param right + */ + void Add(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Sub + * \param left + * \param right + */ + void Sub(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Mul + * \param left + * \param right + */ + void Mul(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Div + * \param left + * \param right + * \return + */ + int Div(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Modulo + * \param left + * \param right + * \return + */ + int Modulo(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Power + * \param left + * \param right + */ + void Power(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Lo + * \param left + * \param right + * \return + */ + bool Lo(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hi + * \param left + * \param right + * \return + */ + bool Hi(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ls + * \param left + * \param right + * \return + */ + bool Ls(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Hs + * \param left + * \param right + * \return + */ + bool Hs(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + bool Eq(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + bool Ne(CBotVar* left, CBotVar* right) override; + + /*! + * \brief XOr + * \param left + * \param right + */ + void XOr(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Or + * \param left + * \param right + */ + void Or(CBotVar* left, CBotVar* right) override; + + /*! + * \brief And + * \param left + * \param right + */ + void And(CBotVar* left, CBotVar* right) override; + + /*! + * \brief SL + * \param left + * \param right + */ + void SL(CBotVar* left, CBotVar* right) override; + + /*! + * \brief SR + * \param left + * \param right + */ + void SR(CBotVar* left, CBotVar* right) override; + + /*! + * \brief ASR + * \param left + * \param right + */ + void ASR(CBotVar* left, CBotVar* right) override; + + /*! + * \brief Neg + */ + void Neg() override; + + /*! + * \brief Not + */ + void Not() override; + + /*! + * \brief Inc + */ + void Inc() override; + + /*! + * \brief Dec + */ + void Dec() override; + + /*! + * \brief Save0State + * \param pf + * \return + */ + bool Save0State(FILE* pf) override; + + /*! + * \brief Save1State + * \param pf + * \return + */ + bool Save1State(FILE* pf) override; + +private: + //! The value. + int m_val; + //! The name if given by DefineNum. + CBotString m_defnum; + friend class CBotVar; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 33474db8..6e8a8039 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -61,6 +61,7 @@ set(SOURCES CBotVar/CBotVarBoolean.cpp CBotVar/CBotVarString.cpp CBotVar/CBotVarFloat.cpp + CBotVar/CBotVarInt.cpp ) # Includes From 2eeab6d4d0c9114f73d753b21838cddfceae14d9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 22:00:17 +0100 Subject: [PATCH 115/360] Moving CBotVarClass function from CBotVar.cpp to CBotVarClass.cpp. --- src/CBot/CBotStack.cpp | 9 - src/CBot/CBotVar.cpp | 373 ---------------------------- src/CBot/CBotVar/CBotVarClass.cpp | 391 ++++++++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarClass.h | 9 +- 4 files changed, 396 insertions(+), 386 deletions(-) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 63ee21d4..87aa0bb2 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -972,15 +972,6 @@ bool CBotVar::Save0State(FILE* pf) return WriteString(pf, m_token->GetString()); // and variable name } -//////////////////////////////////////////////////////////////////////////////// -bool CBotVarClass::Save1State(FILE* pf) -{ - if ( !WriteType(pf, m_type) ) return false; - if ( !WriteLong(pf, m_ItemIdent) ) return false; - - return SaveVar(pf, m_pVar); // content of the object -} - namespace { bool ParseInitType(int rawInitType, CBotVar::InitType* initType) diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 74bfb646..d5c248e7 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -35,7 +35,6 @@ #include "CBotVar/CBotVarFloat.h" #include "CBotVar/CBotVarInt.h" -#include "CBotDefines.h" #include "CBotClass.h" #include @@ -696,378 +695,6 @@ CBotClass* CBotVar::GetClass() return nullptr; } -//////////////////////////////////////////////////////////////// - -// copy a variable into another -void CBotVarClass::Copy(CBotVar* pSrc, bool bName) -{ - pSrc = pSrc->GetPointer(); // if source given by a pointer - - if ( pSrc->GetType() != CBotTypClass ) - assert(0); - - CBotVarClass* p = static_cast(pSrc); - - if (bName) *m_token = *p->m_token; - - m_type = p->m_type; - m_binit = p->m_binit; -//- m_bStatic = p->m_bStatic; - m_pClass = p->m_pClass; - if ( p->m_pParent ) - { - assert(0); // "que faire du pParent"; - } - -// m_next = nullptr; - m_pUserPtr = p->m_pUserPtr; - m_pMyThis = nullptr;//p->m_pMyThis; - m_ItemIdent = p->m_ItemIdent; - - // keeps indentificator the same (by default) - if (m_ident == 0 ) m_ident = p->m_ident; - - delete m_pVar; - m_pVar = nullptr; - - CBotVar* pv = p->m_pVar; - while( pv != nullptr ) - { - CBotVar* pn = CBotVar::Create(pv); - pn->Copy( pv ); - if ( m_pVar == nullptr ) m_pVar = pn; - else m_pVar->AddNext(pn); - - pv = pv->GetNext(); - } -} - -void CBotVarClass::SetItemList(CBotVar* pVar) -{ - delete m_pVar; - m_pVar = pVar; // replaces the existing pointer -} - -void CBotVarClass::SetIdent(long n) -{ - m_ItemIdent = n; -} - -void CBotVarClass::SetClass(CBotClass* pClass)//, int &nIdent) -{ - m_type.m_pClass = pClass; - - if ( m_pClass == pClass ) return; - - m_pClass = pClass; - - // initializes the variables associated with this class - delete m_pVar; - m_pVar = nullptr; - - if (pClass == nullptr) return; - - CBotVar* pv = pClass->GetVar(); // first on a list - while ( pv != nullptr ) - { - // seeks the maximum dimensions of the table - CBotInstr* p = pv->m_LimExpr; // the different formulas - if ( p != nullptr ) - { - CBotStack* pile = CBotStack::FirstStack(); // an independent stack - int n = 0; - int max[100]; - - while (p != nullptr) - { - while( pile->IsOk() && !p->Execute(pile) ) ; // calculate size without interruptions - CBotVar* v = pile->GetVar(); // result - max[n] = v->GetValInt(); // value - n++; - p = p->GetNext3(); - } - while (n<100) max[n++] = 0; - - pv->m_type.SetArray( max ); // stores the limitations - pile->Delete(); - } - - CBotVar* pn = CBotVar::Create( pv ); // a copy - pn->SetStatic(pv->IsStatic()); - pn->SetPrivate(pv->GetPrivate()); - - if ( pv->m_InitExpr != nullptr ) // expression for initialization? - { -#if STACKMEM - CBotStack* pile = CBotStack::FirstStack(); // an independent stack - - while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pn)); // evaluates the expression without timer - - pile->Delete(); -#else - CBotStack* pile = new CBotStack(nullptr); // an independent stack - while(!pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer - pn->SetVal( pile->GetVar() ) ; - delete pile; -#endif - } - -// pn->SetUniqNum(CBotVar::NextUniqNum()); // enumerate elements - pn->SetUniqNum(pv->GetUniqNum()); //++nIdent - pn->m_pMyThis = this; - - if ( m_pVar == nullptr) m_pVar = pn; - else m_pVar->AddNext( pn ); - pv = pv->GetNext(); - } -} - -CBotClass* CBotVarClass::GetClass() -{ - return m_pClass; -} - - -void CBotVarClass::Maj(void* pUser, bool bContinu) -{ -/* if (!bContinu && m_pMyThis != nullptr) - m_pMyThis->Maj(pUser, true);*/ - - // an update routine exist? - - if ( m_pClass->m_rMaj == nullptr ) return; - - // retrieves the user pointer according to the class - // or according to the parameter passed to CBotProgram::Run() - - if ( m_pUserPtr != nullptr) pUser = m_pUserPtr; - if ( pUser == OBJECTDELETED || - pUser == OBJECTCREATED ) return; - m_pClass->m_rMaj( this, pUser ); -} - -CBotVar* CBotVarClass::GetItem(const char* name) -{ - CBotVar* p = m_pVar; - - while ( p != nullptr ) - { - if ( p->GetName() == name ) return p; - p = p->GetNext(); - } - - if ( m_pParent != nullptr ) return m_pParent->GetItem(name); - return nullptr; -} - -CBotVar* CBotVarClass::GetItemRef(int nIdent) -{ - CBotVar* p = m_pVar; - - while ( p != nullptr ) - { - if ( p->GetUniqNum() == nIdent ) return p; - p = p->GetNext(); - } - - if ( m_pParent != nullptr ) return m_pParent->GetItemRef(nIdent); - return nullptr; -} - -// for the management of an array -// bExtend can enlarge the table, but not beyond the threshold size of SetArray () - -CBotVar* CBotVarClass::GetItem(int n, bool bExtend) -{ - CBotVar* p = m_pVar; - - if ( n < 0 ) return nullptr; - if ( n > MAXARRAYSIZE ) return nullptr; - - if ( m_type.GetLimite() >= 0 && n >= m_type.GetLimite() ) return nullptr; - - if ( p == nullptr && bExtend ) - { - p = CBotVar::Create("", m_type.GetTypElem()); - m_pVar = p; - } - - if ( n == 0 ) return p; - - while ( n-- > 0 ) - { - if ( p->m_next == nullptr ) - { - if ( bExtend ) p->m_next = CBotVar::Create("", m_type.GetTypElem()); - if ( p->m_next == nullptr ) return nullptr; - } - p = p->m_next; - } - - return p; -} - -CBotVar* CBotVarClass::GetItemList() -{ - return m_pVar; -} - - -CBotString CBotVarClass::GetValString() -{ -// if ( m_Indirect != nullptr) return m_Indirect->GetValString(); - - CBotString res; - - if ( m_pClass != nullptr ) // not used for an array - { - res = m_pClass->GetName() + CBotString("( "); - - CBotVarClass* my = this; - while ( my != nullptr ) - { - CBotVar* pv = my->m_pVar; - while ( pv != nullptr ) - { - res += pv->GetName() + CBotString("="); - - if ( pv->IsStatic() ) - { - CBotVar* pvv = my->m_pClass->GetItem(pv->GetName()); - res += pvv->GetValString(); - } - else - { - res += pv->GetValString(); - } - pv = pv->GetNext(); - if ( pv != nullptr ) res += ", "; - } - my = my->m_pParent; - if ( my != nullptr ) - { - res += ") extends "; - res += my->m_pClass->GetName(); - res += " ("; - } - } - } - else - { - res = "( "; - - CBotVar* pv = m_pVar; - while ( pv != nullptr ) - { - res += pv->GetValString(); - if ( pv->GetNext() != nullptr ) res += ", "; - pv = pv->GetNext(); - } - } - - res += " )"; - return res; -} - -void CBotVarClass::IncrementUse() -{ - m_CptUse++; -} - -void CBotVarClass::DecrementUse() -{ - m_CptUse--; - if ( m_CptUse == 0 ) - { - // if there is one, call the destructor - // but only if a constructor had been called. - if ( m_bConstructor ) - { - m_CptUse++; // does not return to the destructor - - // m_error is static in the stack - // saves the value for return - int err, start, end; - CBotStack* pile = nullptr; - err = pile->GetError(start,end); // stack == nullptr it does not bother! - - pile = CBotStack::FirstStack(); // clears the error - CBotVar* ppVars[1]; - ppVars[0] = nullptr; - - CBotVar* pThis = CBotVar::Create("this", CBotTypNullPointer); - pThis->SetPointer(this); - CBotVar* pResult = nullptr; - - CBotString nom = CBotString("~") + m_pClass->GetName(); - long ident = 0; - - while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end - - pile->ResetError(err, start,end); - - pile->Delete(); - delete pThis; - m_CptUse--; - } - - delete this; // self-destructs! - } -} - -CBotVarClass* CBotVarClass::GetPointer() -{ - return this; -} - - -// makes an instance according to its unique number - -CBotVarClass* CBotVarClass::Find(long id) -{ - CBotVarClass* p = m_ExClass; - - while ( p != nullptr ) - { - if ( p->m_ItemIdent == id ) return p; - p = p->m_ExNext; - } - - return nullptr; -} - -bool CBotVarClass::Eq(CBotVar* left, CBotVar* right) -{ - CBotVar* l = left->GetItemList(); - CBotVar* r = right->GetItemList(); - - while ( l != nullptr && r != nullptr ) - { - if ( l->Ne(l, r) ) return false; - l = l->GetNext(); - r = r->GetNext(); - } - - // should always arrived simultaneously at the end (same classes) - return l == r; -} - -bool CBotVarClass::Ne(CBotVar* left, CBotVar* right) -{ - CBotVar* l = left->GetItemList(); - CBotVar* r = right->GetItemList(); - - while ( l != nullptr && r != nullptr ) - { - if ( l->Ne(l, r) ) return true; - l = l->GetNext(); - r = r->GetNext(); - } - - // should always arrived simultaneously at the end (same classes) - return l != r; -} - /////////////////////////////////////////////////////// // management of results types diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 73d14ac5..f07fbe9f 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -22,6 +22,10 @@ #include "CBotClass.h" +#include "CBotStack.h" + +#include "CBotDefines.h" + // Local include // Global include @@ -108,3 +112,390 @@ void CBotVarClass::ConstructorSet() { m_bConstructor = true; } + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::Copy(CBotVar* pSrc, bool bName) +{ + pSrc = pSrc->GetPointer(); // if source given by a pointer + + if ( pSrc->GetType() != CBotTypClass ) + assert(0); + + CBotVarClass* p = static_cast(pSrc); + + if (bName) *m_token = *p->m_token; + + m_type = p->m_type; + m_binit = p->m_binit; +//- m_bStatic = p->m_bStatic; + m_pClass = p->m_pClass; + if ( p->m_pParent ) + { + assert(0); // "que faire du pParent"; + } + +// m_next = nullptr; + m_pUserPtr = p->m_pUserPtr; + m_pMyThis = nullptr;//p->m_pMyThis; + m_ItemIdent = p->m_ItemIdent; + + // keeps indentificator the same (by default) + if (m_ident == 0 ) m_ident = p->m_ident; + + delete m_pVar; + m_pVar = nullptr; + + CBotVar* pv = p->m_pVar; + while( pv != nullptr ) + { + CBotVar* pn = CBotVar::Create(pv); + pn->Copy( pv ); + if ( m_pVar == nullptr ) m_pVar = pn; + else m_pVar->AddNext(pn); + + pv = pv->GetNext(); + } +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::SetItemList(CBotVar* pVar) +{ + delete m_pVar; + m_pVar = pVar; // replaces the existing pointer +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::SetIdent(long n) +{ + m_ItemIdent = n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::SetClass(CBotClass* pClass)//, int &nIdent) +{ + m_type.m_pClass = pClass; + + if ( m_pClass == pClass ) return; + + m_pClass = pClass; + + // initializes the variables associated with this class + delete m_pVar; + m_pVar = nullptr; + + if (pClass == nullptr) return; + + CBotVar* pv = pClass->GetVar(); // first on a list + while ( pv != nullptr ) + { + // seeks the maximum dimensions of the table + CBotInstr* p = pv->m_LimExpr; // the different formulas + if ( p != nullptr ) + { + CBotStack* pile = CBotStack::FirstStack(); // an independent stack + int n = 0; + int max[100]; + + while (p != nullptr) + { + while( pile->IsOk() && !p->Execute(pile) ) ; // calculate size without interruptions + CBotVar* v = pile->GetVar(); // result + max[n] = v->GetValInt(); // value + n++; + p = p->GetNext3(); + } + while (n<100) max[n++] = 0; + + pv->m_type.SetArray( max ); // stores the limitations + pile->Delete(); + } + + CBotVar* pn = CBotVar::Create( pv ); // a copy + pn->SetStatic(pv->IsStatic()); + pn->SetPrivate(pv->GetPrivate()); + + if ( pv->m_InitExpr != nullptr ) // expression for initialization? + { +#if STACKMEM + CBotStack* pile = CBotStack::FirstStack(); // an independent stack + + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pn)); // evaluates the expression without timer + + pile->Delete(); +#else + CBotStack* pile = new CBotStack(nullptr); // an independent stack + while(!pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer + pn->SetVal( pile->GetVar() ) ; + delete pile; +#endif + } + +// pn->SetUniqNum(CBotVar::NextUniqNum()); // enumerate elements + pn->SetUniqNum(pv->GetUniqNum()); //++nIdent + pn->m_pMyThis = this; + + if ( m_pVar == nullptr) m_pVar = pn; + else m_pVar->AddNext( pn ); + pv = pv->GetNext(); + } +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotVarClass::GetClass() +{ + return m_pClass; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::Maj(void* pUser, bool bContinu) +{ +/* if (!bContinu && m_pMyThis != nullptr) + m_pMyThis->Maj(pUser, true);*/ + + // an update routine exist? + + if ( m_pClass->m_rMaj == nullptr ) return; + + // retrieves the user pointer according to the class + // or according to the parameter passed to CBotProgram::Run() + + if ( m_pUserPtr != nullptr) pUser = m_pUserPtr; + if ( pUser == OBJECTDELETED || + pUser == OBJECTCREATED ) return; + m_pClass->m_rMaj( this, pUser ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarClass::GetItem(const char* name) +{ + CBotVar* p = m_pVar; + + while ( p != nullptr ) + { + if ( p->GetName() == name ) return p; + p = p->GetNext(); + } + + if ( m_pParent != nullptr ) return m_pParent->GetItem(name); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarClass::GetItemRef(int nIdent) +{ + CBotVar* p = m_pVar; + + while ( p != nullptr ) + { + if ( p->GetUniqNum() == nIdent ) return p; + p = p->GetNext(); + } + + if ( m_pParent != nullptr ) return m_pParent->GetItemRef(nIdent); + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarClass::GetItem(int n, bool bExtend) +{ + CBotVar* p = m_pVar; + + if ( n < 0 ) return nullptr; + if ( n > MAXARRAYSIZE ) return nullptr; + + if ( m_type.GetLimite() >= 0 && n >= m_type.GetLimite() ) return nullptr; + + if ( p == nullptr && bExtend ) + { + p = CBotVar::Create("", m_type.GetTypElem()); + m_pVar = p; + } + + if ( n == 0 ) return p; + + while ( n-- > 0 ) + { + if ( p->m_next == nullptr ) + { + if ( bExtend ) p->m_next = CBotVar::Create("", m_type.GetTypElem()); + if ( p->m_next == nullptr ) return nullptr; + } + p = p->m_next; + } + + return p; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotVarClass::GetItemList() +{ + return m_pVar; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString CBotVarClass::GetValString() +{ +// if ( m_Indirect != nullptr) return m_Indirect->GetValString(); + + CBotString res; + + if ( m_pClass != nullptr ) // not used for an array + { + res = m_pClass->GetName() + CBotString("( "); + + CBotVarClass* my = this; + while ( my != nullptr ) + { + CBotVar* pv = my->m_pVar; + while ( pv != nullptr ) + { + res += pv->GetName() + CBotString("="); + + if ( pv->IsStatic() ) + { + CBotVar* pvv = my->m_pClass->GetItem(pv->GetName()); + res += pvv->GetValString(); + } + else + { + res += pv->GetValString(); + } + pv = pv->GetNext(); + if ( pv != nullptr ) res += ", "; + } + my = my->m_pParent; + if ( my != nullptr ) + { + res += ") extends "; + res += my->m_pClass->GetName(); + res += " ("; + } + } + } + else + { + res = "( "; + + CBotVar* pv = m_pVar; + while ( pv != nullptr ) + { + res += pv->GetValString(); + if ( pv->GetNext() != nullptr ) res += ", "; + pv = pv->GetNext(); + } + } + + res += " )"; + return res; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::IncrementUse() +{ + m_CptUse++; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotVarClass::DecrementUse() +{ + m_CptUse--; + if ( m_CptUse == 0 ) + { + // if there is one, call the destructor + // but only if a constructor had been called. + if ( m_bConstructor ) + { + m_CptUse++; // does not return to the destructor + + // m_error is static in the stack + // saves the value for return + int err, start, end; + CBotStack* pile = nullptr; + err = pile->GetError(start,end); // stack == nullptr it does not bother! + + pile = CBotStack::FirstStack(); // clears the error + CBotVar* ppVars[1]; + ppVars[0] = nullptr; + + CBotVar* pThis = CBotVar::Create("this", CBotTypNullPointer); + pThis->SetPointer(this); + CBotVar* pResult = nullptr; + + CBotString nom = CBotString("~") + m_pClass->GetName(); + long ident = 0; + + while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end + + pile->ResetError(err, start,end); + + pile->Delete(); + delete pThis; + m_CptUse--; + } + + delete this; // self-destructs! + } +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass* CBotVarClass::GetPointer() +{ + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVarClass* CBotVarClass::Find(long id) +{ + CBotVarClass* p = m_ExClass; + + while ( p != nullptr ) + { + if ( p->m_ItemIdent == id ) return p; + p = p->m_ExNext; + } + + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarClass::Eq(CBotVar* left, CBotVar* right) +{ + CBotVar* l = left->GetItemList(); + CBotVar* r = right->GetItemList(); + + while ( l != nullptr && r != nullptr ) + { + if ( l->Ne(l, r) ) return false; + l = l->GetNext(); + r = r->GetNext(); + } + + // should always arrived simultaneously at the end (same classes) + return l == r; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarClass::Ne(CBotVar* left, CBotVar* right) +{ + CBotVar* l = left->GetItemList(); + CBotVar* r = right->GetItemList(); + + while ( l != nullptr && r != nullptr ) + { + if ( l->Ne(l, r) ) return true; + l = l->GetNext(); + r = r->GetNext(); + } + + // should always arrived simultaneously at the end (same classes) + return l != r; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotVarClass::Save1State(FILE* pf) +{ + if ( !WriteType(pf, m_type) ) return false; + if ( !WriteLong(pf, m_ItemIdent) ) return false; + + return SaveVar(pf, m_pVar); // content of the object +} diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index b6a256ff..b7b878f9 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -47,7 +47,7 @@ public: ~CBotVarClass(); /*! - * \brief Copy + * \brief Copy Copy a variable into another. * \param pSrc * \param bName */ @@ -80,9 +80,10 @@ public: CBotVar* GetItemRef(int nIdent) override; /*! - * \brief GetItem + * \brief GetItem For the management of an array. * \param n - * \param bExtend + * \param bExtend can enlarge the table, but not beyond the threshold size + * of SetArray(). * \return */ CBotVar* GetItem(int n, bool bExtend) override; @@ -142,7 +143,7 @@ public: void SetIdent(long n) override; /*! - * \brief Find + * \brief Find Makes an instance according to its unique number. * \param id * \return */ From 660f17454af4f312d1c4942ec388ac5ae688f546 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 23:18:47 +0100 Subject: [PATCH 116/360] Moving CBotVar class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBotCall.cpp | 2 + src/CBot/CBotCallMethode.cpp | 2 + src/CBot/CBotClass.cpp | 2 + src/CBot/CBotClass.h | 2 + src/CBot/CBotDefines.h | 7 + src/CBot/CBotDll.h | 225 --------- src/CBot/CBotInstr/CBotBoolean.cpp | 2 + src/CBot/CBotInstr/CBotCatch.cpp | 2 + src/CBot/CBotInstr/CBotEmpty.cpp | 2 + src/CBot/CBotInstr/CBotExprAlpha.cpp | 2 + src/CBot/CBotInstr/CBotExprBool.cpp | 2 + src/CBot/CBotInstr/CBotExprNan.cpp | 2 + src/CBot/CBotInstr/CBotExprNull.cpp | 2 + src/CBot/CBotInstr/CBotExprNum.cpp | 2 + src/CBot/CBotInstr/CBotExprUnaire.cpp | 2 + src/CBot/CBotInstr/CBotExprVar.h | 2 + src/CBot/CBotInstr/CBotExpression.cpp | 2 + src/CBot/CBotInstr/CBotFloat.cpp | 2 + src/CBot/CBotInstr/CBotFunction.cpp | 2 + src/CBot/CBotInstr/CBotIString.cpp | 2 + src/CBot/CBotInstr/CBotInstArray.cpp | 2 + src/CBot/CBotInstr/CBotInstrCall.cpp | 2 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 2 + src/CBot/CBotInstr/CBotInt.cpp | 2 + src/CBot/CBotInstr/CBotLeftExprVar.cpp | 2 + src/CBot/CBotInstr/CBotListArray.cpp | 2 + src/CBot/CBotInstr/CBotNew.cpp | 2 + src/CBot/CBotInstr/CBotParExpr.cpp | 2 + src/CBot/CBotInstr/CBotPostIncExpr.cpp | 2 + src/CBot/CBotInstr/CBotPreIncExpr.cpp | 2 + src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 2 + src/CBot/CBotUtils.cpp | 2 + src/CBot/{ => CBotVar}/CBotVar.cpp | 120 ++++- src/CBot/CBotVar/CBotVar.h | 624 ++++++++++++++++++++++++ src/CBot/CBotVar/CBotVarArray.h | 2 + src/CBot/CBotVar/CBotVarBoolean.h | 2 + src/CBot/CBotVar/CBotVarClass.h | 2 + src/CBot/CBotVar/CBotVarFloat.h | 2 + src/CBot/CBotVar/CBotVarInt.h | 2 + src/CBot/CBotVar/CBotVarPointer.h | 2 +- src/CBot/CBotVar/CBotVarString.h | 2 + src/CBot/CMakeLists.txt | 2 +- src/CBot/StringFunctions.cpp | 3 + src/script/script.cpp | 1 + src/script/scriptfunc.cpp | 1 + 46 files changed, 810 insertions(+), 248 deletions(-) rename src/CBot/{ => CBotVar}/CBotVar.cpp (70%) create mode 100644 src/CBot/CBotVar/CBotVar.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 76cfe2b5..d528d1f7 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -75,6 +75,7 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 7796786a..75beb6fb 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -25,6 +25,8 @@ #include "CBotUtils.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index 6611129c..2bcc41c8 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -23,6 +23,8 @@ #include "CBotUtils.h" #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 741dfb97..9e20d667 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -33,6 +33,8 @@ #include "CBotUtils.h" #include "CBotCallMethode.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index 3cc4f9f9..fe385461 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -24,6 +24,8 @@ #include "CBotProgram.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 2c6e34d7..d09e3ca2 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -26,3 +26,10 @@ // Global include #define MAXARRAYSIZE 9999 + + +// variable type SetPrivate / IsPrivate +#define PR_PUBLIC 0 // public variable +#define PR_READ 1 // read only +#define PR_PROTECT 2 // protected (inheritance) +#define PR_PRIVATE 3 // strictly private diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 6bd16030..56b43642 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -494,231 +494,6 @@ bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception) #endif -///////////////////////////////////////////////////////////////////////////////// -// Class for managing variables - -// may be useful to the outside of the module -// ( it is currently not expected to be able to create these objects in outer ) - -// variable type SetPrivate / IsPrivate -#define PR_PUBLIC 0 // public variable -#define PR_READ 1 // read only -#define PR_PROTECT 2 // protected (inheritance) -#define PR_PRIVATE 3 // strictly private - -class CBotVar -{ -public: - // results of GetInit() - enum class InitType : int { UNDEF = 0, DEF = 1, IS_POINTER = 2, IS_NAN = 999 }; - -protected: - CBotToken* m_token; // the corresponding token - - CBotVar* m_next; // list of variables - friend class CBotStack; - friend class CBotCStack; - friend class CBotInstrCall; - friend class CBotProgram; - - CBotTypResult m_type; // type of value - - InitType m_binit; // not initialized? - CBotVarClass* m_pMyThis; // ^ corresponding this element - void* m_pUserPtr; // ^user data if necessary - bool m_bStatic; // static element (in class) - int m_mPrivate; // element public, protected or private? - - CBotInstr* m_InitExpr; // expression for the original content - CBotInstr* m_LimExpr; // list of limits for a table - friend class CBotClass; - friend class CBotVarClass; - friend class CBotVarPointer; - friend class CBotVarArray; - - long m_ident; // unique identifier - static long m_identcpt; // counter - -public: - CBotVar(); -virtual ~CBotVar( ); // destructor - - static - CBotVar* Create( const char* name, CBotTypResult type); - // creates from a complete type - - static - CBotVar* Create( const char* name, CBotClass* pClass); - // creates from one instance of a known class - - static - CBotVar* Create( const CBotToken* name, int type ); - static - CBotVar* Create( const CBotToken* name, CBotTypResult type ); - - static - CBotVar* Create( const char* name, int type, CBotClass* pClass); - - static - CBotVar* Create( CBotVar* pVar ); - - static void Destroy(CBotVar* var); - - - void SetUserPtr(void* pUser); - // associate a user pointer to an instance - - virtual void SetIdent(long UniqId); - // associates a unique identifier to an instance - // ( it is used to ensure that the id is unique) - - void* GetUserPtr(); - // makes the pointer associated with the variable - - CBotString GetName(); // the name of the variable, if known - //////////////////////////////////////////////////////////////////////////////////// - void SetName(const char* name); // changes the name of the variable - - int GetType(int mode = 0); // returns the base type (int) of the variable - // TODO check it - //////////////////////////////////////////////////////////////////////////////////////// - - CBotTypResult GetTypResult(int mode = 0); // returns the complete type of the variable - - - CBotToken* GetToken(); - void SetType(CBotTypResult& type); - - void SetInit(InitType initType); // is the variable in the state UNDEF, DEF, NAN - InitType GetInit() const; // gives the state of the variable - bool IsUndefined() const { return GetInit() == InitType::UNDEF; } - bool IsDefined() const { return GetInit() == InitType::DEF; } - bool IsNAN() const { return GetInit() == InitType::IS_NAN; } - - void SetStatic(bool bStatic); - bool IsStatic(); - - void SetPrivate(int mPrivate); - bool IsPrivate(int mode = PR_PROTECT); - int GetPrivate(); - - virtual - void ConstructorSet(); - - void SetVal(CBotVar* var); // remprend une valeur - // TODO remprend value - virtual - CBotVar* GetItem(const char* name); // returns an element of a class according to its name (*) - virtual - CBotVar* GetItemRef(int nIdent); // idem à partir du n° ref - // TODO ditto from ref no. - virtual - CBotVar* GetItem(int row, bool bGrow = false); - - virtual - CBotVar* GetItemList(); // lists the elements - - CBotVar* GetStaticVar(); // makes the pointer to the variable if it is static - - bool IsElemOfClass(const char* name); - // said if the element belongs to the class "name" - // makes true if the object is a subclass - - CBotVar* GetNext(); // next variable in the list (parameters) - //////////////////////////////////////////////////////////////////////////////////////////// - - void AddNext(CBotVar* pVar); // added to a list - - virtual - void Copy(CBotVar* pSrc, bool bName = true); // makes a copy of the variable - - virtual void SetValInt(int val, const char* name = nullptr); - // initialized with an integer value (#) - ///////////////////////////////////////////////////////////////////////////////// - - virtual void SetValFloat(float val); // initialized with a real value (#) - //////////////////////////////////////////////////////////////////////////////// - - virtual void SetValString(const char* p);// initialized with a string value (#) - //////////////////////////////////////////////////////////////////////////////// - - virtual int GetValInt(); // request the full value (#) - //////////////////////////////////////////////////////////////////////// - - virtual float GetValFloat(); // gets real value (#) - /////////////////////////////////////////////////////////////////////// - - virtual - CBotString GetValString(); // request the string value (#) - /////////////////////////////////////////////////////////////////////// - - virtual void SetClass(CBotClass* pClass); - virtual - CBotClass* GetClass(); - - virtual void SetPointer(CBotVar* p); - virtual - CBotVarClass* GetPointer(); -// virtual void SetIndirection(CBotVar* pVar); - - virtual void Add(CBotVar* left, CBotVar* right); // addition - virtual void Sub(CBotVar* left, CBotVar* right); // subtraction - virtual void Mul(CBotVar* left, CBotVar* right); // multiplication - virtual int Div(CBotVar* left, CBotVar* right); // division - virtual int Modulo(CBotVar* left, CBotVar* right); // remainder of division - virtual void Power(CBotVar* left, CBotVar* right); // power - - virtual bool Lo(CBotVar* left, CBotVar* right); - virtual bool Hi(CBotVar* left, CBotVar* right); - virtual bool Ls(CBotVar* left, CBotVar* right); - virtual bool Hs(CBotVar* left, CBotVar* right); - virtual bool Eq(CBotVar* left, CBotVar* right); - virtual bool Ne(CBotVar* left, CBotVar* right); - - virtual void And(CBotVar* left, CBotVar* right); - virtual void Or(CBotVar* left, CBotVar* right); - virtual void XOr(CBotVar* left, CBotVar* right); - virtual void ASR(CBotVar* left, CBotVar* right); - virtual void SR(CBotVar* left, CBotVar* right); - virtual void SL(CBotVar* left, CBotVar* right); - - virtual void Neg(); - virtual void Not(); - virtual void Inc(); - virtual void Dec(); - - - virtual bool Save0State(FILE* pf); - virtual bool Save1State(FILE* pf); - static bool RestoreState(FILE* pf, CBotVar* &pVar); - - void debug(); - -// virtual -// CBotVar* GetMyThis(); - - virtual - void Maj(void* pUser = nullptr, bool bContinue = true); - - void SetUniqNum(long n); - long GetUniqNum(); - static long NextUniqNum(); -}; - -/* NOTE (#) - methods SetValInt() SetValFloat() et SetValString() - can be called with objects which are respectively integer, real or string - Always be sure of the type of the variable before calling these methods - - if ( pVar->GetType() == CBotInt() ) pVar->SetValFloat( 3.3 ); // plante !! - - methods GetValInt(), GetValFloat() et GetValString() - use value conversions, - GetValString() works on numbers (makes the corresponding string) - but do not make GetValInt () with a string variable! -*/ - - /* //////////////////////////////////////////////////////////////////////// // Examples of use diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index 6fda2dbf..ea0103e5 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -25,6 +25,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index 77b5294d..fdbc1d45 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -24,6 +24,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotEmpty.cpp b/src/CBot/CBotInstr/CBotEmpty.cpp index 0f0ad7ce..4318eadd 100644 --- a/src/CBot/CBotInstr/CBotEmpty.cpp +++ b/src/CBot/CBotInstr/CBotEmpty.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index d0edb1d2..60923754 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp index 3a252676..ebefa6dd 100644 --- a/src/CBot/CBotInstr/CBotExprBool.cpp +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp index 7335219b..a2cb1c65 100644 --- a/src/CBot/CBotInstr/CBotExprNan.cpp +++ b/src/CBot/CBotInstr/CBotExprNan.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNull.cpp b/src/CBot/CBotInstr/CBotExprNull.cpp index d80ef035..cef5eca8 100644 --- a/src/CBot/CBotInstr/CBotExprNull.cpp +++ b/src/CBot/CBotInstr/CBotExprNull.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index 24ba0ac7..6082c0e1 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 2b7c0d6e..4732eda1 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h index 46017e51..a4535659 100644 --- a/src/CBot/CBotInstr/CBotExprVar.h +++ b/src/CBot/CBotInstr/CBotExprVar.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index 3637049b..bdf096a5 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index 70a2c97b..1a721458 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -25,6 +25,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index fd81a441..6700fab7 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -34,6 +34,8 @@ #include "CBotDefParam.h" #include "CBotUtils.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index 91e1a925..3c348111 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -24,6 +24,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index 4bf2fd16..f53cb65e 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -29,6 +29,8 @@ #include "CBotDefines.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index cec9810b..c2c33b0f 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index a33207fb..dabcd463 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index f94d53c5..1649de55 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -26,6 +26,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index ff0bbf15..d0c3482b 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -22,6 +22,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index dc6e2b29..682505b7 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -25,6 +25,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 9da2a88e..094e5a08 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" #include "CBotClass.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index 5d2839e8..fc34b513 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -32,6 +32,8 @@ #include "CBotExprNan.h" #include "CBotExpression.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp index f7fbddab..938274e6 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp index 5fe3d365..30ee9a97 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -23,6 +23,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 816efefb..4ad5ad03 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -25,6 +25,8 @@ #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index eee71e44..b5f9c235 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -24,6 +24,8 @@ #include "CBotClass.h" #include "CBotStack.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp similarity index 70% rename from src/CBot/CBotVar.cpp rename to src/CBot/CBotVar/CBotVar.cpp index d5c248e7..e2c1fe78 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -17,13 +17,9 @@ * along with this program. If not, see http://gnu.org/licenses */ -//////////////////////////////////////////////////////////////////// -// Definition for the class CBotVar -// variables management of the language CBoT -// it never creates an instance of the class mother CBotVar - -#include "CBot.h" +// Modules inlcude +#include "CBotVar.h" #include "CBotStack.h" @@ -37,12 +33,17 @@ #include "CBotClass.h" +// Local include + +// Global include #include #include #include +//////////////////////////////////////////////////////////////////////////////// long CBotVar::m_identcpt = 0; +//////////////////////////////////////////////////////////////////////////////// CBotVar::CBotVar( ) { m_next = nullptr; @@ -57,12 +58,14 @@ CBotVar::CBotVar( ) m_mPrivate = 0; } +//////////////////////////////////////////////////////////////////////////////// CBotVar::~CBotVar( ) { delete m_token; delete m_next; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::debug() { // const char* p = static_cast( m_token->GetString()); @@ -80,11 +83,13 @@ void CBotVar::debug() } } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::ConstructorSet() { // nop } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetUserPtr(void* pUser) { m_pUserPtr = pUser; @@ -93,6 +98,7 @@ void CBotVar::SetUserPtr(void* pUser) (static_cast(this))->m_pVarClass->SetUserPtr(pUser); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetIdent(long n) { if (m_type.Eq(CBotTypPointer) && @@ -100,6 +106,7 @@ void CBotVar::SetIdent(long n) (static_cast(this))->m_pVarClass->SetIdent(n); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetUniqNum(long n) { m_ident = n; @@ -107,23 +114,26 @@ void CBotVar::SetUniqNum(long n) if ( n == 0 ) assert(0); } +//////////////////////////////////////////////////////////////////////////////// long CBotVar::NextUniqNum() { if (++m_identcpt < 10000) m_identcpt = 10000; return m_identcpt; } +//////////////////////////////////////////////////////////////////////////////// long CBotVar::GetUniqNum() { return m_ident; } - +//////////////////////////////////////////////////////////////////////////////// void* CBotVar::GetUserPtr() { return m_pUserPtr; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Save1State(FILE* pf) { // this routine "virtual" must never be called, @@ -133,21 +143,21 @@ bool CBotVar::Save1State(FILE* pf) return false; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Maj(void* pUser, bool bContinu) { /* if (!bContinu && m_pMyThis != nullptr) m_pMyThis->Maj(pUser, true);*/ } - -// creates a variable depending on its type - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create(const CBotToken* name, int type ) { CBotTypResult t(type); return Create(name, t); } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create(const CBotToken* name, CBotTypResult type) { switch (type.GetType()) @@ -201,13 +211,14 @@ CBotVar* CBotVar::Create(const CBotToken* name, CBotTypResult type) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create( CBotVar* pVar ) { CBotVar* p = Create(pVar->m_token->GetString(), pVar->GetTypResult(2)); return p; } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create( const char* n, CBotTypResult type) { CBotToken name(n); @@ -272,6 +283,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) { CBotToken token( name, "" ); @@ -293,6 +305,7 @@ CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) return pVar; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::Create( const char* name, CBotClass* pClass) { CBotToken token( name, "" ); @@ -301,11 +314,13 @@ CBotVar* CBotVar::Create( const char* name, CBotClass* pClass) return pVar; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Destroy(CBotVar* var) { delete var; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotVar::GetTypResult(int mode) { CBotTypResult r = m_type; @@ -318,6 +333,7 @@ CBotTypResult CBotVar::GetTypResult(int mode) return r; } +//////////////////////////////////////////////////////////////////////////////// int CBotVar::GetType(int mode) { if ( mode == 1 && m_type.Eq(CBotTypClass) ) @@ -327,11 +343,13 @@ int CBotVar::GetType(int mode) return m_type.GetType(); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetType(CBotTypResult& type) { m_type = type; } +//////////////////////////////////////////////////////////////////////////////// CBotVar::InitType CBotVar::GetInit() const { if ( m_type.Eq(CBotTypClass) ) return InitType::DEF; // always set! @@ -339,6 +357,7 @@ CBotVar::InitType CBotVar::GetInit() const return m_binit; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetInit(CBotVar::InitType bInit) { m_binit = bInit; @@ -368,46 +387,53 @@ void CBotVar::SetInit(CBotVar::InitType bInit) } } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotVar::GetName() { return m_token->GetString(); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetName(const char* name) { m_token->SetString(name); } +//////////////////////////////////////////////////////////////////////////////// CBotToken* CBotVar::GetToken() { return m_token; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetItem(const char* name) { assert(0); return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetItemRef(int nIdent) { assert(0); return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetItemList() { assert(0); return nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetItem(int row, bool bGrow) { assert(0); return nullptr; } -// check if a variable belongs to a given class +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::IsElemOfClass(const char* name) { CBotClass* pc = nullptr; @@ -430,7 +456,7 @@ bool CBotVar::IsElemOfClass(const char* name) return false; } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetStaticVar() { // makes the pointer to the variable if it is static @@ -440,12 +466,13 @@ CBotVar* CBotVar::GetStaticVar() return pClass->GetItem( m_token->GetString() ); } - +//////////////////////////////////////////////////////////////////////////////// CBotVar* CBotVar::GetNext() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::AddNext(CBotVar* pVar) { CBotVar* p = this; @@ -454,6 +481,7 @@ void CBotVar::AddNext(CBotVar* pVar) p->m_next = pVar; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetVal(CBotVar* var) { switch (var->GetType()) @@ -489,37 +517,43 @@ void CBotVar::SetVal(CBotVar* var) m_binit = var->m_binit; // copie l'état nan s'il y a } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetStatic(bool bStatic) { m_bStatic = bStatic; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetPrivate(int mPrivate) { m_mPrivate = mPrivate; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::IsStatic() { return m_bStatic; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::IsPrivate(int mode) { return m_mPrivate >= mode; } +//////////////////////////////////////////////////////////////////////////////// int CBotVar::GetPrivate() { return m_mPrivate; } - +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetPointer(CBotVar* pVarClass) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// CBotVarClass* CBotVar::GetPointer() { assert(0); @@ -528,167 +562,198 @@ CBotVarClass* CBotVar::GetPointer() // All these functions must be defined in the subclasses // derived from class CBotVar - +//////////////////////////////////////////////////////////////////////////////// int CBotVar::GetValInt() { assert(0); return 0; } +//////////////////////////////////////////////////////////////////////////////// float CBotVar::GetValFloat() { assert(0); return 0; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetValInt(int c, const char* s) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetValFloat(float c) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Mul(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Power(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// int CBotVar::Div(CBotVar* left, CBotVar* right) { assert(0); return 0; } +//////////////////////////////////////////////////////////////////////////////// int CBotVar::Modulo(CBotVar* left, CBotVar* right) { assert(0); return 0; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Add(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Sub(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Lo(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Hi(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Ls(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Hs(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Eq(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// bool CBotVar::Ne(CBotVar* left, CBotVar* right) { assert(0); return false; } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::And(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Or(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::XOr(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::ASR(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SR(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SL(CBotVar* left, CBotVar* right) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Neg() { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Not() { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Inc() { assert(0); } + +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Dec() { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::Copy(CBotVar* pSrc, bool bName) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetValString(const char* p) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotVar::GetValString() { assert(0); return CBotString(); } +//////////////////////////////////////////////////////////////////////////////// void CBotVar::SetClass(CBotClass* pClass) { assert(0); } +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotVar::GetClass() { assert(0); @@ -698,7 +763,7 @@ CBotClass* CBotVar::GetClass() /////////////////////////////////////////////////////// // management of results types - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult(int type) { m_type = type; @@ -707,6 +772,7 @@ CBotTypResult::CBotTypResult(int type) m_limite = -1; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult(int type, const char* name) { m_type = type; @@ -723,6 +789,7 @@ CBotTypResult::CBotTypResult(int type, const char* name) } } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult(int type, CBotClass* pClass) { m_type = type; @@ -733,6 +800,7 @@ CBotTypResult::CBotTypResult(int type, CBotClass* pClass) if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult(int type, CBotTypResult elem) { m_type = type; @@ -745,6 +813,7 @@ CBotTypResult::CBotTypResult(int type, CBotTypResult elem) m_pNext = new CBotTypResult( elem ); } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult(const CBotTypResult& typ) { m_type = typ.m_type; @@ -756,6 +825,7 @@ CBotTypResult::CBotTypResult(const CBotTypResult& typ) m_pNext = new CBotTypResult( *typ.m_pNext ); } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::CBotTypResult() { m_type = 0; @@ -764,11 +834,13 @@ CBotTypResult::CBotTypResult() m_pClass = nullptr; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult::~CBotTypResult() { delete m_pNext; } +//////////////////////////////////////////////////////////////////////////////// int CBotTypResult::GetType(int mode) const { #ifdef _DEBUG @@ -786,31 +858,37 @@ int CBotTypResult::GetType(int mode) const return m_type; } +//////////////////////////////////////////////////////////////////////////////// void CBotTypResult::SetType(int n) { m_type = n; } +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotTypResult::GetClass() const { return m_pClass; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult& CBotTypResult::GetTypElem() const { return *m_pNext; } +//////////////////////////////////////////////////////////////////////////////// int CBotTypResult::GetLimite() const { return m_limite; } +//////////////////////////////////////////////////////////////////////////////// void CBotTypResult::SetLimite(int n) { m_limite = n; } +//////////////////////////////////////////////////////////////////////////////// void CBotTypResult::SetArray( int* max ) { m_limite = *max; @@ -822,8 +900,7 @@ void CBotTypResult::SetArray( int* max ) } } - - +//////////////////////////////////////////////////////////////////////////////// bool CBotTypResult::Compare(const CBotTypResult& typ) const { if ( m_type != typ.m_type ) return false; @@ -840,13 +917,14 @@ bool CBotTypResult::Compare(const CBotTypResult& typ) const return true; } +//////////////////////////////////////////////////////////////////////////////// bool CBotTypResult::Eq(int type) const { return m_type == type; } -CBotTypResult& - CBotTypResult::operator=(const CBotTypResult& src) +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src) { m_type = src.m_type; m_limite = src.m_limite; diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h new file mode 100644 index 00000000..8f465fc8 --- /dev/null +++ b/src/CBot/CBotVar/CBotVar.h @@ -0,0 +1,624 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "../CBotDll.h" + +#include "../CBotDefines.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotVar class Class for managing variables. May be useful to the + * outside of the module ( it is currently not expected to be able to create + * these objects in outer ). It never creates an instance of the class mother + * CBotVar. + */ +class CBotVar +{ +public: + /*! + * \brief The InitType enum Results of GetInit(). + */ + enum class InitType : int + { + UNDEF = 0, + DEF = 1, + IS_POINTER = 2, + IS_NAN = 999 + }; + + /*! + * \brief CBotVar + */ + CBotVar(); + + /*! + * \brief ~CBotVar Destructor. + */ + virtual ~CBotVar( ); + + /*! + * \brief Create Creates from a complete type. + * \param name + * \param type + * \return + */ + static CBotVar* Create( const char* name, CBotTypResult type); + + /*! + * \brief Create Creates from one instance of a known class. + * \param name + * \param pClass + * \return + */ + static CBotVar* Create( const char* name, CBotClass* pClass); + + /*! + * \brief Create Creates a variable depending on its type. + * \param name + * \param type + * \return + */ + static CBotVar* Create( const CBotToken* name, int type ); + + /*! + * \brief Create + * \param name + * \param type + * \return + */ + static CBotVar* Create( const CBotToken* name, CBotTypResult type ); + + /*! + * \brief Create + * \param name + * \param type + * \param pClass + * \return + */ + static CBotVar* Create( const char* name, int type, CBotClass* pClass); + + /*! + * \brief Create + * \param pVar + * \return + */ + static CBotVar* Create( CBotVar* pVar ); + + /*! + * \brief Destroy + * \param var + */ + static void Destroy(CBotVar* var); + + /*! + * \brief SetUserPtr Associate a user pointer to an instance. + * \param pUser + */ + void SetUserPtr(void* pUser); + + /*! + * \brief SetIdent Associates a unique identifier to an instance + * ( it is used to ensure that the id is unique) + * \param UniqId + */ + virtual void SetIdent(long UniqId); + + /*! + * \brief GetUserPtr Makes the pointer associated with the variable. + * \return + */ + void* GetUserPtr(); + + /*! + * \brief GetName The name of the variable, if known. + * \return + */ + CBotString GetName(); + + /*! + * \brief SetName Changes the name of the variable + * \param name + */ + void SetName(const char* name); + + /*! + * \brief GetType Returns the base type (int) of the variable + * \param mode + * \return + * \todo Check it? + */ + int GetType(int mode = 0); + + /*! + * \brief GetTypResult Returns the complete type of the variable. + * \param mode + * \return + */ + CBotTypResult GetTypResult(int mode = 0); + + /*! + * \brief GetToken + * \return + */ + CBotToken* GetToken(); + + /*! + * \brief SetType + * \param type + */ + void SetType(CBotTypResult& type); + + /*! + * \brief SetInit Is the variable in the state UNDEF, DEF, NAN. + * \param initType + */ + void SetInit(InitType initType); + + /*! + * \brief GetInit Gives the state of the variable. + * \return + */ + InitType GetInit() const; + + /*! + * \brief IsUndefined + * \return + */ + bool IsUndefined() const { return GetInit() == InitType::UNDEF; } + + /*! + * \brief IsDefined + * \return + */ + bool IsDefined() const { return GetInit() == InitType::DEF; } + + /*! + * \brief IsNAN + * \return + */ + bool IsNAN() const { return GetInit() == InitType::IS_NAN; } + + /*! + * \brief SetStatic + * \param bStatic + */ + void SetStatic(bool bStatic); + + /*! + * \brief IsStatic + * \return + */ + bool IsStatic(); + + /*! + * \brief SetPrivate + * \param mPrivate + */ + void SetPrivate(int mPrivate); + + /*! + * \brief IsPrivate + * \param mode + * \return + */ + bool IsPrivate(int mode = PR_PROTECT); + + /*! + * \brief GetPrivate + * \return + */ + int GetPrivate(); + + /*! + * \brief ConstructorSet + */ + virtual void ConstructorSet(); + + /*! + * \brief SetVal Set the value. + * \param var + */ + void SetVal(CBotVar* var); + + /*! + * \brief GetItem Returns an element of a class according to its name (*). + * \param name + * \return + */ + virtual CBotVar* GetItem(const char* name); + + /*! + * \brief GetItemRef + * \param nIdent + * \return + */ + virtual CBotVar* GetItemRef(int nIdent); + + /*! + * \brief GetItem + * \param row + * \param bGrow + * \return + */ + virtual CBotVar* GetItem(int row, bool bGrow = false); + + /*! + * \brief GetItemList Lists the elements. + * \return + */ + virtual CBotVar* GetItemList(); + + /*! + * \brief GetStaticVar Makes the pointer to the variable if it is static. + * \return + */ + CBotVar* GetStaticVar(); + + /*! + * \brief IsElemOfClass Check if a variable belongs to a given class said if + * the element belongs to the class "name" makes true if the object is a + * subclass. + * \param name + * \return + */ + bool IsElemOfClass(const char* name); + + /*! + * \brief GetNext Next variable in the list (parameters). + * \return + */ + CBotVar* GetNext(); + + /*! + * \brief AddNext Added to a list. + * \param pVar + */ + void AddNext(CBotVar* pVar); + + /*! + * \brief Copy Makes a copy of the variable. + * \param pSrc + * \param bName + */ + virtual void Copy(CBotVar* pSrc, bool bName = true); + + /*! + * \brief SetValInt Initialized with an integer value (#) + * \param val + * \param name + */ + virtual void SetValInt(int val, const char* name = nullptr); + + /*! + * \brief SetValFloat Initialized with a real value (#). + * \param val + */ + virtual void SetValFloat(float val); + + /*! + * \brief SetValString Initialized with a string value (#). + * \param p + */ + virtual void SetValString(const char* p); + + /*! + * \brief GetValInt Request the full value (#). + * \return + */ + virtual int GetValInt(); + + /*! + * \brief GetValFloat Gets real value (#). + * \return + */ + virtual float GetValFloat(); + + /*! + * \brief GetValString Request the string value (#). + * \return + */ + virtual CBotString GetValString(); + + /*! + * \brief SetClass + * \param pClass + */ + virtual void SetClass(CBotClass* pClass); + + /*! + * \brief GetClass + * \return + */ + virtual CBotClass* GetClass(); + + /*! + * \brief SetPointer + * \param p + */ + virtual void SetPointer(CBotVar* p); + + /*! + * \brief GetPointer + * \return + */ + virtual CBotVarClass* GetPointer(); + + /*! + * \brief Add Addition + * \param left + * \param right + */ + virtual void Add(CBotVar* left, CBotVar* right); + + /*! + * \brief Sub Subtraction + * \param left + * \param right + */ + virtual void Sub(CBotVar* left, CBotVar* right); + + /*! + * \brief Mul Multiplication + * \param left + * \param right + */ + virtual void Mul(CBotVar* left, CBotVar* right); + + /*! + * \brief Div Division + * \param left + * \param right + * \return + */ + virtual int Div(CBotVar* left, CBotVar* right); + + /*! + * \brief Modulo Remainder of division + * \param left + * \param right + * \return + */ + virtual int Modulo(CBotVar* left, CBotVar* right); + + /*! + * \brief Power + * \param left + * \param right + */ + virtual void Power(CBotVar* left, CBotVar* right); + + /*! + * \brief Lo + * \param left + * \param right + * \return + */ + virtual bool Lo(CBotVar* left, CBotVar* right); + + /*! + * \brief Hi + * \param left + * \param right + * \return + */ + virtual bool Hi(CBotVar* left, CBotVar* right); + + /*! + * \brief Ls + * \param left + * \param right + * \return + */ + virtual bool Ls(CBotVar* left, CBotVar* right); + + /*! + * \brief Hs + * \param left + * \param right + * \return + */ + virtual bool Hs(CBotVar* left, CBotVar* right); + + /*! + * \brief Eq + * \param left + * \param right + * \return + */ + virtual bool Eq(CBotVar* left, CBotVar* right); + + /*! + * \brief Ne + * \param left + * \param right + * \return + */ + virtual bool Ne(CBotVar* left, CBotVar* right); + + /*! + * \brief And + * \param left + * \param right + */ + virtual void And(CBotVar* left, CBotVar* right); + + /*! + * \brief Or + * \param left + * \param right + */ + virtual void Or(CBotVar* left, CBotVar* right); + + /*! + * \brief XOr + * \param left + * \param right + */ + virtual void XOr(CBotVar* left, CBotVar* right); + + /*! + * \brief ASR + * \param left + * \param right + */ + virtual void ASR(CBotVar* left, CBotVar* right); + + /*! + * \brief SR + * \param left + * \param right + */ + virtual void SR(CBotVar* left, CBotVar* right); + + /*! + * \brief SL + * \param left + * \param right + */ + virtual void SL(CBotVar* left, CBotVar* right); + + /*! + * \brief Neg + */ + virtual void Neg(); + + /*! + * \brief Not + */ + virtual void Not(); + + /*! + * \brief Inc + */ + virtual void Inc(); + + /*! + * \brief Dec + */ + virtual void Dec(); + + /*! + * \brief Save0State + * \param pf + * \return + */ + virtual bool Save0State(FILE* pf); + + /*! + * \brief Save1State + * \param pf + * \return + */ + virtual bool Save1State(FILE* pf); + + /*! + * \brief RestoreState + * \param pf + * \param pVar + * \return + */ + static bool RestoreState(FILE* pf, CBotVar* &pVar); + + /*! + * \brief debug + */ + void debug(); + + /*! + * \brief Maj + * \param pUser + * \param bContinue + */ + virtual void Maj(void* pUser = nullptr, bool bContinue = true); + + /*! + * \brief SetUniqNum + * \param n + */ + void SetUniqNum(long n); + + /*! + * \brief GetUniqNum + * \return + */ + long GetUniqNum(); + + /*! + * \brief NextUniqNum + * \return + */ + static long NextUniqNum(); + +protected: + + //! The corresponding token. + CBotToken* m_token; + //! List of variables. + CBotVar* m_next; + //! Type of value. + CBotTypResult m_type; + //! Not initialized. + InitType m_binit; + //! Corresponding this element. + CBotVarClass* m_pMyThis; + //! User data if necessary. + void* m_pUserPtr; + //! Static element (in class). + bool m_bStatic; + //! Element public, protected or private. + int m_mPrivate; + //! Expression for the original content. + CBotInstr* m_InitExpr; + //! List of limits for a table. + CBotInstr* m_LimExpr; + //! Unique identifier. + long m_ident; + + //! Counter + static long m_identcpt; + + friend class CBotStack; + friend class CBotCStack; + friend class CBotInstrCall; + friend class CBotProgram; + friend class CBotClass; + friend class CBotVarClass; + friend class CBotVarPointer; + friend class CBotVarArray; +}; + +/* NOTE (#) + methods SetValInt() SetValFloat() et SetValString() + can be called with objects which are respectively integer, real or string + Always be sure of the type of the variable before calling these methods + + if ( pVar->GetType() == CBotInt() ) pVar->SetValFloat( 3.3 ); // plante !! + + methods GetValInt(), GetValFloat() et GetValString() + use value conversions, + GetValString() works on numbers (makes the corresponding string) + but do not make GetValInt () with a string variable! +*/ diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h index 158cdf81..65222ac6 100644 --- a/src/CBot/CBotVar/CBotVarArray.h +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -23,6 +23,8 @@ #include "CBot.h" #include "CBotDefines.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h index e57c22f7..f21cf285 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.h +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotToken.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index b7b878f9..5089c408 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index fb30cd49..07a3ecc6 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 741fdc10..65ebb8c3 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h index dbb6ea39..278fbd8d 100644 --- a/src/CBot/CBotVar/CBotVarPointer.h +++ b/src/CBot/CBotVar/CBotVarPointer.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotDll.h" +#include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 31c776e2..93007bee 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 6e8a8039..87303c44 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -5,7 +5,6 @@ set(SOURCES CBotStack.cpp CBotString.cpp CBotToken.cpp - CBotVar.cpp CBotCall.cpp CBotUtils.cpp CBotDefParam.cpp @@ -62,6 +61,7 @@ set(SOURCES CBotVar/CBotVarString.cpp CBotVar/CBotVarFloat.cpp CBotVar/CBotVarInt.cpp + CBotVar/CBotVar.cpp ) # Includes diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp index 975421b2..640efc19 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/StringFunctions.cpp @@ -17,12 +17,15 @@ * along with this program. If not, see http://gnu.org/licenses */ +#include "CBotVar/CBotVar.h" + // definition of string functions // gives the length of a chain // execution + bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter diff --git a/src/script/script.cpp b/src/script/script.cpp index 4ba1f173..d87a41a6 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -43,6 +43,7 @@ #include "ui/controls/list.h" #include "CBot/CBotToken.h" +#include "CBot/CBotVar/CBotVar.h" const int CBOT_IPF = 100; // CBOT: default number of instructions / frame diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 7ff61714..252f09df 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -21,6 +21,7 @@ // TODO must be replaced by CBot.h #include "CBot/CBotClass.h" +#include "CBot/CBotVar/CBotVar.h" #include "app/app.h" From 013be673ce18ef139b5b3a4580c0eae3b5c883d5 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 15 Nov 2015 23:41:24 +0100 Subject: [PATCH 117/360] Moving CBotCStack class in its own header and source files. --- src/CBot/CBot.cpp | 1 + src/CBot/CBot.h | 76 ---- src/CBot/CBotCStack.cpp | 405 ++++++++++++++++++++++ src/CBot/CBotCStack.h | 267 ++++++++++++++ src/CBot/CBotCall.cpp | 3 +- src/CBot/CBotCallMethode.cpp | 1 + src/CBot/CBotClass.cpp | 1 + src/CBot/CBotDefParam.cpp | 1 + src/CBot/CBotInstr/CBotBlock.cpp | 2 + src/CBot/CBotInstr/CBotBoolExpr.cpp | 2 + src/CBot/CBotInstr/CBotBoolean.cpp | 1 + src/CBot/CBotInstr/CBotBreak.cpp | 1 + src/CBot/CBotInstr/CBotCase.cpp | 1 + src/CBot/CBotInstr/CBotCatch.cpp | 1 + src/CBot/CBotInstr/CBotClassInst.cpp | 1 + src/CBot/CBotInstr/CBotCondition.cpp | 2 + src/CBot/CBotInstr/CBotDo.cpp | 1 + src/CBot/CBotInstr/CBotExprAlpha.cpp | 1 + src/CBot/CBotInstr/CBotExprBool.cpp | 1 + src/CBot/CBotInstr/CBotExprNum.cpp | 1 + src/CBot/CBotInstr/CBotExprUnaire.cpp | 1 + src/CBot/CBotInstr/CBotExprVar.cpp | 1 + src/CBot/CBotInstr/CBotExpression.cpp | 1 + src/CBot/CBotInstr/CBotFieldExpr.cpp | 1 + src/CBot/CBotInstr/CBotFloat.cpp | 1 + src/CBot/CBotInstr/CBotFor.cpp | 1 + src/CBot/CBotInstr/CBotFunction.cpp | 1 + src/CBot/CBotInstr/CBotIString.cpp | 1 + src/CBot/CBotInstr/CBotIf.cpp | 1 + src/CBot/CBotInstr/CBotIndexExpr.cpp | 1 + src/CBot/CBotInstr/CBotInstArray.cpp | 1 + src/CBot/CBotInstr/CBotInstrCall.cpp | 1 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 1 + src/CBot/CBotInstr/CBotInt.cpp | 1 + src/CBot/CBotInstr/CBotLeftExpr.cpp | 1 + src/CBot/CBotInstr/CBotLeftExprVar.cpp | 1 + src/CBot/CBotInstr/CBotListArray.cpp | 1 + src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CBotInstr/CBotListInstr.cpp | 1 + src/CBot/CBotInstr/CBotNew.cpp | 1 + src/CBot/CBotInstr/CBotParExpr.cpp | 2 + src/CBot/CBotInstr/CBotReturn.cpp | 1 + src/CBot/CBotInstr/CBotSwitch.cpp | 1 + src/CBot/CBotInstr/CBotThrow.cpp | 1 + src/CBot/CBotInstr/CBotTry.cpp | 1 + src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 1 + src/CBot/CBotInstr/CBotWhile.cpp | 1 + src/CBot/CBotProgram.cpp | 1 + src/CBot/CBotStack.cpp | 389 --------------------- src/CBot/CBotUtils.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 51 files changed, 724 insertions(+), 466 deletions(-) create mode 100644 src/CBot/CBotCStack.cpp create mode 100644 src/CBot/CBotCStack.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index d528d1f7..1c8b4379 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -73,6 +73,7 @@ #include "CBotInstr/CBotInt.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 98d3f9ce..e42d1851 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -52,82 +52,6 @@ class CBotIf; // if (...) {...} else {...} class CBotDefParam; // paramerer list of a function - - - -//////////////////////////////////////////////////////////////////////// -// Management of the stack of compilation -//////////////////////////////////////////////////////////////////////// - - -class CBotCStack -{ -private: - CBotCStack* m_next; - CBotCStack* m_prev; - - static int m_error; - static int m_end; - int m_start; - - CBotVar* m_var; // result of the operations - - bool m_bBlock; // is part of a block (variables are local to this block) - CBotVar* m_listVar; - - static - CBotProgram* m_prog; // list of compiled functions - static - CBotTypResult m_retTyp; -// static -// CBotToken* m_retClass; - -public: - CBotCStack(CBotCStack* ppapa); - ~CBotCStack(); - - bool IsOk(); - int GetError(); - int GetError(int& start, int& end); - // gives error number - - void SetType(CBotTypResult& type);// determines the type - CBotTypResult GetTypResult(int mode = 0); // gives the type of value on the stack - int GetType(int mode = 0); // gives the type of value on the stack - CBotClass* GetClass(); // gives the class of the value on the stack - - void AddVar(CBotVar* p); // adds a local variable - CBotVar* FindVar(CBotToken* &p); // finds a variable - CBotVar* FindVar(CBotToken& Token); - bool CheckVarLocal(CBotToken* &pToken); - CBotVar* CopyVar(CBotToken& Token); // finds and makes a copy - - CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false); - CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper - CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper - - void SetVar( CBotVar* var ); - void SetCopyVar( CBotVar* var ); - CBotVar* GetVar(); - - void SetStartError(int pos); - void SetError(int n, int pos); - void SetError(int n, CBotToken* p); - void ResetError(int n, int start, int end); - - void SetRetType(CBotTypResult& type); - CBotTypResult GetRetType(); - -// void SetBotCall(CBotFunction* &pFunc); - void SetBotCall(CBotProgram* p); - CBotProgram* GetBotCall(); - CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent); - bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); - - bool NextToken(CBotToken* &p); -}; - - extern bool SaveVar(FILE* pf, CBotVar* pVar); diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp new file mode 100644 index 00000000..6d9b820e --- /dev/null +++ b/src/CBot/CBotCStack.cpp @@ -0,0 +1,405 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + + +// Modules inlcude +#include "CBotCStack.h" + +#include "CBotToken.h" +#include "CBotCall.h" + +#include "CBotVar/CBotVar.h" + +#include "CBotInstr/CBotFunction.h" + +// Local include + +// Global include + + + +//////////////////////////////////////////////////////////////////////////////// +CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable +int CBotCStack::m_error = 0; +int CBotCStack::m_end = 0; +CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack::CBotCStack(CBotCStack* ppapa) +{ + m_next = nullptr; + m_prev = ppapa; + + if (ppapa == nullptr) + { + m_error = 0; + m_start = 0; + m_end = 0; + m_bBlock = true; + } + else + { + m_start = ppapa->m_start; + m_bBlock = false; + } + + m_listVar = nullptr; + m_var = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack::~CBotCStack() +{ + if (m_next != nullptr) delete m_next; + if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain + + delete m_var; + delete m_listVar; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) +{ + if (m_next != nullptr) return m_next; // include on an existing stack + + CBotCStack* p = new CBotCStack(this); + m_next = p; // channel element + p->m_bBlock = bBlock; + + if (pToken != nullptr) p->SetStartError(pToken->GetStart()); + + return p; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) +{ + if ( pfils == this ) return inst; + + if (m_var != nullptr) delete m_var; // value replaced? + m_var = pfils->m_var; // result transmitted + pfils->m_var = nullptr; // not to destroy the variable + + if (m_error) + { + m_start = pfils->m_start; // retrieves the position of the error + m_end = pfils->m_end; + } + + delete pfils; + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) +{ + if (m_var != nullptr) delete m_var; // value replaced? + m_var = pfils->m_var; // result transmitted + pfils->m_var = nullptr; // not to destroy the variable + + if (m_error) + { + m_start = pfils->m_start; // retrieves the position of the error + m_end = pfils->m_end; + } + + delete pfils; + return inst; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetError(int& start, int& end) +{ + start = m_start; + end = m_end; + return m_error; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetError() +{ + return m_error; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::GetTypResult(int mode) +{ + if (m_var == nullptr) + return CBotTypResult(99); + return m_var->GetTypResult(mode); +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotCStack::GetType(int mode) +{ + if (m_var == nullptr) + return 99; + return m_var->GetType(mode); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotCStack::GetClass() +{ + if ( m_var == nullptr ) + return nullptr; + if ( m_var->GetType(1) != CBotTypPointer ) return nullptr; + + return m_var->GetClass(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetType(CBotTypResult& type) +{ + if (m_var == nullptr) return; + m_var->SetType( type ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::FindVar(CBotToken* &pToken) +{ + CBotCStack* p = this; + CBotString name = pToken->GetString(); + + while (p != nullptr) + { + CBotVar* pp = p->m_listVar; + while ( pp != nullptr) + { + if (name == pp->GetName()) + { + return pp; + } + pp = pp->m_next; + } + p = p->m_prev; + } + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::FindVar(CBotToken& Token) +{ + CBotToken* pt = &Token; + return FindVar(pt); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::CopyVar(CBotToken& Token) +{ + CBotVar* pVar = FindVar( Token ); + + if ( pVar == nullptr) return nullptr; + + CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() ); + pCopy->Copy(pVar); + return pCopy; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::IsOk() +{ + return (m_error == 0); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetStartError( int pos ) +{ + if ( m_error != 0) return; // does not change existing error + m_start = pos; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetError(int n, int pos) +{ + if ( n!= 0 && m_error != 0) return; // does not change existing error + m_error = n; + m_end = pos; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetError(int n, CBotToken* p) +{ + if (m_error) return; // does not change existing error + m_error = n; + m_start = p->GetStart(); + m_end = p->GetEnd(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::ResetError(int n, int start, int end) +{ + m_error = n; + m_start = start; + m_end = end; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::NextToken(CBotToken* &p) +{ + CBotToken* pp = p; + + p = p->GetNext(); + if (p!=nullptr) return true; + + SetError(TX_ENDOF, pp->GetEnd()); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetBotCall(CBotProgram* p) +{ + m_prog = p; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotProgram* CBotCStack::GetBotCall() +{ + return m_prog; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetRetType(CBotTypResult& type) +{ + m_retTyp = type; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::GetRetType() +{ + return m_retTyp; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetVar( CBotVar* var ) +{ + if (m_var) delete m_var; // replacement of a variable + m_var = var; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::SetCopyVar( CBotVar* var ) +{ + if (m_var) delete m_var; // replacement of a variable + + if ( var == nullptr ) return; + m_var = CBotVar::Create("", var->GetTypResult(2)); + m_var->Copy( var ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotVar* CBotCStack::GetVar() +{ + return m_var; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotCStack::AddVar(CBotVar* pVar) +{ + CBotCStack* p = this; + + // returns to the father element + while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; + + if ( p == nullptr ) return; + + CBotVar** pp = &p->m_listVar; + while ( *pp != nullptr ) pp = &(*pp)->m_next; + + *pp = pVar; // added after + +#ifdef _DEBUG + if ( pVar->GetUniqNum() == 0 ) assert(0); +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::CheckVarLocal(CBotToken* &pToken) +{ + CBotCStack* p = this; + CBotString name = pToken->GetString(); + + while (p != nullptr) + { + CBotVar* pp = p->m_listVar; + while ( pp != nullptr) + { + if (name == pp->GetName()) + return true; + pp = pp->m_next; + } + if ( p->m_bBlock ) return false; + p = p->m_prev; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) +{ + nIdent = 0; + CBotTypResult val(-1); + + val = CBotCall::CompileCall(p, ppVars, this, nIdent); + if (val.GetType() < 0) + { + val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent); + if ( val.GetType() < 0 ) + { + // pVar = nullptr; // the error is not on a particular parameter + SetError( -val.GetType(), p ); + val.SetType(-val.GetType()); + return val; + } + } + return val; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) +{ + CBotString name = pToken->GetString(); + + if ( CBotCall::CheckCall(name) ) return true; + + CBotFunction* pp = m_prog->GetFunctions(); + while ( pp != nullptr ) + { + if ( pToken->GetString() == pp->GetName() ) + { + // are parameters exactly the same? + if ( pp->CheckParam( pParam ) ) + return true; + } + pp = pp->Next(); + } + + pp = CBotFunction::m_listPublic; + while ( pp != nullptr ) + { + if ( pToken->GetString() == pp->GetName() ) + { + // are parameters exactly the same? + if ( pp->CheckParam( pParam ) ) + return true; + } + pp = pp->m_nextpublic; + } + + return false; +} diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h new file mode 100644 index 00000000..28e9e886 --- /dev/null +++ b/src/CBot/CBotCStack.h @@ -0,0 +1,267 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +#include "CBotProgram.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotCStack class Management of the stack of compilation. + */ +class CBotCStack +{ +public: + + /*! + * \brief CBotCStack + * \param ppapa + */ + CBotCStack(CBotCStack* ppapa); + + /*! + * \brief CBotCStack Destructor. + */ + ~CBotCStack(); + + /*! + * \brief IsOk + * \return + */ + bool IsOk(); + + /*! + * \brief GetError + * \return + */ + int GetError(); + + /*! + * \brief GetError Gives error number + * \param start + * \param end + * \return + */ + int GetError(int& start, int& end); + + /*! + * \brief SetType Set the type of instruction on the stack. + * \param type + */ + void SetType(CBotTypResult& type); + + /*! + * \brief GetTypResult Gives the type of value on the stack. Type of + * instruction on the stack. + * \param mode + * \return + */ + CBotTypResult GetTypResult(int mode = 0); + + /*! + * \brief GetType Gives the type of value on the stack. + * \param mode + * \return + */ + int GetType(int mode = 0); + + /*! + * \brief GetClass Gives the class of the value on the stack. + * \return + */ + CBotClass* GetClass(); + + /*! + * \brief AddVar Adds a local variable. + * \param p + */ + void AddVar(CBotVar* p); + + /*! + * \brief FindVar Finds a variable. Seeks a variable on the stack the token + * may be a result of TokenTypVar (object of a class) or a pointer in the + * source. + * \param p + * \return + */ + CBotVar* FindVar(CBotToken* &p); + + /*! + * \brief FindVar + * \param Token + * \return + */ + CBotVar* FindVar(CBotToken& Token); + + /*! + * \brief CheckVarLocal Test whether a variable is already defined locally. + * \param pToken + * \return + */ + bool CheckVarLocal(CBotToken* &pToken); + + /*! + * \brief CopyVar Finds and makes a copy. + * \param Token + * \return + */ + CBotVar* CopyVar(CBotToken& Token); + + /*! + * \brief TokenStack Used only at compile. + * \param pToken + * \param bBlock + * \return + */ + CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false); + + /*! + * \brief Return Transmits the result upper. + * \param p + * \param pParent + * \return + */ + CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); + + /*! + * \brief ReturnFunc Transmits the result upper. + * \param p + * \param pParent + * \return + */ + CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); + + /*! + * \brief SetVar + * \param var + */ + void SetVar( CBotVar* var ); + + /*! + * \brief SetCopyVar Puts on the stack a copy of a variable. + * \param var + */ + void SetCopyVar( CBotVar* var ); + + /*! + * \brief GetVar + * \return + */ + CBotVar* GetVar(); + + /*! + * \brief SetStartError + * \param pos + */ + void SetStartError(int pos); + + /*! + * \brief SetError + * \param n + * \param pos + */ + void SetError(int n, int pos); + + /*! + * \brief SetError + * \param n + * \param p + */ + void SetError(int n, CBotToken* p); + + /*! + * \brief ResetError + * \param n + * \param start + * \param end + */ + void ResetError(int n, int start, int end); + + /*! + * \brief SetRetType + * \param type + */ + void SetRetType(CBotTypResult& type); + + /*! + * \brief GetRetType + * \return + */ + CBotTypResult GetRetType(); + + /*! + * \brief SetBotCall + * \param p + */ + void SetBotCall(CBotProgram* p); + + /*! + * \brief GetBotCall + * \return + */ + CBotProgram* GetBotCall(); + + /*! + * \brief CompileCall + * \param p + * \param ppVars + * \param nIdent + * \return + */ + CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent); + + /*! + * \brief CheckCall Test if a procedure name is already defined somewhere. + * \param pToken + * \param pParam + * \return + */ + bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); + + /*! + * \brief NextToken + * \param p + * \return + */ + bool NextToken(CBotToken* &p); + +private: + CBotCStack* m_next; + CBotCStack* m_prev; + + static int m_error; + static int m_end; + int m_start; + + //! Result of the operations. + CBotVar* m_var; + //! Is part of a block (variables are local to this block). + bool m_bBlock; + CBotVar* m_listVar; + //! List of compiled functions. + static CBotProgram* m_prog; + static CBotTypResult m_retTyp; +}; diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 75beb6fb..ee853d8a 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -22,11 +22,12 @@ #include "CBotToken.h" #include "CBotStack.h" - +#include "CBotCStack.h" #include "CBotUtils.h" #include "CBotVar/CBotVar.h" + // Local include // Global include diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index 2bcc41c8..da915dfb 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -22,6 +22,7 @@ #include "CBotUtils.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 9e20d667..94a05346 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -30,6 +30,7 @@ #include "CBotCall.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotUtils.h" #include "CBotCallMethode.h" diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 601e5676..9af6043f 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -23,6 +23,7 @@ #include "CBot.h" #include "CBotUtils.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarClass.h" diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp index ed87b53b..ba2b5ce5 100644 --- a/src/CBot/CBotInstr/CBotBlock.cpp +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -19,6 +19,8 @@ // Modules inlcude #include "CBotBlock.h" + +#include "CBotCStack.h" #include "CBotListInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index 2815c8ed..db6b36bd 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -21,6 +21,8 @@ #include "CBotBoolExpr.h" #include "CBotTwoOpExpr.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index ea0103e5..64c4d3d3 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index 5879f0f8..9d4100cb 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -21,6 +21,7 @@ #include "CBotBreak.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index f188f8ed..3ae5b706 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -22,6 +22,7 @@ #include "CBotExprNum.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index fdbc1d45..26f7d17d 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -23,6 +23,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index 8426422b..5d2e0a66 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarPointer.h" diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp index d87c451b..453e26c8 100644 --- a/src/CBot/CBotInstr/CBotCondition.cpp +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -21,6 +21,8 @@ #include "CBotCondition.h" #include "CBotBoolExpr.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index 9cfeddb3..c24baff5 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -23,6 +23,7 @@ #include "CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index 60923754..1f93b89a 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -21,6 +21,7 @@ #include "CBotExprAlpha.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp index ebefa6dd..3df5095f 100644 --- a/src/CBot/CBotInstr/CBotExprBool.cpp +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -21,6 +21,7 @@ #include "CBotExprBool.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index 6082c0e1..65dbd780 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -21,6 +21,7 @@ #include "CBotExprNum.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 4732eda1..31056bb3 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -22,6 +22,7 @@ #include "CBotParExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 344ce85c..ee4a748e 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -25,6 +25,7 @@ #include "CBotFieldExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index bdf096a5..b6b97837 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -22,6 +22,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index bad06d93..7c4ff58c 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -21,6 +21,7 @@ #include "CBotFieldExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarClass.h" diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index 1a721458..df69b07f 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -24,6 +24,7 @@ #include "CBotInstArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 7cbca510..2a97b86b 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -24,6 +24,7 @@ #include "CBotBoolExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 6700fab7..d325020e 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -30,6 +30,7 @@ #include "CBotInstr/CBotListArray.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotDefParam.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index 3c348111..6feefc41 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -23,6 +23,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp index b0cdbc88..1075f65f 100644 --- a/src/CBot/CBotInstr/CBotIf.cpp +++ b/src/CBot/CBotInstr/CBotIf.cpp @@ -23,6 +23,7 @@ #include "CBotInstr/CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 2bc37f1e..471089c3 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -21,6 +21,7 @@ #include "CBotIndexExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index f53cb65e..7d2a441e 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -26,6 +26,7 @@ #include "CBotEmpty.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotDefines.h" diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index c2c33b0f..ca21b87d 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index dabcd463..46adf723 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -21,6 +21,7 @@ #include "CBotInstrMethode.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index 1649de55..7ea8cbf6 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -25,6 +25,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 468854a9..e09a2263 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -24,6 +24,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVarArray.h" diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index d0c3482b..18af17c7 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -21,6 +21,7 @@ #include "CBotLeftExprVar.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 682505b7..6ac0d6a0 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -24,6 +24,7 @@ #include "CBotTwoOpExpr.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index afa5f877..670f3fb5 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -26,6 +26,7 @@ #include "CBotInt.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index fde2103c..576012b8 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -22,6 +22,7 @@ #include "CBotBlock.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 094e5a08..6f7d8605 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -21,6 +21,7 @@ #include "CBotNew.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index fc34b513..21b40d18 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -34,6 +34,8 @@ #include "CBotVar/CBotVar.h" +#include "CBotCStack.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index 3837b26c..70c849d2 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index 0a527d2f..ef53fd77 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -26,6 +26,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index c02f2214..4fc8cddd 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index 2ac2ae64..d3aecf85 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -22,6 +22,7 @@ #include "CBotBlock.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 4ad5ad03..ab5bc653 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -24,6 +24,7 @@ #include "CBotExpression.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index bfc2061f..eb38aea1 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -23,6 +23,7 @@ #include "CBotCondition.h" #include "CBotStack.h" +#include "CBotCStack.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 44eaca50..4e3f2c49 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -22,6 +22,7 @@ #include "CBotCall.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotClass.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 87aa0bb2..91f91a93 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -1133,392 +1133,3 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) } return true; } - - - - -//////////////////////////////////////////////////////////////////////////// -// management of the compile stack -//////////////////////////////////////////////////////////////////////////// - -CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable -int CBotCStack::m_error = 0; -int CBotCStack::m_end = 0; -CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); -//CBotToken* CBotCStack::m_retClass= nullptr; - -//////////////////////////////////////////////////////////////////////////////// -CBotCStack::CBotCStack(CBotCStack* ppapa) -{ - m_next = nullptr; - m_prev = ppapa; - - if (ppapa == nullptr) - { - m_error = 0; - m_start = 0; - m_end = 0; - m_bBlock = true; - } - else - { - m_start = ppapa->m_start; - m_bBlock = false; - } - - m_listVar = nullptr; - m_var = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -// destructor -CBotCStack::~CBotCStack() -{ - if (m_next != nullptr) delete m_next; - if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain - - delete m_var; - delete m_listVar; -} - -//////////////////////////////////////////////////////////////////////////////// -// used only at compile -CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) -{ - if (m_next != nullptr) return m_next; // include on an existing stack - - CBotCStack* p = new CBotCStack(this); - m_next = p; // channel element - p->m_bBlock = bBlock; - - if (pToken != nullptr) p->SetStartError(pToken->GetStart()); - - return p; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) -{ - if ( pfils == this ) return inst; - - if (m_var != nullptr) delete m_var; // value replaced? - m_var = pfils->m_var; // result transmitted - pfils->m_var = nullptr; // not to destroy the variable - - if (m_error) - { - m_start = pfils->m_start; // retrieves the position of the error - m_end = pfils->m_end; - } - - delete pfils; - return inst; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) -{ - if (m_var != nullptr) delete m_var; // value replaced? - m_var = pfils->m_var; // result transmitted - pfils->m_var = nullptr; // not to destroy the variable - - if (m_error) - { - m_start = pfils->m_start; // retrieves the position of the error - m_end = pfils->m_end; - } - - delete pfils; - return inst; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError(int& start, int& end) -{ - start = m_start; - end = m_end; - return m_error; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError() -{ - return m_error; -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -CBotTypResult CBotCStack::GetTypResult(int mode) -{ - if (m_var == nullptr) - return CBotTypResult(99); - return m_var->GetTypResult(mode); -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -int CBotCStack::GetType(int mode) -{ - if (m_var == nullptr) - return 99; - return m_var->GetType(mode); -} - -//////////////////////////////////////////////////////////////////////////////// -// pointer on the stack is in what class? -CBotClass* CBotCStack::GetClass() -{ - if ( m_var == nullptr ) - return nullptr; - if ( m_var->GetType(1) != CBotTypPointer ) return nullptr; - - return m_var->GetClass(); -} - -//////////////////////////////////////////////////////////////////////////////// -// type of instruction on the stack -void CBotCStack::SetType(CBotTypResult& type) -{ - if (m_var == nullptr) return; - m_var->SetType( type ); -} - -// seeks a variable on the stack -// the token may be a result of TokenTypVar (object of a class) -// or a pointer in the source -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::FindVar(CBotToken* &pToken) -{ - CBotCStack* p = this; - CBotString name = pToken->GetString(); - - while (p != nullptr) - { - CBotVar* pp = p->m_listVar; - while ( pp != nullptr) - { - if (name == pp->GetName()) - { - return pp; - } - pp = pp->m_next; - } - p = p->m_prev; - } - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::FindVar(CBotToken& Token) -{ - CBotToken* pt = &Token; - return FindVar(pt); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::CopyVar(CBotToken& Token) -{ - CBotVar* pVar = FindVar( Token ); - - if ( pVar == nullptr) return nullptr; - - CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() ); - pCopy->Copy(pVar); - return pCopy; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::IsOk() -{ - return (m_error == 0); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetStartError( int pos ) -{ - if ( m_error != 0) return; // does not change existing error - m_start = pos; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, int pos) -{ - if ( n!= 0 && m_error != 0) return; // does not change existing error - m_error = n; - m_end = pos; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, CBotToken* p) -{ - if (m_error) return; // does not change existing error - m_error = n; - m_start = p->GetStart(); - m_end = p->GetEnd(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::ResetError(int n, int start, int end) -{ - m_error = n; - m_start = start; - m_end = end; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::NextToken(CBotToken* &p) -{ - CBotToken* pp = p; - - p = p->GetNext(); - if (p!=nullptr) return true; - - SetError(TX_ENDOF, pp->GetEnd()); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetBotCall(CBotProgram* p) -{ - m_prog = p; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotProgram* CBotCStack::GetBotCall() -{ - return m_prog; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetRetType(CBotTypResult& type) -{ - m_retTyp = type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCStack::GetRetType() -{ - return m_retTyp; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetVar( CBotVar* var ) -{ - if (m_var) delete m_var; // replacement of a variable - m_var = var; -} - -//////////////////////////////////////////////////////////////////////////////// -// puts on the stack a copy of a variable -void CBotCStack::SetCopyVar( CBotVar* var ) -{ - if (m_var) delete m_var; // replacement of a variable - - if ( var == nullptr ) return; - m_var = CBotVar::Create("", var->GetTypResult(2)); - m_var->Copy( var ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotCStack::GetVar() -{ - return m_var; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotCStack::AddVar(CBotVar* pVar) -{ - CBotCStack* p = this; - - // returns to the father element - while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; - - if ( p == nullptr ) return; - - CBotVar** pp = &p->m_listVar; - while ( *pp != nullptr ) pp = &(*pp)->m_next; - - *pp = pVar; // added after - -#ifdef _DEBUG - if ( pVar->GetUniqNum() == 0 ) assert(0); -#endif -} - -// test whether a variable is already defined locally -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::CheckVarLocal(CBotToken* &pToken) -{ - CBotCStack* p = this; - CBotString name = pToken->GetString(); - - while (p != nullptr) - { - CBotVar* pp = p->m_listVar; - while ( pp != nullptr) - { - if (name == pp->GetName()) - return true; - pp = pp->m_next; - } - if ( p->m_bBlock ) return false; - p = p->m_prev; - } - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) -{ - nIdent = 0; - CBotTypResult val(-1); - - val = CBotCall::CompileCall(p, ppVars, this, nIdent); - if (val.GetType() < 0) - { - val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent); - if ( val.GetType() < 0 ) - { - // pVar = nullptr; // the error is not on a particular parameter - SetError( -val.GetType(), p ); - val.SetType(-val.GetType()); - return val; - } - } - return val; -} - -// test if a procedure name is already defined somewhere -//////////////////////////////////////////////////////////////////////////////// -bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) -{ - CBotString name = pToken->GetString(); - - if ( CBotCall::CheckCall(name) ) return true; - - CBotFunction* pp = m_prog->GetFunctions(); - while ( pp != nullptr ) - { - if ( pToken->GetString() == pp->GetName() ) - { - // are parameters exactly the same? - if ( pp->CheckParam( pParam ) ) - return true; - } - pp = pp->Next(); - } - - pp = CBotFunction::m_listPublic; - while ( pp != nullptr ) - { - if ( pToken->GetString() == pp->GetName() ) - { - // are parameters exactly the same? - if ( pp->CheckParam( pParam ) ) - return true; - } - pp = pp->m_nextpublic; - } - - return false; -} diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index b5f9c235..2df62cc2 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -23,6 +23,7 @@ #include "CBotToken.h" #include "CBotClass.h" #include "CBotStack.h" +#include "CBotCStack.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 87303c44..e69beaea 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -3,6 +3,7 @@ set(SOURCES CBotClass.cpp CBotProgram.cpp CBotStack.cpp + CBotCStack.cpp CBotString.cpp CBotToken.cpp CBotCall.cpp From ef4e2f08a36d5eb5e9ece4b03a758b133e27ae8b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Mon, 16 Nov 2015 22:00:01 +0100 Subject: [PATCH 118/360] Moving CBotInstr class in its own header and source files. --- src/CBot/CBot.cpp | 336 --------------------- src/CBot/CBot.h | 90 ------ src/CBot/CBotDefines.h | 2 + src/CBot/CBotInstr/CBotBlock.h | 2 + src/CBot/CBotInstr/CBotBoolExpr.h | 2 + src/CBot/CBotInstr/CBotBoolean.h | 2 + src/CBot/CBotInstr/CBotBreak.h | 2 + src/CBot/CBotInstr/CBotCase.h | 2 + src/CBot/CBotInstr/CBotCatch.h | 2 + src/CBot/CBotInstr/CBotClassInst.h | 2 + src/CBot/CBotInstr/CBotCondition.h | 2 + src/CBot/CBotInstr/CBotDo.h | 2 + src/CBot/CBotInstr/CBotEmpty.h | 2 + src/CBot/CBotInstr/CBotExprAlpha.h | 2 + src/CBot/CBotInstr/CBotExprBool.h | 2 + src/CBot/CBotInstr/CBotExprNan.h | 2 + src/CBot/CBotInstr/CBotExprNull.h | 2 + src/CBot/CBotInstr/CBotExprNum.h | 2 + src/CBot/CBotInstr/CBotExprUnaire.h | 2 + src/CBot/CBotInstr/CBotExprVar.h | 2 + src/CBot/CBotInstr/CBotExpression.h | 3 + src/CBot/CBotInstr/CBotFieldExpr.h | 2 + src/CBot/CBotInstr/CBotFloat.h | 2 + src/CBot/CBotInstr/CBotFor.h | 2 + src/CBot/CBotInstr/CBotFunction.h | 2 + src/CBot/CBotInstr/CBotIString.h | 2 + src/CBot/CBotInstr/CBotIf.h | 2 + src/CBot/CBotInstr/CBotIndexExpr.h | 2 + src/CBot/CBotInstr/CBotInstArray.h | 2 + src/CBot/CBotInstr/CBotInstr.cpp | 374 ++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstr.h | 266 +++++++++++++++++ src/CBot/CBotInstr/CBotInstrCall.h | 2 + src/CBot/CBotInstr/CBotInstrMethode.h | 2 + src/CBot/CBotInstr/CBotInt.h | 2 + src/CBot/CBotInstr/CBotLeftExpr.h | 2 + src/CBot/CBotInstr/CBotLeftExprVar.h | 2 + src/CBot/CBotInstr/CBotListArray.h | 2 + src/CBot/CBotInstr/CBotListExpression.h | 2 + src/CBot/CBotInstr/CBotListInstr.h | 2 + src/CBot/CBotInstr/CBotLogicExpr.h | 2 + src/CBot/CBotInstr/CBotNew.h | 2 + src/CBot/CBotInstr/CBotParExpr.h | 2 +- src/CBot/CBotInstr/CBotPostIncExpr.h | 2 + src/CBot/CBotInstr/CBotPreIncExpr.h | 2 + src/CBot/CBotInstr/CBotReturn.h | 2 + src/CBot/CBotInstr/CBotSwitch.h | 2 + src/CBot/CBotInstr/CBotThrow.h | 2 + src/CBot/CBotInstr/CBotTry.h | 2 + src/CBot/CBotInstr/CBotTwoOpExpr.h | 2 + src/CBot/CBotInstr/CBotWhile.h | 2 + src/CBot/CBotVar/CBotVarClass.cpp | 4 +- src/CBot/CMakeLists.txt | 1 + 52 files changed, 735 insertions(+), 429 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInstr.cpp create mode 100644 src/CBot/CBotInstr/CBotInstr.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 1c8b4379..1822df7b 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -83,342 +83,6 @@ // Global include #include - -CBotInstr::CBotInstr() -{ - name = "CBotInstr"; - m_next = nullptr; - m_next2b = nullptr; - m_next3 = nullptr; - m_next3b = nullptr; -} - -CBotInstr::~CBotInstr() -{ - delete m_next; - delete m_next2b; - delete m_next3; - delete m_next3b; -} - -// counter of nested loops, -// to determine the break and continue valid -// list of labels used - - -int CBotInstr::m_LoopLvl = 0; -CBotStringArray CBotInstr::m_labelLvl = CBotStringArray(); - -// adds a level with a label -void CBotInstr::IncLvl(CBotString& label) -{ - m_labelLvl.SetSize(m_LoopLvl+1); - m_labelLvl[m_LoopLvl] = label; - m_LoopLvl++; -} - -// adds a level (switch statement) -void CBotInstr::IncLvl() -{ - m_labelLvl.SetSize(m_LoopLvl+1); - m_labelLvl[m_LoopLvl] = "#SWITCH"; - m_LoopLvl++; -} - -// free a level -void CBotInstr::DecLvl() -{ - m_LoopLvl--; - m_labelLvl[m_LoopLvl].Empty(); -} - -// control validity of break and continue -bool CBotInstr::ChkLvl(const CBotString& label, int type) -{ - int i = m_LoopLvl; - while (--i>=0) - { - if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue; - if (label.IsEmpty()) return true; - if (m_labelLvl[i] == label) return true; - } - return false; -} - -bool CBotInstr::IsOfClass(CBotString n) -{ - return name == n; -} - - -//////////////////////////////////////////////////////////////////////////// -// database management class CBotInstr - -// set the token corresponding to the instruction - -void CBotInstr::SetToken(CBotToken* p) -{ - m_token = *p; -} - -// return the type of the token assicated with the instruction - -int CBotInstr::GetTokenType() -{ - return m_token.GetType(); -} - -// return associated token - -CBotToken* CBotInstr::GetToken() -{ - return &m_token; -} - -// adds the statement following the other - -void CBotInstr::AddNext(CBotInstr* n) -{ - CBotInstr* p = this; - while (p->m_next != nullptr) p = p->m_next; - p->m_next = n; -} - -void CBotInstr::AddNext3(CBotInstr* n) -{ - CBotInstr* p = this; - while (p->m_next3 != nullptr) p = p->m_next3; - p->m_next3 = n; -} - -void CBotInstr::AddNext3b(CBotInstr* n) -{ - CBotInstr* p = this; - while (p->m_next3b != nullptr) p = p->m_next3b; - p->m_next3b = n; -} - -// returns next statement - -CBotInstr* CBotInstr::GetNext() -{ - return m_next; -} - -CBotInstr* CBotInstr::GetNext3() -{ - return m_next3; -} - -CBotInstr* CBotInstr::GetNext3b() -{ - return m_next3b; -} - -/////////////////////////////////////////////////////////////////////////// -// compile an instruction which can be -// while, do, try, throw, if, for, switch, break, continue, return -// int, float, boolean, string, -// declaration of an instance of a class -// arbitrary expression - - -CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotToken* pp = p; - - if (p == nullptr) return nullptr; - - int type = p->GetType(); // what is the next token - - // is it a lable? - if (IsOfType(pp, TokenTypVar) && - IsOfType(pp, ID_DOTS)) - { - type = pp->GetType(); - // these instructions accept only lable - if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, 0)) - { - pStack->SetError(TX_LABEL, pp->GetStart()); - return nullptr; - } - } - - // call routine corresponding to the compilation token found - switch (type) - { - case ID_WHILE: - return CBotWhile::Compile(p, pStack); - - case ID_FOR: - return CBotFor::Compile(p, pStack); - - case ID_DO: - return CBotDo::Compile(p, pStack); - - case ID_BREAK: - case ID_CONTINUE: - return CBotBreak::Compile(p, pStack); - - case ID_SWITCH: - return CBotSwitch::Compile(p, pStack); - - case ID_TRY: - return CBotTry::Compile(p, pStack); - - case ID_THROW: - return CBotThrow::Compile(p, pStack); - - case ID_INT: - return CBotInt::Compile(p, pStack); - - case ID_FLOAT: - return CBotFloat::Compile(p, pStack); - - case ID_STRING: - return CBotIString::Compile(p, pStack); - - case ID_BOOLEAN: - case ID_BOOL: - return CBotBoolean::Compile(p, pStack); - - case ID_IF: - return CBotIf::Compile(p, pStack); - - case ID_RETURN: - return CBotReturn::Compile(p, pStack); - - case ID_ELSE: - pStack->SetStartError(p->GetStart()); - pStack->SetError(TX_ELSEWITHOUTIF, p->GetEnd()); - return nullptr; - - case ID_CASE: - pStack->SetStartError(p->GetStart()); - pStack->SetError(TX_OUTCASE, p->GetEnd()); - return nullptr; - } - - pStack->SetStartError(p->GetStart()); - - // should not be a reserved word DefineNum - if (p->GetType() == TokenTypDef) - { - pStack->SetError(TX_RESERVED, p); - return nullptr; - } - - // this might be an instance of class definnition - CBotToken* ppp = p; - if (IsOfType(ppp, TokenTypVar)) - { - if (CBotClass::Find(p) != nullptr) - { - // yes, compiles the declaration of the instance - return CBotClassInst::Compile(p, pStack); - } - } - - // this can be an arythmetic instruction - CBotInstr* inst = CBotExpression::Compile(p, pStack); - if (IsOfType(p, ID_SEP)) - { - return inst; - } - pStack->SetError(TX_ENDOF, p->GetStart()); - delete inst; - return nullptr; -} - -bool CBotInstr::Execute(CBotStack* &pj) -{ - CBotString ClassManquante = name; - assert(0); // should never go through this routine - // but use the routines of the subclasses - return false; -} - -bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) -{ - if (!Execute(pj)) return false; - pVar->SetVal(pj->GetVar()); - return true; -} - -void CBotInstr::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotString ClassManquante = name; - assert(0); // should never go through this routine - // but use the routines of the subclasses -} - - -bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) -{ - assert(0); // dad do not know, see the girls - return false; -} - -bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) -{ - assert(0); // dad do not know, see the girls - return false; -} - -void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain) -{ - assert(0); // dad do not know, see the girls -} - -// this routine is defined only for the subclass CBotCase -// this allows to make the call on all instructions CompCase -// to see if it's a case to the desired value. - -bool CBotInstr::CompCase(CBotStack* &pj, int val) -{ - return false; -} - -CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first) -{ - if (IsOfType(p, ID_OPBRK)) - { - if (!IsOfType(p, ID_CLBRK)) - { - pStack->SetError(TX_CLBRK, p->GetStart()); - return nullptr; - } - - CBotInstr* inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false); - if (inst != nullptr || !pStack->IsOk()) return inst; - } - - // compiles an array declaration - if (first) return nullptr ; - - CBotInstr* inst = CBotInstArray::Compile(p, pStack, type); - if (inst == nullptr) return nullptr; - - if (IsOfType(p, ID_COMMA)) // several definitions - { - if (nullptr != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false))) // compiles next one - { - return inst; - } - delete inst; - return nullptr; - } - - if (IsOfType(p, ID_SEP)) // end of instruction - { - return inst; - } - - delete inst; - pStack->SetError(TX_ENDOF, p->GetStart()); - return nullptr; -} - ////////////////////////////////////////////////////////////////////////////////////////// // compile a list of parameters diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e42d1851..71c2279c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -54,96 +54,6 @@ class CBotDefParam; // paramerer list of a function extern bool SaveVar(FILE* pf, CBotVar* pVar); - -///////////////////////////////////////////////////////////////////// -// class defining an instruction -class CBotInstr -{ -private: - static - CBotStringArray - m_labelLvl; -protected: - CBotToken m_token; // keeps the token - CBotString name; // debug - CBotInstr* m_next; // linked command - CBotInstr* m_next2b; // second list definition chain - CBotInstr* m_next3; // third list for indices and fields - CBotInstr* m_next3b; // necessary for reporting tables -/* - for example, the following program - int x[]; x[1] = 4; - int y[x[1]][10], z; - is generated - CBotInstrArray - m_next3b-> CBotEmpty - m_next-> - CBotExpression .... - m_next-> - CBotInstrArray - m_next3b-> CBotExpression ('x') ( m_next3-> CBotIndexExpr ('1') ) - m_next3b-> CBotExpression ('10') - m_next2-> 'z' - m_next->... - -*/ - - static - int m_LoopLvl; - friend class CBotClassInst; - friend class CBotInt; - friend class CBotListArray; - -public: - CBotInstr(); - virtual - ~CBotInstr(); - - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - static - CBotInstr* CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first = true); - - virtual - bool Execute(CBotStack* &pj); - virtual - bool Execute(CBotStack* &pj, CBotVar* pVar); - virtual - void RestoreState(CBotStack* &pj, bool bMain); - - virtual - bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile); - virtual - bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend); - virtual - void RestoreStateVar(CBotStack* &pile, bool bMain); - - virtual - bool CompCase(CBotStack* &pj, int val); - - void SetToken(CBotToken* p); - int GetTokenType(); - CBotToken* GetToken(); - - void AddNext(CBotInstr* n); - CBotInstr* GetNext(); - void AddNext3(CBotInstr* n); - CBotInstr* GetNext3(); - void AddNext3b(CBotInstr* n); - CBotInstr* GetNext3b(); - - static - void IncLvl(CBotString& label); - static - void IncLvl(); - static - void DecLvl(); - static - bool ChkLvl(const CBotString& label, int type); - - bool IsOfClass(CBotString name); -}; - #define MAX(a,b) ((a>b) ? a : b) extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index d09e3ca2..ae72dbbb 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -21,6 +21,8 @@ // Modules inlcude +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBlock.h b/src/CBot/CBotInstr/CBotBlock.h index f413e756..6c7c6334 100644 --- a/src/CBot/CBotInstr/CBotBlock.h +++ b/src/CBot/CBotInstr/CBotBlock.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.h b/src/CBot/CBotInstr/CBotBoolExpr.h index df7354ee..e50d8a63 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.h +++ b/src/CBot/CBotInstr/CBotBoolExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBoolean.h b/src/CBot/CBotInstr/CBotBoolean.h index 57674200..217daadc 100644 --- a/src/CBot/CBotInstr/CBotBoolean.h +++ b/src/CBot/CBotInstr/CBotBoolean.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h index 0ad39408..ae35a70f 100644 --- a/src/CBot/CBotInstr/CBotBreak.h +++ b/src/CBot/CBotInstr/CBotBreak.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCase.h b/src/CBot/CBotInstr/CBotCase.h index 9ba1b86f..e5043330 100644 --- a/src/CBot/CBotInstr/CBotCase.h +++ b/src/CBot/CBotInstr/CBotCase.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCatch.h b/src/CBot/CBotInstr/CBotCatch.h index 9756c8b8..d4450ec1 100644 --- a/src/CBot/CBotInstr/CBotCatch.h +++ b/src/CBot/CBotInstr/CBotCatch.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotClassInst.h b/src/CBot/CBotInstr/CBotClassInst.h index 370a46cd..3ee791f0 100644 --- a/src/CBot/CBotInstr/CBotClassInst.h +++ b/src/CBot/CBotInstr/CBotClassInst.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCondition.h b/src/CBot/CBotInstr/CBotCondition.h index 08996db1..3958cadb 100644 --- a/src/CBot/CBotInstr/CBotCondition.h +++ b/src/CBot/CBotInstr/CBotCondition.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h index 670a0701..11fe40f4 100644 --- a/src/CBot/CBotInstr/CBotDo.h +++ b/src/CBot/CBotInstr/CBotDo.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotEmpty.h b/src/CBot/CBotInstr/CBotEmpty.h index 04f9fafd..dc50b49b 100644 --- a/src/CBot/CBotInstr/CBotEmpty.h +++ b/src/CBot/CBotInstr/CBotEmpty.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.h b/src/CBot/CBotInstr/CBotExprAlpha.h index 3f820607..3cadc322 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.h +++ b/src/CBot/CBotInstr/CBotExprAlpha.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprBool.h b/src/CBot/CBotInstr/CBotExprBool.h index a2609e26..90f53daa 100644 --- a/src/CBot/CBotInstr/CBotExprBool.h +++ b/src/CBot/CBotInstr/CBotExprBool.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNan.h b/src/CBot/CBotInstr/CBotExprNan.h index 0d6bbf6f..1f0d58d8 100644 --- a/src/CBot/CBotInstr/CBotExprNan.h +++ b/src/CBot/CBotInstr/CBotExprNan.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNull.h b/src/CBot/CBotInstr/CBotExprNull.h index 187cb261..90b3f89a 100644 --- a/src/CBot/CBotInstr/CBotExprNull.h +++ b/src/CBot/CBotInstr/CBotExprNull.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprNum.h b/src/CBot/CBotInstr/CBotExprNum.h index dc213319..07fca7e9 100644 --- a/src/CBot/CBotInstr/CBotExprNum.h +++ b/src/CBot/CBotInstr/CBotExprNum.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.h b/src/CBot/CBotInstr/CBotExprUnaire.h index 25d21251..75b30a94 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.h +++ b/src/CBot/CBotInstr/CBotExprUnaire.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h index a4535659..638cf8fe 100644 --- a/src/CBot/CBotInstr/CBotExprVar.h +++ b/src/CBot/CBotInstr/CBotExprVar.h @@ -24,6 +24,8 @@ #include "CBotDefines.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotExpression.h b/src/CBot/CBotInstr/CBotExpression.h index d25fd39c..ddf2e257 100644 --- a/src/CBot/CBotInstr/CBotExpression.h +++ b/src/CBot/CBotInstr/CBotExpression.h @@ -21,8 +21,11 @@ // Modules inlcude #include "CBot.h" + #include "CBotLeftExpr.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.h b/src/CBot/CBotInstr/CBotFieldExpr.h index 13f9fc37..41e828bd 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.h +++ b/src/CBot/CBotInstr/CBotFieldExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFloat.h b/src/CBot/CBotInstr/CBotFloat.h index 6223071c..309697b0 100644 --- a/src/CBot/CBotInstr/CBotFloat.h +++ b/src/CBot/CBotInstr/CBotFloat.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h index 01edc666..d7d4256d 100644 --- a/src/CBot/CBotInstr/CBotFor.h +++ b/src/CBot/CBotInstr/CBotFor.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index 486ffff8..f1fc3c8d 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIString.h b/src/CBot/CBotInstr/CBotIString.h index 1d91ea26..2ea8e4ee 100644 --- a/src/CBot/CBotInstr/CBotIString.h +++ b/src/CBot/CBotInstr/CBotIString.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIf.h b/src/CBot/CBotInstr/CBotIf.h index 6ea6ee9c..e39e5226 100644 --- a/src/CBot/CBotInstr/CBotIf.h +++ b/src/CBot/CBotInstr/CBotIf.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.h b/src/CBot/CBotInstr/CBotIndexExpr.h index 730a4de4..a8e7e07a 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.h +++ b/src/CBot/CBotInstr/CBotIndexExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstArray.h b/src/CBot/CBotInstr/CBotInstArray.h index ca2cbe07..4ad025d6 100644 --- a/src/CBot/CBotInstr/CBotInstArray.h +++ b/src/CBot/CBotInstr/CBotInstArray.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp new file mode 100644 index 00000000..7d376f7c --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -0,0 +1,374 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInstr.h" + +#include "CBotInstr/CBotFor.h" +#include "CBotInstr/CBotDo.h" +#include "CBotInstr/CBotBreak.h" +#include "CBotInstr/CBotSwitch.h" +#include "CBotInstr/CBotTry.h" +#include "CBotInstr/CBotThrow.h" +#include "CBotInstr/CBotInt.h" +#include "CBotInstr/CBotFloat.h" +#include "CBotInstr/CBotWhile.h" +#include "CBotInstr/CBotIString.h" +#include "CBotInstr/CBotBoolean.h" +#include "CBotInstr/CBotIf.h" +#include "CBotInstr/CBotReturn.h" +#include "CBotInstr/CBotClassInst.h" +#include "CBotInstr/CBotExpression.h" +#include "CBotInstr/CBotInstArray.h" + +#include "CBotVar/CBotVar.h" + +#include "CBotClass.h" +#include "CBotStack.h" + + +// Local include + +// Global include +#include + +//////////////////////////////////////////////////////////////////////////////// +int CBotInstr::m_LoopLvl = 0; +CBotStringArray CBotInstr::m_labelLvl = CBotStringArray(); + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr::CBotInstr() +{ + name = "CBotInstr"; + m_next = nullptr; + m_next2b = nullptr; + m_next3 = nullptr; + m_next3b = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr::~CBotInstr() +{ + delete m_next; + delete m_next2b; + delete m_next3; + delete m_next3b; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::IncLvl(CBotString& label) +{ + m_labelLvl.SetSize(m_LoopLvl+1); + m_labelLvl[m_LoopLvl] = label; + m_LoopLvl++; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::IncLvl() +{ + m_labelLvl.SetSize(m_LoopLvl+1); + m_labelLvl[m_LoopLvl] = "#SWITCH"; + m_LoopLvl++; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::DecLvl() +{ + m_LoopLvl--; + m_labelLvl[m_LoopLvl].Empty(); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::ChkLvl(const CBotString& label, int type) +{ + int i = m_LoopLvl; + while (--i>=0) + { + if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue; + if (label.IsEmpty()) return true; + if (m_labelLvl[i] == label) return true; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::IsOfClass(CBotString n) +{ + return name == n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::SetToken(CBotToken* p) +{ + m_token = *p; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotInstr::GetTokenType() +{ + return m_token.GetType(); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotToken* CBotInstr::GetToken() +{ + return &m_token; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::AddNext(CBotInstr* n) +{ + CBotInstr* p = this; + while (p->m_next != nullptr) p = p->m_next; + p->m_next = n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::AddNext3(CBotInstr* n) +{ + CBotInstr* p = this; + while (p->m_next3 != nullptr) p = p->m_next3; + p->m_next3 = n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::AddNext3b(CBotInstr* n) +{ + CBotInstr* p = this; + while (p->m_next3b != nullptr) p = p->m_next3b; + p->m_next3b = n; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstr::GetNext() +{ + return m_next; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstr::GetNext3() +{ + return m_next3; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstr::GetNext3b() +{ + return m_next3b; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) +{ + CBotToken* pp = p; + + if (p == nullptr) return nullptr; + + int type = p->GetType(); // what is the next token + + // is it a lable? + if (IsOfType(pp, TokenTypVar) && + IsOfType(pp, ID_DOTS)) + { + type = pp->GetType(); + // these instructions accept only lable + if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, 0)) + { + pStack->SetError(TX_LABEL, pp->GetStart()); + return nullptr; + } + } + + // call routine corresponding to the compilation token found + switch (type) + { + case ID_WHILE: + return CBotWhile::Compile(p, pStack); + + case ID_FOR: + return CBotFor::Compile(p, pStack); + + case ID_DO: + return CBotDo::Compile(p, pStack); + + case ID_BREAK: + case ID_CONTINUE: + return CBotBreak::Compile(p, pStack); + + case ID_SWITCH: + return CBotSwitch::Compile(p, pStack); + + case ID_TRY: + return CBotTry::Compile(p, pStack); + + case ID_THROW: + return CBotThrow::Compile(p, pStack); + + case ID_INT: + return CBotInt::Compile(p, pStack); + + case ID_FLOAT: + return CBotFloat::Compile(p, pStack); + + case ID_STRING: + return CBotIString::Compile(p, pStack); + + case ID_BOOLEAN: + case ID_BOOL: + return CBotBoolean::Compile(p, pStack); + + case ID_IF: + return CBotIf::Compile(p, pStack); + + case ID_RETURN: + return CBotReturn::Compile(p, pStack); + + case ID_ELSE: + pStack->SetStartError(p->GetStart()); + pStack->SetError(TX_ELSEWITHOUTIF, p->GetEnd()); + return nullptr; + + case ID_CASE: + pStack->SetStartError(p->GetStart()); + pStack->SetError(TX_OUTCASE, p->GetEnd()); + return nullptr; + } + + pStack->SetStartError(p->GetStart()); + + // should not be a reserved word DefineNum + if (p->GetType() == TokenTypDef) + { + pStack->SetError(TX_RESERVED, p); + return nullptr; + } + + // this might be an instance of class definnition + CBotToken* ppp = p; + if (IsOfType(ppp, TokenTypVar)) + { + if (CBotClass::Find(p) != nullptr) + { + // yes, compiles the declaration of the instance + return CBotClassInst::Compile(p, pStack); + } + } + + // this can be an arythmetic instruction + CBotInstr* inst = CBotExpression::Compile(p, pStack); + if (IsOfType(p, ID_SEP)) + { + return inst; + } + pStack->SetError(TX_ENDOF, p->GetStart()); + delete inst; + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::Execute(CBotStack* &pj) +{ + CBotString ClassManquante = name; + assert(0); // should never go through this routine + // but use the routines of the subclasses + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) +{ + if (!Execute(pj)) return false; + pVar->SetVal(pj->GetVar()); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotString ClassManquante = name; + assert(0); // should never go through this routine + // but use the routines of the subclasses +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +{ + assert(0); // dad do not know, see the girls + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) +{ + assert(0); // dad do not know, see the girls + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain) +{ + assert(0); // dad do not know, see the girls +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotInstr::CompCase(CBotStack* &pj, int val) +{ + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first) +{ + if (IsOfType(p, ID_OPBRK)) + { + if (!IsOfType(p, ID_CLBRK)) + { + pStack->SetError(TX_CLBRK, p->GetStart()); + return nullptr; + } + + CBotInstr* inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false); + if (inst != nullptr || !pStack->IsOk()) return inst; + } + + // compiles an array declaration + if (first) return nullptr ; + + CBotInstr* inst = CBotInstArray::Compile(p, pStack, type); + if (inst == nullptr) return nullptr; + + if (IsOfType(p, ID_COMMA)) // several definitions + { + if (nullptr != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false))) // compiles next one + { + return inst; + } + delete inst; + return nullptr; + } + + if (IsOfType(p, ID_SEP)) // end of instruction + { + return inst; + } + + delete inst; + pStack->SetError(TX_ENDOF, p->GetStart()); + return nullptr; +} diff --git a/src/CBot/CBotInstr/CBotInstr.h b/src/CBot/CBotInstr/CBotInstr.h new file mode 100644 index 00000000..1f25115e --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstr.h @@ -0,0 +1,266 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotToken.h" + +#include "CBotCStack.h" + +// Local include + +// Global include + +/* + for example, the following program + int x[]; x[1] = 4; + int y[x[1]][10], z; + is generated + CBotInstrArray + m_next3b-> CBotEmpty + m_next-> + CBotExpression .... + m_next-> + CBotInstrArray + m_next3b-> CBotExpression ('x') ( m_next3-> CBotIndexExpr ('1') ) + m_next3b-> CBotExpression ('10') + m_next2-> 'z' + m_next->... + +*/ +/*! + * \brief The CBotInstr class Class defining an instruction. + */ +class CBotInstr +{ +public: + + /*! + * \brief CBotInstr + */ + CBotInstr(); + + /*! + * \brief ~CBotInstr + */ + virtual ~CBotInstr(); + + /*! + * \brief Compile Compile an instruction which can be while, do, try, + * throw, if, for, switch, break, continue, return, int, float, boolean, + * string, declaration of an instance of a class, arbitrary expression. + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, + CBotCStack* pStack); + + /*! + * \brief CompileArray + * \param p + * \param pStack + * \param type + * \param first + * \return + */ + static CBotInstr* CompileArray(CBotToken* &p, + CBotCStack* pStack, + CBotTypResult type, + bool first = true); + + /*! + * \brief Execute + * \param pj + * \return + */ + virtual bool Execute(CBotStack* &pj); + + /*! + * \brief Execute + * \param pj + * \param pVar + * \return + */ + virtual bool Execute(CBotStack* &pj, + CBotVar* pVar); + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + virtual void RestoreState(CBotStack* &pj, + bool bMain); + + /*! + * \brief ExecuteVar + * \param pVar + * \param pile + * \return + */ + virtual bool ExecuteVar(CBotVar* &pVar, + CBotCStack* &pile); + + /*! + * \brief ExecuteVar + * \param pVar + * \param pile + * \param prevToken + * \param bStep + * \param bExtend + * \return + */ + virtual bool ExecuteVar(CBotVar* &pVar, + CBotStack* &pile, + CBotToken* prevToken, + bool bStep, + bool bExtend); + + /*! + * \brief RestoreStateVar + * \param pile + * \param bMain + */ + virtual void RestoreStateVar(CBotStack* &pile, + bool bMain); + + /*! + * \brief CompCase This routine is defined only for the subclass CBotCase + * this allows to make the call on all instructions CompCase to see if it's + * a case to the desired value.. + * \param pj + * \param val + * \return + */ + virtual bool CompCase(CBotStack* &pj, + int val); + + /*! + * \brief SetToken Set the token corresponding to the instruction. + * \param p + */ + void SetToken(CBotToken* p); + + /*! + * \brief GetTokenType Return the type of the token assicated with the + * instruction. + * \return + */ + int GetTokenType(); + + /*! + * \brief GetToken Return associated token. + * \return + */ + CBotToken* GetToken(); + + /*! + * \brief AddNext Adds the statement following the other. + * \param n + */ + void AddNext(CBotInstr* n); + + /*! + * \brief GetNext Returns next statement. + * \return + */ + CBotInstr* GetNext(); + + /*! + * \brief AddNext3 + * \param n + */ + void AddNext3(CBotInstr* n); + + /*! + * \brief GetNext3 + * \return + */ + CBotInstr* GetNext3(); + + /*! + * \brief AddNext3b + * \param n + */ + void AddNext3b(CBotInstr* n); + + /*! + * \brief GetNext3b + * \return + */ + CBotInstr* GetNext3b(); + + /*! + * \brief IncLvl Adds a level with a label. + * \param label + */ + static void IncLvl(CBotString& label); + + /*! + * \brief IncLvl Adds a level (switch statement). + */ + static void IncLvl(); + + /*! + * \brief DecLvl Free a level. + */ + static void DecLvl(); + + /*! + * \brief ChkLvl Control validity of break and continue. + * \param label + * \param type + * \return + */ + static bool ChkLvl(const CBotString& label, int type); + + /*! + * \brief IsOfClass + * \param name + * \return + */ + bool IsOfClass(CBotString name); + +protected: + + //! Keeps the token. + CBotToken m_token; + //! Debug. + CBotString name; + //! Linked command. + CBotInstr* m_next; + //! Second list definition chain. + CBotInstr* m_next2b; + //! Third list for indices and fields. + CBotInstr* m_next3; + //! Necessary for reporting tables. + CBotInstr* m_next3b; + + //! Counter of nested loops, to determine the break and continue valid. + static int m_LoopLvl; + friend class CBotClassInst; + friend class CBotInt; + friend class CBotListArray; + +private: + //! List of labels used. + static CBotStringArray m_labelLvl; +}; diff --git a/src/CBot/CBotInstr/CBotInstrCall.h b/src/CBot/CBotInstr/CBotInstrCall.h index 7e194f8a..fa634fed 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.h +++ b/src/CBot/CBotInstr/CBotInstrCall.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h index ca4ad90b..ea398115 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.h +++ b/src/CBot/CBotInstr/CBotInstrMethode.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotInt.h b/src/CBot/CBotInstr/CBotInt.h index 702f5290..085e6265 100644 --- a/src/CBot/CBotInstr/CBotInt.h +++ b/src/CBot/CBotInstr/CBotInt.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.h b/src/CBot/CBotInstr/CBotLeftExpr.h index f0dba0b4..aaf9ee47 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.h +++ b/src/CBot/CBotInstr/CBotLeftExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.h b/src/CBot/CBotInstr/CBotLeftExprVar.h index a264dbae..fd693727 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.h +++ b/src/CBot/CBotInstr/CBotLeftExprVar.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 921273d1..586cc864 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListExpression.h b/src/CBot/CBotInstr/CBotListExpression.h index c4e67115..451b2181 100644 --- a/src/CBot/CBotInstr/CBotListExpression.h +++ b/src/CBot/CBotInstr/CBotListExpression.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotListInstr.h b/src/CBot/CBotInstr/CBotListInstr.h index 763c3a88..0aafaf59 100644 --- a/src/CBot/CBotInstr/CBotListInstr.h +++ b/src/CBot/CBotInstr/CBotListInstr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotLogicExpr.h b/src/CBot/CBotInstr/CBotLogicExpr.h index 2bffc243..db6c67f6 100644 --- a/src/CBot/CBotInstr/CBotLogicExpr.h +++ b/src/CBot/CBotInstr/CBotLogicExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotNew.h b/src/CBot/CBotInstr/CBotNew.h index 77e2b2c6..02598b1a 100644 --- a/src/CBot/CBotInstr/CBotNew.h +++ b/src/CBot/CBotInstr/CBotNew.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h index 60c09933..690d6efb 100644 --- a/src/CBot/CBotInstr/CBotParExpr.h +++ b/src/CBot/CBotInstr/CBotParExpr.h @@ -22,7 +22,7 @@ // Modules inlcude #include "CBot.h" -#include "CBotStack.h" +#include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.h b/src/CBot/CBotInstr/CBotPostIncExpr.h index 5a3240c8..3a30fcef 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.h +++ b/src/CBot/CBotInstr/CBotPostIncExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.h b/src/CBot/CBotInstr/CBotPreIncExpr.h index ede694d4..896c0c9a 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.h +++ b/src/CBot/CBotInstr/CBotPreIncExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotReturn.h b/src/CBot/CBotInstr/CBotReturn.h index 978c6c10..1816bf2d 100644 --- a/src/CBot/CBotInstr/CBotReturn.h +++ b/src/CBot/CBotInstr/CBotReturn.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotSwitch.h b/src/CBot/CBotInstr/CBotSwitch.h index c3f5e02c..b4cff5e4 100644 --- a/src/CBot/CBotInstr/CBotSwitch.h +++ b/src/CBot/CBotInstr/CBotSwitch.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotThrow.h b/src/CBot/CBotInstr/CBotThrow.h index 997550aa..b5227ad7 100644 --- a/src/CBot/CBotInstr/CBotThrow.h +++ b/src/CBot/CBotInstr/CBotThrow.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotTry.h b/src/CBot/CBotInstr/CBotTry.h index 0a8d2b9a..bdc3d4d8 100644 --- a/src/CBot/CBotInstr/CBotTry.h +++ b/src/CBot/CBotInstr/CBotTry.h @@ -21,6 +21,8 @@ #include "CBot.h" #include "CBotCatch.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.h b/src/CBot/CBotInstr/CBotTwoOpExpr.h index 1bcc2f8f..720755fc 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.h +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h index 5d63909a..528fe8f1 100644 --- a/src/CBot/CBotInstr/CBotWhile.h +++ b/src/CBot/CBotInstr/CBotWhile.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index f07fbe9f..4d6ee787 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -21,11 +21,11 @@ #include "CBotVarClass.h" #include "CBotClass.h" - #include "CBotStack.h" - #include "CBotDefines.h" +#include "CBotInstr/CBotInstr.h" + // Local include // Global include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index e69beaea..80cb2d0e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES CBotUtils.cpp CBotDefParam.cpp CBotCallMethode.cpp + CBotInstr/CBotInstr.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp From 67dff4ef6506755eb7312f0ec305d69f56d2a04d Mon Sep 17 00:00:00 2001 From: Grunaka Date: Mon, 16 Nov 2015 22:17:33 +0100 Subject: [PATCH 119/360] Moving CBotStringArray class in its own header and source files. --- src/CBot/CBotDll.h | 21 ----- src/CBot/CBotProgram.h | 1 + src/CBot/CBotString.cpp | 144 ----------------------------------- src/CBot/CBotStringArray.cpp | 136 +++++++++++++++++++++++++++++++++ src/CBot/CBotStringArray.h | 85 +++++++++++++++++++++ src/CBot/CBotToken.h | 2 + src/CBot/CBotUtils.cpp | 20 +++++ src/CBot/CBotUtils.h | 42 ++++++++++ src/CBot/CMakeLists.txt | 1 + 9 files changed, 287 insertions(+), 165 deletions(-) create mode 100644 src/CBot/CBotStringArray.cpp create mode 100644 src/CBot/CBotStringArray.h diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 56b43642..16b400e3 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -419,27 +419,6 @@ private: static const char * MapIdToString(EID id); }; - -// Class used to array management - -class CBotStringArray : public CBotString -{ -private: - int m_nSize; // number of elements - int m_nMaxSize; // reserved size - CBotString* m_pData; // ^data - -public: - CBotStringArray(); - ~CBotStringArray(); - void SetSize(int nb); - int GetSize(); - void Add(const CBotString& str); - CBotString& operator[](int nIndex); - - CBotString& ElementAt(int nIndex); -}; - /////////////////////////////////////////////////////////////////////////////// // routines for file management (* FILE) FILE* fOpen(const char* name, const char* mode); diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 02aa5372..bef08a8c 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -20,6 +20,7 @@ #pragma once // Modules inlcude +#include "CBotStringArray.h" // Local include diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 1f31f7f2..12cc546b 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -524,147 +524,3 @@ const char * CBotString::MapIdToString(EID id) return emptyString; } } - -/////////////////////////////////////////////////////////////////////////////////////////// -// arrays of strings - -CBotStringArray::CBotStringArray() -{ - m_pData = nullptr; - m_nSize = m_nMaxSize = 0; -} - -CBotStringArray::~CBotStringArray() -{ - SetSize(0); // destroys data ! -} - - -int CBotStringArray::GetSize() -{ - return m_nSize; -} - -void CBotStringArray::Add(const CBotString& str) -{ - SetSize(m_nSize+1); - - m_pData[m_nSize-1] = str; -} - -/////////////////////////////////////////////////////////////////////// -// utility routines - -static inline void ConstructElement(CBotString* pNewData) -{ - memset(pNewData, 0, sizeof(CBotString)); -} - -static inline void DestructElement(CBotString* pOldData) -{ - pOldData->~CBotString(); -} - -static inline void CopyElement(CBotString* pSrc, CBotString* pDest) -{ - *pSrc = *pDest; -} - -static void ConstructElements(CBotString* pNewData, int nCount) -{ - while (nCount--) - { - ConstructElement(pNewData); - pNewData++; - } -} - -static void DestructElements(CBotString* pOldData, int nCount) -{ - while (nCount--) - { - DestructElement(pOldData); - pOldData++; - } -} - -// set the array size - -void CBotStringArray::SetSize(int nNewSize) -{ - if (nNewSize == 0) - { - // shrink to nothing - - DestructElements(m_pData, m_nSize); - delete[] reinterpret_cast(m_pData); - m_pData = nullptr; - m_nSize = m_nMaxSize = 0; - } - else if (m_pData == nullptr) - { - // create one with exact size - m_pData = reinterpret_cast (new unsigned char[nNewSize * sizeof(CBotString)]); - - ConstructElements(m_pData, nNewSize); - - m_nSize = m_nMaxSize = nNewSize; - } - else if (nNewSize <= m_nMaxSize) - { - // it fits - if (nNewSize > m_nSize) - { - // initialize the new elements - - ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize); - - } - - else if (m_nSize > nNewSize) // destroy the old elements - DestructElements(&m_pData[nNewSize], m_nSize-nNewSize); - - m_nSize = nNewSize; - } - else - { - // otherwise, grow array - int nGrowBy; - { - // heuristically determine growth when nGrowBy == 0 - // (this avoids heap fragmentation in many situations) - nGrowBy = std::min(1024, std::max(4, m_nSize / 8)); - } - int nNewMax; - if (nNewSize < m_nMaxSize + nGrowBy) - nNewMax = m_nMaxSize + nGrowBy; // granularity - else - nNewMax = nNewSize; // no slush - - CBotString* pNewData = reinterpret_cast (new unsigned char[nNewMax * sizeof(CBotString)]); - - // copy new data from old - memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); - - // construct remaining elements - ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize); - - - // Get rid of old stuff (note: no destructors called) - delete[] reinterpret_cast(m_pData); - m_pData = pNewData; - m_nSize = nNewSize; - m_nMaxSize = nNewMax; - } -} - - -CBotString& CBotStringArray::operator[](int nIndex) -{ - return ElementAt(nIndex); -} - -CBotString& CBotStringArray::ElementAt(int nIndex) -{ - return m_pData[nIndex]; -} diff --git a/src/CBot/CBotStringArray.cpp b/src/CBot/CBotStringArray.cpp new file mode 100644 index 00000000..ecf53bf0 --- /dev/null +++ b/src/CBot/CBotStringArray.cpp @@ -0,0 +1,136 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotStringArray.h" + +#include "CBotUtils.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotStringArray::CBotStringArray() +{ + m_pData = nullptr; + m_nSize = m_nMaxSize = 0; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotStringArray::~CBotStringArray() +{ + SetSize(0); // destroys data ! +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotStringArray::GetSize() +{ + return m_nSize; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotStringArray::Add(const CBotString& str) +{ + SetSize(m_nSize+1); + + m_pData[m_nSize-1] = str; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotStringArray::SetSize(int nNewSize) +{ + if (nNewSize == 0) + { + // shrink to nothing + + DestructElements(m_pData, m_nSize); + delete[] reinterpret_cast(m_pData); + m_pData = nullptr; + m_nSize = m_nMaxSize = 0; + } + else if (m_pData == nullptr) + { + // create one with exact size + m_pData = reinterpret_cast (new unsigned char[nNewSize * sizeof(CBotString)]); + + ConstructElements(m_pData, nNewSize); + + m_nSize = m_nMaxSize = nNewSize; + } + else if (nNewSize <= m_nMaxSize) + { + // it fits + if (nNewSize > m_nSize) + { + // initialize the new elements + + ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize); + + } + + else if (m_nSize > nNewSize) // destroy the old elements + DestructElements(&m_pData[nNewSize], m_nSize-nNewSize); + + m_nSize = nNewSize; + } + else + { + // otherwise, grow array + int nGrowBy; + { + // heuristically determine growth when nGrowBy == 0 + // (this avoids heap fragmentation in many situations) + nGrowBy = std::min(1024, std::max(4, m_nSize / 8)); + } + int nNewMax; + if (nNewSize < m_nMaxSize + nGrowBy) + nNewMax = m_nMaxSize + nGrowBy; // granularity + else + nNewMax = nNewSize; // no slush + + CBotString* pNewData = reinterpret_cast (new unsigned char[nNewMax * sizeof(CBotString)]); + + // copy new data from old + memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); + + // construct remaining elements + ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize); + + + // Get rid of old stuff (note: no destructors called) + delete[] reinterpret_cast(m_pData); + m_pData = pNewData; + m_nSize = nNewSize; + m_nMaxSize = nNewMax; + } +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString& CBotStringArray::operator[](int nIndex) +{ + return ElementAt(nIndex); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotString& CBotStringArray::ElementAt(int nIndex) +{ + return m_pData[nIndex]; +} diff --git a/src/CBot/CBotStringArray.h b/src/CBot/CBotStringArray.h new file mode 100644 index 00000000..761f874a --- /dev/null +++ b/src/CBot/CBotStringArray.h @@ -0,0 +1,85 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotDll.h" + +// Local include + +// Global include + +/*! + * \brief The CBotStringArray class Class used to arrays of strings management. + */ +class CBotStringArray : public CBotString +{ +public: + + /*! + * \brief CBotStringArray + */ + CBotStringArray(); + + /*! + * \brief ~CBotStringArray + */ + ~CBotStringArray(); + + /*! + * \brief SetSize Set the array size. + * \param nb + */ + void SetSize(int nb); + + /*! + * \brief GetSize + * \return + */ + int GetSize(); + + /*! + * \brief Add + * \param str + */ + void Add(const CBotString& str); + + /*! + * \brief operator [] + * \param nIndex + * \return + */ + CBotString& operator[](int nIndex); + + /*! + * \brief ElementAt + * \param nIndex + * \return + */ + CBotString& ElementAt(int nIndex); + +private: + + //! Number of elements. + int m_nSize; + //! Reserved size. + int m_nMaxSize; + CBotString* m_pData; +}; diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index b82cdfea..e8fd0432 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotStringArray.h" + // Local include // Global include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 2df62cc2..824b3fd6 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -140,3 +140,23 @@ bool WriteFloat(FILE* pf, float w) return (lg == 1); } + +//////////////////////////////////////////////////////////////////////////////// +void ConstructElements(CBotString* pNewData, int nCount) +{ + while (nCount--) + { + ConstructElement(pNewData); + pNewData++; + } +} + +//////////////////////////////////////////////////////////////////////////////// +void DestructElements(CBotString* pOldData, int nCount) +{ + while (nCount--) + { + DestructElement(pOldData); + pOldData++; + } +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 354595b8..f25c8c60 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -75,3 +75,45 @@ bool WriteString(FILE* pf, CBotString s); * \return */ bool WriteFloat(FILE* pf, float w); + +/*! + * \brief ConstructElement + * \param pNewData + */ +static inline void ConstructElement(CBotString* pNewData) +{ + memset(pNewData, 0, sizeof(CBotString)); +} + +/*! + * \brief DestructElement + * \param pOldData + */ +static inline void DestructElement(CBotString* pOldData) +{ + pOldData->~CBotString(); +} + +/*! + * \brief CopyElement + * \param pSrc + * \param pDest + */ +static inline void CopyElement(CBotString* pSrc, CBotString* pDest) +{ + *pSrc = *pDest; +} + +/*! + * \brief ConstructElements + * \param pNewData + * \param nCount + */ +void ConstructElements(CBotString* pNewData, int nCount); + +/*! + * \brief DestructElements + * \param pOldData + * \param nCount + */ +void DestructElements(CBotString* pOldData, int nCount); diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 80cb2d0e..28c73204 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES CBotUtils.cpp CBotDefParam.cpp CBotCallMethode.cpp + CBotStringArray.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp From 942d7195e4ad90fc107778b7f5536de992385c8b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Mon, 16 Nov 2015 22:34:30 +0100 Subject: [PATCH 120/360] Moving CBotString class in its own header and source files. --- src/CBot/CBot.h | 1 - src/CBot/CBotCall.h | 2 + src/CBot/CBotDll.h | 188 ------------------------- src/CBot/CBotString.h | 214 +++++++++++++++++++++++++++++ src/CBot/CBotStringArray.h | 2 +- src/CBot/CBotUtils.cpp | 18 +++ src/CBot/CBotUtils.h | 19 +-- src/CBot/CBotVar/CBotVar.h | 2 + test/unit/CBot/CBotString_test.cpp | 2 + 9 files changed, 246 insertions(+), 202 deletions(-) create mode 100644 src/CBot/CBotString.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 71c2279c..0b619fe9 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -67,7 +67,6 @@ extern bool ReadLong(FILE* pf, long& w); extern bool WriteFloat(FILE* pf, float w); extern bool WriteLong(FILE* pf, long w); extern bool ReadFloat(FILE* pf, float& w); -extern bool WriteString(FILE* pf, CBotString s); extern bool ReadString(FILE* pf, CBotString& s); extern bool WriteType(FILE* pf, CBotTypResult type); extern bool ReadType(FILE* pf, CBotTypResult& type); diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h index 79cab9a2..103d1fc4 100644 --- a/src/CBot/CBotCall.h +++ b/src/CBot/CBotCall.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotString.h" + // Local include // Global include diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 16b400e3..40e4931d 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -231,194 +231,6 @@ private: // for example exceptions returned by external routines // and " throw " with any number. - -//////////////////////////////////////////////////////////////////////// -/** - * \brief CBotString Class used to work on strings - */ -class CBotString -{ -public: - - /** - * \brief CBotString Default constructor. - */ - CBotString(); - - /** - * \brief CBotString - * \param p - */ - CBotString(const char* p); - - /** - * \brief CBotString - * \param p - */ - CBotString(const CBotString& p); - - /** - * \brief CBotString Destructor. - */ - ~CBotString(); - - /** - * \brief Empty Clear the internal string. - */ - void Empty(); - - /** - * \brief IsEmpty Check if the string is empty. - * \return True if the sting is empty false otherwise. - */ - bool IsEmpty() const; - - /** - * \brief GetLength Get the string length. - * \return The size of the string. - */ - int GetLength(); - - /** - * \brief Find Find the position of a character in a string starting from - * the beginning of the string. - * \param c The character to find. - * \return The position of the character or -1 if the character was not - * found. - * \see ReverseFind(const char c) - */ - int Find(const char c); - - /** - * \brief Find Find the position of a string in a string starting from the - * beginning of the string. - * \param lpsz The string to find. - * \return The position of the string or -1 if the string was not - * found. - * \see ReverseFind(const char* lpsz) - */ - int Find(const char* lpsz); - - /** - * \brief Find Find the position of a character in a string starting from - * the end of the string. - * \param c The character to find. - * \return The position of the character or -1 if the character was not - * found. - * \see Find(const char c) - */ - int ReverseFind(const char c); - - /** - * \brief Find Find the position of a string in a string starting from the - * end of the string. - * \param lpsz The string to find. - * \return The string of the character or -1 if the string was not - * found. - * \see Find(const char* lpsz) - */ - int ReverseFind(const char* lpsz); - - /** - * \brief LoadString Load the string associate with the id. - * \param id The id to load. - * \return True if the id exist false otherwise. - */ - bool LoadString(unsigned int id); - - /** - * \brief Mid Return a part of a string from a starting index and until - * the end of the string with a limited size. - * \param nFirst The start index of the character in the string. - * \param lg The size limit. Default value is 2000. - * \return The exctracted string. - */ - CBotString Mid(int start, int lg=-1); - - /** - * \brief Left Return a part of a string starting from the left. - * \param nCount The number of character to retreive. - * \return The exctracted string. - */ - CBotString Left(int nCount) const; - - /** - * \brief Right Return a part of a string starting from the right. - * \param nCount The number of character to retreive. - * \return The exctracted string. - */ - CBotString Right(int nCount) const; - - /** - * \brief Compare Compare a given string to an other. - * \param lpsz The string to compare. - * \return 0 if the two string matches. Less than 0 if the current - * string is less than lpsz. Greater than 0 if the current - * string is greater than lpsz. - */ - int Compare(const char* lpsz) const; - - /** - * \brief MakeUpper Uppercase the string. - */ - void MakeUpper(); - - /** - * \brief MakeLower Lowercase the string. - */ - void MakeLower(); - - /** - * @brief CStr Convert the CBotString to a C string. - * @return A C string string. - */ - const char* CStr() const; - - /** - * \brief Overloaded oprators to work on CBotString classes - */ - const CBotString& operator=(const CBotString& stringSrc); - const CBotString& operator=(const char ch); - const CBotString& operator=(const char* pString); - CBotString operator+(const CBotString& str); - - const CBotString& operator+=(const char ch); - const CBotString& operator+=(const CBotString& str); - bool operator==(const CBotString& str); - bool operator==(const char* p); - bool operator!=(const CBotString& str); - bool operator!=(const char* p); - bool operator>(const CBotString& str); - bool operator>(const char* p); - bool operator>=(const CBotString& str); - bool operator>=(const char* p); - bool operator<(const CBotString& str); - bool operator<(const char* p); - bool operator<=(const CBotString& str); - bool operator<=(const char* p); - - operator const char*() const; // as a C string - - -private: - - //! \brief Pointer to string - char* m_ptr; - - //! \brief Length of the string - int m_lg; - - //! \brief Keeps the string corresponding to keyword ID - static const std::map s_keywordString; - - /** - * \brief MapIdToString Maps given ID to its string equivalent. - * \param id Provided identifier. - * \return String if found, else NullString. - */ - static const char * MapIdToString(EID id); -}; - /////////////////////////////////////////////////////////////////////////////// // routines for file management (* FILE) FILE* fOpen(const char* name, const char* mode); diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h new file mode 100644 index 00000000..3297c2b7 --- /dev/null +++ b/src/CBot/CBotString.h @@ -0,0 +1,214 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotUtils.h" + +// Local include + +// Global include +#include + +/** + * \brief CBotString Class used to work on strings + */ +class CBotString +{ +public: + + /** + * \brief CBotString Default constructor. + */ + CBotString(); + + /** + * \brief CBotString + * \param p + */ + CBotString(const char* p); + + /** + * \brief CBotString + * \param p + */ + CBotString(const CBotString& p); + + /** + * \brief CBotString Destructor. + */ + ~CBotString(); + + /** + * \brief Empty Clear the internal string. + */ + void Empty(); + + /** + * \brief IsEmpty Check if the string is empty. + * \return True if the sting is empty false otherwise. + */ + bool IsEmpty() const; + + /** + * \brief GetLength Get the string length. + * \return The size of the string. + */ + int GetLength(); + + /** + * \brief Find Find the position of a character in a string starting from + * the beginning of the string. + * \param c The character to find. + * \return The position of the character or -1 if the character was not + * found. + * \see ReverseFind(const char c) + */ + int Find(const char c); + + /** + * \brief Find Find the position of a string in a string starting from the + * beginning of the string. + * \param lpsz The string to find. + * \return The position of the string or -1 if the string was not + * found. + * \see ReverseFind(const char* lpsz) + */ + int Find(const char* lpsz); + + /** + * \brief Find Find the position of a character in a string starting from + * the end of the string. + * \param c The character to find. + * \return The position of the character or -1 if the character was not + * found. + * \see Find(const char c) + */ + int ReverseFind(const char c); + + /** + * \brief Find Find the position of a string in a string starting from the + * end of the string. + * \param lpsz The string to find. + * \return The string of the character or -1 if the string was not + * found. + * \see Find(const char* lpsz) + */ + int ReverseFind(const char* lpsz); + + /** + * \brief LoadString Load the string associate with the id. + * \param id The id to load. + * \return True if the id exist false otherwise. + */ + bool LoadString(unsigned int id); + + /** + * \brief Mid Return a part of a string from a starting index and until + * the end of the string with a limited size. + * \param nFirst The start index of the character in the string. + * \param lg The size limit. Default value is 2000. + * \return The exctracted string. + */ + CBotString Mid(int start, int lg=-1); + + /** + * \brief Left Return a part of a string starting from the left. + * \param nCount The number of character to retreive. + * \return The exctracted string. + */ + CBotString Left(int nCount) const; + + /** + * \brief Right Return a part of a string starting from the right. + * \param nCount The number of character to retreive. + * \return The exctracted string. + */ + CBotString Right(int nCount) const; + + /** + * \brief Compare Compare a given string to an other. + * \param lpsz The string to compare. + * \return 0 if the two string matches. Less than 0 if the current + * string is less than lpsz. Greater than 0 if the current + * string is greater than lpsz. + */ + int Compare(const char* lpsz) const; + + /** + * \brief MakeUpper Uppercase the string. + */ + void MakeUpper(); + + /** + * \brief MakeLower Lowercase the string. + */ + void MakeLower(); + + /** + * @brief CStr Convert the CBotString to a C string. + * @return A C string string. + */ + const char* CStr() const; + + /** + * \brief Overloaded oprators to work on CBotString classes + */ + const CBotString& operator=(const CBotString& stringSrc); + const CBotString& operator=(const char ch); + const CBotString& operator=(const char* pString); + CBotString operator+(const CBotString& str); + + const CBotString& operator+=(const char ch); + const CBotString& operator+=(const CBotString& str); + bool operator==(const CBotString& str); + bool operator==(const char* p); + bool operator!=(const CBotString& str); + bool operator!=(const char* p); + bool operator>(const CBotString& str); + bool operator>(const char* p); + bool operator>=(const CBotString& str); + bool operator>=(const char* p); + bool operator<(const CBotString& str); + bool operator<(const char* p); + bool operator<=(const CBotString& str); + bool operator<=(const char* p); + + operator const char*() const; // as a C string + + +private: + + //! \brief Pointer to string + char* m_ptr; + + //! \brief Length of the string + int m_lg; + + //! \brief Keeps the string corresponding to keyword ID + static const std::map s_keywordString; + + /** + * \brief MapIdToString Maps given ID to its string equivalent. + * \param id Provided identifier. + * \return String if found, else NullString. + */ + static const char * MapIdToString(EID id); +}; diff --git a/src/CBot/CBotStringArray.h b/src/CBot/CBotStringArray.h index 761f874a..bc13233c 100644 --- a/src/CBot/CBotStringArray.h +++ b/src/CBot/CBotStringArray.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotDll.h" +#include "CBotString.h" // Local include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 824b3fd6..1a226dbc 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -141,6 +141,24 @@ bool WriteFloat(FILE* pf, float w) return (lg == 1); } +//////////////////////////////////////////////////////////////////////////////// +void ConstructElement(CBotString* pNewData) +{ + memset(pNewData, 0, sizeof(CBotString)); +} + +//////////////////////////////////////////////////////////////////////////////// +void DestructElement(CBotString* pOldData) +{ + pOldData->~CBotString(); +} + +//////////////////////////////////////////////////////////////////////////////// +void CopyElement(CBotString* pSrc, CBotString* pDest) +{ + *pSrc = *pDest; +} + //////////////////////////////////////////////////////////////////////////////// void ConstructElements(CBotString* pNewData, int nCount) { diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index f25c8c60..e14b4748 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -22,10 +22,14 @@ // Modules inlcude #include "CBotDll.h" +#include "CBotString.h" + // Local include // Global include +class CBotString; + /*! * \brief MakeListVars Transforms the array of pointers to variables in a * chained list of variables @@ -80,29 +84,20 @@ bool WriteFloat(FILE* pf, float w); * \brief ConstructElement * \param pNewData */ -static inline void ConstructElement(CBotString* pNewData) -{ - memset(pNewData, 0, sizeof(CBotString)); -} +void ConstructElement(CBotString* pNewData); /*! * \brief DestructElement * \param pOldData */ -static inline void DestructElement(CBotString* pOldData) -{ - pOldData->~CBotString(); -} +void DestructElement(CBotString* pOldData); /*! * \brief CopyElement * \param pSrc * \param pDest */ -static inline void CopyElement(CBotString* pSrc, CBotString* pDest) -{ - *pSrc = *pDest; -} +void CopyElement(CBotString* pSrc, CBotString* pDest); /*! * \brief ConstructElements diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 8f465fc8..68132ad2 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -24,6 +24,8 @@ #include "../CBotDefines.h" +#include "../CBotString.h" + // Local include // Global include diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index 97576a99..b0d1ede8 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBot/CBotDll.h" +#include "CBot/CBotString.h" + // Local include // Global include From 3b0561056a0247096e089464ba86b59df3438795 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Tue, 17 Nov 2015 21:06:25 +0100 Subject: [PATCH 121/360] Moving CBotTypResult class in its own header and source files. --- src/CBot/CBotClass.h | 8 +- src/CBot/CBotDll.h | 84 -------------- src/CBot/CBotProgram.h | 3 +- src/CBot/CBotTypResult.cpp | 208 +++++++++++++++++++++++++++++++++++ src/CBot/CBotTypResult.h | 112 +++++++++++++++++++ src/CBot/CBotUtils.h | 1 + src/CBot/CBotVar/CBotVar.cpp | 178 ------------------------------ src/CBot/CMakeLists.txt | 1 + src/script/scriptfunc.h | 1 + 9 files changed, 331 insertions(+), 265 deletions(-) create mode 100644 src/CBot/CBotTypResult.cpp create mode 100644 src/CBot/CBotTypResult.h diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index fe385461..b776fb5a 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -22,14 +22,18 @@ // Modules inlcude #include "CBotDll.h" -#include "CBotProgram.h" - #include "CBotDefines.h" +#include "CBotTypResult.h" + +#include "CBotString.h" + // Local include // Global include +class CBotProgram; + /*! * \brief The CBotClass class Class to define new classes in the language CBOT * for example to define the class CPoint (x, y). diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 40e4931d..fd5939d2 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -69,90 +69,6 @@ class CBotCStack; // stack #define OBJECTCREATED (reinterpret_cast(-2)) -/** \brief CBotTypResult class to define the complete type of a result*/ -class CBotTypResult -{ -public: - /** - * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString) - * \param type type of created result, see CBotType - */ - CBotTypResult(int type); - // for simple types (CBotTypInt à CBotTypString) - - - CBotTypResult(int type, const char* name); - // for pointer types and intrinsic classes - - CBotTypResult(int type, CBotClass* pClass); - // for the instance of a class - - CBotTypResult(int type, CBotTypResult elem); - // for arrays of variables - - CBotTypResult(const CBotTypResult& typ); - // for assignments - - CBotTypResult(); - // for default - - ~CBotTypResult(); - - int GetType(int mode = 0) const; - // returns type CBotType* as a result - - void SetType(int n); - // modifies a type - - CBotClass* GetClass() const; - // makes the pointer to the class (for CBotTypClass, CBotTypPointer) - - int GetLimite() const; - // returns limit size of table (CBotTypArray) - - void SetLimite(int n); - // set limit to the table - - void SetArray(int* max ); - // set limits for a list of dimensions (arrays of arrays) - - CBotTypResult& GetTypElem() const; - // returns type of array elements (CBotTypArray) - // rend le type des éléments du tableau (CBotTypArray) - - bool Compare(const CBotTypResult& typ) const; - // compares whether the types are compatible - bool Eq(int type) const; - // compare type - - CBotTypResult& operator=(const CBotTypResult& src); - // copy a complete type in another - -private: - int m_type; - CBotTypResult* m_pNext; // for the types of type - CBotClass* m_pClass; // for the derivatives of class - int m_limite; // limits of tables - friend class CBotVarClass; - friend class CBotVarPointer; -}; - -/* -// to define a result as output, using for example - - // to return a simple Float - return CBotTypResult( CBotTypFloat ); - - - // to return a string array - return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) ); - - // to return un array of array of "point" class - CBotTypResult typPoint( CBotTypIntrinsic, "point" ); - CBotTypResult arrPoint( CBotTypArray, typPoint ); - return CBotTypResult( CBotTypArray, arrPoint ); -*/ - //////////////////////////////////////////////////////////////////////// // Error Handling of compilation and execution diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index bef08a8c..f13a1af8 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -20,13 +20,14 @@ #pragma once // Modules inlcude +#include "CBotTypResult.h" +#include "CBotString.h" #include "CBotStringArray.h" // Local include // Global include - /*! * \brief The CBotProgram class Main class managing CBot program. */ diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp new file mode 100644 index 00000000..0ba8ff55 --- /dev/null +++ b/src/CBot/CBotTypResult.cpp @@ -0,0 +1,208 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotTypResult.h" + +#include "CBotEnums.h" + +#include "CBotClass.h" + +// Local include + +// Global include + + + +/////////////////////////////////////////////////////// +// management of results types + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, const char* name) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; + + if ( type == CBotTypPointer || + type == CBotTypClass || + type == CBotTypIntrinsic ) + { + m_pClass = CBotClass::Find(name); + if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; + } +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, CBotClass* pClass) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = pClass; + m_limite = -1; + + if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, CBotTypResult elem) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; + + if ( type == CBotTypArrayPointer || + type == CBotTypArrayBody ) + m_pNext = new CBotTypResult( elem ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(const CBotTypResult& typ) +{ + m_type = typ.m_type; + m_pClass = typ.m_pClass; + m_pNext = nullptr; + m_limite = typ.m_limite; + + if ( typ.m_pNext ) + m_pNext = new CBotTypResult( *typ.m_pNext ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult() +{ + m_type = 0; + m_limite = -1; + m_pNext = nullptr; + m_pClass = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::~CBotTypResult() +{ + delete m_pNext; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotTypResult::GetType(int mode) const +{ +#ifdef _DEBUG + if ( m_type == CBotTypPointer || + m_type == CBotTypClass || + m_type == CBotTypIntrinsic ) + + if ( m_pClass == nullptr ) assert(0); + + + if ( m_type == CBotTypArrayPointer ) + if ( m_pNext == nullptr ) assert(0); +#endif + if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer; + return m_type; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetType(int n) +{ + m_type = n; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotTypResult::GetClass() const +{ + return m_pClass; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult& CBotTypResult::GetTypElem() const +{ + return *m_pNext; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotTypResult::GetLimite() const +{ + return m_limite; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetLimite(int n) +{ + m_limite = n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetArray( int* max ) +{ + m_limite = *max; + if (m_limite < 1) m_limite = -1; + + if ( m_pNext != nullptr ) // last dimension? + { + m_pNext->SetArray( max+1 ); + } +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotTypResult::Compare(const CBotTypResult& typ) const +{ + if ( m_type != typ.m_type ) return false; + + if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext); + + if ( m_type == CBotTypPointer || + m_type == CBotTypClass || + m_type == CBotTypIntrinsic ) + { + return m_pClass == typ.m_pClass; + } + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotTypResult::Eq(int type) const +{ + return m_type == type; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src) +{ + m_type = src.m_type; + m_limite = src.m_limite; + m_pClass = src.m_pClass; + m_pNext = nullptr; + if ( src.m_pNext != nullptr ) + { + m_pNext = new CBotTypResult(*src.m_pNext); + } + return *this; +} diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h new file mode 100644 index 00000000..97ac52af --- /dev/null +++ b/src/CBot/CBotTypResult.h @@ -0,0 +1,112 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + +class CBotClass; + +/* +// to define a result as output, using for example + + // to return a simple Float + return CBotTypResult( CBotTypFloat ); + + + // to return a string array + return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) ); + + // to return un array of array of "point" class + CBotTypResult typPoint( CBotTypIntrinsic, "point" ); + CBotTypResult arrPoint( CBotTypArray, typPoint ); + return CBotTypResult( CBotTypArray, arrPoint ); +*/ + +/** \brief CBotTypResult class to define the complete type of a result*/ +class CBotTypResult +{ +public: + /** + * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString) + * \param type type of created result, see CBotType + */ + CBotTypResult(int type); + // for simple types (CBotTypInt à CBotTypString) + + + CBotTypResult(int type, const char* name); + // for pointer types and intrinsic classes + + CBotTypResult(int type, CBotClass* pClass); + // for the instance of a class + + CBotTypResult(int type, CBotTypResult elem); + // for arrays of variables + + CBotTypResult(const CBotTypResult& typ); + // for assignments + + CBotTypResult(); + // for default + + ~CBotTypResult(); + + int GetType(int mode = 0) const; + // returns type CBotType* as a result + + void SetType(int n); + // modifies a type + + CBotClass* GetClass() const; + // makes the pointer to the class (for CBotTypClass, CBotTypPointer) + + int GetLimite() const; + // returns limit size of table (CBotTypArray) + + void SetLimite(int n); + // set limit to the table + + void SetArray(int* max ); + // set limits for a list of dimensions (arrays of arrays) + + CBotTypResult& GetTypElem() const; + // returns type of array elements (CBotTypArray) + // rend le type des éléments du tableau (CBotTypArray) + + bool Compare(const CBotTypResult& typ) const; + // compares whether the types are compatible + bool Eq(int type) const; + // compare type + + CBotTypResult& operator=(const CBotTypResult& src); + // copy a complete type in another + +private: + int m_type; + CBotTypResult* m_pNext; // for the types of type + CBotClass* m_pClass; // for the derivatives of class + int m_limite; // limits of tables + friend class CBotVarClass; + friend class CBotVarPointer; +}; diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index e14b4748..739800eb 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -23,6 +23,7 @@ #include "CBotDll.h" #include "CBotString.h" +#include "CBotTypResult.h" // Local include diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index e2c1fe78..e5ce073e 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -759,181 +759,3 @@ CBotClass* CBotVar::GetClass() assert(0); return nullptr; } - -/////////////////////////////////////////////////////// -// management of results types - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, const char* name) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; - - if ( type == CBotTypPointer || - type == CBotTypClass || - type == CBotTypIntrinsic ) - { - m_pClass = CBotClass::Find(name); - if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; - } -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, CBotClass* pClass) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = pClass; - m_limite = -1; - - if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, CBotTypResult elem) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; - - if ( type == CBotTypArrayPointer || - type == CBotTypArrayBody ) - m_pNext = new CBotTypResult( elem ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(const CBotTypResult& typ) -{ - m_type = typ.m_type; - m_pClass = typ.m_pClass; - m_pNext = nullptr; - m_limite = typ.m_limite; - - if ( typ.m_pNext ) - m_pNext = new CBotTypResult( *typ.m_pNext ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult() -{ - m_type = 0; - m_limite = -1; - m_pNext = nullptr; - m_pClass = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::~CBotTypResult() -{ - delete m_pNext; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotTypResult::GetType(int mode) const -{ -#ifdef _DEBUG - if ( m_type == CBotTypPointer || - m_type == CBotTypClass || - m_type == CBotTypIntrinsic ) - - if ( m_pClass == nullptr ) assert(0); - - - if ( m_type == CBotTypArrayPointer ) - if ( m_pNext == nullptr ) assert(0); -#endif - if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer; - return m_type; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetType(int n) -{ - m_type = n; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotTypResult::GetClass() const -{ - return m_pClass; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult& CBotTypResult::GetTypElem() const -{ - return *m_pNext; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotTypResult::GetLimite() const -{ - return m_limite; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetLimite(int n) -{ - m_limite = n; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetArray( int* max ) -{ - m_limite = *max; - if (m_limite < 1) m_limite = -1; - - if ( m_pNext != nullptr ) // last dimension? - { - m_pNext->SetArray( max+1 ); - } -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotTypResult::Compare(const CBotTypResult& typ) const -{ - if ( m_type != typ.m_type ) return false; - - if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext); - - if ( m_type == CBotTypPointer || - m_type == CBotTypClass || - m_type == CBotTypIntrinsic ) - { - return m_pClass == typ.m_pClass; - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotTypResult::Eq(int type) const -{ - return m_type == type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src) -{ - m_type = src.m_type; - m_limite = src.m_limite; - m_pClass = src.m_pClass; - m_pNext = nullptr; - if ( src.m_pNext != nullptr ) - { - m_pNext = new CBotTypResult(*src.m_pNext); - } - return *this; -} - diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 28c73204..d8bda9ff 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -11,6 +11,7 @@ set(SOURCES CBotDefParam.cpp CBotCallMethode.cpp CBotStringArray.cpp + CBotTypResult.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index 9428879a..07b21cb9 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -25,6 +25,7 @@ #pragma once #include "CBot/CBotDll.h" +#include "CBot/CBotTypResult.h" #include "common/error.h" From 51f0675e413c9fbdd1c12dcfc1956c92285c3f60 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 14:36:50 +0100 Subject: [PATCH 122/360] Moving macro MAX from CBot.h to CBotTwoOpExpr.cpp. --- src/CBot/CBot.h | 2 -- src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 0b619fe9..a732d7ae 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -54,8 +54,6 @@ class CBotDefParam; // paramerer list of a function extern bool SaveVar(FILE* pf, CBotVar* pVar); -#define MAX(a,b) ((a>b) ? a : b) - extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index ab5bc653..6a7477f4 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -33,6 +33,8 @@ // Global include #include +#define MAX(a,b) ((a>b) ? a : b) + //////////////////////////////////////////////////////////////////////////////// CBotTwoOpExpr::CBotTwoOpExpr() { From 7b200a09228a5c6683d6556102b6413716a661f6 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 15:47:46 +0100 Subject: [PATCH 123/360] Moving global CompileParams, TypeCompatible and TypesCompatibles from CBot.cpp to CBotInstrUtils.cpp. --- src/CBot/CBot.cpp | 139 -------------------- src/CBot/CBot.h | 5 - src/CBot/CBotInstr/CBotClassInst.cpp | 3 + src/CBot/CBotInstr/CBotExpression.cpp | 3 + src/CBot/CBotInstr/CBotFunction.cpp | 2 + src/CBot/CBotInstr/CBotInstrMethode.cpp | 2 + src/CBot/CBotInstr/CBotInstrUtils.cpp | 167 ++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstrUtils.h | 61 +++++++++ src/CBot/CBotInstr/CBotListArray.cpp | 2 + src/CBot/CBotInstr/CBotNew.cpp | 2 + src/CBot/CBotInstr/CBotReturn.cpp | 3 + src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 3 + src/CBot/CMakeLists.txt | 1 + 13 files changed, 249 insertions(+), 144 deletions(-) create mode 100644 src/CBot/CBotInstr/CBotInstrUtils.cpp create mode 100644 src/CBot/CBotInstr/CBotInstrUtils.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 1822df7b..da8109f4 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -83,145 +83,6 @@ // Global include #include -////////////////////////////////////////////////////////////////////////////////////////// - -// compile a list of parameters - -CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) -{ - bool first = true; - CBotInstr* ret = nullptr; // to return to the list - - CBotCStack* pile = pStack; - int i = 0; - - if (IsOfType(p, ID_OPENPAR)) - { - int start, end; - if (!IsOfType(p, ID_CLOSEPAR)) while (true) - { - start = p->GetStart(); - pile = pile->TokenStack(); // keeps the result on the stack - - if (first) pStack->SetStartError(start); - first = false; - - CBotInstr* param = CBotExpression::Compile(p, pile); - end = p->GetStart(); - - if (!pile->IsOk()) - { - return pStack->Return(nullptr, pile); - } - - if (ret == nullptr) ret = param; - else ret->AddNext(param); // construct the list - - if (param != nullptr) - { - if (pile->GetTypResult().Eq(99)) - { - delete pStack->TokenStack(); - pStack->SetError(TX_VOID, p->GetStart()); - return nullptr; - } - ppVars[i] = pile->GetVar(); - ppVars[i]->GetToken()->SetPos(start, end); - i++; - - if (IsOfType(p, ID_COMMA)) continue; // skips the comma - if (IsOfType(p, ID_CLOSEPAR)) break; - } - - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - delete pStack->TokenStack(); - return nullptr; - } - } - ppVars[i] = nullptr; - return ret; -} - -///////////////////////////////////////////////////////////// -// check if two results are consistent to make an operation - -bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op) -{ - int t1 = type1.GetType(); - int t2 = type2.GetType(); - - int max = (t1 > t2) ? t1 : t2; - - if (max == 99) return false; // result is void? - - // special case for strin concatenation - if (op == ID_ADD && max >= CBotTypString) return true; - if (op == ID_ASSADD && max >= CBotTypString) return true; - if (op == ID_ASS && t1 == CBotTypString) return true; - - if (max >= CBotTypBoolean) - { - if ( (op == ID_EQ || op == ID_NE) && - (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && - (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE) && - (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && - (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return true; - if (t2 != t1) return false; - if (t1 == CBotTypArrayPointer) return type1.Compare(type2); - if (t1 == CBotTypPointer || - t1 == CBotTypClass || - t1 == CBotTypIntrinsic ) - { - CBotClass* c1 = type1.GetClass(); - CBotClass* c2 = type2.GetClass(); - - return c1->IsChildOf(c2) || c2->IsChildOf(c1); - // accept the case in reverse - // the transaction will be denied at runtime if the pointer is not - // compatible - } - - return true; - } - - type1.SetType(max); - type2.SetType(max); - return true; -} - -// check if two variables are compatible for parameter passing - -bool TypesCompatibles(const CBotTypResult& type1, const CBotTypResult& type2) -{ - int t1 = type1.GetType(); - int t2 = type2.GetType(); - - if (t1 == CBotTypIntrinsic) t1 = CBotTypClass; - if (t2 == CBotTypIntrinsic) t2 = CBotTypClass; - - int max = (t1 > t2) ? t1 : t2; - - if (max == 99) return false; // result is void? - - if (max >= CBotTypBoolean) - { - if (t2 != t1) return false; - - if (max == CBotTypArrayPointer) - return TypesCompatibles(type1.GetTypElem(), type2.GetTypElem()); - - if (max == CBotTypClass || max == CBotTypPointer) - return type1.GetClass() == type2.GetClass() ; - - return true ; - } - return true; -} - - ///////////////////////////////////////////////////////////////////////////////////// // file management diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index a732d7ae..2f2bdffa 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -54,11 +54,6 @@ class CBotDefParam; // paramerer list of a function extern bool SaveVar(FILE* pf, CBotVar* pVar); -extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); - -extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 ); -extern bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ); - extern bool WriteWord(FILE* pf, unsigned short w); extern bool ReadWord(FILE* pf, unsigned short& w); extern bool ReadLong(FILE* pf, long& w); diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index 5d2e0a66..d556dd77 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -19,6 +19,9 @@ // Modules inlcude #include "CBotClassInst.h" + +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotLeftExprVar.h" #include "CBotTwoOpExpr.h" #include "CBotInstArray.h" diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index b6b97837..a3612426 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -19,6 +19,9 @@ // Modules inlcude #include "CBotExpression.h" + +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotTwoOpExpr.h" #include "CBotStack.h" diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index d325020e..0a629c39 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -21,6 +21,8 @@ // Modules inlcude #include "CBotFunction.h" +#include "CBotInstr/CBotInstrUtils.h" + #include "CBot.h" #include "CBotInstr/CBotBlock.h" diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 46adf723..26f188f8 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotInstrMethode.h" +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotStack.h" #include "CBotCStack.h" #include "CBotClass.h" diff --git a/src/CBot/CBotInstr/CBotInstrUtils.cpp b/src/CBot/CBotInstr/CBotInstrUtils.cpp new file mode 100644 index 00000000..576cfa30 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrUtils.cpp @@ -0,0 +1,167 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotInstrUtils.h" + +#include "CBotToken.h" +#include "CBotCStack.h" +#include "CBotTypResult.h" +#include "CBotExpression.h" +#include "CBotClass.h" + +#include "CBotVar/CBotVar.h" + +#include "resource.h" + +// Local include + +// Global include + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) +{ + bool first = true; + CBotInstr* ret = nullptr; // to return to the list + + CBotCStack* pile = pStack; + int i = 0; + + if (IsOfType(p, ID_OPENPAR)) + { + int start, end; + if (!IsOfType(p, ID_CLOSEPAR)) while (true) + { + start = p->GetStart(); + pile = pile->TokenStack(); // keeps the result on the stack + + if (first) pStack->SetStartError(start); + first = false; + + CBotInstr* param = CBotExpression::Compile(p, pile); + end = p->GetStart(); + + if (!pile->IsOk()) + { + return pStack->Return(nullptr, pile); + } + + if (ret == nullptr) ret = param; + else ret->AddNext(param); // construct the list + + if (param != nullptr) + { + if (pile->GetTypResult().Eq(99)) + { + delete pStack->TokenStack(); + pStack->SetError(TX_VOID, p->GetStart()); + return nullptr; + } + ppVars[i] = pile->GetVar(); + ppVars[i]->GetToken()->SetPos(start, end); + i++; + + if (IsOfType(p, ID_COMMA)) continue; // skips the comma + if (IsOfType(p, ID_CLOSEPAR)) break; + } + + pStack->SetError(TX_CLOSEPAR, p->GetStart()); + delete pStack->TokenStack(); + return nullptr; + } + } + ppVars[i] = nullptr; + return ret; +} + +//////////////////////////////////////////////////////////////////////////////// +bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op) +{ + int t1 = type1.GetType(); + int t2 = type2.GetType(); + + int max = (t1 > t2) ? t1 : t2; + + if (max == 99) return false; // result is void? + + // special case for strin concatenation + if (op == ID_ADD && max >= CBotTypString) return true; + if (op == ID_ASSADD && max >= CBotTypString) return true; + if (op == ID_ASS && t1 == CBotTypString) return true; + + if (max >= CBotTypBoolean) + { + if ( (op == ID_EQ || op == ID_NE) && + (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true; + if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && + (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return true; + if ( (op == ID_EQ || op == ID_NE) && + (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return true; + if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && + (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return true; + if (t2 != t1) return false; + if (t1 == CBotTypArrayPointer) return type1.Compare(type2); + if (t1 == CBotTypPointer || + t1 == CBotTypClass || + t1 == CBotTypIntrinsic ) + { + CBotClass* c1 = type1.GetClass(); + CBotClass* c2 = type2.GetClass(); + + return c1->IsChildOf(c2) || c2->IsChildOf(c1); + // accept the case in reverse + // the transaction will be denied at runtime if the pointer is not + // compatible + } + + return true; + } + + type1.SetType(max); + type2.SetType(max); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool TypesCompatibles(const CBotTypResult& type1, const CBotTypResult& type2) +{ + int t1 = type1.GetType(); + int t2 = type2.GetType(); + + if (t1 == CBotTypIntrinsic) t1 = CBotTypClass; + if (t2 == CBotTypIntrinsic) t2 = CBotTypClass; + + int max = (t1 > t2) ? t1 : t2; + + if (max == 99) return false; // result is void? + + if (max >= CBotTypBoolean) + { + if (t2 != t1) return false; + + if (max == CBotTypArrayPointer) + return TypesCompatibles(type1.GetTypElem(), type2.GetTypElem()); + + if (max == CBotTypClass || max == CBotTypPointer) + return type1.GetClass() == type2.GetClass() ; + + return true ; + } + return true; +} diff --git a/src/CBot/CBotInstr/CBotInstrUtils.h b/src/CBot/CBotInstr/CBotInstrUtils.h new file mode 100644 index 00000000..4365aca6 --- /dev/null +++ b/src/CBot/CBotInstr/CBotInstrUtils.h @@ -0,0 +1,61 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + +// Forward declaration +class CBotInstr; +class CBotToken; +class CBotCStack; +class CBotVar; +class CBotTypResult; + +/*! + * \brief CompileParams Compile a list of parameters. + * \param p + * \param pStack + * \param ppVars + * \return + */ +CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars); + +/*! + * \brief TypeCompatible Check if two results are consistent to make an + * operation. + * \param type1 + * \param type2 + * \param op + * \return + */ +bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op = 0); + +/*! + * \brief TypesCompatibles Check if two variables are compatible for parameter + * passing. + * \param type1 + * \param type2 + * \return + */ +bool TypesCompatibles(const CBotTypResult& type1, const CBotTypResult& type2); diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 6ac0d6a0..ce1a5f8a 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotListArray.h" +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotExprNull.h" #include "CBotTwoOpExpr.h" diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 6f7d8605..b7e36316 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -24,6 +24,8 @@ #include "CBotCStack.h" #include "CBotClass.h" +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index 70c849d2..9f5d00f7 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -19,6 +19,9 @@ // Modules inlcude #include "CBotReturn.h" + +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotExpression.h" #include "CBotStack.h" diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 6a7477f4..0d97f407 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -19,6 +19,9 @@ // Modules inlcude #include "CBotTwoOpExpr.h" + +#include "CBotInstr/CBotInstrUtils.h" + #include "CBotParExpr.h" #include "CBotLogicExpr.h" #include "CBotExpression.h" diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index d8bda9ff..e2fa17ce 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES CBotStringArray.cpp CBotTypResult.cpp CBotInstr/CBotInstr.cpp + CBotInstr/CBotInstrUtils.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp CBotInstr/CBotFor.cpp From 43ac0e35f2b3c5d66738e3dd035080927d0ecb23 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 16:04:38 +0100 Subject: [PATCH 124/360] Moving global files function from CBot.cpp to CBotFileUtils.cpp --- src/CBot/CBot.cpp | 40 ----------- src/CBot/CBotDll.h | 7 -- src/CBot/CBotFileUtils.cpp | 62 ++++++++++++++++ src/CBot/CBotFileUtils.h | 71 +++++++++++++++++++ src/CBot/CMakeLists.txt | 3 +- src/level/robotmain.cpp | 1 + .../implementation/programmable_impl.cpp | 2 + src/script/script.cpp | 1 + 8 files changed, 139 insertions(+), 48 deletions(-) create mode 100644 src/CBot/CBotFileUtils.cpp create mode 100644 src/CBot/CBotFileUtils.h diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index da8109f4..52ea9c60 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -83,43 +83,3 @@ // Global include #include -///////////////////////////////////////////////////////////////////////////////////// -// file management - -// necessary because it is not possible to do the fopen in the main program -// fwrite and fread in a dll or using the FILE * returned. - - -FILE* fOpen(const char* name, const char* mode) -{ - return fopen(name, mode); -} - -int fClose(FILE* filehandle) -{ - return fclose(filehandle); -} - -size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle) -{ - return fwrite(buffer, elemsize, length, filehandle); -} - -size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle) -{ - return fread(buffer, elemsize, length, filehandle); -} - -size_t fWrite(const void *buffer, size_t length, FILE* filehandle) -{ - return fwrite(buffer, 1, length, filehandle); -} - -size_t fRead(void *buffer, size_t length, FILE* filehandle) -{ - return fread(buffer, 1, length, filehandle); -} - - -//////////////////////////////////////// - diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index fd5939d2..d1d1838e 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -147,13 +147,6 @@ class CBotCStack; // stack // for example exceptions returned by external routines // and " throw " with any number. -/////////////////////////////////////////////////////////////////////////////// -// routines for file management (* FILE) - FILE* fOpen(const char* name, const char* mode); - int fClose(FILE* filehandle); - size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle); - size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle); - #if 0 /* diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp new file mode 100644 index 00000000..1c585713 --- /dev/null +++ b/src/CBot/CBotFileUtils.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotFileUtils.h" + +// Local include + +// Global include + + + +// file management + +// necessary because it is not possible to do the fopen in the main program +// fwrite and fread in a dll or using the FILE * returned. + +//////////////////////////////////////////////////////////////////////////////// +FILE* fOpen(const char* name, const char* mode) +{ + return fopen(name, mode); +} + +//////////////////////////////////////////////////////////////////////////////// +int fClose(FILE* filehandle) +{ + return fclose(filehandle); +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t fWrite(const void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle) +{ + return fwrite(buffer, elemsize, length, filehandle); +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t fRead(void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle) +{ + return fread(buffer, elemsize, length, filehandle); +} diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h new file mode 100644 index 00000000..8f76ec4d --- /dev/null +++ b/src/CBot/CBotFileUtils.h @@ -0,0 +1,71 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + #include + +/////////////////////////////////////////////////////////////////////////////// +// routines for file management (* FILE) + +/*! + * \brief fOpen + * \param name + * \param mode + * \return + */ +FILE* fOpen(const char* name, const char* mode); + +/*! + * \brief fClose + * \param filehandle + * \return + */ +int fClose(FILE* filehandle); + +/*! + * \brief fWrite + * \param buffer + * \param elemsize + * \param length + * \param filehandle + * \return + */ +std::size_t fWrite(const void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle); + +/*! + * \brief fRead + * \param buffer + * \param elemsize + * \param length + * \param filehandle + * \return + */ +std::size_t fRead(void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle); diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index e2fa17ce..3bb1eb91 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,5 +1,7 @@ set(SOURCES CBot.cpp + CBotUtils.cpp + CBotFileUtils.cpp CBotClass.cpp CBotProgram.cpp CBotStack.cpp @@ -7,7 +9,6 @@ set(SOURCES CBotString.cpp CBotToken.cpp CBotCall.cpp - CBotUtils.cpp CBotDefParam.cpp CBotCallMethode.cpp CBotStringArray.cpp diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 8ff82eee..7cd1bdb0 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -20,6 +20,7 @@ #include "level/robotmain.h" #include "CBot/CBotDll.h" +#include "CBot/CBotFileUtils.h" // TODO must be replaced by CBot.h #include "CBot/CBotClass.h" diff --git a/src/object/implementation/programmable_impl.cpp b/src/object/implementation/programmable_impl.cpp index fe594e75..379929e5 100644 --- a/src/object/implementation/programmable_impl.cpp +++ b/src/object/implementation/programmable_impl.cpp @@ -40,6 +40,8 @@ #include "ui/controls/edit.h" +#include "CBot/CBotFileUtils.h" + #include #include diff --git a/src/script/script.cpp b/src/script/script.cpp index d87a41a6..92c658f6 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -44,6 +44,7 @@ #include "CBot/CBotToken.h" #include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotFileUtils.h" const int CBOT_IPF = 100; // CBOT: default number of instructions / frame From 2f7932ff69bfd7be0cb9e9f68998a27e05dd3304 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 16:21:30 +0100 Subject: [PATCH 125/360] Moving defines from CBotDll.h to CBotDefines.h. --- src/CBot/CBotDefines.h | 81 +++++++++++++++++++++++++++++++++++++++- src/CBot/CBotDll.h | 84 ------------------------------------------ 2 files changed, 80 insertions(+), 85 deletions(-) diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index ae72dbbb..9830fcbf 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -27,11 +27,90 @@ // Global include -#define MAXARRAYSIZE 9999 +#define MAXARRAYSIZE 9999 // variable type SetPrivate / IsPrivate #define PR_PUBLIC 0 // public variable #define PR_READ 1 // read only #define PR_PROTECT 2 // protected (inheritance) #define PR_PRIVATE 3 // strictly private + +//! Define the current CBot version +#define CBOTVERSION 104 + +// for SetUserPtr when deleting an object +// \TODO define own types to distinct between different states of objects +#define OBJECTDELETED (reinterpret_cast(-1)) +// value set before initialization +#define OBJECTCREATED (reinterpret_cast(-2)) + + +//////////////////////////////////////////////////////////////////////// +// Error Handling of compilation and execution +//////////////////////////////////////////////////////////////////////// + +// Here are the list of errors that can be returned by the module +// for compilation + +#define CBotErrOpenPar 5000 // missing the opening parenthesis +#define CBotErrClosePar 5001 // missing the closing parenthesis +#define CBotErrNotBoolean 5002 // expression must be a boolean +#define CBotErrUndefVar 5003 // undeclared variable +#define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... ) +#define CBotErrNoTerminator 5005 // semicolon expected +#define CBotErrCaseOut 5006 // case outside a switch +#define CBotErrCloseBlock 5008 // missing " } " +#define CBotErrElseWhitoutIf 5009 // else without matching if +#define CBotErrOpenBlock 5010 // missing " { " +#define CBotErrBadType1 5011 // wrong type for the assignment +#define CBotErrRedefVar 5012 // redefinition of the variable +#define CBotErrBadType2 5013 // Two operands are incompatible +#define CBotErrUndefCall 5014 // routine undefined +#define CBotErrNoDoubleDots 5015 // " : " expected +#define CBotErrBreakOutside 5017 // break outside of a loop +#define CBotErrUndefLabel 5019 // label udnefined +#define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here) +#define CBotErrNoCase 5020 // missing " case " +#define CBotErrBadNum 5021 // expected number +#define CBotErrVoid 5022 // " void " not possible here +#define CBotErrNoType 5023 // type declaration expected +#define CBotErrNoVar 5024 // variable name expected +#define CBotErrNoFunc 5025 // expected function name +#define CBotErrOverParam 5026 // too many parameters +#define CBotErrRedefFunc 5027 // this function already exists +#define CBotErrLowParam 5028 // not enough parameters +#define CBotErrBadParam 5029 // wrong types of parameters +#define CBotErrNbParam 5030 // wrong number of parameters +#define CBotErrUndefItem 5031 // element does not exist in the class +#define CBotErrUndefClass 5032 // variable is not a class +#define CBotErrNoConstruct 5033 // no appropriate constructor +#define CBotErrRedefClass 5034 // class already exists +#define CBotErrCloseIndex 5035 // " ] " expected +#define CBotErrReserved 5036 // reserved word (for a DefineNum) +#define CBotErrBadNew 5037 // wrong setting for new +#define CBotErrOpenIndex 5038 // " [ " expected +#define CBotErrBadString 5039 // expected string +#define CBotErrBadIndex 5040 // wrong index type "[ false ]" +#define CBotErrPrivate 5041 // protected item +#define CBotErrNoPublic 5042 // missing word "public" + +// here is the list of errors that can be returned by the module +// for the execution + +#define CBotErrZeroDiv 6000 // division by zero +#define CBotErrNotInit 6001 // uninitialized variable +#define CBotErrBadThrow 6002 // throw a negative value +#define CBotErrNoRetVal 6003 // function did not return results +#define CBotErrNoRun 6004 // Run() without active function +#define CBotErrUndefFunc 6005 // calling a function that no longer exists +#define CBotErrNotClass 6006 // this class does not exist +#define CBotErrNull 6007 // null pointer +#define CBotErrNan 6008 // calculation with a NAN +#define CBotErrOutArray 6009 // index out of array +#define CBotErrStackOver 6010 // stack overflow +#define CBotErrDeletedPtr 6011 // pointer to an object destroyed +#define CBotErrFileOpen 6012 // cannot open the file +#define CBotErrNotOpen 6013 // channel not open +#define CBotErrRead 6014 // error while reading +#define CBotErrWrite 6015 // writing error diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index d1d1838e..118263c6 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -37,9 +37,6 @@ #include #include - -#define CBOTVERSION 104 - //////////////////////////////////////////////////////////////////////// // forward declaration of needed classes @@ -62,87 +59,6 @@ class CBotCStack; // stack //////////////////////////////////////////////////////////////////////// //n = not implemented yet -// for SetUserPtr when deleting an object -// \TODO define own types to distinct between different states of objects -#define OBJECTDELETED (reinterpret_cast(-1)) -// value set before initialization -#define OBJECTCREATED (reinterpret_cast(-2)) - - - -//////////////////////////////////////////////////////////////////////// -// Error Handling of compilation and execution -//////////////////////////////////////////////////////////////////////// - -// Here are the list of errors that can be returned by the module -// for compilation - -#define CBotErrOpenPar 5000 // missing the opening parenthesis -#define CBotErrClosePar 5001 // missing the closing parenthesis -#define CBotErrNotBoolean 5002 // expression must be a boolean -#define CBotErrUndefVar 5003 // undeclared variable -#define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... ) -#define CBotErrNoTerminator 5005 // semicolon expected -#define CBotErrCaseOut 5006 // case outside a switch -// CBotErrNoTerm 5007, plus utile -#define CBotErrCloseBlock 5008 // missing " } " -#define CBotErrElseWhitoutIf 5009 // else without matching if -#define CBotErrOpenBlock 5010 // missing " { " -#define CBotErrBadType1 5011 // wrong type for the assignment -#define CBotErrRedefVar 5012 // redefinition of the variable -#define CBotErrBadType2 5013 // Two operands are incompatible -#define CBotErrUndefCall 5014 // routine undefined -#define CBotErrNoDoubleDots 5015 // " : " expected -// CBotErrWhile 5016, plus utile -#define CBotErrBreakOutside 5017 // break outside of a loop -#define CBotErrUndefLabel 5019 // label udnefined -#define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here) -#define CBotErrNoCase 5020 // missing " case " -#define CBotErrBadNum 5021 // expected number -#define CBotErrVoid 5022 // " void " not possible here -#define CBotErrNoType 5023 // type declaration expected -#define CBotErrNoVar 5024 // variable name expected -#define CBotErrNoFunc 5025 // expected function name -#define CBotErrOverParam 5026 // too many parameters -#define CBotErrRedefFunc 5027 // this function already exists -#define CBotErrLowParam 5028 // not enough parameters -#define CBotErrBadParam 5029 // wrong types of parameters -#define CBotErrNbParam 5030 // wrong number of parameters -#define CBotErrUndefItem 5031 // element does not exist in the class -#define CBotErrUndefClass 5032 // variable is not a class -#define CBotErrNoConstruct 5033 // no appropriate constructor -#define CBotErrRedefClass 5034 // class already exists -#define CBotErrCloseIndex 5035 // " ] " expected -#define CBotErrReserved 5036 // reserved word (for a DefineNum) -#define CBotErrBadNew 5037 // wrong setting for new -#define CBotErrOpenIndex 5038 // " [ " expected -#define CBotErrBadString 5039 // expected string -#define CBotErrBadIndex 5040 // wrong index type "[ false ]" -#define CBotErrPrivate 5041 // protected item -#define CBotErrNoPublic 5042 // missing word "public" - -// here is the list of errors that can be returned by the module -// for the execution - -#define CBotErrZeroDiv 6000 // division by zero -#define CBotErrNotInit 6001 // uninitialized variable -#define CBotErrBadThrow 6002 // throw a negative value -#define CBotErrNoRetVal 6003 // function did not return results -#define CBotErrNoRun 6004 // Run() without active function -#define CBotErrUndefFunc 6005 // calling a function that no longer exists -#define CBotErrNotClass 6006 // this class does not exist -#define CBotErrNull 6007 // null pointer -#define CBotErrNan 6008 // calculation with a NAN -#define CBotErrOutArray 6009 // index out of array -#define CBotErrStackOver 6010 // stack overflow -#define CBotErrDeletedPtr 6011 // pointer to an object destroyed - -#define CBotErrFileOpen 6012 // cannot open the file -#define CBotErrNotOpen 6013 // channel not open -#define CBotErrRead 6014 // error while reading -#define CBotErrWrite 6015 // writing error - - // other values ​​may be returned // for example exceptions returned by external routines // and " throw " with any number. From 1a6b5ded640c1a606d85fd5b5d1b68254b855423 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 16:42:51 +0100 Subject: [PATCH 126/360] Delete CBotDll.h --- src/CBot/CBot.h | 1 - src/CBot/CBotCStack.h | 5 +- src/CBot/CBotCall.h | 7 +- src/CBot/CBotClass.h | 9 +- src/CBot/CBotDefParam.h | 1 - src/CBot/CBotDll.h | 207 ---------------------------- src/CBot/CBotProgram.h | 16 ++- src/CBot/CBotStack.h | 3 + src/CBot/CBotString.h | 1 + src/CBot/CBotStringArray.cpp | 2 + src/CBot/CBotToken.h | 2 - src/CBot/CBotUtils.cpp | 2 +- src/CBot/CBotUtils.h | 7 +- src/CBot/CBotVar/CBotVar.h | 5 +- src/CBot/CBotVar/CBotVarBoolean.cpp | 21 +-- src/CBot/CBotVar/CBotVarFloat.cpp | 2 + src/CBot/CBotVar/CBotVarFloat.h | 2 - src/CBot/CBotVar/CBotVarInt.cpp | 2 + src/CBot/CBotVar/CBotVarInt.h | 2 - src/CBot/CBotVar/CBotVarString.cpp | 2 + src/CBot/CBotVar/CBotVarString.h | 2 - src/level/robotmain.cpp | 1 - src/object/old_object.cpp | 2 - src/script/script.h | 1 - src/script/scriptfunc.h | 2 +- src/ui/studio.cpp | 2 - test/cbot/console/main.cpp | 5 +- test/unit/CBot/CBotString_test.cpp | 2 - 28 files changed, 62 insertions(+), 254 deletions(-) delete mode 100644 src/CBot/CBotDll.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 2f2bdffa..1e281109 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -26,7 +26,6 @@ #pragma once #include "resource.h" -#include "CBotDll.h" // public definitions #include "CBotToken.h" // token management #include "CBotProgram.h" diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h index 28e9e886..70ce456a 100644 --- a/src/CBot/CBotCStack.h +++ b/src/CBot/CBotCStack.h @@ -20,14 +20,13 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotProgram.h" // Local include // Global include - +class CBotInstr; +class CBotDefParam; /*! * \brief The CBotCStack class Management of the stack of compilation. diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h index 103d1fc4..b4dc4fe9 100644 --- a/src/CBot/CBotCall.h +++ b/src/CBot/CBotCall.h @@ -20,15 +20,16 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotString.h" // Local include // Global include -#define STACKRUN 1 /// \def return execution directly on a suspended routine +// Forward declaration +class CBotStack; + +#define STACKRUN 1 //! \def return execution directly on a suspended routine /*! * \brief The CBotCall class. Class for routine calls (external). diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index b776fb5a..ac9e418d 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotDefines.h" #include "CBotTypResult.h" @@ -32,7 +30,14 @@ // Global include +// Forward declaration +class CBotVar; +class CBotClass; +class CBotCallMethode; +class CBotFunction; class CBotProgram; +class CBotStack; +class CBotDefParam; /*! * \brief The CBotClass class Class to define new classes in the language CBOT diff --git a/src/CBot/CBotDefParam.h b/src/CBot/CBotDefParam.h index 705660e3..6da8e2cd 100644 --- a/src/CBot/CBotDefParam.h +++ b/src/CBot/CBotDefParam.h @@ -20,7 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" #include "CBotToken.h" #include "CBotStack.h" diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h deleted file mode 100644 index 118263c6..00000000 --- a/src/CBot/CBotDll.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -//////////////////////////////////////////////////////////////////////// - -/** - * \file CBotDll.h - * \brief Library for interpretation of CBOT language - */ - -#pragma once - -// Modules inlcude -#include "resource.h" -#include "CBotEnums.h" - -// Local include - -// Global include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////// -// forward declaration of needed classes - -class CBotToken; // program turned into "tokens -class CBotStack; // for the execution stack -class CBotClass; // class of object -class CBotInstr; // instruction to be executed -class CBotFunction; // user functions -class CBotVar; // variables -class CBotVarClass; // instance of class -class CBotVarPointer; // pointer to an instance of class -class CBotCall; // functions -class CBotCallMethode; // methods -class CBotDefParam; // parameter list -class CBotCStack; // stack - - -//////////////////////////////////////////////////////////////////////// -// Variables management -//////////////////////////////////////////////////////////////////////// -//n = not implemented yet - -// other values ​​may be returned -// for example exceptions returned by external routines -// and " throw " with any number. - - -#if 0 -/* -(**) Note: - To define an external function, proceed as follows: - - a) define a routine for compilation - this routine receive list of parameters (no values) - and either returns a result type (CBotTyp... or 0 = void) - or an error number - b) define a routine for the execution - this routine receive list of parameters (with valeurs), - a variable to store the result (according to the given type at compile time) - - For example, a routine which calculates the mean of a parameter list */ - -int cMean(CBotVar* &pVar, CBotString& ClassName) -{ - if ( pVar == nullptr ) return 6001; // there is no parameter! - - while ( pVar != nullptr ) - { - if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number - pVar = pVar -> GetNext(); - } - - return CBotTypFloat; // the type of the result may depend on the parameters! -} - - -bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - float total = 0; - int nb = 0; - while (pVar != nullptr) - { - total += pVar->GetValFloat(); - pVar = pVar->GetNext(); - nb++; - } - pResult->SetValFloat(total/nb); // returns the mean value - - return true; // operation fully completed -} - -#endif - -/* -//////////////////////////////////////////////////////////////////////// -// Examples of use -// Definition classes and functions - - -// define the global class CPoint -// -------------------------------- - m_pClassPoint = new CBotClass("CPoint", nullptr); - // adds the component ".x" - m_pClassPoint->AddItem("x", CBotTypResult(CBotTypFloat)); - // adds the component ".y" - m_pClassPoint->AddItem("y", CBotTypResult(CBotTypFloat)); - // the player can then use the instructions - // CPoint position; position.x = 12; position.y = -13.6 - -// define class CColobotObject -// -------------------------------- -// This class manages all the objects in the world of COLOBOT -// the "main" user program belongs to this class - m_pClassObject = new CBotClass("CColobotObject", m_pClassBase); - // adds the component ".position" - m_pClassObject->AddItem("position", m_pClassPoint); - // adds the component ".type" - m_pClassObject->AddItem("type", CBotTypResult(CBotTypShort)); - // adds a definition of constant - m_pClassObject->AddConst("ROBOT", CBotTypShort, 1); // ROBOT equivalent to the value 1 - // adds the FIND routine - m_pClassObject->AddFunction( rCompFind, rDoFind ); - // the player can now use the instructions - // CColobotObject chose; chose = FIND( ROBOT ) - - - -// define class CColobotRobot derived from CColobotObject -// --------------------------------------------------------- -// programs "main" associated with robots as a part of this class - m_pClassRobot = new CBotClass("CColobotRobot", m_pClassObject); - // add routine GOTO - m_pClassRobot->AddFunction( rCompGoto, rDoGoto ); - // the player can now use - // GOTO( FIND ( ROBOT ) ); - - -// creates an instance of the class Robot -// ------------------------------------ -// for example a new robot which has just been manufactured - CBotVar* m_pMonRobot = new CBotVar("MonRobot", m_pClassRobot); - -// compiles the program by hand for this robot -// ------------------------------------------ - CString LeProgramme( "void main() {GOTO(0, 0); return 0;}" ); - if ( !m_pMonRobot->Compile( LeProgramme ) ) {error handling ...}; - -// build a stack for interpreter -// -------------------------------------- - CBotStack* pStack = new CBotStack(nullptr); - -// executes the main program -// ------------------------- - while( false = m_pMonRobot->Execute( "main", pStack )) - { - // program suspended - // could be pass a handle to another (safeguarding pstack for the robot one) - }; - // programme "main" finished ! - - - - -// routine that implements the GOTO (CPoint pos) -bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception ) -{ - if (pVar->GetType() != CBotTypeClass || - pVar->IsElemOfClas("CPoint") ) { exception = 6522; return false; ) - // the parameter is not the right class? - // in fact the control is done to the routine of compilation - - m_PosToGo.Copy( pVar ); // keeps the target position (object type CBotVar) - - // or so - CBotVar* temp; - temp = pVar->GetItem("x"); // is necessary for the object of type CPoint - ASSERT (temp != nullptr && temp->GetType() == CBotTypFloat); - m_PosToGo.x = temp->GetValFloat(); - - temp = pVar->GetItem("y"); // is necessary for the object of type CPoint - ASSERT (temp != nullptr && temp->GetType() == CBotTypFloat); - m_PosToGo.y = temp->GetValFloat(); - - return (m_CurentPos == m_PosToGo); // makes true if the position is reached - // returns false if one had wait yet -} - -*/ diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index f13a1af8..87dff3c2 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -24,10 +24,18 @@ #include "CBotString.h" #include "CBotStringArray.h" +#include "CBotEnums.h" + // Local include // Global include +// Forward declaration +class CBotFunction; +class CBotClass; +class CBotStack; +class CBotVar; + /*! * \brief The CBotProgram class Main class managing CBot program. */ @@ -225,9 +233,11 @@ public: * \param modestop * \return */ - bool GetPosition(const char* name, int& start, int& stop, - CBotGet modestart = GetPosExtern, - CBotGet modestop = GetPosBloc); + bool GetPosition(const char* name, + int& start, + int& stop, + CBotGet modestart = GetPosExtern, + CBotGet modestop = GetPosBloc); /*! * \brief GetFunctions diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index df69a0d4..36f45b1e 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -26,6 +26,9 @@ // Global include +// Forward declaration +class CBotInstr; +class CBotCall; /*! * \class CBotStack diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h index 3297c2b7..ea065b29 100644 --- a/src/CBot/CBotString.h +++ b/src/CBot/CBotString.h @@ -21,6 +21,7 @@ // Modules inlcude #include "CBotUtils.h" +#include "resource.h" // Local include diff --git a/src/CBot/CBotStringArray.cpp b/src/CBot/CBotStringArray.cpp index ecf53bf0..6d5d6617 100644 --- a/src/CBot/CBotStringArray.cpp +++ b/src/CBot/CBotStringArray.cpp @@ -26,6 +26,8 @@ // Global include +// Forward declaration +#include //////////////////////////////////////////////////////////////////////////////// CBotStringArray::CBotStringArray() diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index e8fd0432..85dc6988 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotStringArray.h" // Local include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 1a226dbc..c59f8745 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -30,7 +30,7 @@ // Local include // Global include - +#include //////////////////////////////////////////////////////////////////////////////// CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal) diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 739800eb..bf958bc8 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -20,16 +20,19 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotString.h" #include "CBotTypResult.h" // Local include // Global include +#include +// Forward declaration class CBotString; +class CBotVar; +class CBotToken; +class CBotCStack; /*! * \brief MakeListVars Transforms the array of pointers to variables in a diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 68132ad2..1abedb33 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "../CBotDll.h" - #include "../CBotDefines.h" #include "../CBotString.h" @@ -30,6 +28,9 @@ // Global include +// Forward declaration +class CBotVarClass; +class CBotInstr; /*! * \brief The CBotVar class Class for managing variables. May be useful to the diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp index f1c59347..b7680078 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.cpp +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotVarBoolean.h" +#include "CBotEnums.h" + #include "CBotUtils.h" // Local include @@ -30,18 +32,17 @@ //////////////////////////////////////////////////////////////////////////////// CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) { - m_token = new CBotToken(name); - m_next = nullptr; - m_pMyThis = nullptr; - m_pUserPtr = nullptr; + m_token = new CBotToken(name); + m_next = nullptr; + m_pMyThis = nullptr; + m_pUserPtr = nullptr; m_InitExpr = nullptr; - m_LimExpr = nullptr; - m_type = CBotTypBoolean; - m_binit = InitType::UNDEF; - m_bStatic = false; + m_LimExpr = nullptr; + m_type = CBotTypBoolean; + m_binit = InitType::UNDEF; + m_bStatic = false; m_mPrivate = 0; - - m_val = 0; + m_val = 0; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index 465c2940..9f25fbb7 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotVarFloat.h" +#include "CBotEnums.h" + #include "CBotToken.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index 07a3ecc6..e55378a7 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 76f89c12..67220a1a 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotVarInt.h" +#include "CBotEnums.h" + #include "CBotToken.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 65ebb8c3..524c2762 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp index 7b740147..09c4e761 100644 --- a/src/CBot/CBotVar/CBotVarString.cpp +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBotVarString.h" +#include "CBotEnums.h" + #include "CBotToken.h" #include "CBotUtils.h" diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 93007bee..75b4b1d0 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBotDll.h" - #include "CBotVar/CBotVar.h" // Local include diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 7cd1bdb0..e2c82908 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -19,7 +19,6 @@ #include "level/robotmain.h" -#include "CBot/CBotDll.h" #include "CBot/CBotFileUtils.h" // TODO must be replaced by CBot.h #include "CBot/CBotClass.h" diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 1939f655..b7a7929d 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -20,8 +20,6 @@ #include "object/old_object.h" -#include "CBot/CBotDll.h" - #include "app/app.h" #include "common/global.h" diff --git a/src/script/script.h b/src/script/script.h index d4a42eb7..be3f055a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -25,7 +25,6 @@ #pragma once // TODO replace by CBot.h -#include "CBot/CBotDll.h" #include "CBot/CBotProgram.h" #include diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index 07b21cb9..13c48893 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -24,7 +24,6 @@ #pragma once -#include "CBot/CBotDll.h" #include "CBot/CBotTypResult.h" #include "common/error.h" @@ -36,6 +35,7 @@ class CObject; class CScript; class CExchangePost; +class CBotVar; class CScriptFunctions diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 614a2888..511372fb 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -20,8 +20,6 @@ #include "ui/studio.h" -#include "CBot/CBotDll.h" - #include "app/app.h" #include "app/pausemanager.h" diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp index 83e06dea..54ea1690 100644 --- a/test/cbot/console/main.cpp +++ b/test/cbot/console/main.cpp @@ -2,7 +2,8 @@ #include #include "common/restext.h" -#include "CBot/CBotDll.h" + +#include "CBot/CBot.h" CBotTypResult cMessage(CBotVar* &var, void* user) { @@ -91,4 +92,4 @@ int main(int argc, char* argv[]) } return runErrors ? 3 : 0; -} \ No newline at end of file +} diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index b0d1ede8..3e6b6da0 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -18,8 +18,6 @@ */ // Modules inlcude -#include "CBot/CBotDll.h" - #include "CBot/CBotString.h" // Local include From 889c0fbe8e96c2a76ab8cae9884b90241e351bd2 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 17:25:46 +0100 Subject: [PATCH 127/360] Split file StringFunctions.cpp into two files StringFunctions.h and StringFunctions.cpp. --- src/CBot/CBotInstr/CBotExprNum.cpp | 98 --------------------- src/CBot/CBotProgram.cpp | 4 +- src/CBot/CBotUtils.cpp | 94 ++++++++++++++++++++ src/CBot/CBotUtils.h | 15 ++++ src/CBot/CMakeLists.txt | 1 + src/CBot/StringFunctions.cpp | 70 +++++---------- src/CBot/StringFunctions.h | 137 +++++++++++++++++++++++++++++ 7 files changed, 273 insertions(+), 146 deletions(-) create mode 100644 src/CBot/StringFunctions.h diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index 65dbd780..acf1e9a2 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -29,104 +29,6 @@ // Global include - -//////////////////////////////////////////////////////////////////////////////// -// converts a string into integer -// may be of the form 0xabc123 -long GetNumInt(const char* p) -{ - long num = 0; - while (*p >= '0' && *p <= '9') - { - num = num * 10 + *p - '0'; - p++; - } - if (*p == 'x' || *p == 'X') - { - while (*++p != 0) - { - if (*p >= '0' && *p <= '9') - { - num = num * 16 + *p - '0'; - continue; - } - if (*p >= 'A' && *p <= 'F') - { - num = num * 16 + *p - 'A' + 10; - continue; - } - if (*p >= 'a' && *p <= 'f') - { - num = num * 16 + *p - 'a' + 10; - continue; - } - break; - } - } - return num; -} - -//////////////////////////////////////////////////////////////////////////////// -// converts a string into a float number -extern float GetNumFloat(const char* p) -{ - double num = 0; - double div = 10; - bool bNeg = false; - - if (*p == '-') - { - bNeg = true; - p++; - } - while (*p >= '0' && *p <= '9') - { - num = num * 10. + (*p - '0'); - p++; - } - - if (*p == '.') - { - p++; - while (*p >= '0' && *p <= '9') - { - num = num + (*p - '0') / div; - div = div * 10; - p++; - } - } - - int exp = 0; - if (*p == 'e' || *p == 'E') - { - char neg = 0; - p++; - if (*p == '-' || *p == '+') neg = *p++; - - while (*p >= '0' && *p <= '9') - { - exp = exp * 10 + (*p - '0'); - p++; - } - if (neg == '-') exp = -exp; - } - - while (exp > 0) - { - num *= 10.0; - exp--; - } - - while (exp < 0) - { - num /= 10.0; - exp++; - } - - if (bNeg) num = -num; - return static_cast(num); -} - //////////////////////////////////////////////////////////////////////////////// CBotExprNum::CBotExprNum() { diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 4e3f2c49..4ee5bffb 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -20,6 +20,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotVar/CBotVar.h" + #include "CBotCall.h" #include "CBotStack.h" #include "CBotCStack.h" @@ -28,7 +30,7 @@ #include "CBotInstr/CBotFunction.h" -#include "StringFunctions.cpp" +#include "StringFunctions.h" // Local include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index c59f8745..5e38cb5f 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -178,3 +178,97 @@ void DestructElements(CBotString* pOldData, int nCount) pOldData++; } } + +//////////////////////////////////////////////////////////////////////////////// +long GetNumInt(const char* p) +{ + long num = 0; + while (*p >= '0' && *p <= '9') + { + num = num * 10 + *p - '0'; + p++; + } + if (*p == 'x' || *p == 'X') + { + while (*++p != 0) + { + if (*p >= '0' && *p <= '9') + { + num = num * 16 + *p - '0'; + continue; + } + if (*p >= 'A' && *p <= 'F') + { + num = num * 16 + *p - 'A' + 10; + continue; + } + if (*p >= 'a' && *p <= 'f') + { + num = num * 16 + *p - 'a' + 10; + continue; + } + break; + } + } + return num; +} + +//////////////////////////////////////////////////////////////////////////////// +float GetNumFloat(const char* p) +{ + double num = 0; + double div = 10; + bool bNeg = false; + + if (*p == '-') + { + bNeg = true; + p++; + } + while (*p >= '0' && *p <= '9') + { + num = num * 10. + (*p - '0'); + p++; + } + + if (*p == '.') + { + p++; + while (*p >= '0' && *p <= '9') + { + num = num + (*p - '0') / div; + div = div * 10; + p++; + } + } + + int exp = 0; + if (*p == 'e' || *p == 'E') + { + char neg = 0; + p++; + if (*p == '-' || *p == '+') neg = *p++; + + while (*p >= '0' && *p <= '9') + { + exp = exp * 10 + (*p - '0'); + p++; + } + if (neg == '-') exp = -exp; + } + + while (exp > 0) + { + num *= 10.0; + exp--; + } + + while (exp < 0) + { + num /= 10.0; + exp++; + } + + if (bNeg) num = -num; + return static_cast(num); +} diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index bf958bc8..0ce76414 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -116,3 +116,18 @@ void ConstructElements(CBotString* pNewData, int nCount); * \param nCount */ void DestructElements(CBotString* pOldData, int nCount); + +/*! + * \brief GetNumInt Converts a string into integer may be of the form 0xabc123. + * \param p + * \return + */ +long GetNumInt(const char* p); + +/*! + * \brief GetNumFloat Converts a string into a float number. + * \param p + * \return + */ +float GetNumFloat(const char* p); + diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 3bb1eb91..a2d530e1 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES CBotCallMethode.cpp CBotStringArray.cpp CBotTypResult.cpp + StringFunctions.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotInstrUtils.cpp CBotInstr/CBotWhile.cpp diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp index 640efc19..c38af371 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/StringFunctions.cpp @@ -17,15 +17,20 @@ * along with this program. If not, see http://gnu.org/licenses */ +// Modules inlcude +#include "StringFunctions.h" + +#include "CBotProgram.h" +#include "CBotEnums.h" + #include "CBotVar/CBotVar.h" -// definition of string functions +// Local include -// gives the length of a chain -// execution - +// Global include +//////////////////////////////////////////////////////////////////////////////// bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -45,9 +50,7 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// int xxx ( string ) -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cIntStr( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -64,10 +67,7 @@ CBotTypResult cIntStr( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypInt ); } - -// gives the left side of a chain -// execution - +//////////////////////////////////////////////////////////////////////////////// bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -100,9 +100,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// string xxx ( string, int ) -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -127,9 +125,7 @@ CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypString ); } -// gives the right of a string -// execution - +//////////////////////////////////////////////////////////////////////////////// bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -162,9 +158,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// gives the central part of a chain -// execution - +//////////////////////////////////////////////////////////////////////////////// bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -214,9 +208,7 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// gives the central part of a chain -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -251,10 +243,7 @@ CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypString ); } - -// gives the number stored in a string -// execution - +//////////////////////////////////////////////////////////////////////////////// bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -276,9 +265,7 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// float xxx ( string ) -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -295,10 +282,7 @@ CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypFloat ); } - -// find string in other -// exécution - +//////////////////////////////////////////////////////////////////////////////// bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -330,9 +314,7 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// int xxx ( string, string ) -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -357,9 +339,7 @@ CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypInt ); } -// gives a string to uppercase -// exécution - +//////////////////////////////////////////////////////////////////////////////// bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -382,9 +362,7 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// gives a string to lowercase -// exécution - +//////////////////////////////////////////////////////////////////////////////// bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter @@ -407,9 +385,7 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -// string xxx ( string ) -// compilation - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult cStrStr( CBotVar* &pVar, void* pUser ) { // it takes a parameter @@ -426,7 +402,7 @@ CBotTypResult cStrStr( CBotVar* &pVar, void* pUser ) return CBotTypResult( CBotTypString ); } - +//////////////////////////////////////////////////////////////////////////////// void InitStringFunctions() { CBotProgram::AddFunction("strlen", rStrLen, cIntStr ); diff --git a/src/CBot/StringFunctions.h b/src/CBot/StringFunctions.h new file mode 100644 index 00000000..da534aad --- /dev/null +++ b/src/CBot/StringFunctions.h @@ -0,0 +1,137 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude +#include "CBotTypResult.h" + +// Local include + +// Global include + +// Forward declaration +class CBotVar; + +/*! + * \brief rStrLen Gives the length of a chain execution + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief cIntStr int xxx ( string ) compilation + * \param pVar + * \param pUser + * \return + */ +CBotTypResult cIntStr( CBotVar* &pVar, void* pUser ); + +/*! + * \brief rStrLeft Gives the left side of a chain execution + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief cStrStrInt string xxx ( string, int ) compilation + * \param pVar + * \param pUser + * \return + */ +CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser ); + +/*! + * \brief rStrRight Gives the right of a string execution + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief rStrMid Gives the central part of a chain execution + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief rStrVal Gives the number stored in a string execution. + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief cIntStrStr int xxx ( string, string ) compilation + * \param pVar + * \param pUser + * \return + */ +CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser ); + +/*! + * \brief rStrUpper Gives a string to uppercase exécution + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief rStrLower Gives a string to lowercase exécution. + * \param pVar + * \param pResult + * \param ex + * \param pUser + * \return + */ +bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); + +/*! + * \brief cStrStr String xxx ( string ) compilation + * \param pVar + * \param pUser + * \return + */ +CBotTypResult cStrStr( CBotVar* &pVar, void* pUser ); + +/*! + * \brief InitStringFunctions + */ +void InitStringFunctions(); From 751999064bbb478e274b6b20a9fe96697b6e647b Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 17:36:01 +0100 Subject: [PATCH 128/360] Moving global files function from CBotProgram.cpp to CBotFileUtils.cpp. --- src/CBot/CBot.h | 15 ---- src/CBot/CBotClass.cpp | 1 + src/CBot/CBotFileUtils.cpp | 113 ++++++++++++++++++++++++++++ src/CBot/CBotFileUtils.h | 85 +++++++++++++++++++++ src/CBot/CBotProgram.cpp | 108 +------------------------- src/CBot/CBotStack.cpp | 2 + src/CBot/CBotVar/CBotVarArray.cpp | 2 + src/CBot/CBotVar/CBotVarClass.cpp | 2 + src/CBot/CBotVar/CBotVarPointer.cpp | 3 + 9 files changed, 209 insertions(+), 122 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 1e281109..458cfdd2 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -50,21 +50,6 @@ class CBotWhile; // while (...) {...}; class CBotIf; // if (...) {...} else {...} class CBotDefParam; // paramerer list of a function - -extern bool SaveVar(FILE* pf, CBotVar* pVar); - -extern bool WriteWord(FILE* pf, unsigned short w); -extern bool ReadWord(FILE* pf, unsigned short& w); -extern bool ReadLong(FILE* pf, long& w); -extern bool WriteFloat(FILE* pf, float w); -extern bool WriteLong(FILE* pf, long w); -extern bool ReadFloat(FILE* pf, float& w); -extern bool ReadString(FILE* pf, CBotString& s); -extern bool WriteType(FILE* pf, CBotTypResult type); -extern bool ReadType(FILE* pf, CBotTypResult& type); - -extern float GetNumFloat( const char* p ); - #if 0 extern void DEBUG( const char* text, int val, CBotStack* pile ); #endif diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 94a05346..172f2cd3 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -32,6 +32,7 @@ #include "CBotStack.h" #include "CBotCStack.h" #include "CBotUtils.h" +#include "CBotFileUtils.h" #include "CBotCallMethode.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp index 1c585713..bb561bdf 100644 --- a/src/CBot/CBotFileUtils.cpp +++ b/src/CBot/CBotFileUtils.cpp @@ -20,6 +20,11 @@ // Modules inlcude #include "CBotFileUtils.h" +#include "CBotString.h" +#include "CBotClass.h" + +#include "CBotEnums.h" + // Local include // Global include @@ -60,3 +65,111 @@ std::size_t fRead(void *buffer, { return fread(buffer, elemsize, length, filehandle); } + + +//////////////////////////////////////////////////////////////////////////////// +bool ReadWord(FILE* pf, unsigned short& w) +{ + size_t lg; + + lg = fread(&w, sizeof( unsigned short ), 1, pf ); + + return (lg == 1); +} + +//////////////////////////////////////////////////////////////////////////////// +bool ReadFloat(FILE* pf, float& w) +{ + size_t lg; + + lg = fread(&w, sizeof( float ), 1, pf ); + + return (lg == 1); +} + +//////////////////////////////////////////////////////////////////////////////// +bool WriteLong(FILE* pf, long w) +{ + size_t lg; + + lg = fwrite(&w, sizeof( long ), 1, pf ); + + return (lg == 1); +} + +//////////////////////////////////////////////////////////////////////////////// +bool ReadLong(FILE* pf, long& w) +{ + size_t lg; + + lg = fread(&w, sizeof( long ), 1, pf ); + + return (lg == 1); +} + +//////////////////////////////////////////////////////////////////////////////// +bool ReadString(FILE* pf, CBotString& s) +{ + unsigned short w; + char buf[1000]; + size_t lg1, lg2; + + if (!ReadWord(pf, w)) return false; + lg1 = w; + lg2 = fread(buf, 1, lg1, pf ); + buf[lg2] = 0; + + s = buf; + return (lg1 == lg2); +} + +//////////////////////////////////////////////////////////////////////////////// +bool WriteType(FILE* pf, CBotTypResult type) +{ + int typ = type.GetType(); + if ( typ == CBotTypIntrinsic ) typ = CBotTypClass; + if ( !WriteWord(pf, typ) ) return false; + if ( typ == CBotTypClass ) + { + CBotClass* p = type.GetClass(); + if ( !WriteString(pf, p->GetName()) ) return false; + } + if ( type.Eq( CBotTypArrayBody ) || + type.Eq( CBotTypArrayPointer ) ) + { + if ( !WriteWord(pf, type.GetLimite()) ) return false; + if ( !WriteType(pf, type.GetTypElem()) ) return false; + } + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool ReadType(FILE* pf, CBotTypResult& type) +{ + unsigned short w, ww; + if ( !ReadWord(pf, w) ) return false; + type.SetType(w); + + if ( type.Eq( CBotTypIntrinsic ) ) + { + type = CBotTypResult( w, "point" ); + } + + if ( type.Eq( CBotTypClass ) ) + { + CBotString s; + if ( !ReadString(pf, s) ) return false; + type = CBotTypResult( w, s ); + } + + if ( type.Eq( CBotTypArrayPointer ) || + type.Eq( CBotTypArrayBody ) ) + { + CBotTypResult r; + if ( !ReadWord(pf, ww) ) return false; + if ( !ReadType(pf, r) ) return false; + type = CBotTypResult( w, r ); + type.SetLimite(static_cast(ww)); + } + return true; +} diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h index 8f76ec4d..1ac1664b 100644 --- a/src/CBot/CBotFileUtils.h +++ b/src/CBot/CBotFileUtils.h @@ -20,12 +20,17 @@ #pragma once // Modules inlcude +#include "CBotTypResult.h" // Local include // Global include #include +// Forward declaration +class CBotVar; +class CBotString; + /////////////////////////////////////////////////////////////////////////////// // routines for file management (* FILE) @@ -69,3 +74,83 @@ std::size_t fRead(void *buffer, std::size_t elemsize, std::size_t length, FILE* filehandle); + +/*! + * \brief SaveVar + * \param pf + * \param pVar + * \return + */ +bool SaveVar(FILE* pf, CBotVar* pVar); + +/*! + * \brief WriteWord + * \param pf + * \param w + * \return + */ +bool WriteWord(FILE* pf, unsigned short w); + +/*! + * \brief ReadWord + * \param pf + * \param w + * \return + */ +bool ReadWord(FILE* pf, unsigned short& w); + +/*! + * \brief ReadLong + * \param pf + * \param w + * \return + */ +bool ReadLong(FILE* pf, long& w); + +/*! + * \brief WriteFloat + * \param pf + * \param w + * \return + */ +bool WriteFloat(FILE* pf, float w); + +/*! + * \brief WriteLong + * \param pf + * \param w + * \return + */ +bool WriteLong(FILE* pf, long w); + +/*! + * \brief ReadFloat + * \param pf + * \param w + * \return + */ +bool ReadFloat(FILE* pf, float& w); + +/*! + * \brief ReadString + * \param pf + * \param s + * \return + */ +bool ReadString(FILE* pf, CBotString& s); + +/*! + * \brief WriteType + * \param pf + * \param type + * \return + */ +bool WriteType(FILE* pf, CBotTypResult type); + +/*! + * \brief ReadType + * \param pf + * \param type + * \return + */ +bool ReadType(FILE* pf, CBotTypResult& type); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 4ee5bffb..187f560e 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -27,6 +27,7 @@ #include "CBotCStack.h" #include "CBotClass.h" #include "CBotUtils.h" +#include "CBotFileUtils.h" #include "CBotInstr/CBotFunction.h" @@ -385,113 +386,6 @@ bool CBotProgram::AddFunction(const char* name, return CBotCall::AddFunction(name, rExec, rCompile); } -//////////////////////////////////////////////////////////////////////////////// -bool ReadWord(FILE* pf, unsigned short& w) -{ - size_t lg; - - lg = fread(&w, sizeof( unsigned short ), 1, pf ); - - return (lg == 1); -} - -//////////////////////////////////////////////////////////////////////////////// -bool ReadFloat(FILE* pf, float& w) -{ - size_t lg; - - lg = fread(&w, sizeof( float ), 1, pf ); - - return (lg == 1); -} - -//////////////////////////////////////////////////////////////////////////////// -bool WriteLong(FILE* pf, long w) -{ - size_t lg; - - lg = fwrite(&w, sizeof( long ), 1, pf ); - - return (lg == 1); -} - -//////////////////////////////////////////////////////////////////////////////// -bool ReadLong(FILE* pf, long& w) -{ - size_t lg; - - lg = fread(&w, sizeof( long ), 1, pf ); - - return (lg == 1); -} - -//////////////////////////////////////////////////////////////////////////////// -bool ReadString(FILE* pf, CBotString& s) -{ - unsigned short w; - char buf[1000]; - size_t lg1, lg2; - - if (!ReadWord(pf, w)) return false; - lg1 = w; - lg2 = fread(buf, 1, lg1, pf ); - buf[lg2] = 0; - - s = buf; - return (lg1 == lg2); -} - -//////////////////////////////////////////////////////////////////////////////// -bool WriteType(FILE* pf, CBotTypResult type) -{ - int typ = type.GetType(); - if ( typ == CBotTypIntrinsic ) typ = CBotTypClass; - if ( !WriteWord(pf, typ) ) return false; - if ( typ == CBotTypClass ) - { - CBotClass* p = type.GetClass(); - if ( !WriteString(pf, p->GetName()) ) return false; - } - if ( type.Eq( CBotTypArrayBody ) || - type.Eq( CBotTypArrayPointer ) ) - { - if ( !WriteWord(pf, type.GetLimite()) ) return false; - if ( !WriteType(pf, type.GetTypElem()) ) return false; - } - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -bool ReadType(FILE* pf, CBotTypResult& type) -{ - unsigned short w, ww; - if ( !ReadWord(pf, w) ) return false; - type.SetType(w); - - if ( type.Eq( CBotTypIntrinsic ) ) - { - type = CBotTypResult( w, "point" ); - } - - if ( type.Eq( CBotTypClass ) ) - { - CBotString s; - if ( !ReadString(pf, s) ) return false; - type = CBotTypResult( w, s ); - } - - if ( type.Eq( CBotTypArrayPointer ) || - type.Eq( CBotTypArrayBody ) ) - { - CBotTypResult r; - if ( !ReadWord(pf, ww) ) return false; - if ( !ReadType(pf, r) ) return false; - type = CBotTypResult( w, r ); - type.SetLimite(static_cast(ww)); - } - return true; -} - //////////////////////////////////////////////////////////////////////////////// bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 91f91a93..ac312c9a 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -26,6 +26,8 @@ #include "CBotVar/CBotVarPointer.h" #include "CBotVar/CBotVarClass.h" +#include "CBotFileUtils.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index b030e7ae..59a3b97d 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -21,6 +21,8 @@ #include "CBotVarArray.h" #include "CBotVarClass.h" +#include "CBotFileUtils.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 4d6ee787..467255cb 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -24,6 +24,8 @@ #include "CBotStack.h" #include "CBotDefines.h" +#include "CBotFileUtils.h" + #include "CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index df333221..9bbaee78 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -23,6 +23,9 @@ #include "CBot.h" #include "CBotClass.h" #include "CBotVarClass.h" + +#include "CBotFileUtils.h" + // Local include // Global include From b28e2aec0170930d7bdbec9288cb7318217bf06f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 17:38:16 +0100 Subject: [PATCH 129/360] Moving some define from CBot.h to CBotDefines.h. --- src/CBot/CBot.h | 5 ----- src/CBot/CBotDefines.h | 5 +++++ src/CBot/CBotStack.h | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 458cfdd2..97e2919f 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -29,11 +29,6 @@ #include "CBotToken.h" // token management #include "CBotProgram.h" -#define STACKMEM 1 /// \def preserve memory for the execution stack -#define MAXSTACK 990 /// \def stack size reserved - -#define EOX (reinterpret_cast(-1)) /// \def tag special condition - ///////////////////////////////////////////////////////////////////// // forward declaration diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 9830fcbf..9cb70ab7 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -28,6 +28,11 @@ // Global include +#define STACKMEM 1 /// \def preserve memory for the execution stack +#define MAXSTACK 990 /// \def stack size reserved + +#define EOX (reinterpret_cast(-1)) /// \def tag special condition + #define MAXARRAYSIZE 9999 // variable type SetPrivate / IsPrivate diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 36f45b1e..283a8ae3 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -22,6 +22,8 @@ // Modules inlcude #include "CBot.h" +#include "CBotDefines.h" + // Local include // Global include From cedaaad45901d3973bfcd35b616294fccc764808 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 17:39:35 +0100 Subject: [PATCH 130/360] Deleted file CBot.cpp. --- src/CBot/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index a2d530e1..0d1cc7cd 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,5 +1,4 @@ set(SOURCES - CBot.cpp CBotUtils.cpp CBotFileUtils.cpp CBotClass.cpp From 575ff47c829c775eb92cac058115bda3d54149d1 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 17:54:40 +0100 Subject: [PATCH 131/360] Cleaning the CBot.h file. --- src/CBot/CBot.h | 32 +++---------------------- src/CBot/CBotCallMethode.h | 8 +++++-- src/CBot/CBotDefParam.cpp | 2 -- src/CBot/CBotInstr/CBotBlock.h | 2 -- src/CBot/CBotInstr/CBotBoolExpr.h | 2 -- src/CBot/CBotInstr/CBotBoolean.h | 2 -- src/CBot/CBotInstr/CBotBreak.h | 2 -- src/CBot/CBotInstr/CBotCase.h | 2 -- src/CBot/CBotInstr/CBotCatch.h | 2 -- src/CBot/CBotInstr/CBotClassInst.h | 2 -- src/CBot/CBotInstr/CBotCondition.h | 2 -- src/CBot/CBotInstr/CBotDo.h | 2 -- src/CBot/CBotInstr/CBotEmpty.h | 2 -- src/CBot/CBotInstr/CBotExprAlpha.h | 2 -- src/CBot/CBotInstr/CBotExprBool.h | 2 -- src/CBot/CBotInstr/CBotExprNan.h | 2 -- src/CBot/CBotInstr/CBotExprNull.h | 2 -- src/CBot/CBotInstr/CBotExprNum.h | 2 -- src/CBot/CBotInstr/CBotExprUnaire.h | 2 -- src/CBot/CBotInstr/CBotExprVar.h | 2 -- src/CBot/CBotInstr/CBotExpression.h | 2 -- src/CBot/CBotInstr/CBotFieldExpr.h | 2 -- src/CBot/CBotInstr/CBotFloat.h | 2 -- src/CBot/CBotInstr/CBotFor.h | 2 -- src/CBot/CBotInstr/CBotFunction.cpp | 2 -- src/CBot/CBotInstr/CBotFunction.h | 2 -- src/CBot/CBotInstr/CBotIString.h | 2 -- src/CBot/CBotInstr/CBotIf.h | 2 -- src/CBot/CBotInstr/CBotIndexExpr.h | 2 -- src/CBot/CBotInstr/CBotInstArray.h | 2 -- src/CBot/CBotInstr/CBotInstrCall.h | 2 -- src/CBot/CBotInstr/CBotInstrMethode.h | 2 -- src/CBot/CBotInstr/CBotInt.h | 2 -- src/CBot/CBotInstr/CBotLeftExpr.h | 2 -- src/CBot/CBotInstr/CBotLeftExprVar.h | 2 -- src/CBot/CBotInstr/CBotListArray.h | 2 -- src/CBot/CBotInstr/CBotListExpression.h | 2 -- src/CBot/CBotInstr/CBotListInstr.h | 2 -- src/CBot/CBotInstr/CBotLogicExpr.h | 2 -- src/CBot/CBotInstr/CBotNew.h | 2 -- src/CBot/CBotInstr/CBotParExpr.h | 2 -- src/CBot/CBotInstr/CBotPostIncExpr.h | 2 -- src/CBot/CBotInstr/CBotPreIncExpr.h | 2 -- src/CBot/CBotInstr/CBotReturn.h | 2 -- src/CBot/CBotInstr/CBotSwitch.h | 2 -- src/CBot/CBotInstr/CBotThrow.h | 2 -- src/CBot/CBotInstr/CBotTry.h | 1 - src/CBot/CBotInstr/CBotTwoOpExpr.h | 2 -- src/CBot/CBotInstr/CBotWhile.h | 2 -- src/CBot/CBotProgram.cpp | 2 -- src/CBot/CBotStack.h | 18 +++++++++----- src/CBot/CBotString.cpp | 5 ++-- src/CBot/CBotToken.cpp | 2 +- src/CBot/CBotVar/CBotVar.cpp | 2 ++ src/CBot/CBotVar/CBotVarArray.cpp | 4 +++- src/CBot/CBotVar/CBotVarArray.h | 1 - src/CBot/CBotVar/CBotVarClass.h | 2 -- src/CBot/CBotVar/CBotVarPointer.cpp | 3 ++- 58 files changed, 31 insertions(+), 141 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 97e2919f..868bf137 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -17,34 +17,8 @@ * along with this program. If not, see http://gnu.org/licenses */ -//////////////////////////////////////////////////////////////////// -/** - * \file CBot.h - * \brief Interpreter of the language CBot for COLOBOT game - */ +// Modules inlcude -#pragma once +// Local include -#include "resource.h" -#include "CBotToken.h" // token management -#include "CBotProgram.h" - - -///////////////////////////////////////////////////////////////////// -// forward declaration - -class CBotParExpr; // basic type or instruction in parenthesis - // Toto.truc - // 12.5 - // "string" - // ( expression ) -class CBotExprVar; // a variable name as - // Toto - // chose.truc.machin -class CBotWhile; // while (...) {...}; -class CBotIf; // if (...) {...} else {...} -class CBotDefParam; // paramerer list of a function - -#if 0 -extern void DEBUG( const char* text, int val, CBotStack* pile ); -#endif +// Global include diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h index 8ea40254..d60a9b77 100644 --- a/src/CBot/CBotCallMethode.h +++ b/src/CBot/CBotCallMethode.h @@ -20,12 +20,16 @@ #pragma once // Modules inlcude -#include "CBot.h" +#include "CBotTypResult.h" +#include "CBotString.h" // Local include // Global include - +class CBotVar; +class CBotCStack; +class CBotStack; +class CBotToken; /*! * \brief The CBotCallMethode class Class managing the methods declared by diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 9af6043f..fe7ce8bf 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -20,8 +20,6 @@ // Modules inlcude #include "CBotDefParam.h" -#include "CBot.h" - #include "CBotUtils.h" #include "CBotCStack.h" diff --git a/src/CBot/CBotInstr/CBotBlock.h b/src/CBot/CBotInstr/CBotBlock.h index 6c7c6334..7df0bb5b 100644 --- a/src/CBot/CBotInstr/CBotBlock.h +++ b/src/CBot/CBotInstr/CBotBlock.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.h b/src/CBot/CBotInstr/CBotBoolExpr.h index e50d8a63..af6cd4f8 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.h +++ b/src/CBot/CBotInstr/CBotBoolExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolean.h b/src/CBot/CBotInstr/CBotBoolean.h index 217daadc..e589f508 100644 --- a/src/CBot/CBotInstr/CBotBoolean.h +++ b/src/CBot/CBotInstr/CBotBoolean.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h index ae35a70f..78b39dd3 100644 --- a/src/CBot/CBotInstr/CBotBreak.h +++ b/src/CBot/CBotInstr/CBotBreak.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCase.h b/src/CBot/CBotInstr/CBotCase.h index e5043330..03ddddde 100644 --- a/src/CBot/CBotInstr/CBotCase.h +++ b/src/CBot/CBotInstr/CBotCase.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCatch.h b/src/CBot/CBotInstr/CBotCatch.h index d4450ec1..60ee00a9 100644 --- a/src/CBot/CBotInstr/CBotCatch.h +++ b/src/CBot/CBotInstr/CBotCatch.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotClassInst.h b/src/CBot/CBotInstr/CBotClassInst.h index 3ee791f0..ab70c0f2 100644 --- a/src/CBot/CBotInstr/CBotClassInst.h +++ b/src/CBot/CBotInstr/CBotClassInst.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCondition.h b/src/CBot/CBotInstr/CBotCondition.h index 3958cadb..f36c998a 100644 --- a/src/CBot/CBotInstr/CBotCondition.h +++ b/src/CBot/CBotInstr/CBotCondition.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h index 11fe40f4..30f1db9d 100644 --- a/src/CBot/CBotInstr/CBotDo.h +++ b/src/CBot/CBotInstr/CBotDo.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotEmpty.h b/src/CBot/CBotInstr/CBotEmpty.h index dc50b49b..782e87ca 100644 --- a/src/CBot/CBotInstr/CBotEmpty.h +++ b/src/CBot/CBotInstr/CBotEmpty.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.h b/src/CBot/CBotInstr/CBotExprAlpha.h index 3cadc322..01e97a8e 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.h +++ b/src/CBot/CBotInstr/CBotExprAlpha.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprBool.h b/src/CBot/CBotInstr/CBotExprBool.h index 90f53daa..a81ec2ee 100644 --- a/src/CBot/CBotInstr/CBotExprBool.h +++ b/src/CBot/CBotInstr/CBotExprBool.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNan.h b/src/CBot/CBotInstr/CBotExprNan.h index 1f0d58d8..c7c25963 100644 --- a/src/CBot/CBotInstr/CBotExprNan.h +++ b/src/CBot/CBotInstr/CBotExprNan.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNull.h b/src/CBot/CBotInstr/CBotExprNull.h index 90b3f89a..662ded3d 100644 --- a/src/CBot/CBotInstr/CBotExprNull.h +++ b/src/CBot/CBotInstr/CBotExprNull.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNum.h b/src/CBot/CBotInstr/CBotExprNum.h index 07fca7e9..e9ccf932 100644 --- a/src/CBot/CBotInstr/CBotExprNum.h +++ b/src/CBot/CBotInstr/CBotExprNum.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.h b/src/CBot/CBotInstr/CBotExprUnaire.h index 75b30a94..660afdd7 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.h +++ b/src/CBot/CBotInstr/CBotExprUnaire.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h index 638cf8fe..9757b898 100644 --- a/src/CBot/CBotInstr/CBotExprVar.h +++ b/src/CBot/CBotInstr/CBotExprVar.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotDefines.h" #include "CBotInstr.h" diff --git a/src/CBot/CBotInstr/CBotExpression.h b/src/CBot/CBotInstr/CBotExpression.h index ddf2e257..637ff051 100644 --- a/src/CBot/CBotInstr/CBotExpression.h +++ b/src/CBot/CBotInstr/CBotExpression.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotLeftExpr.h" #include "CBotInstr.h" diff --git a/src/CBot/CBotInstr/CBotFieldExpr.h b/src/CBot/CBotInstr/CBotFieldExpr.h index 41e828bd..4a56a3f6 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.h +++ b/src/CBot/CBotInstr/CBotFieldExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFloat.h b/src/CBot/CBotInstr/CBotFloat.h index 309697b0..3e095fe5 100644 --- a/src/CBot/CBotInstr/CBotFloat.h +++ b/src/CBot/CBotInstr/CBotFloat.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h index d7d4256d..56442b0c 100644 --- a/src/CBot/CBotInstr/CBotFor.h +++ b/src/CBot/CBotInstr/CBotFor.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 0a629c39..f8e4b6df 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -23,8 +23,6 @@ #include "CBotInstr/CBotInstrUtils.h" -#include "CBot.h" - #include "CBotInstr/CBotBlock.h" #include "CBotInstr/CBotTwoOpExpr.h" #include "CBotInstr/CBotExpression.h" diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index f1fc3c8d..7c44dc3e 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIString.h b/src/CBot/CBotInstr/CBotIString.h index 2ea8e4ee..1435bb36 100644 --- a/src/CBot/CBotInstr/CBotIString.h +++ b/src/CBot/CBotInstr/CBotIString.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIf.h b/src/CBot/CBotInstr/CBotIf.h index e39e5226..de4c3672 100644 --- a/src/CBot/CBotInstr/CBotIf.h +++ b/src/CBot/CBotInstr/CBotIf.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.h b/src/CBot/CBotInstr/CBotIndexExpr.h index a8e7e07a..fe1ea555 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.h +++ b/src/CBot/CBotInstr/CBotIndexExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstArray.h b/src/CBot/CBotInstr/CBotInstArray.h index 4ad025d6..2b02c66d 100644 --- a/src/CBot/CBotInstr/CBotInstArray.h +++ b/src/CBot/CBotInstr/CBotInstArray.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrCall.h b/src/CBot/CBotInstr/CBotInstrCall.h index fa634fed..db259039 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.h +++ b/src/CBot/CBotInstr/CBotInstrCall.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h index ea398115..f9447609 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.h +++ b/src/CBot/CBotInstr/CBotInstrMethode.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInt.h b/src/CBot/CBotInstr/CBotInt.h index 085e6265..113897f6 100644 --- a/src/CBot/CBotInstr/CBotInt.h +++ b/src/CBot/CBotInstr/CBotInt.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.h b/src/CBot/CBotInstr/CBotLeftExpr.h index aaf9ee47..5f09b507 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.h +++ b/src/CBot/CBotInstr/CBotLeftExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.h b/src/CBot/CBotInstr/CBotLeftExprVar.h index fd693727..0c9e0cc2 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.h +++ b/src/CBot/CBotInstr/CBotLeftExprVar.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 586cc864..32a155c6 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListExpression.h b/src/CBot/CBotInstr/CBotListExpression.h index 451b2181..a4ea3b2f 100644 --- a/src/CBot/CBotInstr/CBotListExpression.h +++ b/src/CBot/CBotInstr/CBotListExpression.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.h b/src/CBot/CBotInstr/CBotListInstr.h index 0aafaf59..b0612d86 100644 --- a/src/CBot/CBotInstr/CBotListInstr.h +++ b/src/CBot/CBotInstr/CBotListInstr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLogicExpr.h b/src/CBot/CBotInstr/CBotLogicExpr.h index db6c67f6..25e67854 100644 --- a/src/CBot/CBotInstr/CBotLogicExpr.h +++ b/src/CBot/CBotInstr/CBotLogicExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotNew.h b/src/CBot/CBotInstr/CBotNew.h index 02598b1a..f93bb6be 100644 --- a/src/CBot/CBotInstr/CBotNew.h +++ b/src/CBot/CBotInstr/CBotNew.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h index 690d6efb..3fdbb639 100644 --- a/src/CBot/CBotInstr/CBotParExpr.h +++ b/src/CBot/CBotInstr/CBotParExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.h b/src/CBot/CBotInstr/CBotPostIncExpr.h index 3a30fcef..79bc86e2 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.h +++ b/src/CBot/CBotInstr/CBotPostIncExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.h b/src/CBot/CBotInstr/CBotPreIncExpr.h index 896c0c9a..cf91a22f 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.h +++ b/src/CBot/CBotInstr/CBotPreIncExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotReturn.h b/src/CBot/CBotInstr/CBotReturn.h index 1816bf2d..7af52e52 100644 --- a/src/CBot/CBotInstr/CBotReturn.h +++ b/src/CBot/CBotInstr/CBotReturn.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.h b/src/CBot/CBotInstr/CBotSwitch.h index b4cff5e4..6edb38b8 100644 --- a/src/CBot/CBotInstr/CBotSwitch.h +++ b/src/CBot/CBotInstr/CBotSwitch.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.h b/src/CBot/CBotInstr/CBotThrow.h index b5227ad7..cbe06e50 100644 --- a/src/CBot/CBotInstr/CBotThrow.h +++ b/src/CBot/CBotInstr/CBotThrow.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.h b/src/CBot/CBotInstr/CBotTry.h index bdc3d4d8..9c79b3a4 100644 --- a/src/CBot/CBotInstr/CBotTry.h +++ b/src/CBot/CBotInstr/CBotTry.h @@ -18,7 +18,6 @@ */ // Modules inlcude -#include "CBot.h" #include "CBotCatch.h" #include "CBotInstr.h" diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.h b/src/CBot/CBotInstr/CBotTwoOpExpr.h index 720755fc..63e20ddc 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.h +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h index 528fe8f1..a6fac948 100644 --- a/src/CBot/CBotInstr/CBotWhile.h +++ b/src/CBot/CBotInstr/CBotWhile.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotInstr.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 187f560e..1bdd89c6 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -18,8 +18,6 @@ */ // Modules inlcude -#include "CBot.h" - #include "CBotVar/CBotVar.h" #include "CBotCall.h" diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 283a8ae3..0e8ddd03 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -20,17 +20,21 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotDefines.h" +#include "CBotTypResult.h" +#include "CBotString.h" // Local include // Global include +#include // Forward declaration class CBotInstr; class CBotCall; +class CBotVar; +class CBotProgram; +class CBotToken; /*! * \class CBotStack @@ -122,8 +126,9 @@ public: * \param [in] bModif Not used. Probably need to be removed * \return Found variable */ - CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false, - bool bModif = false); + CBotVar* FindVar(CBotToken* &pToken, + bool bUpdate = false, + bool bModif = false); /** * \brief Fetch a variable by its token. @@ -133,8 +138,9 @@ public: * \param [in] bModif Not used. Probably need to be removed * \return Found variable */ - CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false, - bool bModif = false); + CBotVar* FindVar(CBotToken& pToken, + bool bUpdate = false, + bool bModif = false); /** * \brief Fetch variable by its name diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 12cc546b..d8fc07c7 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -19,10 +19,9 @@ ///////////////////////////////////////////////////// +#include "CBotString.h" + //strings management - -#include "CBot.h" - #include #include #include diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index 2b06c0ff..d5840f99 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -18,7 +18,7 @@ */ // Modules inlcude -#include "CBot.h" +#include "CBotToken.h" // Local include diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index e5ce073e..4f75249c 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -33,6 +33,8 @@ #include "CBotClass.h" +#include "CBotEnums.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index 59a3b97d..cece8117 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -20,9 +20,11 @@ // Modules inlcude #include "CBotVarArray.h" #include "CBotVarClass.h" - +#include "CBotToken.h" #include "CBotFileUtils.h" +#include "CBotEnums.h" + // Local include // Global include diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h index 65222ac6..650437f3 100644 --- a/src/CBot/CBotVar/CBotVarArray.h +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -20,7 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" #include "CBotDefines.h" #include "CBotVar/CBotVar.h" diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index 5089c408..ff6f9248 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -20,8 +20,6 @@ #pragma once // Modules inlcude -#include "CBot.h" - #include "CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index 9bbaee78..ff01eec7 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -20,12 +20,13 @@ // Modules inlcude #include "CBotVarPointer.h" #include "CBotToken.h" -#include "CBot.h" #include "CBotClass.h" #include "CBotVarClass.h" #include "CBotFileUtils.h" +#include "CBotEnums.h" + // Local include // Global include From ece0666954adae4e7b02bdec4ea8c9b16778740c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 18:29:25 +0100 Subject: [PATCH 132/360] Create new file CBot.h. Included only useful interfaces. --- src/CBot/CBot.h | 8 ++++++++ src/common/restext.cpp | 2 +- src/level/robotmain.cpp | 4 +--- src/object/implementation/programmable_impl.cpp | 2 +- src/script/script.cpp | 4 +--- src/script/script.h | 3 +-- src/script/scriptfunc.cpp | 4 +--- src/script/scriptfunc.h | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 868bf137..bea5ce75 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -18,6 +18,14 @@ */ // Modules inlcude +#include "CBot/resource.h" +#include "CBot/CBotFileUtils.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotProgram.h" +#include "CBot/CBotTypResult.h" + +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 67ac2158..8b2cb435 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -22,7 +22,7 @@ #include "common/config.h" -#include "CBot/resource.h" +#include "CBot/CBot.h" #include "app/input.h" diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index e2c82908..51107497 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -19,9 +19,7 @@ #include "level/robotmain.h" -#include "CBot/CBotFileUtils.h" -// TODO must be replaced by CBot.h -#include "CBot/CBotClass.h" +#include "CBot/CBot.h" #include "app/app.h" #include "app/input.h" diff --git a/src/object/implementation/programmable_impl.cpp b/src/object/implementation/programmable_impl.cpp index 379929e5..cea959ce 100644 --- a/src/object/implementation/programmable_impl.cpp +++ b/src/object/implementation/programmable_impl.cpp @@ -40,7 +40,7 @@ #include "ui/controls/edit.h" -#include "CBot/CBotFileUtils.h" +#include "CBot/CBot.h" #include #include diff --git a/src/script/script.cpp b/src/script/script.cpp index 92c658f6..5908d43b 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -42,9 +42,7 @@ #include "ui/controls/interface.h" #include "ui/controls/list.h" -#include "CBot/CBotToken.h" -#include "CBot/CBotVar/CBotVar.h" -#include "CBot/CBotFileUtils.h" +#include "CBot/CBot.h" const int CBOT_IPF = 100; // CBOT: default number of instructions / frame diff --git a/src/script/script.h b/src/script/script.h index be3f055a..7bf9b62f 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -24,8 +24,7 @@ #pragma once -// TODO replace by CBot.h -#include "CBot/CBotProgram.h" +#include "CBot/CBot.h" #include #include diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 252f09df..b2fce1c1 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -19,9 +19,7 @@ #include "script/scriptfunc.h" -// TODO must be replaced by CBot.h -#include "CBot/CBotClass.h" -#include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBot.h" #include "app/app.h" diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index 13c48893..e739ecdd 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -24,7 +24,7 @@ #pragma once -#include "CBot/CBotTypResult.h" +#include "CBot/CBot.h" #include "common/error.h" From 922082b360add4944a92e0860fc40d77ccaf318f Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 18:33:55 +0100 Subject: [PATCH 133/360] Move define from resource.h to CBotDefines.h. --- src/CBot/CBotDefines.h | 64 +++++++++++++++++++++++++++- src/CBot/CBotInstr/CBotBlock.cpp | 2 + src/CBot/CBotInstr/CBotBoolExpr.cpp | 2 + src/CBot/CBotInstr/CBotCondition.cpp | 2 + src/CBot/resource.h | 61 -------------------------- 5 files changed, 68 insertions(+), 63 deletions(-) diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 9cb70ab7..b1c73b38 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -21,8 +21,6 @@ // Modules inlcude -#include "CBotInstr.h" - // Local include // Global include @@ -119,3 +117,65 @@ #define CBotErrNotOpen 6013 // channel not open #define CBotErrRead 6014 // error while reading #define CBotErrWrite 6015 // writing error + + +// TODO: refactor & change to enum! + +// Compile errors +#define TX_OPENPAR 5000 +#define TX_CLOSEPAR 5001 +#define TX_NOTBOOL 5002 +#define TX_UNDEFVAR 5003 +#define TX_BADLEFT 5004 +#define TX_ENDOF 5005 +#define TX_OUTCASE 5006 +#define TX_CLOSEBLK 5008 +#define TX_ELSEWITHOUTIF 5009 +#define TX_OPENBLK 5010 +#define TX_BADTYPE 5011 +#define TX_REDEFVAR 5012 +#define TX_BAD2TYPE 5013 +#define TX_UNDEFCALL 5014 +#define TX_MISDOTS 5015 +#define TX_WHILE 5016 +#define TX_BREAK 5017 +#define TX_LABEL 5018 +#define TX_NOLABEL 5019 +#define TX_NOCASE 5020 +#define TX_BADNUM 5021 +#define TX_VOID 5022 +#define TX_NOTYP 5023 +#define TX_NOVAR 5024 +#define TX_NOFONC 5025 +#define TX_OVERPARAM 5026 +#define TX_REDEF 5027 +#define TX_LOWPARAM 5028 +#define TX_BADPARAM 5029 +#define TX_NUMPARAM 5030 +#define TX_NOITEM 5031 +#define TX_DOT 5032 +#define TX_NOCONST 5033 +#define TX_REDEFCLASS 5034 +#define TX_CLBRK 5035 +#define TX_RESERVED 5036 +#define TX_BADNEW 5037 +#define TX_BADSTRING 5039 +#define TX_BADINDEX 5040 +#define TX_PRIVATE 5041 +#define TX_NOPUBLIC 5042 + +// Runtime errors +#define TX_DIVZERO 6000 +#define TX_NOTINIT 6001 +#define TX_BADTHROW 6002 +#define TX_NORUN 6004 +#define TX_NOCALL 6005 +#define TX_NOCLASS 6006 +#define TX_NULLPT 6007 +#define TX_OPNAN 6008 +#define TX_OUTARRAY 6009 +#define TX_STACKOVER 6010 +#define TX_DELETEDPT 6011 + +// Max errors +#define TX_MAX 6012 diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp index ba2b5ce5..648c5ac3 100644 --- a/src/CBot/CBotInstr/CBotBlock.cpp +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -23,6 +23,8 @@ #include "CBotCStack.h" #include "CBotListInstr.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index db6b36bd..873a1a6c 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -23,6 +23,8 @@ #include "CBotCStack.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp index 453e26c8..6c5e53db 100644 --- a/src/CBot/CBotInstr/CBotCondition.cpp +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -23,6 +23,8 @@ #include "CBotCStack.h" +#include "CBotDefines.h" + // Local include // Global include diff --git a/src/CBot/resource.h b/src/CBot/resource.h index 5c204f83..60d2c775 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -112,64 +112,3 @@ enum EID TX_UNDEF = 4000, TX_NAN }; - -// TODO: refactor & change to enum! - -// Compile errors -#define TX_OPENPAR 5000 -#define TX_CLOSEPAR 5001 -#define TX_NOTBOOL 5002 -#define TX_UNDEFVAR 5003 -#define TX_BADLEFT 5004 -#define TX_ENDOF 5005 -#define TX_OUTCASE 5006 -#define TX_CLOSEBLK 5008 -#define TX_ELSEWITHOUTIF 5009 -#define TX_OPENBLK 5010 -#define TX_BADTYPE 5011 -#define TX_REDEFVAR 5012 -#define TX_BAD2TYPE 5013 -#define TX_UNDEFCALL 5014 -#define TX_MISDOTS 5015 -#define TX_WHILE 5016 -#define TX_BREAK 5017 -#define TX_LABEL 5018 -#define TX_NOLABEL 5019 -#define TX_NOCASE 5020 -#define TX_BADNUM 5021 -#define TX_VOID 5022 -#define TX_NOTYP 5023 -#define TX_NOVAR 5024 -#define TX_NOFONC 5025 -#define TX_OVERPARAM 5026 -#define TX_REDEF 5027 -#define TX_LOWPARAM 5028 -#define TX_BADPARAM 5029 -#define TX_NUMPARAM 5030 -#define TX_NOITEM 5031 -#define TX_DOT 5032 -#define TX_NOCONST 5033 -#define TX_REDEFCLASS 5034 -#define TX_CLBRK 5035 -#define TX_RESERVED 5036 -#define TX_BADNEW 5037 -#define TX_BADSTRING 5039 -#define TX_BADINDEX 5040 -#define TX_PRIVATE 5041 -#define TX_NOPUBLIC 5042 - -// Runtime errors -#define TX_DIVZERO 6000 -#define TX_NOTINIT 6001 -#define TX_BADTHROW 6002 -#define TX_NORUN 6004 -#define TX_NOCALL 6005 -#define TX_NOCLASS 6006 -#define TX_NULLPT 6007 -#define TX_OPNAN 6008 -#define TX_OUTARRAY 6009 -#define TX_STACKOVER 6010 -#define TX_DELETEDPT 6011 - -// Max errors -#define TX_MAX 6012 From 4a9afdc525feaf4a8ea33363ddf30dcfb6891bde Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 18:38:43 +0100 Subject: [PATCH 134/360] Move enum from resource.h to CBotEnums.h. Delete file resource.h. --- src/CBot/CBot.h | 1 - src/CBot/CBotEnums.h | 94 +++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotInstrUtils.cpp | 2 - src/CBot/CBotString.h | 3 +- 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index bea5ce75..11595183 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -18,7 +18,6 @@ */ // Modules inlcude -#include "CBot/resource.h" #include "CBot/CBotFileUtils.h" #include "CBot/CBotClass.h" #include "CBot/CBotToken.h" diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h index 524f00c1..17dbef69 100644 --- a/src/CBot/CBotEnums.h +++ b/src/CBot/CBotEnums.h @@ -58,3 +58,97 @@ enum CBotGet GetPosParam = 3, GetPosBloc = 4 }; + + +enum EID +{ + ID_IF = 2000, + ID_ELSE, + ID_WHILE, + ID_DO, + ID_FOR, + ID_BREAK, + ID_CONTINUE, + ID_SWITCH, + ID_CASE, + ID_DEFAULT, + ID_TRY, + ID_THROW, + ID_CATCH, + ID_FINALLY, + ID_TXT_AND, + ID_TXT_OR, + ID_TXT_NOT, + ID_RETURN, + ID_CLASS, + ID_EXTENDS, + ID_SYNCHO, + ID_NEW, + ID_PUBLIC, + ID_EXTERN, + ID_STATIC, + ID_PROTECTED, + ID_PRIVATE, + ID_INT, + ID_FLOAT, + ID_BOOLEAN, + ID_STRING, + ID_VOID, + ID_BOOL, + + ID_TRUE = 2200, + ID_FALSE, + ID_NULL, + ID_NAN, + + ID_OPENPAR = 2300, + ID_CLOSEPAR, + ID_OPBLK, + ID_CLBLK, + ID_SEP, + ID_COMMA, + ID_DOTS, + ID_DOT, + ID_OPBRK, + ID_CLBRK, + ID_DBLDOTS, + ID_LOGIC, + ID_ADD, + ID_SUB, + ID_MUL, + ID_DIV, + ID_ASS, + ID_ASSADD, + ID_ASSSUB, + ID_ASSMUL, + ID_ASSDIV, + ID_ASSOR, + ID_ASSAND, + ID_ASSXOR, + ID_ASSSL, + ID_ASSSR, + ID_ASSASR, + ID_SL, + ID_SR, + ID_ASR, + ID_INC, + ID_DEC, + ID_LO, + ID_HI, + ID_LS, + ID_HS, + ID_EQ, + ID_NE, + ID_AND, + ID_XOR, + ID_OR, + ID_LOG_AND, + ID_LOG_OR, + ID_LOG_NOT, + ID_NOT, + ID_MODULO, + ID_POWER, + ID_ASSMODULO, + TX_UNDEF = 4000, + TX_NAN +}; diff --git a/src/CBot/CBotInstr/CBotInstrUtils.cpp b/src/CBot/CBotInstr/CBotInstrUtils.cpp index 576cfa30..1b7e65c7 100644 --- a/src/CBot/CBotInstr/CBotInstrUtils.cpp +++ b/src/CBot/CBotInstr/CBotInstrUtils.cpp @@ -28,8 +28,6 @@ #include "CBotVar/CBotVar.h" -#include "resource.h" - // Local include // Global include diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h index ea065b29..58630ea6 100644 --- a/src/CBot/CBotString.h +++ b/src/CBot/CBotString.h @@ -21,7 +21,8 @@ // Modules inlcude #include "CBotUtils.h" -#include "resource.h" + +#include "CBotEnums.h" // Local include From 5c7a665639dbeecde5affd09f992cc42de23283e Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 18:48:54 +0100 Subject: [PATCH 135/360] Add CBot.h, CBotEnums.h and CBotDefines.h in CMakeLists.txt. --- src/CBot/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 0d1cc7cd..91f08748 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,4 +1,7 @@ set(SOURCES + CBot.h + CBotEnums.h + CBotDefines.h CBotUtils.cpp CBotFileUtils.cpp CBotClass.cpp From fa9dc0dace1824661e8ef6199d457a50aacf4462 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 22 Nov 2015 18:59:01 +0100 Subject: [PATCH 136/360] Start cleaning of files CBotFileUtils.h and CBotFileUtils.cpp. Pass CBotTypResult parameter as reference. --- src/CBot/CBotFileUtils.cpp | 4 ++-- src/CBot/CBotFileUtils.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp index bb561bdf..79a1240a 100644 --- a/src/CBot/CBotFileUtils.cpp +++ b/src/CBot/CBotFileUtils.cpp @@ -124,7 +124,7 @@ bool ReadString(FILE* pf, CBotString& s) } //////////////////////////////////////////////////////////////////////////////// -bool WriteType(FILE* pf, CBotTypResult type) +bool WriteType(FILE* pf, const CBotTypResult &type) { int typ = type.GetType(); if ( typ == CBotTypIntrinsic ) typ = CBotTypClass; @@ -144,7 +144,7 @@ bool WriteType(FILE* pf, CBotTypResult type) } //////////////////////////////////////////////////////////////////////////////// -bool ReadType(FILE* pf, CBotTypResult& type) +bool ReadType(FILE* pf, CBotTypResult &type) { unsigned short w, ww; if ( !ReadWord(pf, w) ) return false; diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h index 1ac1664b..75bfa434 100644 --- a/src/CBot/CBotFileUtils.h +++ b/src/CBot/CBotFileUtils.h @@ -20,7 +20,6 @@ #pragma once // Modules inlcude -#include "CBotTypResult.h" // Local include @@ -30,6 +29,7 @@ // Forward declaration class CBotVar; class CBotString; +class CBotTypResult; /////////////////////////////////////////////////////////////////////////////// // routines for file management (* FILE) @@ -145,7 +145,7 @@ bool ReadString(FILE* pf, CBotString& s); * \param type * \return */ -bool WriteType(FILE* pf, CBotTypResult type); +bool WriteType(FILE* pf, const CBotTypResult &type); /*! * \brief ReadType @@ -153,4 +153,4 @@ bool WriteType(FILE* pf, CBotTypResult type); * \param type * \return */ -bool ReadType(FILE* pf, CBotTypResult& type); +bool ReadType(FILE* pf, CBotTypResult &type); From de5a57f793fb10a578775d6513f6f01637bb8df7 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Mon, 23 Nov 2015 21:59:56 +0100 Subject: [PATCH 137/360] Change CBot default include directory. Make all include directive absolute. --- src/CBot/CBotCStack.cpp | 10 +++--- src/CBot/CBotCStack.h | 2 +- src/CBot/CBotCall.cpp | 12 +++---- src/CBot/CBotCall.h | 2 +- src/CBot/CBotCallMethode.cpp | 10 +++--- src/CBot/CBotCallMethode.h | 4 +-- src/CBot/CBotClass.cpp | 30 ++++++++--------- src/CBot/CBotClass.h | 6 ++-- src/CBot/CBotDefParam.cpp | 8 ++--- src/CBot/CBotDefParam.h | 4 +-- src/CBot/CBotFileUtils.cpp | 8 ++--- src/CBot/CBotInstr/CBotBlock.cpp | 8 ++--- src/CBot/CBotInstr/CBotBlock.h | 2 +- src/CBot/CBotInstr/CBotBoolExpr.cpp | 8 ++--- src/CBot/CBotInstr/CBotBoolExpr.h | 2 +- src/CBot/CBotInstr/CBotBoolean.cpp | 14 ++++---- src/CBot/CBotInstr/CBotBoolean.h | 2 +- src/CBot/CBotInstr/CBotBreak.cpp | 6 ++-- src/CBot/CBotInstr/CBotBreak.h | 2 +- src/CBot/CBotInstr/CBotCase.cpp | 8 ++--- src/CBot/CBotInstr/CBotCase.h | 2 +- src/CBot/CBotInstr/CBotCatch.cpp | 12 +++---- src/CBot/CBotInstr/CBotCatch.h | 2 +- src/CBot/CBotInstr/CBotClassInst.cpp | 18 +++++----- src/CBot/CBotInstr/CBotClassInst.h | 2 +- src/CBot/CBotInstr/CBotCondition.cpp | 8 ++--- src/CBot/CBotInstr/CBotCondition.h | 2 +- src/CBot/CBotInstr/CBotDo.cpp | 10 +++--- src/CBot/CBotInstr/CBotDo.h | 2 +- src/CBot/CBotInstr/CBotEmpty.cpp | 6 ++-- src/CBot/CBotInstr/CBotEmpty.h | 2 +- src/CBot/CBotInstr/CBotExprAlpha.cpp | 8 ++--- src/CBot/CBotInstr/CBotExprAlpha.h | 2 +- src/CBot/CBotInstr/CBotExprBool.cpp | 8 ++--- src/CBot/CBotInstr/CBotExprBool.h | 2 +- src/CBot/CBotInstr/CBotExprNan.cpp | 6 ++-- src/CBot/CBotInstr/CBotExprNan.h | 2 +- src/CBot/CBotInstr/CBotExprNull.cpp | 6 ++-- src/CBot/CBotInstr/CBotExprNull.h | 2 +- src/CBot/CBotInstr/CBotExprNum.cpp | 8 ++--- src/CBot/CBotInstr/CBotExprNum.h | 2 +- src/CBot/CBotInstr/CBotExprUnaire.cpp | 10 +++--- src/CBot/CBotInstr/CBotExprUnaire.h | 2 +- src/CBot/CBotInstr/CBotExprVar.cpp | 16 ++++----- src/CBot/CBotInstr/CBotExprVar.h | 4 +-- src/CBot/CBotInstr/CBotExpression.cpp | 12 +++---- src/CBot/CBotInstr/CBotExpression.h | 4 +-- src/CBot/CBotInstr/CBotFieldExpr.cpp | 10 +++--- src/CBot/CBotInstr/CBotFieldExpr.h | 2 +- src/CBot/CBotInstr/CBotFloat.cpp | 14 ++++---- src/CBot/CBotInstr/CBotFloat.h | 2 +- src/CBot/CBotInstr/CBotFor.cpp | 12 +++---- src/CBot/CBotInstr/CBotFor.h | 2 +- src/CBot/CBotInstr/CBotFunction.cpp | 26 +++++++-------- src/CBot/CBotInstr/CBotFunction.h | 2 +- src/CBot/CBotInstr/CBotIString.cpp | 12 +++---- src/CBot/CBotInstr/CBotIString.h | 2 +- src/CBot/CBotInstr/CBotIf.cpp | 10 +++--- src/CBot/CBotInstr/CBotIf.h | 2 +- src/CBot/CBotInstr/CBotIndexExpr.cpp | 8 ++--- src/CBot/CBotInstr/CBotIndexExpr.h | 2 +- src/CBot/CBotInstr/CBotInstArray.cpp | 18 +++++----- src/CBot/CBotInstr/CBotInstArray.h | 2 +- src/CBot/CBotInstr/CBotInstr.cpp | 40 +++++++++++------------ src/CBot/CBotInstr/CBotInstr.h | 4 +-- src/CBot/CBotInstr/CBotInstrCall.cpp | 8 ++--- src/CBot/CBotInstr/CBotInstrCall.h | 2 +- src/CBot/CBotInstr/CBotInstrMethode.cpp | 12 +++---- src/CBot/CBotInstr/CBotInstrMethode.h | 2 +- src/CBot/CBotInstr/CBotInstrUtils.cpp | 14 ++++---- src/CBot/CBotInstr/CBotInt.cpp | 14 ++++---- src/CBot/CBotInstr/CBotInt.h | 2 +- src/CBot/CBotInstr/CBotLeftExpr.cpp | 16 ++++----- src/CBot/CBotInstr/CBotLeftExpr.h | 2 +- src/CBot/CBotInstr/CBotLeftExprVar.cpp | 8 ++--- src/CBot/CBotInstr/CBotLeftExprVar.h | 2 +- src/CBot/CBotInstr/CBotListArray.cpp | 14 ++++---- src/CBot/CBotInstr/CBotListArray.h | 2 +- src/CBot/CBotInstr/CBotListExpression.cpp | 14 ++++---- src/CBot/CBotInstr/CBotListExpression.h | 2 +- src/CBot/CBotInstr/CBotListInstr.cpp | 8 ++--- src/CBot/CBotInstr/CBotListInstr.h | 2 +- src/CBot/CBotInstr/CBotLogicExpr.cpp | 4 +-- src/CBot/CBotInstr/CBotLogicExpr.h | 2 +- src/CBot/CBotInstr/CBotNew.cpp | 12 +++---- src/CBot/CBotInstr/CBotNew.h | 2 +- src/CBot/CBotInstr/CBotParExpr.cpp | 30 ++++++++--------- src/CBot/CBotInstr/CBotParExpr.h | 2 +- src/CBot/CBotInstr/CBotPostIncExpr.cpp | 8 ++--- src/CBot/CBotInstr/CBotPostIncExpr.h | 2 +- src/CBot/CBotInstr/CBotPreIncExpr.cpp | 8 ++--- src/CBot/CBotInstr/CBotPreIncExpr.h | 2 +- src/CBot/CBotInstr/CBotReturn.cpp | 10 +++--- src/CBot/CBotInstr/CBotReturn.h | 2 +- src/CBot/CBotInstr/CBotSwitch.cpp | 12 +++---- src/CBot/CBotInstr/CBotSwitch.h | 2 +- src/CBot/CBotInstr/CBotThrow.cpp | 8 ++--- src/CBot/CBotInstr/CBotThrow.h | 2 +- src/CBot/CBotInstr/CBotTry.cpp | 6 ++-- src/CBot/CBotInstr/CBotTry.h | 4 +-- src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 16 ++++----- src/CBot/CBotInstr/CBotTwoOpExpr.h | 2 +- src/CBot/CBotInstr/CBotWhile.cpp | 10 +++--- src/CBot/CBotInstr/CBotWhile.h | 2 +- src/CBot/CBotProgram.cpp | 16 ++++----- src/CBot/CBotProgram.h | 8 ++--- src/CBot/CBotStack.cpp | 12 +++---- src/CBot/CBotStack.h | 6 ++-- src/CBot/CBotString.cpp | 2 +- src/CBot/CBotString.h | 4 +-- src/CBot/CBotStringArray.cpp | 4 +-- src/CBot/CBotStringArray.h | 2 +- src/CBot/CBotToken.cpp | 2 +- src/CBot/CBotToken.h | 2 +- src/CBot/CBotTypResult.cpp | 6 ++-- src/CBot/CBotUtils.cpp | 12 +++---- src/CBot/CBotUtils.h | 4 +-- src/CBot/CBotVar/CBotVar.cpp | 22 ++++++------- src/CBot/CBotVar/CBotVar.h | 4 +-- src/CBot/CBotVar/CBotVarArray.cpp | 10 +++--- src/CBot/CBotVar/CBotVarArray.h | 4 +-- src/CBot/CBotVar/CBotVarBoolean.cpp | 6 ++-- src/CBot/CBotVar/CBotVarBoolean.h | 4 +-- src/CBot/CBotVar/CBotVarClass.cpp | 12 +++---- src/CBot/CBotVar/CBotVarClass.h | 2 +- src/CBot/CBotVar/CBotVarFloat.cpp | 8 ++--- src/CBot/CBotVar/CBotVarFloat.h | 2 +- src/CBot/CBotVar/CBotVarInt.cpp | 8 ++--- src/CBot/CBotVar/CBotVarInt.h | 2 +- src/CBot/CBotVar/CBotVarPointer.cpp | 12 +++---- src/CBot/CBotVar/CBotVarPointer.h | 2 +- src/CBot/CBotVar/CBotVarString.cpp | 8 ++--- src/CBot/CBotVar/CBotVarString.h | 2 +- src/CBot/CMakeLists.txt | 2 +- src/CBot/StringFunctions.cpp | 8 ++--- src/CBot/StringFunctions.h | 2 +- 136 files changed, 475 insertions(+), 475 deletions(-) diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index 6d9b820e..ed56e22a 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -19,14 +19,14 @@ // Modules inlcude -#include "CBotCStack.h" +#include "CBot/CBotCStack.h" -#include "CBotToken.h" -#include "CBotCall.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotCall.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" -#include "CBotInstr/CBotFunction.h" +#include "CBot/CBotInstr/CBotFunction.h" // Local include diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h index 70ce456a..e6210f80 100644 --- a/src/CBot/CBotCStack.h +++ b/src/CBot/CBotCStack.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotProgram.h" +#include "CBot/CBotProgram.h" // Local include diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index ee853d8a..13f1e857 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotCall.h" +#include "CBot/CBotCall.h" -#include "CBotToken.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotUtils.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotUtils.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h index b4dc4fe9..bb94c23e 100644 --- a/src/CBot/CBotCall.h +++ b/src/CBot/CBotCall.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotString.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index da915dfb..d38da859 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotCallMethode.h" +#include "CBot/CBotCallMethode.h" -#include "CBotUtils.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotUtils.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h index d60a9b77..445e259a 100644 --- a/src/CBot/CBotCallMethode.h +++ b/src/CBot/CBotCallMethode.h @@ -20,8 +20,8 @@ #pragma once // Modules inlcude -#include "CBotTypResult.h" -#include "CBotString.h" +#include "CBot/CBotTypResult.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 172f2cd3..8e580bb6 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -18,24 +18,24 @@ */ // Modules inlcude -#include "CBotClass.h" +#include "CBot/CBotClass.h" -#include "CBotInstr/CBotNew.h" -#include "CBotInstr/CBotLeftExprVar.h" -#include "CBotInstr/CBotTwoOpExpr.h" -#include "CBotInstr/CBotFunction.h" -#include "CBotInstr/CBotExpression.h" -#include "CBotInstr/CBotListArray.h" -#include "CBotInstr/CBotEmpty.h" +#include "CBot/CBotInstr/CBotNew.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotFunction.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotListArray.h" +#include "CBot/CBotInstr/CBotEmpty.h" -#include "CBotCall.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotUtils.h" -#include "CBotFileUtils.h" -#include "CBotCallMethode.h" +#include "CBot/CBotCall.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotUtils.h" +#include "CBot/CBotFileUtils.h" +#include "CBot/CBotCallMethode.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index ac9e418d..2b151b0a 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -20,11 +20,11 @@ #pragma once // Modules inlcude -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" -#include "CBotTypResult.h" +#include "CBot/CBotTypResult.h" -#include "CBotString.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index fe7ce8bf..7f13f89d 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotDefParam.h" +#include "CBot/CBotDefParam.h" -#include "CBotUtils.h" -#include "CBotCStack.h" +#include "CBot/CBotUtils.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVarClass.h" +#include "CBot/CBotVar/CBotVarClass.h" // Local include diff --git a/src/CBot/CBotDefParam.h b/src/CBot/CBotDefParam.h index 6da8e2cd..433d18f4 100644 --- a/src/CBot/CBotDefParam.h +++ b/src/CBot/CBotDefParam.h @@ -20,8 +20,8 @@ #pragma once // Modules inlcude -#include "CBotToken.h" -#include "CBotStack.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotStack.h" // Local include diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp index 79a1240a..c6e50e1a 100644 --- a/src/CBot/CBotFileUtils.cpp +++ b/src/CBot/CBotFileUtils.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotFileUtils.h" +#include "CBot/CBotFileUtils.h" -#include "CBotString.h" -#include "CBotClass.h" +#include "CBot/CBotString.h" +#include "CBot/CBotClass.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp index 648c5ac3..9e6b2537 100644 --- a/src/CBot/CBotInstr/CBotBlock.cpp +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotBlock.h" +#include "CBot/CBotInstr/CBotBlock.h" -#include "CBotCStack.h" -#include "CBotListInstr.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotInstr/CBotListInstr.h" -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBlock.h b/src/CBot/CBotInstr/CBotBlock.h index 7df0bb5b..c88e5006 100644 --- a/src/CBot/CBotInstr/CBotBlock.h +++ b/src/CBot/CBotInstr/CBotBlock.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index 873a1a6c..e219d159 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotBoolExpr.h" -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotBoolExpr.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotCStack.h" +#include "CBot/CBotCStack.h" -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolExpr.h b/src/CBot/CBotInstr/CBotBoolExpr.h index af6cd4f8..31545029 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.h +++ b/src/CBot/CBotInstr/CBotBoolExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index 64c4d3d3..0b44d71e 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotBoolean.h" -#include "CBotLeftExprVar.h" -#include "CBotTwoOpExpr.h" -#include "CBotInstArray.h" +#include "CBot/CBotInstr/CBotBoolean.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotInstArray.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBoolean.h b/src/CBot/CBotInstr/CBotBoolean.h index e589f508..78b49093 100644 --- a/src/CBot/CBotInstr/CBotBoolean.h +++ b/src/CBot/CBotInstr/CBotBoolean.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index 9d4100cb..d97d65ae 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -18,10 +18,10 @@ */ // Modules inlcude -#include "CBotBreak.h" +#include "CBot/CBotInstr/CBotBreak.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h index 78b39dd3..7961b0bf 100644 --- a/src/CBot/CBotInstr/CBotBreak.h +++ b/src/CBot/CBotInstr/CBotBreak.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index 3ae5b706..9387330f 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotCase.h" -#include "CBotExprNum.h" +#include "CBot/CBotInstr/CBotCase.h" +#include "CBot/CBotInstr/CBotExprNum.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCase.h b/src/CBot/CBotInstr/CBotCase.h index 03ddddde..ebd67485 100644 --- a/src/CBot/CBotInstr/CBotCase.h +++ b/src/CBot/CBotInstr/CBotCase.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index 26f7d17d..f62f662e 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotCatch.h" -#include "CBotBlock.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotCatch.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCatch.h b/src/CBot/CBotInstr/CBotCatch.h index 60ee00a9..eec4196f 100644 --- a/src/CBot/CBotInstr/CBotCatch.h +++ b/src/CBot/CBotInstr/CBotCatch.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index d556dd77..d66ba3ec 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -20,18 +20,18 @@ // Modules inlcude #include "CBotClassInst.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotLeftExprVar.h" -#include "CBotTwoOpExpr.h" -#include "CBotInstArray.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotInstArray.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" -#include "CBotVar/CBotVarPointer.h" -#include "CBotVar/CBotVarClass.h" +#include "CBot/CBotVar/CBotVarPointer.h" +#include "CBot/CBotVar/CBotVarClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotClassInst.h b/src/CBot/CBotInstr/CBotClassInst.h index ab70c0f2..743e39e0 100644 --- a/src/CBot/CBotInstr/CBotClassInst.h +++ b/src/CBot/CBotInstr/CBotClassInst.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp index 6c5e53db..6c88869e 100644 --- a/src/CBot/CBotInstr/CBotCondition.cpp +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotCondition.h" -#include "CBotBoolExpr.h" +#include "CBot/CBotInstr/CBotCondition.h" +#include "CBot/CBotInstr/CBotBoolExpr.h" -#include "CBotCStack.h" +#include "CBot/CBotCStack.h" -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" // Local include diff --git a/src/CBot/CBotInstr/CBotCondition.h b/src/CBot/CBotInstr/CBotCondition.h index f36c998a..334354f7 100644 --- a/src/CBot/CBotInstr/CBotCondition.h +++ b/src/CBot/CBotInstr/CBotCondition.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index c24baff5..ef682b36 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotDo.h" -#include "CBotBlock.h" -#include "CBotCondition.h" +#include "CBot/CBotInstr/CBotDo.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotCondition.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h index 30f1db9d..8a800400 100644 --- a/src/CBot/CBotInstr/CBotDo.h +++ b/src/CBot/CBotInstr/CBotDo.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotEmpty.cpp b/src/CBot/CBotInstr/CBotEmpty.cpp index 4318eadd..ba9a9fd3 100644 --- a/src/CBot/CBotInstr/CBotEmpty.cpp +++ b/src/CBot/CBotInstr/CBotEmpty.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotEmpty.h" +#include "CBot/CBotInstr/CBotEmpty.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotEmpty.h b/src/CBot/CBotInstr/CBotEmpty.h index 782e87ca..ebbee7b1 100644 --- a/src/CBot/CBotInstr/CBotEmpty.h +++ b/src/CBot/CBotInstr/CBotEmpty.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index 1f93b89a..da68497e 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotExprAlpha.h" +#include "CBot/CBotInstr/CBotExprAlpha.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprAlpha.h b/src/CBot/CBotInstr/CBotExprAlpha.h index 01e97a8e..10f4e240 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.h +++ b/src/CBot/CBotInstr/CBotExprAlpha.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp index 3df5095f..94736934 100644 --- a/src/CBot/CBotInstr/CBotExprBool.cpp +++ b/src/CBot/CBotInstr/CBotExprBool.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotExprBool.h" +#include "CBot/CBotInstr/CBotExprBool.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprBool.h b/src/CBot/CBotInstr/CBotExprBool.h index a81ec2ee..ac1d84fd 100644 --- a/src/CBot/CBotInstr/CBotExprBool.h +++ b/src/CBot/CBotInstr/CBotExprBool.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp index a2cb1c65..df0a296d 100644 --- a/src/CBot/CBotInstr/CBotExprNan.cpp +++ b/src/CBot/CBotInstr/CBotExprNan.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotExprNan.h" +#include "CBot/CBotInstr/CBotExprNan.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNan.h b/src/CBot/CBotInstr/CBotExprNan.h index c7c25963..623502a7 100644 --- a/src/CBot/CBotInstr/CBotExprNan.h +++ b/src/CBot/CBotInstr/CBotExprNan.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNull.cpp b/src/CBot/CBotInstr/CBotExprNull.cpp index cef5eca8..a36b4889 100644 --- a/src/CBot/CBotInstr/CBotExprNull.cpp +++ b/src/CBot/CBotInstr/CBotExprNull.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotExprNull.h" +#include "CBot/CBotInstr/CBotExprNull.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNull.h b/src/CBot/CBotInstr/CBotExprNull.h index 662ded3d..473ddb60 100644 --- a/src/CBot/CBotInstr/CBotExprNull.h +++ b/src/CBot/CBotInstr/CBotExprNull.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index acf1e9a2..e9a72dec 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotExprNum.h" +#include "CBot/CBotInstr/CBotExprNum.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprNum.h b/src/CBot/CBotInstr/CBotExprNum.h index e9ccf932..7195f7bb 100644 --- a/src/CBot/CBotInstr/CBotExprNum.h +++ b/src/CBot/CBotInstr/CBotExprNum.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 31056bb3..50e39a78 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotExprUnaire.h" -#include "CBotParExpr.h" +#include "CBot/CBotInstr/CBotExprUnaire.h" +#include "CBot/CBotInstr/CBotParExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprUnaire.h b/src/CBot/CBotInstr/CBotExprUnaire.h index 660afdd7..b015f341 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.h +++ b/src/CBot/CBotInstr/CBotExprUnaire.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index ee4a748e..4dc078dd 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -18,16 +18,16 @@ */ // Modules inlcude -#include "CBotExprVar.h" -#include "CBotInstrMethode.h" -#include "CBotExpression.h" -#include "CBotIndexExpr.h" -#include "CBotFieldExpr.h" +#include "CBot/CBotInstr/CBotExprVar.h" +#include "CBot/CBotInstr/CBotInstrMethode.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotIndexExpr.h" +#include "CBot/CBotInstr/CBotFieldExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVarArray.h" +#include "CBot/CBotVar/CBotVarArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h index 9757b898..ff5cf17d 100644 --- a/src/CBot/CBotInstr/CBotExprVar.h +++ b/src/CBot/CBotInstr/CBotExprVar.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index a3612426..d3821aab 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -18,16 +18,16 @@ */ // Modules inlcude -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotExpression.h b/src/CBot/CBotInstr/CBotExpression.h index 637ff051..a854d8bf 100644 --- a/src/CBot/CBotInstr/CBotExpression.h +++ b/src/CBot/CBotInstr/CBotExpression.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotLeftExpr.h" +#include "CBot/CBotInstr/CBotLeftExpr.h" -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index 7c4ff58c..c5817695 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotFieldExpr.h" +#include "CBot/CBotInstr/CBotFieldExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" -#include "CBotVar/CBotVarClass.h" +#include "CBot/CBotVar/CBotVarClass.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFieldExpr.h b/src/CBot/CBotInstr/CBotFieldExpr.h index 4a56a3f6..84c014fb 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.h +++ b/src/CBot/CBotInstr/CBotFieldExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index df69b07f..f4a8ac31 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotFloat.h" -#include "CBotLeftExprVar.h" -#include "CBotTwoOpExpr.h" -#include "CBotInstArray.h" +#include "CBot/CBotInstr/CBotFloat.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotInstArray.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFloat.h b/src/CBot/CBotInstr/CBotFloat.h index 3e095fe5..fa1d6f66 100644 --- a/src/CBot/CBotInstr/CBotFloat.h +++ b/src/CBot/CBotInstr/CBotFloat.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 2a97b86b..e225b99b 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotFor.h" -#include "CBotListExpression.h" -#include "CBotBlock.h" -#include "CBotBoolExpr.h" +#include "CBot/CBotInstr/CBotFor.h" +#include "CBot/CBotInstr/CBotListExpression.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotBoolExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h index 56442b0c..5b9a93eb 100644 --- a/src/CBot/CBotInstr/CBotFor.h +++ b/src/CBot/CBotInstr/CBotFor.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index f8e4b6df..7277486e 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -19,23 +19,23 @@ // Modules inlcude -#include "CBotFunction.h" +#include "CBot/CBotInstr/CBotFunction.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotInstr/CBotBlock.h" -#include "CBotInstr/CBotTwoOpExpr.h" -#include "CBotInstr/CBotExpression.h" -#include "CBotInstr/CBotEmpty.h" -#include "CBotInstr/CBotListArray.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotEmpty.h" +#include "CBot/CBotInstr/CBotListArray.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" -#include "CBotDefParam.h" -#include "CBotUtils.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotDefParam.h" +#include "CBot/CBotUtils.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index 7c44dc3e..f11015f5 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index 6feefc41..be03c6e8 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotIString.h" -#include "CBotLeftExprVar.h" -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotIString.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIString.h b/src/CBot/CBotInstr/CBotIString.h index 1435bb36..93fcfbdb 100644 --- a/src/CBot/CBotInstr/CBotIString.h +++ b/src/CBot/CBotInstr/CBotIString.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp index 1075f65f..784b88f9 100644 --- a/src/CBot/CBotInstr/CBotIf.cpp +++ b/src/CBot/CBotInstr/CBotIf.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotIf.h" -#include "CBotInstr/CBotBlock.h" -#include "CBotInstr/CBotCondition.h" +#include "CBot/CBotInstr/CBotIf.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotCondition.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIf.h b/src/CBot/CBotInstr/CBotIf.h index de4c3672..41c533d9 100644 --- a/src/CBot/CBotInstr/CBotIf.h +++ b/src/CBot/CBotInstr/CBotIf.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 471089c3..27784c53 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotIndexExpr.h" +#include "CBot/CBotInstr/CBotIndexExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVarArray.h" +#include "CBot/CBotVar/CBotVarArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotIndexExpr.h b/src/CBot/CBotInstr/CBotIndexExpr.h index fe1ea555..89f39649 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.h +++ b/src/CBot/CBotInstr/CBotIndexExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index 7d2a441e..b5497f3a 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -18,19 +18,19 @@ */ // Modules inlcude -#include "CBotInstArray.h" +#include "CBot/CBotInstr/CBotInstArray.h" -#include "CBotLeftExprVar.h" -#include "CBotExpression.h" -#include "CBotListArray.h" -#include "CBotEmpty.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotListArray.h" +#include "CBot/CBotInstr/CBotEmpty.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstArray.h b/src/CBot/CBotInstr/CBotInstArray.h index 2b02c66d..217cab69 100644 --- a/src/CBot/CBotInstr/CBotInstArray.h +++ b/src/CBot/CBotInstr/CBotInstArray.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp index 7d376f7c..9d6aac32 100644 --- a/src/CBot/CBotInstr/CBotInstr.cpp +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -18,29 +18,29 @@ */ // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" -#include "CBotInstr/CBotFor.h" -#include "CBotInstr/CBotDo.h" -#include "CBotInstr/CBotBreak.h" -#include "CBotInstr/CBotSwitch.h" -#include "CBotInstr/CBotTry.h" -#include "CBotInstr/CBotThrow.h" -#include "CBotInstr/CBotInt.h" -#include "CBotInstr/CBotFloat.h" -#include "CBotInstr/CBotWhile.h" -#include "CBotInstr/CBotIString.h" -#include "CBotInstr/CBotBoolean.h" -#include "CBotInstr/CBotIf.h" -#include "CBotInstr/CBotReturn.h" -#include "CBotInstr/CBotClassInst.h" -#include "CBotInstr/CBotExpression.h" -#include "CBotInstr/CBotInstArray.h" +#include "CBot/CBotInstr/CBotFor.h" +#include "CBot/CBotInstr/CBotDo.h" +#include "CBot/CBotInstr/CBotBreak.h" +#include "CBot/CBotInstr/CBotSwitch.h" +#include "CBot/CBotInstr/CBotTry.h" +#include "CBot/CBotInstr/CBotThrow.h" +#include "CBot/CBotInstr/CBotInt.h" +#include "CBot/CBotInstr/CBotFloat.h" +#include "CBot/CBotInstr/CBotWhile.h" +#include "CBot/CBotInstr/CBotIString.h" +#include "CBot/CBotInstr/CBotBoolean.h" +#include "CBot/CBotInstr/CBotIf.h" +#include "CBot/CBotInstr/CBotReturn.h" +#include "CBot/CBotInstr/CBotClassInst.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotInstArray.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" -#include "CBotClass.h" -#include "CBotStack.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstr.h b/src/CBot/CBotInstr/CBotInstr.h index 1f25115e..acf36781 100644 --- a/src/CBot/CBotInstr/CBotInstr.h +++ b/src/CBot/CBotInstr/CBotInstr.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotToken.h" +#include "CBot/CBotToken.h" -#include "CBotCStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index ca21b87d..d83f2a8a 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -19,12 +19,12 @@ // Modules inlcude #include "CBotInstrCall.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrCall.h b/src/CBot/CBotInstr/CBotInstrCall.h index db259039..2a35eeba 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.h +++ b/src/CBot/CBotInstr/CBotInstrCall.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 26f188f8..3778a9c2 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotInstrMethode.h" +#include "CBot/CBotInstr/CBotInstrMethode.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h index f9447609..1c8512d8 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.h +++ b/src/CBot/CBotInstr/CBotInstrMethode.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInstrUtils.cpp b/src/CBot/CBotInstr/CBotInstrUtils.cpp index 1b7e65c7..a7fc8c9d 100644 --- a/src/CBot/CBotInstr/CBotInstrUtils.cpp +++ b/src/CBot/CBotInstr/CBotInstrUtils.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotToken.h" -#include "CBotCStack.h" -#include "CBotTypResult.h" -#include "CBotExpression.h" -#include "CBotClass.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotTypResult.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotClass.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index 7ea8cbf6..93cc0f68 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -18,16 +18,16 @@ */ // Modules inlcude -#include "CBotInt.h" +#include "CBot/CBotInstr/CBotInt.h" -#include "CBotLeftExprVar.h" -#include "CBotInstArray.h" -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotInstArray.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotInt.h b/src/CBot/CBotInstr/CBotInt.h index 113897f6..4489b8b7 100644 --- a/src/CBot/CBotInstr/CBotInt.h +++ b/src/CBot/CBotInstr/CBotInt.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index e09a2263..28badcaa 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -18,16 +18,16 @@ */ // Modules inlcude -#include "CBotLeftExpr.h" -#include "CBotFieldExpr.h" -#include "CBotIndexExpr.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotLeftExpr.h" +#include "CBot/CBotInstr/CBotFieldExpr.h" +#include "CBot/CBotInstr/CBotIndexExpr.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" -#include "CBotVar/CBotVarArray.h" +#include "CBot/CBotVar/CBotVarArray.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExpr.h b/src/CBot/CBotInstr/CBotLeftExpr.h index 5f09b507..9ac75d95 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.h +++ b/src/CBot/CBotInstr/CBotLeftExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index 18af17c7..517d8b71 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotLeftExprVar.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.h b/src/CBot/CBotInstr/CBotLeftExprVar.h index 0c9e0cc2..a9526e84 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.h +++ b/src/CBot/CBotInstr/CBotLeftExprVar.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index ce1a5f8a..f19cfa5e 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -18,17 +18,17 @@ */ // Modules inlcude -#include "CBotListArray.h" +#include "CBot/CBotInstr/CBotListArray.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotExprNull.h" -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotExprNull.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 32a155c6..a5069a9e 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 670f3fb5..5f5d9141 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotListExpression.h" -#include "CBotExpression.h" -#include "CBotIString.h" -#include "CBotFloat.h" +#include "CBot/CBotInstr/CBotListExpression.h" +#include "CBot/CBotInstr/CBotExpression.h" +#include "CBot/CBotInstr/CBotIString.h" +#include "CBot/CBotInstr/CBotFloat.h" #include "CBotBoolean.h" -#include "CBotInt.h" +#include "CBot/CBotInstr/CBotInt.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListExpression.h b/src/CBot/CBotInstr/CBotListExpression.h index a4ea3b2f..1b4ccae3 100644 --- a/src/CBot/CBotInstr/CBotListExpression.h +++ b/src/CBot/CBotInstr/CBotListExpression.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index 576012b8..13b4ded7 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotListInstr.h" -#include "CBotBlock.h" +#include "CBot/CBotInstr/CBotListInstr.h" +#include "CBot/CBotInstr/CBotBlock.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotListInstr.h b/src/CBot/CBotInstr/CBotListInstr.h index b0612d86..b3d43622 100644 --- a/src/CBot/CBotInstr/CBotListInstr.h +++ b/src/CBot/CBotInstr/CBotListInstr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLogicExpr.cpp b/src/CBot/CBotInstr/CBotLogicExpr.cpp index d332d18f..9e1eb4c4 100644 --- a/src/CBot/CBotInstr/CBotLogicExpr.cpp +++ b/src/CBot/CBotInstr/CBotLogicExpr.cpp @@ -18,9 +18,9 @@ */ // Modules inlcude -#include "CBotLogicExpr.h" +#include "CBot/CBotInstr/CBotLogicExpr.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotLogicExpr.h b/src/CBot/CBotInstr/CBotLogicExpr.h index 25e67854..33b65033 100644 --- a/src/CBot/CBotInstr/CBotLogicExpr.h +++ b/src/CBot/CBotInstr/CBotLogicExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index b7e36316..2351835c 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotNew.h" +#include "CBot/CBotInstr/CBotNew.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotNew.h b/src/CBot/CBotInstr/CBotNew.h index f93bb6be..8a69e61e 100644 --- a/src/CBot/CBotInstr/CBotNew.h +++ b/src/CBot/CBotInstr/CBotNew.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index 21b40d18..e4e34796 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -18,23 +18,23 @@ */ // Modules inlcude -#include "CBotParExpr.h" -#include "CBotExprUnaire.h" -#include "CBotExprVar.h" -#include "CBotInstrCall.h" -#include "CBotPostIncExpr.h" -#include "CBotPreIncExpr.h" -#include "CBotExprNum.h" -#include "CBotExprAlpha.h" -#include "CBotExprBool.h" -#include "CBotNew.h" -#include "CBotExprNull.h" -#include "CBotExprNan.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotParExpr.h" +#include "CBot/CBotInstr/CBotExprUnaire.h" +#include "CBot/CBotInstr/CBotExprVar.h" +#include "CBot/CBotInstr/CBotInstrCall.h" +#include "CBot/CBotInstr/CBotPostIncExpr.h" +#include "CBot/CBotInstr/CBotPreIncExpr.h" +#include "CBot/CBotInstr/CBotExprNum.h" +#include "CBot/CBotInstr/CBotExprAlpha.h" +#include "CBot/CBotInstr/CBotExprBool.h" +#include "CBot/CBotInstr/CBotNew.h" +#include "CBot/CBotInstr/CBotExprNull.h" +#include "CBot/CBotInstr/CBotExprNan.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" -#include "CBotCStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h index 3fdbb639..992b7028 100644 --- a/src/CBot/CBotInstr/CBotParExpr.h +++ b/src/CBot/CBotInstr/CBotParExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp index 938274e6..99531023 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotPostIncExpr.h" -#include "CBotExprVar.h" +#include "CBot/CBotInstr/CBotPostIncExpr.h" +#include "CBot/CBotInstr/CBotExprVar.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.h b/src/CBot/CBotInstr/CBotPostIncExpr.h index 79bc86e2..cdc45b34 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.h +++ b/src/CBot/CBotInstr/CBotPostIncExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp index 30ee9a97..6e8b7440 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotPreIncExpr.h" -#include "CBotExprVar.h" +#include "CBot/CBotInstr/CBotPreIncExpr.h" +#include "CBot/CBotInstr/CBotExprVar.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.h b/src/CBot/CBotInstr/CBotPreIncExpr.h index cf91a22f..eb5d2a98 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.h +++ b/src/CBot/CBotInstr/CBotPreIncExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index 9f5d00f7..c89e959c 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotReturn.h" +#include "CBot/CBotInstr/CBotReturn.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotReturn.h b/src/CBot/CBotInstr/CBotReturn.h index 7af52e52..e41240ec 100644 --- a/src/CBot/CBotInstr/CBotReturn.h +++ b/src/CBot/CBotInstr/CBotReturn.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index ef53fd77..0104d5da 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -20,13 +20,13 @@ */ // Modules inlcude -#include "CBotSwitch.h" -#include "CBotCase.h" -#include "CBotBlock.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotSwitch.h" +#include "CBot/CBotInstr/CBotCase.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotSwitch.h b/src/CBot/CBotInstr/CBotSwitch.h index 6edb38b8..f174161c 100644 --- a/src/CBot/CBotInstr/CBotSwitch.h +++ b/src/CBot/CBotInstr/CBotSwitch.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index 4fc8cddd..4525dbbb 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotThrow.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotThrow.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotThrow.h b/src/CBot/CBotInstr/CBotThrow.h index cbe06e50..62e11fc4 100644 --- a/src/CBot/CBotInstr/CBotThrow.h +++ b/src/CBot/CBotInstr/CBotThrow.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index d3aecf85..5cf57904 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -19,10 +19,10 @@ // Modules inlcude #include "CBotTry.h" -#include "CBotBlock.h" +#include "CBot/CBotInstr/CBotBlock.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTry.h b/src/CBot/CBotInstr/CBotTry.h index 9c79b3a4..6777a710 100644 --- a/src/CBot/CBotInstr/CBotTry.h +++ b/src/CBot/CBotInstr/CBotTry.h @@ -18,9 +18,9 @@ */ // Modules inlcude -#include "CBotCatch.h" +#include "CBot/CBotInstr/CBotCatch.h" -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 0d97f407..26342f94 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -18,18 +18,18 @@ */ // Modules inlcude -#include "CBotTwoOpExpr.h" +#include "CBot/CBotInstr/CBotTwoOpExpr.h" -#include "CBotInstr/CBotInstrUtils.h" +#include "CBot/CBotInstr/CBotInstrUtils.h" -#include "CBotParExpr.h" -#include "CBotLogicExpr.h" -#include "CBotExpression.h" +#include "CBot/CBotInstr/CBotParExpr.h" +#include "CBot/CBotInstr/CBotLogicExpr.h" +#include "CBot/CBotInstr/CBotExpression.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.h b/src/CBot/CBotInstr/CBotTwoOpExpr.h index 63e20ddc..e9829647 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.h +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp index eb38aea1..99e120e6 100644 --- a/src/CBot/CBotInstr/CBotWhile.cpp +++ b/src/CBot/CBotInstr/CBotWhile.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotWhile.h" -#include "CBotBlock.h" -#include "CBotCondition.h" +#include "CBot/CBotInstr/CBotWhile.h" +#include "CBot/CBotInstr/CBotBlock.h" +#include "CBot/CBotInstr/CBotCondition.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" // Local include diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h index a6fac948..6b91c741 100644 --- a/src/CBot/CBotInstr/CBotWhile.h +++ b/src/CBot/CBotInstr/CBotWhile.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 1bdd89c6..e2058a80 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -18,16 +18,16 @@ */ // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" -#include "CBotCall.h" -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" -#include "CBotUtils.h" -#include "CBotFileUtils.h" +#include "CBot/CBotCall.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotUtils.h" +#include "CBot/CBotFileUtils.h" -#include "CBotInstr/CBotFunction.h" +#include "CBot/CBotInstr/CBotFunction.h" #include "StringFunctions.h" diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 87dff3c2..88dd0741 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -20,11 +20,11 @@ #pragma once // Modules inlcude -#include "CBotTypResult.h" -#include "CBotString.h" -#include "CBotStringArray.h" +#include "CBot/CBotTypResult.h" +#include "CBot/CBotString.h" +#include "CBot/CBotStringArray.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index ac312c9a..8577c451 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotStack.h" -#include "CBotCall.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCall.h" -#include "CBotInstr/CBotFunction.h" +#include "CBot/CBotInstr/CBotFunction.h" -#include "CBotVar/CBotVarPointer.h" -#include "CBotVar/CBotVarClass.h" +#include "CBot/CBotVar/CBotVarPointer.h" +#include "CBot/CBotVar/CBotVarClass.h" -#include "CBotFileUtils.h" +#include "CBot/CBotFileUtils.h" // Local include diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 0e8ddd03..3b58116f 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotDefines.h" -#include "CBotTypResult.h" -#include "CBotString.h" +#include "CBot/CBotDefines.h" +#include "CBot/CBotTypResult.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index d8fc07c7..fafcf77a 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -19,7 +19,7 @@ ///////////////////////////////////////////////////// -#include "CBotString.h" +#include "CBot/CBotString.h" //strings management #include diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h index 58630ea6..3d87d2c0 100644 --- a/src/CBot/CBotString.h +++ b/src/CBot/CBotString.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotStringArray.cpp b/src/CBot/CBotStringArray.cpp index 6d5d6617..add32492 100644 --- a/src/CBot/CBotStringArray.cpp +++ b/src/CBot/CBotStringArray.cpp @@ -18,9 +18,9 @@ */ // Modules inlcude -#include "CBotStringArray.h" +#include "CBot/CBotStringArray.h" -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" // Local include diff --git a/src/CBot/CBotStringArray.h b/src/CBot/CBotStringArray.h index bc13233c..af4e9eff 100644 --- a/src/CBot/CBotStringArray.h +++ b/src/CBot/CBotStringArray.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotString.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index d5840f99..6b34d688 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -18,7 +18,7 @@ */ // Modules inlcude -#include "CBotToken.h" +#include "CBot/CBotToken.h" // Local include diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index 85dc6988..12be45cd 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotStringArray.h" +#include "CBot/CBotStringArray.h" // Local include diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp index 0ba8ff55..bde4f748 100644 --- a/src/CBot/CBotTypResult.cpp +++ b/src/CBot/CBotTypResult.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotTypResult.h" +#include "CBot/CBotTypResult.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" -#include "CBotClass.h" +#include "CBot/CBotClass.h" // Local include diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 5e38cb5f..715a84c3 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" -#include "CBotToken.h" -#include "CBotClass.h" -#include "CBotStack.h" -#include "CBotCStack.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotCStack.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 0ce76414..819331cd 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -20,8 +20,8 @@ #pragma once // Modules inlcude -#include "CBotString.h" -#include "CBotTypResult.h" +#include "CBot/CBotString.h" +#include "CBot/CBotTypResult.h" // Local include diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 4f75249c..43a6a34f 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -19,21 +19,21 @@ // Modules inlcude -#include "CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" -#include "CBotStack.h" +#include "CBot/CBotStack.h" -#include "CBotVar/CBotVarArray.h" -#include "CBotVar/CBotVarPointer.h" -#include "CBotVar/CBotVarClass.h" -#include "CBotVar/CBotVarBoolean.h" -#include "CBotVar/CBotVarString.h" -#include "CBotVar/CBotVarFloat.h" -#include "CBotVar/CBotVarInt.h" +#include "CBot/CBotVar/CBotVarArray.h" +#include "CBot/CBotVar/CBotVarPointer.h" +#include "CBot/CBotVar/CBotVarClass.h" +#include "CBot/CBotVar/CBotVarBoolean.h" +#include "CBot/CBotVar/CBotVarString.h" +#include "CBot/CBotVar/CBotVarFloat.h" +#include "CBot/CBotVar/CBotVarInt.h" -#include "CBotClass.h" +#include "CBot/CBotClass.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 1abedb33..56a5d5da 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "../CBotDefines.h" +#include "CBot/CBotDefines.h" -#include "../CBotString.h" +#include "CBot/CBotString.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index cece8117..f24dd207 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "CBotVarArray.h" -#include "CBotVarClass.h" -#include "CBotToken.h" -#include "CBotFileUtils.h" +#include "CBot/CBotVar/CBotVarArray.h" +#include "CBot/CBotVar/CBotVarClass.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotFileUtils.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h index 650437f3..542984d0 100644 --- a/src/CBot/CBotVar/CBotVarArray.h +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotDefines.h" +#include "CBot/CBotDefines.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp index b7680078..2ae7e6b3 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.cpp +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -18,11 +18,11 @@ */ // Modules inlcude -#include "CBotVarBoolean.h" +#include "CBot/CBotVar/CBotVarBoolean.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h index f21cf285..0451f6d2 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.h +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -20,9 +20,9 @@ #pragma once // Modules inlcude -#include "CBotToken.h" +#include "CBot/CBotToken.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 467255cb..894ff039 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -18,15 +18,15 @@ */ // Modules inlcude -#include "CBotVarClass.h" +#include "CBot/CBotVar/CBotVarClass.h" -#include "CBotClass.h" -#include "CBotStack.h" -#include "CBotDefines.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotStack.h" +#include "CBot/CBotDefines.h" -#include "CBotFileUtils.h" +#include "CBot/CBotFileUtils.h" -#include "CBotInstr/CBotInstr.h" +#include "CBot/CBotInstr/CBotInstr.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index ff6f9248..a04fccc7 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index 9f25fbb7..d23fca46 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotVarFloat.h" +#include "CBot/CBotVar/CBotVarFloat.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" -#include "CBotToken.h" +#include "CBot/CBotToken.h" -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index e55378a7..37a121be 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 67220a1a..f584997f 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotVarInt.h" +#include "CBot/CBotVar/CBotVarInt.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" -#include "CBotToken.h" +#include "CBot/CBotToken.h" -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 524c2762..0d8372e9 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index ff01eec7..de0f1665 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -18,14 +18,14 @@ */ // Modules inlcude -#include "CBotVarPointer.h" -#include "CBotToken.h" -#include "CBotClass.h" -#include "CBotVarClass.h" +#include "CBot/CBotVar/CBotVarPointer.h" +#include "CBot/CBotToken.h" +#include "CBot/CBotClass.h" +#include "CBot/CBotVar/CBotVarClass.h" -#include "CBotFileUtils.h" +#include "CBot/CBotFileUtils.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h index 278fbd8d..8f54f58c 100644 --- a/src/CBot/CBotVar/CBotVarPointer.h +++ b/src/CBot/CBotVar/CBotVarPointer.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp index 09c4e761..25f39a6c 100644 --- a/src/CBot/CBotVar/CBotVarString.cpp +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -18,13 +18,13 @@ */ // Modules inlcude -#include "CBotVarString.h" +#include "CBot/CBotVar/CBotVarString.h" -#include "CBotEnums.h" +#include "CBot/CBotEnums.h" -#include "CBotToken.h" +#include "CBot/CBotToken.h" -#include "CBotUtils.h" +#include "CBot/CBotUtils.h" // Local include diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 75b4b1d0..662e1d96 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 91f08748..e9c602e3 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -75,7 +75,7 @@ set(SOURCES # Includes set(LOCAL_INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/.. ) include_directories(${LOCAL_INCLUDES}) diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp index c38af371..e323fe34 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/StringFunctions.cpp @@ -18,12 +18,12 @@ */ // Modules inlcude -#include "StringFunctions.h" +#include "CBot/StringFunctions.h" -#include "CBotProgram.h" -#include "CBotEnums.h" +#include "CBot/CBotProgram.h" +#include "CBot/CBotEnums.h" -#include "CBotVar/CBotVar.h" +#include "CBot/CBotVar/CBotVar.h" // Local include diff --git a/src/CBot/StringFunctions.h b/src/CBot/StringFunctions.h index da534aad..fd3618f4 100644 --- a/src/CBot/StringFunctions.h +++ b/src/CBot/StringFunctions.h @@ -20,7 +20,7 @@ #pragma once // Modules inlcude -#include "CBotTypResult.h" +#include "CBot/CBotTypResult.h" // Local include From 2048ecb14816989d7bbfb63ad0912b6d46538b5e Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 14:45:31 +0100 Subject: [PATCH 138/360] Delete CBot.cpp. --- src/CBot/CBot.cpp | 85 ----------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 src/CBot/CBot.cpp diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp deleted file mode 100644 index 52ea9c60..00000000 --- a/src/CBot/CBot.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -/////////////////////////////////////////////////////////////////////// - -// compilation of various instructions -// compile all routines as static -// and return an object according to what was found as instruction - -// compiler principle: -// compile the routines return an object of the class corresponding to the operation found -// this is always a subclass of CBotInstr. -// (CBotInstr objects are never used directly) - - -// compiles if the routine returns nullptr is that the statement is false -// or misunderstood. -// the error is then on the stack CBotCStack :: Isok () is false - - -// Modules inlcude -#include "CBot.h" -#include "CBotInstr/CBotDo.h" -#include "CBotInstr/CBotFor.h" -#include "CBotInstr/CBotSwitch.h" -#include "CBotInstr/CBotBreak.h" -#include "CBotInstr/CBotTry.h" -#include "CBotInstr/CBotThrow.h" -#include "CBotInstr/CBotWhile.h" -#include "CBotInstr/CBotExprAlpha.h" -#include "CBotInstr/CBotExprNum.h" -#include "CBotInstr/CBotNew.h" -#include "CBotInstr/CBotExprNan.h" -#include "CBotInstr/CBotExprNull.h" -#include "CBotInstr/CBotExprBool.h" -#include "CBotInstr/CBotLeftExprVar.h" -#include "CBotInstr/CBotPreIncExpr.h" -#include "CBotInstr/CBotPostIncExpr.h" -#include "CBotInstr/CBotExprVar.h" -#include "CBotInstr/CBotInstrCall.h" -#include "CBotInstr/CBotListInstr.h" -#include "CBotInstr/CBotExprUnaire.h" -#include "CBotInstr/CBotBoolExpr.h" -#include "CBotInstr/CBotTwoOpExpr.h" -#include "CBotInstr/CBotExpression.h" -#include "CBotInstr/CBotIndexExpr.h" -#include "CBotInstr/CBotFieldExpr.h" -#include "CBotInstr/CBotClassInst.h" -#include "CBotInstr/CBotIString.h" -#include "CBotInstr/CBotFloat.h" -#include "CBotInstr/CBotBoolean.h" -#include "CBotInstr/CBotEmpty.h" -#include "CBotInstr/CBotReturn.h" -#include "CBotInstr/CBotIf.h" -#include "CBotInstr/CBotListArray.h" -#include "CBotInstr/CBotInstArray.h" -#include "CBotInstr/CBotInt.h" - -#include "CBotStack.h" -#include "CBotCStack.h" -#include "CBotClass.h" - -#include "CBotVar/CBotVar.h" - -// Local include - -// Global include -#include - From 17704c4d547f4d4e4d9f17adf30f0727642ee9c9 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 14:46:38 +0100 Subject: [PATCH 139/360] Delete resource.h. --- src/CBot/resource.h | 114 -------------------------------------------- 1 file changed, 114 deletions(-) delete mode 100644 src/CBot/resource.h diff --git a/src/CBot/resource.h b/src/CBot/resource.h deleted file mode 100644 index 60d2c775..00000000 --- a/src/CBot/resource.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -#pragma once - - -enum EID -{ - ID_IF = 2000, - ID_ELSE, - ID_WHILE, - ID_DO, - ID_FOR, - ID_BREAK, - ID_CONTINUE, - ID_SWITCH, - ID_CASE, - ID_DEFAULT, - ID_TRY, - ID_THROW, - ID_CATCH, - ID_FINALLY, - ID_TXT_AND, - ID_TXT_OR, - ID_TXT_NOT, - ID_RETURN, - ID_CLASS, - ID_EXTENDS, - ID_SYNCHO, - ID_NEW, - ID_PUBLIC, - ID_EXTERN, - ID_STATIC, - ID_PROTECTED, - ID_PRIVATE, - ID_INT, - ID_FLOAT, - ID_BOOLEAN, - ID_STRING, - ID_VOID, - ID_BOOL, - - ID_TRUE = 2200, - ID_FALSE, - ID_NULL, - ID_NAN, - - ID_OPENPAR = 2300, - ID_CLOSEPAR, - ID_OPBLK, - ID_CLBLK, - ID_SEP, - ID_COMMA, - ID_DOTS, - ID_DOT, - ID_OPBRK, - ID_CLBRK, - ID_DBLDOTS, - ID_LOGIC, - ID_ADD, - ID_SUB, - ID_MUL, - ID_DIV, - ID_ASS, - ID_ASSADD, - ID_ASSSUB, - ID_ASSMUL, - ID_ASSDIV, - ID_ASSOR, - ID_ASSAND, - ID_ASSXOR, - ID_ASSSL, - ID_ASSSR, - ID_ASSASR, - ID_SL, - ID_SR, - ID_ASR, - ID_INC, - ID_DEC, - ID_LO, - ID_HI, - ID_LS, - ID_HS, - ID_EQ, - ID_NE, - ID_AND, - ID_XOR, - ID_OR, - ID_LOG_AND, - ID_LOG_OR, - ID_LOG_NOT, - ID_NOT, - ID_MODULO, - ID_POWER, - ID_ASSMODULO, - TX_UNDEF = 4000, - TX_NAN -}; From f9ab37fd1401c1924598398012a489c5034ff55c Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 14:49:27 +0100 Subject: [PATCH 140/360] Add comment deleted by commit 573e1152e339f5d018464a473340980a3d8dbb8b. --- src/CBot/CBotEnums.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h index 17dbef69..0db5aff0 100644 --- a/src/CBot/CBotEnums.h +++ b/src/CBot/CBotEnums.h @@ -49,6 +49,7 @@ enum CBotType CBotTypClass = 15, CBotTypIntrinsic = 16 // instance of a class intrinsic }; +//n = not implemented yet //! \brief CBotGet Different modes for GetPosition. enum CBotGet From 0f491ce433e39b49e329f5920779a5e50950e1e4 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 15:05:22 +0100 Subject: [PATCH 141/360] Add commments in CBot.h --- src/CBot/CBot.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 11595183..4ba45b0e 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -17,6 +17,12 @@ * along with this program. If not, see http://gnu.org/licenses */ +/*! + * \file CBot.h + * \brief Public interface of CBot language interpreter. CBot.h is the only file + * that should be included by any Colobot files outside of the CBot module. + */ + // Modules inlcude #include "CBot/CBotFileUtils.h" #include "CBot/CBotClass.h" From aa3f8c0cd1884950487e6164f20b7f21e669d3bd Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 15:37:18 +0100 Subject: [PATCH 142/360] Add missing include in CBot.h. --- src/CBot/CBot.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 4ba45b0e..d0f42f1f 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -25,6 +25,8 @@ // Modules inlcude #include "CBot/CBotFileUtils.h" +#include "CBot/CBotString.h" +#include "CBot/CBotStringArray.h" #include "CBot/CBotClass.h" #include "CBot/CBotToken.h" #include "CBot/CBotProgram.h" From f45d657ab02ac21d8087e3addeca1e8ceb90e61e Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 15:42:09 +0100 Subject: [PATCH 143/360] Add comments delete by commit 1a6b5ded640c1a606d85fd5b5d1b68254b855423. --- src/CBot/CBotClass.h | 140 ++++++++++++++++++++++++++++++++++++++++- src/CBot/CBotDefines.h | 3 + src/CBot/CBotProgram.h | 51 +++++++++++++-- 3 files changed, 187 insertions(+), 7 deletions(-) diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index 2b151b0a..69f3605e 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -41,7 +41,8 @@ class CBotDefParam; /*! * \brief The CBotClass class Class to define new classes in the language CBOT - * for example to define the class CPoint (x, y). + * For example to define the class CPoint (x, y) see comments at end of this + * file. */ class CBotClass { @@ -77,8 +78,9 @@ public: bool intrinsic = false); /*! - * \brief AddFunction This call allows to add as external (**) new method - * used by the objects of this class. + * \brief AddFunction This call allows to add as external new method + * used by the objects of this class. See (**) at end of this file for + * more details. * \param name * \param rExec * \param rCompile @@ -339,3 +341,135 @@ private: //! Processes waiting for sync. CBotProgram* m_ProgInLock[5]; }; + +/* +(**) Note: + + To define an external function, proceed as follows: + + a) define a routine for compilation this routine receive list of parameters + (no values) and either returns a result type (CBotTyp... or 0 = void) + or an error number. + + b) define a routine for the execution this routine receive list of + parameters (with valeurs), a variable to store the result + (according to the given type at compile time) + + For example, a routine which calculates the mean of a parameter list + +int cMean(CBotVar* &pVar, CBotString& ClassName) +{ + if ( pVar == nullptr ) return 6001; // there is no parameter! + while ( pVar != nullptr ) + { + if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number + pVar = pVar -> GetNext(); + } + return CBotTypFloat; // the type of the result may depend on the parameters! +} + + +bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception) +{ + float total = 0; + int nb = 0; + while (pVar != nullptr) + { + total += pVar->GetValFloat(); + pVar = pVar->GetNext(); + nb++; + } + pResult->SetValFloat(total/nb); // returns the mean value + return true; // operation fully completed +} + +//////////////////////////////////////////////////////////////////////////////// +// Examples of use +// Definition classes and functions + + +// define the global class CPoint +// -------------------------------- + m_pClassPoint = new CBotClass("CPoint", nullptr); + // adds the component ".x" + m_pClassPoint->AddItem("x", CBotTypResult(CBotTypFloat)); + // adds the component ".y" + m_pClassPoint->AddItem("y", CBotTypResult(CBotTypFloat)); + // the player can then use the instructions + // CPoint position; position.x = 12; position.y = -13.6 + +// define class CColobotObject +// -------------------------------- + // This class manages all the objects in the world of COLOBOT + // the "main" user program belongs to this class + m_pClassObject = new CBotClass("CColobotObject", m_pClassBase); + // adds the component ".position" + m_pClassObject->AddItem("position", m_pClassPoint); + // adds the component ".type" + m_pClassObject->AddItem("type", CBotTypResult(CBotTypShort)); + // adds a definition of constant + m_pClassObject->AddConst("ROBOT", CBotTypShort, 1); // ROBOT equivalent to the value 1 + // adds the FIND routine + m_pClassObject->AddFunction( rCompFind, rDoFind ); + // the player can now use the instructions + // CColobotObject chose; chose = FIND( ROBOT ) + +// define class CColobotRobot derived from CColobotObject +// --------------------------------------------------------- + // programs "main" associated with robots as a part of this class + m_pClassRobot = new CBotClass("CColobotRobot", m_pClassObject); + // add routine GOTO + m_pClassRobot->AddFunction( rCompGoto, rDoGoto ); + // the player can now use + // GOTO( FIND ( ROBOT ) ); + + +// creates an instance of the class Robot +// ------------------------------------ + // for example a new robot which has just been manufactured + CBotVar* m_pMonRobot = new CBotVar("MonRobot", m_pClassRobot); + + +// compiles the program by hand for this robot +// ------------------------------------------ + CString LeProgramme( "void main() {GOTO(0, 0); return 0;}" ); + if ( !m_pMonRobot->Compile( LeProgramme ) ) {error handling ...}; + +// build a stack for interpreter +// -------------------------------------- + CBotStack* pStack = new CBotStack(nullptr); + +// executes the main program +// ------------------------- + while( false = m_pMonRobot->Execute( "main", pStack )) + { + // program suspended + // could be pass a handle to another (safeguarding pstack for the robot one) + }; + // programme "main" finished ! + +// routine that implements the GOTO (CPoint pos) +bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception ) +{ + if (pVar->GetType() != CBotTypeClass || + pVar->IsElemOfClas("CPoint") ) { exception = 6522; return false; ) + // the parameter is not the right class? + // in fact the control is done to the routine of compilation + + m_PosToGo.Copy( pVar ); // keeps the target position (object type CBotVar) + + // or so + CBotVar* temp; + temp = pVar->GetItem("x"); // is necessary for the object of type CPoint + ASSERT (temp != nullptr && temp->GetType() == CBotTypFloat); + m_PosToGo.x = temp->GetValFloat(); + + temp = pVar->GetItem("y"); // is necessary for the object of type CPoint + ASSERT (temp != nullptr && temp->GetType() == CBotTypFloat); + m_PosToGo.y = temp->GetValFloat(); + + return (m_CurentPos == m_PosToGo); // makes true if the position is reached + // returns false if one had wait yet +} + +*/ diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index b1c73b38..93be12bb 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -118,6 +118,9 @@ #define CBotErrRead 6014 // error while reading #define CBotErrWrite 6015 // writing error +// other values ​​may be returned +// for example exceptions returned by external routines +// and " throw " with any number. // TODO: refactor & change to enum! diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 88dd0741..98854b33 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -186,16 +186,16 @@ public: // /*! - * \brief AddFunction Call this to add externally (**) a new function used - * by the program CBoT. + * \brief AddFunction Call this to add externally a new function used + * by the program CBoT. See (**) at end of this file for more details. * \param name * \param rExec * \param rCompile * \return */ static bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); /*! * \brief DefineNum @@ -270,3 +270,46 @@ private: //! Associated identifier. long m_Ident; }; + +/* +(**) Note: + + To define an external function, proceed as follows: + + a) define a routine for compilation this routine receive list of parameters + (no values) and either returns a result type (CBotTyp... or 0 = void) + or an error number. + + b) define a routine for the execution this routine receive list of + parameters (with valeurs), a variable to store the result + (according to the given type at compile time) + + For example, a routine which calculates the mean of a parameter list + +int cMean(CBotVar* &pVar, CBotString& ClassName) +{ + if ( pVar == nullptr ) return 6001; // there is no parameter! + while ( pVar != nullptr ) + { + if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number + pVar = pVar -> GetNext(); + } + return CBotTypFloat; // the type of the result may depend on the parameters! +} + + +bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception) +{ + float total = 0; + int nb = 0; + while (pVar != nullptr) + { + total += pVar->GetValFloat(); + pVar = pVar->GetNext(); + nb++; + } + pResult->SetValFloat(total/nb); // returns the mean value + return true; // operation fully completed +} + +*/ From 30c3d031410aa8f4936807d2e72638b864de83d3 Mon Sep 17 00:00:00 2001 From: Grunaka Date: Sun, 6 Dec 2015 16:30:13 +0100 Subject: [PATCH 144/360] Remove header files from to the list of .cpp files in CBot CMakeLists.txt. --- src/CBot/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index e9c602e3..b38ff615 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,7 +1,4 @@ set(SOURCES - CBot.h - CBotEnums.h - CBotDefines.h CBotUtils.cpp CBotFileUtils.cpp CBotClass.cpp From aa2e14219e698b5da543826e21227b11d138ab34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 18 Dec 2015 21:04:16 +0100 Subject: [PATCH 145/360] Added warnings and error messages to graphics devices regarding unsupported OpenGL version --- src/app/app.cpp | 5 ++++- src/graphics/core/device.h | 9 +++++++++ src/graphics/opengl/gl21device.cpp | 7 ++++++- src/graphics/opengl/gl33device.cpp | 11 +++++++++-- src/graphics/opengl/gldevice.cpp | 14 +++++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 5c124083..0a82f32f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -624,7 +624,10 @@ bool CApplication::Create() if (! m_device->Create() ) { - m_errorMessage = std::string("Error in CDevice::Create()\n") + standardInfoMessage; + m_errorMessage = std::string("Error in CDevice::Create()\n") + + "\n\n" + + m_device->GetError() + + standardInfoMessage; m_exitCode = 5; return false; } diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 36ba9580..def5b7f2 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -276,9 +276,18 @@ public: */ class CDevice { +protected: + std::string m_errorMessage; + public: virtual ~CDevice() {} + //! Returns last error message or empty string + inline std::string GetError() + { + return m_errorMessage; + } + //! Provides a hook to debug graphics code (implementation-specific) virtual void DebugHook() = 0; diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index 1a86fade..bd8f2726 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -177,6 +177,7 @@ bool CGL21Device::Create() if (glewInit() != GLEW_OK) { GetLogger()->Error("GLEW initialization failed\n"); + m_errorMessage = "An error occured while initializing GLEW."; return false; } @@ -186,7 +187,11 @@ bool CGL21Device::Create() if (m_glMajor < 2) { - GetLogger()->Error("Your hardware does not support OpenGL 2.0 or 2.1."); + GetLogger()->Error("Unsupported OpenGL version: %d.%d\n", m_glMajor, m_glMinor); + GetLogger()->Error("OpenGL 2.0 or newer is required to use this engine.\n"); + m_errorMessage = "It seems your graphics card does not support OpenGL 2.0.\n"; + m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; + m_errorMessage += "(OpenGL 2.0 is roughly equivalent to Direct3D 9)"; return false; } diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 1246564d..1560cc8c 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -177,6 +177,7 @@ bool CGL33Device::Create() if (glewInit() != GLEW_OK) { GetLogger()->Error("GLEW initialization failed\n"); + m_errorMessage = "An error occured while initializing GLEW."; return false; } @@ -187,12 +188,18 @@ bool CGL33Device::Create() int glVersion = 10 * m_glMajor + m_glMinor; if (glVersion < 30) { - GetLogger()->Error("Your hardware does not support OpenGL 3.0+. Exiting.\n"); + GetLogger()->Error("Unsupported OpenGL version: %d.%d\n", m_glMajor, m_glMinor); + GetLogger()->Error("OpenGL 3.0 or newer is required to use this engine.\n"); + m_errorMessage = "It seems your graphics card does not support OpenGL 3.0.\n"; + m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; + m_errorMessage += "(OpenGL 3.0 is roughly equivalent to Direct3D 10)"; return false; } else if (glVersion < 33) { - GetLogger()->Warn("Full OpenGL 3.3 unavailable. Graphics might be bugged.\n"); + GetLogger()->Warn("Partially supported OpenGL version: %d.%d\n", m_glMajor, m_glMinor); + GetLogger()->Warn("You may experience problems while running the game on this engine.\n"); + GetLogger()->Warn("OpenGL 3.3 or newer is recommended.\n"); } else { diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 6070acdf..4eba81a6 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -173,12 +173,24 @@ bool CGLDevice::Create() if (glewInit() != GLEW_OK) { GetLogger()->Error("GLEW initialization failed\n"); + m_errorMessage = "An error occured while initializing GLEW."; return false; } // Extract OpenGL version const char *version = reinterpret_cast(glGetString(GL_VERSION)); sscanf(version, "%d.%d", &m_glMajor, &m_glMinor); + + int glVersion = 10 * m_glMajor + m_glMinor; + if (glVersion < 13) + { + GetLogger()->Error("Unsupported OpenGL version: %d.%d\n", m_glMajor, m_glMinor); + GetLogger()->Error("OpenGL 1.3 or newer is required to use this engine.\n"); + m_errorMessage = "It seems your graphics card does not support OpenGL 1.3.\n"; + m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; + return false; + } + GetLogger()->Info("OpenGL %d.%d\n", m_glMajor, m_glMinor); // Detect multitexture support @@ -306,7 +318,7 @@ bool CGLDevice::Create() m_framebufferSupport = DetectFramebufferSupport(); if (m_framebufferSupport != FBS_NONE) - GetLogger()->Debug("Framebuffer supported\n"); + GetLogger()->Info("Framebuffer supported\n"); GetLogger()->Info("CDevice created successfully\n"); From 964d3574fd368dbed946ae3f4c7f18f54d258d59 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 21:20:41 +0100 Subject: [PATCH 146/360] Fixed treating 'bool' as 'int' in CBot engine Appears to fix #199 - further testing required --- src/CBot/CBotInstr/CBotFor.cpp | 2 +- src/CBot/CBotInstr/CBotFunction.cpp | 14 +++++------ src/CBot/CBotInstr/CBotInstrMethode.cpp | 4 ++-- src/CBot/CBotInstr/CBotListInstr.cpp | 2 +- src/CBot/CBotStack.cpp | 32 ++++++++++++------------- src/CBot/CBotStack.h | 17 ++++++------- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index e225b99b..80488328 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -115,7 +115,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) //////////////////////////////////////////////////////////////////////////////// bool CBotFor :: Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this, true); // adds an item to the stack (variables locales) + CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // adds an item to the stack (variables locales) // or find in case of recovery // if ( pile == EOX ) return true; diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 7277486e..f61328b3 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -345,7 +345,7 @@ static int xx = 0; //////////////////////////////////////////////////////////////////////////////// bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { - CBotStack* pile = pj->AddStack(this, 2); // one end of stack local to this function + CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_2); // one end of stack local to this function // if ( pile == EOX ) return true; pile->SetBotCall(m_pProg); // bases for routines @@ -401,7 +401,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst pile->SetBotCall(m_pProg); // bases for routines - if ( pile->GetBlock() < 2 ) + if ( pile->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 ) { CBotStack* pile2 = pile->RestoreStack(nullptr); // one end of stack local to this function if ( pile2 == nullptr ) return; @@ -604,14 +604,14 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS if ( pt != nullptr ) { - CBotStack* pStk1 = pStack->AddStack(pt, 2); // to put "this" + CBotStack* pStk1 = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2); // to put "this" // if ( pStk1 == EOX ) return true; pStk1->SetBotCall(pt->m_pProg); // it may have changed module if ( pStk1->IfStep() ) return false; - CBotStack* pStk3 = pStk1->AddStack(nullptr, true); // parameters + CBotStack* pStk3 = pStk1->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // parameters // preparing parameters on the stack @@ -683,7 +683,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, pStk1->SetBotCall(pt->m_pProg); // it may have changed module - if ( pStk1->GetBlock() < 2 ) + if ( pStk1->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 ) { CBotStack* pStk2 = pStk1->RestoreStack(nullptr); // used more if ( pStk2 == nullptr ) return; @@ -733,11 +733,11 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar { // DEBUG( "CBotFunction::DoCall" + pt->GetName(), 0, pStack); - CBotStack* pStk = pStack->AddStack(pt, 2); + CBotStack* pStk = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2); // if ( pStk == EOX ) return true; pStk->SetBotCall(pt->m_pProg); // it may have changed module - CBotStack* pStk3 = pStk->AddStack(nullptr, true); // to set parameters passed + CBotStack* pStk3 = pStk->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // to set parameters passed // preparing parameters on the stack diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 3778a9c2..1e5c34a5 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -106,7 +106,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) { CBotVar* ppVars[1000]; - CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This + CBotStack* pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // a place for the copy of This if (pVar->GetPointer() == nullptr) { @@ -221,7 +221,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) bool CBotInstrMethode::Execute(CBotStack* &pj) { CBotVar* ppVars[1000]; - CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This + CBotStack* pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // place for the copy of This if (pile1->IfStep()) return false; diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index 13b4ded7..65bdb40e 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -80,7 +80,7 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal bool CBotListInstr::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this, true); //needed for SetState() + CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); //needed for SetState() if (pile->StackOver() ) return pj->Return( pile); diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 8577c451..c2c04d23 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -63,7 +63,7 @@ CBotStack* CBotStack::FirstStack() // completely empty memset(p, 0, size); - p-> m_bBlock = true; + p-> m_bBlock = UnknownEnumBlock::UNKNOWN_TRUE ; m_timer = m_initimer; // sets the timer at the beginning CBotStack* pp = p; @@ -140,7 +140,7 @@ void CBotStack::Delete() // routine improved //////////////////////////////////////////////////////////////////////////////// -CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) +CBotStack* CBotStack::AddStack(CBotInstr* instr, UnknownEnumBlock bBlock) { if (m_next != nullptr) { @@ -168,12 +168,12 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) p->m_prev = this; p->m_state = 0; p->m_call = nullptr; - p->m_bFunc = false; + p->m_bFunc = IsFunctionParam::FALSE; return p; } //////////////////////////////////////////////////////////////////////////////// -CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) +CBotStack* CBotStack::AddStackEOX(CBotCall* instr, UnknownEnumBlock bBlock) { if (m_next != nullptr) { @@ -186,12 +186,12 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) } CBotStack* p = AddStack(nullptr, bBlock); p->m_call = instr; - p->m_bFunc = 2; // special + p->m_bFunc = IsFunctionParam::UNKNOWN_EOX_SPECIAL; // special return p; } //////////////////////////////////////////////////////////////////////////////// -CBotStack* CBotStack::AddStack2(bool bBlock) +CBotStack* CBotStack::AddStack2(UnknownEnumBlock bBlock) { if (m_next2 != nullptr) { @@ -215,7 +215,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock) } //////////////////////////////////////////////////////////////////////////////// -bool CBotStack::GetBlock() +CBotStack::UnknownEnumBlock CBotStack::GetBlock() { return m_bBlock; } @@ -723,7 +723,7 @@ void CBotStack::AddVar(CBotVar* pVar) CBotStack* p = this; // returns to the father element - while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; + while (p != nullptr && p->m_bBlock == UnknownEnumBlock::UNKNOWN_FALSE) p = p->m_prev; if ( p == nullptr ) return; @@ -743,7 +743,7 @@ void CBotStack::AddVar(CBotVar* pVar) void CBotStack::SetBotCall(CBotProgram* p) { m_prog = p; - m_bFunc = true; + m_bFunc = IsFunctionParam::TRUE; } //////////////////////////////////////////////////////////////////////////////// @@ -826,7 +826,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) while (p->m_next != nullptr) { if ( p->m_instr != nullptr ) instr = p->m_instr; - if ( p->m_bFunc == 1 && p->m_instr != nullptr ) funct = p->m_instr; + if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr; if ( p->m_next->m_prog != prog ) break ; if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ; @@ -834,7 +834,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) } if ( p->m_instr != nullptr ) instr = p->m_instr; - if ( p->m_bFunc == 1 && p->m_instr != nullptr ) funct = p->m_instr; + if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr; if ( funct == nullptr ) return; @@ -868,13 +868,13 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) // descends upon the elements of block - while ( p != nullptr && !p->m_bBlock ) p = p->m_prev; + while ( p != nullptr && p->m_bBlock != UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev; // Now p is on the beggining of the top block (with local variables) while ( p != nullptr && level++ < 0 ) { p = p->m_prev; - while ( p != nullptr && !p->m_bBlock ) p = p->m_prev; + while ( p != nullptr && p->m_bBlock != UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev; } // Now p is on the block "level" @@ -884,7 +884,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) CBotStack* pp = p; while ( pp != nullptr ) { - if ( pp->m_bFunc == 1 ) break; + if ( pp->m_bFunc == IsFunctionParam::TRUE) break; pp = pp->m_prev; } @@ -913,7 +913,7 @@ bool CBotStack::SaveState(FILE* pf) { if (!WriteWord(pf, 1)) return false; // a mark of pursuit } - if (!WriteWord(pf, m_bBlock)) return false; // is a local block + if (!WriteWord(pf, static_cast(m_bBlock))) return false; // is a local block if (!WriteWord(pf, m_state)) return false; // in what state? if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete if (!WriteWord(pf, m_step)) return false; // in what state? @@ -947,7 +947,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) } if (!ReadWord(pf, w)) return false; // is a local block - pStack->m_bBlock = w; + pStack->m_bBlock = static_cast(w); if (!ReadWord(pf, w)) return false; // in what state ? pStack->SetState(static_cast(w)); // in a good state diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 3b58116f..738cfd6c 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -45,6 +45,9 @@ class CBotToken; class CBotStack { public: + enum class UnknownEnumBlock : unsigned short { UNKNOWN_FALSE = 0, UNKNOWN_TRUE = 1, UNKNOWN_2 = 2 }; // TODO: figure out what these mean ~krzys_h + enum class IsFunctionParam : unsigned short { FALSE = 0, TRUE = 1, UNKNOWN_EOX_SPECIAL = 2 }; // TODO: just guessing the meaning of values, should be verified ~krzys_h + #if STACKMEM /** * \brief FirstStack Allocate first stack @@ -169,12 +172,12 @@ public: CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false); - CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack - CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack + CBotStack* AddStack(CBotInstr* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack + CBotStack* AddStackEOX(CBotCall* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack CBotStack* RestoreStack(CBotInstr* instr = nullptr); CBotStack* RestoreStackEOX(CBotCall* instr = nullptr); - CBotStack* AddStack2(bool bBlock = false); // extends the stack + CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack bool Return(CBotStack* pFils); // transmits the result over bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack bool BreakReturn(CBotStack* pfils, const char* name = nullptr); @@ -206,7 +209,7 @@ public: void SetBotCall(CBotProgram* p); CBotProgram* GetBotCall(bool bFirst = false); void* GetPUser(); - bool GetBlock(); + UnknownEnumBlock GetBlock(); bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype); @@ -221,8 +224,6 @@ public: void GetRunPos(const char* &FunctionName, int &start, int &end); CBotVar* GetStackVars(const char* &FunctionName, int level); - int m_temp; - private: CBotStack* m_next; CBotStack* m_next2; @@ -243,7 +244,7 @@ private: CBotVar* m_var; // result of the operations CBotVar* m_listVar; // variables declared at this level - bool m_bBlock; // is part of a block (variables are local to this block) + UnknownEnumBlock m_bBlock; // is part of a block (variables are local to this block) bool m_bOver; // stack limits? // bool m_bDontDelete; // special, not to destroy the variable during delete CBotProgram* m_prog; // user-defined functions @@ -258,7 +259,7 @@ private: void* m_pUser; CBotInstr* m_instr; // the corresponding instruction - bool m_bFunc; // an input of a function? + IsFunctionParam m_bFunc; // an input of a function? CBotCall* m_call; // recovery point in a extern call friend class CBotTry; }; From 1dd230aaafcfc4f372c9dbe7dad4c94148b0077d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 22:02:24 +0100 Subject: [PATCH 147/360] Fixed incombatibility with old save files, closes #686 --- src/level/parser/parser.cpp | 10 +++++++++- src/level/parser/parser.h | 3 +++ src/level/player_profile.cpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/level/parser/parser.cpp b/src/level/parser/parser.cpp index a3a7fe5a..f0356bca 100644 --- a/src/level/parser/parser.cpp +++ b/src/level/parser/parser.cpp @@ -358,13 +358,21 @@ void CLevelParser::AddLine(CLevelParserLineUPtr line) } CLevelParserLine* CLevelParser::Get(const std::string& command) +{ + CLevelParserLine* line = GetIfDefined(command); + if (line == nullptr) + throw CLevelParserException("Command not found: " + command); + return line; +} + +CLevelParserLine* CLevelParser::GetIfDefined(const std::string& command) { for (auto& line : m_lines) { if (line->GetCommand() == command) return line.get(); } - throw CLevelParserException("Command not found: " + command); + return nullptr; } int CLevelParser::CountLines(const std::string& command) diff --git a/src/level/parser/parser.h b/src/level/parser/parser.h index 4d78c59d..7b6a3148 100644 --- a/src/level/parser/parser.h +++ b/src/level/parser/parser.h @@ -88,6 +88,9 @@ public: //! Find first line with given command CLevelParserLine* Get(const std::string& command); + //! Find first line with given command, null if doesn't exist + CLevelParserLine* GetIfDefined(const std::string &command); + //! Count lines with given command int CountLines(const std::string& command); diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index 2d6c8f57..d611718d 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -451,7 +451,8 @@ std::vector CPlayerProfile::GetSavedSceneList() { CLevelParser levelParser(savegameFile); levelParser.Load(); - int time = levelParser.Get("Created")->GetParam("date")->AsInt(); + CLevelParserLine* line = levelParser.GetIfDefined("Created"); + int time = line != nullptr ? line->GetParam("date")->AsInt() : 0; sortedSaveDirs[time] = SavedScene(GetSaveFile(dir), levelParser.Get("Title")->GetParam("text")->AsString()); } } From e20f5f6983548241b3742b8d103227a72347def4 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 22:06:16 +0100 Subject: [PATCH 148/360] Allow on-crash save during in-simulation config, closes #685 --- src/app/signal_handlers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index 618f323d..f685a587 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -150,7 +150,7 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) robotMain = CRobotMain::GetInstancePointer(); msg << "The game was in phase " << PhaseToString(robotMain->GetPhase()) << " (ID=" << robotMain->GetPhase() << ")" << std::endl; msg << "Last started level was: category=" << GetLevelCategoryDir(robotMain->GetLevelCategory()) << " chap=" << robotMain->GetLevelChap() << " rank=" << robotMain->GetLevelRank() << std::endl; - canSave = (robotMain->GetPhase() == PHASE_SIMUL) && !robotMain->IsLoading(); + canSave = (robotMain->GetPhase() == PHASE_SIMUL || IsInSimulationConfigPhase(robotMain->GetPhase())) && !robotMain->IsLoading(); } msg << "==============================" << std::endl; msg << std::endl; From 2e17712b5d3c305b67746f0095480365b53588aa Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 22:10:15 +0100 Subject: [PATCH 149/360] Added official build info in crash screen --- CMakeLists.txt | 4 ++++ src/app/signal_handlers.cpp | 8 ++++++-- src/common/version.h.cmake | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a45ae6d0..fd77d671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,10 @@ option(ASSERTS "Enable assert()s" ON) # Development build can be enabled/disabled regardless of build type option(DEV_BUILD "Enable development build (enables some debugging tools, local setting paths, etc.)" OFF) +# Official build - changes text on the crash screen +# PLEASE DO NOT USE ON UNOFFICIAL BUILDS. Thanks. +option(OFFICIAL_BUILD "Official build (changes crash screen text)" OFF) + # Portable build - load all data from current directory option(PORTABLE "Portable build" OFF) diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index f685a587..a2f4e921 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -133,8 +133,12 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) msg << "including information on what you were doing before this happened and all the information below." << std::endl; msg << "==============================" << std::endl; #if BUILD_NUMBER == 0 - // COLOBOT_VERSION_DISPLAY doesn't update if you don't run CMake after "git pull" - msg << "You seem to be running a custom compilation of version " << COLOBOT_VERSION_DISPLAY << ", but please verify that." << std::endl; + #ifdef OFFICIAL_BUILD + msg << "You are running official " << COLOBOT_VERSION_DISPLAY << " build." << std::endl; + #else + // COLOBOT_VERSION_DISPLAY doesn't update if you don't run CMake after "git pull" + msg << "You seem to be running a custom compilation of version " << COLOBOT_VERSION_DISPLAY << ", but please verify that." << std::endl; + #endif #else msg << "You are running version " << COLOBOT_VERSION_DISPLAY << " from CI build #" << BUILD_NUMBER << std::endl; #endif diff --git a/src/common/version.h.cmake b/src/common/version.h.cmake index 5749421e..ad3714b3 100644 --- a/src/common/version.h.cmake +++ b/src/common/version.h.cmake @@ -4,3 +4,4 @@ #define COLOBOT_VERSION_DISPLAY "@COLOBOT_VERSION_DISPLAY@" #define BUILD_NUMBER @BUILD_NUMBER@ +#cmakedefine OFFICIAL_BUILD From 52a18de5c09a0e24ee3a380e197a22a433efcc30 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 22:19:13 +0100 Subject: [PATCH 150/360] Fixed failed assertion when damaging LRV or Scribbler, closes #665 --- src/physics/physics.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index cd91f7d3..7bab9253 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2750,9 +2750,7 @@ bool CPhysics::ExploOther(ObjectType iType, oType == OBJECT_MOBILEwt || oType == OBJECT_MOBILEtt || oType == OBJECT_MOBILEft || - oType == OBJECT_MOBILEit || - oType == OBJECT_MOBILEdr || - oType == OBJECT_APOLLO2 ) // vehicle? + oType == OBJECT_MOBILEit ) // vehicle? { assert(pObj->Implements(ObjectInterfaceType::Damageable)); dynamic_cast(pObj)->DamageObject(DamageType::Collision, force/200.0f); From 5e23426b53e79ccc3d1bba0a84051827d9cdc2ee Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 14:24:49 +0100 Subject: [PATCH 151/360] Refactored CBotString to use std::string and CBotStringArray to use std::vector --- src/CBot/CBotString.cpp | 278 ++++++----------------------- src/CBot/CBotString.h | 25 ++- src/CBot/CBotStringArray.cpp | 87 +-------- src/CBot/CBotStringArray.h | 12 +- test/unit/CBot/CBotString_test.cpp | 16 -- 5 files changed, 68 insertions(+), 350 deletions(-) diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index fafcf77a..fc1cefd8 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -25,6 +25,7 @@ #include #include #include +#include //Map is filled with id-string pars that are needed for CBot language parsing const std::map CBotString::s_keywordString = @@ -120,216 +121,97 @@ const std::map CBotString::s_keywordString = CBotString::CBotString() { - m_ptr = nullptr; - m_lg = 0; + m_str = ""; } CBotString::~CBotString() { - delete[] m_ptr; - m_ptr = nullptr; } CBotString::CBotString(const char* p) { - m_lg = strlen(p); + m_str = p; +} - m_ptr = nullptr; - if (m_lg>0) - { - m_ptr = new char[m_lg+1]; - strcpy(m_ptr, p); - } +CBotString::CBotString(const std::string &p) +{ + m_str = p; } CBotString::CBotString(const CBotString& srcString) { - m_lg = srcString.m_lg; - - m_ptr = nullptr; - if (m_lg>0) - { - m_ptr = new char[m_lg+1]; - strcpy(m_ptr, srcString.m_ptr); - } + m_str = srcString.m_str; } - int CBotString::GetLength() { - if (m_ptr == nullptr) return 0; - return strlen( m_ptr ); + return m_str.length(); } CBotString CBotString::Left(int nCount) const { - char chain[2000]; - - // clamp nCount to correct value - if(nCount < 0) nCount = 0; - if(nCount > m_lg) nCount = m_lg; - - int i; - for (i = 0; i < m_lg && i < nCount && i < 1999; ++i) - { - chain[i] = m_ptr[i]; - } - chain[i] = 0 ; - - return CBotString(chain); + return CBotString(m_str.substr(0, nCount)); } CBotString CBotString::Right(int nCount) const { - char chain[2000]; - - // clamp nCount to correct value - if(nCount < 0) nCount = 0; - if(nCount > m_lg) nCount = m_lg; - - int i = m_lg - nCount; - if ( i < 0 ) i = 0; - - int j; - for (j = 0 ; i < m_lg && i < 1999; ++i) - { - chain[j++] = m_ptr[i]; - } - chain[j] = 0 ; - - return CBotString(chain); + return CBotString(m_str.substr(m_str.length()-nCount, std::string::npos)); } CBotString CBotString::Mid(int start, int lg) { - CBotString res; - - if (lg == -1) lg = 2000; - - // clamp start to correct value - if (start < 0) start = 0; - if (start >= m_lg) return res; - - int remaining = m_lg - start; - if (lg > remaining) lg = remaining; - if (lg < 0) lg = 0; - - char* p = new char[m_lg+1]; - strcpy(p, m_ptr+start); - p[lg] = 0; - - res = p; - delete[] p; - return res; + return CBotString(m_str.substr(start, lg)); } int CBotString::Find(const char c) { - for (int i = 0; i < m_lg; ++i) - { - if (m_ptr[i] == c) return i; - } - return -1; + std::size_t pos = m_str.find(c); + return pos != std::string::npos ? pos : -1; } int CBotString::Find(const char * lpsz) { - int l = strlen(lpsz); - - for (size_t i = 0; static_cast(i) <= m_lg-l; ++i) - { - for (size_t j = 0; static_cast(j) < l; ++j) - { - if (m_ptr[i+j] != lpsz[j]) goto bad; - } - return i; -bad:; - } - return -1; + std::size_t pos = m_str.find(lpsz); + return pos != std::string::npos ? pos : -1; } int CBotString::ReverseFind(const char c) { - int i; - for (i = m_lg-1; i >= 0; --i) - { - if (m_ptr[i] == c) return i; - } - return -1; + std::size_t pos = m_str.rfind(c); + return pos != std::string::npos ? pos : -1; } int CBotString::ReverseFind(const char * lpsz) { - int i, j; - int l = strlen(lpsz); - - for (i = m_lg-l; i >= 0; --i) - { - for (j = 0; j < l; ++j) - { - if (m_ptr[i+j] != lpsz[j]) goto bad; - } - return i; -bad:; - } - return -1; + std::size_t pos = m_str.rfind(lpsz); + return pos != std::string::npos ? pos : -1; } void CBotString::MakeUpper() { - for (size_t i = 0; static_cast(i) < m_lg && static_cast(i) < 1999 ; ++i) - { - char c = m_ptr[i]; - if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A'; - } + boost::to_upper(m_str); } void CBotString::MakeLower() { - for (size_t i = 0; static_cast(i) < m_lg && static_cast(i) < 1999 ; ++i) - { - char c = m_ptr[i]; - if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a'; - } + boost::to_lower(m_str); } bool CBotString::LoadString(unsigned int id) { - const char * str = nullptr; - str = MapIdToString(static_cast(id)); - if (m_ptr != nullptr) - delete[] m_ptr; - - m_lg = strlen(str); - m_ptr = nullptr; - if (m_lg > 0) - { - m_ptr = new char[m_lg+1]; - strcpy(m_ptr, str); - return true; - } - return false; + m_str = MapIdToString(static_cast(id)); + return !m_str.empty(); } const CBotString& CBotString::operator=(const CBotString& stringSrc) { - delete[] m_ptr; - m_ptr = nullptr; - - m_lg = stringSrc.m_lg; - - if (m_lg > 0) - { - m_ptr = new char[m_lg+1]; - strcpy(m_ptr, stringSrc.m_ptr); - } - + m_str = stringSrc.m_str; return *this; } @@ -342,174 +224,114 @@ CBotString CBotString::operator+(const CBotString& stringSrc) const CBotString& CBotString::operator=(const char ch) { - delete[] m_ptr; - - m_lg = 1; - - m_ptr = new char[2]; - m_ptr[0] = ch; - m_ptr[1] = 0; - + m_str = ch; return *this; } const CBotString& CBotString::operator=(const char* pString) { - delete[] m_ptr; - m_ptr = nullptr; - if (pString != nullptr) - { - m_lg = strlen(pString); - - if (m_lg != 0) - { - m_ptr = new char[m_lg+1]; - strcpy(m_ptr, pString); - } - } - + m_str = pString; + else + m_str.clear(); return *this; } const CBotString& CBotString::operator+=(const char ch) { - char* p = new char[m_lg+2]; - - if (m_ptr != nullptr) strcpy(p, m_ptr); - p[m_lg++] = ch; - p[m_lg] = 0; - - delete[] m_ptr; - - m_ptr = p; - + m_str += ch; return *this; } const CBotString& CBotString::operator+=(const CBotString& str) { - char* p = new char[m_lg+str.m_lg+1]; - - //-- Check if the pointer is not null befor trying to copy it - if(m_ptr != nullptr) - { - strcpy(p, m_ptr); - } - - char* pp = p + m_lg; - - //-- Check if the pointer is not null befor trying to copy it - if(str.m_ptr != nullptr) - { - strcpy(pp, str.m_ptr); - } - - m_lg = m_lg + str.m_lg; - - delete[] m_ptr; - - m_ptr = p; - + m_str += str.m_str; return *this; } bool CBotString::operator==(const CBotString& str) { - return Compare(str) == 0; + return m_str == str.m_str; } bool CBotString::operator==(const char* p) { - return Compare(p) == 0; + return m_str == p; } bool CBotString::operator!=(const CBotString& str) { - return Compare(str) != 0; + return m_str != str.m_str; } bool CBotString::operator!=(const char* p) { - return Compare(p) != 0; + return m_str != p; } bool CBotString::operator>(const CBotString& str) { - return Compare(str) > 0; + return m_str > str.m_str; } bool CBotString::operator>(const char* p) { - return Compare(p) > 0; + return m_str > p; } bool CBotString::operator>=(const CBotString& str) { - return Compare(str) >= 0; + return m_str >= str.m_str; } bool CBotString::operator>=(const char* p) { - return Compare(p) >= 0; + return m_str >= p; } bool CBotString::operator<(const CBotString& str) { - return Compare(str) < 0; + return m_str < str.m_str; } bool CBotString::operator<(const char* p) { - return Compare(p) < 0; + return m_str < p; } bool CBotString::operator<=(const CBotString& str) { - return Compare(str) <= 0; + return m_str <= str.m_str; } bool CBotString::operator<=(const char* p) { - return Compare(p) <= 0; + return m_str <= p; } bool CBotString::IsEmpty() const { - return (m_lg == 0); + return m_str.empty(); } void CBotString::Empty() { - delete[] m_ptr; - m_ptr = nullptr; - m_lg = 0; + m_str.clear(); } -static char emptyString[] = {0}; +static char emptyString[] = ""; CBotString::operator const char * () const { - if (this == nullptr || m_ptr == nullptr) return emptyString; - return m_ptr; + if (this == nullptr) return emptyString; // TODO: can this be removed? + return m_str.c_str(); } const char* CBotString::CStr() const { - if (this == nullptr || m_ptr == nullptr) - { - return emptyString; - } - return m_ptr; -} - -int CBotString::Compare(const char * lpsz) const -{ - char* p = m_ptr; - if (lpsz == nullptr) lpsz = emptyString; - if (m_ptr == nullptr) p = emptyString; - return strcmp(p, lpsz); // wcscmp + if (this == nullptr) return emptyString; // TODO: can this be removed? + return m_str.c_str(); } const char * CBotString::MapIdToString(EID id) diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h index 3d87d2c0..1628e07e 100644 --- a/src/CBot/CBotString.h +++ b/src/CBot/CBotString.h @@ -31,13 +31,14 @@ /** * \brief CBotString Class used to work on strings + * TODO: do not use this class, code should be refactored to use std::string instead */ class CBotString { public: /** - * \brief CBotString Default constructor. + * \brief CBotString Creates an empty string */ CBotString(); @@ -47,6 +48,12 @@ public: */ CBotString(const char* p); + /** + * \brief CBotString + * \param p + */ + CBotString(const std::string& p); + /** * \brief CBotString * \param p @@ -145,15 +152,6 @@ public: */ CBotString Right(int nCount) const; - /** - * \brief Compare Compare a given string to an other. - * \param lpsz The string to compare. - * \return 0 if the two string matches. Less than 0 if the current - * string is less than lpsz. Greater than 0 if the current - * string is greater than lpsz. - */ - int Compare(const char* lpsz) const; - /** * \brief MakeUpper Uppercase the string. */ @@ -198,11 +196,8 @@ public: private: - //! \brief Pointer to string - char* m_ptr; - - //! \brief Length of the string - int m_lg; + //! \brief String + std::string m_str; //! \brief Keeps the string corresponding to keyword ID static const std::map s_keywordString; diff --git a/src/CBot/CBotStringArray.cpp b/src/CBot/CBotStringArray.cpp index add32492..759aa6ae 100644 --- a/src/CBot/CBotStringArray.cpp +++ b/src/CBot/CBotStringArray.cpp @@ -17,112 +17,35 @@ * along with this program. If not, see http://gnu.org/licenses */ -// Modules inlcude #include "CBot/CBotStringArray.h" -#include "CBot/CBotUtils.h" - -// Local include - -// Global include - -// Forward declaration -#include - //////////////////////////////////////////////////////////////////////////////// CBotStringArray::CBotStringArray() { - m_pData = nullptr; - m_nSize = m_nMaxSize = 0; } //////////////////////////////////////////////////////////////////////////////// CBotStringArray::~CBotStringArray() { - SetSize(0); // destroys data ! + m_data.clear(); // destroys data ! } //////////////////////////////////////////////////////////////////////////////// int CBotStringArray::GetSize() { - return m_nSize; + return m_data.size(); } //////////////////////////////////////////////////////////////////////////////// void CBotStringArray::Add(const CBotString& str) { - SetSize(m_nSize+1); - - m_pData[m_nSize-1] = str; + m_data.push_back(str); } //////////////////////////////////////////////////////////////////////////////// void CBotStringArray::SetSize(int nNewSize) { - if (nNewSize == 0) - { - // shrink to nothing - - DestructElements(m_pData, m_nSize); - delete[] reinterpret_cast(m_pData); - m_pData = nullptr; - m_nSize = m_nMaxSize = 0; - } - else if (m_pData == nullptr) - { - // create one with exact size - m_pData = reinterpret_cast (new unsigned char[nNewSize * sizeof(CBotString)]); - - ConstructElements(m_pData, nNewSize); - - m_nSize = m_nMaxSize = nNewSize; - } - else if (nNewSize <= m_nMaxSize) - { - // it fits - if (nNewSize > m_nSize) - { - // initialize the new elements - - ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize); - - } - - else if (m_nSize > nNewSize) // destroy the old elements - DestructElements(&m_pData[nNewSize], m_nSize-nNewSize); - - m_nSize = nNewSize; - } - else - { - // otherwise, grow array - int nGrowBy; - { - // heuristically determine growth when nGrowBy == 0 - // (this avoids heap fragmentation in many situations) - nGrowBy = std::min(1024, std::max(4, m_nSize / 8)); - } - int nNewMax; - if (nNewSize < m_nMaxSize + nGrowBy) - nNewMax = m_nMaxSize + nGrowBy; // granularity - else - nNewMax = nNewSize; // no slush - - CBotString* pNewData = reinterpret_cast (new unsigned char[nNewMax * sizeof(CBotString)]); - - // copy new data from old - memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); - - // construct remaining elements - ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize); - - - // Get rid of old stuff (note: no destructors called) - delete[] reinterpret_cast(m_pData); - m_pData = pNewData; - m_nSize = nNewSize; - m_nMaxSize = nNewMax; - } + m_data.resize(nNewSize); } //////////////////////////////////////////////////////////////////////////////// @@ -134,5 +57,5 @@ CBotString& CBotStringArray::operator[](int nIndex) //////////////////////////////////////////////////////////////////////////////// CBotString& CBotStringArray::ElementAt(int nIndex) { - return m_pData[nIndex]; + return m_data[nIndex]; } diff --git a/src/CBot/CBotStringArray.h b/src/CBot/CBotStringArray.h index af4e9eff..fb755bec 100644 --- a/src/CBot/CBotStringArray.h +++ b/src/CBot/CBotStringArray.h @@ -19,15 +19,13 @@ #pragma once -// Modules inlcude #include "CBot/CBotString.h" -// Local include - -// Global include +#include /*! * \brief The CBotStringArray class Class used to arrays of strings management. + * TODO: refactor code to use std::vector instead */ class CBotStringArray : public CBotString { @@ -77,9 +75,5 @@ public: private: - //! Number of elements. - int m_nSize; - //! Reserved size. - int m_nMaxSize; - CBotString* m_pData; + std::vector m_data; }; diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp index 3e6b6da0..c058cfd6 100644 --- a/test/unit/CBot/CBotString_test.cpp +++ b/test/unit/CBot/CBotString_test.cpp @@ -159,22 +159,6 @@ TEST(CBotString_Test, Right) EXPECT_STREQ(str1.Right(7).CStr(), "Colobot"); } -/** - * @brief CBotString_Test.Compare Check Compare function of class - * CBotString_Test - */ -TEST(CBotString_Test, Compare) -{ - CBotString str1("colobot"); - EXPECT_EQ(0, str1.Compare("colobot")); - - CBotString str2("a"); - EXPECT_GT(0, str2.Compare("colobot")); - - CBotString str3("z"); - EXPECT_LT(0, str3.Compare("colobot")); -} - /** * @brief CBotString_Test.MakeUpper Check MakeUpper function of class * CBotString_Test From 6832c914963ac9307fc17d494abd6bca4946d07b Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 14:28:38 +0100 Subject: [PATCH 152/360] Fixed #695 --- src/level/robotmain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 51107497..59265711 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -2200,8 +2200,8 @@ void CRobotMain::HelpObject() CObject* obj = GetSelect(); if (obj == nullptr) return; - const char* filename = GetHelpFilename(obj->GetType()).c_str(); - if (filename[0] == 0) return; + std::string filename = GetHelpFilename(obj->GetType()); + if (filename.empty()) return; StartDisplayInfo(filename, -1); } From 3eeab0f9b788e66a299bcf19a99b6ec0df8648de Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 14:49:30 +0100 Subject: [PATCH 153/360] Removed CBotStringArray --- src/CBot/CBot.h | 1 - src/CBot/CBotInstr/CBotInstr.cpp | 6 +-- src/CBot/CBotInstr/CBotInstr.h | 8 +--- src/CBot/CBotProgram.cpp | 6 +-- src/CBot/CBotProgram.h | 4 +- src/CBot/CBotStringArray.cpp | 61 ------------------------ src/CBot/CBotStringArray.h | 79 -------------------------------- src/CBot/CBotToken.cpp | 24 +++++----- src/CBot/CBotToken.h | 11 ++--- src/CBot/CMakeLists.txt | 1 - src/script/script.cpp | 8 ++-- test/cbot/console/main.cpp | 7 ++- 12 files changed, 33 insertions(+), 183 deletions(-) delete mode 100644 src/CBot/CBotStringArray.cpp delete mode 100644 src/CBot/CBotStringArray.h diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index d0f42f1f..7832144c 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -26,7 +26,6 @@ // Modules inlcude #include "CBot/CBotFileUtils.h" #include "CBot/CBotString.h" -#include "CBot/CBotStringArray.h" #include "CBot/CBotClass.h" #include "CBot/CBotToken.h" #include "CBot/CBotProgram.h" diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp index 9d6aac32..66aff75d 100644 --- a/src/CBot/CBotInstr/CBotInstr.cpp +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -50,7 +50,7 @@ //////////////////////////////////////////////////////////////////////////////// int CBotInstr::m_LoopLvl = 0; -CBotStringArray CBotInstr::m_labelLvl = CBotStringArray(); +std::vector CBotInstr::m_labelLvl = std::vector(); //////////////////////////////////////////////////////////////////////////////// CBotInstr::CBotInstr() @@ -74,7 +74,7 @@ CBotInstr::~CBotInstr() //////////////////////////////////////////////////////////////////////////////// void CBotInstr::IncLvl(CBotString& label) { - m_labelLvl.SetSize(m_LoopLvl+1); + m_labelLvl.resize(m_LoopLvl+1); m_labelLvl[m_LoopLvl] = label; m_LoopLvl++; } @@ -82,7 +82,7 @@ void CBotInstr::IncLvl(CBotString& label) //////////////////////////////////////////////////////////////////////////////// void CBotInstr::IncLvl() { - m_labelLvl.SetSize(m_LoopLvl+1); + m_labelLvl.resize(m_LoopLvl+1); m_labelLvl[m_LoopLvl] = "#SWITCH"; m_LoopLvl++; } diff --git a/src/CBot/CBotInstr/CBotInstr.h b/src/CBot/CBotInstr/CBotInstr.h index acf36781..9ed637c8 100644 --- a/src/CBot/CBotInstr/CBotInstr.h +++ b/src/CBot/CBotInstr/CBotInstr.h @@ -19,14 +19,10 @@ #pragma once -// Modules inlcude #include "CBot/CBotToken.h" - #include "CBot/CBotCStack.h" -// Local include - -// Global include +#include /* for example, the following program @@ -262,5 +258,5 @@ protected: private: //! List of labels used. - static CBotStringArray m_labelLvl; + static std::vector m_labelLvl; }; diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index e2058a80..5ad91194 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -80,7 +80,7 @@ CBotProgram::~CBotProgram() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, void* pUser ) +bool CBotProgram::Compile( const char* program, std::vector& ListFonctions, void* pUser ) { int error = 0; Stop(); @@ -91,7 +91,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, m_pClass = nullptr; delete m_Prog; m_Prog= nullptr; - ListFonctions.SetSize(0); + ListFonctions.clear(); m_ErrorCode = 0; // transforms the program in Tokens @@ -152,7 +152,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, { m_bCompileClass = false; CBotFunction::Compile(p, pStack, next); - if (next->IsExtern()) ListFonctions.Add(next->GetName()/* + next->GetParams()*/); + if (next->IsExtern()) ListFonctions.push_back(next->GetName()/* + next->GetParams()*/); next->m_pProg = this; // keeps pointers to the module next = next->Next(); } diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 98854b33..26aeb688 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -22,13 +22,13 @@ // Modules inlcude #include "CBot/CBotTypResult.h" #include "CBot/CBotString.h" -#include "CBot/CBotStringArray.h" #include "CBot/CBotEnums.h" // Local include // Global include +#include // Forward declaration class CBotFunction; @@ -84,7 +84,7 @@ public: * \return false if an error at compile. * \see GetCompileError() to retrieve the error. */ - bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = nullptr); + bool Compile( const char* program, std::vector& ListFonctions, void* pUser = nullptr); /*! * \brief SetIdent Associates an identifier with the instance CBotProgram. diff --git a/src/CBot/CBotStringArray.cpp b/src/CBot/CBotStringArray.cpp deleted file mode 100644 index 759aa6ae..00000000 --- a/src/CBot/CBotStringArray.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -#include "CBot/CBotStringArray.h" - -//////////////////////////////////////////////////////////////////////////////// -CBotStringArray::CBotStringArray() -{ -} - -//////////////////////////////////////////////////////////////////////////////// -CBotStringArray::~CBotStringArray() -{ - m_data.clear(); // destroys data ! -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotStringArray::GetSize() -{ - return m_data.size(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotStringArray::Add(const CBotString& str) -{ - m_data.push_back(str); -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotStringArray::SetSize(int nNewSize) -{ - m_data.resize(nNewSize); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotString& CBotStringArray::operator[](int nIndex) -{ - return ElementAt(nIndex); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotString& CBotStringArray::ElementAt(int nIndex) -{ - return m_data[nIndex]; -} diff --git a/src/CBot/CBotStringArray.h b/src/CBot/CBotStringArray.h deleted file mode 100644 index fb755bec..00000000 --- a/src/CBot/CBotStringArray.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -#pragma once - -#include "CBot/CBotString.h" - -#include - -/*! - * \brief The CBotStringArray class Class used to arrays of strings management. - * TODO: refactor code to use std::vector instead - */ -class CBotStringArray : public CBotString -{ -public: - - /*! - * \brief CBotStringArray - */ - CBotStringArray(); - - /*! - * \brief ~CBotStringArray - */ - ~CBotStringArray(); - - /*! - * \brief SetSize Set the array size. - * \param nb - */ - void SetSize(int nb); - - /*! - * \brief GetSize - * \return - */ - int GetSize(); - - /*! - * \brief Add - * \param str - */ - void Add(const CBotString& str); - - /*! - * \brief operator [] - * \param nIndex - * \return - */ - CBotString& operator[](int nIndex); - - /*! - * \brief ElementAt - * \param nIndex - * \return - */ - CBotString& ElementAt(int nIndex); - -private: - - std::vector m_data; -}; diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index 6b34d688..e1465ad1 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -26,9 +26,9 @@ #include //////////////////////////////////////////////////////////////////////////////// -CBotStringArray CBotToken::m_ListKeyWords; +std::vector CBotToken::m_ListKeyWords; int CBotToken::m_ListIdKeyWords[200]; -CBotStringArray CBotToken::m_ListKeyDefine; +std::vector CBotToken::m_ListKeyDefine; long CBotToken::m_ListKeyNums[MAXDEFNUM]; //////////////////////////////////////////////////////////////////////////////// @@ -104,7 +104,7 @@ CBotToken::~CBotToken() //////////////////////////////////////////////////////////////////////////////// void CBotToken::Free() { - m_ListKeyDefine.SetSize(0); + m_ListKeyDefine.clear(); } //////////////////////////////////////////////////////////////////////////////// @@ -438,12 +438,12 @@ void CBotToken::Delete(CBotToken* pToken) int CBotToken::GetKeyWords(const char* w) { int i; - int l = m_ListKeyWords.GetSize(); + int l = m_ListKeyWords.size(); if (l == 0) { LoadKeyWords(); // takes the list for the first time - l = m_ListKeyWords.GetSize(); + l = m_ListKeyWords.size(); } for (i = 0; i < l; i++) @@ -458,7 +458,7 @@ int CBotToken::GetKeyWords(const char* w) bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) { int i; - int l = m_ListKeyDefine.GetSize(); + int l = m_ListKeyDefine.size(); for (i = 0; i < l; i++) { @@ -482,14 +482,14 @@ void CBotToken::LoadKeyWords() i = TokenKeyWord; //start with keywords of the language while (s.LoadString(i)) { - m_ListKeyWords.Add(s); + m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyDeclare; //keywords of declarations while (s.LoadString(i)) { - m_ListKeyWords.Add(s); + m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } @@ -497,14 +497,14 @@ void CBotToken::LoadKeyWords() i = TokenKeyVal; //keywords of values while (s.LoadString(i)) { - m_ListKeyWords.Add(s); + m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyOp; //operators while (s.LoadString(i)) { - m_ListKeyWords.Add(s); + m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } } @@ -513,7 +513,7 @@ void CBotToken::LoadKeyWords() bool CBotToken::DefineNum(const char* name, long val) { int i; - int l = m_ListKeyDefine.GetSize(); + int l = m_ListKeyDefine.size(); for (i = 0; i < l; i++) { @@ -521,7 +521,7 @@ bool CBotToken::DefineNum(const char* name, long val) } if ( i == MAXDEFNUM ) return false; - m_ListKeyDefine.Add( name ); + m_ListKeyDefine.push_back( name ); m_ListKeyNums[i] = val; return true; } diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index 12be45cd..1dbe39b2 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -19,12 +19,9 @@ #pragma once -// Modules inlcude -#include "CBot/CBotStringArray.h" +#include "CBot/CBotString.h" -// Local include - -// Global include +#include ///////////////////////////////////////////////////////////////////////////////////// // Token management (tokens) @@ -248,7 +245,7 @@ private: static void LoadKeyWords(); //! List of keywords of the CBot language (if, +, for, while, case, extern ...) - static CBotStringArray m_ListKeyWords; + static std::vector m_ListKeyWords; //! List of id correponding to the keywords of the CBot language static int m_ListIdKeyWords[200]; @@ -256,7 +253,7 @@ private: //! This keywords are defined in : //! - void CScriptFunctions::Init() //! - void CBotProgram::Init() - static CBotStringArray m_ListKeyDefine; + static std::vector m_ListKeyDefine; //! List of id correponding to the defined words static long m_ListKeyNums[MAXDEFNUM]; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index b38ff615..33e47afe 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -10,7 +10,6 @@ set(SOURCES CBotCall.cpp CBotDefParam.cpp CBotCallMethode.cpp - CBotStringArray.cpp CBotTypResult.cpp StringFunctions.cpp CBotInstr/CBotInstr.cpp diff --git a/src/script/script.cpp b/src/script/script.cpp index 5908d43b..42d2fd63 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -228,7 +228,7 @@ bool CScript::CheckToken() bool CScript::Compile() { - CBotStringArray liste; + std::vector functionList; int i; const char* p; @@ -250,16 +250,16 @@ bool CScript::Compile() m_botProg = MakeUnique(m_object->GetBotVar()); } - if ( m_botProg->Compile(m_script.get(), liste, this) ) + if ( m_botProg->Compile(m_script.get(), functionList, this) ) { - if ( liste.GetSize() == 0 ) + if (functionList.empty()) { strcpy(m_title, ""); m_mainFunction[0] = 0; } else { - p = liste[0]; + p = functionList[0]; i = 0; bool titleDone = false; while ( true ) diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp index 54ea1690..721105a7 100644 --- a/test/cbot/console/main.cpp +++ b/test/cbot/console/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) CBotProgram::AddFunction("message", rMessage, cMessage); // Compile the program - CBotStringArray externFunctions; + std::vector externFunctions; std::unique_ptr program{new CBotProgram(nullptr)}; if (!program->Compile(code.c_str(), externFunctions, nullptr)) { @@ -57,15 +57,14 @@ int main(int argc, char* argv[]) } // Execute all compiled functions marked as "extern" - if (externFunctions.GetSize() == 0) + if (externFunctions.empty()) { std::cerr << "NO EXTERN FUNCTIONS FOUND"; return 2; } bool runErrors = false; - for (int i = 0; i < externFunctions.GetSize(); i++) + for (const char* func : externFunctions) { - const char* func = externFunctions[i]; if (!program->Start(func)) { std::cerr << "FAILED TO START: " << func << std::endl; From 87a34ba1ff595812c9248736b7b595dbd57ed7de Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 15:06:35 +0100 Subject: [PATCH 154/360] Refactor CBotString::LoadString --- src/CBot/CBotKeywordStrings.cpp | 109 ++++++++++++++++++++++ src/CBot/CBotKeywordStrings.h | 10 ++ src/CBot/CBotProgram.cpp | 4 +- src/CBot/CBotString.cpp | 111 ---------------------- src/CBot/CBotString.h | 17 ---- src/CBot/CBotToken.cpp | 9 +- src/CBot/CBotVar/CBotVarBoolean.cpp | 8 +- src/CBot/CBotVar/CBotVarFloat.cpp | 8 +- src/CBot/CBotVar/CBotVarInt.cpp | 9 +- src/CBot/CBotVar/CBotVarString.cpp | 11 +-- src/CBot/CMakeLists.txt | 138 ++++++++++++++-------------- 11 files changed, 208 insertions(+), 226 deletions(-) create mode 100644 src/CBot/CBotKeywordStrings.cpp create mode 100644 src/CBot/CBotKeywordStrings.h diff --git a/src/CBot/CBotKeywordStrings.cpp b/src/CBot/CBotKeywordStrings.cpp new file mode 100644 index 00000000..e1a45fa5 --- /dev/null +++ b/src/CBot/CBotKeywordStrings.cpp @@ -0,0 +1,109 @@ +#include "CBot/CBotKeywordStrings.h" + +#include + +//! \brief Keeps the string corresponding to keyword ID +// Map is filled with id-string pars that are needed for CBot language parsing +static const std::map s_keywordString = { + {ID_IF, "if"}, + {ID_ELSE, "else"}, + {ID_WHILE, "while"}, + {ID_DO, "do"}, + {ID_FOR, "for"}, + {ID_BREAK, "break"}, + {ID_CONTINUE, "continue"}, + {ID_SWITCH, "switch"}, + {ID_CASE, "case"}, + {ID_DEFAULT, "default"}, + {ID_TRY, "try"}, + {ID_THROW, "throw"}, + {ID_CATCH, "catch"}, + {ID_FINALLY, "finally"}, + {ID_TXT_AND, "and"}, + {ID_TXT_OR, "or"}, + {ID_TXT_NOT, "not"}, + {ID_RETURN, "return"}, + {ID_CLASS, "class"}, + {ID_EXTENDS, "extends"}, + {ID_SYNCHO, "synchronized"}, + {ID_NEW, "new"}, + {ID_PUBLIC, "public"}, + {ID_EXTERN, "extern"}, + {ID_STATIC, "static"}, + {ID_PROTECTED, "protected"}, + {ID_PRIVATE, "private"}, + {ID_INT, "int"}, + {ID_FLOAT, "float"}, + {ID_BOOLEAN, "boolean"}, + {ID_STRING, "string"}, + {ID_VOID, "void"}, + {ID_BOOL, "bool"}, + {ID_TRUE, "true"}, + {ID_FALSE, "false"}, + {ID_NULL, "null"}, + {ID_NAN, "nan"}, + {ID_OPENPAR, "("}, + {ID_CLOSEPAR, ")"}, + {ID_OPBLK, "{"}, + {ID_CLBLK, "}"}, + {ID_SEP, ";"}, + {ID_COMMA, ","}, + {ID_DOTS, ":"}, + {ID_DOT, "."}, + {ID_OPBRK, "["}, + {ID_CLBRK, "]"}, + {ID_DBLDOTS, "::"}, + {ID_LOGIC, "?"}, + {ID_ADD, "+"}, + {ID_SUB, "-"}, + {ID_MUL, "*"}, + {ID_DIV, "/"}, + {ID_ASS, "="}, + {ID_ASSADD, "+="}, + {ID_ASSSUB, "-="}, + {ID_ASSMUL, "*="}, + {ID_ASSDIV, "/="}, + {ID_ASSOR, "|="}, + {ID_ASSAND, "&="}, + {ID_ASSXOR, "^="}, + {ID_ASSSL, "<<="}, + {ID_ASSSR, ">>>="}, + {ID_ASSASR, ">>="}, + {ID_SL, "<<"}, + {ID_SR, ">>"}, + {ID_ASR, ">>"}, + {ID_INC, "++"}, + {ID_DEC, "--"}, + {ID_LO, "<"}, + {ID_HI, ">"}, + {ID_LS, "<="}, + {ID_HS, ">="}, + {ID_EQ, "=="}, + {ID_NE, "!="}, + {ID_AND, "&"}, + {ID_XOR, "^"}, + {ID_OR, "|"}, + {ID_LOG_AND, "&&"}, + {ID_LOG_OR, "||"}, + {ID_LOG_NOT, "!"}, + {ID_NOT, "~"}, + {ID_MODULO, "%"}, + {ID_POWER, "**"}, + {ID_ASSMODULO, "%="}, + {TX_UNDEF, "undefined"}, + {TX_NAN, "not a number"} +}; + +static const char emptyString[] = ""; + +const char* LoadString(EID id) +{ + if (s_keywordString.find(id) != s_keywordString.end()) + { + return s_keywordString.at(id); + } + else + { + return emptyString; + } +} \ No newline at end of file diff --git a/src/CBot/CBotKeywordStrings.h b/src/CBot/CBotKeywordStrings.h new file mode 100644 index 00000000..b328b787 --- /dev/null +++ b/src/CBot/CBotKeywordStrings.h @@ -0,0 +1,10 @@ +#pragma once + +#include "CBotEnums.h" + +/** + * \brief LoadString Maps given ID to its string equivalent. + * \param id Provided identifier. + * \return String if found, else NullString. + */ +const char* LoadString(EID id); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 5ad91194..80c93276 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -30,6 +30,7 @@ #include "CBot/CBotInstr/CBotFunction.h" #include "StringFunctions.h" +#include "CBotKeywordStrings.h" // Local include @@ -357,9 +358,8 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) //////////////////////////////////////////////////////////////////////////////// CBotString CBotProgram::GetErrorText(int code) { - CBotString TextError; + CBotString TextError = LoadString(static_cast(code)); - TextError.LoadString( code ); if (TextError.IsEmpty()) { char buf[100]; diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index fc1cefd8..2459f39c 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -21,104 +21,11 @@ #include "CBot/CBotString.h" -//strings management #include #include #include #include -//Map is filled with id-string pars that are needed for CBot language parsing -const std::map CBotString::s_keywordString = -{ - {ID_IF, "if"}, - {ID_ELSE, "else"}, - {ID_WHILE, "while"}, - {ID_DO, "do"}, - {ID_FOR, "for"}, - {ID_BREAK, "break"}, - {ID_CONTINUE, "continue"}, - {ID_SWITCH, "switch"}, - {ID_CASE, "case"}, - {ID_DEFAULT, "default"}, - {ID_TRY, "try"}, - {ID_THROW, "throw"}, - {ID_CATCH, "catch"}, - {ID_FINALLY, "finally"}, - {ID_TXT_AND, "and"}, - {ID_TXT_OR, "or"}, - {ID_TXT_NOT, "not"}, - {ID_RETURN, "return"}, - {ID_CLASS, "class"}, - {ID_EXTENDS, "extends"}, - {ID_SYNCHO, "synchronized"}, - {ID_NEW, "new"}, - {ID_PUBLIC, "public"}, - {ID_EXTERN, "extern"}, - {ID_STATIC, "static"}, - {ID_PROTECTED, "protected"}, - {ID_PRIVATE, "private"}, - {ID_INT, "int"}, - {ID_FLOAT, "float"}, - {ID_BOOLEAN, "boolean"}, - {ID_STRING, "string"}, - {ID_VOID, "void"}, - {ID_BOOL, "bool"}, - {ID_TRUE, "true"}, - {ID_FALSE, "false"}, - {ID_NULL, "null"}, - {ID_NAN, "nan"}, - {ID_OPENPAR, "("}, - {ID_CLOSEPAR, ")"}, - {ID_OPBLK, "{"}, - {ID_CLBLK, "}"}, - {ID_SEP, ";"}, - {ID_COMMA, ","}, - {ID_DOTS, ":"}, - {ID_DOT, "."}, - {ID_OPBRK, "["}, - {ID_CLBRK, "]"}, - {ID_DBLDOTS, "::"}, - {ID_LOGIC, "?"}, - {ID_ADD, "+"}, - {ID_SUB, "-"}, - {ID_MUL, "*"}, - {ID_DIV, "/"}, - {ID_ASS, "="}, - {ID_ASSADD, "+="}, - {ID_ASSSUB, "-="}, - {ID_ASSMUL, "*="}, - {ID_ASSDIV, "/="}, - {ID_ASSOR, "|="}, - {ID_ASSAND, "&="}, - {ID_ASSXOR, "^="}, - {ID_ASSSL, "<<="}, - {ID_ASSSR, ">>>="}, - {ID_ASSASR, ">>="}, - {ID_SL, "<<"}, - {ID_SR, ">>"}, - {ID_ASR, ">>"}, - {ID_INC, "++"}, - {ID_DEC, "--"}, - {ID_LO, "<"}, - {ID_HI, ">"}, - {ID_LS, "<="}, - {ID_HS, ">="}, - {ID_EQ, "=="}, - {ID_NE, "!="}, - {ID_AND, "&"}, - {ID_XOR, "^"}, - {ID_OR, "|"}, - {ID_LOG_AND, "&&"}, - {ID_LOG_OR, "||"}, - {ID_LOG_NOT, "!"}, - {ID_NOT, "~"}, - {ID_MODULO, "%"}, - {ID_POWER, "**"}, - {ID_ASSMODULO, "%="}, - {TX_UNDEF, "undefined"}, - {TX_NAN, "not a number"} -}; - CBotString::CBotString() { m_str = ""; @@ -202,12 +109,6 @@ void CBotString::MakeLower() boost::to_lower(m_str); } -bool CBotString::LoadString(unsigned int id) -{ - m_str = MapIdToString(static_cast(id)); - return !m_str.empty(); -} - const CBotString& CBotString::operator=(const CBotString& stringSrc) { @@ -333,15 +234,3 @@ const char* CBotString::CStr() const if (this == nullptr) return emptyString; // TODO: can this be removed? return m_str.c_str(); } - -const char * CBotString::MapIdToString(EID id) -{ - if (s_keywordString.find(id) != s_keywordString.end()) - { - return s_keywordString.at(id); - } - else - { - return emptyString; - } -} diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h index 1628e07e..efe2d9d9 100644 --- a/src/CBot/CBotString.h +++ b/src/CBot/CBotString.h @@ -122,13 +122,6 @@ public: */ int ReverseFind(const char* lpsz); - /** - * \brief LoadString Load the string associate with the id. - * \param id The id to load. - * \return True if the id exist false otherwise. - */ - bool LoadString(unsigned int id); - /** * \brief Mid Return a part of a string from a starting index and until * the end of the string with a limited size. @@ -198,14 +191,4 @@ private: //! \brief String std::string m_str; - - //! \brief Keeps the string corresponding to keyword ID - static const std::map s_keywordString; - - /** - * \brief MapIdToString Maps given ID to its string equivalent. - * \param id Provided identifier. - * \return String if found, else NullString. - */ - static const char * MapIdToString(EID id); }; diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index e1465ad1..baef6977 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -19,6 +19,7 @@ // Modules inlcude #include "CBot/CBotToken.h" +#include "CBotKeywordStrings.h" // Local include @@ -480,14 +481,14 @@ void CBotToken::LoadKeyWords() int i, n = 0; i = TokenKeyWord; //start with keywords of the language - while (s.LoadString(i)) + while (!(s = LoadString(static_cast(i))).IsEmpty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyDeclare; //keywords of declarations - while (s.LoadString(i)) + while (!(s = LoadString(static_cast(i))).IsEmpty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; @@ -495,14 +496,14 @@ void CBotToken::LoadKeyWords() i = TokenKeyVal; //keywords of values - while (s.LoadString(i)) + while (!(s = LoadString(static_cast(i))).IsEmpty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyOp; //operators - while (s.LoadString(i)) + while (!(s = LoadString(static_cast(i))).IsEmpty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp index 2ae7e6b3..7a177e09 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.cpp +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -21,8 +21,8 @@ #include "CBot/CBotVar/CBotVarBoolean.h" #include "CBot/CBotEnums.h" - #include "CBot/CBotUtils.h" +#include "CBot/CBotKeywordStrings.h" // Local include @@ -98,16 +98,16 @@ CBotString CBotVarBoolean::GetValString() if ( m_binit == CBotVar::InitType::UNDEF ) { - res.LoadString(TX_UNDEF); + res = LoadString(TX_UNDEF); return res; } if ( m_binit == CBotVar::InitType::IS_NAN ) { - res.LoadString(TX_NAN); + res = LoadString(TX_NAN); return res; } - ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); + ret = LoadString( m_val > 0 ? ID_TRUE : ID_FALSE ); return ret; } diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index d23fca46..29dbdae4 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -21,8 +21,8 @@ #include "CBot/CBotVar/CBotVarFloat.h" #include "CBot/CBotEnums.h" - #include "CBot/CBotToken.h" +#include "CBot/CBotKeywordStrings.h" #include "CBot/CBotUtils.h" @@ -99,13 +99,11 @@ CBotString CBotVarFloat::GetValString() if ( m_binit == CBotVar::InitType::UNDEF ) { - res.LoadString(TX_UNDEF); - return res; + return LoadString(TX_UNDEF); } if ( m_binit == CBotVar::InitType::IS_NAN ) { - res.LoadString(TX_NAN); - return res; + return LoadString(TX_NAN); } char buffer[300]; diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index f584997f..52b9e5ce 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -21,10 +21,9 @@ #include "CBot/CBotVar/CBotVarInt.h" #include "CBot/CBotEnums.h" - #include "CBot/CBotToken.h" - #include "CBot/CBotUtils.h" +#include "CBot/CBotKeywordStrings.h" // Local include @@ -102,14 +101,12 @@ CBotString CBotVarInt::GetValString() if ( m_binit == CBotVar::InitType::UNDEF ) { - res.LoadString(TX_UNDEF); - return res; + return LoadString(TX_UNDEF); } if ( m_binit == CBotVar::InitType::IS_NAN ) { - res.LoadString(TX_NAN); - return res; + return LoadString(TX_NAN); } char buffer[300]; diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp index 25f39a6c..425733f5 100644 --- a/src/CBot/CBotVar/CBotVarString.cpp +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -21,10 +21,9 @@ #include "CBot/CBotVar/CBotVarString.h" #include "CBot/CBotEnums.h" - #include "CBot/CBotToken.h" - #include "CBot/CBotUtils.h" +#include "CBot/CBotKeywordStrings.h" // Local include @@ -77,15 +76,11 @@ CBotString CBotVarString::GetValString() { if ( m_binit == CBotVar::InitType::UNDEF ) { - CBotString res; - res.LoadString(TX_UNDEF); - return res; + return LoadString(TX_UNDEF); } if ( m_binit == CBotVar::InitType::IS_NAN ) { - CBotString res; - res.LoadString(TX_NAN); - return res; + return LoadString(TX_NAN); } return m_val; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 33e47afe..3f07eb5a 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,73 +1,73 @@ set(SOURCES - CBotUtils.cpp - CBotFileUtils.cpp - CBotClass.cpp - CBotProgram.cpp - CBotStack.cpp - CBotCStack.cpp - CBotString.cpp - CBotToken.cpp - CBotCall.cpp - CBotDefParam.cpp - CBotCallMethode.cpp - CBotTypResult.cpp - StringFunctions.cpp - CBotInstr/CBotInstr.cpp - CBotInstr/CBotInstrUtils.cpp - CBotInstr/CBotWhile.cpp - CBotInstr/CBotDo.cpp - CBotInstr/CBotFor.cpp - CBotInstr/CBotListExpression.cpp - CBotInstr/CBotSwitch.cpp - CBotInstr/CBotCase.cpp - CBotInstr/CBotBreak.cpp - CBotInstr/CBotTry.cpp - CBotInstr/CBotCatch.cpp - CBotInstr/CBotThrow.cpp - CBotInstr/CBotExprAlpha.cpp - CBotInstr/CBotExprNum.cpp - CBotInstr/CBotNew.cpp - CBotInstr/CBotExprNan.cpp - CBotInstr/CBotExprNull.cpp - CBotInstr/CBotExprBool.cpp - CBotInstr/CBotLeftExprVar.cpp - CBotInstr/CBotPreIncExpr.cpp - CBotInstr/CBotPostIncExpr.cpp - CBotInstr/CBotExprVar.cpp - CBotInstr/CBotInstrMethode.cpp - CBotInstr/CBotInstrCall.cpp - CBotInstr/CBotListInstr.cpp - CBotInstr/CBotBlock.cpp - CBotInstr/CBotExprUnaire.cpp - CBotInstr/CBotParExpr.cpp - CBotInstr/CBotBoolExpr.cpp - CBotInstr/CBotLogicExpr.cpp - CBotInstr/CBotTwoOpExpr.cpp - CBotInstr/CBotExpression.cpp - CBotInstr/CBotIndexExpr.cpp - CBotInstr/CBotFieldExpr.cpp - CBotInstr/CBotLeftExpr.cpp - CBotInstr/CBotCondition.cpp - CBotInstr/CBotClassInst.cpp - CBotInstr/CBotIString.cpp - CBotInstr/CBotFloat.cpp - CBotInstr/CBotBoolean.cpp - CBotInstr/CBotEmpty.cpp - CBotInstr/CBotReturn.cpp - CBotInstr/CBotIf.cpp - CBotInstr/CBotListArray.cpp - CBotInstr/CBotInstArray.cpp - CBotInstr/CBotInt.cpp - CBotInstr/CBotFunction.cpp - CBotVar/CBotVarArray.cpp - CBotVar/CBotVarPointer.cpp - CBotVar/CBotVarClass.cpp - CBotVar/CBotVarBoolean.cpp - CBotVar/CBotVarString.cpp - CBotVar/CBotVarFloat.cpp - CBotVar/CBotVarInt.cpp - CBotVar/CBotVar.cpp -) + CBotUtils.cpp + CBotFileUtils.cpp + CBotClass.cpp + CBotProgram.cpp + CBotStack.cpp + CBotCStack.cpp + CBotString.cpp + CBotToken.cpp + CBotCall.cpp + CBotDefParam.cpp + CBotCallMethode.cpp + CBotTypResult.cpp + StringFunctions.cpp + CBotInstr/CBotInstr.cpp + CBotInstr/CBotInstrUtils.cpp + CBotInstr/CBotWhile.cpp + CBotInstr/CBotDo.cpp + CBotInstr/CBotFor.cpp + CBotInstr/CBotListExpression.cpp + CBotInstr/CBotSwitch.cpp + CBotInstr/CBotCase.cpp + CBotInstr/CBotBreak.cpp + CBotInstr/CBotTry.cpp + CBotInstr/CBotCatch.cpp + CBotInstr/CBotThrow.cpp + CBotInstr/CBotExprAlpha.cpp + CBotInstr/CBotExprNum.cpp + CBotInstr/CBotNew.cpp + CBotInstr/CBotExprNan.cpp + CBotInstr/CBotExprNull.cpp + CBotInstr/CBotExprBool.cpp + CBotInstr/CBotLeftExprVar.cpp + CBotInstr/CBotPreIncExpr.cpp + CBotInstr/CBotPostIncExpr.cpp + CBotInstr/CBotExprVar.cpp + CBotInstr/CBotInstrMethode.cpp + CBotInstr/CBotInstrCall.cpp + CBotInstr/CBotListInstr.cpp + CBotInstr/CBotBlock.cpp + CBotInstr/CBotExprUnaire.cpp + CBotInstr/CBotParExpr.cpp + CBotInstr/CBotBoolExpr.cpp + CBotInstr/CBotLogicExpr.cpp + CBotInstr/CBotTwoOpExpr.cpp + CBotInstr/CBotExpression.cpp + CBotInstr/CBotIndexExpr.cpp + CBotInstr/CBotFieldExpr.cpp + CBotInstr/CBotLeftExpr.cpp + CBotInstr/CBotCondition.cpp + CBotInstr/CBotClassInst.cpp + CBotInstr/CBotIString.cpp + CBotInstr/CBotFloat.cpp + CBotInstr/CBotBoolean.cpp + CBotInstr/CBotEmpty.cpp + CBotInstr/CBotReturn.cpp + CBotInstr/CBotIf.cpp + CBotInstr/CBotListArray.cpp + CBotInstr/CBotInstArray.cpp + CBotInstr/CBotInt.cpp + CBotInstr/CBotFunction.cpp + CBotVar/CBotVarArray.cpp + CBotVar/CBotVarPointer.cpp + CBotVar/CBotVarClass.cpp + CBotVar/CBotVarBoolean.cpp + CBotVar/CBotVarString.cpp + CBotVar/CBotVarFloat.cpp + CBotVar/CBotVarInt.cpp + CBotVar/CBotVar.cpp + CBotKeywordStrings.cpp CBotKeywordStrings.h) # Includes set(LOCAL_INCLUDES From 9ec61d93e5a432e93f86666628cc084361d13089 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 16:19:10 +0100 Subject: [PATCH 155/360] Refactored CBotString and const char* to std::string in CBot engine A lot of changes, so it needs lots of testing --- src/CBot/CBot.h | 1 - src/CBot/CBotCStack.cpp | 6 +- src/CBot/CBotCStack.h | 1 + src/CBot/CBotCall.cpp | 22 +- src/CBot/CBotCall.h | 24 +- src/CBot/CBotCallMethode.cpp | 14 +- src/CBot/CBotCallMethode.h | 17 +- src/CBot/CBotClass.cpp | 48 ++-- src/CBot/CBotClass.h | 43 +-- src/CBot/CBotDefParam.cpp | 4 +- src/CBot/CBotDefParam.h | 4 +- src/CBot/CBotFileUtils.cpp | 7 +- src/CBot/CBotFileUtils.h | 6 +- src/CBot/CBotInstr/CBotBreak.cpp | 2 +- src/CBot/CBotInstr/CBotBreak.h | 2 +- src/CBot/CBotInstr/CBotClassInst.cpp | 8 +- src/CBot/CBotInstr/CBotDo.h | 2 +- src/CBot/CBotInstr/CBotExprAlpha.cpp | 4 +- src/CBot/CBotInstr/CBotExprNum.cpp | 8 +- src/CBot/CBotInstr/CBotFor.h | 2 +- src/CBot/CBotInstr/CBotFunction.cpp | 37 +-- src/CBot/CBotInstr/CBotFunction.h | 18 +- src/CBot/CBotInstr/CBotInstr.cpp | 16 +- src/CBot/CBotInstr/CBotInstr.h | 10 +- src/CBot/CBotInstr/CBotInstrMethode.h | 4 +- src/CBot/CBotInstr/CBotReturn.cpp | 2 +- src/CBot/CBotInstr/CBotWhile.h | 2 +- src/CBot/CBotKeywordStrings.cpp | 7 +- src/CBot/CBotKeywordStrings.h | 4 +- src/CBot/CBotProgram.cpp | 26 +- src/CBot/CBotProgram.h | 25 +- src/CBot/CBotStack.cpp | 33 +-- src/CBot/CBotStack.h | 16 +- src/CBot/CBotString.cpp | 236 --------------- src/CBot/CBotString.h | 194 ------------- src/CBot/CBotToken.cpp | 61 ++-- src/CBot/CBotToken.h | 32 +-- src/CBot/CBotTypResult.cpp | 2 +- src/CBot/CBotTypResult.h | 3 +- src/CBot/CBotUtils.cpp | 50 +--- src/CBot/CBotUtils.h | 42 +-- src/CBot/CBotVar/CBotVar.cpp | 25 +- src/CBot/CBotVar/CBotVar.h | 26 +- src/CBot/CBotVar/CBotVarArray.cpp | 4 +- src/CBot/CBotVar/CBotVarArray.h | 2 +- src/CBot/CBotVar/CBotVarBoolean.cpp | 8 +- src/CBot/CBotVar/CBotVarBoolean.h | 4 +- src/CBot/CBotVar/CBotVarClass.cpp | 12 +- src/CBot/CBotVar/CBotVarClass.h | 4 +- src/CBot/CBotVar/CBotVarFloat.cpp | 6 +- src/CBot/CBotVar/CBotVarFloat.h | 4 +- src/CBot/CBotVar/CBotVarInt.cpp | 22 +- src/CBot/CBotVar/CBotVarInt.h | 6 +- src/CBot/CBotVar/CBotVarPointer.cpp | 10 +- src/CBot/CBotVar/CBotVarPointer.h | 4 +- src/CBot/CBotVar/CBotVarString.cpp | 6 +- src/CBot/CBotVar/CBotVarString.h | 6 +- src/CBot/CMakeLists.txt | 4 +- src/CBot/StringFunctions.cpp | 38 +-- src/script/script.cpp | 50 ++-- src/script/scriptfunc.cpp | 72 ++--- test/cbot/console/main.cpp | 7 +- test/unit/CBot/CBotString_test.cpp | 399 -------------------------- test/unit/CMakeLists.txt | 1 - 64 files changed, 421 insertions(+), 1344 deletions(-) delete mode 100644 src/CBot/CBotString.cpp delete mode 100644 src/CBot/CBotString.h delete mode 100644 test/unit/CBot/CBotString_test.cpp diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 7832144c..4ba45b0e 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -25,7 +25,6 @@ // Modules inlcude #include "CBot/CBotFileUtils.h" -#include "CBot/CBotString.h" #include "CBot/CBotClass.h" #include "CBot/CBotToken.h" #include "CBot/CBotProgram.h" diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index ed56e22a..df1f5630 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -174,7 +174,7 @@ void CBotCStack::SetType(CBotTypResult& type) CBotVar* CBotCStack::FindVar(CBotToken* &pToken) { CBotCStack* p = this; - CBotString name = pToken->GetString(); + std::string name = pToken->GetString(); while (p != nullptr) { @@ -332,7 +332,7 @@ void CBotCStack::AddVar(CBotVar* pVar) bool CBotCStack::CheckVarLocal(CBotToken* &pToken) { CBotCStack* p = this; - CBotString name = pToken->GetString(); + std::string name = pToken->GetString(); while (p != nullptr) { @@ -373,7 +373,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId //////////////////////////////////////////////////////////////////////////////// bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) { - CBotString name = pToken->GetString(); + std::string name = pToken->GetString(); if ( CBotCall::CheckCall(name) ) return true; diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h index e6210f80..1bdfa90e 100644 --- a/src/CBot/CBotCStack.h +++ b/src/CBot/CBotCStack.h @@ -27,6 +27,7 @@ // Global include class CBotInstr; class CBotDefParam; +class CBotToken; /*! * \brief The CBotCStack class Management of the stack of compilation. diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 13f1e857..f391c3d3 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -40,9 +40,9 @@ CBotCall* CBotCall::m_ListCalls = nullptr; void* CBotCall::m_pUser = nullptr; //////////////////////////////////////////////////////////////////////////////// -CBotCall::CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) +CBotCall::CBotCall(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)) { m_name = name; m_rExec = rExec; @@ -65,9 +65,9 @@ void CBotCall::Free() } //////////////////////////////////////////////////////////////////////////////// -bool CBotCall::AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) +bool CBotCall::AddFunction(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)) { CBotCall* p = m_ListCalls; CBotCall* pp = nullptr; @@ -102,7 +102,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack* { nIdent = 0; CBotCall* pt = m_ListCalls; - CBotString name = p->GetString(); + std::string name = p->GetString(); while ( pt != nullptr ) { @@ -136,7 +136,7 @@ void CBotCall::SetPUser(void* pUser) } //////////////////////////////////////////////////////////////////////////////// -bool CBotCall::CheckCall(const char* name) +bool CBotCall::CheckCall(const std::string& name) { CBotCall* p = m_ListCalls; @@ -149,7 +149,7 @@ bool CBotCall::CheckCall(const char* name) } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotCall::GetName() +std::string CBotCall::GetName() { return m_name; } @@ -178,7 +178,7 @@ int CBotCall::DoCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* if ( token != nullptr ) { - CBotString name = token->GetString(); + std::string name = token->GetString(); while ( pt != nullptr ) { if ( pt->m_name == name ) @@ -260,7 +260,7 @@ bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBot CBotCall* pt = m_ListCalls; { - CBotString name = token->GetString(); + std::string name = token->GetString(); while ( pt != nullptr ) { if ( pt->m_name == name ) diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h index bb94c23e..3dcb3aae 100644 --- a/src/CBot/CBotCall.h +++ b/src/CBot/CBotCall.h @@ -20,14 +20,18 @@ #pragma once // Modules inlcude -#include "CBot/CBotString.h" // Local include // Global include +#include // Forward declaration class CBotStack; +class CBotCStack; +class CBotVar; +class CBotTypResult; +class CBotToken; #define STACKRUN 1 //! \def return execution directly on a suspended routine @@ -44,9 +48,9 @@ public: * \param rExec * \param rCompile */ - CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + CBotCall(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)); /*! * \brief ~CBotCall @@ -60,9 +64,9 @@ public: * \param rCompile * \return */ - static bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + static bool AddFunction(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)); /*! * \brief CompileCall Is acceptable by a call procedure name and given @@ -80,7 +84,7 @@ public: * \param name * \return */ - static bool CheckCall(const char* name); + static bool CheckCall(const std::string& name); /*! * \brief DoCall @@ -117,7 +121,7 @@ public: * \brief GetName * \return */ - CBotString GetName(); + std::string GetName(); /*! * \brief Next @@ -142,7 +146,7 @@ private: static void* m_pUser; long m_nFuncIdent; - CBotString m_name; + std::string m_name; bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser); CBotTypResult (*m_rComp) (CBotVar* &pVar, void* pUser); CBotCall* m_next; diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index d38da859..b3512f6e 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -32,9 +32,9 @@ //////////////////////////////////////////////////////////////////////////////// -CBotCallMethode::CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) +CBotCallMethode::CBotCallMethode(const std::string& name, + bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar)) { m_name = name; m_rExec = rExec; @@ -51,7 +51,7 @@ CBotCallMethode::~CBotCallMethode() } //////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotCallMethode::CompileCall(const char* name, +CBotTypResult CBotCallMethode::CompileCall(const std::string& name, CBotVar* pThis, CBotVar** ppVar, CBotCStack* pStack, @@ -82,7 +82,7 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name, } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotCallMethode::GetName() +std::string CBotCallMethode::GetName() { return m_name; } @@ -104,10 +104,10 @@ void CBotCallMethode::AddNext(CBotCallMethode* pt) //////////////////////////////////////////////////////////////////////////////// int CBotCallMethode::DoCall(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppVars, - CBotVar* &pResult, + CBotVar*& pResult, CBotStack* pStack, CBotToken* pToken) { diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h index 445e259a..bdccbb97 100644 --- a/src/CBot/CBotCallMethode.h +++ b/src/CBot/CBotCallMethode.h @@ -21,7 +21,6 @@ // Modules inlcude #include "CBot/CBotTypResult.h" -#include "CBot/CBotString.h" // Local include @@ -45,9 +44,9 @@ public: * \param rExec * \param rCompile */ - CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); + CBotCallMethode(const std::string& name, + bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar)); /*! * \brief ~CBotCallMethode @@ -64,7 +63,7 @@ public: * \param nIdent * \return */ - CBotTypResult CompileCall(const char* name, + CBotTypResult CompileCall(const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotCStack* pStack, @@ -82,10 +81,10 @@ public: * \return */ int DoCall(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppVars, - CBotVar* &pResult, + CBotVar*& pResult, CBotStack* pStack, CBotToken* pFunc); @@ -93,7 +92,7 @@ public: * \brief GetName * \return */ - CBotString GetName(); + std::string GetName(); /*! * \brief Next @@ -108,7 +107,7 @@ public: void AddNext(CBotCallMethode* p); private: - CBotString m_name; + std::string m_name; bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar); CBotCallMethode* m_next; diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 8e580bb6..e7d67191 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -46,7 +46,7 @@ CBotClass* CBotClass::m_ExClass = nullptr; //////////////////////////////////////////////////////////////////////////////// -CBotClass::CBotClass(const char* name, +CBotClass::CBotClass(const std::string& name, CBotClass* pPapa, bool bIntrinsic) { @@ -96,7 +96,7 @@ CBotClass::~CBotClass() } //////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotClass::Create(const char* name, +CBotClass* CBotClass::Create(const std::string& name, CBotClass* parent, bool intrinsic) { @@ -209,11 +209,11 @@ void CBotClass::FreeLock(CBotProgram* p) } //////////////////////////////////////////////////////////////////////////////// -bool CBotClass::AddItem(CBotString name, +bool CBotClass::AddItem(std::string name, CBotTypResult type, int mPrivate) { - CBotToken token(name, CBotString()); + CBotToken token(name, std::string()); CBotClass* pClass = type.GetClass(); CBotVar* pVar = CBotVar::Create( name, type ); @@ -255,7 +255,7 @@ void CBotClass::AddNext(CBotClass* pClass) } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotClass::GetName() +std::string CBotClass::GetName() { return m_name; } @@ -286,7 +286,7 @@ CBotVar* CBotClass::GetVar() } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotClass::GetItem(const char* name) +CBotVar* CBotClass::GetItem(const std::string& name) { CBotVar* p = m_pVar; @@ -326,7 +326,7 @@ CBotClass* CBotClass::Find(CBotToken* &pToken) } //////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotClass::Find(const char* name) +CBotClass* CBotClass::Find(const std::string& name) { CBotClass* p = m_ExClass; @@ -340,9 +340,9 @@ CBotClass* CBotClass::Find(const char* name) } //////////////////////////////////////////////////////////////////////////////// -bool CBotClass::AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) +bool CBotClass::AddFunction(const std::string& name, + bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar)) { // stores pointers to the two functions CBotCallMethode* p = m_pCalls; @@ -377,7 +377,7 @@ bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ) } //////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotClass::CompileMethode(const char* name, +CBotTypResult CBotClass::CompileMethode(const std::string& name, CBotVar* pThis, CBotVar** ppParams, CBotCStack* pStack, @@ -400,11 +400,11 @@ CBotTypResult CBotClass::CompileMethode(const char* name, //////////////////////////////////////////////////////////////////////////////// bool CBotClass::ExecuteMethode(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppParams, - CBotVar* &pResult, - CBotStack* &pStack, + CBotVar*& pResult, + CBotStack*& pStack, CBotToken* pToken) { int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken); @@ -424,10 +424,10 @@ bool CBotClass::ExecuteMethode(long& nIdent, //////////////////////////////////////////////////////////////////////////////// void CBotClass::RestoreMethode(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppParams, - CBotStack* &pStack) + CBotStack*& pStack) { m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this); } @@ -472,7 +472,7 @@ bool CBotClass::SaveStaticState(FILE* pf) //////////////////////////////////////////////////////////////////////////////// bool CBotClass::RestoreStaticState(FILE* pf) { - CBotString ClassName, VarName; + std::string ClassName, VarName; CBotClass* pClass; unsigned short w; @@ -511,7 +511,7 @@ bool CBotClass::RestoreStaticState(FILE* pf) bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) { - CBotString name = pToken->GetString(); + std::string name = pToken->GetString(); if ( CBotCall::CheckCall(name) ) return true; @@ -541,7 +541,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) if ( !IsOfType(p, ID_CLASS) ) return nullptr; - CBotString name = p->GetString(); + std::string name = p->GetString(); CBotClass* pOld = CBotClass::Find(name); if ( pOld != nullptr && pOld->m_IsDef ) @@ -556,7 +556,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) CBotClass* pPapa = nullptr; if ( IsOfType( p, ID_EXTENDS ) ) { - CBotString name = p->GetString(); + std::string name = p->GetString(); pPapa = CBotClass::Find(name); if (!IsOfType(p, TokenTypVar) || pPapa == nullptr ) @@ -680,7 +680,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) CBotCStack* pile = pStack->TokenStack(nullptr, true); // make "this" known - CBotToken TokenThis(CBotString("this"), CBotString()); + CBotToken TokenThis(std::string("this"), std::string()); CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) ); pThis->SetUniqNum(-2); pile->AddVar(pThis); @@ -688,7 +688,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( m_pParent ) { // makes "super" known - CBotToken TokenSuper(CBotString("super"), CBotString()); + CBotToken TokenSuper(std::string("super"), std::string()); CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) ); pThis->SetUniqNum(-3); pile->AddVar(pThis); @@ -796,7 +796,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; if ( !IsOfType(p, ID_CLASS) ) return nullptr; - CBotString name = p->GetString(); + std::string name = p->GetString(); // a name for the class is there? if (IsOfType(p, TokenTypVar)) @@ -807,7 +807,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) if ( IsOfType( p, ID_EXTENDS ) ) { // TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h - CBotString name = p->GetString(); + std::string name = p->GetString(); CBotClass* pPapa = CBotClass::Find(name); if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index 69f3605e..849a066f 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -24,11 +24,10 @@ #include "CBot/CBotTypResult.h" -#include "CBot/CBotString.h" - // Local include // Global include +#include // Forward declaration class CBotVar; @@ -38,6 +37,8 @@ class CBotFunction; class CBotProgram; class CBotStack; class CBotDefParam; +class CBotToken; +class CBotCStack; /*! * \brief The CBotClass class Class to define new classes in the language CBOT @@ -57,9 +58,9 @@ public: * \param pParent * \param bIntrinsic */ - CBotClass( const char* name, - CBotClass* pParent, - bool bIntrinsic = false ); + CBotClass(const std::string& name, + CBotClass* pParent, + bool bIntrinsic = false); /*! * \brief CBotClass Destructor. @@ -73,7 +74,7 @@ public: * \param intrinsic * \return */ - static CBotClass* Create(const char* name, + static CBotClass* Create(const std::string& name, CBotClass* parent, bool intrinsic = false); @@ -86,9 +87,9 @@ public: * \param rCompile * \return */ - bool AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), - CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); + bool AddFunction(const std::string& name, + bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user), + CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar)); /*! * \brief AddUpdateFunc Defines routine to be called to update the elements @@ -106,7 +107,7 @@ public: * \param mPrivate * \return */ - bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); + bool AddItem(std::string name, CBotTypResult type, int mPrivate = PR_PUBLIC); /*! * \brief AddItem Adds an item by passing the pointer to an instance of a @@ -126,7 +127,7 @@ public: * \brief GetName Gives the name of the class. * \return */ - CBotString GetName(); + std::string GetName(); /*! * \brief GetParent Gives the parent class (or nullptr). @@ -153,7 +154,7 @@ public: * \param name * \return */ - static CBotClass* Find(const char* name); + static CBotClass* Find(const std::string& name); /*! * \brief GetVar Return the list of variables. @@ -165,7 +166,7 @@ public: * \param name * \return */ - CBotVar* GetItem(const char* name); + CBotVar* GetItem(const std::string& name); /*! * \brief GetItemRef @@ -184,7 +185,7 @@ public: * \param nIdent * \return */ - CBotTypResult CompileMethode(const char* name, + CBotTypResult CompileMethode(const std::string& name, CBotVar* pThis, CBotVar** ppParams, CBotCStack* pStack, @@ -202,11 +203,11 @@ public: * \return */ bool ExecuteMethode(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppParams, - CBotVar* &pResult, - CBotStack* &pStack, + CBotVar*& pResult, + CBotStack*& pStack, CBotToken* pToken); /*! @@ -218,10 +219,10 @@ public: * \param pStack */ void RestoreMethode(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppParams, - CBotStack* &pStack); + CBotStack*& pStack); /*! * \brief Compile Compiles a class declared by the user. @@ -319,7 +320,7 @@ private: //! Parent class. CBotClass* m_pParent; //! Name of this class. - CBotString m_name; + std::string m_name; //! Number of variables in the chain. int m_nbVar; //! Content of the class. @@ -357,7 +358,7 @@ private: For example, a routine which calculates the mean of a parameter list -int cMean(CBotVar* &pVar, CBotString& ClassName) +int cMean(CBotVar* &pVar, std::string& ClassName) { if ( pVar == nullptr ) return 6001; // there is no parameter! while ( pVar != nullptr ) diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 7f13f89d..2e48c06f 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -196,9 +196,9 @@ CBotDefParam* CBotDefParam::GetNext() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotDefParam::GetParamString() +std::string CBotDefParam::GetParamString() { - CBotString param; + std::string param; param = m_typename; param += ' '; diff --git a/src/CBot/CBotDefParam.h b/src/CBot/CBotDefParam.h index 433d18f4..70069648 100644 --- a/src/CBot/CBotDefParam.h +++ b/src/CBot/CBotDefParam.h @@ -99,13 +99,13 @@ public: * \brief GetParamString * \return */ - CBotString GetParamString(); + std::string GetParamString(); private: //! Name of the parameter. CBotToken m_token; //! Type name. - CBotString m_typename; + std::string m_typename; //! Type of paramteter. CBotTypResult m_type; //! Next parameter. diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp index c6e50e1a..c3be54a1 100644 --- a/src/CBot/CBotFileUtils.cpp +++ b/src/CBot/CBotFileUtils.cpp @@ -20,10 +20,9 @@ // Modules inlcude #include "CBot/CBotFileUtils.h" -#include "CBot/CBotString.h" #include "CBot/CBotClass.h" - #include "CBot/CBotEnums.h" +#include "CBot/CBotUtils.h" // Local include @@ -108,7 +107,7 @@ bool ReadLong(FILE* pf, long& w) } //////////////////////////////////////////////////////////////////////////////// -bool ReadString(FILE* pf, CBotString& s) +bool ReadString(FILE* pf, std::string& s) { unsigned short w; char buf[1000]; @@ -157,7 +156,7 @@ bool ReadType(FILE* pf, CBotTypResult &type) if ( type.Eq( CBotTypClass ) ) { - CBotString s; + std::string s; if ( !ReadString(pf, s) ) return false; type = CBotTypResult( w, s ); } diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h index 75bfa434..534634af 100644 --- a/src/CBot/CBotFileUtils.h +++ b/src/CBot/CBotFileUtils.h @@ -24,11 +24,11 @@ // Local include // Global include - #include +#include +#include // Forward declaration class CBotVar; -class CBotString; class CBotTypResult; /////////////////////////////////////////////////////////////////////////////// @@ -137,7 +137,7 @@ bool ReadFloat(FILE* pf, float& w); * \param s * \return */ -bool ReadString(FILE* pf, CBotString& s); +bool ReadString(FILE* pf, std::string& s); /*! * \brief WriteType diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index d97d65ae..b0a308de 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -46,7 +46,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen - if ( !ChkLvl(CBotString(), type ) ) + if ( !ChkLvl(std::string(), type ) ) { pStack->SetError(TX_BREAK, pp); return nullptr; // no object, the error is on the stack diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h index 7961b0bf..ce65b336 100644 --- a/src/CBot/CBotInstr/CBotBreak.h +++ b/src/CBot/CBotInstr/CBotBreak.h @@ -70,6 +70,6 @@ public: private: //! A label if there is - CBotString m_label; + std::string m_label; }; diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index d66ba3ec..e03fa3d6 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -82,7 +82,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* inst = new CBotClassInst(); /// TODO Need to be revised and fixed after adding unit tests - CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd()); + CBotToken token(pClass->GetName(), std::string(), p->GetStart(), p->GetEnd()); inst->SetToken(&token); CBotToken* vartoken = p; @@ -137,7 +137,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* if ( inst->m_hasParams ) { // the constructor is there? -// CBotString noname; +// std::string noname; CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent); delete pStk->TokenStack(); // releases the supplement stack int typ = r.GetType(); @@ -242,7 +242,7 @@ bool CBotClassInst::Execute(CBotStack* &pj) if ( pile->GetState()==0) { - CBotString name = m_var->m_token.GetString(); + std::string name = m_var->m_token.GetString(); if ( bIntrincic ) { pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass )); @@ -371,7 +371,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain) // creates the variable of type pointer to the object { - CBotString name = m_var->m_token.GetString(); + std::string name = m_var->m_token.GetString(); pThis = pile->FindVar(name); pThis->SetUniqNum((static_cast(m_var))->m_nIdent); // its attribute a unique number } diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h index 8a800400..b2cb6463 100644 --- a/src/CBot/CBotInstr/CBotDo.h +++ b/src/CBot/CBotInstr/CBotDo.h @@ -69,5 +69,5 @@ private: //! Conditions CBotInstr* m_Condition; //! A label if there is - CBotString m_label; + std::string m_label; }; diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp index da68497e..a5a415b4 100644 --- a/src/CBot/CBotInstr/CBotExprAlpha.cpp +++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp @@ -65,8 +65,8 @@ bool CBotExprAlpha::Execute(CBotStack* &pj) CBotVar* var = CBotVar::Create(static_cast(nullptr), CBotTypString); - CBotString chaine = m_token.GetString(); - chaine = chaine.Mid(1, chaine.GetLength()-2); // removes the quotes + std::string chaine = m_token.GetString(); + chaine = chaine.substr(1, chaine.length()-2); // removes the quotes var->SetValString(chaine); // value of the number diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp index e9a72dec..a4fcb8dc 100644 --- a/src/CBot/CBotInstr/CBotExprNum.cpp +++ b/src/CBot/CBotInstr/CBotExprNum.cpp @@ -25,6 +25,8 @@ #include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotUtils.h" + // Local include // Global include @@ -48,7 +50,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) CBotExprNum* inst = new CBotExprNum(); inst->SetToken(p); - CBotString s = p->GetString(); + std::string s = p->GetString(); inst->m_numtype = CBotTypInt; if (p->GetType() == TokenTypDef) @@ -57,7 +59,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) } else { - if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) )) + if (s.find('.') != std::string::npos || ( s.find('x') == std::string::npos && ( s.find_first_of("eE") != std::string::npos ) )) { inst->m_numtype = CBotTypFloat; inst->m_valfloat = GetNumFloat(s); @@ -88,7 +90,7 @@ bool CBotExprNum::Execute(CBotStack* &pj) CBotVar* var = CBotVar::Create(static_cast(nullptr), m_numtype); - CBotString nombre ; + std::string nombre ; if (m_token.GetType() == TokenTypDef) { nombre = m_token.GetString(); diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h index 5b9a93eb..949b28c7 100644 --- a/src/CBot/CBotInstr/CBotFor.h +++ b/src/CBot/CBotInstr/CBotFor.h @@ -77,5 +77,5 @@ private: //! Instructions CBotInstr* m_Block; //! A label if there is - CBotString m_label; + std::string m_label; }; diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index f61328b3..0744f70c 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -182,7 +182,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct if ( IsOfType(p, ID_NOT) ) { - CBotToken d(CBotString("~") + p->GetString()); + CBotToken d(std::string("~") + p->GetString()); func->m_token = d; } @@ -207,7 +207,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct { pStk->SetRetType(func->m_retTyp); // for knowledge what type returns - if (!func->m_MasterClass.IsEmpty()) + if (!func->m_MasterClass.empty()) { // return "this" known CBotVar* pThis = CBotVar::Create("this", CBotTypResult( CBotTypClass, func->m_MasterClass )); @@ -356,7 +356,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) pile->IncState(); } - if ( pile->GetState() == 1 && !m_MasterClass.IsEmpty() ) + if ( pile->GetState() == 1 && !m_MasterClass.empty() ) { // makes "this" known CBotVar* pThis = nullptr; @@ -411,7 +411,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst m_Param->RestoreState(pile2, true); // parameters - if ( !m_MasterClass.IsEmpty() ) + if ( !m_MasterClass.empty() ) { CBotVar* pThis = pile->FindVar("this"); pThis->SetInit(CBotVar::InitType::IS_POINTER); @@ -431,7 +431,7 @@ void CBotFunction::AddNext(CBotFunction* p) } //////////////////////////////////////////////////////////////////////////////// -CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long& nIdent) +CBotTypResult CBotFunction::CompileCall(const std::string& name, CBotVar** ppVars, long& nIdent) { nIdent = 0; CBotTypResult type; @@ -442,7 +442,8 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long } //////////////////////////////////////////////////////////////////////////////// -CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic) +CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars, + CBotTypResult& TypeOrError, bool bPublic) { TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name CBotFunction* pt; @@ -470,7 +471,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB } } - if ( name == nullptr ) return nullptr; + if ( name.empty() ) return nullptr; int delta = 99999; // seeks the lowest signature CBotFunction* pFunc = nullptr; // the best function found @@ -595,7 +596,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB } //////////////////////////////////////////////////////////////////////////////// -int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) +int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) { CBotTypResult type; CBotFunction* pt = nullptr; @@ -617,7 +618,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS if ( pStk1->GetState() == 0 ) { - if ( !pt->m_MasterClass.IsEmpty() ) + if ( !pt->m_MasterClass.empty() ) { CBotVar* pInstance = m_pProg->m_pInstance; // make "this" known @@ -665,7 +666,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS } //////////////////////////////////////////////////////////////////////////////// -void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack) +void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack) { CBotTypResult type; CBotFunction* pt = nullptr; @@ -699,7 +700,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, // preparing parameters on the stack { - if ( !pt->m_MasterClass.IsEmpty() ) + if ( !pt->m_MasterClass.empty() ) { // CBotVar* pInstance = m_pProg->m_pInstance; // make "this" known @@ -722,7 +723,8 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, } //////////////////////////////////////////////////////////////////////////////// -int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass) +int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, + CBotToken* pToken, CBotClass* pClass) { CBotTypResult type; CBotProgram* pProgCurrent = pStack->GetBotCall(); @@ -803,7 +805,8 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar } //////////////////////////////////////////////////////////////////////////////// -void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass) +void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, + CBotStack* pStack, CBotClass* pClass) { CBotTypResult type; CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type); @@ -851,17 +854,17 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam) } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotFunction::GetName() +std::string CBotFunction::GetName() { return m_token.GetString(); } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotFunction::GetParams() +std::string CBotFunction::GetParams() { - if ( m_Param == nullptr ) return CBotString("()"); + if ( m_Param == nullptr ) return std::string("()"); - CBotString params = "( "; + std::string params = "( "; CBotDefParam* p = m_Param; // list of parameters while (p != nullptr) diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index f11015f5..dbf96763 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -104,7 +104,7 @@ public: * \param nIdent * \return */ - CBotTypResult CompileCall(const char* name, + CBotTypResult CompileCall(const std::string& name, CBotVar** ppVars, long& nIdent); @@ -118,7 +118,7 @@ public: * \param bPublic * \return */ - CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, + CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic = true); @@ -134,7 +134,7 @@ public: */ int DoCall(long& nIdent, - const char* name, + const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken); @@ -147,7 +147,7 @@ public: * \param pStack */ void RestoreCall(long& nIdent, - const char* name, + const std::string& name, CBotVar** ppVars, CBotStack* pStack); @@ -164,7 +164,7 @@ public: * \return */ int DoCall(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, @@ -181,7 +181,7 @@ public: * \param pClass */ void RestoreCall(long& nIdent, - const char* name, + const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, @@ -204,13 +204,13 @@ public: * \brief GetName * \return */ - CBotString GetName(); + std::string GetName(); /*! * \brief GetParams * \return */ - CBotString GetParams(); + std::string GetParams(); /*! * \brief IsPublic @@ -263,7 +263,7 @@ private: //! Extern function. bool m_bExtern; //! Name of the class we derive. - CBotString m_MasterClass; + std::string m_MasterClass; CBotProgram* m_pProg; //! For the position of the word "extern". CBotToken m_extern; diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp index 66aff75d..c08723e1 100644 --- a/src/CBot/CBotInstr/CBotInstr.cpp +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -50,7 +50,7 @@ //////////////////////////////////////////////////////////////////////////////// int CBotInstr::m_LoopLvl = 0; -std::vector CBotInstr::m_labelLvl = std::vector(); +std::vector CBotInstr::m_labelLvl = std::vector(); //////////////////////////////////////////////////////////////////////////////// CBotInstr::CBotInstr() @@ -72,7 +72,7 @@ CBotInstr::~CBotInstr() } //////////////////////////////////////////////////////////////////////////////// -void CBotInstr::IncLvl(CBotString& label) +void CBotInstr::IncLvl(std::string& label) { m_labelLvl.resize(m_LoopLvl+1); m_labelLvl[m_LoopLvl] = label; @@ -91,24 +91,24 @@ void CBotInstr::IncLvl() void CBotInstr::DecLvl() { m_LoopLvl--; - m_labelLvl[m_LoopLvl].Empty(); + m_labelLvl[m_LoopLvl].clear(); } //////////////////////////////////////////////////////////////////////////////// -bool CBotInstr::ChkLvl(const CBotString& label, int type) +bool CBotInstr::ChkLvl(const std::string& label, int type) { int i = m_LoopLvl; while (--i>=0) { if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue; - if (label.IsEmpty()) return true; + if (label.empty()) return true; if (m_labelLvl[i] == label) return true; } return false; } //////////////////////////////////////////////////////////////////////////////// -bool CBotInstr::IsOfClass(CBotString n) +bool CBotInstr::IsOfClass(const std::string& n) { return name == n; } @@ -284,7 +284,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) //////////////////////////////////////////////////////////////////////////////// bool CBotInstr::Execute(CBotStack* &pj) { - CBotString ClassManquante = name; + std::string ClassManquante = name; assert(0); // should never go through this routine // but use the routines of the subclasses return false; @@ -301,7 +301,7 @@ bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) //////////////////////////////////////////////////////////////////////////////// void CBotInstr::RestoreState(CBotStack* &pj, bool bMain) { - CBotString ClassManquante = name; + std::string ClassManquante = name; assert(0); // should never go through this routine // but use the routines of the subclasses } diff --git a/src/CBot/CBotInstr/CBotInstr.h b/src/CBot/CBotInstr/CBotInstr.h index 9ed637c8..e8221a2f 100644 --- a/src/CBot/CBotInstr/CBotInstr.h +++ b/src/CBot/CBotInstr/CBotInstr.h @@ -208,7 +208,7 @@ public: * \brief IncLvl Adds a level with a label. * \param label */ - static void IncLvl(CBotString& label); + static void IncLvl(std::string& label); /*! * \brief IncLvl Adds a level (switch statement). @@ -226,21 +226,21 @@ public: * \param type * \return */ - static bool ChkLvl(const CBotString& label, int type); + static bool ChkLvl(const std::string& label, int type); /*! * \brief IsOfClass * \param name * \return */ - bool IsOfClass(CBotString name); + bool IsOfClass(const std::string& name); protected: //! Keeps the token. CBotToken m_token; //! Debug. - CBotString name; + std::string name; //! Linked command. CBotInstr* m_next; //! Second list definition chain. @@ -258,5 +258,5 @@ protected: private: //! List of labels used. - static std::vector m_labelLvl; + static std::vector m_labelLvl; }; diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h index 1c8512d8..f6bb1abe 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.h +++ b/src/CBot/CBotInstr/CBotInstrMethode.h @@ -84,9 +84,9 @@ private: //! Complete type of the result. CBotTypResult m_typRes; //! Name of the method. - CBotString m_NomMethod; + std::string m_NomMethod; //! Identifier of the method. long m_MethodeIdent; //! Name of the class. - CBotString m_ClassName; + std::string m_ClassName; }; diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index c89e959c..aeb6d520 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -97,7 +97,7 @@ bool CBotReturn::Execute(CBotStack* &pj) if ( pile->IfStep() ) return false; - pile->SetBreak(3, CBotString()); + pile->SetBreak(3, std::string()); return pj->Return(pile); } diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h index 6b91c741..8898413f 100644 --- a/src/CBot/CBotInstr/CBotWhile.h +++ b/src/CBot/CBotInstr/CBotWhile.h @@ -74,6 +74,6 @@ private: //! Instructions CBotInstr* m_Block; //! A label if there is - CBotString m_label; + std::string m_label; }; diff --git a/src/CBot/CBotKeywordStrings.cpp b/src/CBot/CBotKeywordStrings.cpp index e1a45fa5..2af5eb0e 100644 --- a/src/CBot/CBotKeywordStrings.cpp +++ b/src/CBot/CBotKeywordStrings.cpp @@ -4,7 +4,7 @@ //! \brief Keeps the string corresponding to keyword ID // Map is filled with id-string pars that are needed for CBot language parsing -static const std::map s_keywordString = { +static const std::map s_keywordString = { {ID_IF, "if"}, {ID_ELSE, "else"}, {ID_WHILE, "while"}, @@ -94,9 +94,8 @@ static const std::map s_keywordString = { {TX_NAN, "not a number"} }; -static const char emptyString[] = ""; - -const char* LoadString(EID id) +static const std::string emptyString = ""; +const std::string& LoadString(EID id) { if (s_keywordString.find(id) != s_keywordString.end()) { diff --git a/src/CBot/CBotKeywordStrings.h b/src/CBot/CBotKeywordStrings.h index b328b787..e652a205 100644 --- a/src/CBot/CBotKeywordStrings.h +++ b/src/CBot/CBotKeywordStrings.h @@ -2,9 +2,11 @@ #include "CBotEnums.h" +#include + /** * \brief LoadString Maps given ID to its string equivalent. * \param id Provided identifier. * \return String if found, else NullString. */ -const char* LoadString(EID id); +const std::string& LoadString(EID id); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 80c93276..0dd62f1e 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -81,7 +81,7 @@ CBotProgram::~CBotProgram() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::Compile( const char* program, std::vector& ListFonctions, void* pUser ) +bool CBotProgram::Compile(const std::string& program, std::vector& ListFonctions, void* pUser) { int error = 0; Stop(); @@ -176,7 +176,7 @@ bool CBotProgram::Compile( const char* program, std::vector& ListFon } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::Start(const char* name) +bool CBotProgram::Start(const std::string& name) { #if STACKMEM m_pStack->Delete(); @@ -210,7 +210,7 @@ bool CBotProgram::Start(const char* name) } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop) +bool CBotProgram::GetPosition(const std::string& name, int& start, int& stop, CBotGet modestart, CBotGet modestop) { CBotFunction* p = m_Prog; while (p != nullptr) @@ -293,7 +293,7 @@ void CBotProgram::Stop() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end) +bool CBotProgram::GetRunPos(std::string& FunctionName, int& start, int& end) { FunctionName = nullptr; start = end = 0; @@ -304,7 +304,7 @@ bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level) +CBotVar* CBotProgram::GetStackVars(std::string& FunctionName, int level) { FunctionName = nullptr; if (m_pStack == nullptr) return nullptr; @@ -356,11 +356,11 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotProgram::GetErrorText(int code) +std::string CBotProgram::GetErrorText(int code) { - CBotString TextError = LoadString(static_cast(code)); + std::string TextError = LoadString(static_cast(code)); - if (TextError.IsEmpty()) + if (TextError.empty()) { char buf[100]; sprintf(buf, "Exception numéro %d.", code); @@ -376,9 +376,9 @@ CBotFunction* CBotProgram::GetFunctions() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) +bool CBotProgram::AddFunction(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)) { // stores pointers to the two functions return CBotCall::AddFunction(name, rExec, rCompile); @@ -412,7 +412,7 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser ) } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::DefineNum(const char* name, long val) +bool CBotProgram::DefineNum(const std::string& name, long val) { return CBotToken::DefineNum(name, val); } @@ -440,7 +440,7 @@ bool CBotProgram::SaveState(FILE* pf) bool CBotProgram::RestoreState(FILE* pf) { unsigned short w; - CBotString s; + std::string s; Stop(); diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 26aeb688..50c62f63 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -21,7 +21,6 @@ // Modules inlcude #include "CBot/CBotTypResult.h" -#include "CBot/CBotString.h" #include "CBot/CBotEnums.h" @@ -84,7 +83,7 @@ public: * \return false if an error at compile. * \see GetCompileError() to retrieve the error. */ - bool Compile( const char* program, std::vector& ListFonctions, void* pUser = nullptr); + bool Compile(const std::string& program, std::vector& ListFonctions, void* pUser = nullptr); /*! * \brief SetIdent Associates an identifier with the instance CBotProgram. @@ -128,7 +127,7 @@ public: * \param code * \return */ - static CBotString GetErrorText(int code); + static std::string GetErrorText(int code); /*! * \brief Start Defines what function should be executed. The program does @@ -136,7 +135,7 @@ public: * \param name * \return false if the funtion name is not found */ - bool Start(const char* name); + bool Start(const std::string& name); /*! * \brief Run Executes the program. @@ -154,7 +153,7 @@ public: * \param end * \return false if it is not running (program completion) */ - bool GetRunPos(const char* &FunctionName, int &start, int &end); + bool GetRunPos(std::string& FunctionName, int& start, int& end); /*! * \brief GetStackVars provides the pointer to the variables on the @@ -168,7 +167,7 @@ public: * \param level * \return */ - CBotVar* GetStackVars(const char* &FunctionName, int level); + CBotVar* GetStackVars(std::string& FunctionName, int level); /*! * \brief Stop stops execution of the program therefore quits "suspend" mode @@ -193,9 +192,9 @@ public: * \param rCompile * \return */ - static bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), - CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); + static bool AddFunction(const std::string& name, + bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotTypResult rCompile(CBotVar*& pVar, void* pUser)); /*! * \brief DefineNum @@ -203,7 +202,7 @@ public: * \param val * \return */ - static bool DefineNum(const char* name, long val); + static bool DefineNum(const std::string& name, long val); /*! * \brief SaveState Backup the execution status in the file the file must @@ -233,11 +232,11 @@ public: * \param modestop * \return */ - bool GetPosition(const char* name, + bool GetPosition(const std::string& name, int& start, int& stop, CBotGet modestart = GetPosExtern, - CBotGet modestop = GetPosBloc); + CBotGet modestop = GetPosBloc); /*! * \brief GetFunctions @@ -286,7 +285,7 @@ private: For example, a routine which calculates the mean of a parameter list -int cMean(CBotVar* &pVar, CBotString& ClassName) +int cMean(CBotVar* &pVar, std::string& ClassName) { if ( pVar == nullptr ) return 6001; // there is no parameter! while ( pVar != nullptr ) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index c2c04d23..f77b9f7e 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -27,6 +27,7 @@ #include "CBot/CBotVar/CBotVarClass.h" #include "CBot/CBotFileUtils.h" +#include "CBot/CBotUtils.h" // Local include @@ -44,7 +45,7 @@ CBotVar* CBotStack::m_retvar = nullptr; int CBotStack::m_error = 0; int CBotStack::m_start = 0; int CBotStack::m_end = 0; -CBotString CBotStack::m_labelBreak=""; +std::string CBotStack::m_labelBreak=""; void* CBotStack::m_pUser = nullptr; #if STACKMEM @@ -381,7 +382,7 @@ void CBotStack::Reset(void* pUser) m_error = 0; // m_start = 0; // m_end = 0; - m_labelBreak.Empty(); + m_labelBreak.clear(); m_pUser = pUser; } @@ -414,36 +415,36 @@ bool CBotStack::IfStep() } //////////////////////////////////////////////////////////////////////////////// -bool CBotStack::BreakReturn(CBotStack* pfils, const char* name) +bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name) { if ( m_error>=0 ) return false; // normal output if ( m_error==-3 ) return false; // normal output (return current) - if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name)) + if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name)) return false; // it's not for me m_error = 0; - m_labelBreak.Empty(); + m_labelBreak.clear(); return Return(pfils); } //////////////////////////////////////////////////////////////////////////////// -bool CBotStack::IfContinue(int state, const char* name) +bool CBotStack::IfContinue(int state, const std::string& name) { if ( m_error != -2 ) return false; - if (!m_labelBreak.IsEmpty() && (name == nullptr || m_labelBreak != name)) + if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name)) return false; // it's not for me m_state = state; // where again? m_error = 0; - m_labelBreak.Empty(); + m_labelBreak.clear(); if ( m_next != EOX ) m_next->Delete(); // purge above stack return true; } //////////////////////////////////////////////////////////////////////////////// -void CBotStack::SetBreak(int val, const char* name) +void CBotStack::SetBreak(int val, const std::string& name) { m_error = -val; // reacts as an Exception m_labelBreak = name; @@ -502,7 +503,7 @@ void CBotStack::SetType(CBotTypResult& type) CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) { CBotStack* p = this; - CBotString name = pToken->GetString(); + std::string name = pToken->GetString(); while (p != nullptr) { @@ -524,7 +525,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotStack::FindVar(const char* name) +CBotVar* CBotStack::FindVar(const std::string& name) { CBotStack* p = this; while (p != nullptr) @@ -814,7 +815,7 @@ bool SaveVar(FILE* pf, CBotVar* pVar) } //////////////////////////////////////////////////////////////////////////////// -void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) +void CBotStack::GetRunPos(std::string& FunctionName, int& start, int& end) { CBotProgram* prog = m_prog; // Current program @@ -849,7 +850,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) +CBotVar* CBotStack::GetStackVars(std::string& FunctionName, int level) { CBotProgram* prog = m_prog; // current program FunctionName = nullptr; @@ -1005,7 +1006,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) { unsigned short w, wi, prv, st; float ww; - CBotString name, s; + std::string name, s; delete pVar; @@ -1018,7 +1019,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) if (!ReadWord(pf, w)) return false; // private or type? if ( w == 0 ) return true; - CBotString defnum; + std::string defnum; if ( w == 200 ) { if (!ReadString(pf, defnum)) return false; // number with identifier @@ -1039,7 +1040,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) if (!ReadWord(pf, wi) || !ParseInitType(wi, &initType)) return false; // init ? if (!ReadString(pf, name)) return false; // variable name - CBotToken token(name, CBotString()); + CBotToken token(name, std::string()); switch (w) { diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 738cfd6c..b5afe4d5 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -22,12 +22,12 @@ // Modules inlcude #include "CBot/CBotDefines.h" #include "CBot/CBotTypResult.h" -#include "CBot/CBotString.h" // Local include // Global include #include +#include // Forward declaration class CBotInstr; @@ -150,7 +150,7 @@ public: * \param [in] name Name of variable to find * \return Found variable */ - CBotVar* FindVar(const char* name); + CBotVar* FindVar(const std::string& name); /** * \brief Fetch a variable on the stack according to its identification number @@ -180,9 +180,9 @@ public: CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack bool Return(CBotStack* pFils); // transmits the result over bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack - bool BreakReturn(CBotStack* pfils, const char* name = nullptr); + bool BreakReturn(CBotStack* pfils, const std::string& name = nullptr); // in case of eventual break - bool IfContinue(int state, const char* name); + bool IfContinue(int state, const std::string& name); // or "continue" bool IsOk(); @@ -204,7 +204,7 @@ public: void SetError(int n, CBotToken* token = nullptr); void SetPosError(CBotToken* token); void ResetError(int n, int start, int end); - void SetBreak(int val, const char* name); + void SetBreak(int val, const std::string& name); void SetBotCall(CBotProgram* p); CBotProgram* GetBotCall(bool bFirst = false); @@ -221,8 +221,8 @@ public: static void SetTimer(int n); - void GetRunPos(const char* &FunctionName, int &start, int &end); - CBotVar* GetStackVars(const char* &FunctionName, int level); + void GetRunPos(std::string& FunctionName, int& start, int& end); + CBotVar* GetStackVars(std::string& FunctionName, int level); private: CBotStack* m_next; @@ -254,7 +254,7 @@ private: static int m_timer; static - CBotString m_labelBreak; + std::string m_labelBreak; static void* m_pUser; diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp deleted file mode 100644 index 2459f39c..00000000 --- a/src/CBot/CBotString.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -///////////////////////////////////////////////////// - -#include "CBot/CBotString.h" - -#include -#include -#include -#include - -CBotString::CBotString() -{ - m_str = ""; -} - -CBotString::~CBotString() -{ -} - - -CBotString::CBotString(const char* p) -{ - m_str = p; -} - -CBotString::CBotString(const std::string &p) -{ - m_str = p; -} - -CBotString::CBotString(const CBotString& srcString) -{ - m_str = srcString.m_str; -} - - - -int CBotString::GetLength() -{ - return m_str.length(); -} - - - -CBotString CBotString::Left(int nCount) const -{ - return CBotString(m_str.substr(0, nCount)); -} - -CBotString CBotString::Right(int nCount) const -{ - return CBotString(m_str.substr(m_str.length()-nCount, std::string::npos)); -} - -CBotString CBotString::Mid(int start, int lg) -{ - return CBotString(m_str.substr(start, lg)); -} - -int CBotString::Find(const char c) -{ - std::size_t pos = m_str.find(c); - return pos != std::string::npos ? pos : -1; -} - -int CBotString::Find(const char * lpsz) -{ - std::size_t pos = m_str.find(lpsz); - return pos != std::string::npos ? pos : -1; -} - -int CBotString::ReverseFind(const char c) -{ - std::size_t pos = m_str.rfind(c); - return pos != std::string::npos ? pos : -1; -} - -int CBotString::ReverseFind(const char * lpsz) -{ - std::size_t pos = m_str.rfind(lpsz); - return pos != std::string::npos ? pos : -1; -} - -void CBotString::MakeUpper() -{ - boost::to_upper(m_str); -} - -void CBotString::MakeLower() -{ - boost::to_lower(m_str); -} - - -const CBotString& CBotString::operator=(const CBotString& stringSrc) -{ - m_str = stringSrc.m_str; - return *this; -} - -CBotString CBotString::operator+(const CBotString& stringSrc) -{ - CBotString s(*this); - s += stringSrc; - return s; -} - -const CBotString& CBotString::operator=(const char ch) -{ - m_str = ch; - return *this; -} - -const CBotString& CBotString::operator=(const char* pString) -{ - if (pString != nullptr) - m_str = pString; - else - m_str.clear(); - return *this; -} - - -const CBotString& CBotString::operator+=(const char ch) -{ - m_str += ch; - return *this; -} - -const CBotString& CBotString::operator+=(const CBotString& str) -{ - m_str += str.m_str; - return *this; -} - -bool CBotString::operator==(const CBotString& str) -{ - return m_str == str.m_str; -} - -bool CBotString::operator==(const char* p) -{ - return m_str == p; -} - -bool CBotString::operator!=(const CBotString& str) -{ - return m_str != str.m_str; -} - -bool CBotString::operator!=(const char* p) -{ - return m_str != p; -} - -bool CBotString::operator>(const CBotString& str) -{ - return m_str > str.m_str; -} - -bool CBotString::operator>(const char* p) -{ - return m_str > p; -} - -bool CBotString::operator>=(const CBotString& str) -{ - return m_str >= str.m_str; -} - -bool CBotString::operator>=(const char* p) -{ - return m_str >= p; -} - -bool CBotString::operator<(const CBotString& str) -{ - return m_str < str.m_str; -} - -bool CBotString::operator<(const char* p) -{ - return m_str < p; -} - -bool CBotString::operator<=(const CBotString& str) -{ - return m_str <= str.m_str; -} - -bool CBotString::operator<=(const char* p) -{ - return m_str <= p; -} - -bool CBotString::IsEmpty() const -{ - return m_str.empty(); -} - -void CBotString::Empty() -{ - m_str.clear(); -} - -static char emptyString[] = ""; - -CBotString::operator const char * () const -{ - if (this == nullptr) return emptyString; // TODO: can this be removed? - return m_str.c_str(); -} - -const char* CBotString::CStr() const -{ - if (this == nullptr) return emptyString; // TODO: can this be removed? - return m_str.c_str(); -} diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h deleted file mode 100644 index efe2d9d9..00000000 --- a/src/CBot/CBotString.h +++ /dev/null @@ -1,194 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -#pragma once - -// Modules inlcude -#include "CBot/CBotUtils.h" - -#include "CBot/CBotEnums.h" - -// Local include - -// Global include -#include - -/** - * \brief CBotString Class used to work on strings - * TODO: do not use this class, code should be refactored to use std::string instead - */ -class CBotString -{ -public: - - /** - * \brief CBotString Creates an empty string - */ - CBotString(); - - /** - * \brief CBotString - * \param p - */ - CBotString(const char* p); - - /** - * \brief CBotString - * \param p - */ - CBotString(const std::string& p); - - /** - * \brief CBotString - * \param p - */ - CBotString(const CBotString& p); - - /** - * \brief CBotString Destructor. - */ - ~CBotString(); - - /** - * \brief Empty Clear the internal string. - */ - void Empty(); - - /** - * \brief IsEmpty Check if the string is empty. - * \return True if the sting is empty false otherwise. - */ - bool IsEmpty() const; - - /** - * \brief GetLength Get the string length. - * \return The size of the string. - */ - int GetLength(); - - /** - * \brief Find Find the position of a character in a string starting from - * the beginning of the string. - * \param c The character to find. - * \return The position of the character or -1 if the character was not - * found. - * \see ReverseFind(const char c) - */ - int Find(const char c); - - /** - * \brief Find Find the position of a string in a string starting from the - * beginning of the string. - * \param lpsz The string to find. - * \return The position of the string or -1 if the string was not - * found. - * \see ReverseFind(const char* lpsz) - */ - int Find(const char* lpsz); - - /** - * \brief Find Find the position of a character in a string starting from - * the end of the string. - * \param c The character to find. - * \return The position of the character or -1 if the character was not - * found. - * \see Find(const char c) - */ - int ReverseFind(const char c); - - /** - * \brief Find Find the position of a string in a string starting from the - * end of the string. - * \param lpsz The string to find. - * \return The string of the character or -1 if the string was not - * found. - * \see Find(const char* lpsz) - */ - int ReverseFind(const char* lpsz); - - /** - * \brief Mid Return a part of a string from a starting index and until - * the end of the string with a limited size. - * \param nFirst The start index of the character in the string. - * \param lg The size limit. Default value is 2000. - * \return The exctracted string. - */ - CBotString Mid(int start, int lg=-1); - - /** - * \brief Left Return a part of a string starting from the left. - * \param nCount The number of character to retreive. - * \return The exctracted string. - */ - CBotString Left(int nCount) const; - - /** - * \brief Right Return a part of a string starting from the right. - * \param nCount The number of character to retreive. - * \return The exctracted string. - */ - CBotString Right(int nCount) const; - - /** - * \brief MakeUpper Uppercase the string. - */ - void MakeUpper(); - - /** - * \brief MakeLower Lowercase the string. - */ - void MakeLower(); - - /** - * @brief CStr Convert the CBotString to a C string. - * @return A C string string. - */ - const char* CStr() const; - - /** - * \brief Overloaded oprators to work on CBotString classes - */ - const CBotString& operator=(const CBotString& stringSrc); - const CBotString& operator=(const char ch); - const CBotString& operator=(const char* pString); - CBotString operator+(const CBotString& str); - - const CBotString& operator+=(const char ch); - const CBotString& operator+=(const CBotString& str); - bool operator==(const CBotString& str); - bool operator==(const char* p); - bool operator!=(const CBotString& str); - bool operator!=(const char* p); - bool operator>(const CBotString& str); - bool operator>(const char* p); - bool operator>=(const CBotString& str); - bool operator>=(const char* p); - bool operator<(const CBotString& str); - bool operator<(const char* p); - bool operator<=(const CBotString& str); - bool operator<=(const char* p); - - operator const char*() const; // as a C string - - -private: - - //! \brief String - std::string m_str; -}; diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index baef6977..9951c181 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -27,9 +27,9 @@ #include //////////////////////////////////////////////////////////////////////////////// -std::vector CBotToken::m_ListKeyWords; +std::vector CBotToken::m_ListKeyWords; int CBotToken::m_ListIdKeyWords[200]; -std::vector CBotToken::m_ListKeyDefine; +std::vector CBotToken::m_ListKeyDefine; long CBotToken::m_ListKeyNums[MAXDEFNUM]; //////////////////////////////////////////////////////////////////////////////// @@ -47,8 +47,8 @@ CBotToken::CBotToken(const CBotToken* pSrc) m_next = nullptr; m_prev = nullptr; - m_Text.Empty(); - m_Sep.Empty(); + m_Text.clear(); + m_Sep.clear(); m_type = 0; m_IdKeyWord = 0; @@ -71,7 +71,7 @@ CBotToken::CBotToken(const CBotToken* pSrc) } //////////////////////////////////////////////////////////////////////////////// -CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, int end) +CBotToken::CBotToken(const std::string& mot, const std::string& sep, int start, int end) { m_Text = mot; // word (mot) found as token m_Sep = sep; // separator @@ -84,17 +84,6 @@ CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, in m_IdKeyWord = -1; } -CBotToken::CBotToken(const char* mot, const char* sep) -{ - m_Text = mot; - if ( sep != nullptr ) m_Sep = sep; - m_next = nullptr; - m_prev = nullptr; - - m_type = TokenTypVar; // at the beginning a default variable type - m_IdKeyWord = -1; -} - //////////////////////////////////////////////////////////////////////////////// CBotToken::~CBotToken() { @@ -155,19 +144,19 @@ CBotToken* CBotToken::GetPrev() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotToken::GetString() +std::string CBotToken::GetString() { return m_Text; } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotToken::GetSep() +std::string CBotToken::GetSep() { return m_Sep; } //////////////////////////////////////////////////////////////////////////////// -void CBotToken::SetString(const char* name) +void CBotToken::SetString(const std::string& name) { m_Text = name; } @@ -229,8 +218,8 @@ static char nch[] = "\"\r\n\t"; // forbidden in cha //////////////////////////////////////////////////////////////////////////////// CBotToken* CBotToken::NextToken(char* &program, int& error, bool first) { - CBotString mot; // the word which is found - CBotString sep; // separators that are after + std::string mot; // the word which is found + std::string sep; // separators that are after char c; bool stop = first; @@ -315,7 +304,7 @@ cc: mot += c; if (CharInList(mot[0], sep3)) // an operational separator? { - CBotString motc = mot; + std::string motc = mot; while (motc += c, c != 0 && GetKeyWords(motc)>0) // operand seeks the longest possible { mot += c; // build the word @@ -332,7 +321,7 @@ cc: mot += c; { if (stop || c == 0 || CharInList(c, sep1)) { - if (!first && mot.IsEmpty()) return nullptr; // end of the analysis + if (!first && mot.empty()) return nullptr; // end of the analysis bis: while (CharInList(c, sep2)) { @@ -387,10 +376,10 @@ bis: } //////////////////////////////////////////////////////////////////////////////// -CBotToken* CBotToken::CompileTokens(const char* program, int& error) +CBotToken* CBotToken::CompileTokens(const std::string& program, int& error) { CBotToken *nxt, *prv, *tokenbase; - char* p = const_cast ( program); + char* p = const_cast (program.c_str()); int pos = 0; error = 0; @@ -399,9 +388,9 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error) if (tokenbase == nullptr) return nullptr; tokenbase->m_start = pos; - pos += tokenbase->m_Text.GetLength(); + pos += tokenbase->m_Text.length(); tokenbase->m_end = pos; - pos += tokenbase->m_Sep.GetLength(); + pos += tokenbase->m_Sep.length(); char* pp = p; while (nullptr != (nxt = NextToken(p, error))) @@ -415,7 +404,7 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error) nxt->m_end = pos; pos += nxt->m_Sep.GetLength();*/ pos += (p - pp); // total size - nxt->m_end = pos - nxt->m_Sep.GetLength(); + nxt->m_end = pos - nxt->m_Sep.length(); pp = p; } @@ -436,7 +425,7 @@ void CBotToken::Delete(CBotToken* pToken) } //////////////////////////////////////////////////////////////////////////////// -int CBotToken::GetKeyWords(const char* w) +int CBotToken::GetKeyWords(const std::string& w) { int i; int l = m_ListKeyWords.size(); @@ -456,7 +445,7 @@ int CBotToken::GetKeyWords(const char* w) } //////////////////////////////////////////////////////////////////////////////// -bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) +bool CBotToken::GetKeyDefNum(const std::string& w, CBotToken*& token) { int i; int l = m_ListKeyDefine.size(); @@ -477,18 +466,18 @@ bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token) //////////////////////////////////////////////////////////////////////////////// void CBotToken::LoadKeyWords() { - CBotString s; + std::string s; int i, n = 0; i = TokenKeyWord; //start with keywords of the language - while (!(s = LoadString(static_cast(i))).IsEmpty()) + while (!(s = LoadString(static_cast(i))).empty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyDeclare; //keywords of declarations - while (!(s = LoadString(static_cast(i))).IsEmpty()) + while (!(s = LoadString(static_cast(i))).empty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; @@ -496,14 +485,14 @@ void CBotToken::LoadKeyWords() i = TokenKeyVal; //keywords of values - while (!(s = LoadString(static_cast(i))).IsEmpty()) + while (!(s = LoadString(static_cast(i))).empty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; } i = TokenKeyOp; //operators - while (!(s = LoadString(static_cast(i))).IsEmpty()) + while (!(s = LoadString(static_cast(i))).empty()) { m_ListKeyWords.push_back(s); m_ListIdKeyWords[n++] = i++; @@ -511,7 +500,7 @@ void CBotToken::LoadKeyWords() } //////////////////////////////////////////////////////////////////////////////// -bool CBotToken::DefineNum(const char* name, long val) +bool CBotToken::DefineNum(const std::string& name, long val) { int i; int l = m_ListKeyDefine.size(); diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index 1dbe39b2..4a0e2d6a 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -19,9 +19,8 @@ #pragma once -#include "CBot/CBotString.h" - #include +#include ///////////////////////////////////////////////////////////////////////////////////// // Token management (tokens) @@ -69,11 +68,10 @@ public: */ CBotToken(); CBotToken(const CBotToken* pSrc); - CBotToken(const CBotString& mot, - const CBotString& sep, + CBotToken(const std::string& mot, + const std::string& sep = "", int start=0, int end=0); - CBotToken(const char* mot, const char* sep = nullptr); /*! * \brief ~CBotToken Destructor. Be careful when you delete a CBotToken that @@ -92,20 +90,20 @@ public: * \return The token string if a string has been set. An empty string * otherwise. */ - CBotString GetString(); + std::string GetString(); /*! * \brief SetString Set the token string. * \param [in] name The new string to set. */ - void SetString(const char* name); + void SetString(const std::string& name); /*! * \brief GetSep Return the token separator. * \return The token separator a separator has been set. An empty separator * otherwise. */ - CBotString GetSep(); + std::string GetSep(); /*! * \brief GetStart Return the start position of the string token in the @@ -165,7 +163,7 @@ public: * \return The first token of the linked liste. * \todo Replace the error code by an enum. */ - static CBotToken* CompileTokens(const char* p, int& error); + static CBotToken* CompileTokens(const std::string& p, int& error); /*! * \brief NextToken Looking for the next token in the string. The string must @@ -191,7 +189,7 @@ public: * \param [in] val The number associated with the keyword. * \return Ture if the number is available false oterhwise. */ - static bool DefineNum(const char* name, long val); + static bool DefineNum(const std::string& name, long val); /*! * \brief Free Free the array created with DefineNum. @@ -211,9 +209,9 @@ private: long m_IdKeyWord; //! The token string - CBotString m_Text; + std::string m_Text; //! The token separator - CBotString m_Sep; + std::string m_Sep; //! The strat position of the token in the CBotProgram int m_start; @@ -225,7 +223,7 @@ private: * \param w The word to compare. * \return -1 if this is not a keyword the keyword number otherwise. */ - static int GetKeyWords(const char* w); // is it a keyword? + static int GetKeyWords(const std::string& w); // is it a keyword? /*! * \brief GetKeyDefNum Check if this is a defined word and set the defined @@ -234,18 +232,18 @@ private: * \param [out] token The token in which the type will be set. * \return True if the defined word is found false otherwise. */ - static bool GetKeyDefNum(const char* w, CBotToken* &token); + static bool GetKeyDefNum(const std::string& w, CBotToken*& token); /*! * \brief LoadKeyWords Loads the list of keywords. The list of keyword is - * CBotString::s_keywordString. This keywords are keywords languages (if, +, + * std::string::s_keywordString. This keywords are keywords languages (if, +, * for, while, case, extern ...) * \todo Fixme Figure out how this should work. */ static void LoadKeyWords(); //! List of keywords of the CBot language (if, +, for, while, case, extern ...) - static std::vector m_ListKeyWords; + static std::vector m_ListKeyWords; //! List of id correponding to the keywords of the CBot language static int m_ListIdKeyWords[200]; @@ -253,7 +251,7 @@ private: //! This keywords are defined in : //! - void CScriptFunctions::Init() //! - void CBotProgram::Init() - static std::vector m_ListKeyDefine; + static std::vector m_ListKeyDefine; //! List of id correponding to the defined words static long m_ListKeyNums[MAXDEFNUM]; diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp index bde4f748..c4f9ee2f 100644 --- a/src/CBot/CBotTypResult.cpp +++ b/src/CBot/CBotTypResult.cpp @@ -43,7 +43,7 @@ CBotTypResult::CBotTypResult(int type) } //////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, const char* name) +CBotTypResult::CBotTypResult(int type, const std::string& name) { m_type = type; m_pNext = nullptr; diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h index 97ac52af..f992f01e 100644 --- a/src/CBot/CBotTypResult.h +++ b/src/CBot/CBotTypResult.h @@ -24,6 +24,7 @@ // Local include // Global include +#include class CBotClass; @@ -55,7 +56,7 @@ public: // for simple types (CBotTypInt à CBotTypString) - CBotTypResult(int type, const char* name); + CBotTypResult(int type, const std::string& name); // for pointer types and intrinsic classes CBotTypResult(int type, CBotClass* pClass); diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index 715a84c3..c098e463 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -120,14 +120,14 @@ bool WriteWord(FILE* pf, unsigned short w) } //////////////////////////////////////////////////////////////////////////////// -bool WriteString(FILE* pf, CBotString s) +bool WriteString(FILE* pf, std::string s) { size_t lg1, lg2; - lg1 = s.GetLength(); + lg1 = s.size(); if (!WriteWord(pf, lg1)) return false; - lg2 = fwrite(s, 1, lg1, pf ); + lg2 = fwrite(s.c_str(), 1, lg1, pf ); return (lg1 == lg2); } @@ -142,46 +142,9 @@ bool WriteFloat(FILE* pf, float w) } //////////////////////////////////////////////////////////////////////////////// -void ConstructElement(CBotString* pNewData) -{ - memset(pNewData, 0, sizeof(CBotString)); -} - -//////////////////////////////////////////////////////////////////////////////// -void DestructElement(CBotString* pOldData) -{ - pOldData->~CBotString(); -} - -//////////////////////////////////////////////////////////////////////////////// -void CopyElement(CBotString* pSrc, CBotString* pDest) -{ - *pSrc = *pDest; -} - -//////////////////////////////////////////////////////////////////////////////// -void ConstructElements(CBotString* pNewData, int nCount) -{ - while (nCount--) - { - ConstructElement(pNewData); - pNewData++; - } -} - -//////////////////////////////////////////////////////////////////////////////// -void DestructElements(CBotString* pOldData, int nCount) -{ - while (nCount--) - { - DestructElement(pOldData); - pOldData++; - } -} - -//////////////////////////////////////////////////////////////////////////////// -long GetNumInt(const char* p) +long GetNumInt(const std::string& str) { + const char* p = str.c_str(); long num = 0; while (*p >= '0' && *p <= '9') { @@ -214,8 +177,9 @@ long GetNumInt(const char* p) } //////////////////////////////////////////////////////////////////////////////// -float GetNumFloat(const char* p) +float GetNumFloat(const std::string& str) { + const char* p = str.c_str(); double num = 0; double div = 10; bool bNeg = false; diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index 819331cd..74914caa 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -20,16 +20,15 @@ #pragma once // Modules inlcude -#include "CBot/CBotString.h" #include "CBot/CBotTypResult.h" // Local include // Global include #include +#include // Forward declaration -class CBotString; class CBotVar; class CBotToken; class CBotCStack; @@ -74,7 +73,7 @@ bool WriteWord(FILE* pf, unsigned short w); * \param s * \return */ -bool WriteString(FILE* pf, CBotString s); +bool WriteString(FILE* pf, std::string s); /*! * \brief WriteFloat @@ -84,50 +83,17 @@ bool WriteString(FILE* pf, CBotString s); */ bool WriteFloat(FILE* pf, float w); -/*! - * \brief ConstructElement - * \param pNewData - */ -void ConstructElement(CBotString* pNewData); - -/*! - * \brief DestructElement - * \param pOldData - */ -void DestructElement(CBotString* pOldData); - -/*! - * \brief CopyElement - * \param pSrc - * \param pDest - */ -void CopyElement(CBotString* pSrc, CBotString* pDest); - -/*! - * \brief ConstructElements - * \param pNewData - * \param nCount - */ -void ConstructElements(CBotString* pNewData, int nCount); - -/*! - * \brief DestructElements - * \param pOldData - * \param nCount - */ -void DestructElements(CBotString* pOldData, int nCount); - /*! * \brief GetNumInt Converts a string into integer may be of the form 0xabc123. * \param p * \return */ -long GetNumInt(const char* p); +long GetNumInt(const std::string& p); /*! * \brief GetNumFloat Converts a string into a float number. * \param p * \return */ -float GetNumFloat(const char* p); +float GetNumFloat(const std::string& str); diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 43a6a34f..fc41945a 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -41,6 +41,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////////////////// long CBotVar::m_identcpt = 0; @@ -71,7 +72,7 @@ CBotVar::~CBotVar( ) void CBotVar::debug() { // const char* p = static_cast( m_token->GetString()); - CBotString s = static_cast( GetValString()); + std::string s = GetValString(); // const char* v = static_cast (s); if ( m_type.Eq(CBotTypClass) ) @@ -221,7 +222,7 @@ CBotVar* CBotVar::Create( CBotVar* pVar ) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVar::Create( const char* n, CBotTypResult type) +CBotVar* CBotVar::Create(const std::string& n, CBotTypResult type) { CBotToken name(n); @@ -286,7 +287,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) +CBotVar* CBotVar::Create(const std::string& name, int type, CBotClass* pClass) { CBotToken token( name, "" ); CBotVar* pVar = Create( &token, type ); @@ -308,7 +309,7 @@ CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVar::Create( const char* name, CBotClass* pClass) +CBotVar* CBotVar::Create(const std::string& name, CBotClass* pClass) { CBotToken token( name, "" ); CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) ); @@ -390,13 +391,13 @@ void CBotVar::SetInit(CBotVar::InitType bInit) } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVar::GetName() +std::string CBotVar::GetName() { return m_token->GetString(); } //////////////////////////////////////////////////////////////////////////////// -void CBotVar::SetName(const char* name) +void CBotVar::SetName(const std::string& name) { m_token->SetString(name); } @@ -408,7 +409,7 @@ CBotToken* CBotVar::GetToken() } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVar::GetItem(const char* name) +CBotVar* CBotVar::GetItem(const std::string& name) { assert(0); return nullptr; @@ -436,7 +437,7 @@ CBotVar* CBotVar::GetItem(int row, bool bGrow) } //////////////////////////////////////////////////////////////////////////////// -bool CBotVar::IsElemOfClass(const char* name) +bool CBotVar::IsElemOfClass(const std::string& name) { CBotClass* pc = nullptr; @@ -579,7 +580,7 @@ float CBotVar::GetValFloat() } //////////////////////////////////////////////////////////////////////////////// -void CBotVar::SetValInt(int c, const char* s) +void CBotVar::SetValInt(int c, const std::string& s) { assert(0); } @@ -737,16 +738,16 @@ void CBotVar::Copy(CBotVar* pSrc, bool bName) } //////////////////////////////////////////////////////////////////////////////// -void CBotVar::SetValString(const char* p) +void CBotVar::SetValString(const std::string& p) { assert(0); } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVar::GetValString() +std::string CBotVar::GetValString() { assert(0); - return CBotString(); + return std::string(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 56a5d5da..6f95db48 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -21,16 +21,18 @@ // Modules inlcude #include "CBot/CBotDefines.h" - -#include "CBot/CBotString.h" +#include "CBot/CBotTypResult.h" // Local include // Global include +#include // Forward declaration class CBotVarClass; class CBotInstr; +class CBotClass; +class CBotToken; /*! * \brief The CBotVar class Class for managing variables. May be useful to the @@ -68,7 +70,7 @@ public: * \param type * \return */ - static CBotVar* Create( const char* name, CBotTypResult type); + static CBotVar* Create(const std::string& name, CBotTypResult type); /*! * \brief Create Creates from one instance of a known class. @@ -76,7 +78,7 @@ public: * \param pClass * \return */ - static CBotVar* Create( const char* name, CBotClass* pClass); + static CBotVar* Create(const std::string& name, CBotClass* pClass); /*! * \brief Create Creates a variable depending on its type. @@ -101,7 +103,7 @@ public: * \param pClass * \return */ - static CBotVar* Create( const char* name, int type, CBotClass* pClass); + static CBotVar* Create(const std::string& name, int type, CBotClass* pClass); /*! * \brief Create @@ -139,13 +141,13 @@ public: * \brief GetName The name of the variable, if known. * \return */ - CBotString GetName(); + std::string GetName(); /*! * \brief SetName Changes the name of the variable * \param name */ - void SetName(const char* name); + void SetName(const std::string& name); /*! * \brief GetType Returns the base type (int) of the variable @@ -251,7 +253,7 @@ public: * \param name * \return */ - virtual CBotVar* GetItem(const char* name); + virtual CBotVar* GetItem(const std::string& name); /*! * \brief GetItemRef @@ -287,7 +289,7 @@ public: * \param name * \return */ - bool IsElemOfClass(const char* name); + bool IsElemOfClass(const std::string& name); /*! * \brief GetNext Next variable in the list (parameters). @@ -313,7 +315,7 @@ public: * \param val * \param name */ - virtual void SetValInt(int val, const char* name = nullptr); + virtual void SetValInt(int val, const std::string& name = ""); /*! * \brief SetValFloat Initialized with a real value (#). @@ -325,7 +327,7 @@ public: * \brief SetValString Initialized with a string value (#). * \param p */ - virtual void SetValString(const char* p); + virtual void SetValString(const std::string& p); /*! * \brief GetValInt Request the full value (#). @@ -343,7 +345,7 @@ public: * \brief GetValString Request the string value (#). * \return */ - virtual CBotString GetValString(); + virtual std::string GetValString(); /*! * \brief SetClass diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp index f24dd207..aa01b661 100644 --- a/src/CBot/CBotVar/CBotVarArray.cpp +++ b/src/CBot/CBotVar/CBotVarArray.cpp @@ -131,9 +131,9 @@ CBotVar* CBotVarArray::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarArray::GetValString() +std::string CBotVarArray::GetValString() { - if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ; + if ( m_pInstance == nullptr ) return ( std::string( "Null pointer" ) ) ; return m_pInstance->GetValString(); } diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h index 542984d0..5ce4b5b2 100644 --- a/src/CBot/CBotVar/CBotVarArray.h +++ b/src/CBot/CBotVar/CBotVarArray.h @@ -86,7 +86,7 @@ public: * \brief GetValString Gets the contents of the array into a string. * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Save1State diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp index 7a177e09..10d33bd8 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.cpp +++ b/src/CBot/CBotVar/CBotVarBoolean.cpp @@ -64,7 +64,7 @@ void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) } //////////////////////////////////////////////////////////////////////////////// -void CBotVarBoolean::SetValInt(int val, const char* s) +void CBotVarBoolean::SetValInt(int val, const std::string& s) { m_val = static_cast(val); m_binit = CBotVar::InitType::DEF; @@ -90,11 +90,11 @@ float CBotVarBoolean::GetValFloat() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarBoolean::GetValString() +std::string CBotVarBoolean::GetValString() { - CBotString ret; + std::string ret; - CBotString res; + std::string res; if ( m_binit == CBotVar::InitType::UNDEF ) { diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h index 0451f6d2..9ac52fe8 100644 --- a/src/CBot/CBotVar/CBotVarBoolean.h +++ b/src/CBot/CBotVar/CBotVarBoolean.h @@ -47,7 +47,7 @@ public: * \param val * \param s */ - void SetValInt(int val, const char* s = nullptr) override; + void SetValInt(int val, const std::string& s = nullptr) override; /*! * \brief SetValFloat @@ -71,7 +71,7 @@ public: * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Copy Copy a variable into another. diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 894ff039..484cbb25 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -268,7 +268,7 @@ void CBotVarClass::Maj(void* pUser, bool bContinu) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVarClass::GetItem(const char* name) +CBotVar* CBotVarClass::GetItem(const std::string& name) { CBotVar* p = m_pVar; @@ -335,15 +335,15 @@ CBotVar* CBotVarClass::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarClass::GetValString() +std::string CBotVarClass::GetValString() { // if ( m_Indirect != nullptr) return m_Indirect->GetValString(); - CBotString res; + std::string res; if ( m_pClass != nullptr ) // not used for an array { - res = m_pClass->GetName() + CBotString("( "); + res = m_pClass->GetName() + std::string("( "); CBotVarClass* my = this; while ( my != nullptr ) @@ -351,7 +351,7 @@ CBotString CBotVarClass::GetValString() CBotVar* pv = my->m_pVar; while ( pv != nullptr ) { - res += pv->GetName() + CBotString("="); + res += pv->GetName() + std::string("="); if ( pv->IsStatic() ) { @@ -423,7 +423,7 @@ void CBotVarClass::DecrementUse() pThis->SetPointer(this); CBotVar* pResult = nullptr; - CBotString nom = CBotString("~") + m_pClass->GetName(); + std::string nom = std::string("~") + m_pClass->GetName(); long ident = 0; while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h index a04fccc7..7d564d91 100644 --- a/src/CBot/CBotVar/CBotVarClass.h +++ b/src/CBot/CBotVar/CBotVarClass.h @@ -70,7 +70,7 @@ public: * \param name * \return */ - CBotVar* GetItem(const char* name) override; + CBotVar* GetItem(const std::string& name) override; /*! * \brief GetItemRef @@ -98,7 +98,7 @@ public: * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Save1State diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index 29dbdae4..e5b41320 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -67,7 +67,7 @@ void CBotVarFloat::Copy(CBotVar* pSrc, bool bName) } //////////////////////////////////////////////////////////////////////////////// -void CBotVarFloat::SetValInt(int val, const char* s) +void CBotVarFloat::SetValInt(int val, const std::string& s) { m_val = static_cast(val); m_binit = CBotVar::InitType::DEF; @@ -93,9 +93,9 @@ float CBotVarFloat::GetValFloat() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarFloat::GetValString() +std::string CBotVarFloat::GetValString() { - CBotString res; + std::string res; if ( m_binit == CBotVar::InitType::UNDEF ) { diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index 37a121be..c8821a56 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -45,7 +45,7 @@ public: * \param val * \param s */ - void SetValInt(int val, const char* s = nullptr) override; + void SetValInt(int val, const std::string& s = nullptr) override; /*! * \brief SetValFloat @@ -69,7 +69,7 @@ public: * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Copy Copy a variable into another. diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 52b9e5ce..3e3a1827 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -66,7 +66,7 @@ void CBotVarInt::Copy(CBotVar* pSrc, bool bName) } //////////////////////////////////////////////////////////////////////////////// -void CBotVarInt::SetValInt(int val, const char* defnum) +void CBotVarInt::SetValInt(int val, const std::string& defnum) { m_val = val; m_binit = CBotVar::InitType::DEF; @@ -93,11 +93,11 @@ float CBotVarInt::GetValFloat() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarInt::GetValString() +std::string CBotVarInt::GetValString() { - if ( !m_defnum.IsEmpty() ) return m_defnum; + if ( !m_defnum.empty() ) return m_defnum; - CBotString res; + std::string res; if ( m_binit == CBotVar::InitType::UNDEF ) { @@ -216,27 +216,27 @@ void CBotVarInt::SR(CBotVar* left, CBotVar* right) //////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Neg() { - m_val = -m_val; + m_val = -m_val; } //////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Not() { - m_val = ~m_val; + m_val = ~m_val; } //////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Inc() { - m_val++; - m_defnum.Empty(); + m_val++; + m_defnum.empty(); } //////////////////////////////////////////////////////////////////////////////// void CBotVarInt::Dec() { - m_val--; - m_defnum.Empty(); + m_val--; + m_defnum.empty(); } //////////////////////////////////////////////////////////////////////////////// @@ -278,7 +278,7 @@ bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) //////////////////////////////////////////////////////////////////////////////// bool CBotVarInt::Save0State(FILE* pf) { - if ( !m_defnum.IsEmpty() ) + if ( !m_defnum.empty() ) { if(!WriteWord(pf, 200 )) return false; // special marker if(!WriteString(pf, m_defnum)) return false; // name of the value diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 0d8372e9..16da7882 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -45,7 +45,7 @@ public: * \param val * \param s */ - void SetValInt(int val, const char* s = nullptr) override; + void SetValInt(int val, const std::string& s = nullptr) override; /*! * \brief SetValFloat @@ -69,7 +69,7 @@ public: * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Copy Copy a variable in to another. @@ -250,6 +250,6 @@ private: //! The value. int m_val; //! The name if given by DefineNum. - CBotString m_defnum; + std::string m_defnum; friend class CBotVar; }; diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp index de0f1665..18b4d59e 100644 --- a/src/CBot/CBotVar/CBotVarPointer.cpp +++ b/src/CBot/CBotVar/CBotVarPointer.cpp @@ -23,9 +23,9 @@ #include "CBot/CBotClass.h" #include "CBot/CBotVar/CBotVarClass.h" -#include "CBot/CBotFileUtils.h" - #include "CBot/CBotEnums.h" +#include "CBot/CBotUtils.h" +#include "CBot/CBotFileUtils.h" // Local include @@ -71,7 +71,7 @@ void CBotVarPointer::Maj(void* pUser, bool bContinu) } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotVarPointer::GetItem(const char* name) +CBotVar* CBotVarPointer::GetItem(const std::string& name) { if ( m_pVarClass == nullptr) // no existing instance? return m_pClass->GetItem(name); // makes the pointer in the class itself @@ -96,9 +96,9 @@ CBotVar* CBotVarPointer::GetItemList() } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarPointer::GetValString() +std::string CBotVarPointer::GetValString() { - CBotString s = "Pointer to "; + std::string s = "Pointer to "; if ( m_pVarClass == nullptr ) s = "Null pointer" ; else s += m_pVarClass->GetValString(); return s; diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h index 8f54f58c..c7800bcb 100644 --- a/src/CBot/CBotVar/CBotVarPointer.h +++ b/src/CBot/CBotVar/CBotVarPointer.h @@ -71,7 +71,7 @@ public: * \param name * \return */ - CBotVar* GetItem(const char* name) override; + CBotVar* GetItem(const std::string& name) override; /*! * \brief GetItemRef @@ -90,7 +90,7 @@ public: * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief SetPointer Initializes the pointer to the instance of a class. diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp index 425733f5..5cf3d47e 100644 --- a/src/CBot/CBotVar/CBotVarString.cpp +++ b/src/CBot/CBotVar/CBotVarString.cpp @@ -43,7 +43,7 @@ CBotVarString::CBotVarString( const CBotToken* name ) m_bStatic = false; m_mPrivate = 0; - m_val.Empty(); + m_val.clear(); } //////////////////////////////////////////////////////////////////////////////// @@ -65,14 +65,14 @@ void CBotVarString::Copy(CBotVar* pSrc, bool bName) } //////////////////////////////////////////////////////////////////////////////// -void CBotVarString::SetValString(const char* p) +void CBotVarString::SetValString(const std::string& p) { m_val = p; m_binit = CBotVar::InitType::DEF; } //////////////////////////////////////////////////////////////////////////////// -CBotString CBotVarString::GetValString() +std::string CBotVarString::GetValString() { if ( m_binit == CBotVar::InitType::UNDEF ) { diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h index 662e1d96..b291c5e8 100644 --- a/src/CBot/CBotVar/CBotVarString.h +++ b/src/CBot/CBotVar/CBotVarString.h @@ -44,13 +44,13 @@ public: * \brief SetValString * \param p */ - void SetValString(const char* p) override; + void SetValString(const std::string& p) override; /*! * \brief GetValString * \return */ - CBotString GetValString() override; + std::string GetValString() override; /*! * \brief Copy Copy a variable into another. @@ -123,5 +123,5 @@ public: private: //! The value. - CBotString m_val; + std::string m_val; }; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 3f07eb5a..08f83568 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -5,12 +5,12 @@ set(SOURCES CBotProgram.cpp CBotStack.cpp CBotCStack.cpp - CBotString.cpp CBotToken.cpp CBotCall.cpp CBotDefParam.cpp CBotCallMethode.cpp CBotTypResult.cpp + CBotKeywordStrings.cpp StringFunctions.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotInstrUtils.cpp @@ -67,7 +67,7 @@ set(SOURCES CBotVar/CBotVarFloat.cpp CBotVar/CBotVarInt.cpp CBotVar/CBotVar.cpp - CBotKeywordStrings.cpp CBotKeywordStrings.h) +) # Includes set(LOCAL_INCLUDES diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp index e323fe34..7ffe4254 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/StringFunctions.cpp @@ -24,11 +24,13 @@ #include "CBot/CBotEnums.h" #include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotUtils.h" // Local include // Global include +#include //////////////////////////////////////////////////////////////////////////////// bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) @@ -43,10 +45,10 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // puts the length of the stack - pResult->SetValInt( s.GetLength() ); + pResult->SetValInt( s.length() ); return true; } @@ -77,7 +79,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); @@ -93,7 +95,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } // takes the interesting part - s = s.Left( n ); + s = s.substr(0, n); // puts on the stack pResult->SetValString( s ); @@ -135,7 +137,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); @@ -151,7 +153,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } // takes the interesting part - s = s.Right( n ); + s = s.substr(s.length()-n, std::string::npos); // puts on the stack pResult->SetValString( s ); @@ -168,7 +170,7 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); @@ -195,12 +197,12 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } // takes the interesting part - s = s.Mid( n, l ); + s = s.substr(n, l); } else { // takes the interesting part - s = s.Mid( n ); + s = s.substr(n); } // puts on the stack @@ -253,7 +255,7 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // but no second parameter if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } @@ -292,7 +294,7 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); @@ -302,14 +304,14 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // retrieves this number - CBotString s2 = pVar->GetValString(); + std::string s2 = pVar->GetValString(); // no third parameter if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } // puts the result on the stack - int res = s.Find(s2); - pResult->SetValInt( res ); + std::size_t res = s.find(s2); + pResult->SetValInt( res != std::string::npos ? res : -1 ); if ( res < 0 ) pResult->SetInit( CBotVar::InitType::IS_NAN ); return true; } @@ -349,13 +351,13 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // but no second parameter if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } - s.MakeUpper(); + boost::to_upper(s); // puts the value on the stack pResult->SetValString( s ); @@ -372,13 +374,13 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } // get the contents of the string - CBotString s = pVar->GetValString(); + std::string s = pVar->GetValString(); // but no second parameter if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } - s.MakeLower(); + boost::to_lower(s); // puts the value on the stack pResult->SetValString( s ); diff --git a/src/script/script.cpp b/src/script/script.cpp index 42d2fd63..4e70817c 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -158,8 +158,8 @@ bool CScript::CheckToken() { CBotToken* bt; CBotToken* allBt; - CBotString bs; - const char* token; + std::string bs; + std::string token; int error, cursor1, cursor2, i; char used[100]; @@ -186,13 +186,13 @@ bool CScript::CheckToken() cursor1 = bt->GetStart(); cursor2 = bt->GetEnd(); - i = m_main->IsObligatoryToken(token); + i = m_main->IsObligatoryToken(token.c_str()); if ( i != -1 ) { used[i] = 1; // token used } - if ( !m_main->IsProhibitedToken(token) ) + if ( !m_main->IsProhibitedToken(token.c_str()) ) { m_error = ERR_PROHIBITEDTOKEN; m_cursor1 = cursor1; @@ -228,9 +228,9 @@ bool CScript::CheckToken() bool CScript::Compile() { - std::vector functionList; + std::vector functionList; int i; - const char* p; + std::string p; m_error = 0; m_cursor1 = 0; @@ -486,8 +486,7 @@ bool CScript::IsContinue() bool CScript::GetCursor(int &cursor1, int &cursor2) { - const char* funcName; - + std::string funcName; cursor1 = cursor2 = 0; if (m_botProg == nullptr) return false; @@ -508,11 +507,10 @@ bool CScript::GetCursor(int &cursor1, int &cursor2) void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, int &rankList) { - CBotString bs; CBotVar *svar, *pStatic; char varName[100]; char buffer[100]; - const char *p; + std::string p; int index, type; if ( var == nullptr && baseName[0] != 0 ) @@ -528,8 +526,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i var->Maj(nullptr, false); pStatic = var->GetStaticVar(); // finds the static element - bs = pStatic->GetName(); // variable name - p = bs; + p = pStatic->GetName(); // variable name //? if ( strcmp(p, "this") == 0 ) //? { //? var = var->GetNext(); @@ -538,7 +535,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i if ( baseName[0] == 0 ) { - sprintf(varName, "%s", p); + sprintf(varName, "%s", p.c_str()); } else { @@ -548,7 +545,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i } else { - sprintf(varName, "%s.%s", baseName, p); + sprintf(varName, "%s.%s", baseName, p.c_str()); } } @@ -556,18 +553,14 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i if ( type < CBotTypBoolean ) { - CBotString value; - value = pStatic->GetValString(); - p = value; - sprintf(buffer, "%s = %s;", varName, p); + p = pStatic->GetValString(); + sprintf(buffer, "%s = %s;", varName, p.c_str()); list->SetItemName(rankList++, buffer); } else if ( type == CBotTypString ) { - CBotString value; - value = pStatic->GetValString(); - p = value; - sprintf(buffer, "%s = \"%s\";", varName, p); + p = pStatic->GetValString(); + sprintf(buffer, "%s = \"%s\";", varName, p.c_str()); list->SetItemName(rankList++, buffer); } else if ( type == CBotTypArrayPointer ) @@ -597,7 +590,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i void CScript::UpdateList(Ui::CList* list) { CBotVar *var; - const char *progName, *funcName; + std::string progName, funcName; int total, select, level, cursor1, cursor2, rank; if (m_botProg == nullptr) return; @@ -607,7 +600,7 @@ void CScript::UpdateList(Ui::CList* list) list->Flush(); // empty list m_botProg->GetRunPos(progName, cursor1, cursor2); - if ( progName == nullptr ) return; + if ( progName.empty() ) return; level = 0; rank = 0; @@ -646,8 +639,7 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd) CBotToken* bt = CBotToken::CompileTokens(text.c_str(), error); while ( bt != nullptr ) { - CBotString bs = bt->GetString(); - const char* token = bs; + std::string token = bt->GetString(); int type = bt->GetType(); int cursor1 = bt->GetStart(); @@ -659,15 +651,15 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd) cursor2 += rangeStart; Gfx::FontHighlight color = Gfx::FONT_HIGHLIGHT_NONE; - if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token)) // types (basic types are TokenKeyWord, classes are TokenTypVar) + if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token.c_str())) // types (basic types are TokenKeyWord, classes are TokenTypVar) { color = Gfx::FONT_HIGHLIGHT_TYPE; } - else if (type == TokenTypVar && IsFunction(token)) // functions + else if (type == TokenTypVar && IsFunction(token.c_str())) // functions { color = Gfx::FONT_HIGHLIGHT_TOKEN; } - else if (type == TokenTypVar && (strcmp(token, "this") == 0 || strcmp(token, "super") == 0)) // this, super + else if (type == TokenTypVar && (token == "this" || token == "super")) // this, super { color = Gfx::FONT_HIGHLIGHT_THIS; } diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index b2fce1c1..060dddc6 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -473,7 +473,7 @@ CBotTypResult CScriptFunctions::cPlayMusic(CBotVar* &var, void* user) bool CScriptFunctions::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user) { std::string filename; - CBotString cbs; + std::string cbs; bool repeat; cbs = var->GetValString(); @@ -703,13 +703,9 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul ObjectType type = static_cast(var->GetValInt()); var = var->GetNext(); - CBotString cbs; - const char* program; + std::string program; if ( var != nullptr ) - { - cbs = var->GetValString(); - program = cbs; - } + program = var->GetValString(); else program = ""; @@ -1584,8 +1580,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v if ( var != nullptr ) { - CBotString cbs = var->GetValString(); - name = static_cast(cbs); + name = var->GetValString(); var = var->GetNext(); if ( var != nullptr ) { @@ -2225,17 +2220,15 @@ CBotTypResult CScriptFunctions::cReceive(CBotVar* &var, void* user) bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user) { CScript* script = static_cast(user); - CBotString cbs; Error err; - const char* p; + std::string p; float power; exception = 0; if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress? { - cbs = var->GetValString(); - p = cbs; + p = var->GetValString(); var = var->GetNext(); power = 10.0f*g_unit; @@ -2245,7 +2238,7 @@ bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, v var = var->GetNext(); } - err = script->m_taskExecutor->StartTaskInfo(p, 0.0f, power, false); + err = script->m_taskExecutor->StartTaskInfo(p.c_str(), 0.0f, power, false); if ( err != ERR_OK ) { script->m_taskExecutor->StopForegroundTask(); @@ -2294,17 +2287,15 @@ CBotTypResult CScriptFunctions::cSend(CBotVar* &var, void* user) bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user) { CScript* script = static_cast(user); - CBotString cbs; Error err; - const char* p; + std::string p; float value, power; exception = 0; if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress? { - cbs = var->GetValString(); - p = cbs; + p = var->GetValString(); var = var->GetNext(); value = var->GetValFloat(); @@ -2317,7 +2308,7 @@ bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void var = var->GetNext(); } - err = script->m_taskExecutor->StartTaskInfo(static_cast(p), value, power, true); + err = script->m_taskExecutor->StartTaskInfo(p.c_str(), value, power, true); if ( err != ERR_OK ) { script->m_taskExecutor->StopForegroundTask(); @@ -2365,15 +2356,13 @@ bool CScriptFunctions::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception exception = 0; - CBotString infoNameCbs = var->GetValString(); - std::string infoName = std::string(static_cast(infoNameCbs)); + std::string infoName = var->GetValString(); var = var->GetNext(); float power = 10.0f*g_unit; if (var != nullptr) { power = var->GetValFloat()*g_unit; - var = var->GetNext(); } CExchangePost* exchangePost = FindExchangePost(pThis, power); @@ -2413,15 +2402,13 @@ bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception, exception = 0; - CBotString infoNameCbs = var->GetValString(); - std::string infoName = std::string(static_cast(infoNameCbs)); + std::string infoName = var->GetValString(); var = var->GetNext(); float power = 10.0f*g_unit; if (var != nullptr) { power = var->GetValFloat()*g_unit; - var = var->GetNext(); } CExchangePost* exchangePost = FindExchangePost(pThis, power); @@ -2813,12 +2800,10 @@ CBotTypResult CScriptFunctions::cMessage(CBotVar* &var, void* user) bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) { CScript* script = static_cast(user); - CBotString cbs; - const char* p; + std::string p; Ui::TextType type; - cbs = var->GetValString(); - p = cbs; + p = var->GetValString(); type = Ui::TT_MESSAGE; var = var->GetNext(); @@ -2827,7 +2812,7 @@ bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, v type = static_cast(var->GetValInt()); } - script->m_main->GetDisplayText()->DisplayText(p, script->m_object, 10.0f, type); + script->m_main->GetDisplayText()->DisplayText(p.c_str(), script->m_object, 10.0f, type); return true; } @@ -3157,22 +3142,22 @@ int CScriptFunctions::m_nextFile = 1; // Prepares a file name. -void PrepareFilename(CBotString &filename) +void PrepareFilename(std::string &filename) { CResourceManager::CreateDirectory("files"); - filename = CBotString("files/") + filename; - GetLogger()->Debug("CBot accessing file '%s'\n", static_cast(filename)); + filename = "files/" + filename; + GetLogger()->Debug("CBot accessing file '%s'\n", filename.c_str()); } bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) { - CBotString mode; + std::string mode; // must be a character string if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - CBotString filename = pVar->GetValString(); + std::string filename = pVar->GetValString(); PrepareFilename(filename); // there may be a second parameter @@ -3196,20 +3181,20 @@ bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* // which must not be initialized if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; } - if ( ! mode.IsEmpty() ) + if ( !mode.empty() ) { // opens the requested file bool ok = false; std::unique_ptr file; if (mode == "r") { - auto is = MakeUnique(static_cast(filename)); + auto is = MakeUnique(filename); ok = is->is_open(); file = std::move(is); } else if (mode == "w") { - auto os = MakeUnique(static_cast(filename)); + auto os = MakeUnique(filename); ok = os->is_open(); file = std::move(os); } @@ -3396,7 +3381,7 @@ bool CScriptFunctions::rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, // which must be a character string if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - CBotString param = pVar->GetValString(); + std::string param = pVar->GetValString(); // retrieve the item "handle" pVar = pThis->GetItem("handle"); @@ -3526,11 +3511,10 @@ CBotTypResult CScriptFunctions::cfeof (CBotVar* pThis, CBotVar* &pVar) bool CScriptFunctions::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user) { - CBotString cbs; + std::string filename; - cbs = var->GetValString(); - PrepareFilename(cbs); - std::string filename = static_cast(cbs); + filename = var->GetValString(); + PrepareFilename(filename); return CResourceManager::Remove(filename); } @@ -3773,7 +3757,7 @@ void CScriptFunctions::Init() bc->AddFunction("eof", CScriptFunctions::rfeof, CScriptFunctions::cfeof ); //m_pFuncFile = new CBotProgram( ); - //CBotStringArray ListFonctions; + //std::stringArray ListFonctions; //m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions); //m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp index 721105a7..fc0e5cc5 100644 --- a/test/cbot/console/main.cpp +++ b/test/cbot/console/main.cpp @@ -18,8 +18,7 @@ CBotTypResult cMessage(CBotVar* &var, void* user) bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) { - CBotString cbs = var->GetValString(); - const char* message = cbs; // Don't ask me why, but it doesn't work if you write it on a single line + std::string message = var->GetValString(); std::cout << message << std::endl; @@ -44,7 +43,7 @@ int main(int argc, char* argv[]) CBotProgram::AddFunction("message", rMessage, cMessage); // Compile the program - std::vector externFunctions; + std::vector externFunctions; std::unique_ptr program{new CBotProgram(nullptr)}; if (!program->Compile(code.c_str(), externFunctions, nullptr)) { @@ -63,7 +62,7 @@ int main(int argc, char* argv[]) return 2; } bool runErrors = false; - for (const char* func : externFunctions) + for (const std::string& func : externFunctions) { if (!program->Start(func)) { diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp deleted file mode 100644 index c058cfd6..00000000 --- a/test/unit/CBot/CBotString_test.cpp +++ /dev/null @@ -1,399 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -// Modules inlcude -#include "CBot/CBotString.h" - -// Local include - -// Global include -#include - -/** - * @brief CBotString_Test.Empty Check Empty and IsEmpty functions of class - * CBotString_Test. - */ -TEST(CBotString_Test, Empty) -{ - CBotString str1; - EXPECT_EQ(true, str1.IsEmpty()); - - CBotString str2("qsexrdctfvygbuh"); - EXPECT_EQ(false, str2.IsEmpty()); - str2.Empty(); - EXPECT_EQ(true, str2.IsEmpty()); -} - -/** - * @brief CBotString_Test.Length Check GetLength function of class - * CBotString_Test. - */ -TEST(CBotString_Test, Length) -{ - CBotString str1; - EXPECT_EQ(0, str1.GetLength()); - - CBotString str2("a"); - EXPECT_EQ(1, str2.GetLength()); - - CBotString str3("aaaaa"); - EXPECT_EQ(5, str3.GetLength()); -} - -/** - * @brief CBotString_Test.Find Check find functions of class CBotString_Test - */ -TEST(CBotString_Test, Find) -{ - CBotString str1("a"); - EXPECT_EQ(0, str1.Find('a')); - - CBotString str2("b"); - EXPECT_EQ(-1, str2.Find('a')); - - CBotString str3("bbabb"); - EXPECT_EQ(2, str3.Find('a')); - - CBotString str4("bbAbb"); - EXPECT_EQ(-1, str4.Find('a')); - - CBotString str5("bbAbb"); - EXPECT_EQ(2, str5.Find('A')); - - CBotString str6("test"); - EXPECT_EQ(0, str6.Find("test")); - - CBotString str7("azazdazd"); - EXPECT_EQ(-1, str7.Find("test")); - - CBotString str8("bbtestbb"); - EXPECT_EQ(2, str8.Find("test")); - - CBotString str9("bbTestbb"); - EXPECT_EQ(-1, str9.Find("test")); - - CBotString str10("bbTestbb"); - EXPECT_EQ(2, str10.Find("Test")); -} - -/** - * @brief CBotString_Test.ReverseFind Check find functions of class - * CBotString_Test - */ -TEST(CBotString_Test, ReverseFind) -{ - CBotString str1("a"); - EXPECT_EQ(0, str1.ReverseFind('a')); - - CBotString str2("b"); - EXPECT_EQ(-1, str2.ReverseFind('a')); - - CBotString str3("bbabb"); - EXPECT_EQ(2, str3.ReverseFind('a')); - - CBotString str4("bbAbb"); - EXPECT_EQ(-1, str4.ReverseFind('a')); - - CBotString str5("bbAbb"); - EXPECT_EQ(2, str5.ReverseFind('A')); - - CBotString str6("test"); - EXPECT_EQ(0, str6.ReverseFind("test")); - - CBotString str7("azazdazd"); - EXPECT_EQ(-1, str7.ReverseFind("test")); - - CBotString str8("bbtestbb"); - EXPECT_EQ(2, str8.ReverseFind("test")); - - CBotString str9("bbTestbb"); - EXPECT_EQ(-1, str9.ReverseFind("test")); - - CBotString str10("bbTestbb"); - EXPECT_EQ(2, str10.ReverseFind("Test")); -} - -/** - * @brief CBotString_Test.Mid Check Mid functions of class CBotString_Test - */ -TEST(CBotString_Test, Mid) -{ - CBotString str1("aaaColobot"); - EXPECT_STREQ(str1.Mid(3).CStr(), "Colobot"); - - CBotString str2("aaaColobotaa"); - EXPECT_STREQ(str2.Mid(3,7).CStr(), "Colobot"); -} - -/** - * @brief CBotString_Test.Left Check Left function of class CBotString_Test - */ -TEST(CBotString_Test, Left) -{ - CBotString str1("Colobotaaa"); - EXPECT_STREQ(str1.Left(7).CStr(), "Colobot"); -} - -/** - * @brief CBotString_Test.Right Check Right function of class CBotString_Test - */ -TEST(CBotString_Test, Right) -{ - CBotString str1("aaaColobot"); - EXPECT_STREQ(str1.Right(7).CStr(), "Colobot"); -} - -/** - * @brief CBotString_Test.MakeUpper Check MakeUpper function of class - * CBotString_Test - */ -TEST(CBotString_Test, MakeUpper) -{ - CBotString str1("colobot"); - str1.MakeUpper(); - EXPECT_STREQ(str1.CStr(), "COLOBOT"); - - CBotString str2("Colobot"); - str2.MakeUpper(); - EXPECT_STREQ(str2.CStr(), "COLOBOT"); -} - -/** - * @brief CBotString_Test.MakeLower Check MakeLower function of class - * CBotString_Test - */ -TEST(CBotString_Test, MakeLower) -{ - CBotString str1("COLOBOT"); - str1.MakeLower(); - EXPECT_STREQ(str1.CStr(), "colobot"); - - CBotString str2("Colobot"); - str2.MakeLower(); - EXPECT_STREQ(str2.CStr(), "colobot"); -} - -/** - * @brief CBotString_Test.operatorEqual Check operator equal of class - * CBotString_Test - */ -TEST(CBotString_Test, operatorEqual) -{ - //-- CBotString - CBotString botStr1; - CBotString botStr2("Colobot"); - - //-- C Character - const char cStr1[2] = "C"; - - //-- C string - const char cStr2[8] = "Colobot"; - - //-- Compare with CBotString - botStr1 = botStr2; - EXPECT_STREQ(botStr1.CStr(), botStr2.CStr()); - - //-- Compare with C character - botStr1 = cStr1[0]; - EXPECT_STREQ(botStr1.CStr(), cStr1); - - //-- Compare with C string - botStr1 = cStr2; - EXPECT_STREQ(botStr1.CStr(), cStr2); - -} - -/** - * @brief CBotString_Test.operatorIsEqual Check operator is equal of class - * CBotString_Test - */ -TEST(CBotString_Test, operatorIsEqual) -{ - //-- CBotString - CBotString botStr1("C"); - CBotString botStr2("C"); - CBotString botStr3("Colobot"); - - //-- C string - const char cStr1[8] = "Colobot"; - const char cStr2[8] = "colobot"; - - EXPECT_EQ(true, (botStr1 == botStr2)); - EXPECT_EQ(false, (botStr1 == botStr3)); - - //-- Compare with C string - EXPECT_EQ(true, (botStr3 == cStr1)); - EXPECT_EQ(false, (botStr3 == cStr2)); -} - -/** - * @brief CBotString_Test.operatorAdd Check operator add of class - * CBotString_Test. - */ -TEST(CBotString_Test, operatorAdd) -{ - //-- CBotString - CBotString botStr1; - CBotString botStr2("C"); - CBotString botStr3("olobot"); - CBotString botStr4("Colobot"); - - //-- C string - const char* cStr1 = "olobot"; - - botStr1 = botStr1 + botStr2; - botStr1 = botStr1 + botStr3; - EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); - - botStr1.Empty(); - botStr1 = botStr2 + cStr1; - EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); - - botStr1.Empty(); - botStr1 += botStr2; - botStr1 += botStr3; - EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); - - - botStr1.Empty(); - botStr1 += botStr2; - botStr1 += cStr1; - EXPECT_STREQ(botStr1.CStr(), botStr4.CStr()); -} - -/** - * @brief CBotString_Test.operatorDiff Check operator diff of class - * CBotString_Test. - */ -TEST(CBotString_Test, operatorDiff) -{ - //-- CBotString - CBotString botStr1("C"); - CBotString botStr2("C"); - CBotString botStr3("Colobot"); - - //-- C string - const char cStr1[8] = "Colobot"; - const char cStr2[8] = "colobot"; - - EXPECT_EQ(false, (botStr1 != botStr2)); - EXPECT_EQ(true, (botStr1 != botStr3)); - - //-- Compare with C string - EXPECT_EQ(false, (botStr3 != cStr1)); - EXPECT_EQ(true, (botStr3 != cStr2)); -} - -/** - * @brief CBotString_Test.operatorSuperior Check operator superior of class - * CBotString_Test. - */ -TEST(CBotString_Test, operatorSuperior) -{ - //-- CBotString - CBotString botStr1("a"); - CBotString botStr2("z"); - CBotString botStr3("colobot"); - - //-- C string - const char cStr1[2] = "a"; - const char cStr2[2] = "z"; - - EXPECT_EQ(true, (botStr3 > botStr1)); - EXPECT_EQ(false, (botStr3 > botStr2)); - - //-- Compare with C string - EXPECT_EQ(true, (botStr3 > cStr1)); - EXPECT_EQ(false, (botStr3 > cStr2)); -} - -/** - * @brief CBotString_Test.operatorSuperiorOrEqual Check operator superior or - * equa of class CBotString_Test. - */ -TEST(CBotString_Test, operatorSuperiorOrEqual) -{ - //-- CBotString - CBotString botStr1("a"); - CBotString botStr2("z"); - CBotString botStr3("colobot"); - - //-- C string - const char cStr1[2] = "a"; - const char cStr2[2] = "z"; - const char cStr3[8] = "colobot"; - - EXPECT_EQ(true, (botStr3 >= botStr1)); - EXPECT_EQ(false, (botStr3 >= botStr2)); - EXPECT_EQ(true, (botStr3 >= botStr3)); - - //-- Compare with C string - EXPECT_EQ(true, (botStr3 >= cStr1)); - EXPECT_EQ(false, (botStr3 >= cStr2)); - EXPECT_EQ(true, (botStr3 >= cStr3)); -} - -/** - * @brief CBotString_Test.operatorInferior Check operator Inferior of class - * CBotString_Test. - */ -TEST(CBotString_Test, operatorInferior) -{ - //-- CBotString - CBotString botStr1("a"); - CBotString botStr2("z"); - CBotString botStr3("colobot"); - - //-- C string - const char cStr1[2] = "a"; - const char cStr2[2] = "z"; - - EXPECT_EQ(false, (botStr3 < botStr1)); - EXPECT_EQ(true, (botStr3 < botStr2)); - - //-- Compare with C string - EXPECT_EQ(false, (botStr3 < cStr1)); - EXPECT_EQ(true, (botStr3 < cStr2)); -} - -/** - * @brief CBotString_Test.operatorInferiorOrEqual Check operator Inferior or - * equa of class CBotString_Test. - */ -TEST(CBotString_Test, operatorInferiorOrEqual) -{ - //-- CBotString - CBotString botStr1("a"); - CBotString botStr2("z"); - CBotString botStr3("colobot"); - - //-- C string - const char cStr1[2] = "a"; - const char cStr2[2] = "z"; - const char cStr3[8] = "colobot"; - - EXPECT_EQ(false, (botStr3 <= botStr1)); - EXPECT_EQ(true, (botStr3 <= botStr2)); - EXPECT_EQ(true, (botStr3 <= botStr3)); - - //-- Compare with C string - EXPECT_EQ(false, (botStr3 <= cStr1)); - EXPECT_EQ(true, (botStr3 <= cStr2)); - EXPECT_EQ(true, (botStr3 <= cStr3)); -} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 5bdc38a4..f12c3a22 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,7 +15,6 @@ set(UT_SOURCES math/geometry_test.cpp math/matrix_test.cpp math/vector_test.cpp - CBot/CBotString_test.cpp ${PLATFORM_TESTS} ) From 97558530ce1ee0a5739c57e84f6886805aff9532 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 16:21:45 +0100 Subject: [PATCH 156/360] Updated data submodule --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 827c18d1..64d56c3a 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 827c18d17395ed886e999967551b50e2a5079ac4 +Subproject commit 64d56c3a4ad85caa349af9b1a88a4b12f4f1443c From 22e963e2c4dbd4da840f643dd4c6971df5c3f1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sun, 20 Dec 2015 17:34:55 +0100 Subject: [PATCH 157/360] Added information about graphics card to error message --- src/graphics/opengl/gl21device.cpp | 3 ++- src/graphics/opengl/gl33device.cpp | 3 ++- src/graphics/opengl/gldevice.cpp | 3 ++- src/graphics/opengl/glutil.cpp | 24 ++++++++++++++++++++++++ src/graphics/opengl/glutil.h | 4 ++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index bd8f2726..6b4327ad 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -191,7 +191,8 @@ bool CGL21Device::Create() GetLogger()->Error("OpenGL 2.0 or newer is required to use this engine.\n"); m_errorMessage = "It seems your graphics card does not support OpenGL 2.0.\n"; m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; - m_errorMessage += "(OpenGL 2.0 is roughly equivalent to Direct3D 9)"; + m_errorMessage += "(OpenGL 2.0 is roughly equivalent to Direct3D 9)\n\n"; + m_errorMessage += GetHardwareInfo(false); return false; } diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index 1560cc8c..8799013c 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -192,7 +192,8 @@ bool CGL33Device::Create() GetLogger()->Error("OpenGL 3.0 or newer is required to use this engine.\n"); m_errorMessage = "It seems your graphics card does not support OpenGL 3.0.\n"; m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; - m_errorMessage += "(OpenGL 3.0 is roughly equivalent to Direct3D 10)"; + m_errorMessage += "(OpenGL 3.0 is roughly equivalent to Direct3D 10)\n\n"; + m_errorMessage += GetHardwareInfo(false); return false; } else if (glVersion < 33) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 4eba81a6..5aeab5f3 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -187,7 +187,8 @@ bool CGLDevice::Create() GetLogger()->Error("Unsupported OpenGL version: %d.%d\n", m_glMajor, m_glMinor); GetLogger()->Error("OpenGL 1.3 or newer is required to use this engine.\n"); m_errorMessage = "It seems your graphics card does not support OpenGL 1.3.\n"; - m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n"; + m_errorMessage += "Please make sure you have appropriate hardware and newest drivers installed.\n\n"; + m_errorMessage += GetHardwareInfo(false); return false; } diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index 75f2a9ff..41caf2e6 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -73,6 +73,30 @@ int GetOpenGLVersion() return 10 * major + minor; } +std::string GetHardwareInfo(bool full) +{ + int glversion = GetOpenGLVersion(); + + const char* version = reinterpret_cast(glGetString(GL_VERSION)); + const char* vendor = reinterpret_cast(glGetString(GL_VENDOR)); + const char* renderer = reinterpret_cast(glGetString(GL_RENDERER)); + + std::string result; + + result += std::string("Hardware information:\n\n"); + result += "Version:\t" + std::string(version) + '\n'; + result += "Vendor:\t" + std::string(vendor) + '\n'; + result += "Renderer:\t" + std::string(renderer) + '\n'; + + if (glversion >= 20) + { + const char* glslVersion = reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + result += "Shading Language:\t" + std::string(glslVersion) + '\n'; + } + + return result; +} + GLenum TranslateGfxPrimitive(PrimitiveType type) { GLenum flag = 0; diff --git a/src/graphics/opengl/glutil.h b/src/graphics/opengl/glutil.h index 2b451c46..1c23140e 100644 --- a/src/graphics/opengl/glutil.h +++ b/src/graphics/opengl/glutil.h @@ -30,6 +30,7 @@ #include +#include #include @@ -53,6 +54,9 @@ std::unique_ptr CreateDevice(const DeviceConfig &config, const std::str // First digit is major part, second digit is minor part. int GetOpenGLVersion(); +//! Returns information about graphics card +std::string GetHardwareInfo(bool full); + //! Translate Gfx primitive type to OpenGL primitive type GLenum TranslateGfxPrimitive(PrimitiveType type); From 51644369cbd3886132da70466202d1b7c99a499e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 18:35:52 +0100 Subject: [PATCH 158/360] Moved standard math and file functions into CBot library --- po/colobot.pot | 18 + po/de.po | 36 +- po/fr.po | 36 +- po/pl.po | 36 +- po/ru.po | 36 +- src/CBot/CBot.h | 5 +- src/CBot/CBotDefines.h | 13 +- src/CBot/CBotProgram.cpp | 17 +- src/CBot/CMakeLists.txt | 5 +- src/CBot/StringFunctions.h | 137 ---- src/CBot/stdlib/Compilation.cpp | 217 +++++ src/CBot/stdlib/Compilation.h | 37 + src/CBot/stdlib/FileFunctions.cpp | 375 +++++++++ src/CBot/stdlib/MathFunctions.cpp | 189 +++++ src/CBot/{ => stdlib}/StringFunctions.cpp | 140 +--- src/CBot/stdlib/stdlib.h | 7 + src/CBot/stdlib/stdlib_public.h | 34 + src/common/restext.cpp | 6 + src/level/robotmain.cpp | 2 +- src/script/scriptfunc.cpp | 923 +++++----------------- src/script/scriptfunc.h | 47 +- 21 files changed, 1166 insertions(+), 1150 deletions(-) delete mode 100644 src/CBot/StringFunctions.h create mode 100644 src/CBot/stdlib/Compilation.cpp create mode 100644 src/CBot/stdlib/Compilation.h create mode 100644 src/CBot/stdlib/FileFunctions.cpp create mode 100644 src/CBot/stdlib/MathFunctions.cpp rename src/CBot/{ => stdlib}/StringFunctions.cpp (65%) create mode 100644 src/CBot/stdlib/stdlib.h create mode 100644 src/CBot/stdlib/stdlib_public.h diff --git a/po/colobot.pot b/po/colobot.pot index 453930ac..28315a39 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -1712,6 +1712,9 @@ msgstr "" msgid "Bad argument for \"new\"" msgstr "" +msgid "\" [ \" expected" +msgstr "" + msgid "String missing" msgstr "" @@ -1733,6 +1736,9 @@ msgstr "" msgid "Negative value rejected by \"throw\"" msgstr "" +msgid "The function returned no value " +msgstr "" + msgid "No function running" msgstr "" @@ -1757,5 +1763,17 @@ msgstr "" msgid "Illegal object" msgstr "" +msgid "Can't open file" +msgstr "" + +msgid "File not open" +msgstr "" + +msgid "Read error" +msgstr "" + +msgid "Write error" +msgstr "" + msgid "Button %1" msgstr "" diff --git a/po/de.po b/po/de.po index ce9cf97a..ad1ac8cc 100644 --- a/po/de.po +++ b/po/de.po @@ -55,6 +55,9 @@ msgstr " Zusammenfassung:" msgid " or " msgstr " oder " +msgid "\" [ \" expected" +msgstr "Es fehlt eine offene eckige Klammer \" [ \"" + msgid "\" ] \" missing" msgstr "Es fehlt eine geschlossene eckige Klammer \" ] \"" @@ -352,6 +355,9 @@ msgstr "Das erforschte Objekt kann nicht produziert werden" msgid "Can not produce this object in this mission" msgstr "Das Objekt kann in dieser Mission nicht produziert werden" +msgid "Can't open file" +msgstr "Die Datei kann nicht geöffnet werden" + msgid "Cancel" msgstr "Abbrechen" @@ -548,6 +554,9 @@ msgstr "Brille:" msgid "Face type:" msgstr "Kopf:" +msgid "File not open" +msgstr "Die Datei wurde nicht geöffnet" + msgid "Filename:" msgstr "Dateiname:" @@ -1164,6 +1173,9 @@ msgstr "Mission verlassen\\Eine Mission oder Übung verlassen" msgid "Radar station" msgstr "Radar" +msgid "Read error" +msgstr "Fehler beim Lesezugriff" + msgid "Recorder" msgstr "Recorder" @@ -1460,6 +1472,9 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Der Ausdruck muss einen boolschen Wert ergeben" +msgid "The function returned no value " +msgstr "Die Funktion hat kein Ergebnis zurückgegeben" + msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1664,6 +1679,9 @@ msgstr "Wurm tödlich verwundet" msgid "Wreckage" msgstr "Roboterwrack" +msgid "Write error" +msgstr "Fehler beim Schreibzugriff" + msgid "Wrong type for the assignment" msgstr "Der Ausdruck ergibt einen falschen Typ für die Zuweisung" @@ -1799,9 +1817,6 @@ msgstr "www.epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Missionen des Userlevels:" -#~ msgid "\" [ \" expected" -#~ msgstr "Es fehlt eine offene eckige Klammer \" [ \"" - #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-Geräusche\\Orten der Geräusche im Raum" @@ -1814,9 +1829,6 @@ msgstr "www.epsitec.com" #~ msgid "Can not create this; there are too many objects" #~ msgstr "Kein neues Objekt kann erstellt werden (zu viele vorhanden)" -#~ msgid "Can't open file" -#~ msgstr "Die Datei kann nicht geöffnet werden" - #~ msgid "Cancel\\Keep current player name" #~ msgstr "Abbrechen\\Behält den bisherigen Spieler bei" @@ -1845,9 +1857,6 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Zurücksetzen \\Kleine Show beim Zurücksetzen in den Übungen" -#~ msgid "File not open" -#~ msgstr "Die Datei wurde nicht geöffnet" - #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Eigenbeschuss\\Ihre Einheiten werden von Ihren Waffen beschädigt" @@ -1887,9 +1896,6 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Schließen\\COLOBOT schließen" -#~ msgid "Read error" -#~ msgstr "Fehler beim Lesezugriff" - #~ msgid "Robbie\\Your assistant" #~ msgstr "Robby\\Ihr Assistent" @@ -1908,9 +1914,6 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualität der Texturen\\Qualität der Anzeige" -#~ msgid "The function returned no value " -#~ msgstr "Die Funktion hat kein Ergebnis zurückgegeben" - #~ msgid "" #~ "The list is only available if a \\l;radar station\\u object\\radar; is " #~ "working.\n" @@ -1919,9 +1922,6 @@ msgstr "www.epsitec.com" #~ msgid "User\\User levels" #~ msgstr "User\\Userlevels" -#~ msgid "Write error" -#~ msgstr "Fehler beim Schreibzugriff" - #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Zurück zu COLOBOT" diff --git a/po/fr.po b/po/fr.po index ed5d83d4..6ed78e66 100644 --- a/po/fr.po +++ b/po/fr.po @@ -48,6 +48,9 @@ msgstr " Résumé :" msgid " or " msgstr " ou " +msgid "\" [ \" expected" +msgstr "\" [ \" attendu" + msgid "\" ] \" missing" msgstr "\" ] \" attendu" @@ -349,6 +352,9 @@ msgstr "Impossible de créer un objet n'ayant pas été recherché" msgid "Can not produce this object in this mission" msgstr "Impossible de créer cet objet dans cette mission" +msgid "Can't open file" +msgstr "Ouverture du fichier impossible" + msgid "Cancel" msgstr "Annuler" @@ -543,6 +549,9 @@ msgstr "Lunettes :" msgid "Face type:" msgstr "Type de visage :" +msgid "File not open" +msgstr "Le fichier n'est pas ouvert" + msgid "Filename:" msgstr "Nom du fichier :" @@ -1155,6 +1164,9 @@ msgstr "Quitter la mission en cours\\Terminer un exercice ou une mssion" msgid "Radar station" msgstr "Radar" +msgid "Read error" +msgstr "Erreur à la lecture" + msgid "Recorder" msgstr "Enregistreur" @@ -1445,6 +1457,9 @@ msgstr "Textures" msgid "The expression must return a boolean value" msgstr "L'expression doit ętre un boolean" +msgid "The function returned no value " +msgstr "La fonction n'a pas retourné de résultat" + msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1650,6 +1665,9 @@ msgstr "Ver mortellement touché" msgid "Wreckage" msgstr "Epave de robot" +msgid "Write error" +msgstr "Erreur à l'écriture" + msgid "Wrong type for the assignment" msgstr "Mauvais type de résultat pour l'assignation" @@ -1786,9 +1804,6 @@ msgstr "www.epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Missions du niveau :" -#~ msgid "\" [ \" expected" -#~ msgstr "\" [ \" attendu" - #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Bruitages 3D\\Positionnement sonore dans l'espace" @@ -1801,9 +1816,6 @@ msgstr "www.epsitec.com" #~ msgid "Can not create this; there are too many objects" #~ msgstr "Création impossible; il y a trop d'objets" -#~ msgid "Can't open file" -#~ msgstr "Ouverture du fichier impossible" - #~ msgid "Cancel\\Keep current player name" #~ msgstr "Annuler\\Conserver le joueur actuel" @@ -1832,9 +1844,6 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Retour animé\\Retour animé dans les exercices" -#~ msgid "File not open" -#~ msgstr "Le fichier n'est pas ouvert" - #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Dégâts à soi-même\\Vos tirs infligent des dommages à vos unités" @@ -1874,9 +1883,6 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Quitter\\Quitter COLOBOT" -#~ msgid "Read error" -#~ msgstr "Erreur à la lecture" - #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Votre assistant" @@ -1895,9 +1901,6 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Qualité des textures\\Qualité des images" -#~ msgid "The function returned no value " -#~ msgstr "La fonction n'a pas retourné de résultat" - #~ msgid "" #~ "The list is only available if a \\l;radar station\\u object\\radar; is " #~ "working.\n" @@ -1906,9 +1909,6 @@ msgstr "www.epsitec.com" #~ msgid "User\\User levels" #~ msgstr "Suppl.\\Niveaux supplémentaires" -#~ msgid "Write error" -#~ msgstr "Erreur à l'écriture" - #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Retourner dans COLOBOT" diff --git a/po/pl.po b/po/pl.po index d4572786..4180c418 100644 --- a/po/pl.po +++ b/po/pl.po @@ -54,6 +54,9 @@ msgstr " Streszczenie:" msgid " or " msgstr " lub " +msgid "\" [ \" expected" +msgstr "Oczekiwane \" [ \"" + msgid "\" ] \" missing" msgstr "Brak \" ] \"" @@ -355,6 +358,9 @@ msgstr "Nie można wyprodukować nie wynalezionego obiektu" msgid "Can not produce this object in this mission" msgstr "Nie można utworzyć tego obiektu w tej misji" +msgid "Can't open file" +msgstr "Nie można otworzyć pliku" + msgid "Cancel" msgstr "Anuluj" @@ -549,6 +555,9 @@ msgstr "Okulary:" msgid "Face type:" msgstr "Rodzaj twarzy:" +msgid "File not open" +msgstr "Plik nie jest otwarty" + msgid "Filename:" msgstr "Nazwa pliku:" @@ -1163,6 +1172,9 @@ msgstr "Zakończ\\Kończy bieżącą misję lub ćwiczenie" msgid "Radar station" msgstr "Stacja radarowa" +msgid "Read error" +msgstr "Błąd odczytu" + msgid "Recorder" msgstr "Nagrywanie" @@ -1453,6 +1465,9 @@ msgstr "Tekstury" msgid "The expression must return a boolean value" msgstr "Wyrażenie musi zwrócić wartość logiczną" +msgid "The function returned no value " +msgstr "Funkcja nie zwróciła żadnej wartości " + msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "Misja nie jest wypełniona (naciśnij \\key help; aby uzyskać szczegóły)" @@ -1655,6 +1670,9 @@ msgstr "Robal śmiertelnie raniony" msgid "Wreckage" msgstr "Wrak" +msgid "Write error" +msgstr "Błąd zapisu" + msgid "Wrong type for the assignment" msgstr "Zły typ dla przypisania" @@ -1784,9 +1802,6 @@ msgstr "www.epsitec.com" #~ msgid " Drivers:" #~ msgstr " Sterowniki:" -#~ msgid "\" [ \" expected" -#~ msgstr "Oczekiwane \" [ \"" - #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "Dźwięk 3D\\Przestrzenne pozycjonowanie dźwięków" @@ -1796,9 +1811,6 @@ msgstr "www.epsitec.com" #~ msgid "Can not create this; there are too many objects" #~ msgstr "Nie można tego utworzyć, za dużo obiektów" -#~ msgid "Can't open file" -#~ msgstr "Nie można otworzyć pliku" - #~ msgid "Cancel\\Keep current player name" #~ msgstr "Anuluj\\Zachowuje bieżące imię gracza" @@ -1823,9 +1835,6 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Końcowy film\\Film na zakończenie ćwiczeń" -#~ msgid "File not open" -#~ msgstr "Plik nie jest otwarty" - #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Przyjacielski ogień\\Własne strzały uszkadzają Twoje obiekty" @@ -1867,9 +1876,6 @@ msgstr "www.epsitec.com" #~ msgid "Quit the mission?" #~ msgstr "Opuścić misję?" -#~ msgid "Read error" -#~ msgstr "Błąd odczytu" - #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Twój asystent" @@ -1885,9 +1891,6 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Tekstury\\Jakość tekstur " -#~ msgid "The function returned no value " -#~ msgstr "Funkcja nie zwróciła żadnej wartości " - #~ msgid "" #~ "The list is only available if a \\l;radar station\\u object\\radar; is " #~ "working.\n" @@ -1895,9 +1898,6 @@ msgstr "www.epsitec.com" #~ "Lista jest dostępna jedynie gdy działa \\l;stacja radarowa\\u object" #~ "\\radar;.\n" -#~ msgid "Write error" -#~ msgstr "Błąd zapisu" - #~ msgid "\\b;Aliens\n" #~ msgstr "\\b;Obcy\n" diff --git a/po/ru.po b/po/ru.po index dad69058..2248e642 100644 --- a/po/ru.po +++ b/po/ru.po @@ -53,6 +53,9 @@ msgstr " Итог:" msgid " or " msgstr " или " +msgid "\" [ \" expected" +msgstr "Ожидалось \" [ \"" + msgid "\" ] \" missing" msgstr "Отсутствует \"]\" " @@ -347,6 +350,9 @@ msgstr "" msgid "Can not produce this object in this mission" msgstr "" +msgid "Can't open file" +msgstr "Невозможно открыть файл" + msgid "Cancel" msgstr "Отмена" @@ -542,6 +548,9 @@ msgstr "Очки:" msgid "Face type:" msgstr "Лицо:" +msgid "File not open" +msgstr "Файл не открыт" + msgid "Filename:" msgstr "Имя файла:" @@ -1160,6 +1169,9 @@ msgstr "Выход\\Выход из текущей миссии" msgid "Radar station" msgstr "Радар" +msgid "Read error" +msgstr "Ошибка чтения" + msgid "Recorder" msgstr "Запись" @@ -1452,6 +1464,9 @@ msgstr "" msgid "The expression must return a boolean value" msgstr "Выражение должно возвращать логическое значение" +msgid "The function returned no value " +msgstr "Функция не возвратила значения" + msgid "" "The mission is not accomplished yet (press \\key help; for more details)" msgstr "" @@ -1655,6 +1670,9 @@ msgstr "Червь смертельно ранен" msgid "Wreckage" msgstr "Обломки" +msgid "Write error" +msgstr "Ошибка записи" + msgid "Wrong type for the assignment" msgstr "Неверный тип для назначения" @@ -1790,9 +1808,6 @@ msgstr "www.epsitec.com" #~ msgid " Missions on this level:" #~ msgstr " Миссии на этом уровне:" -#~ msgid "\" [ \" expected" -#~ msgstr "Ожидалось \" [ \"" - #~ msgid "3D sound\\3D positioning of the sound" #~ msgstr "3D-звук\\Стерео звук" @@ -1805,9 +1820,6 @@ msgstr "www.epsitec.com" #~ msgid "Can not create this; there are too many objects" #~ msgstr "Не удается это создать, слишком много объектов" -#~ msgid "Can't open file" -#~ msgstr "Невозможно открыть файл" - #~ msgid "Cancel\\Keep current player name" #~ msgstr "Отмена\\Отмена" @@ -1836,9 +1848,6 @@ msgstr "www.epsitec.com" #~ msgid "Exit film\\Film at the exit of exercises" #~ msgstr "Ролик при выходе\\Ролик во время выхода из упражнения" -#~ msgid "File not open" -#~ msgstr "Файл не открыт" - #~ msgid "Friendly fire\\Your shooting can damage your own objects " #~ msgstr "Огонь по своим\\Вы можете повредить собственные объекты" @@ -1878,9 +1887,6 @@ msgstr "www.epsitec.com" #~ msgid "Quit\\Quit COLOBOT" #~ msgstr "Выход\\Выход из COLOBOT" -#~ msgid "Read error" -#~ msgstr "Ошибка чтения" - #~ msgid "Robbie\\Your assistant" #~ msgstr "Робби\\Ваш помощник" @@ -1899,9 +1905,6 @@ msgstr "www.epsitec.com" #~ msgid "Textures\\Quality of textures " #~ msgstr "Текстуры\\Качество текстур " -#~ msgid "The function returned no value " -#~ msgstr "Функция не возвратила значения" - #~ msgid "" #~ "The list is only available if a \\l;radar station\\u object\\radar; is " #~ "working.\n" @@ -1911,9 +1914,6 @@ msgstr "www.epsitec.com" #~ msgid "User\\User levels" #~ msgstr "Польз.\\Пользовательские уровни" -#~ msgid "Write error" -#~ msgstr "Ошибка записи" - #~ msgid "\\Return to COLOBOT" #~ msgstr "\\Вернуться в COLOBOT" diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 4ba45b0e..3f590057 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -23,7 +23,6 @@ * that should be included by any Colobot files outside of the CBot module. */ -// Modules inlcude #include "CBot/CBotFileUtils.h" #include "CBot/CBotClass.h" #include "CBot/CBotToken.h" @@ -32,6 +31,4 @@ #include "CBot/CBotVar/CBotVar.h" -// Local include - -// Global include +#include "CBot/stdlib/stdlib_public.h" diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 93be12bb..514e733d 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -53,6 +53,8 @@ // Error Handling of compilation and execution //////////////////////////////////////////////////////////////////////// +// TODO: Why are all of those duplicated? This needs to be unified across the source code ~krzys_h + // Here are the list of errors that can be returned by the module // for compilation @@ -132,6 +134,7 @@ #define TX_BADLEFT 5004 #define TX_ENDOF 5005 #define TX_OUTCASE 5006 +#define TX_NOTERM 5007 #define TX_CLOSEBLK 5008 #define TX_ELSEWITHOUTIF 5009 #define TX_OPENBLK 5010 @@ -162,6 +165,7 @@ #define TX_CLBRK 5035 #define TX_RESERVED 5036 #define TX_BADNEW 5037 +#define TX_OPBRK 5038 #define TX_BADSTRING 5039 #define TX_BADINDEX 5040 #define TX_PRIVATE 5041 @@ -171,6 +175,7 @@ #define TX_DIVZERO 6000 #define TX_NOTINIT 6001 #define TX_BADTHROW 6002 +#define TX_NORETVAL 6003 #define TX_NORUN 6004 #define TX_NOCALL 6005 #define TX_NOCLASS 6006 @@ -179,6 +184,10 @@ #define TX_OUTARRAY 6009 #define TX_STACKOVER 6010 #define TX_DELETEDPT 6011 +#define TX_FILEOPEN 6012 +#define TX_NOTOPEN 6013 +#define TX_ERRREAD 6014 +#define TX_ERRWRITE 6015 -// Max errors -#define TX_MAX 6012 +// Max errors (NOTE: See above TODO near file errors) +#define TX_MAX 6016 diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 0dd62f1e..6ac9f43b 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -29,9 +29,10 @@ #include "CBot/CBotInstr/CBotFunction.h" -#include "StringFunctions.h" #include "CBotKeywordStrings.h" +#include "CBot/stdlib/stdlib.h" + // Local include // Global include @@ -482,19 +483,21 @@ void CBotProgram::Init() CBotToken::DefineNum("CBotErrZeroDiv", TX_DIVZERO); // division by zero CBotToken::DefineNum("CBotErrNotInit", TX_NOTINIT); // uninitialized variable CBotToken::DefineNum("CBotErrBadThrow", TX_BADTHROW); // throw a negative value - //CBotToken::DefineNum("CBotErrNoRetVal", 6003); // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P + CBotToken::DefineNum("CBotErrNoRetVal", TX_NORETVAL); // function did not return results CBotToken::DefineNum("CBotErrNoRun", TX_NORUN); // active Run () without a function // TODO: Is this actually a runtime error? CBotToken::DefineNum("CBotErrUndefFunc", TX_NOCALL); // Calling a function that no longer exists - CBotToken::DefineNum("CBotErrUndefClass", TX_NOCLASS); // Class no longer exists - CBotToken::DefineNum("CBotErrNullPointer", TX_NULLPT); // Attempted to use a null pointer + CBotToken::DefineNum("CBotErrNotClass", TX_NOCLASS); // Class no longer exists + CBotToken::DefineNum("CBotErrNull", TX_NULLPT); // Attempted to use a null pointer CBotToken::DefineNum("CBotErrNan", TX_OPNAN); // Can't do operations on nan - CBotToken::DefineNum("CBotErrOutOfBounds", TX_OUTARRAY); // Attempted access out of bounds of an array - CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER); // Stack overflow - CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT); // Attempted to use deleted object + CBotToken::DefineNum("CBotErrOutArray", TX_OUTARRAY); // Attempted access out of bounds of an array + CBotToken::DefineNum("CBotErrStackOver", TX_STACKOVER); // Stack overflow + CBotToken::DefineNum("CBotErrDeletedPtr", TX_DELETEDPT); // Attempted to use deleted object CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); InitStringFunctions(); + InitMathFunctions(); + InitFileFunctions(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 08f83568..62f7d72f 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -11,7 +11,6 @@ set(SOURCES CBotCallMethode.cpp CBotTypResult.cpp CBotKeywordStrings.cpp - StringFunctions.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotInstrUtils.cpp CBotInstr/CBotWhile.cpp @@ -67,6 +66,10 @@ set(SOURCES CBotVar/CBotVarFloat.cpp CBotVar/CBotVarInt.cpp CBotVar/CBotVar.cpp + stdlib/FileFunctions.cpp + stdlib/StringFunctions.cpp + stdlib/MathFunctions.cpp + stdlib/Compilation.cpp ) # Includes diff --git a/src/CBot/StringFunctions.h b/src/CBot/StringFunctions.h deleted file mode 100644 index fd3618f4..00000000 --- a/src/CBot/StringFunctions.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * 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://gnu.org/licenses - */ - -#pragma once - -// Modules inlcude -#include "CBot/CBotTypResult.h" - -// Local include - -// Global include - -// Forward declaration -class CBotVar; - -/*! - * \brief rStrLen Gives the length of a chain execution - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief cIntStr int xxx ( string ) compilation - * \param pVar - * \param pUser - * \return - */ -CBotTypResult cIntStr( CBotVar* &pVar, void* pUser ); - -/*! - * \brief rStrLeft Gives the left side of a chain execution - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief cStrStrInt string xxx ( string, int ) compilation - * \param pVar - * \param pUser - * \return - */ -CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser ); - -/*! - * \brief rStrRight Gives the right of a string execution - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief rStrMid Gives the central part of a chain execution - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief rStrVal Gives the number stored in a string execution. - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief cIntStrStr int xxx ( string, string ) compilation - * \param pVar - * \param pUser - * \return - */ -CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser ); - -/*! - * \brief rStrUpper Gives a string to uppercase exécution - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief rStrLower Gives a string to lowercase exécution. - * \param pVar - * \param pResult - * \param ex - * \param pUser - * \return - */ -bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ); - -/*! - * \brief cStrStr String xxx ( string ) compilation - * \param pVar - * \param pUser - * \return - */ -CBotTypResult cStrStr( CBotVar* &pVar, void* pUser ); - -/*! - * \brief InitStringFunctions - */ -void InitStringFunctions(); diff --git a/src/CBot/stdlib/Compilation.cpp b/src/CBot/stdlib/Compilation.cpp new file mode 100644 index 00000000..a0174a68 --- /dev/null +++ b/src/CBot/stdlib/Compilation.cpp @@ -0,0 +1,217 @@ +#include "CBot/stdlib/Compilation.h" + +#include "CBot/CBot.h" + +// Compiling a procedure without any parameters. + +CBotTypResult cNull(CBotVar* &var, void* user) +{ + if ( var != nullptr ) return CBotErrOverParam; + return CBotTypResult(CBotTypFloat); +} + +// Compiling a procedure with a single real number. + +CBotTypResult cOneFloat(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypFloat); +} + +// Compiling a procedure with two real numbers. + +CBotTypResult cTwoFloat(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypFloat); +} + + +// Compiling a procedure with a single string. + +CBotTypResult cString(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypString && + var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypFloat); +} + +// Compiling a procedure with a single string, returning string. + +CBotTypResult cStringString(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypString && + var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypString); +} + +// compilation of instruction with one int returning int + +CBotTypResult cOneInt(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypInt); +} + +// compilation of instruction with one int returning boolean + +CBotTypResult cOneIntReturnBool(CBotVar* &var, void* user) +{ + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypBoolean); +} + + + +CBotTypResult cStrStr(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // no second parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + + // the end result is a string + return CBotTypResult( CBotTypString ); +} + +CBotTypResult cIntStrStr(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // it takes a second parameter + var = var->GetNext(); + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // no third parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + + // the end result is a number + return CBotTypResult( CBotTypInt ); +} + +CBotTypResult cFloatStr(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult(TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // no second parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + + // the end result is a number + return CBotTypResult( CBotTypFloat ); +} + +CBotTypResult cStrStrIntInt(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // it takes a second parameter + var = var->GetNext(); + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // which must be a number + if ( var->GetType() > CBotTypDouble ) + return CBotTypResult( TX_BADNUM ); + + // third parameter optional + if ( var->GetNext() != nullptr ) + { + + var = var->GetNext(); + // which must be a number + if ( var->GetType() > CBotTypDouble ) + return CBotTypResult( TX_BADNUM ); + + // no fourth parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + } + + // the end result is a string + return CBotTypResult( CBotTypString ); +} + +CBotTypResult cStrStrInt(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADSTRING ); + + // it takes a second parameter + var = var->GetNext(); + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // which must be a number + if ( var->GetType() > CBotTypDouble ) + return CBotTypResult( TX_BADNUM ); + + // no third parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + + // the end result is a string + return CBotTypResult( CBotTypString ); +} + +CBotTypResult cIntStr(CBotVar*& var, void* user) +{ + // it takes a parameter + if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + + // to be a string + if ( var->GetType() != CBotTypString ) + return CBotTypResult( TX_BADPARAM ); + + // no second parameter + if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + + // the end result is an integer + return CBotTypResult( CBotTypInt ); +} \ No newline at end of file diff --git a/src/CBot/stdlib/Compilation.h b/src/CBot/stdlib/Compilation.h new file mode 100644 index 00000000..b53519c8 --- /dev/null +++ b/src/CBot/stdlib/Compilation.h @@ -0,0 +1,37 @@ +#pragma once + +#include "CBot/CBotTypResult.h" + +class CBotVar; + +// Commonly used functions for parameter compilation +// type "number" is anything > CBotTypDouble + +// float foo() +CBotTypResult cNull(CBotVar* &var, void* user); +// float foo(number) +CBotTypResult cOneFloat(CBotVar* &var, void* user); +// float foo(number, number) +CBotTypResult cTwoFloat(CBotVar* &var, void* user); +// float foo(string) +CBotTypResult cString(CBotVar* &var, void* user); +// string foo(string) +CBotTypResult cStringString(CBotVar* &var, void* user); +// int foo(int) +CBotTypResult cOneInt(CBotVar* &var, void* user); +// bool foo(int) +CBotTypResult cOneIntReturnBool(CBotVar* &var, void* user); + + +// string foo(string) +CBotTypResult cStrStr(CBotVar*& var, void* user); +// int foo(string, string) +CBotTypResult cIntStrStr(CBotVar*& var, void* user); +// float foo(string) +CBotTypResult cFloatStr(CBotVar*& var, void* user); +// string foo(string, number[, number]) +CBotTypResult cStrStrIntInt(CBotVar*& var, void* user); +// string foo(string, number) +CBotTypResult cStrStrInt(CBotVar*& var, void* user); +// int foo(string) +CBotTypResult cIntStr(CBotVar*& var, void* user); \ No newline at end of file diff --git a/src/CBot/stdlib/FileFunctions.cpp b/src/CBot/stdlib/FileFunctions.cpp new file mode 100644 index 00000000..26836a90 --- /dev/null +++ b/src/CBot/stdlib/FileFunctions.cpp @@ -0,0 +1,375 @@ +#include "CBot/stdlib/stdlib.h" + +#include "CBot/CBot.h" + +#include +#include +#include + +namespace { +std::unique_ptr g_fileHandler; +std::unordered_map> g_files; +int g_nextFileId = 1; +} + + +bool FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) +{ + std::string mode; + + // must be a character string + if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } + + std::string filename = pVar->GetValString(); + + // there may be a second parameter + pVar = pVar->GetNext(); + if ( pVar != nullptr ) + { + // recover mode + mode = pVar->GetValString(); + if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; } + + // no third parameter + if ( pVar->GetNext() != nullptr ) { Exception = CBotErrOverParam; return false; } + } + + // saves the file name + pVar = pThis->GetItem("filename"); + pVar->SetValString(filename); + + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + // which must not be initialized + if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; } + + if ( !mode.empty() ) + { + // opens the requested file + assert(g_fileHandler != nullptr); + std::unique_ptr file = g_fileHandler->OpenFile(filename, mode == "r" ? CBotFileAccessHandler::OpenMode::Read : CBotFileAccessHandler::OpenMode::Write); + + if (!file->Opened()) { Exception = CBotErrFileOpen; return false; } + + int fileHandle = g_nextFileId++; + g_files[fileHandle] = std::move(file); + + // save the file handle + pVar = pThis->GetItem("handle"); + pVar->SetValInt(fileHandle); + } + return true; +} + +// constructor of the class +// get the filename as a parameter + +// execution +bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // accepts no parameters + if ( pVar == nullptr ) return true; + + return FileClassOpenFile(pThis, pVar, pResult, Exception); +} + +// compilation +CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar) +{ + // accepts no parameters + if ( pVar == nullptr ) return CBotTypResult( 0 ); + + // must be a character string + if ( pVar->GetType() != CBotTypString ) + return CBotTypResult( CBotErrBadString ); + + // there may be a second parameter + pVar = pVar->GetNext(); + if ( pVar != nullptr ) + { + // which must be a string + if ( pVar->GetType() != CBotTypString ) + return CBotTypResult( CBotErrBadString ); + // no third parameter + if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); + } + + // the result is void (constructor) + return CBotTypResult( 0 ); +} + + +// destructor of the class + +// execution +bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + + if (!pVar->IsDefined()) return true; // file not opened + g_files.erase(pVar->GetValInt()); + + pVar->SetInit(CBotVar::InitType::IS_NAN); + return true; +} + + +// process FILE :: open +// get the r/w mode as a parameter + +// execution +bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // there must be a parameter + if ( pVar == nullptr ) { Exception = CBotErrLowParam; return false; } + + bool result = FileClassOpenFile(pThis, pVar, pResult, Exception); + pResult->SetValInt(result); + return result; +} + +// compilation +CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar) +{ + // there must be a parameter + if ( pVar == nullptr ) return CBotTypResult( CBotErrLowParam ); + + // which must be a string + if ( pVar->GetType() != CBotTypString ) + return CBotTypResult( CBotErrBadString ); + + // there may be a second parameter + pVar = pVar->GetNext(); + if ( pVar != nullptr ) + { + // which must be a string + if ( pVar->GetType() != CBotTypString ) + return CBotTypResult( CBotErrBadString ); + + // no third parameter + if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); + } + + // the result is bool + return CBotTypResult(CBotTypBoolean); +} + + +// process FILE :: close + +// execeution +bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // it shouldn't be any parameters + if (pVar != nullptr) { Exception = CBotErrOverParam; return false; } + + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + + if (!pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } + + int fileHandle = pVar->GetValInt(); + + const auto handleIter = g_files.find(fileHandle); + if (handleIter == g_files.end()) + { + Exception = CBotErrNotOpen; + return false; + } + + g_files.erase(handleIter); + + pVar->SetInit(CBotVar::InitType::IS_NAN); + return true; +} + +// compilation +CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar) +{ + // it shouldn't be any parameters + if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); + + // function returns a result "void" + return CBotTypResult( 0 ); +} + +// process FILE :: writeln + +// execution +bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // there must be a parameter + if ( pVar == nullptr ) { Exception = CBotErrLowParam; return false; } + + // which must be a character string + if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } + + std::string param = pVar->GetValString(); + + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + + if ( !pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } + + int fileHandle = pVar->GetValInt(); + + const auto handleIter = g_files.find(fileHandle); + if (handleIter == g_files.end()) + { + Exception = CBotErrNotOpen; + return false; + } + + handleIter->second->Write(param + "\n"); + + // if an error occurs generate an exception + if ( handleIter->second->Errored() ) { Exception = CBotErrWrite; return false; } + + return true; +} + +// compilation +CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar) +{ + // there must be a parameter + if ( pVar == nullptr ) return CBotTypResult( CBotErrLowParam ); + + // which must be a character string + if ( pVar->GetType() != CBotTypString ) return CBotTypResult( CBotErrBadString ); + + // no other parameter + if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); + + // the function returns a void result + return CBotTypResult( 0 ); +} + +// process FILE :: readln + +// execution +bool rfread(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // it shouldn't be any parameters + if (pVar != nullptr) { Exception = CBotErrOverParam; return false; } + + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + + if (!pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } + + int fileHandle = pVar->GetValInt(); + + const auto handleIter = g_files.find(fileHandle); + if (handleIter == g_files.end()) + { + Exception = CBotErrNotOpen; + return false; + } + + std::string line = handleIter->second->ReadLine(); + + // if an error occurs generate an exception + if ( handleIter->second->Errored() ) { Exception = CBotErrRead; return false; } + + pResult->SetValString( line.c_str() ); + + return true; +} + +// compilation +CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar) +{ + // it should not be any parameter + if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); + + // function returns a result "string" + return CBotTypResult( CBotTypString ); +} +// process FILE :: readln + + +// execution +bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) +{ + // it should not be any parameter + if ( pVar != nullptr ) { Exception = CBotErrOverParam; return false; } + + // retrieve the item "handle" + pVar = pThis->GetItem("handle"); + + if ( !pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } + + int fileHandle = pVar->GetValInt(); + + const auto handleIter = g_files.find(fileHandle); + if (handleIter == g_files.end()) + { + Exception = CBotErrNotOpen; + return false; + } + + pResult->SetValInt( handleIter->second->IsEOF() ); + + return true; +} + +// compilation +CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar) +{ + // it shouldn't be any parameter + if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); + + // the function returns a boolean result + return CBotTypResult( CBotTypBoolean ); +} + +// Instruction "deletefile(filename)". + +bool rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + std::string filename = var->GetValString(); + assert(g_fileHandler != nullptr); + return g_fileHandler->DeleteFile(filename); +} + + +void InitFileFunctions() +{ + // create a class for file management + // the use is as follows: + // file canal( "NomFichier.txt" ) + // canal.open( "r" ); // open for read + // s = canal.readln( ); // reads a line + // canal.close(); // close the file + + // create the class FILE + CBotClass* bc = CBotClass::Create("file", nullptr); + // adds the component ".filename" + bc->AddItem("filename", CBotTypString); + // adds the component ".handle" + bc->AddItem("handle", CBotTypInt, PR_PRIVATE); + + // define a constructor and a destructor + bc->AddFunction("file", rfconstruct, cfconstruct); + bc->AddFunction("~file", rfdestruct, nullptr); + + // end of the methods associated + bc->AddFunction("open", rfopen, cfopen); + bc->AddFunction("close", rfclose, cfclose); + bc->AddFunction("writeln", rfwrite, cfwrite); + bc->AddFunction("readln", rfread, cfread); + bc->AddFunction("eof", rfeof, cfeof ); + + CBotProgram::AddFunction("deletefile", rDeleteFile, cString); + + //m_pFuncFile = new CBotProgram( ); + //std::stringArray ListFonctions; + //m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions); + //m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function +} + +void SetFileAccessHandler(std::unique_ptr fileHandler) +{ + g_fileHandler = std::move(fileHandler); +} \ No newline at end of file diff --git a/src/CBot/stdlib/MathFunctions.cpp b/src/CBot/stdlib/MathFunctions.cpp new file mode 100644 index 00000000..9375b92d --- /dev/null +++ b/src/CBot/stdlib/MathFunctions.cpp @@ -0,0 +1,189 @@ +#include "CBot/stdlib/stdlib.h" + +#include "CBot/CBot.h" + +#include + +// Instruction "sin(degrees)". + +bool rSin(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(sinf(value*M_PI/180.0f)); + return true; +} + +// Instruction "cos(degrees)". + +bool rCos(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(cosf(value*M_PI/180.0f)); + return true; +} + +// Instruction "tan(degrees)". + +bool rTan(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(tanf(value*M_PI/180.0f)); + return true; +} + +// Instruction "asin(degrees)". + +bool raSin(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(asinf(value)*180.0f/M_PI); + return true; +} + +// Instruction "acos(degrees)". + +bool raCos(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(acosf(value)*180.0f/M_PI); + return true; +} + +// Instruction "atan(degrees)". + +bool raTan(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(atanf(value)*180.0f/M_PI); + return true; +} + +// Instruction "atan2(y,x)". + +bool raTan2(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float y = var->GetValFloat(); + var = var->GetNext(); + float x = var->GetValFloat(); + + result->SetValFloat(atan2(y, x) * 180.0f / M_PI); + return true; +} + +// Instruction "sqrt(value)". + +bool rSqrt(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(sqrtf(value)); + return true; +} + +// Instruction "pow(x, y)". + +bool rPow(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float x, y; + + x = var->GetValFloat(); + var = var->GetNext(); + y = var->GetValFloat(); + result->SetValFloat(powf(x, y)); + return true; +} + +// Instruction "rand()". + +bool rRand(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + result->SetValFloat(static_cast(rand()) / static_cast(RAND_MAX)); + return true; +} + +// Instruction "abs()". + +bool rAbs(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(fabs(value)); + return true; +} + +// Instruction "floor()" + +bool rFloor(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(floor(value)); + return true; +} + +// Instruction "ceil()" + +bool rCeil(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(ceil(value)); + return true; +} + +// Instruction "round()" + +bool rRound(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(round(value)); + return true; +} + +// Instruction "trunc()" + +bool rTrunc(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + float value; + + value = var->GetValFloat(); + result->SetValFloat(trunc(value)); + return true; +} + +void InitMathFunctions() +{ + CBotProgram::AddFunction("sin", rSin, cOneFloat); + CBotProgram::AddFunction("cos", rCos, cOneFloat); + CBotProgram::AddFunction("tan", rTan, cOneFloat); + CBotProgram::AddFunction("asin", raSin, cOneFloat); + CBotProgram::AddFunction("acos", raCos, cOneFloat); + CBotProgram::AddFunction("atan", raTan, cOneFloat); + CBotProgram::AddFunction("atan2", raTan2, cTwoFloat); + CBotProgram::AddFunction("sqrt", rSqrt, cOneFloat); + CBotProgram::AddFunction("pow", rPow, cTwoFloat); + CBotProgram::AddFunction("rand", rRand, cNull); + CBotProgram::AddFunction("abs", rAbs, cOneFloat); + CBotProgram::AddFunction("floor", rFloor, cOneFloat); + CBotProgram::AddFunction("ceil", rCeil, cOneFloat); + CBotProgram::AddFunction("round", rRound, cOneFloat); + CBotProgram::AddFunction("trunc", rTrunc, cOneFloat); +} \ No newline at end of file diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/stdlib/StringFunctions.cpp similarity index 65% rename from src/CBot/StringFunctions.cpp rename to src/CBot/stdlib/StringFunctions.cpp index 7ffe4254..91c63629 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/stdlib/StringFunctions.cpp @@ -18,12 +18,10 @@ */ // Modules inlcude -#include "CBot/StringFunctions.h" +#include "CBot/stdlib/stdlib.h" -#include "CBot/CBotProgram.h" -#include "CBot/CBotEnums.h" +#include "CBot/CBot.h" -#include "CBot/CBotVar/CBotVar.h" #include "CBot/CBotUtils.h" @@ -52,23 +50,6 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cIntStr( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADPARAM ); - - // no second parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // the end result is an integer - return CBotTypResult( CBotTypInt ); -} - //////////////////////////////////////////////////////////////////////////////// bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { @@ -102,31 +83,6 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // it takes a second parameter - pVar = pVar->GetNext(); - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // which must be a number - if ( pVar->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); - - // no third parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // the end result is a string - return CBotTypResult( CBotTypString ); -} - //////////////////////////////////////////////////////////////////////////////// bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { @@ -210,41 +166,6 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // it takes a second parameter - pVar = pVar->GetNext(); - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // which must be a number - if ( pVar->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); - - // third parameter optional - if ( pVar->GetNext() != nullptr ) - { - - pVar = pVar->GetNext(); - // which must be a number - if ( pVar->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); - - // no fourth parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - } - - // the end result is a string - return CBotTypResult( CBotTypString ); -} - //////////////////////////////////////////////////////////////////////////////// bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { @@ -267,23 +188,6 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // no second parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // the end result is a number - return CBotTypResult( CBotTypFloat ); -} - //////////////////////////////////////////////////////////////////////////////// bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { @@ -316,31 +220,6 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // it takes a second parameter - pVar = pVar->GetNext(); - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // no third parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // the end result is a number - return CBotTypResult( CBotTypInt ); -} - //////////////////////////////////////////////////////////////////////////////// bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { @@ -387,22 +266,7 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) return true; } -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult cStrStr( CBotVar* &pVar, void* pUser ) -{ - // it takes a parameter - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); - // to be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); - - // no second parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); - - // the end result is a string - return CBotTypResult( CBotTypString ); -} //////////////////////////////////////////////////////////////////////////////// void InitStringFunctions() diff --git a/src/CBot/stdlib/stdlib.h b/src/CBot/stdlib/stdlib.h new file mode 100644 index 00000000..fd75279b --- /dev/null +++ b/src/CBot/stdlib/stdlib.h @@ -0,0 +1,7 @@ +#pragma once + +#include "CBot/stdlib/stdlib_public.h" + +void InitStringFunctions(); +void InitFileFunctions(); +void InitMathFunctions(); \ No newline at end of file diff --git a/src/CBot/stdlib/stdlib_public.h b/src/CBot/stdlib/stdlib_public.h new file mode 100644 index 00000000..0497906e --- /dev/null +++ b/src/CBot/stdlib/stdlib_public.h @@ -0,0 +1,34 @@ +#pragma once + +#include "CBot/stdlib/Compilation.h" + +#include + +class CBotFile +{ +public: + virtual ~CBotFile() {} + + virtual bool Opened() = 0; + virtual bool Errored() = 0; + virtual bool IsEOF() = 0; + + virtual std::string ReadLine() = 0; + virtual void Write(const std::string& s) = 0; + + //TODO +}; + +class CBotFileAccessHandler +{ +public: + virtual ~CBotFileAccessHandler() {} + + enum class OpenMode : char { Read = 'r', Write = 'w' }; + virtual std::unique_ptr OpenFile(const std::string& filename, OpenMode mode) = 0; + virtual bool DeleteFile(const std::string& filename) = 0; +}; + +void SetFileAccessHandler(std::unique_ptr fileHandler); + +// TODO: provide default implementation of CBotFileAccessHandler \ No newline at end of file diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 8b2cb435..db7a6c40 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -707,6 +707,7 @@ void InitializeRestext() stringsCbot[TX_CLBRK] = TR("\" ] \" missing"); stringsCbot[TX_RESERVED] = TR("Reserved keyword of CBOT language"); stringsCbot[TX_BADNEW] = TR("Bad argument for \"new\""); + stringsCbot[TX_OPBRK] = TR("\" [ \" expected"); stringsCbot[TX_BADSTRING] = TR("String missing"); stringsCbot[TX_BADINDEX] = TR("Incorrect index type"); stringsCbot[TX_PRIVATE] = TR("Private element"); @@ -714,6 +715,7 @@ void InitializeRestext() stringsCbot[TX_DIVZERO] = TR("Dividing by zero"); stringsCbot[TX_NOTINIT] = TR("Variable not initialized"); stringsCbot[TX_BADTHROW] = TR("Negative value rejected by \"throw\""); + stringsCbot[TX_NORETVAL] = TR("The function returned no value "); stringsCbot[TX_NORUN] = TR("No function running"); stringsCbot[TX_NOCALL] = TR("Calling an unknown function"); stringsCbot[TX_NOCLASS] = TR("This class does not exist"); @@ -722,6 +724,10 @@ void InitializeRestext() stringsCbot[TX_OUTARRAY] = TR("Access beyond array limit"); stringsCbot[TX_STACKOVER] = TR("Stack overflow"); stringsCbot[TX_DELETEDPT] = TR("Illegal object"); + stringsCbot[TX_FILEOPEN] = TR("Can't open file"); + stringsCbot[TX_NOTOPEN] = TR("File not open"); + stringsCbot[TX_ERRREAD] = TR("Read error"); + stringsCbot[TX_ERRWRITE] = TR("Write error"); } diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 59265711..3929cf3f 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -4472,7 +4472,7 @@ std::string CRobotMain::GetNewScriptName(ObjectType type, int rank) //! Seeks if an object occupies in a spot, to prevent a backup of the game bool CRobotMain::IOIsBusy() { - if (CScriptFunctions::m_numberOfOpenFiles > 0) return true; + if (CScriptFunctions::CheckOpenFiles()) return true; for (CObject* obj : m_objMan->GetAllObjects()) { diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 060dddc6..93e02419 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -68,49 +68,14 @@ #include "ui/displaytext.h" -// Compiling a procedure without any parameters. - -CBotTypResult CScriptFunctions::cNull(CBotVar* &var, void* user) -{ - if ( var != nullptr ) return CBotErrOverParam; - return CBotTypResult(CBotTypFloat); -} - CBotTypResult CScriptFunctions::cClassNull(CBotVar* thisclass, CBotVar* &var) { - return CScriptFunctions::cNull(var, nullptr); -} - -// Compiling a procedure with a single real number. - -CBotTypResult CScriptFunctions::cOneFloat(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypFloat); + return cNull(var, nullptr); } CBotTypResult CScriptFunctions::cClassOneFloat(CBotVar* thisclass, CBotVar* &var) { - return CScriptFunctions::cOneFloat(var, nullptr); -} - -// Compiling a procedure with two real numbers. - -CBotTypResult CScriptFunctions::cTwoFloat(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypFloat); + return cOneFloat(var, nullptr); } // Compiling a procedure with a "dot". @@ -154,53 +119,6 @@ CBotTypResult CScriptFunctions::cOnePoint(CBotVar* &var, void* user) return CBotTypResult(CBotTypFloat); } -// Compiling a procedure with a single string. - -CBotTypResult CScriptFunctions::cString(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() != CBotTypString && - var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypFloat); -} - -// Compiling a procedure with a single string, returning string. - -CBotTypResult CScriptFunctions::cStringString(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() != CBotTypString && - var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypString); -} - -// compilation of instruction with one int returning int - -CBotTypResult CScriptFunctions::cOneInt(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypInt); -} - -// compilation of instruction with one int returning boolean - -CBotTypResult CScriptFunctions::cOneIntReturnBool(CBotVar* &var, void* user) -{ - if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum); - var = var->GetNext(); - if ( var != nullptr ) return CBotTypResult(CBotErrOverParam); - return CBotTypResult(CBotTypBoolean); -} - - // Seeking value in an array of integers. bool FindList(CBotVar* array, int type) @@ -259,171 +177,6 @@ bool GetPoint(CBotVar* &var, int& exception, Math::Vector& pos) } -// Instruction "sin(degrees)". - -bool CScriptFunctions::rSin(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(sinf(value*Math::PI/180.0f)); - return true; -} - -// Instruction "cos(degrees)". - -bool CScriptFunctions::rCos(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(cosf(value*Math::PI/180.0f)); - return true; -} - -// Instruction "tan(degrees)". - -bool CScriptFunctions::rTan(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(tanf(value*Math::PI/180.0f)); - return true; -} - -// Instruction "asin(degrees)". - -bool raSin(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(asinf(value)*180.0f/Math::PI); - return true; -} - -// Instruction "acos(degrees)". - -bool raCos(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(acosf(value)*180.0f/Math::PI); - return true; -} - -// Instruction "atan(degrees)". - -bool raTan(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(atanf(value)*180.0f/Math::PI); - return true; -} - -// Instruction "atan2(y,x)". - -bool raTan2(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float y = var->GetValFloat(); - var = var->GetNext(); - float x = var->GetValFloat(); - - result->SetValFloat(atan2(y, x) * 180.0f / Math::PI); - return true; -} - -// Instruction "sqrt(value)". - -bool CScriptFunctions::rSqrt(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(sqrtf(value)); - return true; -} - -// Instruction "pow(x, y)". - -bool CScriptFunctions::rPow(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float x, y; - - x = var->GetValFloat(); - var = var->GetNext(); - y = var->GetValFloat(); - result->SetValFloat(powf(x, y)); - return true; -} - -// Instruction "rand()". - -bool CScriptFunctions::rRand(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - result->SetValFloat(Math::Rand()); - return true; -} - -// Instruction "abs()". - -bool CScriptFunctions::rAbs(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(fabs(value)); - return true; -} - -// Instruction "floor()" - -bool CScriptFunctions::rFloor(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(floor(value)); - return true; -} - -// Instruction "ceil()" - -bool CScriptFunctions::rCeil(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(ceil(value)); - return true; -} - -// Instruction "round()" - -bool CScriptFunctions::rRound(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(round(value)); - return true; -} - -// Instruction "trunc()" - -bool CScriptFunctions::rTrunc(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - float value; - - value = var->GetValFloat(); - result->SetValFloat(trunc(value)); - return true; -} - // Compilation of the instruction "endmission(result, delay)" CBotTypResult CScriptFunctions::cEndMission(CBotVar* &var, void* user) @@ -3132,391 +2885,6 @@ bool CScriptFunctions::rCameraFocus(CBotVar* var, CBotVar* result, int& exceptio return true; } -// Static variables - -int CScriptFunctions::m_numberOfOpenFiles = 0; -std::unordered_map> CScriptFunctions::m_files; -int CScriptFunctions::m_nextFile = 1; - - - -// Prepares a file name. - -void PrepareFilename(std::string &filename) -{ - CResourceManager::CreateDirectory("files"); - filename = "files/" + filename; - GetLogger()->Debug("CBot accessing file '%s'\n", filename.c_str()); -} - - -bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - std::string mode; - - // must be a character string - if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - - std::string filename = pVar->GetValString(); - PrepareFilename(filename); - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != nullptr ) - { - // recover mode - mode = pVar->GetValString(); - if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; } - - // no third parameter - if ( pVar->GetNext() != nullptr ) { Exception = CBotErrOverParam; return false; } - } - - // saves the file name - pVar = pThis->GetItem("filename"); - pVar->SetValString(filename); - - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - // which must not be initialized - if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; } - - if ( !mode.empty() ) - { - // opens the requested file - bool ok = false; - std::unique_ptr file; - if (mode == "r") - { - auto is = MakeUnique(filename); - ok = is->is_open(); - file = std::move(is); - } - else if (mode == "w") - { - auto os = MakeUnique(filename); - ok = os->is_open(); - file = std::move(os); - } - if (!ok) { Exception = CBotErrFileOpen; return false; } - - m_numberOfOpenFiles ++; - - int fileHandle = m_nextFile++; - - m_files[fileHandle] = std::move(file); - - // save the file handle - pVar = pThis->GetItem("handle"); - pVar->SetValInt(fileHandle); - } - return true; -} - -// constructor of the class -// get the filename as a parameter - -// execution -bool CScriptFunctions::rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // accepts no parameters - if ( pVar == nullptr ) return true; - - return FileClassOpenFile(pThis, pVar, pResult, Exception); -} - -// compilation -CBotTypResult CScriptFunctions::cfconstruct (CBotVar* pThis, CBotVar* &pVar) -{ - // accepts no parameters - if ( pVar == nullptr ) return CBotTypResult( 0 ); - - // must be a character string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != nullptr ) - { - // which must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - // no third parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); - } - - // the result is void (constructor) - return CBotTypResult( 0 ); -} - - -// destructor of the class - -// execution -bool CScriptFunctions::rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - - // don't open? no problem :) - if ( pVar->IsDefined()) return true; - - int fileHandle = pVar->GetValInt(); - - std::ios* file = m_files[fileHandle].get(); - CInputStream* is = dynamic_cast(file); - if(is != nullptr) is->close(); - COutputStream* os = dynamic_cast(file); - if(os != nullptr) os->close(); - - m_numberOfOpenFiles--; - - pVar->SetInit(CBotVar::InitType::IS_NAN); - - m_files.erase(fileHandle); - - return true; -} - - -// process FILE :: open -// get the r/w mode as a parameter - -// execution -bool CScriptFunctions::rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // there must be a parameter - if ( pVar == nullptr ) { Exception = CBotErrLowParam; return false; } - - bool result = FileClassOpenFile(pThis, pVar, pResult, Exception); - pResult->SetValInt(result); - return result; -} - -// compilation -CBotTypResult CScriptFunctions::cfopen (CBotVar* pThis, CBotVar* &pVar) -{ - // there must be a parameter - if ( pVar == nullptr ) return CBotTypResult( CBotErrLowParam ); - - // which must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // there may be a second parameter - pVar = pVar->GetNext(); - if ( pVar != nullptr ) - { - // which must be a string - if ( pVar->GetType() != CBotTypString ) - return CBotTypResult( CBotErrBadString ); - - // no third parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); - } - - // the result is bool - return CBotTypResult(CBotTypBoolean); -} - - -// process FILE :: close - -// execeution -bool CScriptFunctions::rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // it shouldn't be any parameters - if (pVar != nullptr) { Exception = CBotErrOverParam; return false; } - - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - - if ( !pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } - - int fileHandle = pVar->GetValInt(); - - const auto handleIter = m_files.find(fileHandle); - if (handleIter == m_files.end()) - { - Exception = CBotErrNotOpen; - return false; - } - - assert(handleIter->second); - - std::ios* file = handleIter->second.get(); - CInputStream* is = dynamic_cast(file); - if(is != nullptr) is->close(); - COutputStream* os = dynamic_cast(file); - if(os != nullptr) os->close(); - - m_numberOfOpenFiles--; - - pVar->SetInit(CBotVar::InitType::IS_NAN); - - m_files.erase(handleIter); - - return true; -} - -// compilation -CBotTypResult CScriptFunctions::cfclose (CBotVar* pThis, CBotVar* &pVar) -{ - // it shouldn't be any parameters - if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); - - // function returns a result "void" - return CBotTypResult( 0 ); -} - -// process FILE :: writeln - -// execution -bool CScriptFunctions::rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // there must be a parameter - if ( pVar == nullptr ) { Exception = CBotErrLowParam; return false; } - - // which must be a character string - if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; } - - std::string param = pVar->GetValString(); - - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - - if ( !pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } - - int fileHandle = pVar->GetValInt(); - - const auto handleIter = m_files.find(fileHandle); - if (handleIter == m_files.end()) - { - Exception = CBotErrNotOpen; - return false; - } - - COutputStream* os = dynamic_cast(handleIter->second.get()); - if (os == nullptr) { Exception = CBotErrWrite; return false; } - - *os << param << "\n"; - - // if an error occurs generate an exception - if ( os->bad() ) { Exception = CBotErrWrite; return false; } - - return true; -} - -// compilation -CBotTypResult CScriptFunctions::cfwrite (CBotVar* pThis, CBotVar* &pVar) -{ - // there must be a parameter - if ( pVar == nullptr ) return CBotTypResult( CBotErrLowParam ); - - // which must be a character string - if ( pVar->GetType() != CBotTypString ) return CBotTypResult( CBotErrBadString ); - - // no other parameter - if ( pVar->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); - - // the function returns a void result - return CBotTypResult( 0 ); -} - -// process FILE :: readln - -// execution -bool CScriptFunctions::rfread(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // it shouldn't be any parameters - if (pVar != nullptr) { Exception = CBotErrOverParam; return false; } - - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - - if (!pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } - - int fileHandle = pVar->GetValInt(); - - const auto handleIter = m_files.find(fileHandle); - if (handleIter == m_files.end()) - { - Exception = CBotErrNotOpen; - return false; - } - - CInputStream* is = dynamic_cast(handleIter->second.get()); - if (is == nullptr) { Exception = CBotErrRead; return false; } - - std::string line; - std::getline(*is, line); - - // if an error occurs generate an exception - if ( is->bad() ) { Exception = CBotErrRead; return false; } - - pResult->SetValString( line.c_str() ); - - return true; -} - -// compilation -CBotTypResult CScriptFunctions::cfread (CBotVar* pThis, CBotVar* &pVar) -{ - // it should not be any parameter - if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); - - // function returns a result "string" - return CBotTypResult( CBotTypString ); -} -// process FILE :: readln - - -// execution -bool CScriptFunctions::rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user) -{ - // it should not be any parameter - if ( pVar != nullptr ) { Exception = CBotErrOverParam; return false; } - - // retrieve the item "handle" - pVar = pThis->GetItem("handle"); - - if ( !pVar->IsDefined()) { Exception = CBotErrNotOpen; return false; } - - int fileHandle = pVar->GetValInt(); - - const auto handleIter = m_files.find(fileHandle); - if (handleIter == m_files.end()) - { - Exception = CBotErrNotOpen; - return false; - } - - pResult->SetValInt( handleIter->second->eof() ); - - return true; -} - -// compilation -CBotTypResult CScriptFunctions::cfeof (CBotVar* pThis, CBotVar* &pVar) -{ - // it shouldn't be any parameter - if ( pVar != nullptr ) return CBotTypResult( CBotErrOverParam ); - - // the function returns a boolean result - return CBotTypResult( CBotTypBoolean ); -} - -// Instruction "deletefile(filename)". - -bool CScriptFunctions::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - std::string filename; - - filename = var->GetValString(); - PrepareFilename(filename); - return CResourceManager::Remove(filename); -} // Compilation of class "point". @@ -3608,6 +2976,112 @@ bool CScriptFunctions::rPointConstructor(CBotVar* pThis, CBotVar* var, CBotVar* return true; // no interruption } +class CBotFileAccessHandlerColobot; +class CBotFileColobot : public CBotFile +{ +public: + static int m_numFilesOpen; + + CBotFileColobot(const std::string& filename, CBotFileAccessHandler::OpenMode mode) + { + if (mode == CBotFileAccessHandler::OpenMode::Read) + { + auto is = MakeUnique(filename); + if (is->is_open()) + { + m_file = std::move(is); + } + } + else if (mode == CBotFileAccessHandler::OpenMode::Write) + { + auto os = MakeUnique(filename); + if (os->is_open()) + { + m_file = std::move(os); + } + } + + if (Opened()) + { + GetLogger()->Info("CBot open file '%s'\n", filename.c_str()); + m_numFilesOpen++; + } + } + + ~CBotFileColobot() + { + if (Opened()) + { + GetLogger()->Debug("CBot close file\n"); + m_numFilesOpen--; + } + + std::ios* file = m_file.get(); + CInputStream* is = dynamic_cast(file); + if(is != nullptr) is->close(); + COutputStream* os = dynamic_cast(file); + if(os != nullptr) os->close(); + } + + virtual bool Opened() override + { + return m_file != nullptr; + } + + virtual bool Errored() override + { + return m_file->bad(); + } + + virtual bool IsEOF() override + { + return m_file->eof(); + } + + virtual std::string ReadLine() override + { + CInputStream* is = dynamic_cast(m_file.get()); + assert(is != nullptr); + + std::string line; + std::getline(*is, line); + return line; + } + + virtual void Write(const std::string& s) override + { + COutputStream* os = dynamic_cast(m_file.get()); + assert(os != nullptr); + + *os << s; + } + +private: + std::unique_ptr m_file; +}; +int CBotFileColobot::m_numFilesOpen = 0; + +class CBotFileAccessHandlerColobot : public CBotFileAccessHandler +{ +public: + virtual std::unique_ptr OpenFile(const std::string& filename, OpenMode mode) override + { + return MakeUnique(PrepareFilename(filename), mode); + } + + virtual bool DeleteFile(const std::string& filename) override + { + GetLogger()->Info("CBot delete file '%s'\n", filename.c_str()); + return CResourceManager::Remove(PrepareFilename(filename)); + } + +private: + static std::string PrepareFilename(const std::string& filename) + { + CResourceManager::CreateDirectory("files"); + return "files/" + filename; + } +}; @@ -3705,7 +3179,7 @@ void CScriptFunctions::Init() bc->AddItem("x", CBotTypFloat); bc->AddItem("y", CBotTypFloat); bc->AddItem("z", CBotTypFloat); - bc->AddFunction("point", CScriptFunctions::rPointConstructor, CScriptFunctions::cPointConstructor); + bc->AddFunction("point", rPointConstructor, cPointConstructor); // Adds the class Object. bc = CBotClass::Create("object", nullptr); @@ -3724,123 +3198,77 @@ void CScriptFunctions::Init() bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ); bc->AddItem("team", CBotTypResult(CBotTypInt), PR_READ); bc->AddItem("velocity", CBotTypResult(CBotTypClass, "point"), PR_READ); - bc->AddFunction("busy", CScriptFunctions::rBusy, CScriptFunctions::cBusy); - bc->AddFunction("factory", CScriptFunctions::rFactory, CScriptFunctions::cFactory); - bc->AddFunction("research", CScriptFunctions::rResearch, CScriptFunctions::cClassOneFloat); - bc->AddFunction("takeoff", CScriptFunctions::rTakeOff, CScriptFunctions::cClassNull); - bc->AddFunction("destroy", CScriptFunctions::rDestroy, CScriptFunctions::cClassNull); + bc->AddFunction("busy", rBusy, cBusy); + bc->AddFunction("factory", rFactory, cFactory); + bc->AddFunction("research", rResearch, cClassOneFloat); + bc->AddFunction("takeoff", rTakeOff, cClassNull); + bc->AddFunction("destroy", rDestroy, cClassNull); - // InitClassFILE: - // create a class for file management - // the use is as follows: - // file canal( "NomFichier.txt" ) - // canal.open( "r" ); // open for read - // s = canal.readln( ); // reads a line - // canal.close(); // close the file + CBotProgram::AddFunction("endmission",rEndMission,cEndMission); + CBotProgram::AddFunction("playmusic", rPlayMusic ,cPlayMusic); + CBotProgram::AddFunction("stopmusic", rStopMusic ,cNull); - // create the class FILE - bc = CBotClass::Create("file", nullptr); - // adds the component ".filename" - bc->AddItem("filename", CBotTypString); - // adds the component ".handle" - bc->AddItem("handle", CBotTypInt, PR_PRIVATE); + CBotProgram::AddFunction("getbuild", rGetBuild, cNull); + CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, cNull); + CBotProgram::AddFunction("getresearchdone", rGetResearchDone, cNull); + CBotProgram::AddFunction("setbuild", rSetBuild, cOneInt); + CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, cOneInt); + CBotProgram::AddFunction("setresearchdone", rSetResearchDone, cOneInt); - // define a constructor and a destructor - bc->AddFunction("file", CScriptFunctions::rfconstruct, CScriptFunctions::cfconstruct ); - bc->AddFunction("~file", CScriptFunctions::rfdestruct, nullptr ); + CBotProgram::AddFunction("canbuild", rCanBuild, cOneIntReturnBool); + CBotProgram::AddFunction("canresearch", rCanResearch, cOneIntReturnBool); + CBotProgram::AddFunction("researched", rResearched, cOneIntReturnBool); + CBotProgram::AddFunction("buildingenabled", rBuildingEnabled, cOneIntReturnBool); - // end of the methods associated - bc->AddFunction("open", CScriptFunctions::rfopen, CScriptFunctions::cfopen ); - bc->AddFunction("close", CScriptFunctions::rfclose, CScriptFunctions::cfclose ); - bc->AddFunction("writeln", CScriptFunctions::rfwrite, CScriptFunctions::cfwrite ); - bc->AddFunction("readln", CScriptFunctions::rfread, CScriptFunctions::cfread ); - bc->AddFunction("eof", CScriptFunctions::rfeof, CScriptFunctions::cfeof ); + CBotProgram::AddFunction("build", rBuild, cOneInt); - //m_pFuncFile = new CBotProgram( ); - //std::stringArray ListFonctions; - //m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions); - //m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function - - CBotProgram::AddFunction("sin", rSin, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("cos", rCos, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("tan", rTan, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("asin", raSin, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("acos", raCos, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("atan", raTan, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("atan2", raTan2, CScriptFunctions::cTwoFloat); - CBotProgram::AddFunction("sqrt", rSqrt, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("pow", rPow, CScriptFunctions::cTwoFloat); - CBotProgram::AddFunction("rand", rRand, CScriptFunctions::cNull); - CBotProgram::AddFunction("abs", rAbs, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("floor", rFloor, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("ceil", rCeil, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("round", rRound, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("trunc", rTrunc, CScriptFunctions::cOneFloat); - - CBotProgram::AddFunction("endmission",rEndMission,CScriptFunctions::cEndMission); - CBotProgram::AddFunction("playmusic", rPlayMusic ,CScriptFunctions::cPlayMusic); - CBotProgram::AddFunction("stopmusic", rStopMusic ,CScriptFunctions::cNull); - - CBotProgram::AddFunction("getbuild", rGetBuild, CScriptFunctions::cNull); - CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, CScriptFunctions::cNull); - CBotProgram::AddFunction("getresearchdone", rGetResearchDone, CScriptFunctions::cNull); - CBotProgram::AddFunction("setbuild", rSetBuild, CScriptFunctions::cOneInt); - CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScriptFunctions::cOneInt); - CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScriptFunctions::cOneInt); - - CBotProgram::AddFunction("canbuild", rCanBuild, CScriptFunctions::cOneIntReturnBool); - CBotProgram::AddFunction("canresearch", rCanResearch, CScriptFunctions::cOneIntReturnBool); - CBotProgram::AddFunction("researched", rResearched, CScriptFunctions::cOneIntReturnBool); - CBotProgram::AddFunction("buildingenabled", rBuildingEnabled, CScriptFunctions::cOneIntReturnBool); - - CBotProgram::AddFunction("build", rBuild, CScriptFunctions::cOneInt); - - CBotProgram::AddFunction("retobject", rGetObject, CScriptFunctions::cGetObject); - CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScriptFunctions::cGetObject); - CBotProgram::AddFunction("delete", rDelete, CScriptFunctions::cDelete); - CBotProgram::AddFunction("search", rSearch, CScriptFunctions::cSearch); - CBotProgram::AddFunction("radar", rRadar, CScriptFunctions::cRadar); - CBotProgram::AddFunction("radarall", rRadarAll, CScriptFunctions::cRadarAll); - CBotProgram::AddFunction("detect", rDetect, CScriptFunctions::cDetect); - CBotProgram::AddFunction("direction", rDirection, CScriptFunctions::cDirection); - CBotProgram::AddFunction("produce", rProduce, CScriptFunctions::cProduce); - CBotProgram::AddFunction("distance", rDistance, CScriptFunctions::cDistance); - CBotProgram::AddFunction("distance2d",rDistance2d,CScriptFunctions::cDistance); - CBotProgram::AddFunction("space", rSpace, CScriptFunctions::cSpace); - CBotProgram::AddFunction("flatspace", rFlatSpace, CScriptFunctions::cFlatSpace); - CBotProgram::AddFunction("flatground",rFlatGround,CScriptFunctions::cFlatGround); - CBotProgram::AddFunction("wait", rWait, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("move", rMove, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("turn", rTurn, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("goto", rGoto, CScriptFunctions::cGoto); - CBotProgram::AddFunction("grab", rGrab, CScriptFunctions::cGrabDrop); - CBotProgram::AddFunction("drop", rDrop, CScriptFunctions::cGrabDrop); - CBotProgram::AddFunction("sniff", rSniff, CScriptFunctions::cNull); - CBotProgram::AddFunction("receive", rReceive, CScriptFunctions::cReceive); - CBotProgram::AddFunction("send", rSend, CScriptFunctions::cSend); - CBotProgram::AddFunction("deleteinfo",rDeleteInfo,CScriptFunctions::cDeleteInfo); - CBotProgram::AddFunction("testinfo", rTestInfo, CScriptFunctions::cTestInfo); - CBotProgram::AddFunction("thump", rThump, CScriptFunctions::cNull); - CBotProgram::AddFunction("recycle", rRecycle, CScriptFunctions::cNull); - CBotProgram::AddFunction("shield", rShield, CScriptFunctions::cShield); - CBotProgram::AddFunction("fire", rFire, CScriptFunctions::cFire); - CBotProgram::AddFunction("aim", rAim, CScriptFunctions::cAim); - CBotProgram::AddFunction("motor", rMotor, CScriptFunctions::cMotor); - CBotProgram::AddFunction("jet", rJet, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("topo", rTopo, CScriptFunctions::cTopo); - CBotProgram::AddFunction("message", rMessage, CScriptFunctions::cMessage); - CBotProgram::AddFunction("cmdline", rCmdline, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("ismovie", rIsMovie, CScriptFunctions::cNull); - CBotProgram::AddFunction("errmode", rErrMode, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("ipf", rIPF, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("abstime", rAbsTime, CScriptFunctions::cNull); - CBotProgram::AddFunction("deletefile",rDeleteFile,CScriptFunctions::cString); - CBotProgram::AddFunction("pendown", rPenDown, CScriptFunctions::cPenDown); - CBotProgram::AddFunction("penup", rPenUp, CScriptFunctions::cNull); - CBotProgram::AddFunction("pencolor", rPenColor, CScriptFunctions::cOneFloat); - CBotProgram::AddFunction("penwidth", rPenWidth, CScriptFunctions::cOneFloat); + CBotProgram::AddFunction("retobject", rGetObject, cGetObject); + CBotProgram::AddFunction("retobjectbyid", rGetObjectById, cGetObject); + CBotProgram::AddFunction("delete", rDelete, cDelete); + CBotProgram::AddFunction("search", rSearch, cSearch); + CBotProgram::AddFunction("radar", rRadar, cRadar); + CBotProgram::AddFunction("radarall", rRadarAll, cRadarAll); + CBotProgram::AddFunction("detect", rDetect, cDetect); + CBotProgram::AddFunction("direction", rDirection, cDirection); + CBotProgram::AddFunction("produce", rProduce, cProduce); + CBotProgram::AddFunction("distance", rDistance, cDistance); + CBotProgram::AddFunction("distance2d",rDistance2d,cDistance); + CBotProgram::AddFunction("space", rSpace, cSpace); + CBotProgram::AddFunction("flatspace", rFlatSpace, cFlatSpace); + CBotProgram::AddFunction("flatground",rFlatGround,cFlatGround); + CBotProgram::AddFunction("wait", rWait, cOneFloat); + CBotProgram::AddFunction("move", rMove, cOneFloat); + CBotProgram::AddFunction("turn", rTurn, cOneFloat); + CBotProgram::AddFunction("goto", rGoto, cGoto); + CBotProgram::AddFunction("grab", rGrab, cGrabDrop); + CBotProgram::AddFunction("drop", rDrop, cGrabDrop); + CBotProgram::AddFunction("sniff", rSniff, cNull); + CBotProgram::AddFunction("receive", rReceive, cReceive); + CBotProgram::AddFunction("send", rSend, cSend); + CBotProgram::AddFunction("deleteinfo",rDeleteInfo,cDeleteInfo); + CBotProgram::AddFunction("testinfo", rTestInfo, cTestInfo); + CBotProgram::AddFunction("thump", rThump, cNull); + CBotProgram::AddFunction("recycle", rRecycle, cNull); + CBotProgram::AddFunction("shield", rShield, cShield); + CBotProgram::AddFunction("fire", rFire, cFire); + CBotProgram::AddFunction("aim", rAim, cAim); + CBotProgram::AddFunction("motor", rMotor, cMotor); + CBotProgram::AddFunction("jet", rJet, cOneFloat); + CBotProgram::AddFunction("topo", rTopo, cTopo); + CBotProgram::AddFunction("message", rMessage, cMessage); + CBotProgram::AddFunction("cmdline", rCmdline, cOneFloat); + CBotProgram::AddFunction("ismovie", rIsMovie, cNull); + CBotProgram::AddFunction("errmode", rErrMode, cOneFloat); + CBotProgram::AddFunction("ipf", rIPF, cOneFloat); + CBotProgram::AddFunction("abstime", rAbsTime, cNull); + CBotProgram::AddFunction("pendown", rPenDown, cPenDown); + CBotProgram::AddFunction("penup", rPenUp, cNull); + CBotProgram::AddFunction("pencolor", rPenColor, cOneFloat); + CBotProgram::AddFunction("penwidth", rPenWidth, cOneFloat); CBotProgram::AddFunction("camerafocus", rCameraFocus, CScriptFunctions::cOneObject); + + SetFileAccessHandler(MakeUnique()); } @@ -4016,3 +3444,8 @@ void CScriptFunctions::DestroyObjectVar(CBotVar* botVar, bool permanent) if (permanent) CBotVar::Destroy(botVar); } + +bool CScriptFunctions::CheckOpenFiles() +{ + return CBotFileColobot::m_numFilesOpen > 0; +} \ No newline at end of file diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index e739ecdd..8746ae57 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -42,17 +42,13 @@ class CScriptFunctions { public: static void Init(); + static CBotVar* CreateObjectVar(CObject* obj); static void DestroyObjectVar(CBotVar* botVar, bool permanent); + static bool CheckOpenFiles(); + private: - static CBotTypResult cNull(CBotVar* &var, void* user); - static CBotTypResult cOneFloat(CBotVar* &var, void* user); - static CBotTypResult cTwoFloat(CBotVar* &var, void* user); - static CBotTypResult cString(CBotVar* &var, void* user); - static CBotTypResult cStringString(CBotVar* &var, void* user); - static CBotTypResult cOneInt(CBotVar* &var, void* user); - static CBotTypResult cOneIntReturnBool(CBotVar* &var, void* user); static CBotTypResult cEndMission(CBotVar* &var, void* user); static CBotTypResult cPlayMusic(CBotVar* &var, void* user); static CBotTypResult cGetObject(CBotVar* &var, void* user); @@ -80,22 +76,11 @@ private: static CBotTypResult cTopo(CBotVar* &var, void* user); static CBotTypResult cMessage(CBotVar* &var, void* user); 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); - static bool rCos(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rTan(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rSqrt(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rPow(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rRand(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rAbs(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rFloor(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rCeil(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rRound(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rTrunc(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user); @@ -149,7 +134,6 @@ private: static bool rErrMode(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rIPF(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rAbsTime(CBotVar* var, CBotVar* result, int& exception, void* user); - static bool rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenDown(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user); @@ -168,37 +152,14 @@ private: static bool rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user); - - static CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar); - static CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar); - static CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar); - static CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar); - static CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar); - static CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar); - static bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user); - static CBotTypResult cPointConstructor(CBotVar* pThis, CBotVar* &var); static bool rPointConstructor(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception, void* user); static void uObject(CBotVar* botThis, void* user); -public: - static int m_numberOfOpenFiles; - private: static bool WaitForForegroundTask(CScript* script, CBotVar* result, int &exception); static bool WaitForBackgroundTask(CScript* script, CBotVar* result, int &exception); static bool ShouldTaskStop(Error err, int errMode); static CExchangePost* FindExchangePost(CObject* object, float power); - - static bool FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception); - - static std::unordered_map> m_files; - static int m_nextFile; }; From 5db1254dd8b71a2a5d48dead9cf4e7beb8e21455 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 19:01:03 +0100 Subject: [PATCH 159/360] Unified CBot error naming --- po/colobot.pot | 3 + po/de.po | 6 +- po/fr.po | 6 +- po/pl.po | 6 +- po/ru.po | 6 +- src/CBot/CBotCStack.cpp | 2 +- src/CBot/CBotCall.cpp | 2 +- src/CBot/CBotClass.cpp | 26 +++--- src/CBot/CBotDefParam.cpp | 8 +- src/CBot/CBotDefines.h | 81 ++-------------- src/CBot/CBotInstr/CBotBlock.cpp | 4 +- src/CBot/CBotInstr/CBotBoolExpr.cpp | 2 +- src/CBot/CBotInstr/CBotBoolean.cpp | 8 +- src/CBot/CBotInstr/CBotBreak.cpp | 6 +- src/CBot/CBotInstr/CBotCase.cpp | 4 +- src/CBot/CBotInstr/CBotCatch.cpp | 6 +- src/CBot/CBotInstr/CBotClassInst.cpp | 18 ++-- src/CBot/CBotInstr/CBotCondition.cpp | 4 +- src/CBot/CBotInstr/CBotDo.cpp | 4 +- src/CBot/CBotInstr/CBotExprUnaire.cpp | 2 +- src/CBot/CBotInstr/CBotExprVar.cpp | 16 ++-- src/CBot/CBotInstr/CBotExpression.cpp | 16 ++-- src/CBot/CBotInstr/CBotFieldExpr.cpp | 8 +- src/CBot/CBotInstr/CBotFloat.cpp | 8 +- src/CBot/CBotInstr/CBotFor.cpp | 8 +- src/CBot/CBotInstr/CBotFunction.cpp | 36 ++++---- src/CBot/CBotInstr/CBotIString.cpp | 6 +- src/CBot/CBotInstr/CBotIndexExpr.cpp | 6 +- src/CBot/CBotInstr/CBotInstArray.cpp | 6 +- src/CBot/CBotInstr/CBotInstr.cpp | 14 +-- src/CBot/CBotInstr/CBotInstrCall.cpp | 4 +- src/CBot/CBotInstr/CBotInstrMethode.cpp | 2 +- src/CBot/CBotInstr/CBotInstrUtils.cpp | 4 +- src/CBot/CBotInstr/CBotInt.cpp | 8 +- src/CBot/CBotInstr/CBotLeftExpr.cpp | 16 ++-- src/CBot/CBotInstr/CBotLeftExprVar.cpp | 2 +- src/CBot/CBotInstr/CBotListArray.cpp | 6 +- src/CBot/CBotInstr/CBotListInstr.cpp | 2 +- src/CBot/CBotInstr/CBotNew.cpp | 6 +- src/CBot/CBotInstr/CBotParExpr.cpp | 6 +- src/CBot/CBotInstr/CBotPostIncExpr.cpp | 4 +- src/CBot/CBotInstr/CBotPreIncExpr.cpp | 4 +- src/CBot/CBotInstr/CBotReturn.cpp | 6 +- src/CBot/CBotInstr/CBotSwitch.cpp | 14 +-- src/CBot/CBotInstr/CBotThrow.cpp | 4 +- src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 14 +-- src/CBot/CBotProgram.cpp | 34 +++---- src/CBot/CBotStack.cpp | 4 +- src/CBot/CBotUtils.cpp | 2 +- src/CBot/CBotVar/CBotVarFloat.cpp | 4 +- src/CBot/CBotVar/CBotVarInt.cpp | 4 +- src/CBot/stdlib/Compilation.cpp | 50 +++++----- src/CBot/stdlib/StringFunctions.cpp | 66 ++++++------- src/common/restext.cpp | 118 ++++++++++++------------ 54 files changed, 325 insertions(+), 387 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 28315a39..eb7538a1 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -1622,6 +1622,9 @@ msgstr "" msgid "Instruction \"case\" outside a block \"switch\"" msgstr "" +msgid "Instructions after the final closing brace" +msgstr "" + msgid "End of block missing" msgstr "" diff --git a/po/de.po b/po/de.po index ad1ac8cc..05f592fb 100644 --- a/po/de.po +++ b/po/de.po @@ -736,6 +736,9 @@ msgstr "Anweisung \"else\" ohne vorhergehende Anweisung \"if\"" msgid "Instructions (\\key help;)" msgstr "Anweisungen (\\key help;)" +msgid "Instructions after the final closing brace" +msgstr "Hier ist eine Anweisung nach dem Ende des Programms" + msgid "Instructions for the mission (\\key help;)" msgstr "Anweisungen über die Mission(\\key help;)" @@ -1863,9 +1866,6 @@ msgstr "www.epsitec.com" #~ msgid "Ground inappropriate" #~ msgstr "Boden ungeeignet" -#~ msgid "Instructions after the final closing brace" -#~ msgstr "Hier ist eine Anweisung nach dem Ende des Programms" - #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Hilfe über Begriff\\Hilfe über einen Begriff" diff --git a/po/fr.po b/po/fr.po index 6ed78e66..df972dca 100644 --- a/po/fr.po +++ b/po/fr.po @@ -730,6 +730,9 @@ msgstr "Instruction \"else\" sans \"if\" correspondant" msgid "Instructions (\\key help;)" msgstr "Instructions (\\key help;)" +msgid "Instructions after the final closing brace" +msgstr "Instructions après la fin" + msgid "Instructions for the mission (\\key help;)" msgstr "Instructions sur la mission (\\key help;)" @@ -1850,9 +1853,6 @@ msgstr "www.epsitec.com" #~ msgid "Ground inappropriate" #~ msgstr "Terrain inadapté" -#~ msgid "Instructions after the final closing brace" -#~ msgstr "Instructions après la fin" - #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Instructions mot-clé\\Explication sur le mot-clé" diff --git a/po/pl.po b/po/pl.po index 4180c418..f4cbf2cb 100644 --- a/po/pl.po +++ b/po/pl.po @@ -737,6 +737,9 @@ msgstr "Polecenie \"else\" bez wystąpienia \"if\" " msgid "Instructions (\\key help;)" msgstr "Rozkazy (\\key help;)" +msgid "Instructions after the final closing brace" +msgstr "Polecenie po końcowej klamrze zamykającej" + msgid "Instructions for the mission (\\key help;)" msgstr "Rozkazy dotyczące misji (\\key help;)" @@ -1841,9 +1844,6 @@ msgstr "www.epsitec.com" #~ msgid "Ground inappropriate" #~ msgstr "Nieodpowiedni teren" -#~ msgid "Instructions after the final closing brace" -#~ msgstr "Polecenie po końcowej klamrze zamykającej" - #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "" #~ "Pomoc dot. słów kluczowych\\Dokładniejsza pomoc na temat słów kluczowych" diff --git a/po/ru.po b/po/ru.po index 2248e642..c29a8bff 100644 --- a/po/ru.po +++ b/po/ru.po @@ -729,6 +729,9 @@ msgstr "Инструкция \"else\" без \"if\" " msgid "Instructions (\\key help;)" msgstr "Инструкции (\\key help;)" +msgid "Instructions after the final closing brace" +msgstr "Инструкция после последней закрывающей фигурной скобки" + msgid "Instructions for the mission (\\key help;)" msgstr "Инструкции для миссии (\\key help;)" @@ -1854,9 +1857,6 @@ msgstr "www.epsitec.com" #~ msgid "Ground inappropriate" #~ msgstr "Земля не подходит" -#~ msgid "Instructions after the final closing brace" -#~ msgstr "Инструкция после последней закрывающей фигурной скобки" - #~ msgid "Key word help\\More detailed help about key words" #~ msgstr "Помощь по командам\\Более подробная справку по командам" diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index df1f5630..6d8b027c 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -257,7 +257,7 @@ bool CBotCStack::NextToken(CBotToken* &p) p = p->GetNext(); if (p!=nullptr) return true; - SetError(TX_ENDOF, pp->GetEnd()); + SetError(CBotErrNoTerminator, pp->GetEnd()); return false; } diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index f391c3d3..8f4cfe51 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -222,7 +222,7 @@ fund: if ( rettype.GetType() > 0 && pResult == nullptr ) { - pStack->SetError(TX_NORETVAL, token); + pStack->SetError(CBotErrNoRetVal, token); } nIdent = pt->m_nFuncIdent; return true; diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index e7d67191..48e74395 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -393,7 +393,7 @@ CBotTypResult CBotClass::CompileMethode(const std::string& name, // find the methods declared by user r = m_pMethod->CompileCall(name, ppParams, nIdent); - if ( r.Eq(TX_UNDEFCALL) && m_pParent != nullptr ) + if ( r.Eq(CBotErrUndefCall) && m_pParent != nullptr ) return m_pParent->m_pMethod->CompileCall(name, ppParams, nIdent); return r; } @@ -535,7 +535,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_PUBLIC) ) { - pStack->SetError(TX_NOPUBLIC, p); + pStack->SetError(CBotErrNoPublic, p); return nullptr; } @@ -546,7 +546,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) CBotClass* pOld = CBotClass::Find(name); if ( pOld != nullptr && pOld->m_IsDef ) { - pStack->SetError( TX_REDEFCLASS, p ); + pStack->SetError( CBotErrRedefClass, p ); return nullptr; } @@ -561,7 +561,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, TokenTypVar) || pPapa == nullptr ) { - pStack->SetError( TX_NOCLASS, p ); + pStack->SetError( CBotErrNotClass, p ); return nullptr; } } @@ -571,7 +571,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) if ( !IsOfType( p, ID_OPBLK) ) { - pStack->SetError(TX_OPENBLK, p); + pStack->SetError(CBotErrOpenBlock, p); return nullptr; } @@ -582,7 +582,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) if (pStack->IsOk()) return classe; } - pStack->SetError(TX_ENDOF, p); + pStack->SetError(CBotErrNoTerminator, p); return nullptr; } @@ -611,7 +611,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( type.Eq(-1) ) { - pStack->SetError(TX_NOTYP, p); + pStack->SetError(CBotErrNoType, p); return false; } @@ -636,14 +636,14 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) ) { - pStack->SetError(TX_CLBRK, p->GetStart()); + pStack->SetError(CBotErrCloseIndex, p->GetStart()); return false; } /* CBotVar* pv = pStack->GetVar(); if ( pv->GetType()>= CBotTypBoolean ) { - pStack->SetError(TX_BADTYPE, p->GetStart()); + pStack->SetError(CBotErrBadType1, p->GetStart()); return false; }*/ @@ -739,7 +739,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) // definition of an element if (type.Eq(0)) { - pStack->SetError(TX_ENDOF, p); + pStack->SetError(CBotErrNoTerminator, p); return false; } @@ -785,7 +785,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( IsOfType(p, ID_COMMA) ) continue; if ( IsOfType(p, ID_SEP) ) break; } - pStack->SetError(TX_ENDOF, p); + pStack->SetError(CBotErrNoTerminator, p); } return pStack->IsOk(); } @@ -812,7 +812,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, TokenTypVar) || pPapa == nullptr) { - pStack->SetError( TX_NOCLASS, p ); + pStack->SetError( CBotErrNotClass, p ); return nullptr; } pOld->m_pParent = pPapa; @@ -834,6 +834,6 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) pOld->m_IsDef = true; // complete definition if (pStack->IsOk()) return pOld; } - pStack->SetError(TX_ENDOF, p); + pStack->SetError(CBotErrNoTerminator, p); return nullptr; } diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp index 2e48c06f..df0ff96e 100644 --- a/src/CBot/CBotDefParam.cpp +++ b/src/CBot/CBotDefParam.cpp @@ -76,7 +76,7 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) // variable already declared? if (pStack->CheckVarLocal(pp)) { - pStack->SetError(TX_REDEFVAR, pp); + pStack->SetError(CBotErrRedefVar, pp); break; } @@ -91,15 +91,15 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) if (IsOfType(p, ID_COMMA) || p->GetType() == ID_CLOSEPAR) continue; } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); + pStack->SetError(CBotErrClosePar, p->GetStart()); } - pStack->SetError(TX_NOTYP, p); + pStack->SetError(CBotErrNoType, p); delete list; return nullptr; } return list; } - pStack->SetError(TX_OPENPAR, p->GetStart()); + pStack->SetError(CBotErrOpenPar, p->GetStart()); return nullptr; } diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 514e733d..09b11e5c 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -55,9 +55,7 @@ // TODO: Why are all of those duplicated? This needs to be unified across the source code ~krzys_h -// Here are the list of errors that can be returned by the module -// for compilation - +// Compile errors #define CBotErrOpenPar 5000 // missing the opening parenthesis #define CBotErrClosePar 5001 // missing the closing parenthesis #define CBotErrNotBoolean 5002 // expression must be a boolean @@ -65,6 +63,7 @@ #define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... ) #define CBotErrNoTerminator 5005 // semicolon expected #define CBotErrCaseOut 5006 // case outside a switch +#define CBotErrNoEnd 5007 // instructions after final closing brace #define CBotErrCloseBlock 5008 // missing " } " #define CBotErrElseWhitoutIf 5009 // else without matching if #define CBotErrOpenBlock 5010 // missing " { " @@ -73,6 +72,7 @@ #define CBotErrBadType2 5013 // Two operands are incompatible #define CBotErrUndefCall 5014 // routine undefined #define CBotErrNoDoubleDots 5015 // " : " expected +#define CBotErrNoWhile 5016 // "while" expected (in do..while) #define CBotErrBreakOutside 5017 // break outside of a loop #define CBotErrUndefLabel 5019 // label udnefined #define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here) @@ -100,9 +100,7 @@ #define CBotErrPrivate 5041 // protected item #define CBotErrNoPublic 5042 // missing word "public" -// here is the list of errors that can be returned by the module -// for the execution - +// Runtime errors #define CBotErrZeroDiv 6000 // division by zero #define CBotErrNotInit 6001 // uninitialized variable #define CBotErrBadThrow 6002 // throw a negative value @@ -120,74 +118,9 @@ #define CBotErrRead 6014 // error while reading #define CBotErrWrite 6015 // writing error +// Max errors +#define TX_MAX 6016 + // other values ​​may be returned // for example exceptions returned by external routines // and " throw " with any number. - -// TODO: refactor & change to enum! - -// Compile errors -#define TX_OPENPAR 5000 -#define TX_CLOSEPAR 5001 -#define TX_NOTBOOL 5002 -#define TX_UNDEFVAR 5003 -#define TX_BADLEFT 5004 -#define TX_ENDOF 5005 -#define TX_OUTCASE 5006 -#define TX_NOTERM 5007 -#define TX_CLOSEBLK 5008 -#define TX_ELSEWITHOUTIF 5009 -#define TX_OPENBLK 5010 -#define TX_BADTYPE 5011 -#define TX_REDEFVAR 5012 -#define TX_BAD2TYPE 5013 -#define TX_UNDEFCALL 5014 -#define TX_MISDOTS 5015 -#define TX_WHILE 5016 -#define TX_BREAK 5017 -#define TX_LABEL 5018 -#define TX_NOLABEL 5019 -#define TX_NOCASE 5020 -#define TX_BADNUM 5021 -#define TX_VOID 5022 -#define TX_NOTYP 5023 -#define TX_NOVAR 5024 -#define TX_NOFONC 5025 -#define TX_OVERPARAM 5026 -#define TX_REDEF 5027 -#define TX_LOWPARAM 5028 -#define TX_BADPARAM 5029 -#define TX_NUMPARAM 5030 -#define TX_NOITEM 5031 -#define TX_DOT 5032 -#define TX_NOCONST 5033 -#define TX_REDEFCLASS 5034 -#define TX_CLBRK 5035 -#define TX_RESERVED 5036 -#define TX_BADNEW 5037 -#define TX_OPBRK 5038 -#define TX_BADSTRING 5039 -#define TX_BADINDEX 5040 -#define TX_PRIVATE 5041 -#define TX_NOPUBLIC 5042 - -// Runtime errors -#define TX_DIVZERO 6000 -#define TX_NOTINIT 6001 -#define TX_BADTHROW 6002 -#define TX_NORETVAL 6003 -#define TX_NORUN 6004 -#define TX_NOCALL 6005 -#define TX_NOCLASS 6006 -#define TX_NULLPT 6007 -#define TX_OPNAN 6008 -#define TX_OUTARRAY 6009 -#define TX_STACKOVER 6010 -#define TX_DELETEDPT 6011 -#define TX_FILEOPEN 6012 -#define TX_NOTOPEN 6013 -#define TX_ERRREAD 6014 -#define TX_ERRWRITE 6015 - -// Max errors (NOTE: See above TODO near file errors) -#define TX_MAX 6016 diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp index 9e6b2537..105b718a 100644 --- a/src/CBot/CBotInstr/CBotBlock.cpp +++ b/src/CBot/CBotInstr/CBotBlock.cpp @@ -44,12 +44,12 @@ CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) return inst; } - pStack->SetError(TX_CLOSEBLK, p->GetStart()); // missing parenthesis + pStack->SetError(CBotErrCloseBlock, p->GetStart()); // missing parenthesis delete inst; return nullptr; } - pStack->SetError(TX_OPENBLK, p->GetStart()); + pStack->SetError(CBotErrOpenBlock, p->GetStart()); return nullptr; } diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp index e219d159..a3251380 100644 --- a/src/CBot/CBotInstr/CBotBoolExpr.cpp +++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp @@ -44,7 +44,7 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) { return inst; } - pStack->SetError(TX_NOTBOOL, p->GetStart()); // is not a boolean + pStack->SetError(CBotErrNotBoolean, p->GetStart()); // is not a boolean } delete inst; diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp index 0b44d71e..802727b2 100644 --- a/src/CBot/CBotInstr/CBotBoolean.cpp +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -73,7 +73,7 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo (static_cast(inst->m_var))->m_typevar = CBotTypBoolean; if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable { - pStk->SetError(TX_REDEFVAR, vartoken); + pStk->SetError(CBotErrRedefVar, vartoken); goto error; } @@ -88,7 +88,7 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo if (!pStk->IsOk() ) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto error; } goto suite; // no assignment, variable already created @@ -102,7 +102,7 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo } if (!pStk->GetTypResult().Eq(CBotTypBoolean)) { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } } @@ -126,7 +126,7 @@ suite: return pStack->Return(inst, pStk); } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } error: diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp index b0a308de..d76588b4 100644 --- a/src/CBot/CBotInstr/CBotBreak.cpp +++ b/src/CBot/CBotInstr/CBotBreak.cpp @@ -48,7 +48,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) if ( !ChkLvl(std::string(), type ) ) { - pStack->SetError(TX_BREAK, pp); + pStack->SetError(CBotErrBreakOutside, pp); return nullptr; // no object, the error is on the stack } @@ -62,7 +62,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) if ( !ChkLvl(inst->m_label, type ) ) { delete inst; - pStack->SetError(TX_NOLABEL, pp); + pStack->SetError(CBotErrUndefLabel, pp); return nullptr; // no object, the error is on the stack } } @@ -73,7 +73,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack) } delete inst; - pStack->SetError(TX_ENDOF, p->GetStart()); + pStack->SetError(CBotErrNoTerminator, p->GetStart()); return nullptr; // no object, the error is on the stack } diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp index 9387330f..96c22ff4 100644 --- a/src/CBot/CBotInstr/CBotCase.cpp +++ b/src/CBot/CBotInstr/CBotCase.cpp @@ -56,14 +56,14 @@ CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack) inst->m_Value = CBotExprNum::Compile(p, pStack); if ( inst->m_Value == nullptr ) { - pStack->SetError( TX_BADNUM, pp ); + pStack->SetError( CBotErrBadNum, pp ); delete inst; return nullptr; } } if ( !IsOfType( p, ID_DOTS )) { - pStack->SetError( TX_MISDOTS, p->GetStart() ); + pStack->SetError( CBotErrNoDoubleDots, p->GetStart() ); delete inst; return nullptr; } diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp index f62f662e..d187bec9 100644 --- a/src/CBot/CBotInstr/CBotCatch.cpp +++ b/src/CBot/CBotInstr/CBotCatch.cpp @@ -70,11 +70,11 @@ CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack) if ( pStack->IsOk() ) return inst; // return an object to the application } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); + pStack->SetError(CBotErrClosePar, p->GetStart()); } - pStack->SetError(TX_BADTYPE, p->GetStart()); + pStack->SetError(CBotErrBadType1, p->GetStart()); } - pStack->SetError(TX_OPENPAR, p->GetStart()); + pStack->SetError(CBotErrOpenPar, p->GetStart()); delete inst; // error, frees up return nullptr; // no object, the error is on the stack } diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index e03fa3d6..25700536 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -67,7 +67,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* if ( pClass == nullptr ) { // not found? is bizare - pStack->SetError(TX_NOCLASS, p); + pStack->SetError(CBotErrNotClass, p); return nullptr; } p = p->GetNext(); @@ -92,7 +92,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable { pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + pStk->SetError(CBotErrRedefVar, vartoken->GetEnd()); goto error; } @@ -107,7 +107,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* if (!pStk->IsOk() ) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto error; } goto suite; // no assignment, variable already created @@ -142,12 +142,12 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* delete pStk->TokenStack(); // releases the supplement stack int typ = r.GetType(); - if (typ == TX_UNDEFCALL) + if (typ == CBotErrUndefCall) { // si le constructeur n'existe pas if (inst->m_Parameters != nullptr) // with parameters { - pStk->SetError(TX_NOCONST, vartoken); + pStk->SetError(CBotErrNoConstruct, vartoken); goto error; } typ = 0; @@ -165,7 +165,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* { if (inst->m_hasParams) { - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); goto error; } @@ -178,7 +178,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* ( !pStk->GetTypResult(1).Eq(CBotTypPointer) || ( result != nullptr && !pClass->IsChildOf(result) ))) // type compatible ? { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } // if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer()); @@ -217,7 +217,7 @@ suite: return pStack->Return(inst, pStk); } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } error: @@ -275,7 +275,7 @@ bool CBotClassInst::Execute(CBotStack* &pj) CBotVar* pv = pile->GetVar(); if ( pv == nullptr || pv->GetPointer() == nullptr ) { - pile->SetError(TX_NULLPT, &m_token); + pile->SetError(CBotErrNull, &m_token); return pj->Return(pile); } pThis->Copy(pile->GetVar(), false); diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp index 6c88869e..72a70b2d 100644 --- a/src/CBot/CBotInstr/CBotCondition.cpp +++ b/src/CBot/CBotInstr/CBotCondition.cpp @@ -43,12 +43,12 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) { return inst; } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); // missing parenthesis + pStack->SetError(CBotErrClosePar, p->GetStart()); // missing parenthesis } delete inst; } - pStack->SetError(TX_OPENPAR, p->GetStart()); // missing parenthesis + pStack->SetError(CBotErrOpenPar, p->GetStart()); // missing parenthesis return nullptr; } diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp index ef682b36..60cb4274 100644 --- a/src/CBot/CBotInstr/CBotDo.cpp +++ b/src/CBot/CBotInstr/CBotDo.cpp @@ -80,10 +80,10 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack) { return pStack->Return(inst, pStk); // return an object to the application } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } } - pStk->SetError(TX_WHILE, p->GetStart()); + pStk->SetError(CBotErrNoWhile, p->GetStart()); } delete inst; // error, frees up diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp index 50e39a78..656bda9b 100644 --- a/src/CBot/CBotInstr/CBotExprUnaire.cpp +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -69,7 +69,7 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) if (op == ID_TXT_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean return pStack->Return(inst, pStk); - pStk->SetError(TX_BADTYPE, &inst->m_token); + pStk->SetError(CBotErrBadType1, &inst->m_token); } delete inst; return pStack->Return(nullptr, pStk); diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 4dc078dd..d956d437 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -72,7 +72,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) if ( var->IsPrivate(privat) && !pStk->GetBotCall()->m_bCompileClass) { - pStk->SetError(TX_PRIVATE, p); + pStk->SetError(CBotErrPrivate, p); goto err; } @@ -104,12 +104,12 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) if (i->m_expr == nullptr) { - pStk->SetError(TX_BADINDEX, p->GetStart()); + pStk->SetError(CBotErrBadIndex, p->GetStart()); goto err; } if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto err; } continue; @@ -142,7 +142,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) if ( var->IsPrivate() && !pStk->GetBotCall()->m_bCompileClass) { - pStk->SetError(TX_PRIVATE, pp); + pStk->SetError(CBotErrPrivate, pp); goto err; } } @@ -154,10 +154,10 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) p = p->GetNext(); // skips the name continue; } - pStk->SetError(TX_NOITEM, p); + pStk->SetError(CBotErrUndefItem, p); goto err; } - pStk->SetError(TX_DOT, p->GetStart()); + pStk->SetError(CBotErrUndefClass, p->GetStart()); goto err; } } @@ -168,7 +168,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) pStk->SetCopyVar(var); // place the copy of the variable on the stack (for type) if (pStk->IsOk()) return pStack->Return(inst, pStk); } - pStk->SetError(TX_UNDEFVAR, p); + pStk->SetError(CBotErrUndefVar, p); err: delete inst; return pStack->Return(nullptr, pStk); @@ -252,7 +252,7 @@ bool CBotExprVar::Execute(CBotStack* &pj) { CBotToken* pt = &m_token; while (pt->GetNext() != nullptr) pt = pt->GetNext(); - pile1->SetError(TX_NOTINIT, pt); + pile1->SetError(CBotErrNotInit, pt); return pj->Return(pile1); } return pj->Return(pile1); // operation completed diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index d3821aab..b277fb46 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -69,7 +69,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) { if (inst->m_leftop == nullptr) { - pStack->SetError(TX_BADLEFT, p->GetEnd()); + pStack->SetError(CBotErrBadLeft, p->GetEnd()); delete inst; return nullptr; } @@ -94,7 +94,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) if (OpType != ID_ASS && !var->IsDefined()) { - pStack->SetError(TX_NOTINIT, pp); + pStack->SetError(CBotErrNotInit, pp); delete inst; return nullptr; } @@ -133,7 +133,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) if (!TypeCompatible(type1, type2, OpType)) { - pStack->SetError(TX_BADTYPE, &inst->m_token); + pStack->SetError(CBotErrBadType1, &inst->m_token); delete inst; return nullptr; } @@ -148,7 +148,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) pStack->SetError(0,0); // forget the error CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment - if (i != nullptr && error == TX_PRIVATE && p->GetType() == ID_ASS) + if (i != nullptr && error == CBotErrPrivate && p->GetType() == ID_ASS) pStack->ResetError(error, start, end); return i; } @@ -192,7 +192,7 @@ bool CBotExpression::Execute(CBotStack* &pj) initKind = pVar->GetInit(); if (initKind == CBotVar::InitType::IS_NAN) { - pile2->SetError(TX_OPNAN, m_leftop->GetToken()); + pile2->SetError(CBotErrNan, m_leftop->GetToken()); return pj->Return(pile2); } result = CBotVar::Create("", pVar->GetTypResult(2)); @@ -217,13 +217,13 @@ bool CBotExpression::Execute(CBotStack* &pj) case ID_ASSDIV: if (initKind != CBotVar::InitType::UNDEF && result->Div(pile1->GetVar(), pile2->GetVar())) - pile2->SetError(TX_DIVZERO, &m_token); + pile2->SetError(CBotErrZeroDiv, &m_token); pile2->SetVar(result); break; case ID_ASSMODULO: if (initKind != CBotVar::InitType::UNDEF && result->Modulo(pile1->GetVar(), pile2->GetVar())) - pile2->SetError(TX_DIVZERO, &m_token); + pile2->SetError(CBotErrZeroDiv, &m_token); pile2->SetVar(result); break; case ID_ASSAND: @@ -254,7 +254,7 @@ bool CBotExpression::Execute(CBotStack* &pj) assert(0); } if (initKind == CBotVar::InitType::UNDEF) - pile2->SetError(TX_NOTINIT, m_leftop->GetToken()); + pile2->SetError(CBotErrNotInit, m_leftop->GetToken()); pile1->IncState(); } diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index c5817695..01054555 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -58,7 +58,7 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) pVar = pVar->GetItemRef(m_nIdent); if (pVar == nullptr) { - pile->SetError(TX_NOITEM, &m_token); + pile->SetError(CBotErrUndefItem, &m_token); return false; } @@ -82,12 +82,12 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev CBotVarClass* pItem = pVar->GetPointer(); if (pItem == nullptr) { - pile->SetError(TX_NULLPT, prevToken); + pile->SetError(CBotErrNull, prevToken); return pj->Return(pile); } if (pItem->GetUserPtr() == OBJECTDELETED) { - pile->SetError(TX_DELETEDPT, prevToken); + pile->SetError(CBotErrDeletedPtr, prevToken); return pj->Return(pile); } @@ -96,7 +96,7 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev pVar = pVar->GetItemRef(m_nIdent); if (pVar == nullptr) { - pile->SetError(TX_NOITEM, &m_token); + pile->SetError(CBotErrUndefItem, &m_token); return pj->Return(pile); } diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp index f4a8ac31..f7cbfedf 100644 --- a/src/CBot/CBotInstr/CBotFloat.cpp +++ b/src/CBot/CBotInstr/CBotFloat.cpp @@ -74,7 +74,7 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable { pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + pStk->SetError(CBotErrRedefVar, vartoken->GetEnd()); goto error; } @@ -86,7 +86,7 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool if (!pStk->IsOk() ) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto error; } goto suite; // no assignment, variable already created @@ -100,7 +100,7 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool } if (pStk->GetType() >= CBotTypBoolean) { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } } @@ -124,7 +124,7 @@ suite: return pStack->Return(inst, pStk); } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } error: diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp index 80488328..2b93a171 100644 --- a/src/CBot/CBotInstr/CBotFor.cpp +++ b/src/CBot/CBotInstr/CBotFor.cpp @@ -66,7 +66,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) if ( !IsOfType(p, ID_OPENPAR)) // missing parenthesis ? { - pStack->SetError(TX_OPENPAR, p->GetStart()); + pStack->SetError(CBotErrOpenPar, p->GetStart()); return nullptr; } @@ -78,7 +78,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_SEP)) // lack the semicolon? { - pStack->SetError(TX_OPENPAR, p->GetStart()); + pStack->SetError(CBotErrOpenPar, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); // no object, the error is on the stack } @@ -87,7 +87,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_SEP)) // lack the semicolon? { - pStack->SetError(TX_OPENPAR, p->GetStart()); + pStack->SetError(CBotErrOpenPar, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); // no object, the error is on the stack } @@ -102,7 +102,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack) if ( pStk->IsOk() ) return pStack->Return(inst, pStk);; } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); + pStack->SetError(CBotErrClosePar, p->GetStart()); } } } diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 0744f70c..f024d7d2 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -248,9 +248,9 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct } } bad: - pStk->SetError(TX_NOFONC, p); + pStk->SetError(CBotErrNoFunc, p); } - pStk->SetError(TX_NOTYP, p); + pStk->SetError(CBotErrNoType, p); if ( finput == nullptr ) delete func; return pStack->ReturnFunc(nullptr, pStk); } @@ -294,7 +294,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas CBotClass* pClass = CBotClass::Find(pp); if ( pClass == nullptr ) { - pStk->SetError(TX_NOCLASS, pp); + pStk->SetError(CBotErrNotClass, pp); goto bad; } @@ -325,15 +325,15 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas return pStack->ReturnFunc(func, pStk); } - pStk->SetError(TX_OPENBLK, p); + pStk->SetError(CBotErrOpenBlock, p); } } - pStk->SetError(TX_REDEF, pp); + pStk->SetError(CBotErrRedefFunc, pp); } bad: - pStk->SetError(TX_NOFONC, p); + pStk->SetError(CBotErrNoFunc, p); } - pStk->SetError(TX_NOTYP, p); + pStk->SetError(CBotErrNoType, p); delete func; return pStack->ReturnFunc(nullptr, pStk); } @@ -445,7 +445,7 @@ CBotTypResult CBotFunction::CompileCall(const std::string& name, CBotVar** ppVar CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic) { - TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name + TypeOrError.SetType(CBotErrUndefCall); // no routine of the name CBotFunction* pt; if ( nIdent ) @@ -491,7 +491,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n { if (!TypesCompatibles(pv->GetTypResult(), pw->GetTypResult())) { - if ( pFunc == nullptr ) TypeOrError = TX_BADPARAM; + if ( pFunc == nullptr ) TypeOrError = CBotErrBadParam; break; } int d = pv->GetType() - pw->GetType(2); @@ -503,15 +503,15 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n if ( pw != nullptr ) { if ( pFunc != nullptr ) continue; - if ( TypeOrError.Eq(TX_LOWPARAM) ) TypeOrError.SetType(TX_NUMPARAM); - if ( TypeOrError.Eq(TX_UNDEFCALL)) TypeOrError.SetType(TX_OVERPARAM); + if ( TypeOrError.Eq(CBotErrLowParam) ) TypeOrError.SetType(CBotErrNbParam); + if ( TypeOrError.Eq(CBotErrUndefCall)) TypeOrError.SetType(CBotErrOverParam); continue; // too many parameters } if ( pv != nullptr ) { if ( pFunc != nullptr ) continue; - if ( TypeOrError.Eq(TX_OVERPARAM) ) TypeOrError.SetType(TX_NUMPARAM); - if ( TypeOrError.Eq(TX_UNDEFCALL) ) TypeOrError.SetType(TX_LOWPARAM); + if ( TypeOrError.Eq(CBotErrOverParam) ) TypeOrError.SetType(CBotErrNbParam); + if ( TypeOrError.Eq(CBotErrUndefCall) ) TypeOrError.SetType(CBotErrLowParam); continue; // not enough parameters } @@ -546,7 +546,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n { if (!TypesCompatibles(pv->GetTypResult(), pw->GetTypResult())) { - if ( pFunc == nullptr ) TypeOrError = TX_BADPARAM; + if ( pFunc == nullptr ) TypeOrError = CBotErrBadParam; break; } int d = pv->GetType() - pw->GetType(2); @@ -558,15 +558,15 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n if ( pw != nullptr ) { if ( pFunc != nullptr ) continue; - if ( TypeOrError.Eq(TX_LOWPARAM) ) TypeOrError.SetType(TX_NUMPARAM); - if ( TypeOrError.Eq(TX_UNDEFCALL)) TypeOrError.SetType(TX_OVERPARAM); + if ( TypeOrError.Eq(CBotErrLowParam) ) TypeOrError.SetType(CBotErrNbParam); + if ( TypeOrError.Eq(CBotErrUndefCall)) TypeOrError.SetType(CBotErrOverParam); continue; // to many parameters } if ( pv != nullptr ) { if ( pFunc != nullptr ) continue; - if ( TypeOrError.Eq(TX_OVERPARAM) ) TypeOrError.SetType(TX_NUMPARAM); - if ( TypeOrError.Eq(TX_UNDEFCALL) ) TypeOrError.SetType(TX_LOWPARAM); + if ( TypeOrError.Eq(CBotErrOverParam) ) TypeOrError.SetType(CBotErrNbParam); + if ( TypeOrError.Eq(CBotErrUndefCall) ) TypeOrError.SetType(CBotErrLowParam); continue; // not enough parameters } diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp index be03c6e8..90001888 100644 --- a/src/CBot/CBotInstr/CBotIString.cpp +++ b/src/CBot/CBotInstr/CBotIString.cpp @@ -72,7 +72,7 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo if (pStk->CheckVarLocal(vartoken)) { pStk->SetStartError(vartoken->GetStart()); - pStk->SetError(TX_REDEFVAR, vartoken->GetEnd()); + pStk->SetError(CBotErrRedefVar, vartoken->GetEnd()); goto error; } @@ -84,7 +84,7 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo } /* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ? { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; }*/ } @@ -108,7 +108,7 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo return pStack->Return(inst, pStk); } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } error: diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 27784c53..e83f5619 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -52,7 +52,7 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) pVar = (static_cast(pVar))->GetItem(0, false); // at compile time makes the element [0] if (pVar == nullptr) { - pile->SetError(TX_OUTARRAY, m_token.GetEnd()); + pile->SetError(CBotErrOutArray, m_token.GetEnd()); return false; } if (m_next3 != nullptr) return m_next3->ExecuteVar(pVar, pile); @@ -80,7 +80,7 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev if (p == nullptr || p->GetType() > CBotTypDouble) { - pile->SetError(TX_BADINDEX, prevToken); + pile->SetError(CBotErrBadIndex, prevToken); return pj->Return(pile); } @@ -89,7 +89,7 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev pVar = (static_cast(pVar))->GetItem(n, bExtend); if (pVar == nullptr) { - pile->SetError(TX_OUTARRAY, prevToken); + pile->SetError(CBotErrOutArray, prevToken); return pj->Return(pile); } diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp index b5497f3a..9909a57c 100644 --- a/src/CBot/CBotInstr/CBotInstArray.cpp +++ b/src/CBot/CBotInstr/CBotInstArray.cpp @@ -67,7 +67,7 @@ CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable? { - pStk->SetError(TX_REDEFVAR, vartoken); + pStk->SetError(CBotErrRedefVar, vartoken); goto error; } @@ -84,7 +84,7 @@ CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK )) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto error; } } @@ -146,7 +146,7 @@ bool CBotInstArray::Execute(CBotStack* &pj) max[n] = v->GetValInt(); // value if (max[n]>MAXARRAYSIZE) { - pile->SetError(TX_OUTARRAY, &m_token); + pile->SetError(CBotErrOutArray, &m_token); return pj->Return (pile); } n++; diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp index c08723e1..6a93260e 100644 --- a/src/CBot/CBotInstr/CBotInstr.cpp +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -190,7 +190,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) // these instructions accept only lable if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, 0)) { - pStack->SetError(TX_LABEL, pp->GetStart()); + pStack->SetError(CBotErrLabel, pp->GetStart()); return nullptr; } } @@ -241,12 +241,12 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) case ID_ELSE: pStack->SetStartError(p->GetStart()); - pStack->SetError(TX_ELSEWITHOUTIF, p->GetEnd()); + pStack->SetError(CBotErrElseWhitoutIf, p->GetEnd()); return nullptr; case ID_CASE: pStack->SetStartError(p->GetStart()); - pStack->SetError(TX_OUTCASE, p->GetEnd()); + pStack->SetError(CBotErrCaseOut, p->GetEnd()); return nullptr; } @@ -255,7 +255,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) // should not be a reserved word DefineNum if (p->GetType() == TokenTypDef) { - pStack->SetError(TX_RESERVED, p); + pStack->SetError(CBotErrReserved, p); return nullptr; } @@ -276,7 +276,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) { return inst; } - pStack->SetError(TX_ENDOF, p->GetStart()); + pStack->SetError(CBotErrNoTerminator, p->GetStart()); delete inst; return nullptr; } @@ -339,7 +339,7 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes { if (!IsOfType(p, ID_CLBRK)) { - pStack->SetError(TX_CLBRK, p->GetStart()); + pStack->SetError(CBotErrCloseIndex, p->GetStart()); return nullptr; } @@ -369,6 +369,6 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes } delete inst; - pStack->SetError(TX_ENDOF, p->GetStart()); + pStack->SetError(CBotErrNoTerminator, p->GetStart()); return nullptr; } diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index d83f2a8a..f7ef7cb1 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -86,7 +86,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) if ( pile->GetTypResult().Eq(99) ) { delete pStack->TokenStack(); - pStack->SetError(TX_VOID, p->GetStart()); + pStack->SetError(CBotErrVoid, p->GetStart()); delete inst; return nullptr; } @@ -98,7 +98,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) if (IsOfType(p, ID_CLOSEPAR)) break; } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); + pStack->SetError(CBotErrClosePar, p->GetStart()); delete pStack->TokenStack(); delete inst; return nullptr; diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 1e5c34a5..5a167c8e 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -110,7 +110,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre if (pVar->GetPointer() == nullptr) { - pj->SetError(TX_NULLPT, prevToken); + pj->SetError(CBotErrNull, prevToken); } if (pile1->IfStep()) return false; diff --git a/src/CBot/CBotInstr/CBotInstrUtils.cpp b/src/CBot/CBotInstr/CBotInstrUtils.cpp index a7fc8c9d..48408834 100644 --- a/src/CBot/CBotInstr/CBotInstrUtils.cpp +++ b/src/CBot/CBotInstr/CBotInstrUtils.cpp @@ -68,7 +68,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) if (pile->GetTypResult().Eq(99)) { delete pStack->TokenStack(); - pStack->SetError(TX_VOID, p->GetStart()); + pStack->SetError(CBotErrVoid, p->GetStart()); return nullptr; } ppVars[i] = pile->GetVar(); @@ -79,7 +79,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) if (IsOfType(p, ID_CLOSEPAR)) break; } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); + pStack->SetError(CBotErrClosePar, p->GetStart()); delete pStack->TokenStack(); return nullptr; } diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp index 93cc0f68..bafce954 100644 --- a/src/CBot/CBotInstr/CBotInt.cpp +++ b/src/CBot/CBotInstr/CBotInt.cpp @@ -75,7 +75,7 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool n (static_cast(inst->m_var))->m_typevar = CBotTypInt; if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable { - pStk->SetError(TX_REDEFVAR, vartoken); + pStk->SetError(CBotErrRedefVar, vartoken); goto error; } @@ -90,7 +90,7 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool n if (!pStk->IsOk() ) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto error; } @@ -113,7 +113,7 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool n } if (pStk->GetType() >= CBotTypBoolean) // compatible type ? { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } } @@ -139,7 +139,7 @@ suite: return pStack->Return(inst, pStk); } - pStk->SetError(TX_ENDOF, p->GetStart()); + pStk->SetError(CBotErrNoTerminator, p->GetStart()); } error: diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 28badcaa..9bc5ef92 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -70,7 +70,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) if ( var->IsPrivate(PR_READ) && !pStk->GetBotCall()->m_bCompileClass) { - pStk->SetError(TX_PRIVATE, p); + pStk->SetError(CBotErrPrivate, p); goto err; } // this is an element of the current class @@ -103,13 +103,13 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) if (i->m_expr == nullptr) { - pStk->SetError(TX_BADINDEX, p->GetStart()); + pStk->SetError(CBotErrBadIndex, p->GetStart()); goto err; } if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) { - pStk->SetError(TX_CLBRK, p->GetStart()); + pStk->SetError(CBotErrCloseIndex, p->GetStart()); goto err; } continue; @@ -134,7 +134,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) if ( var->IsPrivate(PR_READ) && !pStk->GetBotCall()->m_bCompileClass) { - pStk->SetError(TX_PRIVATE, pp); + pStk->SetError(CBotErrPrivate, pp); goto err; } @@ -142,9 +142,9 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) p = p->GetNext(); // skips the name continue; } - pStk->SetError(TX_NOITEM, p); + pStk->SetError(CBotErrUndefItem, p); } - pStk->SetError(TX_DOT, p->GetStart()); + pStk->SetError(CBotErrUndefClass, p->GetStart()); goto err; } } @@ -154,7 +154,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) if (pStk->IsOk()) return static_cast (pStack->Return(inst, pStk)); } - pStk->SetError(TX_UNDEFVAR, p); + pStk->SetError(CBotErrUndefVar, p); err: delete inst; return static_cast ( pStack->Return(nullptr, pStk)); @@ -189,7 +189,7 @@ bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) if ( !c2->IsChildOf(c1)) { CBotToken* pt = &m_token; - pile->SetError(TX_BADTYPE, pt); + pile->SetError(CBotErrBadType1, pt); return pj->Return(pile); // operation performed } } diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index 517d8b71..8115fc98 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -49,7 +49,7 @@ CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) // verifies that the token is a variable name if (p->GetType() != TokenTypVar) { - pStack->SetError( TX_NOVAR, p->GetStart()); + pStack->SetError( CBotErrNoVar, p->GetStart()); return nullptr; } diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index f19cfa5e..a3b16c10 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -100,7 +100,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } @@ -118,7 +118,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type? { - pStk->SetError(TX_BADTYPE, p->GetStart()); + pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } inst->m_expr->AddNext3(i); @@ -127,7 +127,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu if (!IsOfType(p, ID_CLOSEPAR) ) { - pStk->SetError(TX_CLOSEPAR, p->GetStart()); + pStk->SetError(CBotErrClosePar, p->GetStart()); goto error; } diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp index 65bdb40e..7958dae5 100644 --- a/src/CBot/CBotInstr/CBotListInstr.cpp +++ b/src/CBot/CBotInstr/CBotListInstr.cpp @@ -57,7 +57,7 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal if (IsOfType(p, 0)) { - pStack->SetError(TX_CLOSEBLK, p->GetStart()); + pStack->SetError(CBotErrCloseBlock, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); } diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 2351835c..2baf7a60 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -59,7 +59,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) CBotClass* pClass = CBotClass::Find(p); if (pClass == nullptr) { - pStack->SetError(TX_BADNEW, p); + pStack->SetError(CBotErrBadNew, p); return nullptr; } @@ -87,7 +87,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) int typ = r.GetType(); // if there is no constructor, and no parameters either, it's ok - if (typ == TX_UNDEFCALL && inst->m_Parameters == nullptr) typ = 0; + if (typ == CBotErrUndefCall && inst->m_Parameters == nullptr) typ = 0; pVar->SetInit(CBotVar::InitType::DEF); // mark the instance as init if (typ>20) @@ -99,7 +99,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) // if the constructor does not exist, but there are parameters if (typ<0 && inst->m_Parameters != nullptr) { - pStk->SetError(TX_NOCONST, &inst->m_vartoken); + pStk->SetError(CBotErrNoConstruct, &inst->m_vartoken); goto error; } diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp index e4e34796..25d530d7 100644 --- a/src/CBot/CBotInstr/CBotParExpr.cpp +++ b/src/CBot/CBotInstr/CBotParExpr.cpp @@ -59,7 +59,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) { return pStack->Return(inst, pStk); } - pStk->SetError(TX_CLOSEPAR, p->GetStart()); + pStk->SetError(CBotErrClosePar, p->GetStart()); } delete inst; return pStack->Return(nullptr, pStk); @@ -94,7 +94,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) { if (pStk->GetType() >= CBotTypBoolean) { - pStk->SetError(TX_BADTYPE, pp); + pStk->SetError(CBotErrBadType1, pp); delete inst; return pStack->Return(nullptr, pStk); } @@ -126,7 +126,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) { if (pStk->GetType() >= CBotTypBoolean) { - pStk->SetError(TX_BADTYPE, pp); + pStk->SetError(CBotErrBadType1, pp); delete inst; return pStack->Return(nullptr, pStk); } diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp index 99531023..b5adae5e 100644 --- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp @@ -62,12 +62,12 @@ bool CBotPostIncExpr::Execute(CBotStack* &pj) if (var1->IsNAN()) { - pile1->SetError(TX_OPNAN, &m_token); + pile1->SetError(CBotErrNan, &m_token); } if (!var1->IsDefined()) { - pile1->SetError(TX_NOTINIT, &m_token); + pile1->SetError(CBotErrNotInit, &m_token); } if (GetTokenType() == ID_INC) var1->Inc(); diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp index 6e8b7440..6f5f9091 100644 --- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp +++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp @@ -60,13 +60,13 @@ bool CBotPreIncExpr::Execute(CBotStack* &pj) if (var1->IsNAN()) { - pile->SetError(TX_OPNAN, &m_token); + pile->SetError(CBotErrNan, &m_token); return pj->Return(pile); // operation performed } if (!var1->IsDefined()) { - pile->SetError(TX_NOTINIT, &m_token); + pile->SetError(CBotErrNotInit, &m_token); return pj->Return(pile); // operation performed } diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index aeb6d520..c3915e48 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -60,7 +60,7 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack) if ( type.GetType() == 0 ) // returned void ? { if ( IsOfType( p, ID_SEP ) ) return inst; - pStack->SetError( TX_BADTYPE, pp ); + pStack->SetError( CBotErrBadType1, pp ); return nullptr; } @@ -73,9 +73,9 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack) if ( IsOfType( p, ID_SEP ) ) return inst; - pStack->SetError(TX_ENDOF, p->GetStart()); + pStack->SetError(CBotErrNoTerminator, p->GetStart()); } - pStack->SetError(TX_BADTYPE, p->GetStart()); + pStack->SetError(CBotErrBadType1, p->GetStart()); } delete inst; diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp index 0104d5da..5f8f7dac 100644 --- a/src/CBot/CBotInstr/CBotSwitch.cpp +++ b/src/CBot/CBotInstr/CBotSwitch.cpp @@ -91,7 +91,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) if ( inst->m_Block == nullptr ) { - pStk->SetError(TX_NOCASE, p->GetStart()); + pStk->SetError(CBotErrNoCase, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); } @@ -106,7 +106,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) if ( p == nullptr ) { - pStk->SetError(TX_CLOSEBLK, -1); + pStk->SetError(CBotErrCloseBlock, -1); delete inst; return pStack->Return(nullptr, pStk); } @@ -115,21 +115,21 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) if ( inst->m_Block == nullptr ) { - pStk->SetError(TX_NOCASE, p->GetStart()); + pStk->SetError(CBotErrNoCase, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); } // the statement block is ok return pStack->Return(inst, pStk); // return an object to the application } - pStk->SetError( TX_OPENBLK, p->GetStart() ); + pStk->SetError( CBotErrOpenBlock, p->GetStart() ); } - pStk->SetError( TX_CLOSEPAR, p->GetStart() ); + pStk->SetError( CBotErrClosePar, p->GetStart() ); } - pStk->SetError( TX_BADTYPE, p->GetStart() ); + pStk->SetError( CBotErrBadType1, p->GetStart() ); } } - pStk->SetError( TX_OPENPAR, p->GetStart()); + pStk->SetError( CBotErrOpenPar, p->GetStart()); delete inst; // error, frees up return pStack->Return(nullptr, pStk); // no object, the error is on the stack diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index 4525dbbb..44c43f07 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -61,7 +61,7 @@ CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack) { return inst; // return an object to the application } - pStack->SetError(TX_BADTYPE, pp); + pStack->SetError(CBotErrBadType1, pp); delete inst; // error, frees up return nullptr; // no object, the error is on the stack @@ -82,7 +82,7 @@ bool CBotThrow::Execute(CBotStack* &pj) if ( pile->IfStep() ) return false; int val = pile->GetVal(); - if ( val < 0 ) val = TX_BADTHROW; + if ( val < 0 ) val = CBotErrBadThrow; pile->SetError( val, &m_token ); return pj->Return( pile ); } diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index 26342f94..bb3375fc 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -147,7 +147,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera { if ( !type1.Eq(CBotTypBoolean) ) { - pStk->SetError( TX_BADTYPE, p); + pStk->SetError( CBotErrBadType1, p); return pStack->Return(nullptr, pStk); } CBotLogicExpr* inst = new CBotLogicExpr(); @@ -158,7 +158,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera CBotToken* pp = p; if ( inst->m_op1 == nullptr || !IsOfType( p, ID_DOTS ) ) { - pStk->SetError( TX_MISDOTS, p->GetStart()); + pStk->SetError( CBotErrNoDoubleDots, p->GetStart()); delete inst; return pStack->Return(nullptr, pStk); } @@ -167,14 +167,14 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera inst->m_op2 = CBotExpression::Compile(p, pStk); if ( inst->m_op2 == nullptr ) { - pStk->SetError( TX_ENDOF, p->GetStart() ); + pStk->SetError( CBotErrNoTerminator, p->GetStart() ); delete inst; return pStack->Return(nullptr, pStk); } type2 = pStk->GetTypResult(); if (!TypeCompatible(type1, type2)) { - pStk->SetError( TX_BAD2TYPE, pp ); + pStk->SetError( CBotErrBadType2, pp ); delete inst; return pStack->Return(nullptr, pStk); } @@ -247,7 +247,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera if ( !TypeCompatible (type1, type2, TypeOp) ) // the results are compatible { - pStk->SetError(TX_BAD2TYPE, &i->m_token); + pStk->SetError(CBotErrBadType2, &i->m_token); delete i; return pStack->Return(nullptr, pStk); } @@ -265,7 +265,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera // and returns the requested object return pStack->Return(inst, pStk); } - pStk->SetError(TX_BAD2TYPE, &inst->m_token); + pStk->SetError(CBotErrBadType2, &inst->m_token); } // in case of error, releases the elements @@ -291,7 +291,7 @@ bool IsNan(CBotVar* left, CBotVar* right, int* err = nullptr) { if ( VarIsNAN(left) || VarIsNAN(right) ) { - if ( err != nullptr ) *err = TX_OPNAN ; + if ( err != nullptr ) *err = CBotErrNan ; return true; } return false; diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 6ac9f43b..a02e8e0f 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -195,7 +195,7 @@ bool CBotProgram::Start(const std::string& name) if ( m_pRun == nullptr ) { - m_ErrorCode = TX_NORUN; + m_ErrorCode = CBotErrNoRun; return false; } @@ -277,7 +277,7 @@ bool CBotProgram::Run(void* pUser, int timer) return ok; error: - m_ErrorCode = TX_NORUN; + m_ErrorCode = CBotErrNoRun; return true; } @@ -388,7 +388,7 @@ bool CBotProgram::AddFunction(const std::string& name, //////////////////////////////////////////////////////////////////////////////// bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { - if ( pVar == nullptr ) return TX_LOWPARAM; + if ( pVar == nullptr ) return CBotErrLowParam; int i = 0; pVar = pVar->GetItemList(); @@ -406,9 +406,9 @@ bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) //////////////////////////////////////////////////////////////////////////////// CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser ) { - if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( pVar == nullptr ) return CBotTypResult( CBotErrLowParam ); if ( pVar->GetType() != CBotTypArrayPointer ) - return CBotTypResult( TX_BADPARAM ); + return CBotTypResult( CBotErrBadParam ); return CBotTypResult( CBotTypInt ); } @@ -480,18 +480,18 @@ int CBotProgram::GetVersion() //////////////////////////////////////////////////////////////////////////////// void CBotProgram::Init() { - CBotToken::DefineNum("CBotErrZeroDiv", TX_DIVZERO); // division by zero - CBotToken::DefineNum("CBotErrNotInit", TX_NOTINIT); // uninitialized variable - CBotToken::DefineNum("CBotErrBadThrow", TX_BADTHROW); // throw a negative value - CBotToken::DefineNum("CBotErrNoRetVal", TX_NORETVAL); // function did not return results - CBotToken::DefineNum("CBotErrNoRun", TX_NORUN); // active Run () without a function // TODO: Is this actually a runtime error? - CBotToken::DefineNum("CBotErrUndefFunc", TX_NOCALL); // Calling a function that no longer exists - CBotToken::DefineNum("CBotErrNotClass", TX_NOCLASS); // Class no longer exists - CBotToken::DefineNum("CBotErrNull", TX_NULLPT); // Attempted to use a null pointer - CBotToken::DefineNum("CBotErrNan", TX_OPNAN); // Can't do operations on nan - CBotToken::DefineNum("CBotErrOutArray", TX_OUTARRAY); // Attempted access out of bounds of an array - CBotToken::DefineNum("CBotErrStackOver", TX_STACKOVER); // Stack overflow - CBotToken::DefineNum("CBotErrDeletedPtr", TX_DELETEDPT); // Attempted to use deleted object + CBotToken::DefineNum("CBotErrZeroDiv", CBotErrZeroDiv); // division by zero + CBotToken::DefineNum("CBotErrNotInit", CBotErrNotInit); // uninitialized variable + CBotToken::DefineNum("CBotErrBadThrow", CBotErrBadThrow); // throw a negative value + CBotToken::DefineNum("CBotErrNoRetVal", CBotErrNoRetVal); // function did not return results + CBotToken::DefineNum("CBotErrNoRun", CBotErrNoRun); // active Run () without a function // TODO: Is this actually a runtime error? + CBotToken::DefineNum("CBotErrUndefFunc", CBotErrUndefFunc); // Calling a function that no longer exists + CBotToken::DefineNum("CBotErrNotClass", CBotErrNotClass); // Class no longer exists + CBotToken::DefineNum("CBotErrNull", CBotErrNull); // Attempted to use a null pointer + CBotToken::DefineNum("CBotErrNan", CBotErrNan); // Can't do operations on nan + CBotToken::DefineNum("CBotErrOutArray", CBotErrOutArray); // Attempted access out of bounds of an array + CBotToken::DefineNum("CBotErrStackOver", CBotErrStackOver); // Stack overflow + CBotToken::DefineNum("CBotErrDeletedPtr", CBotErrDeletedPtr); // Attempted to use deleted object CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index f77b9f7e..fb69c5e3 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -252,7 +252,7 @@ bool CBotStack::ReturnKeep(CBotStack* pfils) bool CBotStack::StackOver() { if (!m_bOver) return false; - m_error = TX_STACKOVER; + m_error = CBotErrStackOver; return true; } @@ -784,7 +784,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo res = m_prog->GetFunctions()->DoCall(nIdent, token->GetString(), ppVar, this, token ); if (res.GetType() >= 0) return res.GetType(); - SetError(TX_NOCALL, token); + SetError(CBotErrUndefFunc, token); return true; } diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp index c098e463..fe51f7f7 100644 --- a/src/CBot/CBotUtils.cpp +++ b/src/CBot/CBotUtils.cpp @@ -101,7 +101,7 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) { if ( !IsOfType( p, ID_CLBRK ) ) { - pile->SetError(TX_CLBRK, p->GetStart()); + pile->SetError(CBotErrCloseIndex, p->GetStart()); return CBotTypResult( -1 ); } type = CBotTypResult( CBotTypArrayPointer, type ); diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index e5b41320..23a1977f 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -136,7 +136,7 @@ int CBotVarFloat::Div(CBotVar* left, CBotVar* right) m_val = left->GetValFloat() / r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? TX_DIVZERO : 0 ); + return ( r == 0 ? CBotErrZeroDiv : 0 ); } //////////////////////////////////////////////////////////////////////////////// @@ -148,7 +148,7 @@ int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) m_val = static_cast(fmod( left->GetValFloat() , r )); m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? TX_DIVZERO : 0 ); + return ( r == 0 ? CBotErrZeroDiv : 0 ); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index 3e3a1827..e6ed9d47 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -139,7 +139,7 @@ int CBotVarInt::Div(CBotVar* left, CBotVar* right) m_val = left->GetValInt() / r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? TX_DIVZERO : 0 ); + return ( r == 0 ? CBotErrZeroDiv : 0 ); } //////////////////////////////////////////////////////////////////////////////// @@ -151,7 +151,7 @@ int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) m_val = left->GetValInt() % r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? TX_DIVZERO : 0 ); + return ( r == 0 ? CBotErrZeroDiv : 0 ); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/stdlib/Compilation.cpp b/src/CBot/stdlib/Compilation.cpp index a0174a68..fd820bf0 100644 --- a/src/CBot/stdlib/Compilation.cpp +++ b/src/CBot/stdlib/Compilation.cpp @@ -89,14 +89,14 @@ CBotTypResult cOneIntReturnBool(CBotVar* &var, void* user) CBotTypResult cStrStr(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // no second parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); // the end result is a string return CBotTypResult( CBotTypString ); @@ -105,22 +105,22 @@ CBotTypResult cStrStr(CBotVar*& var, void* user) CBotTypResult cIntStrStr(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // it takes a second parameter var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // no third parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); // the end result is a number return CBotTypResult( CBotTypInt ); @@ -129,14 +129,14 @@ CBotTypResult cIntStrStr(CBotVar*& var, void* user) CBotTypResult cFloatStr(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult(TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult(CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // no second parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); // the end result is a number return CBotTypResult( CBotTypFloat ); @@ -145,19 +145,19 @@ CBotTypResult cFloatStr(CBotVar*& var, void* user) CBotTypResult cStrStrIntInt(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // it takes a second parameter var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // which must be a number if ( var->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); + return CBotTypResult( CBotErrBadNum ); // third parameter optional if ( var->GetNext() != nullptr ) @@ -166,10 +166,10 @@ CBotTypResult cStrStrIntInt(CBotVar*& var, void* user) var = var->GetNext(); // which must be a number if ( var->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); + return CBotTypResult( CBotErrBadNum ); // no fourth parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); } // the end result is a string @@ -179,22 +179,22 @@ CBotTypResult cStrStrIntInt(CBotVar*& var, void* user) CBotTypResult cStrStrInt(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADSTRING ); + return CBotTypResult( CBotErrBadString ); // it takes a second parameter var = var->GetNext(); - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // which must be a number if ( var->GetType() > CBotTypDouble ) - return CBotTypResult( TX_BADNUM ); + return CBotTypResult( CBotErrBadNum ); // no third parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); // the end result is a string return CBotTypResult( CBotTypString ); @@ -203,14 +203,14 @@ CBotTypResult cStrStrInt(CBotVar*& var, void* user) CBotTypResult cIntStr(CBotVar*& var, void* user) { // it takes a parameter - if ( var == nullptr ) return CBotTypResult( TX_LOWPARAM ); + if ( var == nullptr ) return CBotTypResult( CBotErrLowParam ); // to be a string if ( var->GetType() != CBotTypString ) - return CBotTypResult( TX_BADPARAM ); + return CBotTypResult( CBotErrBadParam ); // no second parameter - if ( var->GetNext() != nullptr ) return CBotTypResult( TX_OVERPARAM ); + if ( var->GetNext() != nullptr ) return CBotTypResult( CBotErrOverParam ); // the end result is an integer return CBotTypResult( CBotTypInt ); diff --git a/src/CBot/stdlib/StringFunctions.cpp b/src/CBot/stdlib/StringFunctions.cpp index 91c63629..6bcaaf6b 100644 --- a/src/CBot/stdlib/StringFunctions.cpp +++ b/src/CBot/stdlib/StringFunctions.cpp @@ -34,13 +34,13 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // no second parameter - if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ) { ex = CBotErrOverParam ; return true; } // get the contents of the string std::string s = pVar->GetValString(); @@ -54,26 +54,26 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // which must be a number - if ( pVar->GetType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; } + if ( pVar->GetType() > CBotTypDouble ) { ex = CBotErrBadNum ; return true; } // retrieves this number int n = pVar->GetValInt(); // no third parameter - if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ) { ex = CBotErrOverParam ; return true; } // takes the interesting part s = s.substr(0, n); @@ -87,26 +87,26 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // which must be a number - if ( pVar->GetType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; } + if ( pVar->GetType() > CBotTypDouble ) { ex = CBotErrBadNum ; return true; } // retrieves this number int n = pVar->GetValInt(); // no third parameter - if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ) { ex = CBotErrOverParam ; return true; } // takes the interesting part s = s.substr(s.length()-n, std::string::npos); @@ -120,20 +120,20 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // which must be a number - if ( pVar->GetType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; } + if ( pVar->GetType() > CBotTypDouble ) { ex = CBotErrBadNum ; return true; } // retrieves this number int n = pVar->GetValInt(); @@ -144,13 +144,13 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) pVar = pVar->GetNext(); // which must be a number - if ( pVar->GetType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; } + if ( pVar->GetType() > CBotTypDouble ) { ex = CBotErrBadNum ; return true; } // retrieves this number int l = pVar->GetValInt(); // but no fourth parameter - if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ){ ex = CBotErrOverParam ; return true; } // takes the interesting part s = s.substr(n, l); @@ -170,16 +170,16 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // but no second parameter - if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ){ ex = CBotErrOverParam ; return true; } float val = GetNumFloat(s); @@ -192,26 +192,26 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // it takes a second parameter pVar = pVar->GetNext(); - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // retrieves this number std::string s2 = pVar->GetValString(); // no third parameter - if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ) { ex = CBotErrOverParam ; return true; } // puts the result on the stack std::size_t res = s.find(s2); @@ -224,16 +224,16 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // but no second parameter - if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ){ ex = CBotErrOverParam ; return true; } boost::to_upper(s); @@ -247,16 +247,16 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) { // it takes a parameter - if ( pVar == nullptr ) { ex = TX_LOWPARAM ; return true; } + if ( pVar == nullptr ) { ex = CBotErrLowParam ; return true; } // to be a string - if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; } + if ( pVar->GetType() != CBotTypString ) { ex = CBotErrBadString ; return true; } // get the contents of the string std::string s = pVar->GetValString(); // but no second parameter - if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; } + if ( pVar->GetNext() != nullptr ){ ex = CBotErrOverParam ; return true; } boost::to_lower(s); diff --git a/src/common/restext.cpp b/src/common/restext.cpp index db7a6c40..8ef7716c 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -670,64 +670,66 @@ void InitializeRestext() - stringsCbot[TX_OPENPAR] = TR("Opening bracket missing"); - stringsCbot[TX_CLOSEPAR] = TR("Closing bracket missing "); - stringsCbot[TX_NOTBOOL] = TR("The expression must return a boolean value"); - stringsCbot[TX_UNDEFVAR] = TR("Variable not declared"); - stringsCbot[TX_BADLEFT] = TR("Assignment impossible"); - stringsCbot[TX_ENDOF] = TR("Semicolon terminator missing"); - stringsCbot[TX_OUTCASE] = TR("Instruction \"case\" outside a block \"switch\""); - stringsCbot[TX_CLOSEBLK] = TR("End of block missing"); - stringsCbot[TX_ELSEWITHOUTIF] = TR("Instruction \"else\" without corresponding \"if\" "); - stringsCbot[TX_OPENBLK] = TR("Opening brace missing "); - stringsCbot[TX_BADTYPE] = TR("Wrong type for the assignment"); - stringsCbot[TX_REDEFVAR] = TR("A variable can not be declared twice"); - stringsCbot[TX_BAD2TYPE] = TR("The types of the two operands are incompatible "); - stringsCbot[TX_UNDEFCALL] = TR("Unknown function"); - stringsCbot[TX_MISDOTS] = TR("Sign \" : \" missing"); - stringsCbot[TX_WHILE] = TR("Keyword \"while\" missing"); - stringsCbot[TX_BREAK] = TR("Instruction \"break\" outside a loop"); - stringsCbot[TX_LABEL] = TR("A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\""); - stringsCbot[TX_NOLABEL] = TR("This label does not exist"); - stringsCbot[TX_NOCASE] = TR("Instruction \"case\" missing"); - stringsCbot[TX_BADNUM] = TR("Number missing"); - stringsCbot[TX_VOID] = TR("Void parameter"); - stringsCbot[TX_NOTYP] = TR("Type declaration missing"); - stringsCbot[TX_NOVAR] = TR("Variable name missing"); - stringsCbot[TX_NOFONC] = TR("Function name missing"); - stringsCbot[TX_OVERPARAM] = TR("Too many parameters"); - stringsCbot[TX_REDEF] = TR("Function already exists"); - stringsCbot[TX_LOWPARAM] = TR("Parameters missing "); - stringsCbot[TX_BADPARAM] = TR("No function with this name accepts this kind of parameter"); - stringsCbot[TX_NUMPARAM] = TR("No function with this name accepts this number of parameters"); - stringsCbot[TX_NOITEM] = TR("This is not a member of this class"); - stringsCbot[TX_DOT] = TR("This object is not a member of a class"); - stringsCbot[TX_NOCONST] = TR("Appropriate constructor missing"); - stringsCbot[TX_REDEFCLASS] = TR("This class already exists"); - stringsCbot[TX_CLBRK] = TR("\" ] \" missing"); - stringsCbot[TX_RESERVED] = TR("Reserved keyword of CBOT language"); - stringsCbot[TX_BADNEW] = TR("Bad argument for \"new\""); - stringsCbot[TX_OPBRK] = TR("\" [ \" expected"); - stringsCbot[TX_BADSTRING] = TR("String missing"); - stringsCbot[TX_BADINDEX] = TR("Incorrect index type"); - stringsCbot[TX_PRIVATE] = TR("Private element"); - stringsCbot[TX_NOPUBLIC] = TR("Public required"); - stringsCbot[TX_DIVZERO] = TR("Dividing by zero"); - stringsCbot[TX_NOTINIT] = TR("Variable not initialized"); - stringsCbot[TX_BADTHROW] = TR("Negative value rejected by \"throw\""); - stringsCbot[TX_NORETVAL] = TR("The function returned no value "); - stringsCbot[TX_NORUN] = TR("No function running"); - stringsCbot[TX_NOCALL] = TR("Calling an unknown function"); - stringsCbot[TX_NOCLASS] = TR("This class does not exist"); - stringsCbot[TX_NULLPT] = TR("Unknown Object"); - stringsCbot[TX_OPNAN] = TR("Operation impossible with value \"nan\""); - stringsCbot[TX_OUTARRAY] = TR("Access beyond array limit"); - stringsCbot[TX_STACKOVER] = TR("Stack overflow"); - stringsCbot[TX_DELETEDPT] = TR("Illegal object"); - stringsCbot[TX_FILEOPEN] = TR("Can't open file"); - stringsCbot[TX_NOTOPEN] = TR("File not open"); - stringsCbot[TX_ERRREAD] = TR("Read error"); - stringsCbot[TX_ERRWRITE] = TR("Write error"); + stringsCbot[CBotErrOpenPar] = TR("Opening bracket missing"); + stringsCbot[CBotErrClosePar] = TR("Closing bracket missing "); + stringsCbot[CBotErrNotBoolean] = TR("The expression must return a boolean value"); + stringsCbot[CBotErrUndefVar] = TR("Variable not declared"); + stringsCbot[CBotErrBadLeft] = TR("Assignment impossible"); + stringsCbot[CBotErrNoTerminator] = TR("Semicolon terminator missing"); + stringsCbot[CBotErrCaseOut] = TR("Instruction \"case\" outside a block \"switch\""); + stringsCbot[CBotErrNoEnd] = TR("Instructions after the final closing brace"); + stringsCbot[CBotErrCloseBlock] = TR("End of block missing"); + stringsCbot[CBotErrElseWhitoutIf] = TR("Instruction \"else\" without corresponding \"if\" "); + stringsCbot[CBotErrOpenBlock] = TR("Opening brace missing "); + stringsCbot[CBotErrBadType1] = TR("Wrong type for the assignment"); + stringsCbot[CBotErrRedefVar] = TR("A variable can not be declared twice"); + stringsCbot[CBotErrBadType2] = TR("The types of the two operands are incompatible "); + stringsCbot[CBotErrUndefCall] = TR("Unknown function"); + stringsCbot[CBotErrNoDoubleDots] = TR("Sign \" : \" missing"); + stringsCbot[CBotErrNoWhile] = TR("Keyword \"while\" missing"); + stringsCbot[CBotErrBreakOutside] = TR("Instruction \"break\" outside a loop"); + stringsCbot[CBotErrLabel] = TR("A label must be followed by \"for\"; \"while\"; \"do\" or \"switch\""); + stringsCbot[CBotErrUndefLabel] = TR("This label does not exist"); + stringsCbot[CBotErrNoCase] = TR("Instruction \"case\" missing"); + stringsCbot[CBotErrBadNum] = TR("Number missing"); + stringsCbot[CBotErrVoid] = TR("Void parameter"); + stringsCbot[CBotErrNoType] = TR("Type declaration missing"); + stringsCbot[CBotErrNoVar] = TR("Variable name missing"); + stringsCbot[CBotErrNoFunc] = TR("Function name missing"); + stringsCbot[CBotErrOverParam] = TR("Too many parameters"); + stringsCbot[CBotErrRedefFunc] = TR("Function already exists"); + stringsCbot[CBotErrLowParam] = TR("Parameters missing "); + stringsCbot[CBotErrBadParam] = TR("No function with this name accepts this kind of parameter"); + stringsCbot[CBotErrNbParam] = TR("No function with this name accepts this number of parameters"); + stringsCbot[CBotErrUndefItem] = TR("This is not a member of this class"); + stringsCbot[CBotErrUndefClass] = TR("This object is not a member of a class"); + stringsCbot[CBotErrNoConstruct] = TR("Appropriate constructor missing"); + stringsCbot[CBotErrRedefClass] = TR("This class already exists"); + stringsCbot[CBotErrCloseIndex] = TR("\" ] \" missing"); + stringsCbot[CBotErrReserved] = TR("Reserved keyword of CBOT language"); + stringsCbot[CBotErrBadNew] = TR("Bad argument for \"new\""); + stringsCbot[CBotErrOpenIndex] = TR("\" [ \" expected"); + stringsCbot[CBotErrBadString] = TR("String missing"); + stringsCbot[CBotErrBadIndex] = TR("Incorrect index type"); + stringsCbot[CBotErrPrivate] = TR("Private element"); + stringsCbot[CBotErrNoPublic] = TR("Public required"); + + stringsCbot[CBotErrZeroDiv] = TR("Dividing by zero"); + stringsCbot[CBotErrNotInit] = TR("Variable not initialized"); + stringsCbot[CBotErrBadThrow] = TR("Negative value rejected by \"throw\""); + stringsCbot[CBotErrNoRetVal] = TR("The function returned no value "); + stringsCbot[CBotErrNoRun] = TR("No function running"); + stringsCbot[CBotErrUndefFunc] = TR("Calling an unknown function"); + stringsCbot[CBotErrNotClass] = TR("This class does not exist"); + stringsCbot[CBotErrNull] = TR("Unknown Object"); + stringsCbot[CBotErrNan] = TR("Operation impossible with value \"nan\""); + stringsCbot[CBotErrOutArray] = TR("Access beyond array limit"); + stringsCbot[CBotErrStackOver] = TR("Stack overflow"); + stringsCbot[CBotErrDeletedPtr] = TR("Illegal object"); + stringsCbot[CBotErrFileOpen] = TR("Can't open file"); + stringsCbot[CBotErrNotOpen] = TR("File not open"); + stringsCbot[CBotErrRead] = TR("Read error"); + stringsCbot[CBotErrWrite] = TR("Write error"); } From 73f8bd5490adeb215320c943cb1036aad665f491 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 20 Dec 2015 19:16:01 +0100 Subject: [PATCH 160/360] Made CBot errors an enum --- src/CBot/CBotCStack.cpp | 16 ++--- src/CBot/CBotCStack.h | 12 ++-- src/CBot/CBotCall.cpp | 2 +- src/CBot/CBotCallMethode.cpp | 2 +- src/CBot/CBotDefines.h | 77 ----------------------- src/CBot/CBotEnums.h | 81 +++++++++++++++++++++++++ src/CBot/CBotInstr/CBotClassInst.cpp | 2 +- src/CBot/CBotInstr/CBotExprVar.cpp | 2 +- src/CBot/CBotInstr/CBotExpression.cpp | 5 +- src/CBot/CBotInstr/CBotInstrCall.cpp | 2 +- src/CBot/CBotInstr/CBotInstrMethode.cpp | 4 +- src/CBot/CBotInstr/CBotNew.cpp | 2 +- 12 files changed, 106 insertions(+), 101 deletions(-) diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index 6d8b027c..47a701bf 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -36,7 +36,7 @@ //////////////////////////////////////////////////////////////////////////////// CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable -int CBotCStack::m_error = 0; +CBotError CBotCStack::m_error = CBotNoErr; int CBotCStack::m_end = 0; CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); @@ -48,7 +48,7 @@ CBotCStack::CBotCStack(CBotCStack* ppapa) if (ppapa == nullptr) { - m_error = 0; + m_error = CBotNoErr; m_start = 0; m_end = 0; m_bBlock = true; @@ -124,7 +124,7 @@ CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) } //////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError(int& start, int& end) +CBotError CBotCStack::GetError(int& start, int& end) { start = m_start; end = m_end; @@ -132,7 +132,7 @@ int CBotCStack::GetError(int& start, int& end) } //////////////////////////////////////////////////////////////////////////////// -int CBotCStack::GetError() +CBotError CBotCStack::GetError() { return m_error; } @@ -225,7 +225,7 @@ void CBotCStack::SetStartError( int pos ) } //////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, int pos) +void CBotCStack::SetError(CBotError n, int pos) { if ( n!= 0 && m_error != 0) return; // does not change existing error m_error = n; @@ -233,7 +233,7 @@ void CBotCStack::SetError(int n, int pos) } //////////////////////////////////////////////////////////////////////////////// -void CBotCStack::SetError(int n, CBotToken* p) +void CBotCStack::SetError(CBotError n, CBotToken* p) { if (m_error) return; // does not change existing error m_error = n; @@ -242,7 +242,7 @@ void CBotCStack::SetError(int n, CBotToken* p) } //////////////////////////////////////////////////////////////////////////////// -void CBotCStack::ResetError(int n, int start, int end) +void CBotCStack::ResetError(CBotError n, int start, int end) { m_error = n; m_start = start; @@ -362,7 +362,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId if ( val.GetType() < 0 ) { // pVar = nullptr; // the error is not on a particular parameter - SetError( -val.GetType(), p ); + SetError( static_cast(-val.GetType()), p ); val.SetType(-val.GetType()); return val; } diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h index 1bdfa90e..ff183788 100644 --- a/src/CBot/CBotCStack.h +++ b/src/CBot/CBotCStack.h @@ -57,7 +57,7 @@ public: * \brief GetError * \return */ - int GetError(); + CBotError GetError(); /*! * \brief GetError Gives error number @@ -65,7 +65,7 @@ public: * \param end * \return */ - int GetError(int& start, int& end); + CBotError GetError(int& start, int& end); /*! * \brief SetType Set the type of instruction on the stack. @@ -183,14 +183,14 @@ public: * \param n * \param pos */ - void SetError(int n, int pos); + void SetError(CBotError n, int pos); /*! * \brief SetError * \param n * \param p */ - void SetError(int n, CBotToken* p); + void SetError(CBotError n, CBotToken* p); /*! * \brief ResetError @@ -198,7 +198,7 @@ public: * \param start * \param end */ - void ResetError(int n, int start, int end); + void ResetError(CBotError n, int start, int end); /*! * \brief SetRetType @@ -252,7 +252,7 @@ private: CBotCStack* m_next; CBotCStack* m_prev; - static int m_error; + static CBotError m_error; static int m_end; int m_start; diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 8f4cfe51..17871abf 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -118,7 +118,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack* if ( ret > 20 ) { - if (pVar2) pStack->SetError(ret, p /*pVar2->GetToken()*/ ); + if (pVar2) pStack->SetError(static_cast(ret), p /*pVar2->GetToken()*/ ); } delete pVar; nIdent = pt->m_nFuncIdent; diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index b3512f6e..0bc8184d 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -70,7 +70,7 @@ CBotTypResult CBotCallMethode::CompileCall(const std::string& name, int ret = r.GetType(); if ( ret > 20 ) { - if (pVar2) pStack->SetError(ret, pVar2->GetToken()); + if (pVar2) pStack->SetError(static_cast(ret), pVar2->GetToken()); } delete pVar; nIdent = pt->m_nFuncIdent; diff --git a/src/CBot/CBotDefines.h b/src/CBot/CBotDefines.h index 09b11e5c..f2ede5ab 100644 --- a/src/CBot/CBotDefines.h +++ b/src/CBot/CBotDefines.h @@ -47,80 +47,3 @@ #define OBJECTDELETED (reinterpret_cast(-1)) // value set before initialization #define OBJECTCREATED (reinterpret_cast(-2)) - - -//////////////////////////////////////////////////////////////////////// -// Error Handling of compilation and execution -//////////////////////////////////////////////////////////////////////// - -// TODO: Why are all of those duplicated? This needs to be unified across the source code ~krzys_h - -// Compile errors -#define CBotErrOpenPar 5000 // missing the opening parenthesis -#define CBotErrClosePar 5001 // missing the closing parenthesis -#define CBotErrNotBoolean 5002 // expression must be a boolean -#define CBotErrUndefVar 5003 // undeclared variable -#define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... ) -#define CBotErrNoTerminator 5005 // semicolon expected -#define CBotErrCaseOut 5006 // case outside a switch -#define CBotErrNoEnd 5007 // instructions after final closing brace -#define CBotErrCloseBlock 5008 // missing " } " -#define CBotErrElseWhitoutIf 5009 // else without matching if -#define CBotErrOpenBlock 5010 // missing " { " -#define CBotErrBadType1 5011 // wrong type for the assignment -#define CBotErrRedefVar 5012 // redefinition of the variable -#define CBotErrBadType2 5013 // Two operands are incompatible -#define CBotErrUndefCall 5014 // routine undefined -#define CBotErrNoDoubleDots 5015 // " : " expected -#define CBotErrNoWhile 5016 // "while" expected (in do..while) -#define CBotErrBreakOutside 5017 // break outside of a loop -#define CBotErrUndefLabel 5019 // label udnefined -#define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here) -#define CBotErrNoCase 5020 // missing " case " -#define CBotErrBadNum 5021 // expected number -#define CBotErrVoid 5022 // " void " not possible here -#define CBotErrNoType 5023 // type declaration expected -#define CBotErrNoVar 5024 // variable name expected -#define CBotErrNoFunc 5025 // expected function name -#define CBotErrOverParam 5026 // too many parameters -#define CBotErrRedefFunc 5027 // this function already exists -#define CBotErrLowParam 5028 // not enough parameters -#define CBotErrBadParam 5029 // wrong types of parameters -#define CBotErrNbParam 5030 // wrong number of parameters -#define CBotErrUndefItem 5031 // element does not exist in the class -#define CBotErrUndefClass 5032 // variable is not a class -#define CBotErrNoConstruct 5033 // no appropriate constructor -#define CBotErrRedefClass 5034 // class already exists -#define CBotErrCloseIndex 5035 // " ] " expected -#define CBotErrReserved 5036 // reserved word (for a DefineNum) -#define CBotErrBadNew 5037 // wrong setting for new -#define CBotErrOpenIndex 5038 // " [ " expected -#define CBotErrBadString 5039 // expected string -#define CBotErrBadIndex 5040 // wrong index type "[ false ]" -#define CBotErrPrivate 5041 // protected item -#define CBotErrNoPublic 5042 // missing word "public" - -// Runtime errors -#define CBotErrZeroDiv 6000 // division by zero -#define CBotErrNotInit 6001 // uninitialized variable -#define CBotErrBadThrow 6002 // throw a negative value -#define CBotErrNoRetVal 6003 // function did not return results -#define CBotErrNoRun 6004 // Run() without active function -#define CBotErrUndefFunc 6005 // calling a function that no longer exists -#define CBotErrNotClass 6006 // this class does not exist -#define CBotErrNull 6007 // null pointer -#define CBotErrNan 6008 // calculation with a NAN -#define CBotErrOutArray 6009 // index out of array -#define CBotErrStackOver 6010 // stack overflow -#define CBotErrDeletedPtr 6011 // pointer to an object destroyed -#define CBotErrFileOpen 6012 // cannot open the file -#define CBotErrNotOpen 6013 // channel not open -#define CBotErrRead 6014 // error while reading -#define CBotErrWrite 6015 // writing error - -// Max errors -#define TX_MAX 6016 - -// other values ​​may be returned -// for example exceptions returned by external routines -// and " throw " with any number. diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h index 0db5aff0..66965169 100644 --- a/src/CBot/CBotEnums.h +++ b/src/CBot/CBotEnums.h @@ -153,3 +153,84 @@ enum EID TX_UNDEF = 4000, TX_NAN }; + +//////////////////////////////////////////////////////////////////////// +// Error Handling of compilation and execution +//////////////////////////////////////////////////////////////////////// + +// NOTE: These CANNOT overlap with CBotType + +enum CBotError +{ + CBotNoErr = 0, + + // Compile errors + CBotErrOpenPar = 5000, //!< missing the opening parenthesis + CBotErrClosePar = 5001, //!< missing the closing parenthesis + CBotErrNotBoolean = 5002, //!< expression must be a boolean + CBotErrUndefVar = 5003, //!< undeclared variable + CBotErrBadLeft = 5004, //!< assignment impossible ( 5 = ... ) + CBotErrNoTerminator = 5005, //!< semicolon expected + CBotErrCaseOut = 5006, //!< case outside a switch + CBotErrNoEnd = 5007, //!< instructions after final closing brace + CBotErrCloseBlock = 5008, //!< missing " } " + CBotErrElseWhitoutIf = 5009, //!< else without matching if + CBotErrOpenBlock = 5010, //!< missing " { " + CBotErrBadType1 = 5011, //!< wrong type for the assignment + CBotErrRedefVar = 5012, //!< redefinition of the variable + CBotErrBadType2 = 5013, //!< Two operands are incompatible + CBotErrUndefCall = 5014, //!< routine undefined + CBotErrNoDoubleDots = 5015, //!< " : " expected + CBotErrNoWhile = 5016, //!< "while" expected (in do..while) + CBotErrBreakOutside = 5017, //!< break outside of a loop + CBotErrUndefLabel = 5019, //!< label udnefined + CBotErrLabel = 5018, //!< label ne peut se mettre ici (label can not get here) + CBotErrNoCase = 5020, //!< missing " case " + CBotErrBadNum = 5021, //!< expected number + CBotErrVoid = 5022, //!< " void " not possible here + CBotErrNoType = 5023, //!< type declaration expected + CBotErrNoVar = 5024, //!< variable name expected + CBotErrNoFunc = 5025, //!< expected function name + CBotErrOverParam = 5026, //!< too many parameters + CBotErrRedefFunc = 5027, //!< this function already exists + CBotErrLowParam = 5028, //!< not enough parameters + CBotErrBadParam = 5029, //!< wrong types of parameters + CBotErrNbParam = 5030, //!< wrong number of parameters + CBotErrUndefItem = 5031, //!< element does not exist in the class + CBotErrUndefClass = 5032, //!< variable is not a class + CBotErrNoConstruct = 5033, //!< no appropriate constructor + CBotErrRedefClass = 5034, //!< class already exists + CBotErrCloseIndex = 5035, //!< " ] " expected + CBotErrReserved = 5036, //!< reserved word (for a DefineNum) + CBotErrBadNew = 5037, //!< wrong setting for new + CBotErrOpenIndex = 5038, //!< " [ " expected + CBotErrBadString = 5039, //!< expected string + CBotErrBadIndex = 5040, //!< wrong index type "[ false ]" + CBotErrPrivate = 5041, //!< protected item + CBotErrNoPublic = 5042, //!< missing word "public" + + // Runtime errors + CBotErrZeroDiv = 6000, //!< division by zero + CBotErrNotInit = 6001, //!< uninitialized variable + CBotErrBadThrow = 6002, //!< throw a negative value + CBotErrNoRetVal = 6003, //!< function did not return results + CBotErrNoRun = 6004, //!< Run() without active function + CBotErrUndefFunc = 6005, //!< calling a function that no longer exists + CBotErrNotClass = 6006, //!< this class does not exist + CBotErrNull = 6007, //!< null pointer + CBotErrNan = 6008, //!< calculation with a NAN + CBotErrOutArray = 6009, //!< index out of array + CBotErrStackOver = 6010, //!< stack overflow + CBotErrDeletedPtr = 6011, //!< pointer to an object destroyed + CBotErrFileOpen = 6012, //!< cannot open the file + CBotErrNotOpen = 6013, //!< channel not open + CBotErrRead = 6014, //!< error while reading + CBotErrWrite = 6015, //!< writing error + + // Max errors + TX_MAX, + + // other values ​​may be returned + // for example exceptions returned by external routines + // and " throw " with any number. +}; diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index 25700536..04650e3f 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -155,7 +155,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* if (typ>20) { - pStk->SetError(typ, vartoken->GetEnd()); + pStk->SetError(static_cast(typ), vartoken->GetEnd()); goto error; } diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index d956d437..7f2d14ac 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -213,7 +213,7 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) p = pp; // previous instruction return pStack->Return(inst, pStk); } - pStk->SetError(0,0); // the error is not adressed here + pStk->SetError(CBotNoErr, 0); // the error is not adressed here } } delete inst; diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index b277fb46..afc86076 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -142,10 +142,11 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) } delete inst; - int start, end, error = pStack->GetError(start, end); + int start, end; + CBotError error = pStack->GetError(start, end); p = pp; // returns to the top - pStack->SetError(0,0); // forget the error + pStack->SetError(CBotNoErr,0); // forget the error CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment if (i != nullptr && error == CBotErrPrivate && p->GetType() == ID_ASS) diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index f7ef7cb1..3ba666d2 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -111,7 +111,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) if ( inst->m_typRes.GetType() >= 20 ) { // if (pVar2!=nullptr) pp = pVar2->RetToken(); - pStack->SetError( inst->m_typRes.GetType(), pp ); + pStack->SetError( static_cast(inst->m_typRes.GetType()), pp ); delete pStack->TokenStack(); delete inst; return nullptr; diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 5a167c8e..f5800c1f 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -77,7 +77,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* if (inst->m_typRes.GetType() > 20) { - pStack->SetError(inst->m_typRes.GetType(), pp); + pStack->SetError(static_cast(inst->m_typRes.GetType()), pp); delete inst; return nullptr; } @@ -97,7 +97,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* return nullptr; } } - pStack->SetError(1234, p); + pStack->SetError(static_cast(1234), p); // TODO: seriously? ~krzys_h delete inst; return nullptr; } diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 2baf7a60..27237ed7 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -92,7 +92,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) if (typ>20) { - pStk->SetError(typ, inst->m_vartoken.GetEnd()); + pStk->SetError(static_cast(typ), inst->m_vartoken.GetEnd()); goto error; } From 76c04e10d5a624b03764824fdc7575131b15235d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 21 Dec 2015 16:46:40 +0100 Subject: [PATCH 161/360] Removed some unused CBot code --- src/CBot/CBotCStack.cpp | 4 ---- src/CBot/CBotClass.cpp | 1 - src/CBot/CBotInstr/CBotExprVar.cpp | 3 --- src/CBot/CBotInstr/CBotFunction.cpp | 7 ------- src/CBot/CBotInstr/CBotInstr.cpp | 2 -- src/CBot/CBotInstr/CBotLeftExpr.cpp | 3 --- src/CBot/CBotProgram.cpp | 8 -------- src/CBot/CBotStack.cpp | 25 ------------------------- src/CBot/CBotStack.h | 3 --- src/CBot/CBotTypResult.cpp | 11 ----------- src/CBot/CBotVar/CBotVar.cpp | 18 ------------------ src/CBot/CBotVar/CBotVar.h | 5 ----- 12 files changed, 90 deletions(-) diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index 47a701bf..90580036 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -322,10 +322,6 @@ void CBotCStack::AddVar(CBotVar* pVar) while ( *pp != nullptr ) pp = &(*pp)->m_next; *pp = pVar; // added after - -#ifdef _DEBUG - if ( pVar->GetUniqNum() == 0 ) assert(0); -#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 48e74395..34a3b333 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -213,7 +213,6 @@ bool CBotClass::AddItem(std::string name, CBotTypResult type, int mPrivate) { - CBotToken token(name, std::string()); CBotClass* pClass = type.GetClass(); CBotVar* pVar = CBotVar::Create( name, type ); diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 7f2d14ac..98f47cf5 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -286,9 +286,6 @@ bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToke pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary if (pVar == nullptr) { -#ifdef _DEBUG - assert(0); -#endif pj->SetError(1, &m_token); return false; } diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index f024d7d2..9a4129aa 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -338,10 +338,6 @@ bad: return pStack->ReturnFunc(nullptr, pStk); } -#ifdef _DEBUG -static int xx = 0; -#endif - //////////////////////////////////////////////////////////////////////////////// bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { @@ -652,9 +648,6 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars { if ( !pStk3->IsOk() && pt->m_pProg != m_pProg ) { -#ifdef _DEBUG - if ( m_pProg->GetFunctions()->GetName() == "LaCommande" ) return false; -#endif pStk3->SetPosError(pToken); // indicates the error on the procedure call } return false; // interrupt ! diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp index 6a93260e..93029496 100644 --- a/src/CBot/CBotInstr/CBotInstr.cpp +++ b/src/CBot/CBotInstr/CBotInstr.cpp @@ -284,7 +284,6 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) //////////////////////////////////////////////////////////////////////////////// bool CBotInstr::Execute(CBotStack* &pj) { - std::string ClassManquante = name; assert(0); // should never go through this routine // but use the routines of the subclasses return false; @@ -301,7 +300,6 @@ bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) //////////////////////////////////////////////////////////////////////////////// void CBotInstr::RestoreState(CBotStack* &pj, bool bMain) { - std::string ClassManquante = name; assert(0); // should never go through this routine // but use the routines of the subclasses } diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 9bc5ef92..4ac6a4e4 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -222,9 +222,6 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT pVar = pile->FindVar(m_nIdent); if (pVar == nullptr) { -#ifdef _DEBUG - assert(0); -#endif pile->SetError(2, &m_token); return false; } diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index a02e8e0f..f65d8e29 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -245,16 +245,8 @@ bool CBotProgram::Run(void* pUser, int timer) ok = m_pStack->Execute(); if ( ok ) { -#ifdef _DEBUG - CBotVar* ppVar[3]; - ppVar[0] = CBotVar::Create("aa", CBotTypInt); - ppVar[1] = CBotVar::Create("bb", CBotTypInt); - ppVar[2] = nullptr; - ok = m_pRun->Execute(ppVar, m_pStack, m_pInstance); -#else // returns to normal execution ok = m_pRun->Execute(nullptr, m_pStack, m_pInstance); -#endif } #else ok = m_pRun->Execute(nullptr, m_pStack, m_pInstance); diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index fb69c5e3..545c49f9 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -75,15 +75,6 @@ CBotStack* CBotStack::FirstStack() pp->m_bOver = true; pp ++; } -#ifdef _DEBUG - int n = 1; - pp = p; - for ( i = 0 ; i< MAXSTACK+10 ; i++ ) - { - pp->m_index = n++; - pp ++; - } -#endif m_error = 0; // avoids deadlocks because m_error is static return p; @@ -124,16 +115,10 @@ void CBotStack::Delete() CBotStack* p = m_prev; bool bOver = m_bOver; -#ifdef _DEBUG - int n = m_index; -#endif // clears the freed block memset(this, 0, sizeof(CBotStack)); m_bOver = bOver; -#ifdef _DEBUG - m_index = n; -#endif if ( p == nullptr ) free( this ); @@ -148,16 +133,10 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, UnknownEnumBlock bBlock) return m_next; // included in an existing stack } -#ifdef _DEBUG - int n = 0; -#endif CBotStack* p = this; do { p ++; -#ifdef _DEBUG - n ++; -#endif } while ( p->m_prev != nullptr ); @@ -734,10 +713,6 @@ void CBotStack::AddVar(CBotVar* pVar) while ( *pp != nullptr ) pp = &(*pp)->m_next; *pp = pVar; // added after - -#ifdef _DEBUG - if ( pVar->GetUniqNum() == 0 ) assert(0); -#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index b5afe4d5..5e40fc3e 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -230,9 +230,6 @@ private: CBotStack* m_prev; friend class CBotInstArray; -#ifdef _DEBUG - int m_index; -#endif int m_state; int m_step; static int m_error; diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp index c4f9ee2f..554b66b8 100644 --- a/src/CBot/CBotTypResult.cpp +++ b/src/CBot/CBotTypResult.cpp @@ -113,17 +113,6 @@ CBotTypResult::~CBotTypResult() //////////////////////////////////////////////////////////////////////////////// int CBotTypResult::GetType(int mode) const { -#ifdef _DEBUG - if ( m_type == CBotTypPointer || - m_type == CBotTypClass || - m_type == CBotTypIntrinsic ) - - if ( m_pClass == nullptr ) assert(0); - - - if ( m_type == CBotTypArrayPointer ) - if ( m_pNext == nullptr ) assert(0); -#endif if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer; return m_type; } diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index fc41945a..80d04db8 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -68,24 +68,6 @@ CBotVar::~CBotVar( ) delete m_next; } -//////////////////////////////////////////////////////////////////////////////// -void CBotVar::debug() -{ -// const char* p = static_cast( m_token->GetString()); - std::string s = GetValString(); -// const char* v = static_cast (s); - - if ( m_type.Eq(CBotTypClass) ) - { - CBotVar* pv = (static_cast(this))->m_pVar; - while (pv != nullptr) - { - pv->debug(); - pv = pv->GetNext(); - } - } -} - //////////////////////////////////////////////////////////////////////////////// void CBotVar::ConstructorSet() { diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 6f95db48..d3202f46 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -547,11 +547,6 @@ public: */ static bool RestoreState(FILE* pf, CBotVar* &pVar); - /*! - * \brief debug - */ - void debug(); - /*! * \brief Maj * \param pUser From 6fee1ee12b21a24419fd66614ee5f15afa84299f Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 21 Dec 2015 17:54:55 +0100 Subject: [PATCH 162/360] Docs for CBotTypResult.h and CBotEnums.h --- src/CBot/CBotEnums.h | 80 ++++++++++++----------- src/CBot/CBotTypResult.h | 137 +++++++++++++++++++++++++-------------- src/ui/controls/edit.h | 2 +- 3 files changed, 132 insertions(+), 87 deletions(-) diff --git a/src/CBot/CBotEnums.h b/src/CBot/CBotEnums.h index 66965169..ee218f7f 100644 --- a/src/CBot/CBotEnums.h +++ b/src/CBot/CBotEnums.h @@ -19,39 +19,43 @@ #pragma once -// Modules inlcude +/** + * \file CBotEnums.h + * \brief Some enum values used across the CBot engine + */ -// Local include - -// Global include - -/*! \brief CBotType Defines known types. This types are modeled on Java types. - * Do not change the order of elements +/** + * \enum CBotType + * \brief Defines known types. This types are modeled on Java types. + * + * Do not change the order of elements. */ enum CBotType { - CBotTypVoid = 0, - CBotTypByte = 1, //n - CBotTypShort = 2, //n - CBotTypChar = 3, //n - CBotTypInt = 4, - CBotTypLong = 5, //n - CBotTypFloat = 6, - CBotTypDouble = 7, //n - CBotTypBoolean = 8, - CBotTypString = 9, + CBotTypVoid = 0, //!< void + CBotTypByte = 1, //!< byte (NOT IMPLEMENTED) + CBotTypShort = 2, //!< short (NOT IMPLEMENTED) + CBotTypChar = 3, //!< char (NOT IMPLEMENTED) + CBotTypInt = 4, //!< int + CBotTypLong = 5, //!< long (NOT IMPLEMENTED) + CBotTypFloat = 6, //!< float + CBotTypDouble = 7, //!< double (NOT IMPLEMENTED) + CBotTypBoolean = 8, //!< bool + CBotTypString = 9, //!< string - CBotTypArrayPointer = 10, // array of variables - CBotTypArrayBody = 11, // same but creates an instance + CBotTypArrayPointer = 10, //!< Pointer to an array (::CBotTypArrayBody) + CBotTypArrayBody = 11, //!< Array - CBotTypPointer = 12, // pointer to an instance - CBotTypNullPointer = 13, // null pointer is special - CBotTypClass = 15, - CBotTypIntrinsic = 16 // instance of a class intrinsic + CBotTypPointer = 12, //!< Pointer to a class (::CBotTypClass or ::CBotTypIntrinsic) + CBotTypNullPointer = 13, //!< Null pointer + CBotTypClass = 15, //!< Class instance + CBotTypIntrinsic = 16 //!< Intrinsic class instance }; -//n = not implemented yet -//! \brief CBotGet Different modes for GetPosition. +/** + * \enum CBotGet + * \brief Different modes for CBotProgram::GetPosition + */ enum CBotGet { GetPosExtern = 1, @@ -60,7 +64,10 @@ enum CBotGet GetPosBloc = 4 }; - +/** + * \enum EID + * \brief This enum contains possible token types + */ enum EID { ID_IF = 2000, @@ -154,12 +161,14 @@ enum EID TX_NAN }; -//////////////////////////////////////////////////////////////////////// -// Error Handling of compilation and execution -//////////////////////////////////////////////////////////////////////// - -// NOTE: These CANNOT overlap with CBotType - +/** + * \enum CBotError + * \brief This enum contains possible CBot error values. Values in range 5000-5999 are compile errors, 6000-6999 are runtime errors + * + * Note that other values ​​may be returned, for example exceptions for user-defined builtin functions, or "throw" instruction + * + * Also note that these can't overlap with CBotType, see CBotTypResult for explanation + */ enum CBotError { CBotNoErr = 0, @@ -227,10 +236,5 @@ enum CBotError CBotErrRead = 6014, //!< error while reading CBotErrWrite = 6015, //!< writing error - // Max errors - TX_MAX, - - // other values ​​may be returned - // for example exceptions returned by external routines - // and " throw " with any number. + TX_MAX, //!< Max errors }; diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h index f992f01e..3cfa6fc0 100644 --- a/src/CBot/CBotTypResult.h +++ b/src/CBot/CBotTypResult.h @@ -19,95 +19,136 @@ #pragma once -// Modules inlcude - -// Local include - -// Global include #include class CBotClass; -/* -// to define a result as output, using for example - - // to return a simple Float - return CBotTypResult( CBotTypFloat ); - - - // to return a string array - return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) ); - - // to return un array of array of "point" class - CBotTypResult typPoint( CBotTypIntrinsic, "point" ); - CBotTypResult arrPoint( CBotTypArray, typPoint ); - return CBotTypResult( CBotTypArray, arrPoint ); -*/ - -/** \brief CBotTypResult class to define the complete type of a result*/ +/** + * \class CBotTypResult + * \brief Class to define the complete type of a variable + * + * Examples: + * \code + * // Return a simple "float" variable + * return CBotTypResult( CBotTypFloat ); + * + * // Return an array of "string" variables + * return CBotTypResult( CBotTypArrayPointer, CBotTypResult( CBotTypString ) ); + * + * // Return an array of "point" class + * return CBotTypResult( CBotTypArrayPointer, CBotTypResult( CBotTypArrayPointer, CBotTypResult( CBotTypIntrinsic, "point" ) ) ); + * \endcode + */ class CBotTypResult { public: /** - * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString) - * \param type type of created result, see CBotType + * \brief Constructor for simple types (::CBotTypInt to ::CBotTypString) + * \param type type of created result, see ::CBotType. This can also sometimes be a value from ::CBotError. */ CBotTypResult(int type); - // for simple types (CBotTypInt à CBotTypString) - + /** + * \brief Constructor for pointer types and intrinsic classes + * \param type type of created result, see ::CBotType + * \param name name of the class + */ CBotTypResult(int type, const std::string& name); - // for pointer types and intrinsic classes + /** + * \brief Constructor for instance of a class + * \param type type of created result, see ::CBotType + * \param pClass class type + */ CBotTypResult(int type, CBotClass* pClass); - // for the instance of a class + /** + * \brief Constructor for arrays + * \param type type of created result, see ::CBotType + * \param elem type of array elements + */ CBotTypResult(int type, CBotTypResult elem); - // for arrays of variables + /** + * \brief Copy constructor + */ CBotTypResult(const CBotTypResult& typ); - // for assignments + /** + * \brief Default constructor + */ CBotTypResult(); - // for default + /** + * \brief Destructor + */ ~CBotTypResult(); + /** + * \brief Returns ::CBotType or ::CBotError stored in this object + * \param mode TODO: document this + */ int GetType(int mode = 0) const; - // returns type CBotType* as a result + /** + * \brief Changes ::CBotType or ::CBotError stored in this object + * \param n new value + */ void SetType(int n); - // modifies a type + /** + * \brief Returns CBotClass pointer (for ::CBotTypClass, ::CBotTypPointer) + */ CBotClass* GetClass() const; - // makes the pointer to the class (for CBotTypClass, CBotTypPointer) + /** + * \brief Get size limit of an array (for ::CBotTypArrayBody or ::CBotTypArrayPointer) + */ int GetLimite() const; - // returns limit size of table (CBotTypArray) + /** + * \brief Set size limit of an array (for ::CBotTypArrayBody or ::CBotTypArrayPointer) + * \param n new value + */ void SetLimite(int n); - // set limit to the table - void SetArray(int* max ); - // set limits for a list of dimensions (arrays of arrays) + /** + * \brief Set size limit of an multidimensional array + * \param max TODO: document this + */ + void SetArray(int* max); + /** + * \brief Get type of array elements (for ::CBotTypArrayBody or ::CBotTypArrayPointer) + * \param n new value + */ CBotTypResult& GetTypElem() const; - // returns type of array elements (CBotTypArray) - // rend le type des éléments du tableau (CBotTypArray) + + /** + * \brief Compares whether the types are compatible + * + * This compares the whole object with another + */ bool Compare(const CBotTypResult& typ) const; - // compares whether the types are compatible - bool Eq(int type) const; - // compare type + /** + * \brief Compare type only + * + * This compares the general "type" part of this object, without checking the additional parameters + */ + bool Eq(int type) const; + + /** + * Copy + */ CBotTypResult& operator=(const CBotTypResult& src); - // copy a complete type in another private: - int m_type; - CBotTypResult* m_pNext; // for the types of type - CBotClass* m_pClass; // for the derivatives of class - int m_limite; // limits of tables + int m_type; //!< type, see ::CBotType and ::CBotError + CBotTypResult* m_pNext; //!< type of array element + CBotClass* m_pClass; //!< class type + int m_limite; //!< array limit friend class CBotVarClass; friend class CBotVarPointer; }; diff --git a/src/ui/controls/edit.h b/src/ui/controls/edit.h index 0a453a6c..87112951 100644 --- a/src/ui/controls/edit.h +++ b/src/ui/controls/edit.h @@ -19,7 +19,7 @@ /** - * \file ui/edit.h + * \file ui/controls/edit.h * \brief CEdit class */ From eedf8dacea348bd6273736b5bf8d84c0b87182bc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 21 Dec 2015 21:35:20 +0100 Subject: [PATCH 163/360] Documentation for CBotProgram; some CBotError refactoring --- src/CBot/CBotCall.cpp | 6 +- src/CBot/CBotCallMethode.cpp | 8 +- src/CBot/CBotInstr/CBotExprVar.cpp | 2 +- src/CBot/CBotInstr/CBotFunction.cpp | 2 +- src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 +- src/CBot/CBotInstr/CBotThrow.cpp | 2 +- src/CBot/CBotInstr/CBotTry.cpp | 6 +- src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 4 +- src/CBot/CBotProgram.cpp | 70 ++--- src/CBot/CBotProgram.h | 397 +++++++++++++++------------ src/CBot/CBotStack.cpp | 20 +- src/CBot/CBotStack.h | 9 +- src/CBot/CBotTypResult.h | 6 + src/CBot/CBotVar/CBotVar.cpp | 8 +- src/CBot/CBotVar/CBotVar.h | 5 +- src/CBot/CBotVar/CBotVarClass.cpp | 3 +- src/CBot/CBotVar/CBotVarFloat.cpp | 8 +- src/CBot/CBotVar/CBotVarFloat.h | 5 +- src/CBot/CBotVar/CBotVarInt.cpp | 8 +- src/CBot/CBotVar/CBotVarInt.h | 5 +- src/CBot/README.txt | 4 + src/script/script.cpp | 10 +- src/script/script.h | 2 +- test/cbot/console/main.cpp | 6 +- 24 files changed, 323 insertions(+), 275 deletions(-) create mode 100644 src/CBot/README.txt diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp index 17871abf..8784fabd 100644 --- a/src/CBot/CBotCall.cpp +++ b/src/CBot/CBotCall.cpp @@ -245,7 +245,7 @@ fund: CBotStack* pile2 = pile->AddStack(); pile2->SetVar( pResult ); - pile->SetError(0, token); // for the position on error + away + pile->SetError(CBotNoErr, token); // for the position on error + away return pt->Run( pStack ); #endif @@ -292,14 +292,14 @@ bool CBotCall::Run(CBotStack* pStack) CBotVar* pResult = pile2->GetVar(); CBotVar* pRes = pResult; - int Exception = 0; + int Exception = 0; // TODO: change this to CBotError int res = m_rExec(pVar, pResult, Exception, pStack->GetPUser()); if (res == false) { if (Exception!=0) { - pStack->SetError(Exception); + pStack->SetError(static_cast(Exception)); } if ( pResult != pRes ) delete pResult; // different result if made return false; diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp index 0bc8184d..39b6084a 100644 --- a/src/CBot/CBotCallMethode.cpp +++ b/src/CBot/CBotCallMethode.cpp @@ -126,7 +126,7 @@ int CBotCallMethode::DoCall(long& nIdent, // then calls the routine external to the module - int Exception = 0; + int Exception = 0; // TODO: Change this to CBotError int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); pStack->SetVar(pResult); @@ -135,7 +135,7 @@ int CBotCallMethode::DoCall(long& nIdent, if (Exception!=0) { // pStack->SetError(Exception, pVar->GetToken()); - pStack->SetError(Exception, pToken); + pStack->SetError(static_cast(Exception), pToken); } delete pVarToDelete; return false; @@ -157,7 +157,7 @@ int CBotCallMethode::DoCall(long& nIdent, CBotVar* pVar = MakeListVars(ppVars, true); CBotVar* pVarToDelete = pVar; - int Exception = 0; + int Exception = 0; // TODO: Change this to CBotError int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetPUser()); pStack->SetVar(pResult); @@ -166,7 +166,7 @@ int CBotCallMethode::DoCall(long& nIdent, if (Exception!=0) { // pStack->SetError(Exception, pVar->GetToken()); - pStack->SetError(Exception, pToken); + pStack->SetError(static_cast(Exception), pToken); } delete pVarToDelete; return false; diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index 98f47cf5..57bee4e3 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -286,7 +286,7 @@ bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToke pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary if (pVar == nullptr) { - pj->SetError(1, &m_token); + pj->SetError(static_cast(1), &m_token); // TODO: yeah, don't care that this exception doesn't exist ~krzys_h return false; } if ( m_next3 != nullptr && diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 9a4129aa..92352455 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -380,7 +380,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) if ( !m_Block->Execute(pile) ) { if ( pile->GetError() < 0 ) - pile->SetError( 0 ); + pile->SetError( CBotNoErr ); else return false; } diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 4ac6a4e4..56f124f1 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -222,7 +222,7 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT pVar = pile->FindVar(m_nIdent); if (pVar == nullptr) { - pile->SetError(2, &m_token); + pile->SetError(static_cast(2), &m_token); // TODO: yup, another unknown error ~krzys_h return false; } diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp index 44c43f07..6393239f 100644 --- a/src/CBot/CBotInstr/CBotThrow.cpp +++ b/src/CBot/CBotInstr/CBotThrow.cpp @@ -83,7 +83,7 @@ bool CBotThrow::Execute(CBotStack* &pj) int val = pile->GetVal(); if ( val < 0 ) val = CBotErrBadThrow; - pile->SetError( val, &m_token ); + pile->SetError( static_cast(val), &m_token ); return pj->Return( pile ); } diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp index 5cf57904..ac890596 100644 --- a/src/CBot/CBotInstr/CBotTry.cpp +++ b/src/CBot/CBotInstr/CBotTry.cpp @@ -109,7 +109,7 @@ bool CBotTry::Execute(CBotStack* &pj) pile1->IncState(); pile2->SetState(val); // stores the error number - pile1->SetError(0); // for now there is are more errors! + pile1->SetError(CBotNoErr); // for now there is are more errors! if ( val == 0 && CBotStack::m_initimer < 0 ) // mode step? return false; // does not make the catch @@ -158,7 +158,7 @@ bool CBotTry::Execute(CBotStack* &pj) if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false; if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception - pile2->SetError(pile1->GetState()==-1 ? val : 0); // gives the initial error + pile2->SetError(pile1->GetState()==-1 ? static_cast(val) : CBotNoErr); // gives the initial error return pj->Return(pile2); } @@ -167,7 +167,7 @@ bool CBotTry::Execute(CBotStack* &pj) if ( val != 0 && m_ListCatch == nullptr && m_FinalInst == nullptr ) return pj->Return(pile2); // ends the try without exception - pile1->SetError(val); // gives the error + pile1->SetError(static_cast(val)); // gives the error return false; // it's not for us } diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp index bb3375fc..43d7c0dd 100644 --- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp @@ -287,7 +287,7 @@ bool VarIsNAN(const CBotVar* var) return var->GetInit() > CBotVar::InitType::DEF; } -bool IsNan(CBotVar* left, CBotVar* right, int* err = nullptr) +bool IsNan(CBotVar* left, CBotVar* right, CBotError* err = nullptr) { if ( VarIsNAN(left) || VarIsNAN(right) ) { @@ -394,7 +394,7 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack) if ( TypeRes == CBotTypClass ) temp = CBotVar::Create( static_cast(nullptr), CBotTypResult(CBotTypIntrinsic, type1.GetClass() ) ); else temp = CBotVar::Create( static_cast(nullptr), TypeRes ); - int err = 0; + CBotError err = CBotNoErr; // is a operation according to request CBotVar* left = pStk1->GetVar(); CBotVar* right = pStk2->GetVar(); diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index f65d8e29..c2cc8169 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -47,7 +47,7 @@ CBotProgram::CBotProgram() m_pStack = nullptr; m_pInstance = nullptr; - m_ErrorCode = 0; + m_ErrorCode = CBotNoErr; m_Ident = 0; } @@ -60,7 +60,7 @@ CBotProgram::CBotProgram(CBotVar* pInstance) m_pStack = nullptr; m_pInstance = pInstance; - m_ErrorCode = 0; + m_ErrorCode = CBotNoErr; m_Ident = 0; } @@ -82,7 +82,7 @@ CBotProgram::~CBotProgram() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::Compile(const std::string& program, std::vector& ListFonctions, void* pUser) +bool CBotProgram::Compile(const std::string& program, std::vector& functions, void* pUser) { int error = 0; Stop(); @@ -93,8 +93,8 @@ bool CBotProgram::Compile(const std::string& program, std::vector& m_pClass = nullptr; delete m_Prog; m_Prog= nullptr; - ListFonctions.clear(); - m_ErrorCode = 0; + functions.clear(); + m_ErrorCode = CBotNoErr; // transforms the program in Tokens CBotToken* pBaseToken = CBotToken::CompileTokens(program, error); @@ -154,7 +154,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector& { m_bCompileClass = false; CBotFunction::Compile(p, pStack, next); - if (next->IsExtern()) ListFonctions.push_back(next->GetName()/* + next->GetParams()*/); + if (next->IsExtern()) functions.push_back(next->GetName()/* + next->GetParams()*/); next->m_pProg = this; // keeps pointers to the module next = next->Next(); } @@ -233,7 +233,7 @@ bool CBotProgram::Run(void* pUser, int timer) if (m_pStack == nullptr || m_pRun == nullptr) goto error; - m_ErrorCode = 0; + m_ErrorCode = CBotNoErr; m_pStack->Reset(pUser); // empty the possible previous error, and resets the timer if ( timer >= 0 ) m_pStack->SetTimer(timer); @@ -286,23 +286,23 @@ void CBotProgram::Stop() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::GetRunPos(std::string& FunctionName, int& start, int& end) +bool CBotProgram::GetRunPos(std::string& functionName, int& start, int& end) { - FunctionName = nullptr; + functionName = nullptr; start = end = 0; if (m_pStack == nullptr) return false; - m_pStack->GetRunPos(FunctionName, start, end); + m_pStack->GetRunPos(functionName, start, end); return true; } //////////////////////////////////////////////////////////////////////////////// -CBotVar* CBotProgram::GetStackVars(std::string& FunctionName, int level) +CBotVar* CBotProgram::GetStackVars(std::string& functionName, int level) { - FunctionName = nullptr; + functionName.clear(); if (m_pStack == nullptr) return nullptr; - return m_pStack->GetStackVars(FunctionName, level); + return m_pStack->GetStackVars(functionName, level); } //////////////////////////////////////////////////////////////////////////////// @@ -312,7 +312,7 @@ void CBotProgram::SetTimer(int n) } //////////////////////////////////////////////////////////////////////////////// -int CBotProgram::GetError() +CBotError CBotProgram::GetError() { return m_ErrorCode; } @@ -330,7 +330,7 @@ long CBotProgram::GetIdent() } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::GetError(int& code, int& start, int& end) +bool CBotProgram::GetError(CBotError& code, int& start, int& end) { code = m_ErrorCode; start = m_ErrorStart; @@ -339,7 +339,7 @@ bool CBotProgram::GetError(int& code, int& start, int& end) } //////////////////////////////////////////////////////////////////////////////// -bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) +bool CBotProgram::GetError(CBotError& code, int& start, int& end, CBotProgram*& pProg) { code = m_ErrorCode; start = m_ErrorStart; @@ -348,20 +348,6 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg) return code > 0; } -//////////////////////////////////////////////////////////////////////////////// -std::string CBotProgram::GetErrorText(int code) -{ - std::string TextError = LoadString(static_cast(code)); - - if (TextError.empty()) - { - char buf[100]; - sprintf(buf, "Exception numéro %d.", code); - TextError = buf; - } - return TextError; -} - //////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotProgram::GetFunctions() { @@ -472,18 +458,18 @@ int CBotProgram::GetVersion() //////////////////////////////////////////////////////////////////////////////// void CBotProgram::Init() { - CBotToken::DefineNum("CBotErrZeroDiv", CBotErrZeroDiv); // division by zero - CBotToken::DefineNum("CBotErrNotInit", CBotErrNotInit); // uninitialized variable - CBotToken::DefineNum("CBotErrBadThrow", CBotErrBadThrow); // throw a negative value - CBotToken::DefineNum("CBotErrNoRetVal", CBotErrNoRetVal); // function did not return results - CBotToken::DefineNum("CBotErrNoRun", CBotErrNoRun); // active Run () without a function // TODO: Is this actually a runtime error? - CBotToken::DefineNum("CBotErrUndefFunc", CBotErrUndefFunc); // Calling a function that no longer exists - CBotToken::DefineNum("CBotErrNotClass", CBotErrNotClass); // Class no longer exists - CBotToken::DefineNum("CBotErrNull", CBotErrNull); // Attempted to use a null pointer - CBotToken::DefineNum("CBotErrNan", CBotErrNan); // Can't do operations on nan - CBotToken::DefineNum("CBotErrOutArray", CBotErrOutArray); // Attempted access out of bounds of an array - CBotToken::DefineNum("CBotErrStackOver", CBotErrStackOver); // Stack overflow - CBotToken::DefineNum("CBotErrDeletedPtr", CBotErrDeletedPtr); // Attempted to use deleted object + CBotToken::DefineNum("CBotErrZeroDiv", CBotErrZeroDiv); // division by zero + CBotToken::DefineNum("CBotErrNotInit", CBotErrNotInit); // uninitialized variable + CBotToken::DefineNum("CBotErrBadThrow", CBotErrBadThrow); // throw a negative value + CBotToken::DefineNum("CBotErrNoRetVal", CBotErrNoRetVal); // function did not return results + CBotToken::DefineNum("CBotErrNoRun", CBotErrNoRun); // active Run () without a function // TODO: Is this actually a runtime error? + CBotToken::DefineNum("CBotErrUndefFunc", CBotErrUndefFunc); // Calling a function that no longer exists + CBotToken::DefineNum("CBotErrNotClass", CBotErrNotClass); // Class no longer exists + CBotToken::DefineNum("CBotErrNull", CBotErrNull); // Attempted to use a null pointer + CBotToken::DefineNum("CBotErrNan", CBotErrNan); // Can't do operations on nan + CBotToken::DefineNum("CBotErrOutArray", CBotErrOutArray); // Attempted access out of bounds of an array + CBotToken::DefineNum("CBotErrStackOver", CBotErrStackOver); // Stack overflow + CBotToken::DefineNum("CBotErrDeletedPtr", CBotErrDeletedPtr); // Attempted to use deleted object CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf ); diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 50c62f63..4ded0aac 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -19,205 +19,286 @@ #pragma once -// Modules inlcude #include "CBot/CBotTypResult.h" - #include "CBot/CBotEnums.h" -// Local include - -// Global include #include -// Forward declaration class CBotFunction; class CBotClass; class CBotStack; class CBotVar; -/*! - * \brief The CBotProgram class Main class managing CBot program. +/** + * \brief Class that manages a CBot program. This is the main entry point into the CBot engine. + * + * \section Init Engine initialization / destruction + * To initialize the CBot engine, call CBotProgram::Init(). This function should be only called once. + * + * Afterwards, you can start defining custom functions, constants and classes. See: + * * CBotProgram::AddFunction() + * * CBotProgram::DefineNum() + * * CBotClass::Create() + * + * Next, compile and run programs. + * * Compile() + * * Start() + * * Run() + * * Stop() + * + * After you are finished, free the memory used by the CBot engine by calling CBotProgram::Free(). + * + * \section Example Example usage + * \code + * // Initialize the engine + * CBotProgram::Init(); + * + * // Add some standard functions + * CBotProgram::AddFunction("message", rMessage, cMessage); + * + * // Compile the program + * std::vector externFunctions; + * CBotProgram* program = new CBotProgram(); + * bool ok = program->Compile(code.c_str(), externFunctions, nullptr); + * if (!ok) + * { + * CBotError error; + * int cursor1, cursor2; + * program->GetError(error, cursor1, cursor2); + * // Handle the error + * } + * + * // Run the program + * program->Start(externFunctions[0]); + * while (!program->Run()); + * + * // Cleanup + * CBotProgram::Free(); + * \endcode */ class CBotProgram { public: - - /*! - * \brief CBotProgram + /** + * \brief Constructor */ CBotProgram(); - /*! - * \brief CBotProgram - * \param pInstance + /** + * \brief Constructor + * \param pInstance Variable to pass to the program as "this" */ CBotProgram(CBotVar* pInstance); - /*! - * \brief ~CBotProgram + /** + * \brief Destructor */ ~CBotProgram(); - /*! - * \brief Init Initializes the module (defined keywords for errors) should - * be done once (and only one) at the beginning. + /** + * \brief Initializes the module, should be done once (and only once) at the beginning */ static void Init(); - /*! - * \brief Free Frees the static memory areas. + /** + * \brief Frees the static memory areas */ static void Free(); - /*! - * \brief GetVersion Gives the version of the library CBOT. - * \return + /** + * \brief Returns version of the CBot library + * \return A number representing the current library version */ static int GetVersion(); - /*! - * \brief Compile compiles the program given in text. - * \param program - * \param ListFonctions Returns the names of functions declared as extern. - * \param pUser Can pass a pointer to routines defined by AddFunction. - * \return false if an error at compile. - * \see GetCompileError() to retrieve the error. + /** + * \brief Compile compiles the program given as string + * \param program Code to compile + * \param[out] functions Returns the names of functions declared as extern + * \param pUser Optional pointer to be passed to compile function (see AddFunction()) + * \return true if compilation is successful, false if an compilation error occurs + * \see GetError() to retrieve the error */ - bool Compile(const std::string& program, std::vector& ListFonctions, void* pUser = nullptr); + bool Compile(const std::string& program, std::vector& functions, void* pUser = nullptr); - /*! - * \brief SetIdent Associates an identifier with the instance CBotProgram. - * \param n + /** + * \brief Associates an identifier with this instance of CBotProgram */ void SetIdent(long n); - /*! - * \brief GetIdent Gives the identifier. - * \return + /** + * \brief Returns the identifier + * \see SetIdent */ long GetIdent(); - /*! - * \brief GetError - * \return + /** + * \brief Returns the last error + * \return Error code + * \see GetError(CBotError&, int&, int&) for error location in the code */ - int GetError(); + CBotError GetError(); - /*! - * \brief GetError - * \param code - * \param start - * \param end - * \return + /** + * \brief Returns the last error + * \param[out] code Error code + * \param[out] start Starting position in the code string of this error + * \param[out] end Ending position in the code string of this error + * \return false if no error has occured */ - bool GetError(int& code, int& start, int& end); + bool GetError(CBotError& code, int& start, int& end); - /*! - * \brief GetError - * \param code - * \param start Delimits the start block where the error occured. - * \param end Delimits the end block where the error occured. - * \param pProg Lets you know what "module" has produced runtime error. - * \return If true gives the error found in the compilation or execution. + /** + * \brief Returns the last error + * \param[out] code Error code + * \param[out] start Starting position in the code string of this error + * \param[out] end Ending position in the code string of this error + * \param[out] pProg Program that caused the error (TODO: This always returns "this"... what?) + * \return false if no error has occured */ - bool GetError(int& code, int& start, int& end, CBotProgram* &pProg); + bool GetError(CBotError& code, int& start, int& end, CBotProgram*& pProg); - /*! - * \brief GetErrorText - * \param code - * \return - */ - static std::string GetErrorText(int code); - - /*! - * \brief Start Defines what function should be executed. The program does - * nothing, we must call Run () for this. - * \param name - * \return false if the funtion name is not found + /** + * \brief Starts the program using given function as an entry point. The function must be declared as "extern" + * \param name Name of function to start + * \return true if the program was started, false if the function name is not found + * \see Compile() returns list of extern functions found in the code */ bool Start(const std::string& name); - /*! - * \brief Run Executes the program. - * \param pUser - * \param timer timer = 0 allows to advance step by step. - * \return false if the program was suspended, true if the program ended - * with or without error. + /** + * \brief Executes the program + * \param pUser Custom pointer to be passed to execute function (see AddFunction()) + * \param timer + * \parblock + * * timer < 0 do nothing + * * timer >= 0 call SetTimer(int timer) before executing + * \parblockend + * \return true if the program execution finished, false if the program is suspended (you then have to call Run() again) */ bool Run(void* pUser = nullptr, int timer = -1); - /*! - * \brief GetRunPos Gives the position in the executing program - * \param FunctionName is a pointer made to the name of the function - * \param start start and end position in the text of the token processing - * \param end + /** + * \brief GetRunPos Gives the current position in the executing program + * \param[out] functionName Name of the currently executed function + * \param[out] start Starting position in the code string of currently executed instruction + * \param[out] end Ending position in the code string of currently executed instruction * \return false if it is not running (program completion) */ - bool GetRunPos(std::string& FunctionName, int& start, int& end); + bool GetRunPos(std::string& functionName, int& start, int& end); - /*! - * \brief GetStackVars provides the pointer to the variables on the - * execution stack level is an input parameter, 0 for the last level, -1, - * -2, etc. for the other levels the return value (CBotVar *) is a variable. - * that can be processed as the list of parameters received by a routine - * list (or nullptr) - * \param FunctionName gives the name of the function where are these - * variables. FunctionName == nullptr means that is more in a program - * (depending on level) - * \param level - * \return + /** + * \brief Provides the pointer to the variables on the execution stack + * \param[out] functionName Name of the function that this stack is part of + * \param level 0 for the last level, -1, -2 etc. for previous ones + * \return Variables on the given stack level. Process using CBotVar::GetNext(). If the stack level is invalid, returns nullptr. */ - CBotVar* GetStackVars(std::string& FunctionName, int level); + CBotVar* GetStackVars(std::string& functionName, int level); - /*! - * \brief Stop stops execution of the program therefore quits "suspend" mode + /** + * \brief Stops execution of the program */ void Stop(); - /*! - * \brief SetTimer defines the number of steps (parts of instructions) to - * done in Run() before rendering hand "false" - * \TODO avant de rendre la main "false" - * \param n + /** + * \brief Sets the number of steps (parts of instructions) to execute in Run() before suspending the program execution + * \param n new timer value + * + * FIXME: Seems to be currently kind of broken (see issue #410) */ static void SetTimer(int n); - // - // - /*! - * \brief AddFunction Call this to add externally a new function used - * by the program CBoT. See (**) at end of this file for more details. - * \param name - * \param rExec - * \param rCompile - * \return + /** + * \brief Add a function that can be called from CBot + * + * To define an external function, proceed as follows: + * + * 1. Define a function for compilation + * + * This function should take a list of function arguments (types only, no values!) and a user-defined void* pointer (can be passed in Compile()) as parameters, and return CBotTypResult. + * + * Usually, name of this function is prefixed with "c". + * + * The function should iterate through the provided parameter list and verify that they match.
+ * If they don't, then return CBotTypResult with an appropariate error code (see ::CBotError).
+ * If they do, return CBotTypResult with the function's return type + * + * \code + * CBotTypResult cMessage(CBotVar* &var, void* user) + * { + * if (var == nullptr) return CBotTypResult(CBotErrLowParam); // Not enough parameters + * if (var->GetType() != CBotTypString) return CBotTypResult(CBotErrBadString); // String expected + * + * var = var->GetNext(); // Get the next parameter + * if (var != nullptr) return CBotTypResult(CBotErrOverParam); // Too many parameters + * + * return CBotTypResult(CBotTypFloat); // This function returns float (it may depend on parameters given!) + * } + * \endcode + * + * 2. Define a function for execution + * + * This function should take: + * * a list of parameters + * * pointer to a result variable (a variable of type given at compilation time will be provided) + * * pointer to an exception variable + * * user-defined pointer (can be passed in Run()) + * + * This function returns true if execution of this function is finished, or false to suspend the program and call this function again on next Run() cycle. + * + * Usually, execution functions are prefixed with "r". + * + * \code + * bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) + * { + * std::string message = var->GetValString(); + * std::cout << message << std::endl; + * return true; // Execution finished + * } + * \endcode + * + * 3. Call AddFunction() to register the function in the CBot engine + * + * \code + * AddFunction("message", rMessage, cMessage); + * \endcode + * + * + * \param name Name of the function + * \param rExec Execution function + * \param rCompile Compilation function + * \return true */ static bool AddFunction(const std::string& name, bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile(CBotVar*& pVar, void* pUser)); - /*! - * \brief DefineNum - * \param name - * \param val - * \return + /** + * \brief Define a new constant + * \param name Name of the constant + * \param val Value of the constant + * \return true on success, false if unable to define (e.g. already defined) */ static bool DefineNum(const std::string& name, long val); /*! - * \brief SaveState Backup the execution status in the file the file must - * have been opened with the fopen call this dll (\TODO this library??) - * if the system crashes - * \param pf - * \return + * \brief Save the current execution status into a file + * \param pf file handle + * \paramblock + * This file handle must have been opened by this library! Otherwise crashes on Windows + * TODO: Verify this + * \endparamblock + * \return true on success, false on write error */ bool SaveState(FILE* pf); /*! - * \brief RestoreState Restores the state of execution from file the - * compiled program must obviously be the same. - * \param pf - * \return + * \brief Restore the execution state from a file + * + * The previous program code must be already recompiled to call this function + * + * \param pf file handle + * \return true on success, false on read error */ bool RestoreState(FILE* pf); @@ -225,6 +306,9 @@ public: * \brief GetPosition Gives the position of a routine in the original text * the user can select the item to find from the beginning to the end * see the above modes in CBotGet. + * + * TODO: Document this + * * \param name * \param start * \param stop @@ -239,76 +323,37 @@ public: CBotGet modestop = GetPosBloc); /*! - * \brief GetFunctions - * \return + * \brief Returns the list of all user-defined functions in this program as instances of CBotFunction + * + * This list includes all the functions (not only extern) + * + * \return Linked list of CBotFunction instances */ CBotFunction* GetFunctions(); /*! * \brief m_bCompileClass + * + * TODO: document this */ bool m_bCompileClass; private: - - //! The user-defined functions. + //! All user-defined functions CBotFunction* m_Prog; - //! The basic function for the execution. + //! The entry point function CBotFunction* m_pRun; - //! Classes defined in this part. + //! Classes defined in this program CBotClass* m_pClass; - //! Execution stack. + //! Execution stack CBotStack* m_pStack; - //! Instance of the parent class. + //! "this" variable CBotVar* m_pInstance; friend class CBotFunction; - int m_ErrorCode; + CBotError m_ErrorCode; int m_ErrorStart; int m_ErrorEnd; - //! Associated identifier. + //! Associated identifier long m_Ident; }; - -/* -(**) Note: - - To define an external function, proceed as follows: - - a) define a routine for compilation this routine receive list of parameters - (no values) and either returns a result type (CBotTyp... or 0 = void) - or an error number. - - b) define a routine for the execution this routine receive list of - parameters (with valeurs), a variable to store the result - (according to the given type at compile time) - - For example, a routine which calculates the mean of a parameter list - -int cMean(CBotVar* &pVar, std::string& ClassName) -{ - if ( pVar == nullptr ) return 6001; // there is no parameter! - while ( pVar != nullptr ) - { - if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number - pVar = pVar -> GetNext(); - } - return CBotTypFloat; // the type of the result may depend on the parameters! -} - - -bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception) -{ - float total = 0; - int nb = 0; - while (pVar != nullptr) - { - total += pVar->GetValFloat(); - pVar = pVar->GetNext(); - nb++; - } - pResult->SetValFloat(total/nb); // returns the mean value - return true; // operation fully completed -} - -*/ diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 545c49f9..4b13df58 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -42,7 +42,7 @@ int CBotStack::m_initimer = ITIMER; int CBotStack::m_timer = 0; CBotVar* CBotStack::m_retvar = nullptr; -int CBotStack::m_error = 0; +CBotError CBotStack::m_error = CBotNoErr; int CBotStack::m_start = 0; int CBotStack::m_end = 0; std::string CBotStack::m_labelBreak=""; @@ -76,7 +76,7 @@ CBotStack* CBotStack::FirstStack() pp ++; } - m_error = 0; // avoids deadlocks because m_error is static + m_error = CBotNoErr; // avoids deadlocks because m_error is static return p; } @@ -358,7 +358,7 @@ bool CBotStack::StackOver() void CBotStack::Reset(void* pUser) { m_timer = m_initimer; // resets the timer - m_error = 0; + m_error = CBotNoErr; // m_start = 0; // m_end = 0; m_labelBreak.clear(); @@ -402,7 +402,7 @@ bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name) if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name)) return false; // it's not for me - m_error = 0; + m_error = CBotNoErr; m_labelBreak.clear(); return Return(pfils); } @@ -416,7 +416,7 @@ bool CBotStack::IfContinue(int state, const std::string& name) return false; // it's not for me m_state = state; // where again? - m_error = 0; + m_error = CBotNoErr; m_labelBreak.clear(); if ( m_next != EOX ) m_next->Delete(); // purge above stack return true; @@ -425,7 +425,7 @@ bool CBotStack::IfContinue(int state, const std::string& name) //////////////////////////////////////////////////////////////////////////////// void CBotStack::SetBreak(int val, const std::string& name) { - m_error = -val; // reacts as an Exception + m_error = static_cast(-val); // reacts as an Exception m_labelBreak = name; if (val == 3) // for a return { @@ -443,14 +443,14 @@ bool CBotStack::GetRetVar(bool bRet) if ( m_var ) delete m_var; m_var = m_retvar; m_retvar = nullptr; - m_error = 0; + m_error = CBotNoErr; return true; } return bRet; // interrupted by something other than return } //////////////////////////////////////////////////////////////////////////////// -int CBotStack::GetError(int& start, int& end) +CBotError CBotStack::GetError(int& start, int& end) { start = m_start; end = m_end; @@ -584,7 +584,7 @@ bool CBotStack::IncState(int limite) } //////////////////////////////////////////////////////////////////////////////// -void CBotStack::SetError(int n, CBotToken* token) +void CBotStack::SetError(CBotError n, CBotToken* token) { if ( n!= 0 && m_error != 0) return; // does not change existing error m_error = n; @@ -596,7 +596,7 @@ void CBotStack::SetError(int n, CBotToken* token) } //////////////////////////////////////////////////////////////////////////////// -void CBotStack::ResetError(int n, int start, int end) +void CBotStack::ResetError(CBotError n, int start, int end) { m_error = n; m_start = start; diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 5e40fc3e..ba823383 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -22,6 +22,7 @@ // Modules inlcude #include "CBot/CBotDefines.h" #include "CBot/CBotTypResult.h" +#include "CBotEnums.h" // Local include @@ -81,7 +82,7 @@ public: * \param [out] end end of stack * \return error number */ - int GetError(int& start, int& end); + CBotError GetError(int& start, int& end); /** * \brief GetError Get error number @@ -201,9 +202,9 @@ public: bool GetRetVar(bool bRet); long GetVal(); - void SetError(int n, CBotToken* token = nullptr); + void SetError(CBotError n, CBotToken* token = nullptr); void SetPosError(CBotToken* token); - void ResetError(int n, int start, int end); + void ResetError(CBotError n, int start, int end); void SetBreak(int val, const std::string& name); void SetBotCall(CBotProgram* p); @@ -232,7 +233,7 @@ private: int m_state; int m_step; - static int m_error; + static CBotError m_error; static int m_start; static int m_end; static diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h index 3cfa6fc0..085422f7 100644 --- a/src/CBot/CBotTypResult.h +++ b/src/CBot/CBotTypResult.h @@ -50,6 +50,12 @@ public: /** * \brief Constructor for pointer types and intrinsic classes + * + * This is equivalent to calling: + * \code + * CBotTypResult(type, CBotClass::Find(name)) + * \endcode + * * \param type type of created result, see ::CBotType * \param name name of the class */ diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 80d04db8..aeab11db 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -586,17 +586,17 @@ void CBotVar::Power(CBotVar* left, CBotVar* right) } //////////////////////////////////////////////////////////////////////////////// -int CBotVar::Div(CBotVar* left, CBotVar* right) +CBotError CBotVar::Div(CBotVar* left, CBotVar* right) { assert(0); - return 0; + return CBotNoErr; } //////////////////////////////////////////////////////////////////////////////// -int CBotVar::Modulo(CBotVar* left, CBotVar* right) +CBotError CBotVar::Modulo(CBotVar* left, CBotVar* right) { assert(0); - return 0; + return CBotNoErr; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index d3202f46..8acd9cf5 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -27,6 +27,7 @@ // Global include #include +#include // Forward declaration class CBotVarClass; @@ -398,7 +399,7 @@ public: * \param right * \return */ - virtual int Div(CBotVar* left, CBotVar* right); + virtual CBotError Div(CBotVar* left, CBotVar* right); /*! * \brief Modulo Remainder of division @@ -406,7 +407,7 @@ public: * \param right * \return */ - virtual int Modulo(CBotVar* left, CBotVar* right); + virtual CBotError Modulo(CBotVar* left, CBotVar* right); /*! * \brief Power diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 484cbb25..0dcef3ea 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -411,7 +411,8 @@ void CBotVarClass::DecrementUse() // m_error is static in the stack // saves the value for return - int err, start, end; + CBotError err; + int start, end; CBotStack* pile = nullptr; err = pile->GetError(start,end); // stack == nullptr it does not bother! diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp index 23a1977f..886d9730 100644 --- a/src/CBot/CBotVar/CBotVarFloat.cpp +++ b/src/CBot/CBotVar/CBotVarFloat.cpp @@ -128,7 +128,7 @@ void CBotVarFloat::Power(CBotVar* left, CBotVar* right) } //////////////////////////////////////////////////////////////////////////////// -int CBotVarFloat::Div(CBotVar* left, CBotVar* right) +CBotError CBotVarFloat::Div(CBotVar* left, CBotVar* right) { float r = right->GetValFloat(); if ( r != 0 ) @@ -136,11 +136,11 @@ int CBotVarFloat::Div(CBotVar* left, CBotVar* right) m_val = left->GetValFloat() / r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? CBotErrZeroDiv : 0 ); + return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); } //////////////////////////////////////////////////////////////////////////////// -int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) +CBotError CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) { float r = right->GetValFloat(); if ( r != 0 ) @@ -148,7 +148,7 @@ int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) m_val = static_cast(fmod( left->GetValFloat() , r )); m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? CBotErrZeroDiv : 0 ); + return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h index c8821a56..7cff1e78 100644 --- a/src/CBot/CBotVar/CBotVarFloat.h +++ b/src/CBot/CBotVar/CBotVarFloat.h @@ -20,6 +20,7 @@ #pragma once // Modules inlcude +#include #include "CBot/CBotVar/CBotVar.h" // Local include @@ -105,7 +106,7 @@ public: * \param right * \return */ - int Div(CBotVar* left, CBotVar* right) override; + CBotError Div(CBotVar* left, CBotVar* right) override; /*! * \brief Modulo Remainder of division. @@ -113,7 +114,7 @@ public: * \param right * \return */ - int Modulo(CBotVar* left, CBotVar* right) override; + CBotError Modulo(CBotVar* left, CBotVar* right) override; /*! * \brief Power diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp index e6ed9d47..614a959f 100644 --- a/src/CBot/CBotVar/CBotVarInt.cpp +++ b/src/CBot/CBotVar/CBotVarInt.cpp @@ -131,7 +131,7 @@ void CBotVarInt::Power(CBotVar* left, CBotVar* right) } //////////////////////////////////////////////////////////////////////////////// -int CBotVarInt::Div(CBotVar* left, CBotVar* right) +CBotError CBotVarInt::Div(CBotVar* left, CBotVar* right) { int r = right->GetValInt(); if ( r != 0 ) @@ -139,11 +139,11 @@ int CBotVarInt::Div(CBotVar* left, CBotVar* right) m_val = left->GetValInt() / r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? CBotErrZeroDiv : 0 ); + return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); } //////////////////////////////////////////////////////////////////////////////// -int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) +CBotError CBotVarInt::Modulo(CBotVar* left, CBotVar* right) { int r = right->GetValInt(); if ( r != 0 ) @@ -151,7 +151,7 @@ int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) m_val = left->GetValInt() % r; m_binit = CBotVar::InitType::DEF; } - return ( r == 0 ? CBotErrZeroDiv : 0 ); + return ( r == 0 ? CBotErrZeroDiv : CBotNoErr ); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h index 16da7882..9cce4e9b 100644 --- a/src/CBot/CBotVar/CBotVarInt.h +++ b/src/CBot/CBotVar/CBotVarInt.h @@ -20,6 +20,7 @@ #pragma once // Modules inlcude +#include #include "CBot/CBotVar/CBotVar.h" // Local include @@ -105,7 +106,7 @@ public: * \param right * \return */ - int Div(CBotVar* left, CBotVar* right) override; + CBotError Div(CBotVar* left, CBotVar* right) override; /*! * \brief Modulo @@ -113,7 +114,7 @@ public: * \param right * \return */ - int Modulo(CBotVar* left, CBotVar* right) override; + CBotError Modulo(CBotVar* left, CBotVar* right) override; /*! * \brief Power diff --git a/src/CBot/README.txt b/src/CBot/README.txt new file mode 100644 index 00000000..f6dcb5fb --- /dev/null +++ b/src/CBot/README.txt @@ -0,0 +1,4 @@ +/** + * \dir src/CBot + * \brief CBot library + */ \ No newline at end of file diff --git a/src/script/script.cpp b/src/script/script.cpp index 4e70817c..0a8b79ef 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -165,7 +165,7 @@ bool CScript::CheckToken() if ( !m_object->GetCheckToken() ) return true; - m_error = 0; + m_error = CBotNoErr; m_title[0] = 0; m_mainFunction[0] = 0; m_token[0] = 0; @@ -194,7 +194,7 @@ bool CScript::CheckToken() if ( !m_main->IsProhibitedToken(token.c_str()) ) { - m_error = ERR_PROHIBITEDTOKEN; + m_error = static_cast(ERR_PROHIBITEDTOKEN); m_cursor1 = cursor1; m_cursor2 = cursor2; strcpy(m_title, ""); @@ -212,7 +212,7 @@ bool CScript::CheckToken() if ( used[i] == 0 ) // token not used? { strcpy(m_token, m_main->GetObligatoryToken(i)); - m_error = ERR_OBLIGATORYTOKEN; + m_error = static_cast(ERR_OBLIGATORYTOKEN); strcpy(m_title, ""); m_mainFunction[0] = 0; CBotToken::Delete(allBt); @@ -232,7 +232,7 @@ bool CScript::Compile() int i; std::string p; - m_error = 0; + m_error = CBotNoErr; m_cursor1 = 0; m_cursor2 = 0; m_title[0] = 0; @@ -815,7 +815,7 @@ void CScript::GetError(std::string& error) } else { - if ( m_error == ERR_OBLIGATORYTOKEN ) + if ( m_error == static_cast(ERR_OBLIGATORYTOKEN) ) { std::string s; GetResource(RES_ERR, m_error, s); diff --git a/src/script/script.h b/src/script/script.h index 7bf9b62f..395c4a4b 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -123,7 +123,7 @@ protected: char m_mainFunction[50] = {}; char m_filename[50] = {}; // file name char m_token[50] = {}; // missing instruction - int m_error = 0; // error (0=ok) + CBotError m_error = CBotNoErr; // error (0=ok) int m_cursor1 = 0; int m_cursor2 = 0; boost::optional m_returnValue = boost::none; diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp index fc0e5cc5..b5e24b41 100644 --- a/test/cbot/console/main.cpp +++ b/test/cbot/console/main.cpp @@ -47,7 +47,8 @@ int main(int argc, char* argv[]) std::unique_ptr program{new CBotProgram(nullptr)}; if (!program->Compile(code.c_str(), externFunctions, nullptr)) { - int error, cursor1, cursor2; + CBotError error; + int cursor1, cursor2; program->GetError(error, cursor1, cursor2); std::string errorStr; GetResource(RES_CBOT, error, errorStr); @@ -74,7 +75,8 @@ int main(int argc, char* argv[]) while (!program->Run(nullptr)); // Run the program - int error, cursor1, cursor2; + CBotError error; + int cursor1, cursor2; program->GetError(error, cursor1, cursor2); if (error != 0) { From c8498740f25f54d90015e7446258ef202f19f829 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 21 Dec 2015 21:46:50 +0100 Subject: [PATCH 164/360] Minor changes to CBotProgram docs --- src/CBot/CBotProgram.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index 4ded0aac..11d44024 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -173,13 +173,13 @@ public: * \parblock * * timer < 0 do nothing * * timer >= 0 call SetTimer(int timer) before executing - * \parblockend + * \endparblock * \return true if the program execution finished, false if the program is suspended (you then have to call Run() again) */ bool Run(void* pUser = nullptr, int timer = -1); /** - * \brief GetRunPos Gives the current position in the executing program + * \brief Gives the current position in the executing program * \param[out] functionName Name of the currently executed function * \param[out] start Starting position in the code string of currently executed instruction * \param[out] end Ending position in the code string of currently executed instruction @@ -263,6 +263,7 @@ public: * AddFunction("message", rMessage, cMessage); * \endcode * + * For more sophisticated examples, see the Colobot source code, mainly the src/script/scriptfunc.cpp file * * \param name Name of the function * \param rExec Execution function @@ -283,11 +284,14 @@ public: /*! * \brief Save the current execution status into a file - * \param pf file handle - * \paramblock + * \param pf + * \parblock + * file handle + * * This file handle must have been opened by this library! Otherwise crashes on Windows + * * TODO: Verify this - * \endparamblock + * \endparblock * \return true on success, false on write error */ bool SaveState(FILE* pf); @@ -295,7 +299,7 @@ public: /*! * \brief Restore the execution state from a file * - * The previous program code must be already recompiled to call this function + * The previous program code must already have been recompiled with Compile() before calling this function * * \param pf file handle * \return true on success, false on read error From 838257943242bedb98d92c51f04c73032748c1d6 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 21 Dec 2015 22:04:56 +0100 Subject: [PATCH 165/360] Updated Doxyfile --- Doxyfile.in | 2438 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 1515 insertions(+), 923 deletions(-) diff --git a/Doxyfile.in b/Doxyfile.in index 4a12dc06..0a0b8e8a 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -1,104 +1,122 @@ -# Doxyfile 1.8.1.2 +# Doxyfile 1.8.9.1 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # -# All text after a hash (#) is considered a comment and will be ignored. +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. # The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" "). +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 -# The PROJECT_NAME tag is a single word (or sequence of words) that should -# identify the project. Note that if you do not use Doxywizard you need -# to put quotes around the project name if it contains spaces. +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. PROJECT_NAME = Colobot -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer -# a quick idea about the purpose of the project. Keep the description short. +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = -# With the PROJECT_LOGO tag one can specify an logo or icon that is -# included in the documentation. The maximum height of the logo should not -# exceed 55 pixels and the maximum width should not exceed 200 pixels. -# Doxygen will copy the logo to the output directory. +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. PROJECT_LOGO = -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. OUTPUT_DIRECTORY = "./doc" -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. CREATE_SUBDIRS = NO +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. OUTPUT_LANGUAGE = English -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. +# The default value is: YES. REPEAT_BRIEF = YES -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ @@ -113,8 +131,9 @@ ABBREVIATE_BRIEF = "The $name class" \ the # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief +# doxygen will generate a detailed section even if there is only a brief # description. +# The default value is: NO. ALWAYS_DETAILED_SEC = NO @@ -122,237 +141,269 @@ ALWAYS_DETAILED_SEC = NO # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. +# The default value is: NO. INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. FULL_PATH_NAMES = YES -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. STRIP_FROM_INC_PATH = -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful if your file system -# doesn't support long names like on DOS, Mac, or CD-ROM. +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. SHORT_NAMES = NO -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. JAVADOC_AUTOBRIEF = NO -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. QT_AUTOBRIEF = NO -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. INHERIT_DOCS = YES -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. SEPARATE_MEMBER_PAGES = NO -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 8 -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. ALIASES = # This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding -# "class=itcl::class" will allow you to use the command class in the -# itcl::class meaning. +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. TCL_SUBST = -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = NO -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this -# tag. The format is ext=language, where ext is a file extension, and language -# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, -# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions -# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. EXTENSION_MAPPING = -# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all -# comments according to the Markdown format, which allows for more readable +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable # documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you -# can mix doxygen, HTML, and XML commands with Markdown formatting. -# Disable only in case of backward compatibilities issues. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. MARKDOWN_SUPPORT = YES +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also makes the inheritance and collaboration +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. +# The default value is: NO. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. +# The default value is: NO. CPP_CLI_SUPPORT = NO -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. SIP_SUPPORT = NO -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first +# tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. +# The default value is: NO. DISTRIBUTE_GROUP_DOC = NO -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. SUBGROUPING = YES -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and -# unions are shown inside the group in which they are included (e.g. using -# @ingroup) instead of on a separate page (for HTML and Man pages) or -# section (for LaTeX and RTF). +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. INLINE_GROUPED_CLASSES = NO -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and -# unions with only public data fields will be shown inline in the documentation -# of the scope in which they are defined (i.e. file, namespace, or group -# documentation), provided this scope is documented. If set to NO (the default), -# structs, classes, and unions are shown on a separate page (for HTML and Man -# pages) or section (for LaTeX and RTF). +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. INLINE_SIMPLE_STRUCTS = NO -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. TYPEDEF_HIDES_STRUCT = NO -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penalty. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will roughly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols. - -SYMBOL_CACHE_SIZE = 0 - -# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be -# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given -# their name and scope. Since this can be an expensive process and often the -# same symbol appear multiple times in the code, doxygen keeps a cache of -# pre-resolved symbols. If the cache is too small doxygen will become slower. -# If the cache is too large, memory is wasted. The cache size is given by this -# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols. +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 @@ -360,343 +411,398 @@ LOOKUP_CACHE_SIZE = 0 # Build related configuration options #--------------------------------------------------------------------------- -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. EXTRACT_ALL = NO -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. EXTRACT_PRIVATE = NO -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal scope will be included in the documentation. +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. EXTRACT_PACKAGE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. EXTRACT_STATIC = NO -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. EXTRACT_LOCAL_CLASSES = YES -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespaces are hidden. +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. EXTRACT_ANON_NSPACES = NO -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_MEMBERS = NO -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_CLASSES = NO -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. HIDE_IN_BODY_DOCS = NO -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. +# The default value is: system dependent. CASE_SENSE_NAMES = NO -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. HIDE_SCOPE_NAMES = NO -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. SHOW_INCLUDE_FILES = YES -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. FORCE_LOCAL_INCLUDES = NO -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. INLINE_INFO = YES -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. SORT_MEMBER_DOCS = YES -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. SORT_BRIEF_DOCS = NO -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. SORT_GROUP_NAMES = NO -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. SORT_BY_SCOPE_NAME = NO -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to -# do proper type resolution of all parameters of a function it will reject a -# match between the prototype and the implementation of a member function even -# if there is only one candidate or it is obvious which candidate to choose -# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen -# will still accept a match between prototype and implementation in such cases. +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. STRICT_PROTO_MATCHING = NO -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. GENERATE_TODOLIST = YES -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. GENERATE_DEPRECATEDLIST= YES -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. ENABLED_SECTIONS = -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or macro consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and macros in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the # list will mention the files that were used to generate the documentation. +# The default value is: YES. SHOW_USED_FILES = YES -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. SHOW_FILES = YES -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. -# You can optionally specify a file name after the option, if omitted -# DoxygenLayout.xml will be used as the name of the layout file. +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. LAYOUT_FILE = -# The CITE_BIB_FILES tag can be used to specify one or more bib files -# containing the references data. This must be a list of .bib files. The -# .bib extension is automatically appended if omitted. Using this command -# requires the bibtex tool to be installed. See also -# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style -# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this -# feature you need bibtex and perl available in the search path. +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- -# configuration options related to warning and progress messages +# Configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. WARNINGS = YES -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. WARN_IF_UNDOCUMENTED = NO -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. WARN_IF_DOC_ERROR = YES -# The WARN_NO_PARAMDOC option can be enabled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. WARN_NO_PARAMDOC = NO -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). WARN_LOGFILE = #--------------------------------------------------------------------------- -# configuration options related to the input files +# Configuration options related to the input files #--------------------------------------------------------------------------- -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. +# Note: If this tag is empty the current directory is searched. INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/src" \ "@CMAKE_CURRENT_SOURCE_DIR@/src/CBot" # This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh -# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py -# *.f90 *.f *.for *.vhd *.vhdl +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank the +# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, +# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, +# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, +# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, +# *.qsf, *.as and *.js. FILE_PATTERNS = *.h \ *.cpp \ README.txt -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. +# # Note that relative paths are relative to the directory from which doxygen is # run. @@ -705,14 +811,16 @@ EXCLUDE = "src/CBot/tests" # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. +# The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = @@ -721,755 +829,1130 @@ EXCLUDE_PATTERNS = # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* EXCLUDE_SYMBOLS = -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. EXAMPLE_PATTERNS = * # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. EXAMPLE_RECURSIVE = NO -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be -# ignored. +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty or if -# non of the patterns match the file name, INPUT_FILTER is applied. +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) -# and it is also possible to disable source filtering for a specific pattern -# using *.ext= (so without naming a filter). This option only has effect when -# FILTER_SOURCE_FILES is enabled. +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + #--------------------------------------------------------------------------- -# configuration options related to source browsing +# Configuration options related to source browsing #--------------------------------------------------------------------------- -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. SOURCE_BROWSER = NO -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. INLINE_SOURCES = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C, C++ and Fortran comments will always remain visible. +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. STRIP_CODE_COMMENTS = YES -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. REFERENCED_BY_RELATION = NO -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. REFERENCES_RELATION = NO -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. REFERENCES_LINK_SOURCE = YES -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. VERBATIM_HEADERS = YES +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# compiled with the --with-libclang option. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + #--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index +# Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. ALPHABETICAL_INDEX = YES -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. COLS_IN_ALPHA_INDEX = 5 -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- -# configuration options related to the HTML output +# Configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. GENERATE_HTML = YES -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. Note that when using a custom header you are responsible -# for the proper inclusion of any scripts and style sheets that doxygen -# needs, which is dependent on the configuration options used. -# It is advised to generate a default header using "doxygen -w html -# header.html footer.html stylesheet.css YourConfigFile" and then modify -# that header. Note that the header is subject to change so you typically -# have to redo this when upgrading to a newer version of doxygen or when -# changing the value of configuration settings such as GENERATE_TREEVIEW! +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# style sheet in the HTML output directory as well, or it will be erased! +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the -# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that -# the files will be copied as-is; there are no commands or markers available. +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. -# Doxygen will adjust the colors in the style sheet and background images -# according to this color. Hue is specified as an angle on a colorwheel, -# see http://en.wikipedia.org/wiki/Hue for more information. -# For instance the value 0 represents red, 60 is yellow, 120 is green, -# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. -# The allowed range is 0 to 359. +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 220 -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of -# the colors in the HTML output. For a value of 0 the output will use -# grayscales only. A value of 255 will produce the most vivid colors. +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to -# the luminance component of the colors in the HTML output. Values below -# 100 gradually make the output lighter, whereas values above 100 make -# the output darker. The value divided by 100 is the actual gamma applied, -# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, -# and 100 does not change the gamma. +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = NO # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = NO -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of -# entries shown in the various tree structured indices initially; the user -# can expand and collapse entries dynamically later on. Doxygen will expand -# the tree to such a level that at most the specified number of entries are -# visible (unless a fully collapsed tree already exceeds this amount). -# So setting the number of entries 1 will produce a full collapsed tree by -# default. 0 is a special value representing an infinite number of entries -# and will result in a full expanded tree by default. +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 100 -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html # for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project -# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher -# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be # written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated -# that can be used as input for Qt's qhelpgenerator to generate a -# Qt Compressed Help (.qch) of the generated HTML documentation. +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to -# add. For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see -# -# Qt Help Project / Custom Filters. +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's -# filter section matches. -# -# Qt Help Project / Filter Attributes. +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project -# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) -# at top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. Since the tabs have the same information as the -# navigation tree you can set this option to NO if you already set -# GENERATE_TREEVIEW to YES. +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = NO # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. -# Since the tree basically has the same information as the tab index you -# could consider to set DISABLE_INDEX to NO when enabling this option. +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = NO -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values -# (range [0,1..20]) that doxygen will group on one line in the generated HTML -# documentation. Note that a value of 0 will completely suppress the enum -# values from appearing in the overview section. +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 4 -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open -# links to external symbols imported via tag files in a separate window. +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are -# not supported properly for IE 6.0, but are supported on all modern browsers. -# Note that when changing this option you need to delete any form_*.png files -# in the HTML output before the changes have effect. +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax -# (see http://www.mathjax.org) which uses client side Javascript for the -# rendering instead of using prerendered bitmaps. Use this if you do not -# have LaTeX installed or if you want to formulas look prettier in the HTML -# output. When enabled you may also need to install MathJax separately and -# configure the path to it using the MATHJAX_RELPATH option. +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = NO -# When MathJax is enabled you need to specify the location relative to the -# HTML output directory using the MATHJAX_RELPATH option. The destination -# directory should contain the MathJax.js script. For instance, if the mathjax -# directory is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to -# the MathJax Content Delivery Network so you can quickly see the result without -# installing MathJax. -# However, it is strongly recommended to install a local -# copy of MathJax from http://www.mathjax.org before deployment. +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest -# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension -# names that should be enabled during MathJax rendering. +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = -# When the SEARCHENGINE tag is enabled doxygen will generate a search box -# for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using -# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets -# (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /