- Added GetTime funcs to utils
- Added Time() to App class to gather the apps run time in seconds
- Updated almost every part of the sourcecode to the D7 Style guide
This commit is contained in:
2025-11-26 13:46:46 +01:00
parent 830524c9eb
commit 2a2a670e1a
32 changed files with 913 additions and 813 deletions

View File

@@ -8,6 +8,6 @@
#include <amethyst/renderer.hpp>
#include <amethyst/texture.hpp>
namespace amy {
void registerCxxExceptionHandler();
namespace Amy {
void RegisterCxxExceptionHandler();
}

View File

@@ -3,18 +3,24 @@
#include <amethyst/asset.hpp>
#include <amethyst/types.hpp>
namespace amy {
class app {
namespace Amy {
class App {
public:
app() {}
~app() {}
App() {
pDelta = 0.0;
pTime = 0.0;
pLast = 0LL;
}
~App() {}
virtual void main() {}
void run();
double delta() const { return m_delta; }
virtual void Main() {}
void Run();
double Delta() const { return pDelta; }
double Time() const { return pTime; }
private:
ull m_last;
double m_delta;
ull pLast;
double pDelta;
double pTime;
};
} // namespace amy
} // namespace Amy

View File

@@ -1,9 +1,9 @@
#pragma once
namespace amy {
class asset {
namespace Amy {
class Asset {
public:
asset() = default;
virtual ~asset() = default;
Asset() = default;
virtual ~Asset() = default;
};
} // namespace amy
} // namespace Amy

View File

@@ -3,22 +3,22 @@
#include <amethyst/texture.hpp>
#include <amethyst/types.hpp>
namespace amy {
class assets {
namespace Amy {
class Assets {
public:
assets() = default;
~assets() = default;
Assets() = default;
~Assets() = default;
void add(cstr& id, asset* v) { m_assets[id] = v; }
void remove(cstr& id) {
if (m_assets.count(id)) {
m_assets.erase(id);
void add(ksr id, Asset* v) { pAssets[id] = v; }
void remove(ksr id) {
if (pAssets.count(id)) {
pAssets.erase(id);
}
}
template <typename T>
T* get(cstr& id) {
auto r = m_assets.find(id);
if (r == m_assets.end()) {
T* get(ksr id) {
auto r = pAssets.find(id);
if (r == pAssets.end()) {
throw std::runtime_error("[amy] assets: unable to find " + id);
}
if (auto v = dynamic_cast<T*>(r->second)) {
@@ -29,6 +29,6 @@ class assets {
}
private:
std::map<str, asset*> m_assets;
std::map<str, Asset*> pAssets;
};
} // namespace amy
} // namespace Amy

View File

@@ -9,115 +9,115 @@
#include <amethyst/types.hpp>
#include <string>
namespace amy {
class c3d {
namespace Amy {
class C3D {
public:
c3d() = default;
~c3d() = default;
C3D() = default;
~C3D() = default;
class screen {
class Screen {
public:
screen(C3D_RenderTarget* t) {
m_target = t;
Screen(C3D_RenderTarget* t) {
pTarget = t;
// Width and height are swapped on 3ds due to screen layout
m_width = m_target->frameBuf.height;
m_height = m_target->frameBuf.width;
pWidth = pTarget->frameBuf.height;
pHeight = pTarget->frameBuf.width;
}
~screen() { C3D_RenderTargetDelete(m_target); }
~Screen() { C3D_RenderTargetDelete(pTarget); }
int width() const { return m_width; }
int height() const { return m_height; }
ivec2 size() const { return ivec2(m_width, m_height); }
void clear() { C3D_RenderTargetClear(m_target, C3D_CLEAR_ALL, 0, 0); }
void startDraw() { C3D_FrameDrawOn(m_target); }
int Width() const { return pWidth; }
int Height() const { return pHeight; }
ivec2 Size() const { return ivec2(pWidth, pHeight); }
void Clear() { C3D_RenderTargetClear(pTarget, C3D_CLEAR_ALL, 0, 0); }
void Use() { C3D_FrameDrawOn(pTarget); }
private:
C3D_RenderTarget* m_target = nullptr;
int m_width = 0;
int m_height = 0;
C3D_RenderTarget* pTarget = nullptr;
int pWidth = 0;
int pHeight = 0;
};
class shader : public asset {
class Shader : public Asset {
public:
shader(const std::string& path);
shader() {}
~shader();
Shader(ksr path);
Shader() {}
~Shader();
void load(const std::string& path);
void load(const std::vector<uc>& data);
void compile(const std::string& code);
void use();
void input(int reg, GPU_FORMATS f, int num);
void input(GPU_FORMATS f, int num) { input(m_reg++, f, num); }
void setMat4(int loc, C3D_Mtx* m);
void setMat4(int loc, const mat4& m);
int loc(const std::string& name);
void Load(ksr path);
void Load(kvr<uc> data);
void Compile(ksr code);
void Use();
void Input(int reg, GPU_FORMATS f, int num);
void Input(GPU_FORMATS f, int num) { Input(pReg++, f, num); }
void SetMat4(int loc, C3D_Mtx* m);
void SetMat4(int loc, const mat4& m);
int loc(ksr name);
private:
C3D_AttrInfo m_info;
shaderProgram_s m_program;
DVLB_s* m_code;
int m_reg = 0;
C3D_AttrInfo pInfo;
shaderProgram_s pProgram;
DVLB_s* pCode;
int pReg = 0;
};
class frag {
class Frag {
public:
frag() = default;
~frag() = default;
Frag() = default;
~Frag() = default;
static void edit(int id = 0);
static void src(C3D_TexEnvMode mode, GPU_TEVSRC s1 = GPU_PRIMARY_COLOR,
static void Edit(int id = 0);
static void Src(C3D_TexEnvMode mode, GPU_TEVSRC s1 = GPU_PRIMARY_COLOR,
GPU_TEVSRC s2 = GPU_PRIMARY_COLOR,
GPU_TEVSRC s3 = GPU_PRIMARY_COLOR);
static void func(C3D_TexEnvMode mode, GPU_COMBINEFUNC func);
static void Func(C3D_TexEnvMode mode, GPU_COMBINEFUNC func);
private:
static C3D_TexEnv* m_env;
static C3D_TexEnv* pEnv;
};
static void init();
static void deinit();
static void startFrame(bool sync = true);
static void endFrame();
static screen* createScreen(gfxScreen_t screen, gfx3dSide_t side = GFX_LEFT);
static void deleteScreen(screen* screen);
static void drawArrays(int start, int count,
static void Init();
static void Deinit();
static void StartFrame(bool sync = true);
static void EndFrame();
static Screen* CreateScreen(gfxScreen_t screen, gfx3dSide_t side = GFX_LEFT);
static void DeleteScreen(Screen* screen);
static void DrawArrays(int start, int count,
GPU_Primitive_t prim = GPU_TRIANGLES);
static void drawElements(int count, const void* idx_ptr,
static void DrawElements(int count, const void* idx_ptr,
int type = C3D_UNSIGNED_SHORT,
GPU_Primitive_t prim = GPU_TRIANGLES);
static void depthTest(bool on, GPU_TESTFUNC func = GPU_GREATER,
static void DepthTest(bool on, GPU_TESTFUNC func = GPU_GREATER,
GPU_WRITEMASK mask = GPU_WRITE_ALL);
static void disableScissor();
static void enableScissor(const ivec4 rect);
static void DisableScissor();
static void EnableScissor(const ivec4 rect);
/**
* Buf cfg die permutation at runtime berechnet
*/
static void bufCfg(void* ptr, int stride, int shader_attribs);
static void BufCfg(void* ptr, int stride, int shader_attribs);
/**
* Klassische config bei der man selber die permutation eintragen muss
*/
static void bufCfg(void* ptr, int stride, int shader_attribs,
static void BufCfg(void* ptr, int stride, int shader_attribs,
u64 permutation);
/**
* Hacky funktion um die permutation automatisch at compile time zu berechnen,
* falls diese immer gleich bleibt.
* In der <> steht die anzahl der shader input werte
* usage: c3d::bufCfg<3>(data, sizeof(vertex));
* usage: C3D::bufCfg<3>(data, sizeof(vertex));
*/
template <int attribs>
constexpr static void bufCfg(void* ptr, int stride) {
constexpr static void BufCfg(void* ptr, int stride) {
auto buf = C3D_GetBufInfo();
BufInfo_Init(buf);
constexpr int pm = permutation(attribs);
constexpr int pm = pPermutation(attribs);
BufInfo_Add(buf, ptr, stride, attribs, pm);
}
static int drawcalls() { return m_drawcalls; }
static int Drawcalls() { return pDrawcalls; }
private:
static int m_drawcalls;
static int m__dc__;
static int pDrawcalls;
static int p__dc__; // draw-calls internal
/**
* Funktion die anhand von **ac** genau den permu station wert für BufInfo
@@ -127,7 +127,7 @@ class c3d {
* ac = 4 -> 0x3210
* ```
*/
constexpr static u64 permutation(int ac) {
constexpr static u64 pPermutation(int ac) {
u64 ret = 0;
if (ac < 1 || ac > 15) {
throw std::runtime_error("[amy] " + std::to_string(ac) +
@@ -139,4 +139,4 @@ class c3d {
return ret;
}
};
} // namespace amy
} // namespace Amy

View File

@@ -2,16 +2,16 @@
#include <amethyst/types.hpp>
namespace amy {
namespace ctru {
enum services {
romfs = 1 << 0,
cfgu = 1 << 1,
gfx = 1 << 2,
gfx_def = 1 << 3,
def = romfs | gfx_def
namespace Amy {
namespace Ctr {
enum Services {
Romfs = 1 << 0,
Cfgu = 1 << 1,
Gfx = 1 << 2,
GfxDefault = 1 << 3,
Default = Romfs | GfxDefault,
};
void init(unsigned int srv = def);
ull getTime();
} // namespace ctru
} // namespace amy
void Init(ui srv = Default);
ull GetTime();
} // namespace Ctr
} // namespace Amy

View File

@@ -2,12 +2,12 @@
#include <string>
namespace amy {
class gtrace {
namespace Amy {
class GTrace {
public:
gtrace() = default;
~gtrace() = default;
GTrace() = default;
~GTrace() = default;
private:
};
} // namespace amy
} // namespace Amy

View File

@@ -2,10 +2,10 @@
#include <amethyst/types.hpp>
namespace amy {
class image {
namespace Amy {
class Image {
public:
enum format {
enum Format {
RGBA, // bpp == 4
RGB, // bpp == 3
RGB565, // bpp == 2 (not supported in laoding)
@@ -13,43 +13,43 @@ class image {
ABGR, // bpp == 4
BGRA, // bpp == 4
};
image() = default;
image(cstr& path) { this->load(path); }
image(const std::vector<uc>& buf) { this->load(buf); }
image(const std::vector<uc>& buf, int w, int h, const format& fmt) {
this->copy(buf, w, h, fmt);
Image() = default;
Image(ksr path) { this->Load(path); }
Image(kvr<uc> buf) { this->Load(buf); }
Image(kvr<uc> buf, int w, int h, const Format& fmt) {
this->Copy(buf, w, h, fmt);
}
~image() = default;
~Image() = default;
void load(cstr& path);
void load(const std::vector<uc>& buf);
void copy(const std::vector<uc>& buf, int w, int h, const format& fmt);
void Load(ksr path);
void Load(kvr<uc> buf);
void Copy(kvr<uc> buf, int w, int h, const Format& fmt);
std::vector<uc>& getBuffer() { return m_buffer; }
std::vector<uc> getBuffer() const { return m_buffer; }
vec<uc>& GetBuffer() { return pBuffer; }
vec<uc> GetBuffer() const { return pBuffer; }
int width() const { return m_w; }
int height() const { return m_h; }
int bpp() const { return getBppOfFmt(m_fmt); }
format fmt() const { return m_fmt; }
void convert(const format& dst) { convert(*this, dst); }
void retile(std::function<ui(int x, int y, int w)> src,
int Width() const { return pW; }
int Height() const { return pH; }
int Bpp() const { return GetBppOfFmt(pFmt); }
Format Fmt() const { return pFmt; }
void Convert(const Format& dst) { Convert(*this, dst); }
void Retile(std::function<ui(int x, int y, int w)> src,
std::function<ui(int x, int y, int w)> dst) {
retile(*this, src, dst);
Retile(*this, src, dst);
}
uc& operator[](int idx) { return m_buffer[idx]; }
uc operator[](int idx) const { return m_buffer[idx]; }
uc& operator[](int idx) { return pBuffer[idx]; }
uc operator[](int idx) const { return pBuffer[idx]; }
static void convert(image& img, const format& dst);
static void retile(image& img, std::function<ui(int x, int y, int w)> src,
static void Convert(Image& img, const Format& dst);
static void Retile(Image& img, std::function<ui(int x, int y, int w)> src,
std::function<ui(int x, int y, int w)> dst);
static int getBppOfFmt(const format& fmt);
static int GetBppOfFmt(const Format& fmt);
private:
std::vector<uc> m_buffer;
int m_w = 0;
int m_h = 0;
format m_fmt = RGBA;
vec<uc> pBuffer;
int pW = 0;
int pH = 0;
Format pFmt = RGBA;
};
} // namespace amy
} // namespace Amy

View File

@@ -8,157 +8,157 @@
#include <amethyst/texture.hpp>
#include <amethyst/types.hpp>
namespace amy {
class iron {
namespace Amy {
class Iron {
public:
struct vertex {
vertex(float x, float y, float u, float v, ui clr) {
struct Vertex {
Vertex(float x, float y, float u, float v, ui clr) {
pos.x = x;
pos.y = y;
uv.x = x;
uv.y = y;
color = clr;
}
vertex(const fvec2& pos, const fvec2& uv, ui clr) {
Vertex(const fvec2& pos, const fvec2& uv, ui clr) {
this->pos = pos;
this->uv = uv;
this->color = clr;
}
vertex() {}
Vertex() {}
amy::fvec2 pos;
amy::fvec2 uv;
fvec2 pos;
fvec2 uv;
ui color = 0;
};
class command {
class Command {
public:
command() = default;
using ref = up<command>;
command& add(const u16& idx) {
indexBuf.push_back(vertexBuf.size() + idx);
Command() = default;
using ref = up<Command>;
Command& Add(const u16& idx) {
IndexBuf.push_back(VertexBuf.size() + idx);
return *this;
}
command& add(const vertex& vtx) {
vertexBuf.push_back(std::move(vtx));
Command& Add(const Vertex& vtx) {
VertexBuf.push_back(std::move(vtx));
return *this;
}
std::vector<vertex> vertexBuf;
std::vector<u16> indexBuf;
ivec4 scissorRect;
bool scissorOn = false;
int layer;
int index;
texture* tex;
std::vector<Vertex> VertexBuf;
std::vector<u16> IndexBuf;
ivec4 ScissorRect;
bool ScissorOn = false;
int Layer;
int Index;
Texture* Tex;
};
class drawlist {
class Drawlist {
public:
drawlist() { drawSolid(); }
~drawlist() { m_data.clear(); }
Drawlist() { DrawSolid(); }
~Drawlist() { pData.clear(); }
// required due to memory management
drawlist(const drawlist&) = delete;
drawlist& operator=(const drawlist&) = delete;
drawlist(drawlist&&) noexcept = default;
drawlist& operator=(drawlist&&) noexcept = default;
Drawlist(const Drawlist&) = delete;
Drawlist& operator=(const Drawlist&) = delete;
Drawlist(Drawlist&&) noexcept = default;
Drawlist& operator=(Drawlist&&) noexcept = default;
std::vector<command::ref>& data() { return m_data; }
std::vector<Command::ref>& Data() { return pData; }
void merge(drawlist* list);
command::ref newCommand();
void push(command ::ref cmd);
void clear();
void Merge(Drawlist* list);
Command::ref NewCommand();
void Push(Command ::ref cmd);
void Clear();
void drawSolid();
void drawTex(texture* tex) { m_tex = tex; }
void DrawSolid();
void DrawTex(Texture* tex) { pTex = tex; }
/** Draw Api */
void drawRect(const fvec2& pos, const fvec2& size, ui color,
void DrawRect(const fvec2& pos, const fvec2& size, ui color,
int thickness = 1);
void drawRectFilled(const fvec2& pos, const fvec2& size, ui color);
void drawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, ui color,
void DrawRectFilled(const fvec2& pos, const fvec2& size, ui color);
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, ui color,
int thickness = 1);
void drawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
ui color);
void drawCircle(const fvec2& center, float radius, ui color, int segments,
void DrawCircle(const fvec2& center, float radius, ui color, int segments,
int thickness = 1);
void drawCircleFilled(const fvec2& center, float radius, ui color,
void DrawCircleFilled(const fvec2& center, float radius, ui color,
int segments);
void drawText(const fvec2& pos, const std::string& text, ui color);
void drawTextEx(const fvec2& pos, const std::string& text, ui color,
void DrawText(const fvec2& pos, const std::string& text, ui color);
void DrawTextEx(const fvec2& pos, const std::string& text, ui color,
ui flags, const fvec2& box = 0);
void drawLine(const fvec2& a, const fvec2& b, ui color, int thickness = 1);
void drawPolyLine(const std::vector<fvec2>& points, ui color, ui flags = 0,
void DrawLine(const fvec2& a, const fvec2& b, ui color, int thickness = 1);
void DrawPolyLine(const std::vector<fvec2>& points, ui color, ui flags = 0,
int thickness = 1);
void drawConvexPolyFilled(const std::vector<fvec2>& points, ui color);
void DrawConvexPolyFilled(const std::vector<fvec2>& points, ui color);
/** Path api */
void pathAdd(const fvec2& pos) { m_path.push_back(std::move(pos)); }
void pathClear() { m_path.clear(); }
void pathReserve(size_t count) { m_path.reserve(m_path.size() + count); }
void pathStroke(ui color, int thickness = 1, ui flags = 0) {
drawPolyLine(m_path, color, flags, thickness);
pathClear();
void PathAdd(const fvec2& pos) { pPath.push_back(std::move(pos)); }
void PathClear() { pPath.clear(); }
void PathReserve(size_t count) { pPath.reserve(pPath.size() + count); }
void PathStroke(ui color, int thickness = 1, ui flags = 0) {
DrawPolyLine(pPath, color, flags, thickness);
PathClear();
}
void pathFill(ui color) { drawConvexPolyFilled(m_path, color); }
void pathArcToN(const fvec2& c, float radius, float a_min, float a_max,
void PathFill(ui color) { DrawConvexPolyFilled(pPath, color); }
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
void pathFastArcToN(const fvec2& c, float radius, float a_min, float a_max,
void PathFastArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
void pathRect(const fvec2& a, const fvec2& b, float rounding = 0.f);
void pathRectEx(const fvec2& a, const fvec2& b, float rounfing, ui flags);
void PathRect(const fvec2& a, const fvec2& b, float rounding = 0.f);
void PathRectEx(const fvec2& a, const fvec2& b, float rounfing, ui flags);
void pushClipRect(const fvec4& clip) { clipRects.push(clip); }
void popClipRect() {
if (!clipRects.empty()) clipRects.pop();
void PushClipRect(const fvec4& clip) { ClipRects.push(clip); }
void PopClipRect() {
if (!ClipRects.empty()) ClipRects.pop();
}
operator std::vector<command::ref>&() { return m_data; }
operator std::vector<Command::ref>&() { return pData; }
private:
void clipCmd(command* ptr);
std::vector<command::ref> m_data;
std::vector<fvec2> m_path;
texture* m_tex = nullptr;
std::stack<fvec4> clipRects;
int m_layer = 0;
void clipCmd(Command* ptr);
std::vector<Command::ref> pData;
std::vector<fvec2> pPath;
Texture* pTex = nullptr;
std::stack<fvec4> ClipRects;
int pLayer = 0;
};
iron() = default;
~iron() = default;
Iron() = default;
~Iron() = default;
static void init();
static void newFrame();
static void drawOn(c3d::screen* screen);
static void draw(const std::vector<command::ref>& data);
static texture* whiteTex() { return m_solid; }
static void Init();
static void NewFrame();
static void DrawOn(C3D::Screen* screen);
static void Draw(const std::vector<Command::ref>& data);
static Texture* WhiteTex() { return m_solid; }
/** Static renderer utility funcs */
static void rotateCorner(fvec2& pos, float s, float c);
static rect primRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
static rect primLine(const fvec2& a, const fvec2& b, int thickness = 1);
static void cmdQuad(command* cmd, const rect& q, const rect& uv, ui color);
static void cmdTriangle(command* cmd, const fvec2& a, const fvec2& b,
static void RotateCorner(fvec2& pos, float s, float c);
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
static void CmdQuad(Command* cmd, const Rect& q, const Rect& uv, ui color);
static void CmdTriangle(Command* cmd, const fvec2& a, const fvec2& b,
const fvec2& c, ui clr);
static void cmdConvexPolyFilled(command* cmd,
static void CmdConvexPolyFilled(Command* cmd,
const std::vector<fvec2>& points, ui clr,
texture* tex);
static bool inBox(const fvec2& pos, const fvec2& size, const fvec4& area);
static bool inBox(const fvec2& pos, const fvec4& area);
static bool inBox(const fvec2& a, const fvec2& b, const fvec2& c,
Texture* tex);
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
static bool InBox(const fvec2& pos, const fvec4& area);
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
const fvec4& area);
private:
static void setupShader();
static void fragConfig();
static void initSolidTex();
static void pSetupShader();
static void pFragConfig();
static void pInitSolidTex();
static std::vector<vertex, linearAllocator<vertex>> m_vbuf;
static std::vector<Vertex, linearAllocator<Vertex>> m_vbuf;
static std::vector<u16, linearAllocator<u16>> m_ibuf;
static int uLocProj;
static c3d::shader* m_shader;
static C3D::Shader* m_shader;
static mat4 m_mtx;
static int m_idx, m_vtx;
static texture* m_solid;
static Texture* m_solid;
};
} // namespace amy
} // namespace Amy

View File

@@ -9,7 +9,7 @@
// based on this guide:
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
namespace amy {
namespace Amy {
template <typename T>
class linearAllocator {
public:
@@ -37,4 +37,4 @@ class linearAllocator {
// or to b eable to see a crash report screen.
size_t max_size() const noexcept { return linearSpaceFree(); }
};
} // namespace amy
} // namespace Amy

View File

@@ -29,11 +29,11 @@ SOFTWARE.
#include <cmath>
#include <numbers>
namespace amy {
namespace numbers {
namespace Amy {
namespace Numbers {
constexpr float Tau = std::numbers::pi * 2.f;
}
constexpr float Radians(float v) { return v * (numbers::Tau / 360.0f); }
constexpr float Radians(float v) { return v * (Numbers::Tau / 360.0f); }
/**
* Minimal Mtx4 Lib that precomputes
* basic stuff stuff at compiletime
@@ -141,4 +141,4 @@ struct mat4 {
static mat4 perspective(float fov, float aspect, float n, float f);
static mat4 lookAt(const fvec3& pos, const fvec3& center, const fvec3& up);
};
} // namespace amy
} // namespace Amy

View File

@@ -36,25 +36,25 @@ SOFTWARE.
*/
template <typename T, typename CharT>
struct std::formatter<amy::vec2<T>, CharT> : std::formatter<T, CharT> {
struct std::formatter<Amy::vec2<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const amy::vec2<T> &v, FormatContext &ctx) const {
auto format(const Amy::vec2<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}", v.x, v.y);
}
};
template <typename T, typename CharT>
struct std::formatter<amy::vec3<T>, CharT> : std::formatter<T, CharT> {
struct std::formatter<Amy::vec3<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const amy::vec3<T> &v, FormatContext &ctx) const {
auto format(const Amy::vec3<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}, {}", v.x, v.y, v.z);
}
};
template <typename T, typename CharT>
struct std::formatter<amy::vec4<T>, CharT> : std::formatter<T, CharT> {
struct std::formatter<Amy::vec4<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const amy::vec4<T> &v, FormatContext &ctx) const {
auto format(const Amy::vec4<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "{}, {}, {}, {}", v.x, v.y, v.z, v.w);
}
};

View File

@@ -27,21 +27,24 @@ SOFTWARE.
#include <cmath>
namespace amy {
template <typename T> class vec2 {
public:
namespace Amy {
template <typename T>
class vec2 {
public:
T x;
T y;
// Constructors
constexpr vec2() : x(0), y(0) {}
template <typename T1> constexpr vec2(T1 v) {
template <typename T1>
constexpr vec2(T1 v) {
x = (T)v;
y = (T)v;
}
template <typename T1> constexpr vec2(const vec2<T1> &v) {
template <typename T1>
constexpr vec2(const vec2<T1>& v) {
x = (T)v.x;
y = (T)v.y;
}
@@ -50,93 +53,111 @@ public:
// Operations
template <typename T1> vec2<T> &operator+=(T1 v) {
template <typename T1>
vec2<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
return *this;
}
template <typename T1> vec2<T> &operator+=(const vec2<T1> &v) {
template <typename T1>
vec2<T>& operator+=(const vec2<T1>& v) {
x += (T)v.x;
y += (T)v.y;
return *this;
}
template <typename T1> vec2<T> operator+(T1 v) const {
template <typename T1>
vec2<T> operator+(T1 v) const {
return vec2<T>(x + (T)v, y + (T)v);
}
template <typename T1> vec2<T> operator+(const vec2<T1> &v) const {
template <typename T1>
vec2<T> operator+(const vec2<T1>& v) const {
return vec2<T>(x + (T)v.x, y + (T)v.y);
}
template <typename T1> vec2<T> &operator-=(T1 v) {
template <typename T1>
vec2<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
return *this;
}
template <typename T1> vec2<T> &operator-=(const vec2<T1> &v) {
template <typename T1>
vec2<T>& operator-=(const vec2<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
return *this;
}
template <typename T1> vec2<T> operator-(T1 v) const {
template <typename T1>
vec2<T> operator-(T1 v) const {
return vec2<T>(x - (T)v, y - (T)v);
}
template <typename T1> vec2<T> operator-(const vec2<T1> &v) const {
template <typename T1>
vec2<T> operator-(const vec2<T1>& v) const {
return vec2<T>(x - (T)v.x, y - (T)v.y);
}
template <typename T1> vec2<T> &operator*=(T1 v) {
template <typename T1>
vec2<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
return *this;
}
template <typename T1> vec2<T> &operator*=(const vec2<T1> &v) {
template <typename T1>
vec2<T>& operator*=(const vec2<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
return *this;
}
template <typename T1> vec2<T> operator*(T1 v) const {
template <typename T1>
vec2<T> operator*(T1 v) const {
return vec2<T>(x * (T)v, y * (T)v);
}
template <typename T1> vec2<T> operator*(const vec2<T1> &v) const {
template <typename T1>
vec2<T> operator*(const vec2<T1>& v) const {
return vec2<T>(x * (T)v.x, y * (T)v.y);
}
template <typename T1> vec2<T> &operator/=(T1 v) {
template <typename T1>
vec2<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
return *this;
}
template <typename T1> vec2<T> &operator/=(const vec2<T1> &v) {
template <typename T1>
vec2<T>& operator/=(const vec2<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
return *this;
}
template <typename T1> vec2<T> operator/(T1 v) const {
template <typename T1>
vec2<T> operator/(T1 v) const {
return vec2<T>(x / (T)v, y / (T)v);
}
template <typename T1> vec2<T> operator/(const vec2<T1> &v) const {
template <typename T1>
vec2<T> operator/(const vec2<T1>& v) const {
return vec2<T>(x / (T)v.x, y / (T)v.y);
}
// Generic Operations
vec2 operator-() const { return vec2(-x, -y); }
template <typename T1> bool operator==(const vec2<T1> &v) const {
template <typename T1>
bool operator==(const vec2<T1>& v) const {
return x == (T)v.x && y == (T)v.y;
}
template <typename T1> bool operator!=(const vec2<T1> &v) const {
template <typename T1>
bool operator!=(const vec2<T1>& v) const {
return !(*this == v);
}
@@ -145,7 +166,8 @@ public:
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y; }
template <typename T1> double Distance(const vec2<T1> &v) const {
template <typename T1>
double Distance(const vec2<T1>& v) const {
return (*this - v).Len();
}
@@ -157,7 +179,8 @@ public:
return *this / (T)l;
}
template <typename T1> T Dot(const vec2<T1> &v) const {
template <typename T1>
T Dot(const vec2<T1>& v) const {
return x * (T)v.x + y * (T)v.y;
}
@@ -171,4 +194,4 @@ public:
using fvec2 = vec2<float>;
using ivec2 = vec2<int>;
using dvec2 = vec2<double>;
} // namespace amy
} // namespace Amy

View File

@@ -29,9 +29,10 @@ SOFTWARE.
// Extended includes (rename if you use other filenames/paths)
#include <amethyst/maths/vec2.hpp>
namespace amy {
template <typename T> class vec3 {
public:
namespace Amy {
template <typename T>
class vec3 {
public:
T x;
T y;
T z;
@@ -39,13 +40,15 @@ public:
// Constructors
constexpr vec3() : x(0), y(0), z(0) {}
template <typename T1> constexpr vec3(T1 v) {
template <typename T1>
constexpr vec3(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
}
template <typename T1> constexpr vec3(const vec3<T1> &v) {
template <typename T1>
constexpr vec3(const vec3<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
@@ -54,7 +57,8 @@ public:
constexpr explicit vec3(T x, T y, T z) : x(x), y(y), z(z) {}
// Extended Constructors
template <typename T1> constexpr explicit vec3(const vec2<T1> &xy, T1 z) {
template <typename T1>
constexpr explicit vec3(const vec2<T1>& xy, T1 z) {
{
x = (T)xy.x;
y = (T)xy.y;
@@ -64,101 +68,119 @@ public:
// Operations
template <typename T1> vec3<T> &operator+=(T1 v) {
template <typename T1>
vec3<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
return *this;
}
template <typename T1> vec3<T> &operator+=(const vec3<T1> &v) {
template <typename T1>
vec3<T>& operator+=(const vec3<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
return *this;
}
template <typename T1> vec3<T> operator+(T1 v) const {
template <typename T1>
vec3<T> operator+(T1 v) const {
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
}
template <typename T1> vec3<T> operator+(const vec3<T1> &v) const {
template <typename T1>
vec3<T> operator+(const vec3<T1>& v) const {
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
}
template <typename T1> vec3<T> &operator-=(T1 v) {
template <typename T1>
vec3<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
return *this;
}
template <typename T1> vec3<T> &operator-=(const vec3<T1> &v) {
template <typename T1>
vec3<T>& operator-=(const vec3<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
return *this;
}
template <typename T1> vec3<T> operator-(T1 v) const {
template <typename T1>
vec3<T> operator-(T1 v) const {
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
}
template <typename T1> vec3<T> operator-(const vec3<T1> &v) const {
template <typename T1>
vec3<T> operator-(const vec3<T1>& v) const {
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
}
template <typename T1> vec3<T> &operator*=(T1 v) {
template <typename T1>
vec3<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
return *this;
}
template <typename T1> vec3<T> &operator*=(const vec3<T1> &v) {
template <typename T1>
vec3<T>& operator*=(const vec3<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
return *this;
}
template <typename T1> vec3<T> operator*(T1 v) const {
template <typename T1>
vec3<T> operator*(T1 v) const {
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
}
template <typename T1> vec3<T> operator*(const vec3<T1> &v) const {
template <typename T1>
vec3<T> operator*(const vec3<T1>& v) const {
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
}
template <typename T1> vec3<T> &operator/=(T1 v) {
template <typename T1>
vec3<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
return *this;
}
template <typename T1> vec3<T> &operator/=(const vec3<T1> &v) {
template <typename T1>
vec3<T>& operator/=(const vec3<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
return *this;
}
template <typename T1> vec3<T> operator/(T1 v) const {
template <typename T1>
vec3<T> operator/(T1 v) const {
return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
}
template <typename T1> vec3<T> operator/(const vec3<T1> &v) const {
template <typename T1>
vec3<T> operator/(const vec3<T1>& v) const {
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
}
// Generic Operations
vec3 operator-() const { return vec3(-x, -y, -z); }
template <typename T1> bool operator==(const vec3<T1> &v) const {
template <typename T1>
bool operator==(const vec3<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z;
}
template <typename T1> bool operator!=(const vec3<T1> &v) const {
template <typename T1>
bool operator!=(const vec3<T1>& v) const {
return !(*this == v);
}
@@ -167,7 +189,8 @@ public:
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z; }
template <typename T1> double Distance(const vec3<T1> &v) const {
template <typename T1>
double Distance(const vec3<T1>& v) const {
return (*this - v).Len();
}
@@ -179,11 +202,13 @@ public:
return *this / (T)l;
}
template <typename T1> T Dot(const vec3<T1> &v) const {
template <typename T1>
T Dot(const vec3<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z;
}
template <typename T1> vec3<T> Cross(const vec3<T1> &v) const {
template <typename T1>
vec3<T> Cross(const vec3<T1>& v) const {
return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
}
@@ -207,4 +232,4 @@ public:
using fvec3 = vec3<float>;
using ivec3 = vec3<int>;
using dvec3 = vec3<double>;
} // namespace amy
} // namespace Amy

View File

@@ -30,9 +30,10 @@ SOFTWARE.
#include <amethyst/maths/vec2.hpp>
#include <amethyst/maths/vec3.hpp>
namespace amy {
template <typename T> class vec4 {
public:
namespace Amy {
template <typename T>
class vec4 {
public:
T x;
T y;
T z;
@@ -41,14 +42,16 @@ public:
// Constructors
constexpr vec4() : x(0), y(0), z(0), w(0) {}
template <typename T1> constexpr vec4(T1 v) {
template <typename T1>
constexpr vec4(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
w = (T)v;
}
template <typename T1> constexpr vec4(const vec4<T1> &v) {
template <typename T1>
constexpr vec4(const vec4<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
@@ -59,7 +62,7 @@ public:
// Extended Constructors
template <typename T1>
constexpr explicit vec4(const vec2<T1> &xy, const vec2<T1> &zw) {
constexpr explicit vec4(const vec2<T1>& xy, const vec2<T1>& zw) {
{
x = (T)xy.x;
y = (T)xy.y;
@@ -68,7 +71,8 @@ public:
}
}
template <typename T1> constexpr explicit vec4(const vec3<T1> &xyz, T1 w) {
template <typename T1>
constexpr explicit vec4(const vec3<T1>& xyz, T1 w) {
{
x = (T)xyz.x;
y = (T)xyz.y;
@@ -79,7 +83,8 @@ public:
// Operations
template <typename T1> vec4<T> &operator+=(T1 v) {
template <typename T1>
vec4<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
@@ -87,7 +92,8 @@ public:
return *this;
}
template <typename T1> vec4<T> &operator+=(const vec4<T1> &v) {
template <typename T1>
vec4<T>& operator+=(const vec4<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
@@ -95,15 +101,18 @@ public:
return *this;
}
template <typename T1> vec4<T> operator+(T1 v) const {
template <typename T1>
vec4<T> operator+(T1 v) const {
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
}
template <typename T1> vec4<T> operator+(const vec4<T1> &v) const {
template <typename T1>
vec4<T> operator+(const vec4<T1>& v) const {
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
}
template <typename T1> vec4<T> &operator-=(T1 v) {
template <typename T1>
vec4<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
@@ -111,7 +120,8 @@ public:
return *this;
}
template <typename T1> vec4<T> &operator-=(const vec4<T1> &v) {
template <typename T1>
vec4<T>& operator-=(const vec4<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
@@ -119,15 +129,18 @@ public:
return *this;
}
template <typename T1> vec4<T> operator-(T1 v) const {
template <typename T1>
vec4<T> operator-(T1 v) const {
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
}
template <typename T1> vec4<T> operator-(const vec4<T1> &v) const {
template <typename T1>
vec4<T> operator-(const vec4<T1>& v) const {
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
}
template <typename T1> vec4<T> &operator*=(T1 v) {
template <typename T1>
vec4<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
@@ -135,7 +148,8 @@ public:
return *this;
}
template <typename T1> vec4<T> &operator*=(const vec4<T1> &v) {
template <typename T1>
vec4<T>& operator*=(const vec4<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
@@ -143,15 +157,18 @@ public:
return *this;
}
template <typename T1> vec4<T> operator*(T1 v) const {
template <typename T1>
vec4<T> operator*(T1 v) const {
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
}
template <typename T1> vec4<T> operator*(const vec4<T1> &v) const {
template <typename T1>
vec4<T> operator*(const vec4<T1>& v) const {
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
}
template <typename T1> vec4<T> &operator/=(T1 v) {
template <typename T1>
vec4<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
@@ -159,7 +176,8 @@ public:
return *this;
}
template <typename T1> vec4<T> &operator/=(const vec4<T1> &v) {
template <typename T1>
vec4<T>& operator/=(const vec4<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
@@ -167,21 +185,25 @@ public:
return *this;
}
template <typename T1> vec4<T> operator/(T1 v) const {
template <typename T1>
vec4<T> operator/(T1 v) const {
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
}
template <typename T1> vec4<T> operator/(const vec4<T1> &v) const {
template <typename T1>
vec4<T> operator/(const vec4<T1>& v) const {
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
}
// Generic Operations
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
template <typename T1> bool operator==(const vec4<T1> &v) const {
template <typename T1>
bool operator==(const vec4<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z && w == (T)v.w;
}
template <typename T1> bool operator!=(const vec4<T1> &v) const {
template <typename T1>
bool operator!=(const vec4<T1>& v) const {
return !(*this == v);
}
@@ -190,7 +212,8 @@ public:
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z + w * w; }
template <typename T1> double Distance(const vec4<T1> &v) const {
template <typename T1>
double Distance(const vec4<T1>& v) const {
return (*this - v).Len();
}
@@ -202,7 +225,8 @@ public:
return *this / (T)l;
}
template <typename T1> T Dot(const vec4<T1> &v) const {
template <typename T1>
T Dot(const vec4<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z + w * (T)v.w;
}
@@ -241,4 +265,4 @@ public:
using fvec4 = vec4<float>;
using ivec4 = vec4<int>;
using dvec4 = vec4<double>;
} // namespace amy
} // namespace Amy

View File

@@ -2,60 +2,60 @@
#include <amethyst/types.hpp>
namespace amy {
class rect {
namespace Amy {
class Rect {
public:
rect() : m_top(0), m_bot(0) {}
~rect() = default;
rect(const fvec4& t, const fvec4& b) : m_top(t), m_bot(b) {}
rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br)
: m_top(tl, tr), m_bot(bl, br) {}
rect(const fvec4& duv)
: m_top(duv.x, duv.y, duv.z, duv.y), m_bot(duv.x, duv.w, duv.z, duv.w) {}
Rect() : pTop(0), pBot(0) {}
~Rect() = default;
Rect(const fvec4& t, const fvec4& b) : pTop(t), pBot(b) {}
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br)
: pTop(tl, tr), pBot(bl, br) {}
Rect(const fvec4& duv)
: pTop(duv.x, duv.y, duv.z, duv.y), pBot(duv.x, duv.w, duv.z, duv.w) {}
fvec2 topLeft() const { return fvec2(m_top.x, m_top.y); }
fvec2 topRight() const { return fvec2(m_top.z, m_top.w); }
fvec2 botLeft() const { return fvec2(m_bot.x, m_bot.y); }
fvec2 botRight() const { return fvec2(m_bot.z, m_bot.w); }
fvec2 TopLeft() const { return fvec2(pTop.x, pTop.y); }
fvec2 TopRight() const { return fvec2(pTop.z, pTop.w); }
fvec2 BotLeft() const { return fvec2(pBot.x, pBot.y); }
fvec2 BotRight() const { return fvec2(pBot.z, pBot.w); }
fvec4 top() const { return m_top; }
fvec4& top() { return m_top; }
fvec4 bot() const { return m_bot; }
fvec4& bot() { return m_bot; }
fvec4 Top() const { return pTop; }
fvec4& Top() { return pTop; }
fvec4 Bot() const { return pBot; }
fvec4& Bot() { return pBot; }
rect& topLeft(const fvec2& v) {
m_top.x = v.x;
m_top.y = v.y;
Rect& TopLeft(const fvec2& v) {
pTop.x = v.x;
pTop.y = v.y;
return *this;
}
rect& topRight(const fvec2& v) {
m_top.z = v.x;
m_top.w = v.y;
Rect& TopRight(const fvec2& v) {
pTop.z = v.x;
pTop.w = v.y;
return *this;
}
rect& botLeft(const fvec2& v) {
m_bot.x = v.x;
m_bot.y = v.y;
Rect& BotLeft(const fvec2& v) {
pBot.x = v.x;
pBot.y = v.y;
return *this;
}
rect& botRight(const fvec2& v) {
m_bot.z = v.x;
m_bot.w = v.y;
Rect& BotRight(const fvec2& v) {
pBot.z = v.x;
pBot.w = v.y;
return *this;
}
void swapVec2XY() {
m_top.SwapXY();
m_top.SwapZW();
m_bot.SwapXY();
m_bot.SwapZW();
void SwapVec2XY() {
pTop.SwapXY();
pTop.SwapZW();
pBot.SwapXY();
pBot.SwapZW();
}
private:
fvec4 m_top;
fvec4 m_bot;
fvec4 pTop;
fvec4 pBot;
};
} // namespace amy
} // namespace Amy

View File

@@ -1,9 +1,9 @@
#pragma once
namespace amy {
namespace Amy {
class Renderer {
public:
Renderer();
~Renderer();
};
} // namespace amys
} // namespace Amy

View File

@@ -7,33 +7,33 @@
#include <amethyst/rect.hpp>
#include <amethyst/types.hpp>
namespace amy {
class texture : public asset {
namespace Amy {
class Texture : public Asset {
public:
texture() = default;
texture(cstr& path);
~texture();
void load(cstr& path);
void load(const std::vector<uc>& pixels, int w, int h, int bpp = 4,
image::format fmt = image::RGBA);
void unload();
Texture() = default;
Texture(ksr path);
~Texture();
void Load(ksr path);
void Load(kvr<uc> pixels, int w, int h, int bpp = 4,
Image::Format fmt = Image::RGBA);
void Unload();
int w() const { return m_size.x; }
int& w() { return m_size.x; }
int h() const { return m_size.y; }
int& h() { return m_size.y; }
ivec2 size() const { return m_size; }
ivec2& size() { return m_size; }
rect& uv() { return m_uv; }
int W() const { return pSize.x; }
int& W() { return pSize.x; }
int H() const { return pSize.y; }
int& H() { return pSize.y; }
ivec2 Size() const { return pSize; }
ivec2& Size() { return pSize; }
Rect& Uv() { return pUv; }
C3D_Tex* ptr() { return m_loaded ? &m_tex : nullptr; }
C3D_Tex* Ptr() { return pLoaded ? &pTex : nullptr; }
void bind(int reg = 0);
void Bind(int reg = 0);
private:
C3D_Tex m_tex;
ivec2 m_size;
rect m_uv;
bool m_loaded = false;
C3D_Tex pTex;
ivec2 pSize;
Rect pUv;
bool pLoaded = false;
};
} // namespace amy
} // namespace Amy

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <amethyst/maths/vec.hpp>
#include <chrono>
#include <cinttypes>
#include <functional>
#include <map>
@@ -12,18 +13,30 @@
#include <string>
#include <vector>
namespace amy {
namespace Amy {
using uc = unsigned char;
using us = unsigned short;
using ui = unsigned int;
using ull = unsigned long long;
// string
using str = std::string;
using cstr = const std::string;
// const string
using kstr = const std::string;
// const string reference
using ksr = const std::string&;
// vector
template <typename T>
using vec = std::vector<T>;
// const vector reference
template <typename T>
using cvec = const std::vector<T>;
using kvr = const std::vector<T>&;
// const vector
template <typename T>
using kvec = const std::vector<T>;
// unique pointer
template <typename T>
using up = std::unique_ptr<T>;
} // namespace amy
// shared pointer
template <typename T>
using sp = std::shared_ptr<T>;
} // namespace Amy

View File

@@ -2,17 +2,20 @@
#include <amethyst/types.hpp>
namespace amy {
namespace utils {
ui fastHash(cstr& s);
vec<uc> loadFile2Mem(cstr& path);
ui hashMemory(cvec<uc>& data);
ui nextPow2(ui v);
bool isSingleBitNum(ui v);
namespace image {
void reverseBuf(vec<uc>& buf, int w, int h, int c);
void removeAlphaChannel(vec<uc>& buf, int w, int h);
void addAlphaChannel(vec<uc>& buf, int w, int h);
} // namespace image
} // namespace utils
} // namespace amy
namespace Amy {
namespace Utils {
ui FastHash(ksr s);
vec<uc> LoadFile2Mem(ksr path);
ui HashMemory(kvr<uc> data);
ui NextPow2(ui v);
bool IsSingleBitNum(ui v);
ull GetTimeNano();
ull GetTimeMicro();
ull GetTimeMilli();
namespace Image {
void ReverseBuf(vec<uc>& buf, int w, int h, int c);
void RemoveAlphaChannel(vec<uc>& buf, int w, int h);
void AddAlphaChannel(vec<uc>& buf, int w, int h);
} // namespace Image
} // namespace Utils
} // namespace Amy