Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Replace generated arrays with macro declarations, align cache lines to 64 bytes #235

Merged
merged 6 commits into from
Jan 29, 2025
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
1,182 changes: 291 additions & 891 deletions clay.h

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/cpp-project-example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ int main(void) {
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, (char *)malloc(totalMemorySize));
Clay_Initialize(clayMemory, Clay_Dimensions {1024,768}, Clay_ErrorHandler { HandleClayErrors });
Clay_BeginLayout();
CLAY(CLAY_RECTANGLE({ .color = {255,255,255,0} }), CLAY_LAYOUT(layoutElement)) {}
CLAY(CLAY_RECTANGLE({ .color = {255,255,255,0} }), CLAY_LAYOUT(layoutElement)) {
CLAY_TEXT(CLAY_STRING(""), CLAY_TEXT_CONFIG({ .fontId = 0 }));
}
Clay_EndLayout();
return 0;
}
2 changes: 1 addition & 1 deletion examples/raylib-multi-context/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_include_directories(clay_examples_raylib_multi_context PUBLIC .)

target_link_libraries(clay_examples_raylib_multi_context PUBLIC raylib)

set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces -DCLAY_DEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "-O3")

add_custom_command(
Expand Down
20 changes: 10 additions & 10 deletions examples/raylib-multi-context/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void RenderHeaderButton(Clay_String text) {
CLAY_LAYOUT({ .padding = { 16, 16, 8, 8 }}),
CLAY_RECTANGLE({
.color = { 140, 140, 140, 255 },
.cornerRadius = 5
.cornerRadius = CLAY_CORNER_RADIUS(5)
})
) {
CLAY_TEXT(text, CLAY_TEXT_CONFIG({
Expand Down Expand Up @@ -79,7 +79,7 @@ typedef struct {
intptr_t memory;
} Arena;

Arena frameArena = {};
Arena frameArena = {0};

Clay_RenderCommandArray CreateLayout(Clay_Context* context, float yOffset, int32_t* documentIndex) {
Clay_SetCurrentContext(context);
Expand All @@ -104,13 +104,13 @@ Clay_RenderCommandArray CreateLayout(Clay_Context* context, float yOffset, int32
);

Clay_Sizing layoutExpand = {
.width = CLAY_SIZING_GROW(),
.height = CLAY_SIZING_GROW()
.width = CLAY_SIZING_GROW(0),
.height = CLAY_SIZING_GROW(0)
};

Clay_RectangleElementConfig contentBackgroundConfig = {
.color = { 90, 90, 90, 255 },
.cornerRadius = 8
.cornerRadius = CLAY_CORNER_RADIUS(8)
};

Clay_BeginLayout();
Expand Down Expand Up @@ -138,14 +138,14 @@ Clay_RenderCommandArray CreateLayout(Clay_Context* context, float yOffset, int32
.childGap = 8,
.sizing = {
.width = CLAY_SIZING_FIXED(250),
.height = CLAY_SIZING_GROW()
.height = CLAY_SIZING_GROW(0)
}
})
) {
for (int i = 0; i < documents.length; i++) {
Document document = documents.documents[i];
Clay_LayoutConfig sidebarButtonLayout = {
.sizing = { .width = CLAY_SIZING_GROW() },
.sizing = { .width = CLAY_SIZING_GROW(0) },
.padding = CLAY_PADDING_ALL(16)
};

Expand All @@ -154,7 +154,7 @@ Clay_RenderCommandArray CreateLayout(Clay_Context* context, float yOffset, int32
CLAY_LAYOUT(sidebarButtonLayout),
CLAY_RECTANGLE({
.color = { 120, 120, 120, 255 },
.cornerRadius = 8,
.cornerRadius = CLAY_CORNER_RADIUS(8),
})
) {
CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({
Expand All @@ -173,9 +173,9 @@ Clay_RenderCommandArray CreateLayout(Clay_Context* context, float yOffset, int32
Clay_Hovered()
? CLAY_RECTANGLE({
.color = { 120, 120, 120, 120 },
.cornerRadius = 8
.cornerRadius = CLAY_CORNER_RADIUS(8)
})
: 0
: (void)0
) {
CLAY_TEXT(document.title, CLAY_TEXT_CONFIG({
.fontId = FONT_ID_BODY_16,
Expand Down
2 changes: 1 addition & 1 deletion examples/raylib-sidebar-scrolling-container/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC ra
if(MSVC)
set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG")
else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCLAY_DEBUG -fsanitize=address")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
endif()

Expand Down
7 changes: 0 additions & 7 deletions generator/array_add.template.c

This file was deleted.

5 changes: 0 additions & 5 deletions generator/array_add_value.template.c

This file was deleted.

3 changes: 0 additions & 3 deletions generator/array_allocate.template.c

This file was deleted.

3 changes: 0 additions & 3 deletions generator/array_allocate_pointer.template.c

This file was deleted.

6 changes: 0 additions & 6 deletions generator/array_define.template.c

This file was deleted.

5 changes: 0 additions & 5 deletions generator/array_define_slice.template.c

This file was deleted.

3 changes: 0 additions & 3 deletions generator/array_get.template.c

This file was deleted.

3 changes: 0 additions & 3 deletions generator/array_get_slice.template.c

This file was deleted.

3 changes: 0 additions & 3 deletions generator/array_get_value.template.c

This file was deleted.

9 changes: 0 additions & 9 deletions generator/array_remove_swapback.template.c

This file was deleted.

6 changes: 0 additions & 6 deletions generator/array_set.template.c

This file was deleted.

69 changes: 0 additions & 69 deletions generator/generate_templates.js

This file was deleted.

4 changes: 2 additions & 2 deletions renderers/raylib/clay_renderer_raylib.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct
CustomLayoutElementType type;
union {
CustomLayoutElement_3DModel model;
};
} customData;
} CustomLayoutElement;

// Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
Expand Down Expand Up @@ -216,7 +216,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
float scaleValue = CLAY__MIN(CLAY__MIN(1, 768 / rootBox.height) * CLAY__MAX(1, rootBox.width / 1024), 1.5f);
Ray positionRay = GetScreenToWorldPointWithZDistance((Vector2) { renderCommand->boundingBox.x + renderCommand->boundingBox.width / 2, renderCommand->boundingBox.y + (renderCommand->boundingBox.height / 2) + 20 }, Raylib_camera, (int)roundf(rootBox.width), (int)roundf(rootBox.height), 140);
BeginMode3D(Raylib_camera);
DrawModel(customElement->model.model, positionRay.position, customElement->model.scale * scaleValue, WHITE); // Draw 3d model with texture
DrawModel(customElement->customData.model.model, positionRay.position, customElement->customData.model.scale * scaleValue, WHITE); // Draw 3d model with texture
EndMode3D();
break;
}
Expand Down
Loading