More code cleanup

This commit is contained in:
Phillip Stephens 2017-01-03 10:32:56 -08:00
parent e5715bbf8f
commit 0eb7fb20e8
24 changed files with 183 additions and 676 deletions

View File

@ -14,7 +14,7 @@ if(NOT TARGET AthenaCore AND NOT Athena_BINARY_DIR)
endif() endif()
# These are IMPORTED targets created by AthenaTargets.cmake # These are IMPORTED targets created by AthenaTargets.cmake
set(ATHENA_LIBRARIES AthenaCore AthenaSakura AthenaZelda AthenaWiiSave) set(ATHENA_LIBRARIES athena-core athena-wiisave athena-sakura athena-zelda)
# Set icon location if on windows # Set icon location if on windows
if(WIN32 AND NOT CYGWIN) if(WIN32 AND NOT CYGWIN)

View File

@ -11,11 +11,11 @@
#include <sys/stat.h> #include <sys/stat.h>
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif #endif
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif #endif
#if !defined(S_ISLNK) #if !defined(S_ISLNK)
@ -29,7 +29,7 @@
#define PRISize "zu" #define PRISize "zu"
#endif #endif
// clang-format off
#ifndef AT_PRETTY_FUNCTION #ifndef AT_PRETTY_FUNCTION
# if defined(__PRETTY_FUNCTION__) || defined(__GNUC__) # if defined(__PRETTY_FUNCTION__) || defined(__GNUC__)
# define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__ # define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__
@ -45,7 +45,7 @@
# define AT_PRETTY_FUNCTION "<unknown>" # define AT_PRETTY_FUNCTION "<unknown>"
# endif # endif
#endif #endif
// clang-format on
#ifdef GEKKO #ifdef GEKKO
#include "gekko_support.h" #include "gekko_support.h"
@ -76,34 +76,34 @@ typedef struct stat64 atStat64_t;
#define _STR(s) #s #define _STR(s) #s
#ifndef ENABLE_BITWISE_ENUM #ifndef ENABLE_BITWISE_ENUM
#define ENABLE_BITWISE_ENUM(type)\ #define ENABLE_BITWISE_ENUM(type) \
constexpr type operator|(type a, type b)\ constexpr type operator|(type a, type b) \
{\ { \
using T = std::underlying_type_t<type>;\ using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) | static_cast<T>(b));\ return type(static_cast<T>(a) | static_cast<T>(b)); \
}\ } \
constexpr type operator&(type a, type b)\ constexpr type operator&(type a, type b) \
{\ { \
using T = std::underlying_type_t<type>;\ using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) & static_cast<T>(b));\ return type(static_cast<T>(a) & static_cast<T>(b)); \
}\ } \
inline type& operator|=(type& a, const type& b)\ inline type& operator|=(type& a, const type& b) \
{\ { \
using T = std::underlying_type_t<type>;\ using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) | static_cast<T>(b));\ a = type(static_cast<T>(a) | static_cast<T>(b)); \
return a;\ return a; \
}\ } \
inline type& operator&=(type& a, const type& b)\ inline type& operator&=(type& a, const type& b) \
{\ { \
using T = std::underlying_type_t<type>;\ using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) & static_cast<T>(b));\ a = type(static_cast<T>(a) & static_cast<T>(b)); \
return a;\ return a; \
}\ } \
inline type operator~(const type& key)\ inline type operator~(const type& key) \
{\ { \
using T = std::underlying_type_t<type>;\ using T = std::underlying_type_t<type>; \
return type(~static_cast<T>(key));\ return type(~static_cast<T>(key)); \
} }
#endif #endif
namespace athena namespace athena
@ -132,7 +132,8 @@ enum Endian
}; };
} // Athena } // Athena
typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line, const char* fmt, ...); typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line,
const char* fmt, ...);
atEXCEPTION_HANDLER atGetExceptionHandler(); atEXCEPTION_HANDLER atGetExceptionHandler();
/** /**
@ -146,73 +147,93 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef NDEBUG #ifndef NDEBUG
#define atDebug(fmt, ...) \ #define atDebug(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#else #else
#define atDebug(fmt, ...) #define atDebug(fmt, ...)
#endif #endif
#define atMessage(fmt, ...) \ #define atMessage(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atWarning(fmt, ...) \ #define atWarning(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atError(fmt, ...) \ #define atError(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#define atFatal(fmt, ...) \ #define atFatal(fmt, ...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
} while (0)
#elif defined(__GNUC__) #elif defined(__GNUC__)
#ifndef NDEBUG #ifndef NDEBUG
#define atDebug(fmt...) \ #define atDebug(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#else // _MSC_VER #else // _MSC_VER
#define atDebug(fmt, ...) #define atDebug(fmt, ...)
#endif // NDEBUG #endif // NDEBUG
#define atMessage(fmt...) \ #define atMessage(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atWarning(fmt...) \ #define atWarning(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atError(fmt...) \ #define atError(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#define atFatal(fmt...) \ #define atFatal(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \ do \
if (__handler) \ { \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \ atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
} while(0) if (__handler) \
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while (0)
#endif // defined(__GNUC__) #endif // defined(__GNUC__)
#endif // GLOBAL_HPP #endif // GLOBAL_HPP

View File

@ -11,7 +11,6 @@ namespace io
class SkywardSwordFileReader : public MemoryCopyReader class SkywardSwordFileReader : public MemoryCopyReader
{ {
public: public:
SkywardSwordFileReader(atUint8* data, atUint64 length); SkywardSwordFileReader(atUint8* data, atUint64 length);
SkywardSwordFileReader(const std::string& filename); SkywardSwordFileReader(const std::string& filename);

View File

@ -43,17 +43,16 @@ public:
void setSkipData(std::unique_ptr<atUint8[]>&& data); void setSkipData(std::unique_ptr<atUint8[]>&& data);
atUint8* skipData() const; atUint8* skipData() const;
atUint32 slotChecksum(); atUint32 slotChecksum();
atUint32 skipChecksum(); atUint32 skipChecksum();
void fixChecksums(); void fixChecksums();
void setNew(bool isNew); void setNew(bool isNew);
bool isNew() const; bool isNew() const;
private: private:
std::unique_ptr<atUint8[]> m_skipData; std::unique_ptr<atUint8[]> m_skipData;
}; };
} // Athena } // Athena
#endif // SSQUEST_HPP #endif // SSQUEST_HPP

View File

@ -1,15 +1,8 @@
#ifndef SSPRITE_HPP #ifndef SSPRITE_HPP
#define SSPRITE_HPP #define SSPRITE_HPP
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#include <string> #include <string>
#else
#include <QObject>
#include <QPoint>
#include <QString>
#include <QList>
#endif
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
namespace athena namespace athena
@ -19,35 +12,18 @@ namespace Sakura
class SpriteFile; class SpriteFile;
class SpriteFrame; class SpriteFrame;
#ifndef ATHENA_USE_QT
class Sprite class Sprite
{ {
#else
class Sprite : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(qreal currentState READ currentState WRITE setCurrentState)
Q_PROPERTY(qreal stateCount READ stateCount CONSTANT)
#endif
public: public:
Sprite(SpriteFile* root); Sprite(SpriteFile* root);
Sprite(SpriteFile* root, const std::string& name); Sprite(SpriteFile* root, const std::string& name);
virtual ~Sprite(); virtual ~Sprite();
virtual void setPosition(const float x, const float y); virtual void setPosition(const float x, const float y);
#ifndef ATHENA_USE_QT
virtual void setPosition(const Vector2Df& pos); virtual void setPosition(const Vector2Df& pos);
virtual Vector2Df position() const; virtual Vector2Df position() const;
void setName(const std::string& name); void setName(const std::string& name);
std::string name() const; std::string name() const;
#else
virtual void setPosition(const QPoint& pos);
virtual QPoint position() const;
void setName(const QString& name);
QString name() const;
#endif
void addStateId(int id); void addStateId(int id);
@ -58,11 +34,7 @@ public:
*/ */
int stateId(int index) const; int stateId(int index) const;
void setStateIds(std::vector<int> ids); void setStateIds(std::vector<int> ids);
#ifndef ATHENA_USE_QT
std::vector<int> stateIds() const; std::vector<int> stateIds() const;
#else
QList<int> stateIds() const;
#endif
atUint32 stateCount() const; atUint32 stateCount() const;
void setCurrentState(atUint32 id); void setCurrentState(atUint32 id);
atUint32 currentState() const; atUint32 currentState() const;
@ -71,18 +43,10 @@ public:
bool removeFrame(SpriteFrame* Frame); bool removeFrame(SpriteFrame* Frame);
SpriteFrame* Frame(atUint32 id); SpriteFrame* Frame(atUint32 id);
void setFrame(atUint32 id); void setFrame(atUint32 id);
#ifndef ATHENA_USE_QT
void setFrames(std::vector<SpriteFrame*> frames); void setFrames(std::vector<SpriteFrame*> frames);
#else
void setFrames(QList<SpriteFrame*> frames);
#endif
atUint32 frameCount() const; atUint32 frameCount() const;
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*> frames() const; std::vector<SpriteFrame*> frames() const;
#else
QList<SpriteFrame*> frames() const;
#endif
SpriteFile* container() const; SpriteFile* container() const;
@ -95,36 +59,17 @@ public:
void setRoot(SpriteFile* root); void setRoot(SpriteFile* root);
SpriteFile* root() const; SpriteFile* root() const;
#ifdef ATHENA_USE_QT
signals:
void frameChanged(SpriteFrame* frame);
void nameChanged(QString);
void stateChanged(quint32);
#endif
private: private:
SpriteFile* m_root; SpriteFile* m_root;
#ifndef ATHENA_USE_QT std::string m_name;
std::string m_name; Vector2Df m_position;
Vector2Df m_position; std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
std::vector<SpriteFrame*> m_frames; std::vector<SpriteFrame*> m_frames;
#else atUint32 m_currentState;
QString m_name; atUint32 m_currentFrame;
QPoint m_position;
QList<int> m_stateIds;
QList<SpriteFrame*> m_frames;
#endif
atUint32 m_currentState;
atUint32 m_currentFrame;
}; };
} // Sakura } // Sakura
} // zelda } // zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(Uint32)
Q_DECLARE_METATYPE(athena::Sakura::Sprite*)
#endif
#endif // SSPRITE_HPP #endif // SSPRITE_HPP

View File

@ -1,16 +1,8 @@
#ifndef SSPRITEFILE_HPP #ifndef SSPRITEFILE_HPP
#define SSPRITEFILE_HPP #define SSPRITEFILE_HPP
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
#else
#include <QObject>
#include <QMap>
#include <QList>
#include <QSize>
#include <QPoint>
#endif
#include <string> #include <string>
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
@ -26,14 +18,8 @@ struct STexture
}; };
class Sprite; class Sprite;
#ifndef ATHENA_USE_QT
class SpriteFile class SpriteFile
{ {
#else
class SpriteFile : public QObject
{
Q_OBJECT
#endif
public: public:
/*! /*!
* \brief Major * \brief Major
@ -109,21 +95,13 @@ public slots:
* \brief setSize * \brief setSize
* \param size * \param size
*/ */
#ifndef ATHENA_USE_QT
void setSize(const Vector2Di& size); void setSize(const Vector2Di& size);
#else
void setSize(const QSize& size);
#endif
/*! /*!
* \brief size * \brief size
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Di size() const; Vector2Di size() const;
#else
QSize size() const;
#endif
/*! /*!
* \brief width * \brief width
@ -148,21 +126,13 @@ public slots:
* \brief setOrigin * \brief setOrigin
* \param origin * \param origin
*/ */
#ifndef ATHENA_USE_QT
void setOrigin(const Vector2Df& origin); void setOrigin(const Vector2Df& origin);
#else
void setOrigin(const QPoint& origin);
#endif
/*! /*!
* \brief origin * \brief origin
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df origin() const; Vector2Df origin() const;
#else
QPoint origin() const;
#endif
/*! /*!
@ -195,71 +165,33 @@ public slots:
* \return * \return
*/ */
STexture* texture(atUint32 id); STexture* texture(atUint32 id);
#ifndef ATHENA_USE_QT
std::vector<STexture*> textures() const; std::vector<STexture*> textures() const;
#else
QList<STexture*> textures() const;
#endif
atUint32 textureCount() const; atUint32 textureCount() const;
/*! /*!
* \brief setTextures * \brief setTextures
* \param textures * \param textures
*/ */
#ifndef ATHENA_USE_QT
void setTextures(std::vector<STexture*> textures); void setTextures(std::vector<STexture*> textures);
#else
void setTextures(QList<STexture*> textures);
#endif
void addSprite(Sprite* sprite); void addSprite(Sprite* sprite);
#ifndef ATHENA_USE_QT
void removeSprite(const std::string& name); void removeSprite(const std::string& name);
#else
void removeSprite(const QString& name);
#endif
void removeSprite(Sprite* sprite); void removeSprite(Sprite* sprite);
#ifndef ATHENA_USE_QT
void setSprites(std::unordered_map<std::string, Sprite*> sprites); void setSprites(std::unordered_map<std::string, Sprite*> sprites);
#else
void setSprites(QMap<QString, Sprite*> sprites);
#endif
#ifndef ATHENA_USE_QT
Sprite* sprite(const std::string& name); Sprite* sprite(const std::string& name);
std::unordered_map<std::string, Sprite*> sprites() const; std::unordered_map<std::string, Sprite*> sprites() const;
#else
Sprite* sprite(const QString& name);
QMap<QString, Sprite*> sprites() const;
#endif
atUint32 spriteCount() const; atUint32 spriteCount() const;
#ifdef ATHENA_USE_QT
signals:
void originChanged(QPoint);
void sizeChanged(QSize);
#endif
private: private:
#ifndef ATHENA_USE_QT
std::vector<STexture*> m_textures; std::vector<STexture*> m_textures;
Vector2Di m_size; Vector2Di m_size;
Vector2Df m_origin; Vector2Df m_origin;
std::unordered_map<std::string, Sprite*> m_sprites; std::unordered_map<std::string, Sprite*> m_sprites;
#else
QList<STexture*> m_textures;
QSize m_size;
QPoint m_origin;
QMap<QString, Sprite*> m_sprites;
#endif
}; };
} // Sakura } // Sakura
} // Zelda } // Zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpriteFile*)
Q_DECLARE_METATYPE(athena::Sakura::STexture*)
#endif
#endif // SSPRITE_HPP #endif // SSPRITE_HPP

View File

@ -15,7 +15,6 @@ namespace io
class SpriteFileWriter : public MemoryCopyWriter class SpriteFileWriter : public MemoryCopyWriter
{ {
MEMORYCOPYWRITER_BASE();
public: public:
SpriteFileWriter(atUint8* data, atUint64 length); SpriteFileWriter(atUint8* data, atUint64 length);

View File

@ -4,13 +4,7 @@
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
#ifndef ATHENA_USE_QT
#include <vector> #include <vector>
#else
#include <QObject>
#include <QList>
#endif
namespace athena namespace athena
{ {
namespace Sakura namespace Sakura
@ -19,15 +13,8 @@ namespace Sakura
class Sprite; class Sprite;
class SpritePart; class SpritePart;
#ifndef ATHENA_USE_QT
class SpriteFrame class SpriteFrame
{ {
#else
class SpriteFrame : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal frameTime READ frameTime WRITE setFrameTime)
#endif
public: public:
/*! /*!
* \brief SSpriteFrame * \brief SSpriteFrame
@ -48,37 +35,20 @@ public:
*/ */
float frameTime() const; float frameTime() const;
#ifndef ATHENA_USE_QT
void setParts(std::vector<SpritePart*> parts); void setParts(std::vector<SpritePart*> parts);
std::vector<SpritePart*> parts() const; std::vector<SpritePart*> parts() const;
#else
void setParts(QList<SpritePart*> parts);
QList<SpritePart*> parts() const;
#endif
atUint32 partCount() const; atUint32 partCount() const;
void setRoot(Sprite* root); void setRoot(Sprite* root);
Sprite* root() const; Sprite* root() const;
#ifdef ATHENA_USE_QT
signals:
void frameTimeChanged(float);
#endif
private: private:
Sprite* m_root; Sprite* m_root;
float m_frameTime; float m_frameTime;
#ifndef ATHENA_USE_QT
std::vector<SpritePart*> m_parts; std::vector<SpritePart*> m_parts;
#else
QList<SpritePart*> m_parts;
#endif
}; };
} // Sakura } // Sakura
} // zelda } // zelda
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpriteFrame*);
#endif
#endif // SSPRITEFRAME_HPP #endif // SSPRITEFRAME_HPP

View File

@ -2,14 +2,7 @@
#define SSPRITEPART_HPP #define SSPRITEPART_HPP
#include "athena/SakuraGlobal.hpp" #include "athena/SakuraGlobal.hpp"
#ifndef ATHENA_USE_QT #include <vector>
# include <vector>
#else
# include <QObject>
# include <QPoint>
# include <QSize>
# include <QString>
#endif
#include <string> #include <string>
@ -19,35 +12,15 @@ namespace Sakura
{ {
class SpriteFrame; class SpriteFrame;
#ifndef ATHENA_USE_QT
class SpritePart class SpritePart
{ {
#else
class SpritePart : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(bool hasCollision READ hasCollision WRITE setCollision)
Q_PROPERTY(bool flippedHorizontally READ flippedHorizontally WRITE setFlippedHorizontally)
Q_PROPERTY(bool flippedVertically READ flippedVertically WRITE setFlippedVertically)
Q_PROPERTY(QPoint offset READ offset WRITE setOffset)
Q_PROPERTY(QPoint textureOffset READ textureOffset WRITE setTextureOffset)
Q_PROPERTY(QSize size READ size WRITE setSize)
#endif
public: public:
SpritePart(SpriteFrame* root); SpritePart(SpriteFrame* root);
SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false); SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false);
virtual ~SpritePart(); virtual ~SpritePart();
#ifndef ATHENA_USE_QT
void setName(const std::string& name); void setName(const std::string& name);
std::string name() const; std::string name() const;
#else
void setName(const QString& name);
QString name() const;
#endif
void setCollision(bool col); void setCollision(bool col);
bool hasCollision() const; bool hasCollision() const;
@ -57,26 +30,13 @@ public:
* \param y * \param y
*/ */
void setOffset(float x, float y); void setOffset(float x, float y);
/*!
* \brief setOffset
* \param offset
*/
#ifndef ATHENA_USE_QT
void setOffset(const Vector2Df& offset); void setOffset(const Vector2Df& offset);
#else
void setOffset(const QPoint& offset);
#endif
/*! /*!
* \brief offset * \brief offset
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df offset() const; Vector2Df offset() const;
#else
QPoint offset() const;
#endif
/*! /*!
* \brief setTextureOffset * \brief setTextureOffset
@ -89,22 +49,13 @@ public:
* \brief setTextureOffset * \brief setTextureOffset
* \param texOff * \param texOff
*/ */
#ifndef ATHENA_USE_QT
void setTextureOffset(const Vector2Df& offset); void setTextureOffset(const Vector2Df& offset);
#else
void setTextureOffset(const QPoint& offset);
#endif
/*! /*!
* \brief textureOffset * \brief textureOffset
* \return * \return
*/ */
#ifndef ATHENA_USE_QT
Vector2Df textureOffset() const; Vector2Df textureOffset() const;
#else
QPoint textureOffset() const;
#endif
/*! /*!
* \brief setSize * \brief setSize
* \param width * \param width
@ -112,25 +63,16 @@ public:
*/ */
void setSize(atUint32 width, atUint32 height); void setSize(atUint32 width, atUint32 height);
/*! /*!
* \brief setSize * \brief setSize
* \param size * \param size
*/ */
#ifndef ATHENA_USE_QT
void setSize(const Vector2Di& size); void setSize(const Vector2Di& size);
#else /*!
void setSize(const QSize& size); * \brief size
#endif * \return
*/
/*!
* \brief size
* \return
*/
#ifndef ATHENA_USE_QT
Vector2Di size() const; Vector2Di size() const;
#else
QSize size() const;
#endif
/*! /*!
* \brief setFlippedHorizontally * \brief setFlippedHorizontally
@ -159,42 +101,19 @@ public:
void setRoot(SpriteFrame* root); void setRoot(SpriteFrame* root);
SpriteFrame* root() const; SpriteFrame* root() const;
#ifdef ATHENA_USE_QT
signals:
void nameChanged(QString);
void orientationChanged(bool, bool);
void offsetChanged(QPoint);
void textureOffsetChanged(QPoint);
void sizeChanged(QSize);
void collisionChanged(bool);
#endif
private: private:
SpriteFrame* m_root; SpriteFrame* m_root;
#ifndef ATHENA_USE_QT std::string m_name;
std::string m_name; bool m_hasCollision;
#else Vector2Df m_offset;
QString m_name; Vector2Df m_textureOffset;
#endif Vector2Di m_size;
bool m_hasCollision; bool m_flippedH;
#ifndef ATHENA_USE_QT bool m_flippedV;
Vector2Df m_offset; atUint32 m_frameIndex;
Vector2Df m_textureOffset;
Vector2Di m_size;
#else
QPoint m_offset;
QPoint m_textureOffset;
QSize m_size;
#endif
bool m_flippedH;
bool m_flippedV;
atUint32 m_frameIndex;
}; };
} }
} }
#ifdef ATHENA_USE_QT
Q_DECLARE_METATYPE(athena::Sakura::SpritePart*)
#endif
#endif // SSPRITEPART_HPP #endif // SSPRITEPART_HPP

View File

@ -6,5 +6,5 @@ Name: libAthena
Description: Basic cross platform IO library Description: Basic cross platform IO library
Version: @ATHENA_VERSION@ Version: @ATHENA_VERSION@
Cflags: -I${includedir}/Athena -std=c++11 Cflags: -I${includedir}/Athena -std=c++11
Libs: -L${libdir} -lAthenaCore -lAthenaSakura -lAthenaZelda -lAthenaWiiSave Libs: -L${libdir} -lathena-core -lathena-sakura -lathena-zelda -lathena-wiiSave
Requires: zlib Requires: zlib

View File

@ -10,12 +10,12 @@ namespace io
{ {
ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length) ALTTPFileReader::ALTTPFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
ALTTPFileReader::ALTTPFileReader(const std::string& filename) ALTTPFileReader::ALTTPFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }

View File

@ -10,12 +10,12 @@ namespace io
{ {
ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length) ALTTPFileWriter::ALTTPFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
ALTTPFileWriter::ALTTPFileWriter(const std::string& filename) ALTTPFileWriter::ALTTPFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }

View File

@ -8,12 +8,12 @@ namespace io
static const atUint32 SCRAMBLE_VALUE = 0x5A424741; static const atUint32 SCRAMBLE_VALUE = 0x5A424741;
MCFileReader::MCFileReader(atUint8* data, atUint64 length) MCFileReader::MCFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
MCFileReader::MCFileReader(const std::string& filename) MCFileReader::MCFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }

View File

@ -6,12 +6,12 @@ namespace io
{ {
MCFileWriter::MCFileWriter(atUint8* data, atUint64 length) MCFileWriter::MCFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
MCFileWriter::MCFileWriter(const std::string& filename) MCFileWriter::MCFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }

View File

@ -9,13 +9,13 @@ namespace io
{ {
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length) SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename) SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }

View File

@ -8,13 +8,13 @@ namespace io
{ {
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len) SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len)
: base(data, len) : MemoryCopyWriter(data, len)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename) SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }

View File

@ -22,21 +22,12 @@ Sprite::Sprite(SpriteFile* root, const std::string& name)
: m_root(root), : m_root(root),
m_currentState(0) m_currentState(0)
{ {
#ifdef ATHENA_USE_QT
m_name = QString::fromStdString(name);
#else
m_name = name; m_name = name;
#endif
} }
Sprite::~Sprite() Sprite::~Sprite()
{ {
#ifndef ATHENA_USE_QT
for (SpriteFrame* frame : m_frames) for (SpriteFrame* frame : m_frames)
#else
foreach (SpriteFrame* frame, m_frames)
#endif
{ {
delete frame; delete frame;
frame = NULL; frame = NULL;
@ -47,49 +38,25 @@ Sprite::~Sprite()
void Sprite::setPosition(const float x, const float y) void Sprite::setPosition(const float x, const float y)
{ {
#ifndef ATHENA_USE_QT
setPosition(Vector2Df(x, y)); setPosition(Vector2Df(x, y));
#else
setPosition(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void Sprite::setPosition(const Vector2Df& pos) void Sprite::setPosition(const Vector2Df& pos)
#else
void Sprite::setPosition(const QPoint& pos)
#endif
{ {
m_position = pos; m_position = pos;
} }
#ifndef ATHENA_USE_QT
Vector2Df Sprite::position() const Vector2Df Sprite::position() const
#else
QPoint Sprite::position() const
#endif
{ {
return m_position; return m_position;
} }
#ifndef ATHENA_USE_QT
void Sprite::setName(const std::string& name) void Sprite::setName(const std::string& name)
#else
void Sprite::setName(const QString& name)
#endif
{ {
m_name = name; m_name = name;
#ifdef ATHENA_USE_QT
emit nameChanged(name);
#endif
} }
#ifndef ATHENA_USE_QT
std::string Sprite::name() const std::string Sprite::name() const
#else
QString Sprite::name() const
#endif
{ {
return m_name; return m_name;
} }
@ -116,18 +83,10 @@ void Sprite::setStateIds(std::vector<int> ids)
if (ids.size() == 0) if (ids.size() == 0)
return; return;
#ifndef ATHENA_USE_QT
m_stateIds = ids; m_stateIds = ids;
#else
m_stateIds = QList<int>::fromVector(QVector<int>::fromStdVector(ids));
#endif
} }
#ifndef ATHENA_USE_QT
std::vector<int> Sprite::stateIds() const std::vector<int> Sprite::stateIds() const
#else
QList<int> Sprite::stateIds() const
#endif
{ {
return m_stateIds; return m_stateIds;
} }
@ -143,9 +102,6 @@ void Sprite::setCurrentState(const atUint32 id)
return; return;
m_currentState = id; m_currentState = id;
#ifdef ATHENA_USE_QT
emit stateChanged(id);
#endif
} }
atUint32 Sprite::currentState() const atUint32 Sprite::currentState() const
@ -170,7 +126,6 @@ bool Sprite::addFrame(SpriteFrame* part)
bool Sprite::removeFrame(SpriteFrame* frame) bool Sprite::removeFrame(SpriteFrame* frame)
{ {
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*>::iterator iter = std::find(m_frames.begin(), m_frames.end(), frame); std::vector<SpriteFrame*>::iterator iter = std::find(m_frames.begin(), m_frames.end(), frame);
if (iter != m_frames.end()) if (iter != m_frames.end())
@ -178,13 +133,6 @@ bool Sprite::removeFrame(SpriteFrame* frame)
m_frames.erase(iter); m_frames.erase(iter);
return true; return true;
} }
#else
if (m_frames.removeOne(frame))
return true;
#endif
return false; return false;
} }
@ -194,7 +142,6 @@ void Sprite::setFrame(atUint32 id)
return; return;
} }
#ifndef ATHENA_USE_QT
void Sprite::setFrames(std::vector<SpriteFrame*> frames) void Sprite::setFrames(std::vector<SpriteFrame*> frames)
{ {
if (frames.size() == 0) if (frames.size() == 0)
@ -213,13 +160,6 @@ void Sprite::setFrames(std::vector<SpriteFrame*> frames)
m_frames = frames; m_frames = frames;
} }
#else
void Sprite::setFrames(QList<SpriteFrame*> frames)
{
m_frames.clear();
m_frames = frames;
}
#endif
atUint32 Sprite::frameCount() const atUint32 Sprite::frameCount() const
@ -227,11 +167,7 @@ atUint32 Sprite::frameCount() const
return (atUint32)m_frames.size(); return (atUint32)m_frames.size();
} }
#ifndef ATHENA_USE_QT
std::vector<SpriteFrame*> Sprite::frames() const std::vector<SpriteFrame*> Sprite::frames() const
#else
QList<SpriteFrame*> Sprite::frames() const
#endif
{ {
return m_frames; return m_frames;
} }
@ -263,9 +199,6 @@ void Sprite::setCurrentFrame(atUint32 id)
return; return;
m_currentFrame = id; m_currentFrame = id;
#ifdef ATHENA_USE_QT
emit frameChanged(currentFrame());
#endif
} }
SpriteFrame* Sprite::currentFrame() const SpriteFrame* Sprite::currentFrame() const

View File

@ -26,11 +26,7 @@ SpriteFile::SpriteFile(atUint32 width, atUint32 height, float originX, float ori
{ {
} }
#ifndef ATHENA_USE_QT
SpriteFile::SpriteFile(const Vector2Di& size, const Vector2Df& origin) SpriteFile::SpriteFile(const Vector2Di& size, const Vector2Df& origin)
#else
SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
#endif
: m_size(size), : m_size(size),
m_origin(origin) m_origin(origin)
{ {
@ -38,113 +34,64 @@ SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
SpriteFile::~SpriteFile() SpriteFile::~SpriteFile()
{ {
#ifndef ATHENA_USE_QT
for (std::pair<std::string, Sprite*> sprite : m_sprites) for (std::pair<std::string, Sprite*> sprite : m_sprites)
{ {
delete sprite.second; delete sprite.second;
sprite.second = NULL; sprite.second = NULL;
} }
#endif
m_sprites.clear(); m_sprites.clear();
} }
void SpriteFile::setSize(atUint32 width, atUint32 height) void SpriteFile::setSize(atUint32 width, atUint32 height)
{ {
#ifndef ATHENA_USE_QT
setSize(Vector2Di(width, height)); setSize(Vector2Di(width, height));
#else
setSize(QSize(width, height));
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setSize(const Vector2Di& size) void SpriteFile::setSize(const Vector2Di& size)
#else
void SpriteFile::setSize(const QSize& size)
#endif
{ {
m_size = size; m_size = size;
#ifdef ATHENA_USE_QT
emit sizeChanged(size);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Di SpriteFile::size() const Vector2Di SpriteFile::size() const
#else
QSize SpriteFile::size() const
#endif
{ {
return m_size; return m_size;
} }
atUint32 SpriteFile::width() const atUint32 SpriteFile::width() const
{ {
#ifndef ATHENA_USE_QT
return m_size.x; return m_size.x;
#else
return m_size.width();
#endif
} }
atUint32 SpriteFile::height() const atUint32 SpriteFile::height() const
{ {
#ifndef ATHENA_USE_QT
return m_size.y; return m_size.y;
#else
return m_size.height();
#endif
} }
void SpriteFile::setOrigin(const float x, const float y) void SpriteFile::setOrigin(const float x, const float y)
{ {
#ifndef ATHENA_USE_QT
setOrigin(Vector2Df(x, y)); setOrigin(Vector2Df(x, y));
#else
setOrigin(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setOrigin(const Vector2Df& origin) void SpriteFile::setOrigin(const Vector2Df& origin)
#else
void SpriteFile::setOrigin(const QPoint& origin)
#endif
{ {
m_origin = origin; m_origin = origin;
#ifdef ATHENA_USE_QT
emit originChanged(origin);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpriteFile::origin() const Vector2Df SpriteFile::origin() const
#else
QPoint SpriteFile::origin() const
#endif
{ {
return m_origin; return m_origin;
} }
float SpriteFile::originX() const float SpriteFile::originX() const
{ {
#ifndef ATHENA_USE_QT
return m_origin.x; return m_origin.x;
#else
return m_origin.x();
#endif
} }
float SpriteFile::originY() const float SpriteFile::originY() const
{ {
#ifndef ATHENA_USE_QT
return m_origin.y; return m_origin.y;
#else
return m_origin.y();
#endif
} }
bool SpriteFile::addTexture(STexture* texture) bool SpriteFile::addTexture(STexture* texture)
@ -174,11 +121,7 @@ STexture* SpriteFile::texture(atUint32 id)
return m_textures[id]; return m_textures[id];
} }
#ifndef ATHENA_USE_QT
std::vector<STexture*> SpriteFile::textures() const std::vector<STexture*> SpriteFile::textures() const
#else
QList<STexture*> SpriteFile::textures() const
#endif
{ {
return m_textures; return m_textures;
} }
@ -190,25 +133,15 @@ atUint32 SpriteFile::textureCount() const
void SpriteFile::addSprite(Sprite* sprite) void SpriteFile::addSprite(Sprite* sprite)
{ {
#ifndef ATHENA_USE_QT
std::string name(sprite->name()); std::string name(sprite->name());
athena::utility::tolower(name); athena::utility::tolower(name);
if (m_sprites.find(name) != m_sprites.end()) if (m_sprites.find(name) != m_sprites.end())
return; return;
#else
QString name = sprite->name().toLower();
if (m_sprites.contains(name))
return;
#endif
m_sprites[name] = sprite; m_sprites[name] = sprite;
} }
#ifndef ATHENA_USE_QT
void SpriteFile::removeSprite(const std::string& name) void SpriteFile::removeSprite(const std::string& name)
{ {
std::string tmpName(name); std::string tmpName(name);
@ -218,19 +151,12 @@ void SpriteFile::removeSprite(const std::string& name)
if (iterator != m_sprites.end()) if (iterator != m_sprites.end())
m_sprites.erase(iterator); m_sprites.erase(iterator);
} }
#else
void SpriteFile::removeSprite(const QString& name)
{
m_sprites.remove(name.toLower());
}
#endif
void SpriteFile::removeSprite(Sprite* sprite) void SpriteFile::removeSprite(Sprite* sprite)
{ {
removeSprite(sprite->name()); removeSprite(sprite->name());
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites) void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites)
{ {
if (sprites.size() == 0) if (sprites.size() == 0)
@ -249,18 +175,7 @@ void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites)
m_sprites = sprites; m_sprites = sprites;
} }
#else
void SpriteFile::setSprites(QMap<QString, Sprite*> sprites)
{
if (sprites.size() == 0)
return;
m_sprites.clear();
m_sprites = sprites;
}
#endif
#ifndef ATHENA_USE_QT
Sprite* SpriteFile::sprite(const std::string& name) Sprite* SpriteFile::sprite(const std::string& name)
{ {
std::string nameLow(name); std::string nameLow(name);
@ -271,21 +186,8 @@ Sprite* SpriteFile::sprite(const std::string& name)
return m_sprites[nameLow]; return m_sprites[nameLow];
} }
#else
Sprite* SpriteFile::sprite(const QString& name)
{
if (!m_sprites.contains(name.toLower()))
return NULL;
return m_sprites[name.toLower()];
}
#endif
#ifndef ATHENA_USE_QT
std::unordered_map<std::string, Sprite*> SpriteFile::sprites() const std::unordered_map<std::string, Sprite*> SpriteFile::sprites() const
#else
QMap<QString, Sprite*> SpriteFile::sprites() const
#endif
{ {
return m_sprites; return m_sprites;
} }
@ -295,7 +197,6 @@ atUint32 SpriteFile::spriteCount() const
return (atUint32)m_sprites.size(); return (atUint32)m_sprites.size();
} }
#ifndef ATHENA_USE_QT
void SpriteFile::setTextures(std::vector<STexture*> textures) void SpriteFile::setTextures(std::vector<STexture*> textures)
{ {
if (textures.size() == 0) if (textures.size() == 0)
@ -314,15 +215,6 @@ void SpriteFile::setTextures(std::vector<STexture*> textures)
m_textures = textures; m_textures = textures;
} }
#else
void SpriteFile::setTextures(QList<STexture*> textures)
{
if (textures.size() == 0)
return;
m_textures.clear();
m_textures = textures;
}
#endif
} // Sakura } // Sakura
} // zelda } // zelda

View File

@ -10,12 +10,12 @@ namespace athena
namespace io namespace io
{ {
SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length) SpriteFileReader::SpriteFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
SpriteFileReader::SpriteFileReader(const std::string& filepath) SpriteFileReader::SpriteFileReader(const std::string& filepath)
: base(filepath) : MemoryCopyReader(filepath)
{ {
} }

View File

@ -9,12 +9,12 @@ namespace athena
namespace io namespace io
{ {
SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length) SpriteFileWriter::SpriteFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
SpriteFileWriter::SpriteFileWriter(const std::string& filepath) SpriteFileWriter::SpriteFileWriter(const std::string& filepath)
: base(filepath) : MemoryCopyWriter(filepath)
{ {
} }
@ -26,73 +26,51 @@ void SpriteFileWriter::writeFile(Sakura::SpriteFile* file)
return; return;
} }
base::writeUint32(Sakura::SpriteFile::Magic); writeUint32(Sakura::SpriteFile::Magic);
base::writeUint32(Sakura::SpriteFile::Version); writeUint32(Sakura::SpriteFile::Version);
base::writeUint16(file->textureCount()); writeUint16(file->textureCount());
base::writeUint32(file->width()); writeUint32(file->width());
base::writeUint32(file->height()); writeUint32(file->height());
base::writeFloat(file->originX()); writeFloat(file->originX());
base::writeFloat(file->originY()); writeFloat(file->originY());
base::writeUint16(file->spriteCount()); writeUint16(file->spriteCount());
base::writeUint32(0xFFFFFFFF); writeUint32(0xFFFFFFFF);
for (Sakura::STexture* texture : file->textures()) for (Sakura::STexture* texture : file->textures())
{ {
base::writeString(texture->Filepath); writeString(texture->Filepath);
base::writeBool(texture->Preload); writeBool(texture->Preload);
} }
#ifndef ATHENA_USE_QT
for (std::pair<std::string, Sakura::Sprite*> spritePair : file->sprites()) for (std::pair<std::string, Sakura::Sprite*> spritePair : file->sprites())
{ {
Sakura::Sprite* sprite = spritePair.second; Sakura::Sprite* sprite = spritePair.second;
base::writeString(sprite->name()); writeString(sprite->name());
#else writeUint16(sprite->frameCount());
writeUint16(sprite->stateCount());
foreach (Sakura::Sprite* sprite, file->sprites().values())
{
base::writeString(sprite->name().toStdString());
#endif
base::writeUint16(sprite->frameCount());
base::writeUint16(sprite->stateCount());
for (int id : sprite->stateIds()) for (int id : sprite->stateIds())
base::writeUint16(id); writeUint16(id);
for (Sakura::SpriteFrame* frame : sprite->frames()) for (Sakura::SpriteFrame* frame : sprite->frames())
{ {
base::writeFloat(frame->frameTime()); writeFloat(frame->frameTime());
base::writeUint16(frame->partCount()); writeUint16(frame->partCount());
for (Sakura::SpritePart* part : frame->parts()) for (Sakura::SpritePart* part : frame->parts())
{ {
#ifndef ATHENA_USE_QT writeString(part->name());
base::writeString(part->name()); writeBool(part->hasCollision());
#else writeFloat(part->offset().x);
base::writeString(part->name().toStdString()); writeFloat(part->offset().y);
#endif writeFloat(part->textureOffset().x);
base::writeBool(part->hasCollision()); writeFloat(part->textureOffset().y);
#ifndef ATHENA_USE_QT writeUint32(part->size().x);
base::writeFloat(part->offset().x); writeUint32(part->size().y);
base::writeFloat(part->offset().y); writeBool(part->flippedHorizontally());
base::writeFloat(part->textureOffset().x); writeBool(part->flippedVertically());
base::writeFloat(part->textureOffset().y);
base::writeUint32(part->size().x);
base::writeUint32(part->size().y);
#else
base::writeFloat(part->offset().x());
base::writeFloat(part->offset().y());
base::writeFloat(part->textureOffset().x());
base::writeFloat(part->textureOffset().y());
base::writeUint32(part->size().width());
base::writeUint32(part->size().height());
#endif
base::writeBool(part->flippedHorizontally());
base::writeBool(part->flippedVertically());
} }
} }
} }

View File

@ -19,25 +19,14 @@ SpriteFrame::SpriteFrame(Sprite* root)
void SpriteFrame::setFrameTime(float frameTime) void SpriteFrame::setFrameTime(float frameTime)
{ {
m_frameTime = frameTime; m_frameTime = frameTime;
#ifdef ATHENA_USE_QT
emit frameTimeChanged(frameTime);
#endif
} }
#ifndef ATHENA_USE_QT
void SpriteFrame::setParts(std::vector<SpritePart*> parts) void SpriteFrame::setParts(std::vector<SpritePart*> parts)
#else
void SpriteFrame::setParts(QList<SpritePart*> parts)
#endif
{ {
m_parts = parts; m_parts = parts;
} }
#ifndef ATHENA_USE_QT
std::vector<SpritePart*> SpriteFrame::parts() const std::vector<SpritePart*> SpriteFrame::parts() const
#else
QList<SpritePart*> SpriteFrame::parts() const
#endif
{ {
return m_parts; return m_parts;
} }

View File

@ -18,34 +18,19 @@ SpritePart::SpritePart(SpriteFrame* root, const std::string& name, bool hasColli
: m_root(root), : m_root(root),
m_hasCollision(hasCollision) m_hasCollision(hasCollision)
{ {
#ifdef ATHENA_USE_QT
m_name = QString::fromStdString(name);
#else
m_name = name; m_name = name;
#endif
} }
SpritePart::~SpritePart() SpritePart::~SpritePart()
{ {
} }
#ifndef ATHENA_USE_QT
void SpritePart::setName(const std::string& name) void SpritePart::setName(const std::string& name)
#else
void SpritePart::setName(const QString& name)
#endif
{ {
m_name = name; m_name = name;
#ifdef ATHENA_USE_QT
emit nameChanged(name);
#endif
} }
#ifndef ATHENA_USE_QT
std::string SpritePart::name() const std::string SpritePart::name() const
#else
QString SpritePart::name() const
#endif
{ {
return m_name; return m_name;
} }
@ -53,9 +38,6 @@ QString SpritePart::name() const
void SpritePart::setCollision(bool col) void SpritePart::setCollision(bool col)
{ {
m_hasCollision = col; m_hasCollision = col;
#ifdef ATHENA_USE_QT
emit collisionChanged(col);
#endif
} }
bool SpritePart::hasCollision() const bool SpritePart::hasCollision() const
@ -65,90 +47,45 @@ bool SpritePart::hasCollision() const
void SpritePart::setOffset(float x, float y) void SpritePart::setOffset(float x, float y)
{ {
#ifndef ATHENA_USE_QT
setOffset(Vector2Df(x, y)); setOffset(Vector2Df(x, y));
#else
setOffset(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setOffset(const Vector2Df& offset) void SpritePart::setOffset(const Vector2Df& offset)
#else
void SpritePart::setOffset(const QPoint& offset)
#endif
{ {
m_offset = offset; m_offset = offset;
#ifdef ATHENA_USE_QT
emit offsetChanged(offset);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpritePart::offset() const Vector2Df SpritePart::offset() const
#else
QPoint SpritePart::offset() const
#endif
{ {
return m_offset; return m_offset;
} }
void SpritePart::setTextureOffset(float x, float y) void SpritePart::setTextureOffset(float x, float y)
{ {
#ifndef ATHENA_USE_QT
setTextureOffset(Vector2Df(x, y)); setTextureOffset(Vector2Df(x, y));
#else
setTextureOffset(QPoint(x, y));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setTextureOffset(const Vector2Df& offset) void SpritePart::setTextureOffset(const Vector2Df& offset)
#else
void SpritePart::setTextureOffset(const QPoint& offset)
#endif
{ {
m_textureOffset = offset; m_textureOffset = offset;
#ifdef ATHENA_USE_QT
emit textureOffsetChanged(offset);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Df SpritePart::textureOffset() const Vector2Df SpritePart::textureOffset() const
#else
QPoint SpritePart::textureOffset() const
#endif
{ {
return m_textureOffset; return m_textureOffset;
} }
void SpritePart::setSize(atUint32 width, atUint32 height) void SpritePart::setSize(atUint32 width, atUint32 height)
{ {
#ifndef ATHENA_USE_QT
setSize(Vector2Di(width, height)); setSize(Vector2Di(width, height));
#else
setSize(QSize(width, height));
#endif
} }
#ifndef ATHENA_USE_QT
void SpritePart::setSize(const Vector2Di& size) void SpritePart::setSize(const Vector2Di& size)
#else
void SpritePart::setSize(const QSize& size)
#endif
{ {
m_size = size; m_size = size;
#ifdef ATHENA_USE_QT
emit sizeChanged(size);
#endif
} }
#ifndef ATHENA_USE_QT
Vector2Di SpritePart::size() const Vector2Di SpritePart::size() const
#else
QSize SpritePart::size() const
#endif
{ {
return m_size; return m_size;
} }
@ -156,9 +93,6 @@ QSize SpritePart::size() const
void SpritePart::setFlippedHorizontally(const bool val) void SpritePart::setFlippedHorizontally(const bool val)
{ {
m_flippedH = val; m_flippedH = val;
#ifdef ATHENA_USE_QT
emit orientationChanged(val, flippedVertically());
#endif
} }
bool SpritePart::flippedHorizontally() const bool SpritePart::flippedHorizontally() const
@ -169,9 +103,6 @@ bool SpritePart::flippedHorizontally() const
void SpritePart::setFlippedVertically(const bool val) void SpritePart::setFlippedVertically(const bool val)
{ {
m_flippedV = val; m_flippedV = val;
#ifdef ATHENA_USE_QT
emit orientationChanged(flippedHorizontally(), val);
#endif
} }
bool SpritePart::flippedVertically() const bool SpritePart::flippedVertically() const

View File

@ -13,12 +13,12 @@ namespace io
{ {
ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length) ZQuestFileReader::ZQuestFileReader(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyReader(data, length)
{ {
} }
ZQuestFileReader::ZQuestFileReader(const std::string& filename) ZQuestFileReader::ZQuestFileReader(const std::string& filename)
: base(filename) : MemoryCopyReader(filename)
{ {
} }

View File

@ -9,12 +9,12 @@ namespace io
{ {
ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length) ZQuestFileWriter::ZQuestFileWriter(atUint8* data, atUint64 length)
: base(data, length) : MemoryCopyWriter(data, length)
{ {
} }
ZQuestFileWriter::ZQuestFileWriter(const std::string& filename) ZQuestFileWriter::ZQuestFileWriter(const std::string& filename)
: base(filename) : MemoryCopyWriter(filename)
{ {
} }