Skip to content

Commit cde0a77

Browse files
authored
chore(project): Overhaul project structure and build system (#20)
1 parent 812064d commit cde0a77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+803
-403
lines changed

ARCHITECTURE.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# 🏛️ Prism Project Architecture
2+
3+
This document provides a visual overview of the dependency structure of the Prism rendering engine, from a high-level view down to the internal class relationships.
4+
5+
---
6+
7+
## High-Level Project Dependency Graph
8+
9+
This graph shows how the main project components (the demo application, the core library, and the unit tests) interact with each other and with external libraries.
10+
11+
```mermaid
12+
graph TD;
13+
subgraph "External Dependencies"
14+
YAML_CPP["📚 yaml-cpp"];
15+
GTEST["🧪 GoogleTest"];
16+
end
17+
18+
subgraph "Prism Project"
19+
DEMO["💻 prism_demo (Demo App)"];
20+
PRISM_LIB["🎨 Prism (Library)"];
21+
TESTS["⚙️ runTests (Unit Tests)"];
22+
end
23+
24+
DEMO --> PRISM_LIB;
25+
TESTS --> PRISM_LIB;
26+
TESTS --> GTEST;
27+
PRISM_LIB --> YAML_CPP;
28+
```
29+
30+
---
31+
32+
## Internal Library Dependencies
33+
34+
This section details the dependencies within the Prism library, divided into different levels of abstraction for greater clarity and understanding of the project's architecture.
35+
36+
---
37+
38+
### 1. Dependencies between Modules (High-Level Overview)
39+
40+
This graph shows the high-level dependencies between the main modules of the Prism library. An arrow from A to B indicates that Module A depends on Module B.
41+
42+
```mermaid
43+
graph TD;
44+
CORE["🔧 Core"];
45+
OBJECTS["🧩 Objects"];
46+
SCENE["🎬 Scene"];
47+
48+
OBJECTS --> CORE;
49+
SCENE --> CORE;
50+
SCENE --> OBJECTS;
51+
```
52+
53+
---
54+
55+
### 2. Internal Dependencies by Module
56+
57+
These graphs detail the relationships between the classes within each module. To simplify, common dependencies to basic types from other modules (like the Core classes) are abstracted and not explicitly shown here.
58+
59+
#### 2.1. Module: Core
60+
61+
This graph focuses on the internal dependencies of the fundamental math and data type classes within the Core module.
62+
63+
```mermaid
64+
graph TD;
65+
subgraph "Core"
66+
RAY["➡️ Ray"];
67+
POINT3["📍 Point3"];
68+
VECTOR3["📏 Vector3"];
69+
MATRIX["🧮 Matrix"];
70+
MATERIAL["✨ Material"];
71+
COLOR["🌈 Color"];
72+
STYLE["🎨 Style"];
73+
INIT["🔧 Init"];
74+
UTILS["🛠️ Utils"];
75+
end
76+
77+
INIT --> STYLE;
78+
MATRIX --> POINT3;
79+
MATRIX --> VECTOR3;
80+
POINT3 --> VECTOR3;
81+
VECTOR3 --> POINT3;
82+
RAY --> POINT3;
83+
RAY --> VECTOR3;
84+
RAY --> MATRIX;
85+
UTILS --> MATRIX;
86+
UTILS --> POINT3;
87+
UTILS --> VECTOR3;
88+
```
89+
90+
---
91+
92+
#### 2.2. Module: Objects
93+
94+
This graph illustrates the dependencies between the objects and the associated I/O classes, excluding dependencies on basic Core types.
95+
96+
```mermaid
97+
graph TD;
98+
subgraph " Objects"
99+
OBJECT["🧩 Object (Base)"];
100+
SPHERE["⚪ Sphere"];
101+
PLANE["🌐 Plane"];
102+
TRIANGLE["🔺 Triangle"];
103+
MESH["🧊 Mesh"];
104+
OBJ_READER["📑 ObjReader"];
105+
COLORMAP["🌈 ColorMap"];
106+
end
107+
108+
MESH --> OBJECT;
109+
MESH --> OBJ_READER;
110+
OBJ_READER --> COLORMAP;
111+
SPHERE --> OBJECT;
112+
PLANE --> OBJECT;
113+
TRIANGLE --> OBJECT;
114+
```
115+
116+
---
117+
118+
#### 2.3. Module: Scene
119+
120+
This graph details the relationships within the scene module, including the interaction with the external YAML dependency.
121+
122+
```mermaid
123+
graph TD;
124+
subgraph "Scene Management"
125+
SCENE["🎬 Scene"];
126+
CAMERA["📷 Camera"];
127+
SCENE_PARSER["📄 SceneParser"];
128+
end
129+
130+
subgraph "External Dependency"
131+
YAML_CPP["📄 yaml-cpp"];
132+
end
133+
134+
SCENE --> CAMERA;
135+
SCENE_PARSER --> CAMERA;
136+
SCENE_PARSER --> YAML_CPP;
137+
SCENE_PARSER --> SCENE;
138+
```

CMakeLists.txt

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
cmake_minimum_required(VERSION 3.14.0)
2-
cmake_policy(SET CMP0135 NEW) # Policy to modern FetchContent behavior
1+
# ===================================================================
2+
# Prism Library | Root CMakeLists.txt
3+
#
4+
# This is the main project file that orchestrates the entire build.
5+
# It sets global settings and includes the sub-projects.
6+
# ===================================================================
7+
cmake_minimum_required(VERSION 3.22)
8+
project(Prism VERSION 0.1.0 LANGUAGES CXX)
39

4-
project(PG_Project VERSION 0.0.1 LANGUAGES C CXX)
10+
# Set the policy for FetchContent to use modern, safer behavior.
11+
cmake_policy(SET CMP0135 NEW)
512

13+
# --- Global Project Settings ---
614
set(CMAKE_CXX_STANDARD 17)
715
set(CMAKE_CXX_STANDARD_REQUIRED ON)
816
set(CMAKE_CXX_EXTENSIONS OFF)
917

10-
enable_testing()
18+
# --- Build Options ---
19+
# Add an option to control whether the demo application is built.
20+
# Defaults to ON for typical development, but can be turned off.
21+
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)
22+
option(PRISM_BUILD_DEMO "Build the Prism demo application" ON)
1123

24+
# Set a common output directory for all executables.
1225
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
13-
add_subdirectory(libs)
14-
add_subdirectory(src)
1526

27+
# --- Sub-projects ---
28+
add_subdirectory(src) # The Prism library
29+
add_subdirectory(demo) # The demo application
30+
31+
# --- Testing ---
32+
enable_testing()
1633
if(BUILD_TESTING)
17-
### include GoogleTest via FetchContent
18-
include(FetchContent)
19-
FetchContent_Declare(
20-
googletest
21-
URL https://github.com/google/googletest/archive/v1.14.0.zip
22-
)
23-
24-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
25-
FetchContent_MakeAvailable(googletest)
26-
###
27-
add_subdirectory(tests)
28-
endif()
29-
30-
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
31-
install(DIRECTORY data DESTINATION bin)
34+
# Fetch GoogleTest only when tests are enabled.
35+
include(FetchContent)
36+
FetchContent_Declare(
37+
googletest
38+
URL https://github.com/google/googletest/archive/v1.14.0.zip
39+
)
40+
set(INSTALL_GTEST OFF CACHE BOOL "Disable GTest installation" FORCE)
41+
set(BUILD_GTEST_INSTALL OFF CACHE BOOL "Disable GTest installation" FORCE)
42+
FetchContent_MakeAvailable(googletest)
43+
44+
45+
add_subdirectory(tests)
46+
endif()

CMakePresets.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"installDir": "${sourceDir}/install/debug",
1010
"cacheVariables": {
1111
"CMAKE_BUILD_TYPE": "Debug",
12-
"BUILD_TESTING": "ON"
12+
"BUILD_TESTING": "ON",
13+
"PRISM_BUILD_DEMO": "ON"
1314
}
1415
},
1516
{
@@ -20,7 +21,8 @@
2021
"installDir": "${sourceDir}/install/release",
2122
"cacheVariables": {
2223
"CMAKE_BUILD_TYPE": "Release",
23-
"BUILD_TESTING": "OFF"
24+
"BUILD_TESTING": "OFF",
25+
"PRISM_BUILD_DEMO": "OFF"
2426
}
2527
}
2628
],

README.MD renamed to README.md

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
To build and run this project, you will need:
66

77
* **Git**
8-
* **CMake** (version 3.15 or higher recommended)
8+
* **CMake** (version 3.22 or higher recommended)
99
* A **C++17 compliant compiler** (e.g., GCC, Clang, MSVC)
1010

1111
## Building the Project
@@ -55,36 +55,6 @@ The following presets are available:
5555

5656
---
5757

58-
## Code Formatting
59-
60-
This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules.
61-
62-
Before committing any changes, please format your code.
63-
64-
### Installing clang-format
65-
66-
You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with:
67-
68-
```sh
69-
sudo apt install clang-format
70-
```
71-
72-
### Formatting the Entire Project
73-
74-
To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**:
75-
76-
```sh
77-
find src libs tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i
78-
```
79-
80-
**What this command does:**
81-
82-
* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders.
83-
* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`.
84-
* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place.
85-
86-
---
87-
8858
## Running the Application
8959

9060
The executable (`PG_Project`) will be located in the `bin` subdirectory of your build folder.
@@ -128,3 +98,66 @@ This project includes rules to create a clean, distributable package in a local
12898
```
12999

130100
The `install/release` folder will then contain the `PG_Project` executable and the `libPrism.so` (or `Prism.dll`) library, ready to be run together.
101+
102+
## Code Formatting
103+
104+
This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules.
105+
106+
Before committing any changes, please format your code.
107+
108+
### Installing clang-format
109+
110+
You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with:
111+
112+
```sh
113+
sudo apt install clang-format
114+
```
115+
116+
### Formatting the Entire Project
117+
118+
To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**:
119+
120+
```sh
121+
find src demo tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i
122+
```
123+
124+
**What this command does:**
125+
126+
* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders.
127+
* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`.
128+
* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place.
129+
130+
---
131+
132+
## 🏛️ Project Architecture
133+
134+
The project is organized into three main components: the core `Prism` library, a `prism_demo` application that uses the library, and a `runTests` executable for unit testing. The dependencies are managed by CMake and are visualized below.
135+
136+
```mermaid
137+
graph TD;
138+
subgraph "External Dependencies"
139+
YAML_CPP["📚 yaml-cpp"];
140+
GTEST["🧪 GoogleTest"];
141+
end
142+
143+
subgraph "Prism Project"
144+
DEMO["💻 prism_demo (Demo App)"];
145+
PRISM_LIB["🎨 Prism (Library)"];
146+
TESTS["⚙️ runTests (Unit Tests)"];
147+
end
148+
149+
DEMO --> PRISM_LIB;
150+
TESTS --> PRISM_LIB;
151+
TESTS --> GTEST;
152+
PRISM_LIB --> YAML_CPP;
153+
154+
style DEMO fill:#cce5ff,stroke:#333,stroke-width:2px;
155+
style TESTS fill:#d5e8d4,stroke:#333,stroke-width:2px;
156+
style PRISM_LIB fill:#ffcce5,stroke:#333,stroke-width:2px;
157+
style YAML_CPP fill:#fff2cc,stroke:#333,stroke-width:2px;
158+
style GTEST fill:#fff2cc,stroke:#333,stroke-width:2px;
159+
```
160+
161+
For a more detailed breakdown of the internal library dependencies, please see the ARCHITECTURE.md file.
162+
163+
---

demo/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ===================================================================
2+
# Prism Demo Application
3+
#
4+
# This CMakeLists.txt file defines the demo application that uses the
5+
# Prism library. It sets up the executable target, links against the
6+
# Prism library, and handles installation.
7+
# ===================================================================
8+
9+
add_executable(prism_demo src/main.cpp)
10+
11+
target_link_libraries(prism_demo PRIVATE Prism)
12+
13+
set_target_properties(prism_demo PROPERTIES
14+
INSTALL_RPATH "$ORIGIN/../lib"
15+
)
16+
17+
# --- Installation ---
18+
install(TARGETS prism_demo DESTINATION bin)
19+
20+
# This command is now much cleaner. It copies the 'data' directory
21+
# from this subdirectory into the install directory.
22+
install(DIRECTORY data/ DESTINATION ./bin/data)
23+
24+
# --- Development/Debugging Support ---
25+
26+
# This is the key command that solves the debugging issue.
27+
# It copies the 'data' directory into the build output directory
28+
# *after* the executable is built.
29+
add_custom_command(TARGET prism_demo POST_BUILD
30+
COMMAND ${CMAKE_COMMAND} -E copy_directory
31+
${CMAKE_CURRENT_SOURCE_DIR}/data
32+
$<TARGET_FILE_DIR:prism_demo>/data
33+
COMMENT "Copying data folder for debug/run..."
34+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ objects:
6969

7070
- name: Malha de Cubo Metálico
7171
type: mesh
72-
path: "./data/input/cubo.obj" # Caminho para o arquivo .obj
72+
path: "./cubo.obj" # Caminho para o arquivo .obj
7373
material: *material_cubo_metalico # Reutiliza o material metálico
7474
# Múltiplas transformações são aplicadas em ordem
7575
transform:

src/main.cpp renamed to demo/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
int main() {
55
try {
66
Prism::SceneParser("./data/input/scene.yml").parse().render();
7-
7+
88
} catch (const std::exception& e) {
99
Prism::Style::logError(e.what());
1010
return 1;

0 commit comments

Comments
 (0)