some refastoring, cycled map

This commit is contained in:
programsnail 2024-07-25 20:51:31 +03:00
parent b4509733da
commit 1e9c70f7d8
5 changed files with 44 additions and 16 deletions

View file

@ -1,8 +1,10 @@
#pragma once
#include <algorithm>
#include <cassert>
#include "Engine.h"
#include "Params.hpp"
#include "Vec.hpp"
namespace utils {
@ -21,21 +23,39 @@ inline int x(int x) { return safe::ux(safe::lx(x)); }
inline int y(int y) { return safe::uy(safe::ly(y)); }
} // namespace safe
inline uint32_t *screen_at(int x, int y) {
return &buffer[safe::x(x)][safe::y(y)];
inline uint32_t *screen_at(Veci pos) {
return &buffer[safe::x(pos.x)][safe::y(pos.y)];
}
template <typename T> inline bool is_valid_pos(Vec<T> pos) {
template <typename T> inline bool is_on_screen(Vec<T> pos) {
return pos.x >= 0 and pos.x < SCREEN_HEIGHT and pos.y >= 0 and
pos.y < SCREEN_WIDTH;
}
inline Veci get_cursor() { return {.x = get_cursor_y(), .y = get_cursor_x()}; }
inline constexpr Veci get_center() {
inline constexpr Veci get_screen_center() {
return {.x = SCREEN_HEIGHT / 2, .y = SCREEN_WIDTH / 2};
}
//
template <typename T> inline T to_inteval_from_zero_to(uint bound, T val) {
assert(bound != 0);
bool was_negative = (val < 0);
val = std::abs(val);
val = val - int((int(val) / bound) * bound);
return was_negative ? bound - val : val;
}
template <typename T> inline Vec<T> to_world_coord(Vec<T> pos) {
return {
.x = to_inteval_from_zero_to(WORLD_SIZE.x, pos.x),
.y = to_inteval_from_zero_to(WORLD_SIZE.y, pos.y),
};
}
} // namespace utils
namespace color {