Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: move collide2 out as a library #1041

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ SET(CMAKE_C_EXTENSIONS ON)
OPTION(ENABLE_PIE "Enable Position Independent Executables/Shared Libraries (NOT RECOMMENDED on Ubuntu/Mint)" OFF)
MESSAGE(STATUS "Always using preferred PIE logic now")

include(CheckPIESupported)
INCLUDE(CheckPIESupported)
check_pie_supported()
UNSET(CMAKE_POSITION_INDEPENDENT_CODE)
IF (ENABLE_PIE)
Expand All @@ -149,6 +149,39 @@ ELSE (ENABLE_PIE)
SET(CMAKE_POSITION_INDEPENDENT_CODE OFF)
ENDIF (ENABLE_PIE)

INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckTypeSize)
INCLUDE(CMakePushCheckState)
SET(SIZEOF_VOID_P CMAKE_SIZEOF_VOID_P)

SET(CMAKE_FIND_FRAMEWORK "LAST")

#Find Math
INCLUDE(CheckSymbolExists)
IF(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to find a lot of information about this. Is there really a chance modern systems don't have POW? (whatever that is)
I'm asking because a lot of stuff in our cmake was really legacy from 2001.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it. Created #1043 to follow up on that.

# cmake_push_check_state()
check_symbol_exists(pow math.h POW_FUNCTION_EXISTS)
IF(NOT POW_FUNCTION_EXISTS)
UNSET(POW_FUNCTION_EXISTS CACHE)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES m)
# LIST(APPEND CMAKE_REQUIRED_INCLUDES math.h)
check_symbol_exists(pow math.h POW_FUNCTION_EXISTS)
IF(POW_FUNCTION_EXISTS)
SET(NEED_LINKING_AGAINST_LIBM True CACHE BOOL "" FORCE)
ELSE(POW_FUNCTION_EXISTS)
MESSAGE(FATAL_ERROR "Failed making the pow() function available")
ENDIF(POW_FUNCTION_EXISTS)
ENDIF(NOT POW_FUNCTION_EXISTS)
# cmake_pop_check_state()
ENDIF(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM)

# Set the default build type
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Release, RelWithDebInfo, Debug, Profiler" FORCE )
ENDIF (NOT CMAKE_BUILD_TYPE)
MESSAGE("** Build Type: ${CMAKE_BUILD_TYPE}")

# Should we install gtest?
OPTION(INSTALL_GTEST "Should we download and install GTest?" ON)

Expand Down Expand Up @@ -178,7 +211,7 @@ ENDIF (INSTALL_GTEST OR USE_GTEST)

INCLUDE(GNUInstallDirs)

SET(VS_SUBDIRECTORIES "engine")
SET(VS_SUBDIRECTORIES "libraries" "engine")
FOREACH(VS_SUBDIR IN LISTS VS_SUBDIRECTORIES)
ADD_SUBDIRECTORY(${VS_SUBDIR})
ENDFOREACH(VS_SUBDIR)
93 changes: 4 additions & 89 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ INCLUDE(InstallRequiredSystemLibraries)

LIST(APPEND
VS_INCLUDE_DIRS
# VS engine headers
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd
Expand All @@ -52,6 +53,9 @@ LIST(APPEND
${CMAKE_CURRENT_SOURCE_DIR}/src/resource
${CMAKE_CURRENT_SOURCE_DIR}/src/python/base_computer
${CMAKE_CURRENT_SOURCE_DIR}/src/python/config
# Library Headers
${CMAKE_SOURCE_DIR}/libraries/collide2
# CMake Artifacts
${Vega_Strike_BINARY_DIR}
${Vega_Strike_BINARY_DIR}/src
)
Expand All @@ -65,39 +69,6 @@ MESSAGE("VS INCLUDE DIRS: ${VS_INCLUDE_DIRS}")

# The source files used to be listed here...

INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckTypeSize)
INCLUDE(CMakePushCheckState)
SET(SIZEOF_VOID_P CMAKE_SIZEOF_VOID_P)

SET(CMAKE_FIND_FRAMEWORK "LAST")

#Find Math
INCLUDE(CheckSymbolExists)
IF(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM)
# cmake_push_check_state()
check_symbol_exists(pow math.h POW_FUNCTION_EXISTS)
IF(NOT POW_FUNCTION_EXISTS)
UNSET(POW_FUNCTION_EXISTS CACHE)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES m)
# LIST(APPEND CMAKE_REQUIRED_INCLUDES math.h)
check_symbol_exists(pow math.h POW_FUNCTION_EXISTS)
IF(POW_FUNCTION_EXISTS)
SET(NEED_LINKING_AGAINST_LIBM True CACHE BOOL "" FORCE)
ELSE(POW_FUNCTION_EXISTS)
MESSAGE(FATAL_ERROR "Failed making the pow() function available")
ENDIF(POW_FUNCTION_EXISTS)
ENDIF(NOT POW_FUNCTION_EXISTS)
# cmake_pop_check_state()
ENDIF(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM)

# Set the default build type
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Release, RelWithDebInfo, Debug, Profiler" FORCE )
ENDIF (NOT CMAKE_BUILD_TYPE)
MESSAGE("** Build Type: ${CMAKE_BUILD_TYPE}")

# Option to turn off compiling vegastrike bin
OPTION(DISABLE_CLIENT "Disable building the vegastrike bin" OFF )

Expand Down Expand Up @@ -586,61 +557,6 @@ SET(LIBAI_SOURCES
src/cmd/ai/flykeyboard_generic.cpp
)

ADD_LIBRARY(vegastrike-OPcollide
src/cmd/collide2/Ice/IceAABB.cpp
src/cmd/collide2/Ice/IceContainer.cpp
src/cmd/collide2/Ice/IceHPoint.cpp
src/cmd/collide2/Ice/IceIndexedTriangle.cpp
src/cmd/collide2/Ice/IceMatrix3x3.cpp
src/cmd/collide2/Ice/IceMatrix4x4.cpp
src/cmd/collide2/Ice/IceOBB.cpp
src/cmd/collide2/Ice/IcePlane.cpp
src/cmd/collide2/Ice/IcePoint.cpp
src/cmd/collide2/Ice/IceRandom.cpp
src/cmd/collide2/Ice/IceRay.cpp
src/cmd/collide2/Ice/IceRevisitedRadix.cpp
src/cmd/collide2/Ice/IceSegment.cpp
src/cmd/collide2/Ice/IceTriangle.cpp
src/cmd/collide2/Ice/IceUtils.cpp
src/cmd/collide2/csgeom2/opbox.cpp
src/cmd/collide2/csgeom2/opmatrix3.cpp
src/cmd/collide2/csgeom2/opvector3.cpp
src/cmd/collide2/OPC_AABBCollider.cpp
src/cmd/collide2/OPC_AABBTree.cpp
src/cmd/collide2/OPC_BaseModel.cpp
src/cmd/collide2/OPC_BoxPruning.cpp
src/cmd/collide2/OPC_Collider.cpp
src/cmd/collide2/OPC_HybridModel.cpp
src/cmd/collide2/OPC_LSSCollider.cpp
src/cmd/collide2/OPC_MeshInterface.cpp
src/cmd/collide2/OPC_Model.cpp
src/cmd/collide2/OPC_OBBCollider.cpp
src/cmd/collide2/OPC_OptimizedTree.cpp
src/cmd/collide2/OPC_Picking.cpp
src/cmd/collide2/OPC_PlanesCollider.cpp
src/cmd/collide2/OPC_RayCollider.cpp
src/cmd/collide2/OPC_SphereCollider.cpp
src/cmd/collide2/OPC_SweepAndPrune.cpp
src/cmd/collide2/OPC_TreeBuilders.cpp
src/cmd/collide2/OPC_TreeCollider.cpp
src/cmd/collide2/OPC_VolumeCollider.cpp
src/cmd/collide2/CSopcodecollider.cpp
)
TARGET_INCLUDE_DIRECTORIES(vegastrike-OPcollide PUBLIC ${VS_INCLUDE_DIRS})

#TARGET_COMPILE_FEATURES(vegastrike-OPcollide PUBLIC cxx_std_11)
set_property(TARGET vegastrike-OPcollide PROPERTY POSITION_INDEPENDENT_CODE TRUE)
IF (NEED_LINKING_AGAINST_LIBM)
TARGET_LINK_LIBRARIES(vegastrike-OPcollide m)
ENDIF()
TARGET_COMPILE_DEFINITIONS(vegastrike-OPcollide PUBLIC "BOOST_ALL_DYN_LINK" "$<$<CONFIG:Debug>:BOOST_DEBUG_PYTHON>")
IF (WIN32)
TARGET_COMPILE_DEFINITIONS(vegastrike-OPcollide PUBLIC BOOST_USE_WINAPI_VERSION=0x0A00)
TARGET_COMPILE_DEFINITIONS(vegastrike-OPcollide PUBLIC _WIN32_WINNT=0x0A00)
TARGET_COMPILE_DEFINITIONS(vegastrike-OPcollide PUBLIC WINVER=0x0A00)
TARGET_COMPILE_DEFINITIONS(vegastrike-OPcollide PUBLIC "$<$<CONFIG:Debug>:Py_DEBUG>")
ENDIF()

SET(LIBCMD_SOURCES
src/cmd/alphacurve.cpp
src/cmd/carrier.cpp
Expand Down Expand Up @@ -1025,7 +941,6 @@ SET(VEGASTRIKE_SOURCES
src/python/briefing_wrapper.cpp
)


SET(TST_LIBS vegastrike-engine_com vegastrike-OPcollide ${TST_LIBS})

IF (NOT DISABLE_CLIENT)
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cmd/collide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include "physics.h"
#include "universe.h"

#include "collide2/CSopcodecollider.h"
#include "collide2/csgeom2/optransfrm.h"
#include "collide2/basecollider.h"
#include "CSopcodecollider.h"
#include "csgeom2/optransfrm.h"
#include "basecollider.h"

#include "hashtable.h"
#include <string>
Expand Down
8 changes: 4 additions & 4 deletions engine/src/cmd/cont_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#include "vegastrike.h"
#include "gfx/mesh.h"
#include "unit_generic.h"
#include "collide2/Opcode.h"
#include "collide2/CSopcodecollider.h"
#include "collide2/csgeom2/optransfrm.h"
#include "collide2/basecollider.h"
#include "Opcode.h"
#include "CSopcodecollider.h"
#include "csgeom2/optransfrm.h"
#include "basecollider.h"
#include "damageable.h"

#include "unit_collide.h"
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/cont_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
// NO HEADER GUARD

#include "cmd/collide2/Opcode.h"
#include "cmd/collide2/CSopcodecollider.h"
#include "Opcode.h"
#include "CSopcodecollider.h"
#include "terrain.h"

class StarSystem;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/intelligent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "pilot.h"
#include "gfx/mesh.h"
#include "ai/turretai.h"
#include "collide2/CSopcodecollider.h"
#include "CSopcodecollider.h"
#include "vega_cast_utils.h"

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "gfx/planetary_transform.h"
#endif

#include "collide2/CSopcodecollider.h"
#include "CSopcodecollider.h"
#include "images.h"
#include "gfx/halo.h"
#include "gfx/animation.h"
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cmd/unit_collide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "unit_collide.h"
#include "physics.h"

#include "collide2/CSopcodecollider.h"
#include "collide2/csgeom2/optransfrm.h"
#include "collide2/basecollider.h"
#include "CSopcodecollider.h"
#include "csgeom2/optransfrm.h"
#include "basecollider.h"

#include "hashtable.h"

Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include "xml_serializer.h"
#include "gfx/sphere.h"
#include "unit_collide.h"
#include "collide2/Opcode.h"
#include "collide2/CSopcodecollider.h"
#include "Opcode.h"
#include "CSopcodecollider.h"
#include "audiolib.h"
#include "unit_xml.h"
#include "gfx/quaternion.h"
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/unit_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "gfx/sphere.h"
#include "gfx/sprite.h"
#include "audiolib.h"
#include "collide2/CSopcodecollider.h"
#include "CSopcodecollider.h"
#include "unit_collide.h"
#include <string>
#include <set>
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/unit_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include "unit_generic.h"
#include "gfx/sphere.h"
#include "role_bitmask.h"
#include "cmd/collide2/Opcode.h"
#include "cmd/collide2/CSopcodecollider.h"
#include "Opcode.h"
#include "CSopcodecollider.h"
#include "vs_math.h"
#include "mount_size.h"
#include "weapon_info.h"
Expand Down
2 changes: 1 addition & 1 deletion engine/src/gfx/halo_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "lin_time.h"
#include "animation.h"
#include "car_assist.h"
#include "cmd/collide2/CSopcodecollider.h"
#include "CSopcodecollider.h"
#include "options.h"
#include "cmd/unit_collide.h"

Expand Down
12 changes: 6 additions & 6 deletions engine/src/vegastrike.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ extern float AUDIO_ATOM;
#if !defined (NO_GFX)
# if defined(__APPLE__) && defined(__MACH__)
# define GL_GLEXT_FUNCTION_POINTERS 1
# include <gl.h>
# include <glu.h>
# include <glut.h>
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
# else //defined(__APPLE__) && defined(__MACH__)
# define __glext_h_
# include <gl.h>
# include <glu.h>
# include <glut.h>
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
# undef __glext_h_
# endif //defined(__APPLE__) && defined(__MACH__)
#endif //NO_GFX
Expand Down
27 changes: 27 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2025 Benjamen Meyer and other Vega Strike contributors.
#
# https://github.com/vegastrike/Vega-Strike-Engine-Source
#
# This file is part of Vega Strike.
#
# Vega Strike 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.
#
# Vega Strike 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 Vega Strike. If not, see <https://www.gnu.org/licenses/>.

MESSAGE("PROCESSING DIRECTORY: ${CMAKE_CURRENT_SOURCE_DIR}")

#FILE(GLOB VS_LIBRARIES LIST_DIRECTORIES true RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
SET(VS_LIBRARIES "collide2")
FOREACH(VS_LIBDIR IN LISTS VS_LIBRARIES)
MESSAGE("Found Library Directory " ${VS_LIBDIR})
ADD_SUBDIRECTORY(${VS_LIBDIR})
ENDFOREACH(VS_LIBDIR)
Loading
Loading