Misc intermediate fixes, more work on these to follow.

--Bug fixes:
-Fix crash when using smooth interpolation in EmberGenome.
-Print error and exit EmberGenome when sequencing if times are not
sorted.

--Code changes:
-Another attempt at Singleton. This reverts the design to what it was
before with a fix to the code that was causing it not to behave like a
singleton should.
This commit is contained in:
Matt Feemster
2016-04-21 15:33:00 -07:00
parent d639921d68
commit cac7308776
9 changed files with 45 additions and 57 deletions

View File

@ -440,15 +440,16 @@ public:
Align(&embers[i1], &localEmbers[0], 2);
smoothFlag = false;
}
if (i2 == size - 1)
else if (i2 == size - 1)
{
Align(&embers[i1], &localEmbers[0], 2);
smoothFlag = false;
}
Align(&embers[i1 - 1], &localEmbers[0], 4);//Should really be doing some sort of checking here to ensure the ember vectors have 4 elements.
smoothFlag = true;
else
{
Align(&embers[i1 - 1], &localEmbers[0], 4);//Should really be doing some sort of checking here to ensure the ember vectors have 4 elements.
smoothFlag = true;
}
}
result.m_Time = time;

View File

@ -193,16 +193,13 @@ private:
/// member variables cannot be exported across module boundaries.
/// Derived classes should inherit from this using the CRTP, and declare a friend to it.
/// They also should make their constructors private and destructors public.
/// This has a severe flaw in that it cannot be used across module boundaries, else
/// every module will have its own copy. This makes it function as a per-module
/// singleton, which is unlikely to ever be desired.
/// Attribution: This class is a combination of
/// http://btorpey.github.io/blog/2014/02/12/shared-singletons/
/// and
/// http://enki-tech.blogspot.com/2012/08/c11-generic-singleton.html
/// </summary>
template <class T>
class EMBER_API Singleton
class Singleton
{
public:
/// <summary>
@ -213,7 +210,7 @@ public:
template <typename... Args>
static shared_ptr<T> Instance(Args... args)
{
static weak_ptr<T> staticInstance;
auto& staticInstance = GetStaticInstance();
auto temp = staticInstance.lock();
if (!temp)
@ -224,6 +221,18 @@ public:
return temp;
}
protected:
/// <summary>
/// Clever hack to get a static to behave like a member variable that can be seen between classes and functions in the hierarchy.
/// Also has the added benefit that it makes this work across module boundaries.
/// </summary>
/// <returns>static weak_ptr reference</returns>
static std::weak_ptr<T>& GetStaticInstance()
{
static std::weak_ptr<T> staticInstance;
return staticInstance;
}
};
//Use this if the body of the destructor will be implemented in a cpp file.
@ -231,8 +240,6 @@ public:
friend class Singleton<x>; \
public: \
~x(); \
\
private: \
x(const x& other) = delete; \
const x& operator=(const x& other) = delete//Semicolon deliberately omitted to force it on the caller.
@ -241,33 +248,9 @@ public:
friend class Singleton<x>; \
public: \
~x(){} \
\
private: \
x(const x& other) = delete; \
const x& operator=(const x& other) = delete
//Use this if not deriving from the Singleton class and are declaring Instance() in a header and implementing it in a cpp file.
#define SINGLETON_INSTANCE_DECL(x) \
static std::shared_ptr<x> Instance(); \
x(const x& other) = delete; \
const x& operator=(const x& other) = delete//Semicolon deliberately omitted to force it on the caller.
//Use this if not deriving from the Singleton class and are implementing Instance() in a cpp file.
#define SINGLETON_INSTANCE_IMPL(x) \
std::shared_ptr<x> x::Instance() \
{ \
static weak_ptr<x> staticInstance; \
auto temp = staticInstance.lock(); \
\
if (!temp) \
{ \
temp.reset(new x()); \
staticInstance = temp; \
} \
\
return temp; \
}
/// <summary>
/// Open a file in binary mode and read its entire contents into a vector of bytes. Optionally null terminate.
/// </summary>

View File

@ -13,7 +13,7 @@ namespace EmberNs
/// This class is a singleton since all of its data is shared and read-only.
/// </summary>
template <typename T>
class EMBER_API VarFuncs
class EMBER_API VarFuncs : public Singleton<VarFuncs<T>>
{
public:
/// <summary>
@ -542,7 +542,7 @@ public:
}
}
SINGLETON_INSTANCE_DECL(VarFuncs);//Implemented in VariationList.cpp
SINGLETON_DERIVED_IMPL(VarFuncs<T>);
private:
/// <summary>

View File

@ -16,14 +16,6 @@ namespace EmberNs
m_Variations.push_back(new Pre##varName##Variation<T>()); \
m_Variations.push_back(new Post##varName##Variation<T>());
/// <summary>
/// Singleton patterns, return a reference to the only instance of this object in existence.
/// </summary>
template <typename T>
SINGLETON_INSTANCE_IMPL(VarFuncs<T>)
template <typename T>
SINGLETON_INSTANCE_IMPL(VariationList<T>)
/// <summary>
/// Constructor which initializes all of the variation objects and stores them in the list.
/// </summary>

View File

@ -18,10 +18,10 @@ namespace EmberNs
/// Template argument expected to be float or double.
/// </summary>
template <typename T>
class EMBER_API VariationList
class EMBER_API VariationList: public Singleton<VariationList<T>>
{
public:
~VariationList();
//~VariationList();
const Variation<T>* GetVariation(size_t index) const;
const Variation<T>* GetVariation(size_t index, eVariationType varType) const;
Variation<T>* GetVariationCopy(size_t index, T weight = 1) const;
@ -45,7 +45,7 @@ public:
const vector<Variation<T>*>& PreVars() const;
const vector<Variation<T>*>& PostVars() const;
SINGLETON_INSTANCE_DECL(VariationList);//Implemented in VariationList.cpp
SINGLETON_DERIVED_DECL(VariationList<T>);
private:
VariationList();