/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#ifndef TWP_UTIL_H
#define TWP_UTIL_H
#include "common/formats/json.h"
#include "common/hashmap.h"
#include "common/rect.h"
#include "math/vector2d.h"
#include "math/matrix4.h"
#include "twp/ids.h"
#include "twp/objectanimation.h"
namespace Twp {
enum class Facing;
}
namespace Common {
template<>
struct Hash : public UnaryFunction {
uint operator()(Twp::Facing val) const { return (uint)val; }
};
} // namespace Common
namespace Twp {
class Object;
struct Vector2i {
int x = 0;
int y = 0;
Vector2i() {}
Vector2i(int x_, int y_) : x(x_), y(y_) {}
Vector2i(float x_, float y_) : x(round(x_)), y(round(y_)) {}
explicit Vector2i(const Math::Vector2d &p) : x(round(p.getX())), y(round(p.getY())) {}
explicit operator Math::Vector2d() const {
return Math::Vector2d(x, y);
}
Vector2i operator-(const Vector2i &v) const {
return Vector2i(x - v.x, y - v.y);
}
Vector2i operator+(const Vector2i &v) const {
return Vector2i(x + v.x, y + v.y);
}
Vector2i operator*(float f) const {
return Vector2i(x * f, y * f);
}
Vector2i operator/(float f) const {
return Vector2i(x / f, y / f);
}
};
// general util
template >
using unique_ptr = Common::ScopedPtr;
// game util
Facing getFacing(int dir, Facing facing);
Facing flip(Facing facing);
Facing getFacingToFaceTo(Common::SharedPtr