More code cleanup

keep-around/0eb7fb20e8ec47eea3c9ed47a2b91a4923050d1a
Phillip Stephens 7 years ago
parent e5715bbf8f
commit 0eb7fb20e8
  1. 2
      AthenaConfig.cmake.in
  2. 199
      include/athena/Global.hpp
  3. 1
      include/athena/SkywardSwordFileReader.hpp
  4. 3
      include/athena/SkywardSwordQuest.hpp
  5. 67
      include/athena/Sprite.hpp
  6. 70
      include/athena/SpriteFile.hpp
  7. 1
      include/athena/SpriteFileWriter.hpp
  8. 30
      include/athena/SpriteFrame.hpp
  9. 125
      include/athena/SpritePart.hpp
  10. 2
      libAthena.pc.in
  11. 4
      src/athena/ALTTPFileReader.cpp
  12. 4
      src/athena/ALTTPFileWriter.cpp
  13. 4
      src/athena/MCFileReader.cpp
  14. 4
      src/athena/MCFileWriter.cpp
  15. 4
      src/athena/SkywardSwordFileReader.cpp
  16. 4
      src/athena/SkywardSwordFileWriter.cpp
  17. 67
      src/athena/Sprite.cpp
  18. 108
      src/athena/SpriteFile.cpp
  19. 4
      src/athena/SpriteFileReader.cpp
  20. 80
      src/athena/SpriteFileWriter.cpp
  21. 11
      src/athena/SpriteFrame.cpp
  22. 69
      src/athena/SpritePart.cpp
  23. 4
      src/athena/ZQuestFileReader.cpp
  24. 4
      src/athena/ZQuestFileWriter.cpp

@ -14,7 +14,7 @@ if(NOT TARGET AthenaCore AND NOT Athena_BINARY_DIR)
endif()
# 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
if(WIN32 AND NOT CYGWIN)

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

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

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

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

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

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

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

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

@ -6,5 +6,5 @@ Name: libAthena
Description: Basic cross platform IO library
Version: @ATHENA_VERSION@
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

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

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

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

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

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

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

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

@ -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)
#else
SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
#endif
: m_size(size),
m_origin(origin)
{
@ -38,113 +34,64 @@ SpriteFile::SpriteFile(const QSize& size, const QPoint& origin)
SpriteFile::~SpriteFile()
{
#ifndef ATHENA_USE_QT
for (std::pair<std::string, Sprite*> sprite : m_sprites)
{
delete sprite.second;
sprite.second = NULL;
}
#endif
m_sprites.clear();
}
void SpriteFile::setSize(atUint32 width, atUint32 height)
{
#ifndef ATHENA_USE_QT
setSize(Vector2Di(width, height));
#else
setSize(QSize(width, height));
#endif
}
#ifndef ATHENA_USE_QT
void SpriteFile::setSize(const Vector2Di& size)
#else
void SpriteFile::setSize(const QSize& size)
#endif
{
m_size = size;
#ifdef ATHENA_USE_QT
emit sizeChanged(size);
#endif
}
#ifndef ATHENA_USE_QT
Vector2Di SpriteFile::size() const
#else
QSize SpriteFile::size() const
#endif
{
return m_size;
}
atUint32 SpriteFile::width() const
{
#ifndef ATHENA_USE_QT
return m_size.x;
#else
return m_size.width();
#endif
}
atUint32 SpriteFile::height() const
{
#ifndef ATHENA_USE_QT
return m_size.y;
#else
return m_size.height();
#endif
}
void SpriteFile::setOrigin(const float x, const float y)
{
#ifndef ATHENA_USE_QT
setOrigin(Vector2Df(x, y));
#else
setOrigin(QPoint(x, y));
#endif
}
#ifndef ATHENA_USE_QT
void SpriteFile::setOrigin(const Vector2Df& origin)
#else
void SpriteFile::setOrigin(const QPoint& origin)
#endif
{
m_origin = origin;
#ifdef ATHENA_USE_QT
emit originChanged(origin);
#endif
}
#ifndef ATHENA_USE_QT
Vector2Df SpriteFile::origin() const
#else
QPoint SpriteFile::origin() const
#endif
{
return m_origin;
}
float SpriteFile::originX() const
{
#ifndef ATHENA_USE_QT
return m_origin.x;
#else
return m_origin.x();
#endif
}
float SpriteFile::originY() const
{
#ifndef ATHENA_USE_QT
return m_origin.y;
#else
return m_origin.y();
#endif
}
bool SpriteFile::addTexture(STexture* texture)
@ -174,11 +121,7 @@ STexture* SpriteFile::texture(atUint32 id)
return m_textures[id];
}
#ifndef ATHENA_USE_QT
std::vector<STexture*> SpriteFile::textures() const
#else
QList<STexture*> SpriteFile::textures() const
#endif
{
return m_textures;
}
@ -190,25 +133,15 @@ atUint32 SpriteFile::textureCount() const
void SpriteFile::addSprite(Sprite* sprite)
{
#ifndef ATHENA_USE_QT
std::string name(sprite->name());
athena::utility::tolower(name);
if (m_sprites.find(name) != m_sprites.end())
return;
#else
QString name = sprite->name().toLower();
if (m_sprites.contains(name))
return;
#endif
m_sprites[name] = sprite;
}
#ifndef ATHENA_USE_QT
void SpriteFile::removeSprite(const std::string& name)
{
std::string tmpName(name);
@ -218,19 +151,12 @@ void SpriteFile::removeSprite(const std::string& name)
if (iterator != m_sprites.end())
m_sprites.erase(iterator);
}
#else
void SpriteFile::removeSprite(const QString& name)
{
m_sprites.remove(name.toLower());
}
#endif
void SpriteFile::removeSprite(Sprite* sprite)
{
removeSprite(sprite->name());
}