Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 97-feat-create-game-f…
Browse files Browse the repository at this point in the history
…older
  • Loading branch information
Peralban committed Oct 2, 2024
2 parents 7480fdd + c469b99 commit 4348918
Show file tree
Hide file tree
Showing 21 changed files with 660 additions and 102 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/checks.yml → .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
name: cmake
name: Linux
on: [check_run, pull_request]
jobs:
cmake-build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
cmake-build-linux:
runs-on: ubuntu-latest

steps:
- name: Checkout project
Expand All @@ -20,30 +15,18 @@ jobs:
key: vcpkg-cache-${{ runner.os }}

- name: Apt install for Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
- name: Install dependencies on Windows (vcpkg)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
if (-Not (Test-Path "vcpkg")) {
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
}
.\vcpkg\vcpkg install
- name: Install dependencies on Ubuntu (vcpkg)
if: matrix.os == 'ubuntu-latest'
run: |
if [ ! -d "vcpkg" ]; then
git clone https://github.com/microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh
fi
./vcpkg/vcpkg install
- name: Build project (Windows or Ubuntu)
- name: Build project
run: |
cmake -B build -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build/ --config Debug
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Windows
on: [check_run, pull_request]
jobs:
cmake-build-windows:
runs-on: windows-latest

steps:
- name: Checkout project
uses: actions/checkout@v4

- name: Cache vcpkg
uses: actions/cache@v4
with:
path: vcpkg
key: vcpkg-cache-${{ runner.os }}

- name: Install dependencies on Windows (vcpkg)
shell: pwsh
run: |
if (-Not (Test-Path "vcpkg")) {
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
}
.\vcpkg\vcpkg install
- name: Build project
run: |
cmake -B build -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build/ --config Debug
- name: Run tests
run: |
cd build/tests/
ctest -C Debug
42 changes: 25 additions & 17 deletions Engine/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game)
set(EXE_SRC_PATH "Src")
set(EXE_INCLUDE_PATH "Include")

set(COMPONENT_SRC_FILE ./Src/Components/ShaderComponent/ShaderPathComponent.cpp)
set(COMPONENT_SRC_FILE
./Src/Components/ShaderComponent/ShaderPathComponent.cpp
../Shared/Component/FontPathComponent.cpp
../Shared/Component/ObjPathComponent.cpp
../Shared/Component/TexturePathComponent.cpp
../Shared/Component/ScaleComponent.cpp
../Shared/Component/ColourComponent.cpp
../Shared/Component/Position3DComponent.cpp
../Shared/Component/Position2DComponent.cpp
../Shared/Component/Size1DComponent.cpp
../Shared/Component/TextComponent.cpp
../Shared/Component/MaterialMapComponent.cpp
../Shared/Component/MusicPathComponent.cpp
../Shared/Component/MusicPitchComponent.cpp
../Shared/Component/MusicVolumeComponent.cpp
../Shared/Component/SoundPathComponent.cpp
../Shared/Component/SoundPitchComponent.cpp
../Shared/Component/SoundVolumeComponent.cpp
)
set(SYSTEM_SRC_FILE
Src/Systems/DrawOBJ/DrawOBJSystem.cpp
)

set(COMPONENT_INCLUDE_DIR ./Include/Components/ShaderComponent)

Expand All @@ -17,24 +38,10 @@ set(SRC_EXE
Src/Application/Application.cpp
Src/ClientSceneManager/ClientSceneManager.cpp
Src/GraphicalLibrary/GetGraphicalLibrary.cpp

../Shared/SceneManager/ASceneManager.cpp
../Shared/Component/FontPathComponent.cpp
../Shared/Component/ObjPathComponent.cpp
../Shared/Component/TexturePathComponent.cpp
../Shared/Component/ScaleComponent.cpp
../Shared/Component/ColourComponent.cpp
../Shared/Component/Position3DComponent.cpp
../Shared/Component/Position2DComponent.cpp
../Shared/Component/Size1DComponent.cpp
../Shared/Component/TextComponent.cpp
../Shared/Component/MaterialMapComponent.cpp
../Shared/Component/MusicPathComponent.cpp
../Shared/Component/MusicPitchComponent.cpp
../Shared/Component/MusicVolumeComponent.cpp
../Shared/Component/SoundPathComponent.cpp
../Shared/Component/SoundPitchComponent.cpp
../Shared/Component/SoundVolumeComponent.cpp
${COMPONENT_SRC_FILE}
${SYSTEM_SRC_FILE}
)

include_directories(
Expand All @@ -43,6 +50,7 @@ include_directories(
Src/ClientSceneManager
Src/GraphicalLibrary
Src/Errors
Src/Systems
../Shared/GraphicalLoad
../Shared/Component
../Shared/Ecs/Src
Expand Down
12 changes: 12 additions & 0 deletions Engine/Client/Src/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ Application::Application()
_registries = std::make_shared<std::vector<ECS::Registry>>();
SceneManager::ClientSceneManager sceneManager(_registries);

_initDefaultGraphicSystems();

_client = std::make_shared<Network::Client>("127.0.0.1", 4444, 4445);
_client->connect([this](Network::UDPPacket packet) {
this->_packetHandler(std::move(packet));
});
}

void Application::_initDefaultGraphicSystems()
{
DrawOBJSystem drawOBJSystem;
_defaultSystems.push_back(drawOBJSystem.getFunction());
}

void Application::run()
{
std::shared_ptr<IGraphic> libGraphic = getGraphicalLibrary();
Expand All @@ -35,7 +43,11 @@ void Application::run()
libGraphic->init(WINDOW_TITLE);

while (libGraphic->windowIsOpen()) {
libGraphic->startDraw();
libGraphic->clear();
_registries->at(SceneManager::RegisterIndex::CURRENT).run_systems(-1);
for (auto defaultSystem : _defaultSystems)
defaultSystem(_registries->at(SceneManager::RegisterIndex::CURRENT), -1);
libGraphic->endDraw();
}
}
8 changes: 8 additions & 0 deletions Engine/Client/Src/Application/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Registry.hpp"
#include "NetworkClient.hpp"
#include "DrawOBJ/DrawOBJSystem.hpp"

#define WINDOW_TITLE "From noware"

Expand Down Expand Up @@ -49,6 +50,13 @@ class Application {
*/
void _packetHandler(Network::UDPPacket packet);

/**
* @brief Initialize default graphics systems.
*
*/
void _initDefaultGraphicSystems();

std::shared_ptr<std::vector<ECS::Registry>> _registries; // Registries for each scene.
std::shared_ptr<Network::Client> _client; // Network class for client.
std::vector<std::function<void(ECS::Registry& reg, int idxPacketEntities)>> _defaultSystems;
};
9 changes: 6 additions & 3 deletions Engine/Client/Src/ClientSceneManager/ClientSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ SceneManager::ClientSceneManager::ClientSceneManager(std::shared_ptr<std::vector
_loadScene(FIRST_SCENE, CURRENT);
}

std::string SceneManager::ClientSceneManager::_getComponentLibPath() const {
std::string SceneManager::ClientSceneManager::_getComponentLibPath() const
{
return LIB_COMPONENTS_PATH;
}

std::string SceneManager::ClientSceneManager::_getSystemLibPath() const {
std::string SceneManager::ClientSceneManager::_getSystemLibPath() const
{
return LIB_SYSTEMS_PATH;
}

std::string SceneManager::ClientSceneManager::_getScenesPath() const {
std::string SceneManager::ClientSceneManager::_getScenesPath() const
{
return SCENE_PATH;
}
54 changes: 54 additions & 0 deletions Engine/Client/Src/Systems/DrawOBJ/DrawOBJSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
** EPITECH PROJECT, 2024
** DrawOBJSystem
** File description:
** DrawOBJSystem
*/

#include "DrawOBJSystem.hpp"
#include "ObjPathComponent.hpp"
#include "Position3DComponent.hpp"
#include "ScaleComponent.hpp"
#include "GetGraphicalLibrary.hpp"
#include "SparseArray.hpp"

#include <exception>

DrawOBJSystem::DrawOBJSystem() :
ASystem("DrawOBJSystem")
{
}

void DrawOBJSystem::_drawOBJ(ECS::Registry& reg, int idxPacketEntities)
{
std::shared_ptr<IGraphic> libGraphic = getGraphicalLibrary();

ECS::SparseArray<IComponent> objPathComponents = reg.get_components<IComponent>("ObjPathComponent");
ECS::SparseArray<IComponent> position3DComponents = reg.get_components<IComponent>("Position3DComponent");
ECS::SparseArray<IComponent> scaleComponents = reg.get_components<IComponent>("ScaleComponent");

for (ECS::entity_t entity = 0; objPathComponents.size() >= entity + 1; entity++) {
std::shared_ptr<ObjPathComponent> obj = std::dynamic_pointer_cast<ObjPathComponent>(objPathComponents[entity]);

std::shared_ptr<Position3DComponent> pos = (position3DComponents.size() >= entity + 1) ?
std::dynamic_pointer_cast<Position3DComponent>(position3DComponents[entity]) : nullptr;

std::shared_ptr<ScaleComponent> scale = (scaleComponents.size() >= entity + 1) ?
std::dynamic_pointer_cast<ScaleComponent>(scaleComponents[entity]) : nullptr;

float modelScale;

if (!obj)
continue;
modelScale = (scale) ? scale->scale : 1.0;
if (pos)
libGraphic->drawOBJ(obj->path, pos->x, pos->y, pos->z, modelScale);
else
libGraphic->drawOBJ(obj->path, 0, 0, 0, modelScale);
}
}

extern "C" ISystem* loadSystemInstance()
{
return new DrawOBJSystem();
}
49 changes: 49 additions & 0 deletions Engine/Client/Src/Systems/DrawOBJ/DrawOBJSystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
** EPITECH PROJECT, 2024
** DrawOBJSystem
** File description:
** DrawOBJSystem
*/

#pragma once

#include <iostream>

#include "ISystem.hpp"

/**
* @brief System to draw an OBJ Model.
*
*/
class DrawOBJSystem : public ASystem {

public:

/**
* @brief Construct a new Draw OBJ System object.
*
*/
DrawOBJSystem();

/**
* @brief Destroy the Draw OBJ System object.
*
*/
~DrawOBJSystem() = default;

/**
* @brief Get the Function object.
*
* @return std::function<void(ECS::Registry& reg, int idxPacketEntities)>
*/
std::function<void(ECS::Registry& reg, int idxPacketEntities)> getFunction()
{
return [this](ECS::Registry& reg, int idxPacketEntities) {
_drawOBJ(reg, idxPacketEntities);
};
}

private:

void _drawOBJ(ECS::Registry& reg, int idxPacketEntities); //< Function to init the player.
};
16 changes: 16 additions & 0 deletions Engine/Shared/Ecs/Src/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ entity_t Registry::spawn_entity() {
return _next_entity++;
}

std::vector<entity_t> Registry::getEntities()
{
return _entities;
}

entity_t Registry::entity_from_index(std::size_t idx) {
if (idx < _entities.size())
return _entities[idx];
Expand All @@ -41,4 +46,15 @@ void Registry::run_systems(int idxPacketEntities) {
system(*this, idxPacketEntities);
}

void Registry::cloneComponentsArray(ECS::Registry &registry)
{
setComponentsArrays(registry._components_arrays, registry._remove_functions);
}

void Registry::setComponentsArrays(std::unordered_map <std::string, std::any> componentsArrays, std::unordered_map <std::string, remove_func_t> removeFunctions)
{
_components_arrays = componentsArrays;
_remove_functions = removeFunctions;
}

} // namespace ECS
Loading

0 comments on commit 4348918

Please sign in to comment.