Skip to content

Commit

Permalink
Scripts & export fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtar00 committed Aug 2, 2024
1 parent af9f2c0 commit 7087a37
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 20 deletions.
9 changes: 7 additions & 2 deletions Eklipse/src/Eklipse/Project/ProjectExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace Eklipse
EK_CORE_PROFILE();
EK_ASSERT(project, "Project is null!");

std::error_code ec;
auto& config = project->GetConfig();
EK_CORE_INFO("Exporting project '{0}' to '{1}'", config.name, settings.path.string());

Expand Down Expand Up @@ -109,7 +110,6 @@ namespace Eklipse
else
{
EK_CORE_WARN("Script library not found at path '{0}'!", scriptLibraryPath.string());
return false;
}

// Copy the engine library
Expand All @@ -130,7 +130,12 @@ namespace Eklipse
if (FileUtilities::IsPathValid(scriptApiLibraryPath))
{
Path destinationScriptApiLibraryPath = destinationDir / (String("EklipseScriptAPI") + EK_SCRIPT_LIBRARY_EXTENSION);
fs::copy_file(scriptApiLibraryPath, destinationScriptApiLibraryPath, fs::copy_options::overwrite_existing);
fs::copy_file(scriptApiLibraryPath, destinationScriptApiLibraryPath, fs::copy_options::overwrite_existing, ec);
if (ec)
{
EK_CORE_ERROR("Failed to copy script API library! {0}", ec.message());
return false;
}
}
else
{
Expand Down
11 changes: 7 additions & 4 deletions Eklipse/src/Eklipse/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,12 @@ namespace Eklipse
if (scriptComponent)
{
auto scriptName = TryDeserailize<String>(scriptComponent, "Name", "");
auto& scriptComponent = deserializedEntity.AddComponent<ScriptComponent>();
scriptComponent.scriptName = scriptName;
ScriptLinker::Get().FetchScriptClasses({ scriptName });
if (!scriptName.empty())
{
auto& scriptComponent = deserializedEntity.AddComponent<ScriptComponent>();
scriptComponent.scriptName = scriptName;
ScriptLinker::Get().FetchScriptClasses({ scriptName });
}
/*if (!scriptName.empty())
{
EklipseEngine::Reflections::ClassInfo info{};
Expand Down Expand Up @@ -685,7 +688,7 @@ namespace Eklipse
if (scriptComponent)
{
auto properties = scriptComponent["Properties"];
if (properties)
if (properties && entity.HasComponent<ScriptComponent>())
DeserializeScriptProperties(entity, properties);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Eklipse/src/Eklipse/Scripting/ScriptLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Eklipse
}
catch (const std::exception& e)
{
EK_CORE_ERROR("Failed to fetch script class: {0}. {1}", scriptClassName, e.what());
EK_CORE_ERROR("Failed to fetch script class: '{0}'. {1}", scriptClassName, e.what());
}
}

Expand Down
14 changes: 12 additions & 2 deletions Eklipse/src/Eklipse/Scripting/ScriptManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ namespace Eklipse
default: return "Unknown";
}
}
static String BuildTypeToFolderName(ProjectExportBuildType type)
{
switch (type)
{
case ProjectExportBuildType::DEBUG: return "Debug";
case ProjectExportBuildType::Developement: return "Developement";
case ProjectExportBuildType::Release: return "Release";
default: return "Unknown";
}
}

ScriptManager::ScriptManager(ScriptManagerSettings* settings)
: m_settings(settings), m_state(ScriptsState::NONE)
Expand All @@ -35,7 +45,7 @@ namespace Eklipse

SetState(ScriptsState::NONE);

auto& libraryPath = config.scriptBuildDirectoryPath / BuildTypeToString(EK_CURRENT_CONFIG) / (config.name + EK_SCRIPT_LIBRARY_EXTENSION);
auto& libraryPath = config.scriptBuildDirectoryPath / BuildTypeToFolderName(EK_CURRENT_CONFIG) / (config.name + EK_SCRIPT_LIBRARY_EXTENSION);
if (fs::exists(libraryPath) && m_scriptLinker->LinkScriptLibrary(libraryPath))
{
auto& classReflections = ScriptParser::ParseDirectory(config.scriptsSourceDirectoryPath);
Expand Down Expand Up @@ -247,7 +257,7 @@ namespace Eklipse
RunPremake(config.scriptPremakeDirectoryPath);
CompileScripts(config.scriptsSourceDirectoryPath, EK_CURRENT_CONFIG);

auto& libraryPath = config.scriptBuildDirectoryPath / BuildTypeToString(EK_CURRENT_CONFIG) / (config.name + EK_SCRIPT_LIBRARY_EXTENSION);
auto& libraryPath = config.scriptBuildDirectoryPath / BuildTypeToFolderName(EK_CURRENT_CONFIG) / (config.name + EK_SCRIPT_LIBRARY_EXTENSION);
if (FileUtilities::IsPathValid(libraryPath))
{
if (m_scriptLinker->LinkScriptLibrary(libraryPath))
Expand Down
6 changes: 3 additions & 3 deletions EklipseEditor/Resources/Scripting/Premake/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ project "__PRJ_NAME__"
}
end

configs = { "Debug", "Developement", "Release" }
for _, config in ipairs(configs) do
configs = { Debug="Debug", Developement="Release", Release="Dist" }
for name, config in pairs(configs) do
for system, ext in pairs(extensions) do
filter { "system:" .. system, "configurations:" .. config }
postbuildcommands
{
"{COPY} %{cfg.targetdir}/%{prj.name}" .. ext .. " ./Scripts/Build/" .. config
"{COPY} %{cfg.targetdir}/%{prj.name}" .. ext .. " ./Scripts/Build/" .. name
}
end
end
5 changes: 5 additions & 0 deletions EklipseEditor/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,11 @@ namespace Eklipse
if (EK_CURRENT_CONFIG != exportSettings.buildType && ScriptLinker::Get().HasAnyScriptClasses())
{
m_scriptManager->CompileScripts(Project::GetActive()->GetConfig().scriptsSourceDirectoryPath, exportSettings.buildType);
if (m_scriptManager->GetScriptsState() == ScriptsState::COMPILATION_FAILED)
{
EK_ERROR("Failed to compile scripts!");
return;
}
}
if (!ProjectExporter::Export(m_editorAssetLibrary, Project::GetActive(), exportSettings))
{
Expand Down
2 changes: 1 addition & 1 deletion EklipseSandbox/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Size=381,205
Collapsed=0

[Window][Sandbox]
Pos=866,80
Pos=1047,132
Size=544,586
Collapsed=0

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Eklipse Engine
# Eklipse Engine

Eklipse is a game engine which tries to provide proof-of-concept solutions to the most important problems of a complex game engine (which this engine is not).

## How it works
## How it works
**Editor** - allows you to import assets, view the scene, scene hierarchy and export the project to a precompiled executable. Editor supports managing multiple projects.


Expand All @@ -19,7 +19,7 @@ Eklipse is a game engine which tries to provide proof-of-concept solutions to th
</p>


**Scritps API** - all scripts are written in C++ and provide a simple custom logic injection system. Scripts are part of a separate C++ project that is automatically created with an editor project. Creating a new script is as simple as writing a new class that derives from the base *Script* class. All scripts are compiled into a shared library that is then linked to a given executable (Editor or Runtime).
**Script API** - all scripts are written in C++ and provide a simple custom logic injection system. Scripts are part of a separate C++ project that is automatically created with an editor project. Creating a new script is as simple as writing a new class that derives from the base *Script* class. All scripts are compiled into a shared library that is then linked to a given executable (Editor or Runtime).


```cpp
Expand All @@ -32,8 +32,8 @@ public:
void OnCreate();
void OnUpdate(float deltaTime);

float speed = 5.0f;
float rotationSpeed = 5.0f;
EK_FLOAT speed = 5.0f;
EK_FLOAT rotationSpeed = 5.0f;
};
```

Expand Down Expand Up @@ -95,9 +95,9 @@ void CameraController::OnUpdate(float deltaTime)
## Disclaimer ⚠
This engine has been written in Visual Studio 2022 on Windows and this is the only target setup that is supported for now.
This project has been written in Visual Studio 2022 on Windows and this is the only target setup that is supported for now.
## How to build
## How to build 🛠
1. Clone the repo with all of it's submodules
Expand Down

0 comments on commit 7087a37

Please sign in to comment.