aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-31 18:11:35 +0100
committerdec05eba <dec05eba@protonmail.com>2018-10-31 18:11:36 +0100
commit07c9e3d393db4b4d59262f7d9898be169ac2f927 (patch)
tree2623fbfd1c1614c2de575437cb89a787e93d8c1d
parenta5e2adedf38f84a8be5e8d844e02991d3bbfecca (diff)
Make generic
m---------depends/odhtdb0
-rw-r--r--include/dchat/Cache.hpp2
-rw-r--r--include/dchat/Gif.hpp6
-rwxr-xr-xinclude/dchat/utils.hpp6
-rw-r--r--src/Cache.cpp7
-rw-r--r--src/Gif.cpp13
6 files changed, 25 insertions, 9 deletions
diff --git a/depends/odhtdb b/depends/odhtdb
-Subproject 55bb14a7e0d034b375da73a9c2aae10881e3280
+Subproject e2eb4f72050a297668850deed91cc88860b6ad4
diff --git a/include/dchat/Cache.hpp b/include/dchat/Cache.hpp
index debcd5b..62df621 100644
--- a/include/dchat/Cache.hpp
+++ b/include/dchat/Cache.hpp
@@ -3,6 +3,7 @@
#include "types.hpp"
#include "WebPagePreview.hpp"
#include "StringView.hpp"
+#include "utils.hpp"
#include <boost/filesystem/path.hpp>
#include <string>
#include <unordered_map>
@@ -64,6 +65,7 @@ namespace dchat
class Cache
{
+ DISABLE_COPY(Cache)
public:
// @createGifFunc can't be nullptr
Cache(CreateGifFunc createGifFunc);
diff --git a/include/dchat/Gif.hpp b/include/dchat/Gif.hpp
index f97ff2f..9e39473 100644
--- a/include/dchat/Gif.hpp
+++ b/include/dchat/Gif.hpp
@@ -28,16 +28,13 @@ namespace dchat
virtual ~Gif();
Vec2u getSize() const;
+ // Throws GifLoadException on error
void update();
static bool isDataGif(const StringView &data);
protected:
// Return false if texture creation failed
virtual bool createTexture(int width, int height) = 0;
- virtual void setPosition(const Vec2f &position) = 0;
- virtual Vec2f getPosition() const = 0;
- virtual void setScale(const Vec2f &scale) = 0;
- virtual void setColor(Color color) = 0;
// Size of texture data is same as the size that the texture was created with (also same size returned by @getSize function)
virtual void updateTexture(void *textureData) = 0;
private:
@@ -48,5 +45,6 @@ namespace dchat
unsigned int currentFrame;
double timeElapsedCs;
Clock frameTimer;
+ bool created;
};
}
diff --git a/include/dchat/utils.hpp b/include/dchat/utils.hpp
new file mode 100755
index 0000000..01e478d
--- /dev/null
+++ b/include/dchat/utils.hpp
@@ -0,0 +1,6 @@
+#pragma once
+
+// Disable copying for a class or struct
+#define DISABLE_COPY(ClassName) \
+ ClassName(ClassName&) = delete; \
+ ClassName& operator = (ClassName&) = delete;
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 712a716..8657371 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -286,6 +286,8 @@ namespace dchat
checkContentAccessTimeThread = thread([this]
{
+ // TODO: Add this back
+ #if 0
while(alive)
{
this_thread::sleep_for(chrono::milliseconds(500));
@@ -323,6 +325,7 @@ namespace dchat
++it;
}
}
+ #endif
});
}
@@ -331,7 +334,8 @@ namespace dchat
alive = false;
downloadWaitThread.join();
checkContentAccessTimeThread.join();
-
+ // TODO: Add this back
+ #if 0
for(auto &it : contentUrlCache)
{
if(!it.second.textureFilePath)
@@ -362,6 +366,7 @@ namespace dchat
break;
}
}
+ #endif
}
static void createFileIgnoreError(const boost::filesystem::path &path)
diff --git a/src/Gif.cpp b/src/Gif.cpp
index 2391872..983030c 100644
--- a/src/Gif.cpp
+++ b/src/Gif.cpp
@@ -81,7 +81,8 @@ namespace dchat
Gif::Gif(StringView _fileContent) :
fileContent(move(_fileContent)),
currentFrame(0),
- timeElapsedCs(0.0)
+ timeElapsedCs(0.0),
+ created(false)
{
try
{
@@ -120,9 +121,6 @@ namespace dchat
}
}
while(code != GIF_OK);
-
- if(!createTexture(gif.width, gif.height))
- throw GifLoadException("Failed to create texture for gif");
}
Gif::~Gif()
@@ -138,6 +136,13 @@ namespace dchat
void Gif::update()
{
+ if(!created)
+ {
+ created = true;
+ if(!createTexture(gif.width, gif.height))
+ throw GifLoadException("Failed to create texture for gif");
+ }
+
double timeElapsedMilli = (double)frameTimer.getElapsedTimeMillis();
// If gif is not redrawn for a while, then we reset timer (gif is paused). This happens when gif is not visible and then appears visible
// (because it's visible in window). The reason this is done is to prevent too much time between rendering gif frames, as processing a gif