Skip to content

v0.5.0

Latest
Compare
Choose a tag to compare
@cemderv cemderv released this 21 Oct 14:52
· 2 commits to main since this release
a3df702

This release adds a 2D particle system to cerlib and focuses on optimizing all-around code, build times and reducing dependencies to third-party libraries.

particles

Changes

Particle systems

  • New types:
    • Particle
    • ParticleEmitter
    • ParticleModifier
      • With many built-in modifiers
    • ParticleSystem
    • Interval
  • New function cer::draw_particles

Immutable text objects

For some scenarios, text-shaping might be too expensive, for example when thousands of strings are drawn within a single frame. To allow the user to cache text-shaping results, a new class cer::Text is introduced. Text objects are strings that are shaped immediately upon construction and are immutable afterwards. They follow standard object semantics, meaning that they support automatic memory management via reference counting.

Additionally, a new function cer::draw_text is added that is capable of drawing cer::Text objects.

Example:

// once:
my_text = cer::Text{"Hello World!", my_font, my_font_size, ...};

// every frame:
cer::draw_text(my_text, text_position, text_color);

Content management

Content functions cer::load* were replaced by individual constructors.
This improves consistency across cerlib's API and makes construction of resources easier. Example:

auto img = cer::load_image("MyImage.png");
auto shader = cer::load_shader("MyShader.shd");
auto font = cer::load_font("MyFont.ttf");
auto sound = cer::load_sound("MySound.wav");

Now becomes:

auto img = cer::Image{"MyImage.png"};
auto shader = cer::Shader{"MyShader.shd"};
auto font = cer::Font{"MyFont.ttf"};
auto sound = cer::Sound{"MySound.wav"};

The semantics remain the same, which implies that multiple objects with the same asset path refer to the same internal object and therefore share the reference count. Once all objects that reference the asset are destroyed, the asset itself is unloaded from memory.

Simplified game creation

Previously, a game had to specify its source files in its CMake script. Example:

cerlib_add_executable(
  NAME MyGame
  ...
  FILES Main.cpp MyGame.hpp ...
)

The FILES parameter is now removed, and was replaced by automatic source file inclusion. The game folder is now expected to contain a src folder that contains all of its source files. These are then picked up automatically.

Reduced complexity

Many third-party dependencies of cerlib are now directly integrated into the codebase, such as SoLoud, ImGui, GSL and utf8cpp.

SoLoud in particular was reduced in code complexity and size, while simultaneously undergoing a C++ modernization process. This resulted in over 200k lines of code being removed and a number of use-after-free and out-of-bounds bugs being fixed. SoLoud is now part of the cerlib code in the form of a heavily-modified version. Its API will be provided in public headers in upcoming releases (issue #4).

Other dependencies underwent a similar process, with similar results.

Additionally, SDL3 is now fetched as a prebuilt library when it is available for the current platform, compiler and architecture combination. The prebuilt libraries are fetched from a separate repository.

This change reduces build times by a factor of 2-3. Building SDL3 alongside cerlib is still supported using the new CMake option CERLIB_FORCE_SDL_BUILD, which is off by default.

cerlib is now built with precompiled headers enabled.

Miscellaneous

Added a new macro defer that allows to perform an arbitrary action at the end of a scope. Example:

void my_function()
{
  defer
  {
    // some code that is always executed at the end of the function's scope
  };

  // some code
}
  • Updated SDL to version 3.1.3
  • cerlib is now static-library-only
  • New type List that serves as a replacement for std::vector
    • List is a vector-like container that enables small-buffer optimizations
    • It is based on gch::small_vector
  • New function cer::squared
  • New fastrand random number generation functions
  • New color constant cer::transparent
  • New operator operator+(Color, Color)
  • New operator operator-(Color, Color)
  • Moved inline math code to .cpp files
  • Changed built-in blend states to constexpr variables
    • e.g. BlendState::opaque() now becomes cer::opaque
  • Changed built-in samplers to constexpr variables
    • e.g. Sampler::point_repeat() now becomes cer::point_repeat
  • Audio can now be disabled at runtime using an environment variable
    • e.g. export CERLIB_DISABLE_AUDIO=1
  • Removed RelWithDebInfo and MinSizeRel CMake configurations
  • New type cer::VariantSwitch
  • cerlib now compiles with GCC 11 and 12
  • Improved documentation
  • Fixed a bug with underlined text drawing, where a wrong line width was used
  • Removed mipmaps, since they are a mostly 3D feature and could confuse users

Full Changelog: v0.4.0...v0.5.0