diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-04 14:02:27 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-04 14:02:27 +0100 |
commit | 17e296d059f09d47009f2427132af8f5f8e2f749 (patch) | |
tree | 8164cfa54670b76de42542ba9bbde6fc6d17ab17 /src | |
parent | 7a8657dfe019104aced61a5b63e63f61ad919f7a (diff) | |
parent | 210800c5fa71460d9cbcfff808a62cc07e0fdb7a (diff) |
Merge branch 'master' into loek/audio
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/Sprite.cpp | 4 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 11 | ||||
-rw-r--r-- | src/crepe/api/Texture.h | 13 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 26 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 22 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.h | 7 | ||||
-rw-r--r-- | src/doc/feature/scene.dox | 41 | ||||
-rw-r--r-- | src/doc/features.dox | 18 | ||||
-rw-r--r-- | src/doc/index.dox | 7 | ||||
-rw-r--r-- | src/doc/layout.xml | 10 | ||||
-rw-r--r-- | src/doc/style.css | 6 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 4 |
13 files changed, 104 insertions, 67 deletions
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 8647794..0a2ad4c 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -22,8 +22,8 @@ Sprite::Sprite(game_object_id_t id, Texture & image, const Color & color, dbg_trace(); - this->mask.w = sprite_image.get_width(); - this->mask.h = sprite_image.get_height(); + this->mask.w = sprite_image.get_size().x; + this->mask.h = sprite_image.get_size().y; this->aspect_ratio = static_cast<double>(this->mask.w) / this->mask.h; } diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index e43bdaa..2b56271 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -3,6 +3,7 @@ #include "Asset.h" #include "Texture.h" +#include "types.h" using namespace crepe; using namespace std; @@ -31,11 +32,7 @@ void Texture::load(const Asset & res) { this->texture = ctx.texture_from_path(res.get_path()); } -int Texture::get_width() const { - if (this->texture == nullptr) return 0; - return SDLContext::get_instance().get_width(*this); -} -int Texture::get_height() const { - if (this->texture == nullptr) return 0; - return SDLContext::get_instance().get_height(*this); +ivec2 Texture::get_size() const { + if (this->texture == nullptr) return {}; + return SDLContext::get_instance().get_size(*this); } diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h index 7206a66..1817910 100644 --- a/src/crepe/api/Texture.h +++ b/src/crepe/api/Texture.h @@ -8,6 +8,7 @@ #include <memory> #include "Asset.h" +#include "types.h" namespace crepe { @@ -42,16 +43,10 @@ public: Texture & operator=(const Texture &) = delete; /** - * \brief Gets the width of the texture. - * \return Width of the texture in pixels. + * \brief Gets the width and height of the texture. + * \return Width and height of the texture in pixels. */ - int get_width() const; - - /** - * \brief Gets the height of the texture. - * \return Height of the texture in pixels. - */ - int get_height() const; + ivec2 get_size() const; private: /** diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 9f60285..e8be7ca 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -1,4 +1,5 @@ #include <SDL2/SDL.h> +#include <SDL2/SDL_blendmode.h> #include <SDL2/SDL_image.h> #include <SDL2/SDL_keycode.h> #include <SDL2/SDL_rect.h> @@ -7,7 +8,9 @@ #include <SDL2/SDL_video.h> #include <cmath> #include <cstddef> +#include <cstdint> #include <functional> +#include <iostream> #include <memory> #include <stdexcept> @@ -18,6 +21,7 @@ #include "../util/Log.h" #include "SDLContext.h" +#include "api/Color.h" #include "types.h" using namespace crepe; @@ -134,6 +138,7 @@ void SDLContext::draw(const RenderContext & ctx) { SDL_Rect dstrect = this->get_dst_rect(ctx.sprite, ctx.pos, ctx.cam, ctx.cam_pos, ctx.scale); + this->set_color_texture(ctx.sprite.sprite_image, ctx.sprite.color); SDL_RenderCopyEx(this->game_renderer.get(), ctx.sprite.sprite_image.texture.get(), &srcrect, &dstrect, ctx.angle, NULL, render_flip); } @@ -207,16 +212,19 @@ SDLContext::texture_from_path(const std::string & path) { std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> img_texture; img_texture = {tmp_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; + SDL_SetTextureBlendMode(img_texture.get(), SDL_BLENDMODE_BLEND); return img_texture; } -int SDLContext::get_width(const Texture & ctx) const { - int w; - SDL_QueryTexture(ctx.texture.get(), NULL, NULL, &w, NULL); - return w; -} -int SDLContext::get_height(const Texture & ctx) const { - int h; - SDL_QueryTexture(ctx.texture.get(), NULL, NULL, NULL, &h); - return h; + +ivec2 SDLContext::get_size(const Texture & ctx) { + ivec2 size; + SDL_QueryTexture(ctx.texture.get(), NULL, NULL, &size.x, &size.y); + return size; } + void SDLContext::delay(int ms) const { SDL_Delay(ms); } + +void SDLContext::set_color_texture(const Texture & texture, const Color & color) { + SDL_SetTextureColorMod(texture.texture.get(), color.r, color.g, color.b); + SDL_SetTextureAlphaMod(texture.texture.get(), color.a); +} diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 6030a6e..e49ca78 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -12,6 +12,8 @@ #include "../api/Camera.h" #include "../api/Sprite.h" +#include "api/Color.h" +#include "api/Texture.h" #include "types.h" namespace crepe { @@ -104,18 +106,11 @@ private: std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture_from_path(const std::string & path); /** - * \brief Gets the width of a texture. + * \brief Gets the size of a texture. * \param texture Reference to the Texture object. - * \return Width of the texture as an integer. + * \return Width and height of the texture as an integer. */ - int get_width(const Texture & texture) const; - - /** - * \brief Gets the height of a texture. - * \param texture Reference to the Texture object. - * \return Height of the texture as an integer. - */ - int get_height(const Texture & texture) const; + ivec2 get_size(const Texture & ctx); private: //! Will use draw,clear_screen, present_screen, camera. @@ -160,6 +155,13 @@ private: */ SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam, const vec2 & cam_pos, const double & img_scale) const; + /** + * \brief Set an additional color value multiplied into render copy operations. + * + * \param texture the given texture to adjust + * \param color the color data for the texture + */ + void set_color_texture(const Texture & texture, const Color & color); private: //! sdl Window diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 0ad685c..92dba43 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -70,7 +70,7 @@ bool RenderSystem::render_particle(const Sprite & sprite, const Camera & cam, bool rendering_particles = false; for (const ParticleEmitter & em : emitters) { - if (!(&em.data.sprite == &sprite)) continue; + if (&em.data.sprite != &sprite) continue; rendering_particles = true; if (!em.active) continue; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index e70831e..096d058 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -46,7 +46,10 @@ private: * \brief Renders all the particles on the screen from a given sprite. * * \param sprite renders the particles with given texture - * \param tm the Transform component for scale + * \param tm the Transform component for scale. This is not a const reference because each + * particle has a position and rotation that needs to overwrite the transform position and + * rotation without overwriting the current transform. and because the transform + * constructor is now protected i cannot make tmp inside * \return true if particles have been rendered */ bool render_particle(const Sprite & sprite, const Camera & cam, const double & scale); @@ -68,13 +71,13 @@ private: RefVector<Sprite> sort(RefVector<Sprite> & objs) const; /** - * \todo Include color handling for sprites. * \todo Add text rendering using SDL_ttf for text components. * \todo Implement a text component and a button component. * \todo Consider adding text input functionality. */ private: + // FIXME: retrieve sdlcontext via mediator after #PR57 SDLContext & context = SDLContext::get_instance(); //! camera postion in the current scene diff --git a/src/doc/feature/scene.dox b/src/doc/feature/scene.dox index d81df4c..4124e37 100644 --- a/src/doc/feature/scene.dox +++ b/src/doc/feature/scene.dox @@ -6,10 +6,11 @@ namespace crepe { \ingroup feature \brief User-defined scenes -Scenes can be used to implement game environments, and allow arbitrary game objects to be organized -as part of the game structure. Scenes are implemented as derivative classes of Scene, which are -added to the game using the SceneManager. Scenes describe the start of a Scene and cannot modify -GameObjects during runtime of a Scene (use \ref feature_script "Scripting" for this purpose). +Scenes can be used to implement game environments, and allow arbitrary game +objects to be organized as part of the game structure. Scenes are implemented as +derivative classes of Scene, which are added to the game using the SceneManager. +Scenes describe the start of a Scene and cannot modify GameObjects during +runtime of a Scene (use \ref feature_script for this purpose). \see SceneManager \see GameObject @@ -18,19 +19,25 @@ GameObjects during runtime of a Scene (use \ref feature_script "Scripting" for t \par Example -This example demonstrates how to define and add scenes to the loop/scene manager in the `crepe` framework. -Each concrete scene should be derived from Scene. In the example below, the concrete scene is named MyScene. -A concrete scene should, at least, implement (override) two methods, namely load_scene() and get_name(). The -scene is build (using GameObjects) in the load_scene() method. GameObjects should be made using the -component_manager::new_object(). In the example below, two GameObjects (named object1 and object2) are added -to MyScene. object1 and object2 do not have any non-default Components attached to them, however, if needed, -this should also be done in load_scene(). Each concrete scene must have a unique name. This unique name is -used to load a new concrete scene (via a Script). The unique name is set using the get_name() method. In the -example below, MyScene's unique name is my_scene. -After setting up one or more concrete scene(s), the concrete scene(s) should be added to the loop/scene manager. -This is done in your main(). Firstly, the LoopManager should be instantiated. Than, all the concrete scene(s) -should be added to the loop/scene manger via loop_mgr::add_scene<>(). The templated argument should define the -concrete scene to be added. +This example demonstrates how to define and add scenes to the loop/scene manager +in the `crepe` framework. Each concrete scene should be derived from Scene. In +the example below, the concrete scene is named MyScene. A concrete scene should, +at least, implement (override) two methods, namely load_scene() and get_name(). +The scene is build (using GameObjects) in the load_scene() method. GameObjects +should be made using the component_manager::new_object(). + +In the example below, two GameObjects (named object1 and object2) are added to +MyScene. object1 and object2 do not have any non-default Components attached to +them, however, if needed, this should also be done in load_scene(). Each +concrete scene must have a unique name. This unique name is used to load a new +concrete scene (via a Script). The unique name is set using the get_name() +method. In the example below, MyScene's unique name is my_scene. + +After setting up one or more concrete scene(s), the concrete scene(s) should be +added to the loop/scene manager. This is done in your main(). Firstly, the +LoopManager should be instantiated. Than, all the concrete scene(s) should be +added to the loop/scene manger via loop_mgr::add_scene<>(). The templated +argument should define the concrete scene to be added. ```cpp #include <crepe/api/LoopManager.h> diff --git a/src/doc/features.dox b/src/doc/features.dox index 4786bed..21a040a 100644 --- a/src/doc/features.dox +++ b/src/doc/features.dox @@ -1,10 +1,28 @@ // vim:ft=doxygen /** +\htmlonly +<style> +table.memberdecls { display: none; } +ul { margin: 1ex 0pt; } +</style> +\endhtmlonly + \defgroup feature Features \brief Engine components This page lists engine features and contains usage instructions for each feature. +\par Features + +- Scripting + - \ref feature_script \n\copybrief feature_script + +- Game flow management + - \ref feature_scene \n\copybrief feature_scene + +- Entity + - \ref feature_gameobject \n\copybrief feature_gameobject + */ diff --git a/src/doc/index.dox b/src/doc/index.dox index 5ec7889..7796f34 100644 --- a/src/doc/index.dox +++ b/src/doc/index.dox @@ -8,3 +8,10 @@ Welcome to the documentation for the crêpe game engine. \see feature */ + +/** + +\namespace crepe +\brief Engine namespace + +*/ diff --git a/src/doc/layout.xml b/src/doc/layout.xml index fb4cc0c..6336655 100644 --- a/src/doc/layout.xml +++ b/src/doc/layout.xml @@ -11,7 +11,7 @@ <tab type="modulelist" visible="yes" title="" intro=""/> <tab type="modulemembers" visible="yes" title="" intro=""/> </tab> - <tab type="namespaces" visible="no" title=""> + <tab type="namespaces" visible="yes" title=""> <tab type="namespacelist" visible="yes" title="" intro=""/> <tab type="namespacemembers" visible="yes" title="" intro=""/> </tab> @@ -56,10 +56,10 @@ <interfaces title=""/> <publicslots title=""/> <signals title=""/> - <publicmethods title=""/> - <publicstaticmethods title=""/> <publicattributes title=""/> <publicstaticattributes title=""/> + <publicmethods title=""/> + <publicstaticmethods title=""/> <protectedtypes title=""/> <protectedslots title=""/> <protectedmethods title=""/> @@ -102,11 +102,12 @@ </class> <namespace> <briefdescription visible="yes"/> + <detaileddescription title=""/> <memberdecl> <nestednamespaces visible="yes" title=""/> <constantgroups visible="yes" title=""/> <interfaces visible="yes" title=""/> - <classes visible="yes" title=""/> + <classes visible="no" title=""/> <concepts visible="yes" title=""/> <structs visible="yes" title=""/> <exceptions visible="yes" title=""/> @@ -119,7 +120,6 @@ <properties title=""/> <membergroups visible="yes"/> </memberdecl> - <detaileddescription title=""/> <memberdef> <inlineclasses title=""/> <typedefs title=""/> diff --git a/src/doc/style.css b/src/doc/style.css index daabd39..c12240c 100644 --- a/src/doc/style.css +++ b/src/doc/style.css @@ -1,6 +1,6 @@ #titlearea, -address { - display: none; -} +address, +a[href="namespaces.html"] +{ display: none; } h2.groupheader { margin-top: revert; } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 3a12144..349d11e 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -28,7 +28,7 @@ int main(int argc, char * argv[]) { ParticleSystem psys{mgr}; AnimatorSystem asys{mgr}; - Color color(255, 255, 255, 255); + Color color(255, 255, 255, 100); auto img = Texture("asset/texture/test_ap43.png"); Sprite & test_sprite = game_object.add_component<Sprite>( @@ -59,7 +59,7 @@ int main(int argc, char * argv[]) { }); */ - auto & cam = game_object.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, + auto & cam = game_object.add_component<Camera>(Color::RED, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f); /* |