Open
Conversation
|
there has been a new community fork of this repository. the community is looking to add some new simple features. please feel free to try your PR over there. |
This file contains hidden or 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
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 PR is supposed to be a fix for:
Solution
The fix consists in storing commands in a
mu_stack(mu_Commands, ...)rather in amu_stack(char, ...).In order to achieve this
mu_TextCommands.strstrings are stored in a separate mu_stack(char, ...) calledctx->command_txt, so thatmu_Command(s)can be considered of fixed sizesizeof(mu_Command) = 32.Text command strings can still be accessed via
cmd->text.strwhich is now achar*that points to the buffer ofctx->command_txtwhich will end up containing a list of\0separated strings (i.e. the text commands contain a pointer to the beginning of the string). This stack is reset together withctx->command_listinsidemu_begin(...).The
mu_Commandunion was updated to fix #80 by making sure all command variants share the same initialtypefield.Advantages
char[1]and relying on an externalsizefield to keep track of how much you went out of bufferDrawbacks
1. More wasted space
ctx->commands_txtis extra wasted space (of 2048 bytes by default)Answer
I assumed that minimizing memory usage is a NOT priority for this library since a lot its type definitions use
intorvoid*rather than a 100% viable smaller version:mu_Command.typecould be auint8_tmu_Fontcould be auint8_tas the index of a global font info tablemu_Vec2andmu_Rectcould useint16_ts since they represent pixel coordinatesAlso all the rendered strings that are not changed during the execution have no reason to be copied into the command buffer (or any buffer) but could simply be referenced by pointer (this PR makes this potential
mu_draw_text_static(ctx, const char*)feature super easy to implement since themu_TextCommandnow uses achar *)Braking Changes
cmd->typeno longer works, usecmd->base.typeinstead