diff --git a/headers/mySprite.h b/headers/mySprite.h index 3f83c04..b2a67a1 100644 --- a/headers/mySprite.h +++ b/headers/mySprite.h @@ -4,7 +4,7 @@ #include #include #include "mingl/gui/sprite.h" -#include "pixelManager/pixelManager.h" +#include "utils.h" using namespace std; @@ -13,8 +13,11 @@ public: /*! * @brief optional actual Sprite * We need to use an optional to init the object through a function, that can be used with std::async + * mutable because for some reason MinGL stores a Vec2D with the pixel data, + * so we modify it each time we need to draw it + * Else, we could copy the Sprite each time, but copying a bunch of images each frame doesn't seems like a good idea */ - optional sp; + mutable optional sp; /*! * @brief load a sprite asynchronously diff --git a/headers/pixelManager/pixelManager.h b/headers/pixelManager/pixelManager.h index 3baa9ae..06894b7 100644 --- a/headers/pixelManager/pixelManager.h +++ b/headers/pixelManager/pixelManager.h @@ -44,9 +44,6 @@ typedef nsGui::GlutFont::GlutFonts Font; #define ADD_SPRITE_TASK(X) ADD_SPRITE_TASK2(X, X) #define ADD_SPRITE_TASK2(X, Y) tasks.push_back((X).asyncLoad("assets/"#Y".si2")); -typedef future Task; - - class PixelManager{ public: MinGL& window; diff --git a/headers/utils.h b/headers/utils.h index b0d4f84..fb08df9 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -12,6 +12,7 @@ #define GUARD_UTILS_H #include +#include #include "mingl/mingl.h" // hardcoded values @@ -49,9 +50,11 @@ enum class WinValue{ typedef nsGraphics::Vec2D Position; typedef unsigned playerID; +typedef future Task; #define PLAYER1 0 #define PLAYER2 1 + /*! * @brief tells if 2 lines are colliding in a 1 dimensional space. Didn't want to use Position because of the semantic with x and y * @param[in] start1 : position of the first point of the first line diff --git a/src/mySprite.cpp b/src/mySprite.cpp index c15c1c2..614f26e 100644 --- a/src/mySprite.cpp +++ b/src/mySprite.cpp @@ -4,7 +4,7 @@ Task MySprite::asyncLoad(const string& fname){ DEBUG_MSG("Load file " << fname) return std::async(std::launch::async, [fname, this]() -> void { - sp = std::make_unique(fname); + sp.emplace(fname); }); } @@ -23,5 +23,5 @@ void MySprite::mirror(MySprite& msp) { outPixels.push_back(inPixels[rowOffset + rowSize - j - 1]); } } - sp = std::make_unique(outPixels, rowSize); + sp.emplace(outPixels, rowSize); }