Skip to content

Commit

Permalink
enhanced release build script
Browse files Browse the repository at this point in the history
moved to dynamic linking
transitioned to dynamic linking
improved textfield logic
added string sorting to cxstructs
basic node creator skeleton working
-> needs more ui tech
-> need dynamic lists
-> easier text input fields
-> proper layering
  • Loading branch information
gk646 committed May 14, 2024
1 parent 9324b71 commit a8a30e1
Show file tree
Hide file tree
Showing 19 changed files with 326 additions and 146 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) # Build as shared lib
option(RN_ENABLE_SANITIZER "Set to compile with adress sanitizer (MSVC)") # set(RN_ENABLE_SANITIZER ON)
option(RN_BUILD_TESTS "Set to compile the test executable") # set(RN_BUILD_TESTS ON)
option(RN_BUILD_RELEASE "Set to build the release archives") # set(RN_BUILD_RELEASE ON) # You don't really need this
set(RN_VERSION "1.0.1")
set(RN_VERSION "1.0.2")

# Compiler options for MSVC and GCC
include(cmake/CompilerOptions.cmake)
Expand Down
42 changes: 37 additions & 5 deletions cmake/BuildRelease.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@

set(OS "Windows")
set(CPACK_PACKAGE_NAME "raynodes")

set(STAGING_DIR "${CMAKE_BINARY_DIR}/staging")
if (MSVC)
set(STAGING_DIR "${CMAKE_BINARY_DIR}/staging-WIN")
set(OS "Windows")
set(REDIS_PATH "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.38.33135/x86/Microsoft.VC143.CRT")
set(EXE_NAME "raynodes.exe")
set(LIB_NAME "raylib.dll")
else ()
set(STAGING_DIR "${CMAKE_BINARY_DIR}/staging-UNIX")
set(OS "GNU-Linux")
set(REDIS_PATH "//wsl.localhost/Ubuntu-22.04/usr/lib/gcc/x86_64-linux-gnu/11")
set(EXE_NAME "raynodes")
set(LIB_NAME "raylib.so")
endif ()

# Ensure the staging directory is properly set up and all files are copied after the build
add_custom_command(TARGET raynodes POST_BUILD
Expand All @@ -11,8 +21,30 @@ add_custom_command(TARGET raynodes POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${STAGING_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E make_directory "${STAGING_DIR}/res"
COMMAND ${CMAKE_COMMAND} -E make_directory "${STAGING_DIR}/plugins"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:raynodes>" "${STAGING_DIR}/raynodes.exe"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:raylib>" "${STAGING_DIR}/raylib.dll"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:raynodes>" "${STAGING_DIR}/${EXE_NAME}"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:raylib>" "${STAGING_DIR}/${LIB_NAME}"

)

# Redistributables
if (MSVC)
add_custom_command(TARGET raynodes POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/msvcp140.dll" "${STAGING_DIR}/msvcp140.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/vcruntime140.dll" "${STAGING_DIR}/vcruntime140.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/concrt140.dll" "${STAGING_DIR}/concrt140.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/vccorlib140.dll" "${STAGING_DIR}/vccorlib140.dll"
)

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_custom_command(TARGET raynodes POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/libgcc_s.so.1" "${STAGING_DIR}/libgcc_s.so.1"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/libstdc++.so.6" "${STAGING_DIR}/libstdc++.so.6"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/libc.so.6" "${STAGING_DIR}/libc.so.6"
COMMAND ${CMAKE_COMMAND} -E copy "${REDIS_PATH}/libm.so.6" "${STAGING_DIR}/libm.so.6"
)
endif ()

add_custom_command(TARGET raynodes POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/plugins" "${STAGING_DIR}/plugins"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/src/import/RnImport.h" "${STAGING_DIR}/include/RnImport.h"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/res" "${STAGING_DIR}/res"
Expand Down
6 changes: 2 additions & 4 deletions cmake/LinkSTL.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
if(MSVC)
# Static runtime libraries for both Debug and Release configurations
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
# Use dynamic linking for the runtime library on Windows
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
elseif(UNIX)
# Static standard libraries for GCC/Clang
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
32 changes: 31 additions & 1 deletion src/external/cxstructs/include/cxutil/cxstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,39 @@ inline float str_parse_float(const char* str) {

return negative ? -result : result;
}
// Returns the levenshtein distance for the two given strings - stops when either string ends
// This doesnt penalize long strings
// Failure: returns -1
template<int MAX_LEN>
int str_sort_levenshtein_prefix(const char* s1, const char* s2) {
const size_t len1 = str_len(s1), len2 = str_len(s2);
const size_t limit = len1 < len2 ? len1 : len2;

if (len1 > MAX_LEN || len2 > MAX_LEN) {
return -1; // Error: string length exceeds maximum allowed length
}

unsigned int d[MAX_LEN + 1][MAX_LEN + 1] = {0};

for (unsigned int i = 1; i <= limit; ++i) d[i][0] = i;
for (unsigned int i = 1; i <= len2; ++i) d[0][i] = i;

for (unsigned int i = 1; i <= limit; ++i) {
for (unsigned int j = 1; j <= len2; ++j) {
unsigned int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1;
unsigned int above = d[i - 1][j] + 1;
unsigned int left = d[i][j - 1] + 1;
unsigned int diag = d[i - 1][j - 1] + cost;

d[i][j] = above < left ? (above < diag ? above : diag) : (left < diag ? left : diag);
}
}

return d[limit][len2];
}

// string hash function
constexpr auto fnv1a_32(char const* s) noexcept -> uint32_t {
constexpr auto str_hash_fnv1a_32(char const* s) noexcept -> uint32_t {
uint32_t hash = 2166136261U;
while (*s != 0) {
hash ^= (uint32_t)*s++;
Expand Down
1 change: 1 addition & 0 deletions src/raynodes/application/NodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ bool NodeEditor::start() {
c + context.core.loadCore(context);
c + context.display.loadResources(context);
c + context.plugin.loadPlugins(context);
c + context.ui.loadUI(context);

// Only load file if path is given - automatically opens picker
if (!context.persist.openedFilePath.empty()) { c + context.persist.loadFromFile(context); }
Expand Down
31 changes: 3 additions & 28 deletions src/raynodes/application/context/ContextTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,9 @@ struct Template {
// Passed template names only have to be valid until this function returns (copied)
bool registerNode(const NodeTemplate& nt, NodeCreateFunc func, const PluginContainer& plugin);
// Passed name only has to be valid until this function returns
Node* createNode(const char* name, Vec2 pos, NodeID nodeID) {
NodeInfo* info = nullptr;

if (registeredNodes.contains(name)) [[likely]] {
info = &registeredNodes[name];
} else if (userDefinedNodes.contains(name)) [[likely]] {
info = &userDefinedNodes[name];
} else {
fprintf(stderr, "No node registered with the name %s", name);
return nullptr;
}
if (info == nullptr) return nullptr; // Safety

auto* node = info->createFunc(info->nTemplate, pos, nodeID); // Has to exist
for (const auto component : info->nTemplate.components) {
if (component.component == nullptr) continue; // We dont break for safety
auto* comp = createComponent(component);
if (comp) node->components.push_back(comp);
else fprintf(stderr, "No component registered with the name %s", component.component);
}
return node;
}

bool registerUserNode(const NodeTemplate& nt, NodeCreateFunc func) {

userDefinedNodes.insert({nt.label,{nt, func}});
return true;
}
Node* createNode(EditorContext& ec, const char* name, Vec2 pos, NodeID nodeID);
// Passed
bool registerUserNode(EditorContext& ec, const NodeTemplate& nt, NodeCreateFunc func);
};

#endif //RAYNODES_SRC_APPLICATION_CONTEXT_CONTEXTTEMPLATES_H_
5 changes: 3 additions & 2 deletions src/raynodes/application/context/ContextUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ struct UI final {
bool showGrid = true;

UI();
bool loadUI(EditorContext& ec);

// UI wrappers
static int DrawListMenu(EditorContext& ec, bool& open, const char* title, const char* listText, int& active);
static int DrawButton(EditorContext& ec, Rectangle& r, const char* txt);
static int DrawButton(EditorContext& ec, Vector2& pos, float w, float h, const char* txt);
static int DrawButton(EditorContext& ec, const Rectangle& r, const char* txt);
static int DrawButton(EditorContext& ec, const Vector2& pos, float w, float h, const char* txt);
static int DrawWindow(EditorContext& ec, const Rectangle& r, const char* txt);
static const char* DrawTextPopUp(EditorContext& ec, const Rectangle& r, const char* text, bool& visible);
// If icns is set it will look for icons in the string
Expand Down
13 changes: 3 additions & 10 deletions src/raynodes/application/context/impl/ContextCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,10 @@ Node* Core::createNode(EditorContext& ec, const char* name, const Vector2 worldP
//Use the hint when provided
const auto nodeID = hint == UINT16_MAX ? getID() : static_cast<NodeID>(hint);

Node* newNode = ec.templates.createNode(name, {worldPos.x, worldPos.y}, nodeID);
// Calls event function internally
Node* newNode = ec.templates.createNode(ec, name, {worldPos.x, worldPos.y}, nodeID);
if (!newNode) return nullptr;

// Call event functions
for (const auto c : newNode->components) {
c->onCreate(ec, *newNode);
}

newNode->onCreation(ec); // Called after all components

insertNode(ec, *newNode);

return newNode;
Expand All @@ -109,8 +103,7 @@ void Core::removeNode(EditorContext& ec, NodeID id) {

void Core::paste(EditorContext& ec) const {
if (copiedNodes.empty()) return;
const Vector2 delta = {ec.logic.worldMouse.x - copiedNodes[0]->x,
ec.logic.worldMouse.y - copiedNodes[0]->y};
const Vector2 delta = {ec.logic.worldMouse.x - copiedNodes[0]->x, ec.logic.worldMouse.y - copiedNodes[0]->y};

const auto action = new NodeCreateAction(static_cast<int>(copiedNodes.size()) + 1);
// It can happen here that we try to copy deleted nodes
Expand Down
2 changes: 1 addition & 1 deletion src/raynodes/application/context/impl/ContextDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <raygui.h>

bool Display::loadResources(EditorContext& /**/) {
editorFont = LoadFontEx("res/monogram.ttf",128,nullptr,95);
editorFont = LoadFontEx("res/monogram.ttf",64,nullptr,95);
GuiSetFont(editorFont);
GuiLoadIcons("res/iconset.rgi", false);
SetWindowIcon(LoadImage("res/icon.png"));
Expand Down
10 changes: 4 additions & 6 deletions src/raynodes/application/context/impl/ContextPersist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,10 @@ bool Persist::loadFromFile(EditorContext& ec) {
//Load data
int nodes = 0;
int connections = 0;
{
LoadEditorData(file, ec);
LoadTemplates(file, ec);
nodes = LoadNodes(file, ec);
connections = LoadConnections(file, ec);
}
LoadEditorData(file, ec);
LoadTemplates(file, ec);
nodes = LoadNodes(file, ec);
connections = LoadConnections(file, ec);

//printf("Loaded %s nodes\n", ec.string.getPaddedNum(nodes));
//printf("Loaded %s connections\n", ec.string.getPaddedNum(connections));
Expand Down
37 changes: 37 additions & 0 deletions src/raynodes/application/context/impl/ContextTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,41 @@ bool Template::registerNode(const NodeTemplate& nt, NodeCreateFunc func, const P

registeredNodes.insert({newTemplate.label, NodeInfo{newTemplate, func}});
return true;
}
Node* Template::createNode(EditorContext& ec, const char* name, Vec2 pos, NodeID nodeID) {
NodeInfo* info = nullptr;

if (registeredNodes.contains(name)) [[likely]] {
info = &registeredNodes[name];
} else if (userDefinedNodes.contains(name)) [[likely]] {
info = &userDefinedNodes[name];
} else {
fprintf(stderr, "No node registered with the name %s", name);
return nullptr;
}

if (info == nullptr) return nullptr; // Safety

auto* node = info->createFunc(info->nTemplate, pos, nodeID); // Has to exist
for (const auto component : info->nTemplate.components) {
if (component.component == nullptr) continue; // We dont break for safety
auto* comp = createComponent(component);
if (comp) node->components.push_back(comp);
else fprintf(stderr, "No component registered with the name %s", component.component);
}

// Call event functions
for (const auto c : node->components) {
c->onCreate(ec, *node);
}

node->onCreation(ec); // Called after all components

return node;
}

bool Template::registerUserNode(EditorContext& ec, const NodeTemplate& nt, NodeCreateFunc func) {

userDefinedNodes.insert({nt.label, {nt, func}});
return true;
}
8 changes: 6 additions & 2 deletions src/raynodes/application/context/impl/ContextUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ UI::UI() {
windows.push_back(new SettingsMenu(bounds, "Settings"));
windows.push_back(new NodeCreator(bounds, "Node Creator"));
}
bool UI::loadUI(EditorContext& ec) {
getWindow<NodeCreator>(NODE_CREATOR)->searchField.font = &ec.display.editorFont;
return true;
}

int UI::DrawListMenu(EditorContext& ec, bool& open, const char* title, const char* listText, int& active) {
if (ec.input.isKeyPressed(KEY_ESCAPE)) open = false;
Expand All @@ -46,7 +50,7 @@ int UI::DrawListMenu(EditorContext& ec, bool& open, const char* title, const cha
GuiListView(ec.display.getFullyScaled(listBounds), listText, &scroll, &active);
return active;
}
int UI::DrawButton(EditorContext& ec, Rectangle& r, const char* txt) {
int UI::DrawButton(EditorContext& ec, const Rectangle& r, const char* txt) {
const auto bounds = ec.display.getFullyScaled(r);
const auto res = GuiButton(bounds, txt);

Expand All @@ -55,7 +59,7 @@ int UI::DrawButton(EditorContext& ec, Rectangle& r, const char* txt) {
}
return res;
}
int UI::DrawButton(EditorContext& ec, Vector2& pos, float w, float h, const char* txt) {
int UI::DrawButton(EditorContext& ec, const Vector2& pos, float w, float h, const char* txt) {
const auto bounds = ec.display.getFullyScaled({pos.x, pos.y, w, h});
const auto res = GuiButton(bounds, txt);

Expand Down
8 changes: 4 additions & 4 deletions src/raynodes/application/editor/EditorUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ inline void DrawTopBar(EditorContext& ec) {
UI::invokeViewMenu(ec, res);

auto buttonBounds = Rectangle{1860, 5.0F, 24.0F, 24.0F};
if (UI::DrawButton(ec, buttonBounds, "#141#")) ec.ui.getWindow(SETTINGS_MENU)->openWindow();
if (UI::DrawButton(ec, buttonBounds, "#141#")) ec.ui.getWindow(SETTINGS_MENU)->toggleWindow();
buttonBounds.x += 24.0F;
if (UI::DrawButton(ec, buttonBounds, "#193#")) ec.ui.getWindow(HELP_MENU)->openWindow();
if (UI::DrawButton(ec, buttonBounds, "#193#")) ec.ui.getWindow(HELP_MENU)->toggleWindow();

// Draw tool toggle buttons
}
Expand Down Expand Up @@ -314,9 +314,9 @@ inline void DrawUnsavedChanges(EditorContext& ec) {
if (UI::DrawButton(ec, windowRect, "#072#Cancel")) { ec.ui.showUnsavedChanges = false; }
}
inline void DrawSideBar(EditorContext& ec) {
Rectangle button = {5, 250, 25, 25};
Rectangle button = {5, 250, 50, 25};
if (GuiButton(ec.display.getFullyScaled(button), "Create custom Node")) {
ec.ui.getWindow(NODE_CREATOR)->openWindow();
ec.ui.getWindow(NODE_CREATOR)->toggleWindow();
}
}
inline void DrawWindows(EditorContext& ec) {
Expand Down
4 changes: 4 additions & 0 deletions src/raynodes/ui/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Window {
void openWindow() noexcept;
// Opens the window
void closeWindow() noexcept;
void toggleWindow() noexcept {
if (isWindowOpen) closeWindow();
else openWindow();
}

// Getters
[[nodiscard]] WindowType getType() const { return type; }
Expand Down
Loading

0 comments on commit a8a30e1

Please sign in to comment.