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()
# 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)

View File

@ -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 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 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 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 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 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 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 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 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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
{
}

View File

@ -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)
{
}

View File

@ -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)
{
}

View File

@ -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)
{
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

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)
#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());
}
#ifndef ATHENA_USE_QT
void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> sprites)
{
if (sprites.size() == 0)
@ -249,18 +175,7 @@ void SpriteFile::setSprites(std::unordered_map<std::string, Sprite*> 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)
{
std::string nameLow(name);
@ -271,21 +186,8 @@ Sprite* SpriteFile::sprite(const std::string& name)
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
#else
QMap<QString, Sprite*> SpriteFile::sprites() const
#endif
{
return m_sprites;
}
@ -295,7 +197,6 @@ atUint32 SpriteFile::spriteCount() const
return (atUint32)m_sprites.size();
}
#ifndef ATHENA_USE_QT
void SpriteFile::setTextures(std::vector<STexture*> textures)
{
if (textures.size() == 0)
@ -314,15 +215,6 @@ void SpriteFile::setTextures(std::vector<STexture*> textures)
m_textures = textures;
}
#else
void SpriteFile::setTextures(QList<STexture*> textures)
{
if (textures.size() == 0)
return;
m_textures.clear();
m_textures = textures;
}
#endif
} // Sakura
} // zelda

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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