mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-04-09 12:31:39 -04:00
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:
parent
d639921d68
commit
cac7308776
@ -440,15 +440,16 @@ public:
|
|||||||
Align(&embers[i1], &localEmbers[0], 2);
|
Align(&embers[i1], &localEmbers[0], 2);
|
||||||
smoothFlag = false;
|
smoothFlag = false;
|
||||||
}
|
}
|
||||||
|
else if (i2 == size - 1)
|
||||||
if (i2 == size - 1)
|
|
||||||
{
|
{
|
||||||
Align(&embers[i1], &localEmbers[0], 2);
|
Align(&embers[i1], &localEmbers[0], 2);
|
||||||
smoothFlag = false;
|
smoothFlag = false;
|
||||||
}
|
}
|
||||||
|
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;
|
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;
|
result.m_Time = time;
|
||||||
|
@ -193,16 +193,13 @@ private:
|
|||||||
/// member variables cannot be exported across module boundaries.
|
/// member variables cannot be exported across module boundaries.
|
||||||
/// Derived classes should inherit from this using the CRTP, and declare a friend to it.
|
/// 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.
|
/// 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
|
/// Attribution: This class is a combination of
|
||||||
/// http://btorpey.github.io/blog/2014/02/12/shared-singletons/
|
/// http://btorpey.github.io/blog/2014/02/12/shared-singletons/
|
||||||
/// and
|
/// and
|
||||||
/// http://enki-tech.blogspot.com/2012/08/c11-generic-singleton.html
|
/// http://enki-tech.blogspot.com/2012/08/c11-generic-singleton.html
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <class T>
|
template <class T>
|
||||||
class EMBER_API Singleton
|
class Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -213,7 +210,7 @@ public:
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static shared_ptr<T> Instance(Args... args)
|
static shared_ptr<T> Instance(Args... args)
|
||||||
{
|
{
|
||||||
static weak_ptr<T> staticInstance;
|
auto& staticInstance = GetStaticInstance();
|
||||||
auto temp = staticInstance.lock();
|
auto temp = staticInstance.lock();
|
||||||
|
|
||||||
if (!temp)
|
if (!temp)
|
||||||
@ -224,6 +221,18 @@ public:
|
|||||||
|
|
||||||
return temp;
|
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.
|
//Use this if the body of the destructor will be implemented in a cpp file.
|
||||||
@ -231,8 +240,6 @@ public:
|
|||||||
friend class Singleton<x>; \
|
friend class Singleton<x>; \
|
||||||
public: \
|
public: \
|
||||||
~x(); \
|
~x(); \
|
||||||
\
|
|
||||||
private: \
|
|
||||||
x(const x& other) = delete; \
|
x(const x& other) = delete; \
|
||||||
const x& operator=(const x& other) = delete//Semicolon deliberately omitted to force it on the caller.
|
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>; \
|
friend class Singleton<x>; \
|
||||||
public: \
|
public: \
|
||||||
~x(){} \
|
~x(){} \
|
||||||
\
|
|
||||||
private: \
|
|
||||||
x(const x& other) = delete; \
|
x(const x& other) = delete; \
|
||||||
const x& operator=(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>
|
/// <summary>
|
||||||
/// Open a file in binary mode and read its entire contents into a vector of bytes. Optionally null terminate.
|
/// Open a file in binary mode and read its entire contents into a vector of bytes. Optionally null terminate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -13,7 +13,7 @@ namespace EmberNs
|
|||||||
/// This class is a singleton since all of its data is shared and read-only.
|
/// This class is a singleton since all of its data is shared and read-only.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class EMBER_API VarFuncs
|
class EMBER_API VarFuncs : public Singleton<VarFuncs<T>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -542,7 +542,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SINGLETON_INSTANCE_DECL(VarFuncs);//Implemented in VariationList.cpp
|
SINGLETON_DERIVED_IMPL(VarFuncs<T>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -16,14 +16,6 @@ namespace EmberNs
|
|||||||
m_Variations.push_back(new Pre##varName##Variation<T>()); \
|
m_Variations.push_back(new Pre##varName##Variation<T>()); \
|
||||||
m_Variations.push_back(new Post##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>
|
/// <summary>
|
||||||
/// Constructor which initializes all of the variation objects and stores them in the list.
|
/// Constructor which initializes all of the variation objects and stores them in the list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -18,10 +18,10 @@ namespace EmberNs
|
|||||||
/// Template argument expected to be float or double.
|
/// Template argument expected to be float or double.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class EMBER_API VariationList
|
class EMBER_API VariationList: public Singleton<VariationList<T>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~VariationList();
|
//~VariationList();
|
||||||
const Variation<T>* GetVariation(size_t index) const;
|
const Variation<T>* GetVariation(size_t index) const;
|
||||||
const Variation<T>* GetVariation(size_t index, eVariationType varType) const;
|
const Variation<T>* GetVariation(size_t index, eVariationType varType) const;
|
||||||
Variation<T>* GetVariationCopy(size_t index, T weight = 1) 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>*>& PreVars() const;
|
||||||
const vector<Variation<T>*>& PostVars() const;
|
const vector<Variation<T>*>& PostVars() const;
|
||||||
|
|
||||||
SINGLETON_INSTANCE_DECL(VariationList);//Implemented in VariationList.cpp
|
SINGLETON_DERIVED_DECL(VariationList<T>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VariationList();
|
VariationList();
|
||||||
|
@ -68,8 +68,6 @@ OpenCLInfo::OpenCLInfo()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SINGLETON_INSTANCE_IMPL(OpenCLInfo)
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a const reference to the vector of available platforms.
|
/// Get a const reference to the vector of available platforms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -17,7 +17,7 @@ namespace EmberCLns
|
|||||||
/// This class derives from EmberReport, so the caller is able
|
/// This class derives from EmberReport, so the caller is able
|
||||||
/// to retrieve a text dump of error information if any errors occur.
|
/// to retrieve a text dump of error information if any errors occur.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class EMBERCL_API OpenCLInfo : public EmberReport
|
class EMBERCL_API OpenCLInfo : public EmberReport, public Singleton<OpenCLInfo>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const vector<cl::Platform>& Platforms() const;
|
const vector<cl::Platform>& Platforms() const;
|
||||||
@ -54,9 +54,10 @@ public:
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
SINGLETON_INSTANCE_DECL(OpenCLInfo);
|
SINGLETON_DERIVED_IMPL(OpenCLInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
OpenCLInfo();
|
OpenCLInfo();
|
||||||
|
|
||||||
bool m_Init;
|
bool m_Init;
|
||||||
|
@ -339,7 +339,7 @@ bool EmberGenome(EmberOptions& opt)
|
|||||||
{
|
{
|
||||||
if (i > 0 && embers[i].m_Time <= embers[i - 1].m_Time)
|
if (i > 0 && embers[i].m_Time <= embers[i - 1].m_Time)
|
||||||
{
|
{
|
||||||
cerr << "Error: control points must be sorted by time, but " << embers[i].m_Time << " <= " << embers[i - 1].m_Time << ", index " << i << ".\n";
|
cerr << "Error: control points must be sorted by time, but time " << embers[i].m_Time << " <= " << embers[i - 1].m_Time << ", index " << i << ".\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,6 +405,15 @@ bool EmberGenome(EmberOptions& opt)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < embers.size(); i++)
|
||||||
|
{
|
||||||
|
if (i > 0 && embers[i].m_Time <= embers[i - 1].m_Time)
|
||||||
|
{
|
||||||
|
cerr << "Error: control points must be sorted by time, but time " << embers[i].m_Time << " <= " << embers[i - 1].m_Time << ", index " << i << ".\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (opt.Enclosed())
|
if (opt.Enclosed())
|
||||||
cout << "<sequence version=\"EMBER-" << EmberVersion() << "\">\n";
|
cout << "<sequence version=\"EMBER-" << EmberVersion() << "\">\n";
|
||||||
|
|
||||||
@ -529,8 +538,8 @@ bool EmberGenome(EmberOptions& opt)
|
|||||||
oldY = embers[i].m_CenterY;
|
oldY = embers[i].m_CenterY;
|
||||||
embers[i].m_FinalRasH = size_t(T(embers[i].m_FinalRasH) / T(opt.Frames()));
|
embers[i].m_FinalRasH = size_t(T(embers[i].m_FinalRasH) / T(opt.Frames()));
|
||||||
embers[i].m_CenterY = embers[i].m_CenterY - ((opt.Frames() - 1) * embers[i].m_FinalRasH) /
|
embers[i].m_CenterY = embers[i].m_CenterY - ((opt.Frames() - 1) * embers[i].m_FinalRasH) /
|
||||||
(2 * embers[i].m_PixelsPerUnit * pow(T(2.0), embers[i].m_Zoom));
|
(2 * embers[i].m_PixelsPerUnit * std::pow(T(2.0), embers[i].m_Zoom));
|
||||||
embers[i].m_CenterY += embers[i].m_FinalRasH * opt.Frame() / (embers[i].m_PixelsPerUnit * pow(T(2.0), embers[i].m_Zoom));
|
embers[i].m_CenterY += embers[i].m_FinalRasH * opt.Frame() / (embers[i].m_PixelsPerUnit * std::pow(T(2.0), embers[i].m_Zoom));
|
||||||
tools.RotateOldCenterBy(embers[i].m_CenterX, embers[i].m_CenterY, oldX, oldY, embers[i].m_Rotate);
|
tools.RotateOldCenterBy(embers[i].m_CenterX, embers[i].m_CenterY, oldX, oldY, embers[i].m_Rotate);
|
||||||
|
|
||||||
if (pTemplate)
|
if (pTemplate)
|
||||||
|
@ -27,8 +27,12 @@ int main(int argc, char* argv[])
|
|||||||
putenv(const_cast<char*>("GPU_MAX_ALLOC_PERCENT=100"));
|
putenv(const_cast<char*>("GPU_MAX_ALLOC_PERCENT=100"));
|
||||||
#endif
|
#endif
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
auto vlf = VariationList<float>::Instance();//Create two instances that will stay alive until this function exits.
|
auto vf = VarFuncs<float>::Instance();//Create instances that will stay alive until the program exits.
|
||||||
|
auto vlf = VariationList<float>::Instance();
|
||||||
|
#ifdef DO_DOUBLE
|
||||||
|
auto vd = VarFuncs<float>::Instance();
|
||||||
auto vld = VariationList<double>::Instance();//No further creations should occur after this.
|
auto vld = VariationList<double>::Instance();//No further creations should occur after this.
|
||||||
|
#endif
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user