Skip to content

Commit

Permalink
qt: Add some more vector types to WzConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed Apr 18, 2011
1 parent dda501b commit c32d791
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/framework/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "frame.h"
#include "math_ext.h"

struct Rotation;
struct Vector2i
{
Vector2i() {}
Expand All @@ -48,7 +49,7 @@ struct Vector3i
Vector3i() {}
Vector3i(int x, int y, int z) : x(x), y(y), z(z) {}
Vector3i(Vector2i const &xy, int z) : x(xy.x), y(xy.y), z(z) {}

Vector3i(Rotation const &r);
int x, y, z;
};
struct Vector3f
Expand All @@ -65,11 +66,13 @@ struct Rotation
{
Rotation() {}
Rotation(int direction, int pitch, int roll) : direction(direction), pitch(pitch), roll(roll) {}

Rotation(Vector3i xyz) : direction(xyz.x), pitch(xyz.y), roll(xyz.z) {}
uint16_t direction, pitch, roll; ///< Object rotation in 0..64k range
};
typedef Vector3i Position; ///< Map position in world coordinates

inline Vector3i::Vector3i(Rotation const &r) : x(r.direction), y(r.pitch), z(r.roll) {}

// removeZ(3d_vector) -> 2d_vector
static inline WZ_DECL_PURE Vector2i removeZ(Vector3i const &a) { return Vector2i(a.x, a.y); }
static inline WZ_DECL_PURE Vector2f removeZ(Vector3f const &a) { return Vector2f(a.x, a.y); }
Expand Down
20 changes: 20 additions & 0 deletions lib/framework/wzapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,3 +1359,23 @@ Vector3i WzConfig::vector3i(const QString &name)
r.z = v[2].toInt();
return r;
}

void WzConfig::setVector2i(const QString &name, const Vector2i &v)
{
QStringList l;
l.push_back(QString::number(v.x));
l.push_back(QString::number(v.y));
setValue(name, l);
}

Vector2i WzConfig::vector2i(const QString &name)
{
Vector2i r;
ASSERT_OR_RETURN(r, contains(name), "Missing %s", name.toUtf8().constData());
QList<QVariant> v = value(name).toList();
ASSERT(v.size() == 2, "Bad list of %s", name.toUtf8().constData());
r.x = v[0].toInt();
r.y = v[1].toInt();
return r;
}

2 changes: 2 additions & 0 deletions lib/framework/wzapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class WzConfig : public QSettings
void setVector3f(const QString &name, const Vector3f &v);
Vector3i vector3i(const QString &name);
void setVector3i(const QString &name, const Vector3i &v);
Vector2i vector2i(const QString &name);
void setVector2i(const QString &name, const Vector2i &v);
};

class WzMainWindow : public QGLWidget
Expand Down

0 comments on commit c32d791

Please sign in to comment.