Skip to content

Commit

Permalink
feat: common utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Mar 7, 2024
1 parent 96ab0d9 commit a42d48f
Show file tree
Hide file tree
Showing 24 changed files with 290 additions and 96 deletions.
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
*.cmake
generator/Makefile
engine/Makefile
common/Makefile
generator/CMakeCache.txt
engine/CMakeCache.txt
common/CMakeCache.txt
generator/CMakeFiles/*
engine/CMakeFiles/*
common/CMakeFiles/*
.idea/*
.vscode/*
generator/generator
engine/engine
common/common
build
CMakeCache.txt
compile_commands.json
CMakeFiles/*
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj
*.bin


# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

.vscode
build
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.5)

# Project Name
project(cg)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(OpenGL_GL_PREFERENCE "GLVND")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")

add_subdirectory(common)
add_subdirectory(generator)
add_subdirectory(engine)
target_include_directories(common PUBLIC common/include)
target_include_directories(generator PUBLIC generator/include)
target_include_directories(engine PUBLIC engine/include)
182 changes: 182 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.28

# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:

# Disable VCS-based implicit rules.
% : %,v

# Disable VCS-based implicit rules.
% : RCS/%

# Disable VCS-based implicit rules.
% : RCS/%,v

# Disable VCS-based implicit rules.
% : SCCS/s.%

# Disable VCS-based implicit rules.
% : s.%

.SUFFIXES: .hpux_make_needs_suffix_list

# Command-line flag to silence nested $(MAKE).
$(VERBOSE)MAKESILENT = -s

#Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E rm -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/mario/CG-Project

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/mario/CG-Project

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake cache editor..."
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/mario/CG-Project/CMakeFiles /home/mario/CG-Project//CMakeFiles/progress.marks
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/mario/CG-Project/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean
.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named common

# Build rule for target.
common: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 common
.PHONY : common

# fast build rule for target.
common/fast:
$(MAKE) $(MAKESILENT) -f common/CMakeFiles/common.dir/build.make common/CMakeFiles/common.dir/build
.PHONY : common/fast

#=============================================================================
# Target rules for targets named generator

# Build rule for target.
generator: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 generator
.PHONY : generator

# fast build rule for target.
generator/fast:
$(MAKE) $(MAKESILENT) -f generator/CMakeFiles/generator.dir/build.make generator/CMakeFiles/generator.dir/build
.PHONY : generator/fast

#=============================================================================
# Target rules for targets named engine

# Build rule for target.
engine: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 engine
.PHONY : engine

# fast build rule for target.
engine/fast:
$(MAKE) $(MAKESILENT) -f engine/CMakeFiles/engine.dir/build.make engine/CMakeFiles/engine.dir/build
.PHONY : engine/fast

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... common"
@echo "... engine"
@echo "... generator"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

9 changes: 9 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.5)

# Project Name
project(common)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

file(GLOB SRC_FILES src/*.cpp)
add_library(${PROJECT_NAME} ${SRC_FILES})
1 change: 1 addition & 0 deletions engine/include/utils.hpp → common/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ typedef struct Point {

// Function to convert Point to string
std::vector<Point> parseFile(std::string filename);
void saveToFile(const std::vector<Point>& points, const char* filepath);

#endif // UTILS_HPP
19 changes: 18 additions & 1 deletion generator/src/utils.cpp → common/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "utils.hpp"
#include "../include/utils.hpp"

#include <fstream>
#include <iostream>
Expand All @@ -8,6 +8,23 @@

#define DIR "../models/"

std::vector<Point> parseFile(std::string filename) {
std::vector<Point> points;
std::ifstream file(filename);

if (!file.is_open()) {
std::cerr << "Error: Unable to open file " << filename << std::endl;
return points;
}

Point point;
while (file >> point.x >> point.y >> point.z) {
points.push_back(point);
}
file.close();
return points;
}

void saveToFile(
const std::vector<Point>& points,
const char* filepath) { // Changed parameter type to const char*
Expand Down
6 changes: 2 additions & 4 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ cmake_minimum_required(VERSION 3.5)
# Project Name
project(engine)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

file(GLOB SRC_FILES src/scene/*.cpp src/*.cpp)
file(GLOB SRC_FILES src/*.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})

include_directories(${PROJECT_NAME} PUBLIC include)
include_directories(../common PUBLIC include)
target_link_libraries(${PROJECT_NAME} common)

find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion engine/include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <string>

#include "../../common/include/utils.hpp"
#include "Camera.hpp"
#include "utils.hpp"

class Camera {
public:
Expand Down
2 changes: 1 addition & 1 deletion engine/include/draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include <vector>

#include "../../common/include/utils.hpp"
#include "draw.hpp"
#include "utils.hpp"

void drawTriangles(const std::vector<Point>& points);

Expand Down
2 changes: 1 addition & 1 deletion engine/src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <vector>

#include "../../common/include/utils.hpp"
#include "draw.hpp"
#include "utils.hpp"

#define MODELS "../models/"

Expand Down
24 changes: 0 additions & 24 deletions engine/src/utils.cpp

This file was deleted.

6 changes: 2 additions & 4 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ cmake_minimum_required(VERSION 3.5)
# Project Name
project(generator)

# Include directories
include_directories(${PROJECT_NAME} PUBLIC include) # Assuming headers are in the 'include' directory

file(GLOB SRC_FILES src/shapes/*.cpp src/*.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})


include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} common)
2 changes: 1 addition & 1 deletion generator/include/shapes/cone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <iostream>
#include <vector>

#include "../utils.hpp"
#include "../../common/include/utils.hpp"

bool generateCone(float radius, float height, int slices, int stacks,
const char* filepath);
Expand Down
Loading

0 comments on commit a42d48f

Please sign in to comment.