-
Notifications
You must be signed in to change notification settings - Fork 345
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] Multi instance support #174
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
monodop
commented
Jan 8, 2025
Comment on lines
-587
to
-668
Clay__WarningArray Clay__WarningArray_Allocate_Arena(int32_t capacity, Clay_Arena *arena) { | ||
size_t totalSizeBytes = capacity * sizeof(Clay_String); | ||
Clay__WarningArray array = {.capacity = capacity, .length = 0}; | ||
uintptr_t nextAllocAddress = arena->nextAllocation + (uintptr_t)arena->memory; | ||
uintptr_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String))); | ||
arenaOffsetAligned -= (uintptr_t)arena->memory; | ||
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) { | ||
array.internalArray = (Clay__Warning*)((uintptr_t)arena->memory + (uintptr_t)arenaOffsetAligned); | ||
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes; | ||
} | ||
else { | ||
Clay__errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { | ||
.errorType = CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED, | ||
.errorText = CLAY_STRING("Clay attempted to allocate memory in its arena, but ran out of capacity. Try increasing the capacity of the arena passed to Clay_Initialize()"), | ||
.userData = Clay__errorHandler.userData }); | ||
} | ||
return array; | ||
} | ||
|
||
Clay__WarningArray Clay_warnings = CLAY__DEFAULT_STRUCT; | ||
|
||
Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning item) | ||
{ | ||
if (array->length < array->capacity) { | ||
array->internalArray[array->length++] = item; | ||
return &array->internalArray[array->length - 1]; | ||
} | ||
return &CLAY__WARNING_DEFAULT; | ||
} | ||
|
||
void* Clay__Array_Allocate_Arena(int32_t capacity, uint32_t itemSize, uint32_t alignment, Clay_Arena *arena) | ||
{ | ||
size_t totalSizeBytes = capacity * itemSize; | ||
uintptr_t nextAllocAddress = arena->nextAllocation + (uintptr_t)arena->memory; | ||
uintptr_t arenaOffsetAligned = nextAllocAddress + (alignment - (nextAllocAddress % alignment)); | ||
arenaOffsetAligned -= (uintptr_t)arena->memory; | ||
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) { | ||
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes; | ||
return (void*)((uintptr_t)arena->memory + (uintptr_t)arenaOffsetAligned); | ||
} | ||
else { | ||
Clay__errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { | ||
.errorType = CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED, | ||
.errorText = CLAY_STRING("Clay attempted to allocate memory in its arena, but ran out of capacity. Try increasing the capacity of the arena passed to Clay_Initialize()"), | ||
.userData = Clay__errorHandler.userData }); | ||
} | ||
return CLAY__NULL; | ||
} | ||
|
||
bool Clay__Array_RangeCheck(int32_t index, int32_t length) | ||
{ | ||
if (index < length && index >= 0) { | ||
return true; | ||
} | ||
Clay__errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { | ||
.errorType = CLAY_ERROR_TYPE_INTERNAL_ERROR, | ||
.errorText = CLAY_STRING("Clay attempted to make an out of bounds array access. This is an internal error and is likely a bug."), | ||
.userData = Clay__errorHandler.userData }); | ||
return false; | ||
} | ||
|
||
bool Clay__Array_AddCapacityCheck(int32_t length, int32_t capacity) | ||
{ | ||
if (length < capacity) { | ||
return true; | ||
} | ||
Clay__errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { | ||
.errorType = CLAY_ERROR_TYPE_INTERNAL_ERROR, | ||
.errorText = CLAY_STRING("Clay attempted to make an out of bounds array access. This is an internal error and is likely a bug."), | ||
.userData = Clay__errorHandler.userData }); | ||
return false; | ||
} | ||
|
||
bool CLAY__BOOL_DEFAULT = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These needed to be moved below Clay_Context, otherwise the struct's fields are not available.
monodop
commented
Jan 8, 2025
monodop
commented
Jan 8, 2025
👀 |
St0wy
pushed a commit
to St0wy/clay
that referenced
this pull request
Jan 9, 2025
nicbarker
pushed a commit
that referenced
this pull request
Jan 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This appears to be working on my local branch, but maybe could use some more testing
TODO: