Implemented sprite & added player animation.
This commit is contained in:
39
src/utils/Assert.cpp
Normal file
39
src/utils/Assert.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Assert.cpp
|
||||
*
|
||||
* Created on: Nov 29, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include <utils/Assert.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace farmlands {
|
||||
namespace utils {
|
||||
|
||||
DEFINE_EXCEPTION_CPP(AssertionFailedException, Exception)
|
||||
|
||||
void _AssertInternal(bool condition, const std::string& msg,
|
||||
const std::string& lineText, const std::string& file, int line)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw AssertionFailedException("Assertion failed: " + msg + "\n" + lineText, file, line);
|
||||
}
|
||||
}
|
||||
|
||||
void _AssertInternalLog(bool condition, const std::string& msg,
|
||||
const std::string& lineText, const std::string& file, int line)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
std::cerr << "In file " << file << ":" << line << ": ";
|
||||
std::cerr << "Assertion failed: " << msg << "\n";
|
||||
std::cerr << lineText << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace farmlands */
|
||||
|
||||
|
30
src/utils/Assert.h
Normal file
30
src/utils/Assert.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Assert.h
|
||||
*
|
||||
* Created on: Nov 29, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef UTILS_ASSERT_H_
|
||||
#define UTILS_ASSERT_H_
|
||||
|
||||
#include <utils/Exceptions.h>
|
||||
|
||||
namespace farmlands {
|
||||
namespace utils {
|
||||
|
||||
DEFINE_EXCEPTION_CLASS(AssertionFailedException, Exception)
|
||||
|
||||
void _AssertInternal(bool condition, const std::string& msg, const std::string& lineText, const std::string& file, int line);
|
||||
void _AssertInternalLog(bool condition, const std::string& msg, const std::string& lineText, const std::string& file, int line);
|
||||
|
||||
#ifdef BUILD_DEBUG
|
||||
#define Assert(condition, message) farmlands::utils::_AssertInternal(condition, message, #condition, __FILE__, __LINE__)
|
||||
#else
|
||||
#define Assert(condition, message) farmlands::utils::_AssertInternalLog(condition, message, #condition, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* UTILS_ASSERT_H_ */
|
45
src/utils/Exceptions.cpp
Normal file
45
src/utils/Exceptions.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Exceptions.cpp
|
||||
*
|
||||
* Created on: Nov 29, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include <utils/Exceptions.h>
|
||||
|
||||
namespace farmlands {
|
||||
namespace utils {
|
||||
|
||||
Exception::Exception()
|
||||
: m_message(),
|
||||
m_file(),
|
||||
m_line()
|
||||
{
|
||||
}
|
||||
|
||||
Exception::Exception(const std::string& msg)
|
||||
: m_message(msg),
|
||||
m_file(),
|
||||
m_line()
|
||||
{
|
||||
}
|
||||
|
||||
Exception::Exception(const std::string& msg, const std::string& file, int line)
|
||||
: m_message(msg),
|
||||
m_file(file),
|
||||
m_line(line)
|
||||
{
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DEFINE_EXCEPTION_CPP(InvalidArgumentException, Exception)
|
||||
DEFINE_EXCEPTION_CPP(IOException, Exception);
|
||||
DEFINE_EXCEPTION_CPP(ResourceLoadException, IOException);
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace farmlands */
|
||||
|
77
src/utils/Exceptions.h
Normal file
77
src/utils/Exceptions.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Exceptions.h
|
||||
*
|
||||
* Created on: Nov 29, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef UTILS_EXCEPTIONS_H_
|
||||
#define UTILS_EXCEPTIONS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace farmlands {
|
||||
namespace utils {
|
||||
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
Exception();
|
||||
Exception(const std::string& msg);
|
||||
Exception(const std::string& msg, const std::string& file, int line);
|
||||
virtual ~Exception();
|
||||
|
||||
inline std::string message() const { return m_message; }
|
||||
inline std::string file() const { return m_file; }
|
||||
inline int line() const { return m_line; }
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
std::string m_file;
|
||||
int m_line;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines an exception class
|
||||
*/
|
||||
#define DEFINE_EXCEPTION_CLASS(className, baseClass) \
|
||||
class className : public baseClass \
|
||||
{ \
|
||||
public: \
|
||||
className(); \
|
||||
className(const std::string& msg); \
|
||||
className(const std::string& msg, const std::string& file, int line); \
|
||||
virtual ~className(); \
|
||||
}; \
|
||||
|
||||
|
||||
/**
|
||||
* Defines the implementation for an exception class
|
||||
*/
|
||||
#define DEFINE_EXCEPTION_CPP(className, baseClass) \
|
||||
className::className() \
|
||||
: baseClass() { } \
|
||||
className::className(const std::string& msg) \
|
||||
: baseClass(msg) { } \
|
||||
className::className(const std::string& msg, const std::string& file, int line) \
|
||||
: baseClass(msg, file, line) { } \
|
||||
className::~className() { } \
|
||||
|
||||
|
||||
/**
|
||||
* Throws an exception; also adds file and line.
|
||||
*/
|
||||
#define THROW(exceptionClass, message) throw exceptionClass(message, __FILE__, __LINE__)
|
||||
|
||||
|
||||
// Common exceptions
|
||||
|
||||
DEFINE_EXCEPTION_CLASS(InvalidArgumentException, Exception);
|
||||
DEFINE_EXCEPTION_CLASS(IOException, Exception);
|
||||
DEFINE_EXCEPTION_CLASS(ResourceLoadException, IOException);
|
||||
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* UTILS_EXCEPTIONS_H_ */
|
Reference in New Issue
Block a user