Skip to content

Commit

Permalink
Merge pull request #193 from JacobDomagala/172-v004-release
Browse files Browse the repository at this point in the history
[#172]: `v0.0.4` release
  • Loading branch information
JacobDomagala authored Feb 9, 2024
2 parents 1118bc0 + eb17a05 commit 8a799d5
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 236 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Looper
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.

![gif](https://raw.githubusercontent.com/wiki/JacobDomagala/Looper/Looper_github.gif)
![gif](https://raw.githubusercontent.com/wiki/JacobDomagala/Looper/gizmo.gif)
![gif](https://raw.githubusercontent.com/wiki/JacobDomagala/Looper/animation.gif)

## Requirements
- C++20 compatible compiler (e.g. GCC, Clang, MSVC)
Expand Down
119 changes: 81 additions & 38 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Editor::KeyCallback(KeyEvent& event)
{
ActionOnObject(action, currentSelectedEditorObject_);
}
else if (currentSelectedGameObject_ != Object::INVALID_ID)
{
ActionOnObject(action, currentSelectedGameObject_);
}
else
{
for (auto it = selectedObjects_.begin(); it < selectedObjects_.end();)
Expand Down Expand Up @@ -199,6 +203,12 @@ Editor::MouseButtonCallback(MouseButtonEvent& event)
gizmo_.Update((min + max) / 2.0f, selectedObjects_.size() == 1
? firstObject.GetSprite().GetRotation()
: 0.0f);

// If we only selected single object, make it as main selected one
if (selectedObjects_.size() == 1)
{
SelectGameObject(selectedObjects_.front());
}
}
selectStartPos_ = glm::vec2{};
selectRect_ = std::array< glm::vec2, 4 >{};
Expand Down Expand Up @@ -304,6 +314,8 @@ Editor::MoveLogic(const glm::vec2& axis)

selectedGameObject.Move(camera_.ConvertToCameraVector(moveBy));
gui_.ObjectUpdated(currentSelectedGameObject_);

UpdateAnimationData(currentSelectedGameObject_);
}
else
{
Expand All @@ -317,12 +329,7 @@ Editor::MoveLogic(const glm::vec2& axis)

gui_.ObjectUpdated(object);

auto* animatable = dynamic_cast< Animatable* >(&baseObject);
if (animatable)
{
animatable->SetAnimationStartLocation(gameObject.GetPosition());
UpdateAnimationData(object);
}
UpdateAnimationData(object);
}
}

Expand Down Expand Up @@ -455,6 +462,11 @@ Editor::SetMouseOnObject()
void
Editor::HandleGameObjectClicked(Object::ID newSelectedGameObject, bool groupSelect, bool fromGUI)
{
if (currentSelectedEditorObject_ != Object::INVALID_ID)
{
UnselectEditorObject(currentSelectedEditorObject_);
}

const auto objectAlreadySelected =
stl::find(selectedObjects_, newSelectedGameObject) != selectedObjects_.end();
const auto mainSelectedObject = currentSelectedGameObject_ == newSelectedGameObject;
Expand Down Expand Up @@ -562,7 +574,7 @@ Editor::SelectGameObject(Object::ID newSelectedGameObject)

// Make sure to render animation points if needed
auto& gameObject = currentLevel_->GetGameObjectRef(newSelectedGameObject);
gameObject.SetColor({0.4f, 0.0f, 0.0f, 0.8f});
gameObject.SetColor({0.6f, 0.0f, 0.0f, 0.8f});
const auto* animatable = dynamic_cast< Animatable* >(&gameObject);

if (animatable and animatable->GetRenderAnimationSteps())
Expand Down Expand Up @@ -629,6 +641,7 @@ void
Editor::UnselectGameObject(Object::ID object, bool groupSelect)
{
movementOnGameObject_ = false;
animateGameObject_ = false;

gui_.ObjectUnselected(object);

Expand All @@ -643,6 +656,12 @@ Editor::UnselectGameObject(Object::ID object, bool groupSelect)
{
currentLevel_->GetGameObjectRef(object).SetColor({1.0f, 1.0f, 1.0f, 1.0f});
currentSelectedGameObject_ = Object::INVALID_ID;

// If main selected object was the only one
if (selectedObjects_.size() == 1)
{
selectedObjects_.clear();
}
}
else if (groupSelect)
{
Expand Down Expand Up @@ -680,9 +699,7 @@ Editor::UnselectAll()

if (currentSelectedGameObject_ != Object::INVALID_ID)
{
currentLevel_->GetGameObjectRef(currentSelectedGameObject_)
.SetColor({1.0f, 1.0f, 1.0f, 1.0f});
currentSelectedGameObject_ = Object::INVALID_ID;
UnselectGameObject(currentSelectedGameObject_, false);
}
}

Expand All @@ -700,6 +717,8 @@ Editor::HandleEditorObjectSelected(EditorObject& newSelectedEditorObject, bool f

newSelectedEditorObject.SetObjectSelected();

const auto& editorObj = GetEditorObjectRef(currentSelectedEditorObject_);
gizmo_.Update(editorObj.GetCenteredPosition(), editorObj.GetSprite().GetRotation());
gizmo_.Show();
gizmoActive_ = true;
}
Expand All @@ -720,6 +739,16 @@ Editor::GetEditorObjectRef(Object::ID object)
return *animationPointIt;
}

EditorObject&
Editor::GetEditorObjectRefByLinkedID(Object::ID linkedObjID)
{
auto animationPointIt = stl::find_if(animationPoints_, [linkedObjID](const auto& editorObject) {
return editorObject.GetLinkedObjectID() == linkedObjID;
});

return *animationPointIt;
}

void
Editor::UnselectEditorObject(Object::ID object)
{
Expand All @@ -728,6 +757,7 @@ Editor::UnselectEditorObject(Object::ID object)

auto& editorObject = GetEditorObjectRef(object);
editorObject.SetObjectUnselected();

currentSelectedEditorObject_ = Object::INVALID_ID;

gizmo_.Hide();
Expand Down Expand Up @@ -873,23 +903,32 @@ Editor::ActionOnObject(Editor::ACTION action, Object::ID object)
}
break;

case ACTION::REMOVE:

if (Object::GetTypeFromID(object) == ObjectType::EDITOR_OBJECT)
{
case ACTION::REMOVE: {
auto removeEditorObject = [this](Object::ID object) {
UnselectEditorObject(object);
auto& currentySelectedObj = GetEditorObjectRef(currentSelectedEditorObject_);

auto& currentySelectedObj = GetEditorObjectRef(object);
gui_.ObjectDeleted(currentySelectedObj.GetLinkedObjectID());
currentySelectedObj.DeleteLinkedObject();

if (Object::GetTypeFromID(currentySelectedObj.GetLinkedObjectID())
== ObjectType::ANIMATION_POINT)
{
animationPoints_.erase(
stl::find_if(animationPoints_, [this](const auto& animationPoint) {
return animationPoint.GetID() == currentSelectedEditorObject_;
}));
auto animationIt =
stl::find_if(animationPoints_, [object](const auto& animationPoint) {
return animationPoint.GetID() == object;
});
animationIt->GetSprite().ClearData();
animationPoints_.erase(animationIt);
}
};
if (Object::GetTypeFromID(object) == ObjectType::EDITOR_OBJECT)
{
removeEditorObject(object);
}
else if (Object::GetTypeFromID(object) == ObjectType::ANIMATION_POINT)
{
removeEditorObject(GetEditorObjectRefByLinkedID(object).GetID());
}
else
{
Expand All @@ -898,7 +937,8 @@ Editor::ActionOnObject(Editor::ACTION action, Object::ID object)

currentLevel_->DeleteObject(object);
}
break;
}
break;
default: {
}
}
Expand Down Expand Up @@ -939,11 +979,14 @@ Editor::Render(VkCommandBuffer cmdBuffer)
vkCmdPushConstants(cmdBuffer, renderData.pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(renderer::QuadShader::PushConstants), &pushConstants);

const auto renderAllLayers = renderLayerToDraw_ == -1;
for (int32_t layer = renderer::NUM_LAYERS - 1; layer >= 0; --layer)
{
const auto idx = static_cast< size_t >(layer);
const auto& numObjects = renderData.numMeshes.at(idx);
const auto renderThisLayer = renderLayerToDraw_ == -1 ? true : renderLayerToDraw_ == layer;

const auto renderThisLayer =
(renderAllLayers or layer == 0) ? true : renderLayerToDraw_ == layer;

if (numObjects == 0 or !renderThisLayer)
{
Expand Down Expand Up @@ -1305,17 +1348,7 @@ Editor::AddObject(ObjectType objectType)
void
Editor::ToggleAnimateObject()
{
if (animateGameObject_)
{
// TODO: This should be changed in future!
auto& enemy = dynamic_cast< Enemy& >(currentLevel_->GetObjectRef(currentSelectedGameObject_));
enemy.SetPosition(enemy.GetInitialPosition());
animateGameObject_ = false;
}
else
{
animateGameObject_ = true;
}
animateGameObject_ = not animateGameObject_;
}

bool
Expand Down Expand Up @@ -1370,11 +1403,8 @@ Editor::SetRenderAnimationPoints(bool render)
auto& animatable =
dynamic_cast< Animatable& >(currentLevel_->GetObjectRef(currentSelectedGameObject_));

if (animatable.GetRenderAnimationSteps() != render)
{
animatable.RenderAnimationSteps(render);
SetVisibleAnimationPoints(animatable, render);
}
animatable.RenderAnimationSteps(render);
SetVisibleAnimationPoints(animatable, render);
}

void
Expand Down Expand Up @@ -1403,6 +1433,11 @@ Editor::Update()

gameObject.Rotate(viewAngle);
gameObject.Move(moveBy);

if (currentSelectedEditorObject_ == Object::INVALID_ID)
{
gizmo_.Move(moveBy);
}
}
else if (animatable.AnimationFinished())
{
Expand Down Expand Up @@ -1436,7 +1471,15 @@ Editor::Update()
void
Editor::UpdateAnimationData(Object::ID object)
{
dynamic_cast< Animatable& >(currentLevel_->GetObjectRef(object)).UpdateAnimationData();
auto& baseObject = currentLevel_->GetObjectRef(object);
auto& gameObject = dynamic_cast< GameObject& >(baseObject);

auto* animatable = dynamic_cast< Animatable* >(&baseObject);
if (animatable)
{
animatable->SetAnimationStartLocation(gameObject.GetPosition());
animatable->UpdateAnimationData();
}
}

glm::vec2
Expand Down
3 changes: 3 additions & 0 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class Editor : public Application
EditorObject&
GetEditorObjectRef(Object::ID object);

EditorObject&
GetEditorObjectRefByLinkedID(Object::ID linkedObjID);

private:
// [[nodiscard]] std::shared_ptr< EditorObject >
// GetEditorObjectByID(Object::ID ID);
Expand Down
7 changes: 0 additions & 7 deletions editor/editor_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ EditorObject::GetSprite()
return sprite_;
}

void
EditorObject::CreateSprite(const glm::vec2& globalPosition, const glm::ivec2& size)
{
sprite_.SetSprite(glm::vec3(globalPosition, 0.0f), size);
position_ = sprite_.GetPosition();
}

void
EditorObject::CreateSpriteTextured(const glm::vec2& /*position*/, const glm::ivec2& /*size*/,
const std::string& /*fileName*/)
Expand Down
5 changes: 0 additions & 5 deletions editor/editor_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ class EditorObject : public Object
void
DeleteLinkedObject();

// Create sprite with default texture
void
CreateSprite(const glm::vec2& position = glm::vec2(0.0f, 0.0f),
const glm::ivec2& size = glm::ivec2(10, 10));

// Create sprite with texture from 'fileName'
void
CreateSpriteTextured(const glm::vec2& position = glm::vec2(0.0f, 0.0f),
Expand Down
15 changes: 6 additions & 9 deletions editor/gizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ namespace looper {
void
Gizmo::Initialize()
{
gizmoCenter_.SetSpriteTextured(glm::vec3{0.0f, 0.0f, renderer::LAYER_1}, {16, 16},
"centered_move.png", renderer::SpriteType::alwaysOnTop);
gizmoCenter_.SetSpriteTextured(glm::vec2{0.0f, 0.0f}, {16, 16}, "centered_move.png", 0);
gizmoCenter_.SetColor({1.0f, 1.0f, 1.0f, 1.0f});

gizmoUp_.SetSpriteTextured(glm::vec3{0.0f, 0.0f, renderer::LAYER_1}, {96, 32}, "arrow.png",
renderer::SpriteType::alwaysOnTop);
gizmoUp_.SetSpriteTextured(glm::vec2{0.0f, 0.0f}, {96, 32}, "arrow.png", 0);
gizmoUp_.Rotate(90.0f, renderer::RotationType::degrees);
gizmoUp_.SetColor({0.0f, 1.0f, 0.0f, 1.0f});

gizmoSide_.SetSpriteTextured(glm::vec3{0.0f, 0.0f, renderer::LAYER_1}, {96, 32}, "arrow.png",
renderer::SpriteType::alwaysOnTop);
gizmoSide_.SetSpriteTextured(glm::vec2{0.0f, 0.0f}, {96, 32}, "arrow.png", 0);
gizmoSide_.SetColor({1.0f, 0.0f, 0.0f, 1.0f});

centerInitialSize_ = {{16, 16}, {96, 96}};
Expand Down Expand Up @@ -105,13 +102,13 @@ Gizmo::AdjustSize()

gizmoUp_.SetInitialPosition(
gizmoCenter_.GetPosition()
+ glm::vec3{0.0f, gizmoCenter_.GetSize().y / 2.0f + gizmoUp_.GetSize().x / 1.85f, 0.0f});
+ glm::vec2{0.0f, gizmoCenter_.GetSize().y / 2.0f + gizmoUp_.GetSize().x / 1.85f});


gizmoSide_.SetInitialPosition(
gizmoCenter_.GetPosition()
+ glm::vec3{glm::vec2(gizmoCenter_.GetSize().x / 2.0f + gizmoSide_.GetSize().x / 1.85f, 0.0f),
0.0f});
+ glm::vec2{
glm::vec2(gizmoCenter_.GetSize().x / 2.0f + gizmoSide_.GetSize().x / 1.85f, 0.0f)});
}

void
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/editor_gui_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ EditorGUI::RenderLevelMenu() // NOLINT

CreateActionRowLabel("RenderLayer", [this] {
const auto items = std::to_array< std::string >(
{"All", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"});
{"All", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"});
const auto layer = parent_.GetRenderLayerToDraw();
if (ImGui::BeginCombo(
"##combo",
Expand Down
Loading

0 comments on commit 8a799d5

Please sign in to comment.