Skip to content
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CMake

on:
push:
branches: [ "master" ]
branches: [ "develop", "master" ]
pull_request:
branches: [ "master" ]
branches: [ "develop", "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -15,7 +15,7 @@ jobs:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/out/build/x64-Debug
/ThirdParty
/CMakeSettings.json
/Bin
25 changes: 11 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(HEADERS
source/ResourceManagement/ResourceCache.hpp
source/ResourceManagement/ResourceContainers.hpp
source/ResourceManagement/ResourceHandle.hpp
source/Systems/GuiSystem.hpp
source/Systems/MovementSystem.hpp
source/Systems/RenderSystem.hpp
source/Systems/System.hpp
Expand All @@ -47,6 +48,7 @@ set(SRCS
source/ResourceManagement/ResourceHandle.cpp
source/ResourceManagement/ResourceCache.cpp
source/ResourceManagement/ResourceContainers.cpp
source/Systems/GuiSystem.cpp
)

# Project Structure
Expand Down Expand Up @@ -78,7 +80,7 @@ FetchContent_Declare(
FetchContent_Declare(
imgui
GIT_REPOSITORY "https://github.com/ocornut/imgui.git"
GIT_TAG "docking"
GIT_TAG "v1.89"
)

# SpdLog, Header only fast C++ logging
Expand All @@ -94,20 +96,13 @@ FetchContent_Declare(ziplib

FetchContent_MakeAvailable(sfml imgui spdlog ziplib)

# ImGUI, handles GUI rendering for the whole project
FetchContent_Declare(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
)

FetchContent_MakeAvailable(imgui)

# ImGUI SFML, Temporary binding support to allow ImGUI to work through SFML. Will be replacing this in the future since it doesn't support multi viewports/docking and isn't being updated.
FetchContent_Declare(imgui-sfml
GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml.git
GIT_REPOSITORY https://github.com/SFML/imgui-sfml.git
GIT_TAG "2.6.x"
)
set(IMGUI_DIR ${imgui_SOURCE_DIR})
option(IMGUI_SFML_FIND_SFML "Use find_package to find SFML" OFF)

FetchContent_MakeAvailable(imgui-sfml)


Expand Down Expand Up @@ -141,14 +136,16 @@ include_directories(
########################################

# Copy SFML dlls into our build directory (Debug only atm)
# TODO: Add configuration subfolders and also automatically ZIP up the assets folder and put it
# in the correct build folder.
add_custom_command(
TARGET TestEngine POST_BUILD

COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/ThirdParty/sfml-build/lib/$<CONFIGURATION>/"
"${PROJECT_SOURCE_DIR}/bin/$<CONFIGURATION>/"
"${PROJECT_SOURCE_DIR}/ThirdParty/sfml-build/lib/"
"${PROJECT_SOURCE_DIR}/bin/"

COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/ThirdParty/imgui-sfml-build/$<CONFIGURATION>/"
"${PROJECT_SOURCE_DIR}/bin/$<CONFIGURATION>/"
"${PROJECT_SOURCE_DIR}/ThirdParty/imgui-sfml-build/"
"${PROJECT_SOURCE_DIR}/bin/"
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TestingGrounds
A hobby 2D/3D Game Engine that I have been working on in my free time, though lately haven't had as much time as I would like.
55 changes: 19 additions & 36 deletions source/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,43 @@
#include <SFML/Window/WindowStyle.hpp>
#include <SFML/System/Clock.hpp>

#include <imgui-SFML.h>
#include <imgui.h>
#include <imgui-SFML.h>

#include "Application.hpp"
#include "Entity/Entity.hpp"

#include "Systems/SystemManager.hpp"
#include "Systems/RenderSystem.hpp"
#include "Systems/MovementSystem.hpp"
#include "Systems/GuiSystem.hpp"

#include "Components/TransformableComponent.hpp"
#include "Components/RenderableComponent.hpp"
#include "Components/MovementComponent.hpp"
#include "Components/SteeringComponent.hpp"
#include "Components/SteeringComponent.hpp"

#include "EventManagement/EventManager.hpp"
#include "Entity/EntityManager.hpp"
#include "ResourceManagement/ResourceCache.hpp"
#include "ResourceManagement/ResourceContainers.hpp"
#include "ResourceManagement/ResourceHandle.hpp"
#include "Systems/SystemManager.hpp"

const sf::Time Application::timePerFrame = sf::seconds(1.0f / 60.0f);

Application::Application()
: window(sf::VideoMode(1920, 1080), "Testing Grounds", sf::Style::Close)
, resourceCache(std::make_unique<ResourceCache>(10, new ZipResourceContainer("Assets.zip"))) // Cache will take ownership
, eventManager(std::make_unique<EventManager>())
, entityManager(std::make_unique<EntityManager>(*eventManager))
, systemManager(std::make_unique<SystemManager>(*entityManager, *eventManager))
, resourceCache(std::make_unique<ResourceCache>(10, new ZipResourceContainer("Assets.zip")))
{
// TODO: Move all this initialization outside of the constructor, it's limiting how errors can be handled.

// Initialize the resource cache
if (!resourceCache->Initialize())
{
// TODO: Move all this initialization outside of the constructor, it's limiting how errors can be handled.

}

// Initialize ImGUI windowing
Expand All @@ -55,15 +57,14 @@ Application::Application()
// Entities represent primarily just a unique ID and that is it.
// All components are housed in their own separate memory pools
// (Based on component families) inside of EntityManager.
Entity aiEntity = entityManager->createEntity();
Entity playerEntity = entityManager->createEntity();
aiEntity = entityManager->createEntity();

// Test 1: Resource Loading - Able to successfully load a png sprite image from our zip file?

// NOTE: This is very sloppy and is wasting RAM by having to load the asset into memory with the cache and resource handle, then copy that same data over into a
// sf::Texture which we then carry around in places like RenderableComponent. Though I am planning to ditch using SFML for rendering in the near future and will have to rewrite all
// rendering code to use pure OpenGL, DirectX or maybe even Vulkan. So will leave it as it is right now.
auto testSpriteHandle = resourceCache->GetResourceHandle("Textures/TestSprite.png");
auto testSpriteHandle = resourceCache->GetResourceHandle("Assets/Textures/TestSprite.png");
sf::Texture testSpriteTexture;
testSpriteTexture.loadFromMemory(testSpriteHandle->GetBuffer(), testSpriteHandle->GetSize());

Expand All @@ -80,16 +81,8 @@ Application::Application()
// Test 3.1: Basic AI (Entity Steering) - Adding the Steering component will use steering behaviors to move an entity around with dynamic movement?
ComponentPtr<SteeringComponent> steering = entityManager->assignComponent<SteeringComponent>(aiEntity.id());
steering->behaviorFlags |= BehaviorType::Arrive;
steering->arrivePosition = sf::Vector2f(400, 400);
steering->arriveDeceleration = SteeringComponent::Deceleration::Normal;


// Feature TODO: Setup GUI for the engine using ImGui, though since there isn't a supported backend for sfml this will require
// either 1) Writing a new SFML backend for ImGUI that uses both SFML rendering and windowing 2) Switching rendering from SFML to OpenGL
// and use the ImGUI OpenGL backend. #1 isn't ideal since it would require constantly keeping our code synced and updated whenever new changes
// roll out. Whereas if we go with #2 we can piggyback on the ImGUI implementation that they keep up to date and only have to interface it with
// SFML windowing which shouldn't require maintence since we can hook into the opengl render target directly.

//=============================================================
// END Testing Code / Feature Demoing
//=============================================================
Expand All @@ -109,14 +102,13 @@ void Application::runApplication()

while (window.isOpen())
{
//ImGui::NewFrame();
ImGui::NewFrame();

const sf::Time deltaTime = clock.restart();
timeSinceLastUpdate += deltaTime;

while (timeSinceLastUpdate >= timePerFrame)
{
//ImGui::EndFrame();
processSFMLEvents();
updateFrame(timePerFrame);

Expand All @@ -129,8 +121,9 @@ void Application::runApplication()

void Application::setupSystems()
{
systemManager->addSystem<RenderSystem>(window);
systemManager->addSystem<RenderSystem>(&window);
systemManager->addSystem<MovementSystem>();
systemManager->addSystem<GuiSystem>(&window);

systemManager->configure();
}
Expand All @@ -141,7 +134,7 @@ void Application::processSFMLEvents()
while (window.pollEvent(sfmlEvent))
{
// The GUI get's first crack at the events
ImGui::SFML::ProcessEvent(sfmlEvent);
ImGui::SFML::ProcessEvent(window, sfmlEvent);

switch (sfmlEvent.type)
{
Expand All @@ -161,28 +154,18 @@ void Application::processSFMLEvents()

void Application::updateFrame(const sf::Time& deltaTime)
{
// TODO: Remove Testing Code
mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
entityManager->getComponent<SteeringComponent>(aiEntity.id())->arrivePosition = mousePosition;

systemManager->updateAllSystems(deltaTime);
}

void Application::renderFrame(const sf::Time& deltaTime)
{
// TODO: GUI isn't working, has to deal with updating and rendering being separated and running at different timesteps.
// Might just move all GUI updating and rending to live strictly on the rendering side, though this is cheap fix and will cause problems
// if we multi-thread in the future.
ImGui::SFML::Update(window, deltaTime);

// TODO: Remove all this is just testing code
ImGui::Begin("Testing ImGUI"); // begin window
if (ImGui::ColorEdit3("Background color", color))
{
bgColor.r = static_cast<sf::Uint8>(color[0] * 255.f);
bgColor.g = static_cast<sf::Uint8>(color[1] * 255.f);
bgColor.b = static_cast<sf::Uint8>(color[2] * 255.f);
}
ImGui::End(); // end window

window.clear(bgColor);
systemManager->getSystem<RenderSystem>()->render(*entityManager);
ImGui::SFML::Render(window);
systemManager->getSystem<RenderSystem>()->Render(*entityManager);
systemManager->getSystem<GuiSystem>()->Render(*entityManager, *eventManager);
window.display();
}
16 changes: 9 additions & 7 deletions source/Application/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <SFML/System/NonCopyable.hpp>
#include <SFML/Graphics/RenderWindow.hpp>

#include "Entity/Entity.hpp"

class ResourceCache;
class EventManager;
class EntityManager;
Expand All @@ -18,7 +20,8 @@ class Application : private sf::NonCopyable
void operator=(const Application&) = delete;

void runApplication();
const sf::RenderWindow& getWindow() const { return window; }

sf::RenderWindow* GetWindow() { return &window; }

private:
Application();
Expand All @@ -31,18 +34,17 @@ class Application : private sf::NonCopyable

private:
static const sf::Time timePerFrame;

sf::RenderWindow window;

// TODO: Remove this later it's testing code
float color[3] = {0, 0, 0};
sf::Color bgColor;

std::unique_ptr<ResourceCache> resourceCache;

// Do not change the ordering of these
// will mess up the constructor if you do.
std::unique_ptr<EventManager> eventManager;
std::unique_ptr<EntityManager> entityManager;
std::unique_ptr<SystemManager> systemManager;
std::unique_ptr<ResourceCache> resourceCache;

// Testing code
Entity aiEntity;
sf::Vector2f mousePosition;
};
36 changes: 36 additions & 0 deletions source/Systems/GuiSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "GuiSystem.hpp"

#include <imgui-SFML.h>
#include <imgui.h>
#include <SFML/Graphics/RenderWindow.hpp>


GuiSystem::GuiSystem(sf::RenderTarget* target)
: renderTarget(target)
{

}

void GuiSystem::Configure(EventManager& eventManager)
{
}

void GuiSystem::Update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime)
{
ImGui::SFML::Update(*dynamic_cast<sf::RenderWindow*>(renderTarget), deltaTime);
}

void GuiSystem::Render(EntityManager& entityManager, EventManager& eventManager)
{
// This is all just testing code for IMGUI and AI Steering Behaviors
ImGui::Begin("Testing ImGUI"); // begin window

const char* steeringOptions[4] = {"None", "Seek", "Flee", "Arrive"};
static int steeringIndex = 0;
ImGui::Combo("AI Steering Behavior", &steeringIndex, steeringOptions, IM_ARRAYSIZE(steeringOptions));

ImGui::ShowStackToolWindow();

ImGui::End();
ImGui::SFML::Render(*renderTarget);
}
23 changes: 23 additions & 0 deletions source/Systems/GuiSystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "System.hpp"

namespace sf
{
class RenderTarget;
}

class GuiSystem : public System<GuiSystem>
{
public:
explicit GuiSystem(sf::RenderTarget* target);

void Configure(EventManager& eventManager) override;
void Update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime) override;
void Render(EntityManager& entityManager, EventManager& eventManager);

void SetRenderTarget(sf::RenderTarget* newRenderTarget) { renderTarget = newRenderTarget; }

private:
sf::RenderTarget* renderTarget;
};
4 changes: 2 additions & 2 deletions source/Systems/MovementSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "Components/TransformableComponent.hpp"
#include "Components/MovementComponent.hpp"

void MovementSystem::configure(EventManager& eventManager)
void MovementSystem::Configure(EventManager& eventManager)
{}

void MovementSystem::update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime)
void MovementSystem::Update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime)
{
ComponentPtr<MovementComponent> movementComp;
ComponentPtr<TransformableComponent> transComp;
Expand Down
4 changes: 2 additions & 2 deletions source/Systems/MovementSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MovementSystem : public System<MovementSystem>
MovementSystem() = default;

// System overrides
void configure(EventManager& eventManager) override;
void update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime) override;
void Configure(EventManager& eventManager) override;
void Update(EntityManager& entityManager, EventManager& eventManager, const sf::Time& deltaTime) override;

private:
// Steering Functionality
Expand Down
Loading