This commit is contained in:
Thomas 2022-01-11 14:16:07 +01:00
parent 443a21d7ac
commit 9cd2593f47
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
4 changed files with 10 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#include <future>
#include <optional>
#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<nsGui::Sprite> sp;
mutable optional<nsGui::Sprite> sp;
/*!
* @brief load a sprite asynchronously

View File

@ -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<void> Task;
class PixelManager{
public:
MinGL& window;

View File

@ -12,6 +12,7 @@
#define GUARD_UTILS_H
#include<vector>
#include<future>
#include "mingl/mingl.h"
// hardcoded values
@ -49,9 +50,11 @@ enum class WinValue{
typedef nsGraphics::Vec2D Position;
typedef unsigned playerID;
typedef future<void> 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

View File

@ -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<nsGui::Sprite>(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<nsGui::Sprite>(outPixels, rowSize);
sp.emplace(outPixels, rowSize);
}