[examples] Possible improvements for text_codepoints_loading, adding ranges#4886
[examples] Possible improvements for text_codepoints_loading, adding ranges#4886raysan5 merged 4 commits intoraysan5:masterfrom
text_codepoints_loading, adding ranges#4886Conversation
A review of the code is required. Since I'm not sure what's written correctly at all.
| if (!cp) return GetFontDefault(); | ||
|
|
||
| // Helper function to add a range of Unicode codepoints | ||
| void AddRange(int start, int stop) |
There was a problem hiding this comment.
Nested functions are a GCC extension, so this should probably be moved out to a function like
// Return non-zero on error, maybe?
int AddCodeRange(int **codes, int *capacity, int *count, int start, int stop) {
// ...
}There was a problem hiding this comment.
Nested functions are a GCC extension, so this should probably be moved out to a function like
// Return non-zero on error, maybe? int AddCodeRange(int **codes, int *capacity, int *count, int start, int stop) { // ... }
Well, I don't know C well, and I didn't even know that.
|
|
||
| Font LoadUnicodeFont(const char* fileName, int fontSize, int textureFilter) | ||
| { | ||
| int* cp = NULL; // Array to store Unicode codepoints |
There was a problem hiding this comment.
I think a better name might be codes or codePoints.
There was a problem hiding this comment.
Yes, you're right, we need to give names more understandable meanings.
| // Expand array if needed | ||
| if (count >= capacity) | ||
| { | ||
| capacity += 1024; | ||
| int* newCp = (int*)realloc(cp, capacity * sizeof(int)); | ||
| if (!newCp) | ||
| { | ||
| free(cp); | ||
| return GetFontDefault(); | ||
| } | ||
| cp = newCp; | ||
| } |
There was a problem hiding this comment.
At a glance, I think the initial capacity of 65536 = 2^16 is big enough without resizing, since you're only adding code points smaller than 0xFFFF?
The creation of the array has been rewritten, the size of the example has been reduced
|
@GuvaCode thanks for the example, there is already a similar example, maybe some parts of this one can be moved to the existing one. I'll keep this PR open to check the parts that can be ported. |
text_codepoints_loading, adding ranges
text_codepoints_loading, adding rangestext_codepoints_loading, adding ranges
|
@GuvaCode I'm merging the example and I'll modify it as required. Thanks! |
A review of the code is required. Since I'm not sure what's written correctly at all.