Skip to content
Merged
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
2 changes: 1 addition & 1 deletion StarEditor/SandboxProject/Assets/Scripts/Source/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Player : Entity
private TransformComponent m_Transform;
private RigidBody2DComponent m_RigidBody;

public float Speed = 1.0f;
public float Speed;
Copy link

Copilot AI May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the default initialization for 'Speed' may result in unintended behavior if the value is assumed to be non-zero elsewhere. Consider reintroducing a default value if one is expected.

Suggested change
public float Speed;
public float Speed = 5.0f;

Copilot uses AI. Check for mistakes.
public float Time = 0.0f;

void OnCreate()
Expand Down
5 changes: 5 additions & 0 deletions StarEditor/SandboxProject/Sandbox.starproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Project:
Name: Sandbox
StartScene: "Scenes/Physics2D.starscene"
AssetDirectory: "Assets"
ScriptModulePath: "Scripts/Binaries/Sandbox.dll"
11 changes: 5 additions & 6 deletions StarEditor/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ project "StarEditor"

filter "system:windows"
systemversion "latest"
postbuildcommands {
"{COPYDIR} %{wks.location}/StarEditor/assets %{wks.location}/bin/" .. outputdir .. "/StarEditor/assets",
"{COPYDIR} %{wks.location}/StarEditor/Resources %{wks.location}/bin/" .. outputdir .. "/StarEditor/Resources",
"{COPYFILE} %{wks.location}/StarEditor/imgui.ini %{wks.location}/bin/" .. outputdir .. "/StarEditor/imgui.ini",
}

filter "configurations:Debug"
defines "SE_DEBUG"
Expand All @@ -47,11 +52,5 @@ project "StarEditor"
runtime "Release"
optimize "on"

postbuildcommands {
"{COPYDIR} %{wks.location}/StarEditor/assets %{wks.location}/bin/" .. outputdir .. "/StarEditor/assets",
"{COPYDIR} %{wks.location}/StarEditor/Resources %{wks.location}/bin/" .. outputdir .. "/StarEditor/Resources",
"{COPYFILE} %{wks.location}/StarEditor/imgui.ini %{wks.location}/bin/" .. outputdir .. "/StarEditor/imgui.ini",
}

filter "action:vs2022"
buildoptions { "/utf-8" }
99 changes: 75 additions & 24 deletions StarEditor/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

namespace StarEngine {

extern const std::filesystem::path g_AssetPath;

EditorLayer::EditorLayer()
: Layer("EditorLayer"), m_CameraController(1280.0f / 720.0f, true), m_SquareColor({ 0.2f, 0.3f, 0.8f, 1.0f })
{
Expand Down Expand Up @@ -47,9 +45,18 @@ namespace StarEngine {
auto commandLineArgs = Application::Get().GetSpecification().CommandLineArgs;
if (commandLineArgs.Count > 1)
{
auto sceneFilePath = commandLineArgs[1];
SceneSerializer serializer(m_ActiveScene);
serializer.Deserialize(sceneFilePath);
auto projectFilePath = commandLineArgs[1];
OpenProject(projectFilePath);
}
else
{
// TODO: prompt the user to select a directory
// NewProject();

if (!OpenProject())
{
Application::Get().Close();
}
}

m_EditorCamera = EditorCamera(30.0f, 1.778f, 0.1f, 1000.0f);
Expand Down Expand Up @@ -193,27 +200,21 @@ namespace StarEngine {
{
if (ImGui::BeginMenu("File"))
{
// Disabling fullscreen would allow the window to be moved to the front of other windows,
// which we can't undo at the moment without finer window depth/z control.
//ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1
if (ImGui::MenuItem("Open Project...", "Ctrl+O"))
OpenProject();

if (ImGui::MenuItem("New", "Ctrl+N"))
{
NewScene();
}
ImGui::Separator();

if (ImGui::MenuItem("Open...", "Ctrl+O"))
{
OpenScene();
}
if (ImGui::MenuItem("New Scene", "Ctrl+N"))
NewScene();

if (ImGui::MenuItem("Save", "Ctrl+S"))
if (ImGui::MenuItem("Save Scene", "Ctrl+S"))
SaveScene();

if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S"))
{
if (ImGui::MenuItem("Save Scene As...", "Ctrl+Shift+S"))
SaveSceneAs();
}

ImGui::Separator();

if (ImGui::MenuItem("Exit"))
Application::Get().Close();
Expand All @@ -233,15 +234,17 @@ namespace StarEngine {
}

m_SceneHierarchyPanel.OnImGuiRender();
m_ContentBrowserPanel.OnImGuiRender();
m_ContentBrowserPanel->OnImGuiRender();

//Camera Info
ImGui::Begin("Stats");

#if 0
std::string name = "None";
if (m_HoveredEntity)
name = m_HoveredEntity.GetComponent<TagComponent>().Tag;
ImGui::Text("Hovered Entity: %s", name.c_str());
#endif

auto stats = Renderer2D::GetStats();
ImGui::Text("Renderer2D Stats:");
Expand Down Expand Up @@ -287,7 +290,7 @@ namespace StarEngine {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_ITEM"))
{
const wchar_t* path = (const wchar_t*)payload->Data;
OpenScene(std::filesystem::path(g_AssetPath) / path);
OpenScene(path);
}
ImGui::EndDragDropTarget();
}
Expand Down Expand Up @@ -477,7 +480,7 @@ namespace StarEngine {
case Key::O:
{
if (control)
OpenScene();
OpenProject();

break;
}
Expand Down Expand Up @@ -536,6 +539,20 @@ namespace StarEngine {
break;
}

case Key::Delete:
{
if (Application::Get().GetImGuiLayer()->GetActiveWidgetID() == 0)
{
Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity();
if (selectedEntity)
{
m_SceneHierarchyPanel.SetSelectedEntity({});
m_ActiveScene->DestroyEntity(selectedEntity);
}
}
break;
}

default:
break;
}
Expand Down Expand Up @@ -615,6 +632,37 @@ namespace StarEngine {
Renderer2D::EndScene();
}

void EditorLayer::NewProject()
{
Project::New();
}

void EditorLayer::OpenProject(const std::filesystem::path& path)
{
if (Project::Load(path))
{
ScriptEngine::Init();

auto startScenePath = Project::GetAssetFileSystemPath(Project::GetActive()->GetConfig().StartScene);
OpenScene(startScenePath);
m_ContentBrowserPanel = CreateScope<ContentBrowserPanel>();
}
}

bool EditorLayer::OpenProject()
{
std::string filepath = FileDialogs::OpenFile("Star Project (*.starproj)\0*.starproj\0");
if (filepath.empty())
return false;

OpenProject(filepath);
return true;
}

void EditorLayer::SaveProject()
{
// Project::SaveActive();
}

void EditorLayer::NewScene()
{
Expand Down Expand Up @@ -738,7 +786,10 @@ namespace StarEngine {

Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity();
if (selectedEntity)
m_EditorScene->DuplicateEntity(selectedEntity);
{
Entity newEntity = m_EditorScene->DuplicateEntity(selectedEntity);
m_SceneHierarchyPanel.SetSelectedEntity(newEntity);
}
}

}
7 changes: 6 additions & 1 deletion StarEditor/src/EditorLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ namespace StarEngine

void OnOverlayRender();

void NewProject();
bool OpenProject();
void OpenProject(const std::filesystem::path& path);
void SaveProject();

void NewScene();
void OpenScene();
void OpenScene(const std::filesystem::path& path);
Expand Down Expand Up @@ -90,7 +95,7 @@ namespace StarEngine

// Panels
SceneHierarchyPanel m_SceneHierarchyPanel;
ContentBrowserPanel m_ContentBrowserPanel;
Scope<ContentBrowserPanel> m_ContentBrowserPanel;

// Editor resources
Ref<Texture2D> m_IconPlay, m_IconPause, m_IconStep, m_IconSimulate, m_IconStop;
Expand Down
11 changes: 5 additions & 6 deletions StarEditor/src/Panels/ContentBrowserPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "sepch.h"
#include "ContentBrowserPanel.h"

#include "StarEngine/Project/Project.h"

#include <imgui/imgui.h>

namespace StarEngine
{
// Once we have projects, change this
extern const std::filesystem::path g_AssetPath = "assets";

ContentBrowserPanel::ContentBrowserPanel()
: m_CurrentDirectory(g_AssetPath)
: m_BaseDirectory(Project::GetAssetDirectory()), m_CurrentDirectory(m_BaseDirectory)
{
m_DirectoryIcon = Texture2D::Create("Resources/Icons/ContentBrowser/DirectoryIcon.png");
m_FileIcon = Texture2D::Create("Resources/Icons/ContentBrowser/FileIcon.png");
Expand All @@ -19,7 +18,7 @@ namespace StarEngine
{
ImGui::Begin("Content Browser");

if (m_CurrentDirectory != std::filesystem::path(g_AssetPath))
if (m_CurrentDirectory != std::filesystem::path(m_BaseDirectory))
{
if (ImGui::Button("<-"))
{
Expand Down Expand Up @@ -50,7 +49,7 @@ namespace StarEngine

if (ImGui::BeginDragDropSource())
{
auto relativePath = std::filesystem::relative(path, g_AssetPath);
std::filesystem::path relativePath(path);
const wchar_t* itemPath = relativePath.c_str();
ImGui::SetDragDropPayload("CONTENT_BROWSER_ITEM", itemPath, (wcslen(itemPath) + 1) * sizeof(wchar_t));
ImGui::EndDragDropSource();
Expand Down
1 change: 1 addition & 0 deletions StarEditor/src/Panels/ContentBrowserPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace StarEngine

void OnImGuiRender();
private:
std::filesystem::path m_BaseDirectory;
std::filesystem::path m_CurrentDirectory;

Ref<Texture2D> m_DirectoryIcon;
Expand Down
15 changes: 6 additions & 9 deletions StarEditor/src/Panels/SceneHierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "StarEngine/Scene/Components.h"

#include "StarEngine/Scripting/ScriptEngine.h"
#include "StarEngine/UI/UI.h"

#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
Expand All @@ -19,9 +20,6 @@

namespace StarEngine
{
// Once we have projects, change this{
extern const std::filesystem::path g_AssetPath;

SceneHierarchyPanel::SceneHierarchyPanel(const Ref<Scene>& context)
{
SetContext(context);
Expand Down Expand Up @@ -330,11 +328,13 @@ namespace StarEngine
static char buffer[64];
strcpy_s(buffer, sizeof(buffer), component.ClassName.c_str());

if (!scriptClassExists)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f));
UI::ScopedStyleColor textColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f), !scriptClassExists);

if (ImGui::InputText("Class", buffer, sizeof(buffer)))
{
component.ClassName = buffer;
return;
}

// Fields
bool sceneRunning = scene->IsRunning();
Expand Down Expand Up @@ -397,9 +397,6 @@ namespace StarEngine
}
}
}

if (!scriptClassExists)
ImGui::PopStyleColor();
});

DrawComponent<SpriteRendererComponent>("Sprite Renderer", entity, [](auto& component)
Expand All @@ -412,7 +409,7 @@ namespace StarEngine
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_ITEM"))
{
const wchar_t* path = (const wchar_t*)payload->Data;
std::filesystem::path texturePath = std::filesystem::path(g_AssetPath) / path;
std::filesystem::path texturePath(path);
Ref<Texture2D> texture = Texture2D::Create(texturePath.string());
if (texture->IsLoaded())
component.Texture = texture;
Expand Down
7 changes: 7 additions & 0 deletions StarEngine-ScriptCore/Source/StarEngine/InternalCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public static class InternalCalls
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void RigidBody2DComponent_ApplyLinearImpulse(ulong entityID, ref Vector2 impulse, ref Vector2 point, bool wake);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void Rigidbody2DComponent_GetLinearVelocity(ulong entityID, out Vector2 linearVelocity);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static RigidBody2DComponent.BodyType Rigidbody2DComponent_GetType(ulong entityID);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void Rigidbody2DComponent_SetType(ulong entityID, RigidBody2DComponent.BodyType type);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static void RigidBody2DComponent_ApplyLinearImpulseToCenter(ulong entityID, ref Vector2 impulse, bool wake);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
Expand Down
17 changes: 17 additions & 0 deletions StarEngine-ScriptCore/Source/StarEngine/Scene/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ public Vector3 Translation

public class RigidBody2DComponent : Component
{
public enum BodyType { Static = 0, Dynamic, Kinematic }

public Vector2 LinearVelocity
{
get
{
InternalCalls.Rigidbody2DComponent_GetLinearVelocity(Entity.ID, out Vector2 velocity);
return velocity;
}
}

public BodyType Type

{
get => InternalCalls.Rigidbody2DComponent_GetType(Entity.ID);
set => InternalCalls.Rigidbody2DComponent_SetType(Entity.ID, value);
}
public void ApplyLinearImpulse(Vector2 impulse, Vector2 worldPosition, bool wake)
{
InternalCalls.RigidBody2DComponent_ApplyLinearImpulse(Entity.ID, ref impulse, ref worldPosition, wake);
Expand Down
13 changes: 12 additions & 1 deletion StarEngine-ScriptCore/Source/StarEngine/Vector2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace StarEngine
using System;

namespace StarEngine
{
public struct Vector2
{
Expand Down Expand Up @@ -28,5 +30,14 @@ public Vector2(float x, float y)
return new Vector2(vector.X * scalar, vector.Y * scalar);
}

public float LengthSquared()
{
return X * X + Y * Y;
}

public float Length()
{
return (float)Math.Sqrt(LengthSquared());
}
}
}
Loading
Loading