Skip to content

Commit

Permalink
[#98]: Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Jul 11, 2023
2 parents 70ad8cd + 83ac1a9 commit d6e4052
Show file tree
Hide file tree
Showing 65 changed files with 3,116 additions and 1,302 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Looper is a game engine with an integrated editor and a 2D type game with a level editor, all written in modern C++20. It uses Vulkan for rendering and ImGui/glfw3 for UI and window/input handling. The project is compatible with Ubuntu and Windows.


[![Watch the video](https://i.imgur.com/BpkWCSF.png)](https://www.youtube.com/watch?v=cyZFLKrvoPc)
[![Watch the video](https://raw.githubusercontent.com/wiki/JacobDomagala/Looper/Looper_github.gif)](https://www.youtube.com/watch?v=Qh-vOKMPQGQ)

## Requirements
- C++20 compatible compiler (e.g. GCC, Clang, MSVC)
Expand Down
Binary file added assets/fonts/fa-regular-400.ttf
Binary file not shown.
Binary file added assets/fonts/fa-solid-900.ttf
Binary file not shown.
Binary file modified assets/images/Level1_Char.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_129.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_183.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_186.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_213.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_71.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_97.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_98.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/tile_99.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/womanGreen_machine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/levels/DummyLevelName.dgl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/levels/MediumLevel.dgl

Large diffs are not rendered by default.

175 changes: 93 additions & 82 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "renderer/window/window.hpp"
#include "utils/file_manager.hpp"
#include "utils/time/stopwatch.hpp"
#include "utils/time/scoped_timer.hpp"

#include <GLFW/glfw3.h>
#include <glm/gtc/matrix_transform.hpp>
Expand All @@ -33,8 +34,6 @@ Editor::Editor(const glm::ivec2& screenSize) : gui_(*this)
renderer::VulkanRenderer::Initialize(m_window->GetWindowHandle(),
renderer::ApplicationType::EDITOR);
gui_.Init();

m_deltaTime = Timer::milliseconds(static_cast< long >(TARGET_TIME * 1000.0f));
}

void
Expand All @@ -46,9 +45,6 @@ Editor::ShowCursor(bool choice)
void
Editor::HandleCamera()
{
m_timer.ToggleTimer();
m_deltaTime = m_timer.GetMsDeltaTime();

auto cameraMoveBy = glm::vec2();

if (!EditorGUI::IsBlockingEvents() && m_levelLoaded)
Expand Down Expand Up @@ -224,7 +220,7 @@ Editor::HandleMouseDrag(const glm::vec2& currentCursorPos, const glm::vec2& axis
{
m_currentSelectedGameObject->Move(m_camera.ConvertToCameraVector(moveBy));
m_currentSelectedGameObject->GetSprite().SetInitialPosition(
m_currentSelectedGameObject->GetPosition());
m_currentSelectedGameObject->GetSprite().GetPosition());
gui_.ObjectUpdated(m_currentSelectedGameObject->GetID());
auto animatable = std::dynamic_pointer_cast< Animatable >(m_currentSelectedGameObject);
if (animatable)
Expand Down Expand Up @@ -332,6 +328,19 @@ Editor::HandleObjectSelected(Object::ID objectID, bool fromGUI)
}
}

Object::ID
Editor::GetSelectedEditorObject() const
{
Object::ID selected = Object::INVALID_ID;

if (m_currentEditorObjectSelected)
{
selected = m_currentEditorObjectSelected->GetLinkedObjectID();
}

return selected;
}

void
Editor::SelectGameObject()
{
Expand Down Expand Up @@ -449,9 +458,6 @@ Editor::SetupRendererData()
renderer::VulkanRenderer::CreateLinePipeline();
renderer::VulkanRenderer::SetupLineData();
renderer::VulkanRenderer::UpdateLineData();

renderer::VulkanRenderer::SetupEditorData(ObjectType::PATHFINDER_NODE);
renderer::VulkanRenderer::SetupEditorData(ObjectType::ANIMATION_POINT);
}

void
Expand All @@ -476,21 +482,17 @@ Editor::ActionOnObject(Editor::ACTION action)
if (m_editorObjectSelected && m_currentEditorObjectSelected)
{
gui_.ObjectDeleted(m_currentEditorObjectSelected->GetLinkedObjectID());
m_editorObjects.erase(std::find(m_editorObjects.begin(), m_editorObjects.end(),
m_currentEditorObjectSelected));
if (Object::GetTypeFromID(m_currentEditorObjectSelected->GetLinkedObjectID())
== ObjectType::ANIMATION_POINT)
{
animationPoints_.erase(stl::find(animationPoints_, m_currentEditorObjectSelected));
}
m_currentEditorObjectSelected->DeleteLinkedObject();
UnselectEditorObject();
}
else if (m_gameObjectSelected && m_currentSelectedGameObject)
{
if (m_currentSelectedGameObject->GetType() == ObjectType::PLAYER)
{
m_player.reset();
}
else
{
m_currentLevel->DeleteObject(m_currentSelectedGameObject->GetID());
}
m_currentLevel->DeleteObject(m_currentSelectedGameObject->GetID());

gui_.ObjectDeleted(m_currentSelectedGameObject->GetID());

Expand Down Expand Up @@ -518,14 +520,9 @@ Editor::Render(VkCommandBuffer cmdBuffer)
vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderData.pipeline);

auto offsets = std::to_array< const VkDeviceSize >({0});
vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderData.vertexBuffer, offsets.data());

vkCmdBindIndexBuffer(cmdBuffer, renderData.indexBuffer, 0, VK_INDEX_TYPE_UINT32);

vkCmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderData.pipelineLayout,
0, 1, &renderData.descriptorSets[renderer::Data::currentFrame_], 0,
nullptr);

renderer::QuadShader::PushConstants pushConstants = {};
pushConstants.selectedIdx = -1.0f;

Expand All @@ -538,57 +535,36 @@ Editor::Render(VkCommandBuffer cmdBuffer)
vkCmdPushConstants(cmdBuffer, renderData.pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(renderer::QuadShader::PushConstants), &pushConstants);

const auto numObjects =
renderData.numMeshes - renderer::EditorData::numNodes_ - renderer::EditorData::numPoints_;
vkCmdDrawIndexed(cmdBuffer, numObjects * renderer::INDICES_PER_SPRITE, 1, 0, 0, 0);

if (m_currentSelectedGameObject)
for (int32_t layer = renderer::NUM_LAYERS - 1; layer >= 0; --layer)
{
const auto tmpIdx = m_currentSelectedGameObject->GetSprite().GetRenderIdx();
pushConstants.selectedIdx = -1.0f;
vkCmdPushConstants(cmdBuffer, renderData.pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(renderer::QuadShader::PushConstants), &pushConstants);
vkCmdDrawIndexed(cmdBuffer, 6, 1, tmpIdx * 6, 0, 0);
}
const auto idx = static_cast< size_t >(layer);
const auto& numObjects = renderData.numMeshes.at(idx);
if (numObjects == 0
or (idx == 9 and not m_renderPathfinderNodes) /* layer 9 means pathfinder nodes*/)
{
continue;
}

// DRAW PATHFINDER NODES
if (m_renderPathfinderNodes)
{
vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderer::EditorData::pathfinderVertexBuffer,
offsets.data());
vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderData.vertexBuffer.at(idx), offsets.data());

vkCmdBindIndexBuffer(cmdBuffer, renderer::EditorData::pathfinderIndexBuffer, 0,
VK_INDEX_TYPE_UINT32);
vkCmdBindIndexBuffer(cmdBuffer, renderData.indexBuffer.at(idx), 0, VK_INDEX_TYPE_UINT32);

vkCmdDrawIndexed(cmdBuffer, renderer::EditorData::numNodes_ * renderer::INDICES_PER_SPRITE,
1, 0, 0, 0);
vkCmdDrawIndexed(cmdBuffer, numObjects * renderer::INDICES_PER_SPRITE, 1, 0, 0, 0);
}


if (renderer::EditorData::numPoints_)
{
// DRAW ANIMATION POINTS
vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderer::EditorData::animationVertexBuffer,
offsets.data());

vkCmdBindIndexBuffer(cmdBuffer, renderer::EditorData::animationIndexBuffer, 0,
VK_INDEX_TYPE_UINT32);

vkCmdDrawIndexed(
cmdBuffer, renderer::EditorData::numPoints_ * renderer::INDICES_PER_SPRITE, 1, 0, 0, 0);
}


// DRAW LINES
vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderer::EditorData::linePipeline_);
vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
renderer::EditorData::linePipeline_);

vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderer::EditorData::lineVertexBuffer, offsets.data());
vkCmdBindVertexBuffers(cmdBuffer, 0, 1, &renderer::EditorData::lineVertexBuffer,
offsets.data());

vkCmdBindIndexBuffer(cmdBuffer, renderer::EditorData::lineIndexBuffer, 0, VK_INDEX_TYPE_UINT32);
vkCmdBindIndexBuffer(cmdBuffer, renderer::EditorData::lineIndexBuffer, 0,
VK_INDEX_TYPE_UINT32);

vkCmdBindDescriptorSets(
cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderer::EditorData::linePipelineLayout_, 0, 1,
&renderer::EditorData::lineDescriptorSets_[renderer::Data::currentFrame_], 0, nullptr);
cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderer::EditorData::linePipelineLayout_, 0,
1, &renderer::EditorData::lineDescriptorSets_[renderer::Data::currentFrame_], 0, nullptr);

renderer::LineShader::PushConstants linePushConstants = {};
linePushConstants.color = glm::vec4(0.4f, 0.5f, 0.6f, static_cast< float >(m_drawGrid));
Expand All @@ -598,8 +574,7 @@ Editor::Render(VkCommandBuffer cmdBuffer)
sizeof(renderer::LineShader::PushConstants), &linePushConstants);

vkCmdDrawIndexed(cmdBuffer, renderer::EditorData::numGridLines * renderer::INDICES_PER_LINE,
1, 0,
0, 0);
1, 0, 0, 0);

linePushConstants.color = glm::vec4(0.5f, 0.8f, 0.8f, 1.0f);
vkCmdPushConstants(cmdBuffer, renderer::EditorData::linePipelineLayout_,
Expand Down Expand Up @@ -731,11 +706,23 @@ Editor::GetGridData() const
}

time::TimeStep
Editor::GetRenderTime() const
Editor::GetFrameTime() const
{
return timeLastFrame_;
}

time::TimeStep
Editor::GetUpdateUITime() const
{
return uiTime_;
}

time::TimeStep
Editor::GetRenderTime() const
{
return renderTime_;
}

std::pair< uint32_t, uint32_t >
Editor::GetRenderOffsets() const
{
Expand All @@ -751,7 +738,7 @@ Editor::SetupPathfinderNodes()
const auto tileSize = m_currentLevel->GetTileSize();

auto pathfinderNode = std::make_shared< EditorObject >(
*this, node.m_position, glm::ivec2(tileSize, tileSize), "white.png", node.GetID());
*this, node.position_, glm::ivec2(tileSize, tileSize), "white.png", node.GetID());

pathfinderNode->Render();

Expand Down Expand Up @@ -885,7 +872,8 @@ Editor::AddObject(ObjectType objectType)
animationPoints_.push_back(newObject);
animatablePtr->ResetAnimation();

renderer::VulkanRenderer::SetupEditorData(ObjectType::ANIMATION_POINT);
renderer::VulkanRenderer::UpdateBuffers();
renderer::VulkanRenderer::CreateLinePipeline();
}

HandleEditorObjectSelected(newObject);
Expand Down Expand Up @@ -1018,14 +1006,17 @@ Editor::Update()
}
}

gui_.UpdateUI();

auto& renderData =
renderer::Data::renderData_.at(renderer::VulkanRenderer::GetCurrentlyBoundType());
renderData.viewMat = m_camera.GetViewMatrix();
renderData.projMat = m_camera.GetProjectionMatrix();

DrawBoundingBoxes();

{
const time::ScopedTimer uiTImer(&uiTime_);
gui_.UpdateUI();
}
}

void
Expand Down Expand Up @@ -1072,28 +1063,48 @@ Editor::IsRunning() const
void
Editor::MainLoop()
{
auto singleFrameTimer = time::microseconds(0);
time::Stopwatch watch;
while (IsRunning())
{
watch.Start();
m_timer.ToggleTimer();
singleFrameTimer += m_timer.GetMicroDeltaTime();

InputManager::PollEvents();
while (IsRunning() and (singleFrameTimer.count() >= TARGET_TIME_MICRO))
{
{
const time::ScopedTimer frameTimer(&timeLastFrame_);
InputManager::PollEvents();

Update();

renderer::VulkanRenderer::Render(this);
{
const time::ScopedTimer renderTimer(&renderTime_);
renderer::VulkanRenderer::Render(this);
}
}

timeLastFrame_ = watch.Stop();
if (m_frameTimer > 1.0f)
{
m_framesLastSecond = m_frames;
m_frameTimer = 0.0f;
m_frames = 0;
}

renderer::EditorData::curDynLineIdx = 0;
if (m_levelLoaded and m_currentLevel->GetPathfinder().IsInitialized())
{
m_currentLevel->GetPathfinder().ClearPerFrameData();
}
++m_frames;
m_frameTimer += TARGET_TIME_S;

if (m_playGame)
{
LaunchGameLoop();
renderer::EditorData::curDynLineIdx = 0;
if (m_levelLoaded and m_currentLevel->GetPathfinder().IsInitialized())
{
m_currentLevel->GetPathfinder().ClearPerFrameData();
}

if (m_playGame)
{
LaunchGameLoop();
}
}
}
}
Expand Down
Loading

0 comments on commit d6e4052

Please sign in to comment.