randygaul / cute_framework Goto Github PK
View Code? Open in Web Editor NEWThe *cutest* framework out there for creating 2D games in C++!
Home Page: https://randygaul.github.io/cute_framework/#/
License: Other
The *cutest* framework out there for creating 2D games in C++!
Home Page: https://randygaul.github.io/cute_framework/#/
License: Other
The m3x2 is multiplied upon batch_flush, but, it should be multiplied within each PUSH_TRI macro
Confusing as they aren't geometry shaders :P
This setup tutorial is for anyone unfamiliar with cmake to build C++ projects. We will go through some steps to have cmake setup Cute Framework (CF) to build along with your game project.
Writing your own CmakeLists.txt file will be pretty difficult as a beginner, so instead I really recommend to copy my list file from the example game Cute Snake here. Go ahead and rename things from snake
to your own game's name.
add_executable
you can list out all of your source code.set(CUTE_FRAMEWORK_STATIC ON)
from ON to OFF.target_include_directories
tells cmake where your source code is. For Cute Snake I have it set to the src
folder.Here are the steps to follow to build your game.
target_include_directories
in your CmakeLists.txt points to the folder you've placed all your source code into (e.g. a src
folder).build_msvc_2019
. This is where cmake will store your generated build files.cmake -G "Visual Studio 16 2019" -A x64 -Bbuild_msvc_2019 .
And that's it! Your visual studio solution has been generated for version 2019. For other versions of visual studio you will want to use slightly different cmake commands. Here are some I have used in the past.
cmake -G "Visual Studio 14 2015" -A x64 -Bbuild_msvc_2015 .
cmake -G "Visual Studio 15 2017" -A x64 -Bbuild_msvc_2017 .
cmake -G "Visual Studio 16 2019" -A x64 -Bbuild_msvc_2019 .
cmake -G "Visual Studio 17 2022" -A x64 -Bbuild_msvc_2022 .
You can also generate your build for makefiles, or even other types of build systems. Here's a bunch of information about various kinds of builds if you're not using visual studio.
Building your game can be done in a bunch of ways. If you're using visual studio I recommend to open up your solution and build it from within visual studio. It will be in your build_msvc_20XX
folder. You can optionally have cmake do your build from the command line with cmake --build build_msvc_20XX
.
If you're stuck I highly recommend downloading a copy of Cute Snake to see as a reference. For Windows users you can simply click on the msvc2019.cmd batch file if you're using Visual Studio 2019, and the script is trivial to modify for other Visual Studio versions.
If this seems overwhelming or you still need help I recommend asking for help here in a GitHub Issue, or hopping onto the CF discord server to ask for help.
Just use a static app context pointer -- nobody will ever use more than one app. No need to force it into the API everywhere. Credit to @apirux for the idea.
app_register_entity_type
breaks if called twice with the same entity
errors need codes also
stuck on with d3d11, super annoying
accidentally disabled gl via macros so it doesn't work on windows -- needs mainly a macro fix (probably just in cute_defines.h) -- has implications for the shaders and app_init flags
There's a mismatch in the APIs on make_xxx vs xxx_make and create_xxx vs xxx_create functions. Should just stick with one verb and one convention. I'm leaning towards make_xxx. Just be consistent.
https://github.com/RandyGaul/cute_framework/blob/master/include/cute_math.h
References to c2 need to be updated. c2 is not user-facing in CF, and cute_math.h should reference only itself in the comment docs.
expose app context pointer
audit code and look for other breakage points, such as function pointers or other statically stored pointers
provide a reset all routine to patch in new pointers
Super annoying but error_t is defined in error_t.h, so anyone doing using namespace cute
will have this problem, or also C people will have this proplem. A good solution would be to rename cute::error_t
to cute:err_t
, which should also work well in C mode.
not error_t
happens in cmake -- but, users will want this to happen in a header (which has not yet been written)
add this
struct entity_config_t
{
const char* entity_name;
array<const char*> component_types;
};
void app_register_entity_type(app_t* app, entity_config_t entity_config);
N being number of entities -- needs doc update -- add a note about it
bool is hacked into kv as a string "true" or false" requiring quotes to be present
should be natively supported as simply true
or false
when serialized
this would require a small refactor and extra parsing, but, definitely worth it
rename without app_
append with ecs_ probably
cute_math_2d.h -> cute_math ?
cute_math.h -> cute_collision ?
high dpi flag should probably be exposed to app options
needs to be documented -- seems mostly just relevant to apple devices?
Converting cute_framework headers to be C compatible, while leaving an optional namespaced C++ API in place.
cf_
#ifdef CUTE_CPP
cf_
prefixed types inside namespaces with their original short nameusing
statements with typedef
sextern "C"
#ifdef CUTE_NO_CPP
to cute_defines.h
for C-only mode when compiling as C++Notes from discord chat
[10:20 PM] Randy: The main problem would be the usage of templated data structures in the implementation of some of the features, like the serialization and the ECS
[10:21 PM] Randy: However, it's possible to compile a C interface and leave the implementation using some C++
[10:21 PM] Randy: Then the main pain point is just some of the templated stuff in the API, but it's not too much
[10:21 PM] Limyc: I'm mostly interested in a c interface, and if it's just some grunt work, I might just do it
[10:22 PM] Randy: It's not a big deal to write C versions of function overloads and whatnot
[10:22 PM] Randy: I would absolutely support you here. I would do it myself, but priorities dictate I work on the other things first, like docs and bugs
[10:22 PM] Randy: So if you do it, that would super awesome
[10:25 PM] Limyc: is there a particular way you would want the interface work done?
[10:26 PM] Randy: https://github.com/RandyGaul/cute_headers/blob/master/cute_sound.h
GitHub
[cute_headers/cute_sound.h at master · RandyGaul/cute_headers](https://github.com/RandyGaul/cute_headers/blob/master/cute_sound.h)
Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games - cute_headers/cute_sound.h at master · RandyGaul/cute_headers
cute_headers/cute_sound.h at master · RandyGaul/cute_headers
[10:27 PM] Randy: This is a pretty good way to create C versions without default arguments
[10:27 PM] Randy:
cs_audio_source_t* cs_load_wav(const char* path, cs_error_t* err /* = NULL */);
cs_audio_source_t* cs_read_mem_wav(const void* memory, size_t size, cs_error_t* err /* = NULL */);
[10:27 PM] Randy: In each header you can #ifdef __cplusplus the C++ header, and in the #else have the C versions
[10:28 PM] Randy: For overloaded functions you can append 2 to the name
[10:28 PM] Randy: Should probably also have a macro to force C-only as an optional macro
[10:29 PM] Limyc: Would you want to keep the namespaced C++ functions wrapped with #ifdef _cplusplus, and those just call into the cf_* functions?
[10:29 PM] Randy: Yeah I think that's a good way to do it
[10:29 PM] Randy: In the places where an array<T> is returned there's a few options on what to do
[10:30 PM] Randy: We can probably discuss those case-by-case
[10:33 PM] Randy: cute_string.h should probably not have a C version at all
[10:33 PM] Randy: I see array<T> in cute_ecs.h and cute_https.h
[10:33 PM] Randy: but those should be easy to change to a C-style implementation
[10:35 PM] Randy: Overall it's a straightforward port to C
[10:35 PM] Limyc: okay, so globals, functions, types all get cf_
overloads get a numerical postfix.
keep the namespaced functions wrapped by an ifdef
deal with templates on a case-by-case basis
[10:35 PM] Randy: sounds pretty good
[10:35 PM] Randy: And ask questions if you need help with anything, we can always discuss things if you're unsure which option to take
[10:37 PM] Limyc: do you want to alias types inside the cpp namespace for convenience and not breaking anyone who updates?
namespace cute {
using ecs_entity_t = cf_ecs_entity_t;
}
[10:37 PM] Randy: yeah that's a good idea
[10:38 PM] Randy: that works well
[10:38 PM] Randy: Probably the big one here would be the sprite
[10:39 PM] Randy: https://github.com/RandyGaul/cute_framework/blob/master/include/cute_handle_table.h
[10:39 PM] Randy: Here's a similar example to how the sprite can be implemented. The C version is the "main" version and the C++ one just calls into the C functions and holds the struct instance
[10:40 PM] Randy: But the sprite would still just be POD style as opposed to the handle_table is heap allocated
cute_framework depends on minicoro now, instead of cute_coroutine.h in cute_headers.
Noel Berry has a good abstraction for time that provides super useful functions for time based events like on_interval
. It's also a great abstraction for supporting fixed timestep as well.
play_sound needs to return instances
instances need modulation in real time, especially the sample index
lifetime management needs to be well thought through
This is a lot more beginner friendly than mounting nothing. Also some documentation page about mounting is necessary. This is a crucial first-step for everyone learning how to use CF and needs to be extremely streamlined.
The docs are unclear that in order to draw stuff using a png_cache, you must call make_batch(png_cache_get_pixels_fn(my_png_cache), my_png_cache)
create a custom batch_t
.
If you fail to create the custom batcher and just use sprite_get_batch()
like I did, you'll get an error in the console when attempting to draw a sprite inside a png_cache_t
. The error is "Aseprite cache -- unable to find id <img_id>"
Supporting use case of multiple batches is making less sense, and API suffers for it
8:43 PM] Limyc: How can I check if I'm going to overflow the sg_buffer with the current batch? I'm rendering circles using batch_circle_line and I assert when I hit around 171 circles using an iter count of 10. It asserts at lower circle counts if I draw higher resolution circles.
sg_append_buffer: overall appended size is bigger than buffer size
[8:44 PM] Randy: https://github.com/RandyGaul/cute_framework/blob/master/src/cute_batch.cpp#L391
[8:44 PM] Randy: it's hard coded for now
[8:45 PM] Randy: Feel free to add a simple function to adjust or get the buffer size
[8:50 PM] Limyc: okay, so for now, there's no way to check if adding something to the batch will exceed the buffer size. I'll need to write that myself
[8:51 PM] Limyc: Would it make sense for CF to split batches up automatically if they are too big?
[8:51 PM] Randy: https://github.com/RandyGaul/cute_framework/blob/master/src/cute_gfx.cpp#L120-L141
[8:51 PM] Randy: Well sokol_gfx is supposed to be dropping draw calls silently if you overflow
[8:52 PM] Randy: But maybe sokol_gfx was changed
[8:52 PM] Randy: And added that nice error message you found
[8:54 PM] Limyc: looks like you can define SOKOL_VALIDATE_NON_FATAL to silently drop overflowed calls
[8:54 PM] Randy: ah that sounds new to me
[8:54 PM] Randy: the perks of using actively maintained software 🙂
[8:56 PM] Limyc: Validation starts here: https://github.com/RandyGaul/cute_framework/blob/master/libraries/sokol/sokol_gfx.h#L15465
And asserts here: https://github.com/RandyGaul/cute_framework/blob/master/libraries/sokol/sokol_gfx.h#L13690
[8:56 PM] Limyc: Should I make an issue for this? If so, what exactly?
[8:57 PM] Randy: Make a pull request
[8:57 PM] Randy: Unless you want me to try and change things
[8:58 PM] Randy: Then go ahead and make an issue, you can just screenshot our convo here, or post in the relevant details
[9:00 PM] Limyc: okay, I'll make an issue then. I think it's worth considering friendlier ways to detecting and handling overflows instead of dropping the draw calls silently.
[9:01 PM] Limyc: I'm not sure how I'd use triple_buffer_append as the public CF api currently stands, and maybe that's the solution and there's just missing docs or an example
[9:02 PM] Randy: the triple_buffer_apped is lower level
[9:02 PM] Randy: you shouldn't have to deal with it directly when using the batch api
[9:02 PM] Randy: I think not silently dropping the calls is a good thing
[9:03 PM] Randy: Just need to expose a getter/setter for the buffer size
[9:04 PM] Limyc: yeah, I'd rather have the assert than not. What's missing is an easy way to detect the overflow at draw time and handle it
Try to building cute_framework on my macOS 12.4,the 3.0 version mbedtls will make "parameter 'output_size' set but not used" error,upgrade to the newer 3.1 will fix it(set GIT_TAG to v3.1.0).
Makes build script a bit simpler and repo size smaller
would be great to have cute framework compile from source without any dependencies in the minimal case. Not everyone wants networking features, and some people will want to use their own platform code
https://github.com/RandyGaul/cute_framework/blob/master/src/cute_hashtable.cpp#L152-L182
Should use s_next_prime
.
consider making it global
would solve some naming considerations for function prefixes
Higher level abstraction around CF coroutines is in the making. I have it sketched out but need to work on implementation at some point, but this requires proper dog-fooding and vetting first. Making this issue so it doesn't get lost. It will basically be the unrestricted and refined version of the routine macros referenced here #54 complete with a verb + adjective lego-style building blocks for more complex behaviors and finite state machines.
miniphysfs is superior due to build script simplification
libsodium is kinda big, this one looks like a smaller version, needs more investigation though https://github.com/jedisct1/libhydrogen
Currently CF drops draw calls if too much data is requested to be sent to the GPU and issues a printed warning to stderr. This should work fairly well for development, but, an alternative may be much better.
Instead of dropping the draw call the vertices can be stored on the CPU in temporary memory, to be flushed to the GPU later. This would allow the entire system to handle temporary stalls in framerate, and simply render things a bit slower until the GPU catches up. The temporary overflow buffer can also fill up, at which point the entire CPU needs to hang and wait for the GPU, and a loud warning can be printed that to explain how the entire process is simply GPU bound.
ifdef out the C++ features
This is important for ABI stability and ease of language bindings
Use or expose scancodes as well so can pick physical layout — use case example: WASD for movement but user isn’t using QWERTY, needs to be a physical mapping.
Not sure how I want to do this. Need to think it through more.
should probably destroy entities in flipped order compared to init -- at least, call the callbacks in reverse order
in cute_ecs.h
param structs should have a consistent naming
params_t
config_t
or just _t
needs to be consistent
In collab with Noel Berry there's a nice implementation of these routine macros super useful for basic AI/behaviors or cutscenes. It can basically be copy + pasted into CF as-is and provides a cross-platform alternative to CF coroutines
https://gist.github.com/RandyGaul/208bfe2cb3265f640019a62ab8e2e273
Right now the cmake options to turn off cryptography aren't implemented. This feature is a nice-to-have to simplify builds for non-networked games, or games that just don't want to deal with the cryptography dependency (even though it's not external).
https://github.com/lecram/gifenc
Would involve async callbacks for GPU readback and some platform dependence for screen capture: floooh/sokol#282
Hi RandyGaul
I created online documentation for cute_framework, using docsify.js, and customized the theme, and it looks pretty good,
The cute_framework doc online address is here, if you think it's ok, I'll be happy to pull request
C:\Users\randy\Documents\projects\cute_framework\build>block_man
Assertion failed: !CUTE_STRCMP(buf, "Debug") || !CUTE_STRCMP(buf, "Release"), file C:/Users/randy/Documents/projects/cute_framework/block_man/world.cpp, line 473
and
All 72 tests ←[32mPASSED←[0m.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.