Skip to content
Merged

#67 #68

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
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ FetchContent_Declare(json
)
FetchContent_MakeAvailable(json)

FetchContent_Declare(googletest
URL https://github.com/google/googletest/archive/refs/heads/main.zip
)
FetchContent_MakeAvailable(googletest)

add_subdirectory(lib)

if (USE_OPEN_GL)
Expand All @@ -53,10 +58,8 @@ if (USE_OPEN_GL)
)
FetchContent_MakeAvailable(glad)

link_libraries(OpenGL::GL glfw glm glad)
target_link_libraries(${LIBRARY_NAME} PUBLIC glfw)
target_link_libraries(${LIBRARY_NAME} PUBLIC glad)
# target_link_libraries(${LIBRARY_NAME} PUBLIC OpenGL::GL)
endif ()


Expand All @@ -70,6 +73,7 @@ endif()

target_link_libraries(${LIBRARY_NAME} PUBLIC eigen)
target_link_libraries(${LIBRARY_NAME} PUBLIC nlohmann_json::nlohmann_json)
target_include_directories(${LIBRARY_NAME} PUBLIC "${BARTA_ENGINE_DIR}/include")

target_compile_features(${LIBRARY_NAME} PRIVATE cxx_std_20)

Expand All @@ -86,12 +90,9 @@ install(
LIBRARY DESTINATION lib
)

enable_testing()
#add_subdirectory(test/run )
#
#install(
# TARGETS ${RUN_TEST_NAME}
# ARCHIVE DESTINATION lib
# LIBRARY DESTINATION lib
# RUNTIME DESTINATION bin
#)
set(TESTS_TARGET_NAME BartaTests)

add_executable(${TESTS_TARGET_NAME} test/main.cpp)
add_subdirectory(test)

gtest_discover_tests(${TESTS_TARGET_NAME})
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ configure:
cmake -B build -S . -G "Unix Makefiles"

build_p:
cmake --build build --target BartaEngine_lib --config Debug
cmake --build cmake-build-debug --target BartaEngine_lib --config Debug -j 18 --

build_tests:
cmake --build cmake-build-debug --target BartaEngine_lib --config Debug -j 18 --

clang_format:
cmake --build build --target run_clang_format -j 18 --
cmake --build cmake-build-debug --target run_clang_format -j 18 --
# clang tidy doesn't work woth pch and g++
# clang_tidy_barta_engine:
# cmake --build build --target BartaEngine_clangtidy

run:
./build/bin/run_sandbox

run_tests:
./cmake-build-debug/test/BartaTests
161 changes: 96 additions & 65 deletions bin/create_class.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,119 @@ fi

classname="$1"
root_path="/home/bartanakin/repos/BartaEngine"
current_path="$(pwd)"
current_dir="$(pwd)"

if [[ "$current_path" != "$root_path/include"* ]]; then
if [[ "$current_dir" != "$root_path/include"* ]]; then
echo "Error: This script must be run within a subdirectory of $root_path."
exit 1
fi

relative_path="$(echo "$current_path" | sed -n 's|.*\/include/||p')"
rootDirectoryNamespace="Barta::$(echo "$relative_path" | sed 's|/|::|g')"
relative_dir="$(echo "$current_dir" | sed -n 's|.*\/include/||p')"
rootDirectoryNamespace="Barta::$(echo "$relative_dir" | sed 's|/|::|g')"

# Create the header file
header_dir="$root_path/include/$relative_path"
header_file="$header_dir/$classname.h"
header_dir="$root_path/include/$relative_dir"
header_file="$root_path/include/$relative_dir/$classname.h"

mkdir -p "$header_dir"

echo "#pragma once" > "$header_file"
echo "#include <pch.h>" >> "$header_file"
echo "" >> "$header_file"
echo "namespace $rootDirectoryNamespace {" >> "$header_file"
echo " class $classname {" >> "$header_file"
echo " };" >> "$header_file"
echo "}" >> "$header_file"

echo "Header file '$header_file' created successfully."

# Create the source directory if it doesn't exist
source_dir="$root_path/lib/$relative_path"
parent_source_dir="$(dirname "$source_dir")"

if [ ! -d "$source_dir" ]; then
mkdir -p "$source_dir"
echo "Created directory '$source_dir'"

# Ensure the parent directory has a CMakeLists.txt
parent_cmake_file="$parent_source_dir/CMakeLists.txt"
if [ ! -f "$parent_cmake_file" ]; then
touch "$parent_cmake_file"
echo "Created parent CMakeLists.txt at '$parent_cmake_file'"
if [ ! -f "$header_file" ]; then
echo "#pragma once" > "$header_file"
echo "#include <pch.h>" >> "$header_file"
echo "" >> "$header_file"
echo "namespace $rootDirectoryNamespace {" >> "$header_file"
echo "class $classname {};" >> "$header_file"
echo "}" >> "$header_file"

echo "Header file '$header_file' created successfully."
else
echo "Header file '$header_file' already exists."
fi

# Traverse up the directory tree to ensure all CMakeLists.txt files exist and include subdirs
add_cmakelists_recursively() {
local root_dir="$1"
local relative_dir="$2"
local classname="$3"
local target_name="$4"
local dir="$root_dir/$relative_dir"

mkdir -p "$dir"

# Ensure base CMakeLists.txt exists
base_cmake="$dir/CMakeLists.txt"
if [ ! -f "$base_cmake" ]; then
touch "$base_cmake"
echo "Created base CMakeLists.txt at $base_cmake"
fi

# Add add_subdirectory if not already present
dir_name="$(basename "$source_dir")"
if ! grep -q "add_subdirectory($dir_name)" "$parent_cmake_file"; then
echo "Adding add_subdirectory($dir_name) to $parent_cmake_file..."
echo "" >> "$parent_cmake_file"
echo "add_subdirectory($dir_name)" >> "$parent_cmake_file"
# Ensure the source file is added to target_sources
if ! grep -q "target_sources(\${${target_name}} PUBLIC" "$base_cmake"; then
echo "Adding target_sources block to CMakeLists.txt..."
echo -e "target_sources(\${${target_name}} PUBLIC\n $classname.cpp\n)" >> "$base_cmake"
else
if ! grep -q "$classname.cpp" "$base_cmake"; then
echo "Adding $classname.cpp to target_sources..."
sed -i "/target_sources(\${${target_name}} PUBLIC/a \ $classname.cpp" "$base_cmake"
else
echo "$classname.cpp is already in CMakeLists.txt."
fi
fi
fi

# Define the CMakeLists.txt file path
cmake_file=""
if [ -f "$source_dir/CMakeLists.txt" ]; then
cmake_file="$source_dir/CMakeLists.txt"
else
cmake_file="$source_dir/CMakeLists.txt"
touch "$cmake_file"
echo "Created empty CMakeLists.txt in '$source_dir'"
fi
while [ "$dir" != "$root_dir" ]; do
parent_dir="$(dirname "$dir")"
dir_name="$(basename "$dir")"

# Create the source file
source_file="$source_dir/$classname.cpp"
cmake_file="$parent_dir/CMakeLists.txt"
if [ ! -f "$cmake_file" ]; then
touch "$cmake_file"
echo "Created CMakeLists.txt at $cmake_file"
fi

if ! grep -q "add_subdirectory($dir_name)" "$cmake_file"; then
echo "" >> "$cmake_file"
echo "add_subdirectory($dir_name)" >> "$cmake_file"
echo "Linked $dir_name in $cmake_file"
fi

echo "#include <$relative_path/$classname.h>" > "$source_file"
echo "" >> "$source_file"
echo "namespace $rootDirectoryNamespace {" >> "$source_file"
echo "}" >> "$source_file"
dir="$parent_dir"
done

echo "Source file '$source_file' created successfully."
echo "CMakeLists.txt updated successfully."
}

# Ensure the source file is added to target_sources
if ! grep -q "target_sources(\${LIBRARY_NAME} PUBLIC" "$cmake_file"; then
echo "Adding target_sources block to CMakeLists.txt..."
echo -e "target_sources(\${LIBRARY_NAME} PUBLIC\n $classname.cpp\n)" >> "$cmake_file"

add_cmakelists_recursively "$root_path/lib" "$relative_dir" "$classname" "LIBRARY_NAME"

# Create the source file
lib_file_path="$root_path/lib/$relative_dir/$classname.cpp"

if [ ! -f "$lib_file_path" ]; then
echo "#include <$relative_dir/$classname.h>" > "$lib_file_path"
echo "" >> "$lib_file_path"
echo "namespace $rootDirectoryNamespace {" >> "$lib_file_path"
echo "}" >> "$lib_file_path"

echo "Source file '$lib_file_path' created successfully."
else
# Check if the source file is already in the list
if ! grep -q "$classname.cpp" "$cmake_file"; then
echo "Adding $classname.cpp to target_sources..."
sed -i "/target_sources(\${LIBRARY_NAME} PUBLIC/a \ $classname.cpp" "$cmake_file"
else
echo "$classname.cpp is already in CMakeLists.txt."
fi
echo "Source file '$lib_file_path' already exists."
fi
add_cmakelists_recursively "$root_path/test" "$relative_dir" "${classname}Test" "TESTS_TARGET_NAME"

# Create the test file
test_file_path="$root_path/test/$relative_dir/${classname}Test.cpp"
if [ ! -f "$test_file_path" ]; then
echo "#include <pch.h>" > "$test_file_path"
echo "#include <gtest/gtest.h>" >> "$test_file_path"
echo "#include <$relative_dir/$classname.h>" >> "$test_file_path"
echo "" >> "$test_file_path"
echo "using namespace $rootDirectoryNamespace;" >> "$test_file_path"
echo "" >> "$test_file_path"
echo "TEST(${classname}Test, ExampleTest) {" >> "$test_file_path"
echo " EXPECT_TRUE(true);" >> "$test_file_path"
echo "}" >> "$test_file_path"

echo "Test file '$test_file_path' created successfully."
else
echo "Test file '$test_file_path' already exists."
fi

echo "CMakeLists.txt updated successfully."
2 changes: 2 additions & 0 deletions include/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ template<typename CollisionLogger, typename EventLogger, typename ObjectManager,

virtual void run() {
this->graphicsBridge->createWindow(Vector2f(700.f, 700.f), this->windowName);
this->timer.restart();
std::this_thread::sleep_for(std::chrono::milliseconds(2));
while (this->isRunning() && this->graphicsBridge->logEvents(*(this->eventLogger))) {
this->timer.restart();
while (!timer.finished()) {
Expand Down
2 changes: 1 addition & 1 deletion include/Collisions/CheckCollisionVisitorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class CheckCollisionVisitorInterface {

virtual CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const = 0;

virtual CollisionTestResult checkDynamicCollision(const float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const = 0;
virtual CollisionTestResult checkDynamicCollision(PrecisionType delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const = 0;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CircleAABBCheckCollisionVisitor: public CheckCollisionVisitorInterface {

CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;
CollisionTestResult checkDynamicCollision(PrecisionType delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

private:
const Circle circle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CircleCircleCheckCollisionVisitor: public CheckCollisionVisitorInterface {

CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;
CollisionTestResult checkDynamicCollision(PrecisionType delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

private:
const Circle circle1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OBB_AABBCheckCollisionVisitor: public CheckCollisionVisitorInterface {

CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(float deltaTime, CollisionTestResultBuilder& collisionTestResultBuilder) const override;
CollisionTestResult checkDynamicCollision(PrecisionType deltaTime, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

Point calculateCollisionPoint() const;

Expand Down
2 changes: 2 additions & 0 deletions include/Dynamics/DynamicsDTOCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DynamicsDTOCollection {
using DynamicsDTOArray = std::array<DynamicsDTO, NUMBER_OF_ITERATIONS>;
DynamicsDTOArray dynamicsDTOs;

DynamicsDTOCollection() noexcept = default;

explicit DynamicsDTOCollection(
std::array<DynamicsDTO, NUMBER_OF_ITERATIONS> dynamicsDTOs
):
Expand Down
16 changes: 16 additions & 0 deletions include/Dynamics/Mass/ConstantPointMassDistributionCalculator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "MassDistributionCalculatorInterface.h"
#include "Objects/Soft/SoftObject.h"
#include <pch.h>

namespace Barta::Dynamics::Mass {
class ConstantPointMassDistributionCalculator: public virtual MassDistributionCalculatorInterface {
public:
ConstantPointMassDistributionCalculator() = default;

void prepareMassDistribution(Objects::Soft::SoftObject& object) override;

SoftBody::StiffnessMatrixType assembleInverseMassMatrix(const Objects::Soft::Mesh& mesh, const Objects::Soft::NodalVectorType& positions)
override;
};
}
20 changes: 20 additions & 0 deletions include/Dynamics/Mass/MassDistributionCalculatorInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "Dynamics/SoftBody/SoftBodyDynamicsInterface.h"
#include "Objects/Soft/Mesh.h"
#include "Objects/Soft/SoftObject.h"
#include <pch.h>

namespace Barta::Dynamics::Mass {
class MassDistributionCalculatorInterface {
public:
MassDistributionCalculatorInterface() noexcept = default;
virtual ~MassDistributionCalculatorInterface() noexcept = default;

virtual void prepareMassDistribution(Objects::Soft::SoftObject& object) = 0;

virtual SoftBody::StiffnessMatrixType assembleInverseMassMatrix(
const Objects::Soft::Mesh& mesh,
const Objects::Soft::NodalVectorType& positions
) = 0;
};
}
29 changes: 29 additions & 0 deletions include/Dynamics/SoftBody/SoftBodyDynamicsInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "Geometrics/Quaternion.h"
#include "Objects/Soft/Mesh.h"
#include "Objects/Soft/TetrahedralElement.h"
#include "Utilities/MatrixUtilities.h"
#include <pch.h>

namespace Barta::Dynamics::SoftBody {

using StiffnessMatrixType = Eigen::MatrixX<PrecisionType>;
using NodalVectorType = Objects::Soft::NodalVectorType;

class SoftBodyDynamicsInterface {
public:
SoftBodyDynamicsInterface() = default;
virtual ~SoftBodyDynamicsInterface() = default;

virtual StiffnessMatrixType assembleTangentStiffnessMatrix(const Objects::Soft::Mesh& elements, const NodalVectorType& nodesPositions) = 0;

virtual NodalVectorType calculateNodalForces(const Objects::Soft::Mesh& elements, const NodalVectorType& nodesPositions) = 0;

static void emplace12Matrix(
const Utils::Matrix12Type& m12,
const std::array<unsigned int, 4>& nodeIndices,
StiffnessMatrixType& stiffnessMatrix,
unsigned int block3x3Count
);
};
}
12 changes: 12 additions & 0 deletions include/Dynamics/SoftBody/StVenantKirchhoffDynamics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "SoftBodyDynamicsInterface.h"
#include <pch.h>

namespace Barta::Dynamics::SoftBody {
class StVenantKirchhoffDynamics: public virtual SoftBodyDynamicsInterface {
public:
StiffnessMatrixType assembleTangentStiffnessMatrix(const Objects::Soft::Mesh& elements, const NodalVectorType& nodesPositions) override;

NodalVectorType calculateNodalForces(const Objects::Soft::Mesh& elements, const NodalVectorType& nodesPositions) override;
};
}
Loading