@@ -4,7 +4,7 @@ project(swan) | |||
find_package(SFML 2.5 COMPONENTS graphics system window REQUIRED) | |||
set(CMAKE_CXX_CLANG_TIDY | |||
clang-tidy; | |||
clang-tidy | |||
-header-filter=.* | |||
-checks=-*,-checks=bugprone-*,cert-*,performance-*,clang-analyzer-*,-cert-dcl16-c,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall) | |||
@@ -12,85 +12,85 @@ struct Vector2 { | |||
constexpr Vector2(T x = 0, T y = 0): x(x), y(y) {} | |||
Vector2<T> &set(T x, T y) { | |||
constexpr Vector2<T> &set(T x, T y) { | |||
this->x = x; | |||
this->y = y; | |||
return *this; | |||
} | |||
operator sf::Vector2<T>() const { | |||
constexpr operator sf::Vector2<T>() const { | |||
return sf::Vector2<T>(x, y); | |||
} | |||
operator std::pair<T, T>() const { | |||
constexpr operator std::pair<T, T>() const { | |||
return std::pair<T, T>(x, y); | |||
} | |||
operator Vector2<float>() const { | |||
constexpr operator Vector2<float>() const { | |||
return Vector2<float>(x, y); | |||
} | |||
bool operator==(const Vector2<T> &vec) const { | |||
constexpr bool operator==(const Vector2<T> &vec) const { | |||
return x == vec.x && y == vec.y; | |||
} | |||
bool operator!=(const Vector2<T> &vec) const { | |||
constexpr bool operator!=(const Vector2<T> &vec) const { | |||
return !(*this == vec); | |||
} | |||
Vector2<T> operator-() const { | |||
constexpr Vector2<T> operator-() const { | |||
return Vector2<T>(-x, -y); | |||
} | |||
Vector2<T> operator+(const Vector2<T> &vec) const { | |||
constexpr Vector2<T> operator+(const Vector2<T> &vec) const { | |||
return Vector2<T>(x + vec.x, y + vec.y); | |||
} | |||
Vector2<T> &operator+=(const Vector2<T> &vec) { | |||
constexpr Vector2<T> &operator+=(const Vector2<T> &vec) { | |||
x += vec.x; | |||
y += vec.y; | |||
return *this; | |||
} | |||
Vector2<T> operator-(const Vector2<T> &vec) const { | |||
constexpr Vector2<T> operator-(const Vector2<T> &vec) const { | |||
return Vector2<T>(x - vec.x, y - vec.y); | |||
} | |||
Vector2<T> &operator-=(const Vector2<T> &vec) { | |||
constexpr Vector2<T> &operator-=(const Vector2<T> &vec) { | |||
x -= vec.x; | |||
y -= vec.y; | |||
return *this; | |||
} | |||
Vector2<T> operator*(const Vector2<T> &vec) const { | |||
constexpr Vector2<T> operator*(const Vector2<T> &vec) const { | |||
return Vector2<T>(x * vec.x, y * vec.y); | |||
} | |||
Vector2<T> &operator*=(const Vector2<T> &vec) { | |||
constexpr Vector2<T> &operator*=(const Vector2<T> &vec) { | |||
x *= vec.x; | |||
y *= vec.y; | |||
return *this; | |||
} | |||
Vector2<T> operator*(T num) const { | |||
constexpr Vector2<T> operator*(T num) const { | |||
return Vector2<T>(x * num, y * num); | |||
} | |||
Vector2<T> operator*=(T num) { | |||
constexpr Vector2<T> operator*=(T num) { | |||
x *= num; | |||
y *= num; | |||
return *this; | |||
} | |||
Vector2<T> operator/(const Vector2<T> &vec) const { | |||
constexpr Vector2<T> operator/(const Vector2<T> &vec) const { | |||
return Vector2<T>(x / vec.x, y / vec.y); | |||
} | |||
Vector2<T> &operator/=(const Vector2<T> &vec) { | |||
constexpr Vector2<T> &operator/=(const Vector2<T> &vec) { | |||
x /= vec.x; | |||
y /= vec.y; | |||
return *this; | |||
} | |||
Vector2<T> operator/(T num) const { | |||
constexpr Vector2<T> operator/(T num) const { | |||
return Vector2<T>(x / num, y / num); | |||
} | |||
Vector2<T> operator/=(T num) { | |||
constexpr Vector2<T> operator/=(T num) { | |||
x /= num; | |||
y /= num; | |||
return *this; |
@@ -0,0 +1,34 @@ | |||
#pragma once | |||
#include "common.h" | |||
namespace Swan { | |||
class Win { | |||
public: | |||
float scale_ = 2; | |||
Vec2 cam_; | |||
Win(sf::RenderWindow *win): window_(win) {} | |||
void setPos(const Vec2 &pos) { | |||
transform_ = sf::Transform() | |||
.scale(scale_, scale_) | |||
.translate((pos - cam_) * TILE_SIZE); | |||
} | |||
void draw(const sf::Drawable &drawable) { | |||
window_->draw(drawable, transform_); | |||
} | |||
Vec2 getSize() { | |||
sf::Vector2u v = window_->getSize(); | |||
return Vec2(v.x, v.y) / (TILE_SIZE * scale_); | |||
} | |||
private: | |||
sf::RenderWindow *window_; | |||
sf::Transform transform_; | |||
}; | |||
} |
@@ -18,6 +18,7 @@ using ChunkPos = Vec2i; | |||
class Game; | |||
class World; | |||
class WorldPlane; | |||
class Win; | |||
struct Context { | |||
Game &game; | |||
@@ -25,28 +26,4 @@ struct Context { | |||
WorldPlane &plane; | |||
}; | |||
struct Win { | |||
sf::RenderWindow *window_; | |||
sf::Transform transform_; | |||
Vec2 cam_; | |||
float scale_ = 2; | |||
Win(sf::RenderWindow *win): window_(win) {} | |||
void setPos(const Vec2 &pos) { | |||
transform_ = sf::Transform() | |||
.scale(scale_, scale_) | |||
.translate((pos - cam_) * TILE_SIZE); | |||
} | |||
void draw(const sf::Drawable &drawable) { | |||
window_->draw(drawable, transform_); | |||
} | |||
Vec2 getSize() { | |||
sf::Vector2u v = window_->getSize(); | |||
return Vec2(v.x, v.y) / (TILE_SIZE * scale_); | |||
} | |||
}; | |||
} |
@@ -12,6 +12,7 @@ | |||
#include <swan/Tile.h> | |||
#include <swan/Timer.h> | |||
#include <swan/Vector2.h> | |||
#include <swan/Win.h> | |||
#include <swan/World.h> | |||
#include <swan/WorldGen.h> | |||
#include <swan/WorldPlane.h> |
@@ -1,5 +1,7 @@ | |||
#include "Animation.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
void Animation::init(int w, int h, float interval, const Asset &asset, int flags) { |
@@ -3,6 +3,7 @@ | |||
#include <math.h> | |||
#include "WorldPlane.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
@@ -5,6 +5,7 @@ | |||
#include "World.h" | |||
#include "Game.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
@@ -6,6 +6,7 @@ | |||
#include "Tile.h" | |||
#include "Asset.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
@@ -3,6 +3,7 @@ | |||
#include <SFML/System/Clock.hpp> | |||
#include "Game.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
@@ -7,6 +7,7 @@ | |||
#include "World.h" | |||
#include "Game.h" | |||
#include "Timer.h" | |||
#include "Win.h" | |||
namespace Swan { | |||
@@ -7,6 +7,7 @@ | |||
#include <swan/World.h> | |||
#include <swan/Game.h> | |||
#include <swan/Timer.h> | |||
#include <swan/Win.h> | |||
#include <SFML/System/Clock.hpp> | |||
#include <SFML/Audio.hpp> |