67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <SDL3/SDL.h>
|
|
#include <shared_mutex>
|
|
#include <random>
|
|
#include <cstdlib>
|
|
|
|
#define DISABLE_COPY(Class) \
|
|
Class(const Class&) = delete; \
|
|
Class& operator=(const Class&) = delete;
|
|
|
|
#define DISABLE_MOVE(Class) \
|
|
Class(Class&&) = delete; \
|
|
Class& operator=(Class&&) = delete;
|
|
|
|
#define DISABLE_COPY_AND_MOVE(Class) \
|
|
DISABLE_COPY(Class) \
|
|
DISABLE_MOVE(Class)
|
|
|
|
#define LOG(Msg) \
|
|
std::cout << "\033[0m[LOG] " << __PRETTY_FUNCTION__ << ' ' << Msg << '\n';
|
|
|
|
#define WARN(Msg) \
|
|
std::cout << "\033[33m[WARN] " << __PRETTY_FUNCTION__ << ' ' << Msg << "\033[0m\n";
|
|
|
|
#define ERROR(Msg) \
|
|
std::cout << "\033[31m[ERROR] " << __PRETTY_FUNCTION__ << ' ' << Msg << "\033[0m\n";
|
|
|
|
#define PLNIMP(Msg) \
|
|
std::cout << "\033[92m" << Msg << "\033[0m\n";
|
|
|
|
#define GAME_ENTITY(ClassName) \
|
|
class ClassName : public Object::Entity { \
|
|
using Object::Entity::Entity; \
|
|
public: \
|
|
~ClassName() override = default; \
|
|
void start() override; \
|
|
void update(float deltaTime) override;
|
|
|
|
#define END_GAME_ENTITY() \
|
|
};
|
|
|
|
#define RUNNING_TIME() \
|
|
SDL_GetTicks() / 1000.f
|
|
|
|
#define PI 3.14159265358979323846f
|
|
#define UNIVERSAL_SCALE_COEFFICIENT 0.25f
|
|
#define TARGET_FPS 60
|
|
#define TARGET_UPDATE_RATE 120
|
|
#define ENABLE_LOW_LATENCY_VSYNC 1
|
|
#define VSYNC_FPS_OFFSET 2
|
|
|
|
class Utils {
|
|
public:
|
|
static Utils& getUtils() { static Utils instance; return instance; }
|
|
// Random in range 32 bits
|
|
int rirng32(int a, int b) {
|
|
std::lock_guard lock(mMutex);
|
|
std::mt19937 mGen(mRd());
|
|
std::uniform_int_distribution<> distr(a, b);
|
|
return distr(mGen);
|
|
}
|
|
private:
|
|
mutable std::shared_mutex mMutex;
|
|
std::random_device mRd;
|
|
}; |