work on app class and start work on iron

This commit is contained in:
2025-11-24 10:02:22 +01:00
parent c3a0e936c8
commit f0117e07d4
12 changed files with 123 additions and 30 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
build/
*.shbin
.vscode
compile_commands.json

View File

@@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 3.22)
project(amethyst)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)
option(AMY_BUILD_3DS "Build for 3ds" ON)
option(AMY_GOD_DEV "Turn this on if you think you are god" OFF)
add_subdirectory(vendor/libpicasso)
add_library(${PROJECT_NAME} STATIC
source/app.cpp
source/amethyst.cpp
source/image.cpp
source/renderer.cpp

View File

@@ -1,6 +1,7 @@
#include "amethyst/iron.hpp"
#include <amethyst.hpp>
#include "amethyst/iron.hpp"
const char* shader_ = R"(; Example PICA200 vertex shader
; Uniforms
@@ -41,20 +42,35 @@ const char* shader_ = R"(; Example PICA200 vertex shader
.end
)";
static C3D_Mtx projection;
class example : public amy::app {
public:
example() {
amy::ctru::init();
amy::c3d::init();
m_top = amy::c3d::createScreen(GFX_TOP, GFX_LEFT);
amy::iron::init();
};
~example() {
amy::c3d::deleteScreen(m_top);
amy::c3d::deinit();
};
void main() {
amy::c3d::startFrame();
m_top->startDraw();
m_top->clear();
amy::iron::newFrame();
amy::iron::drawOn(m_top);
amy::c3d::endFrame();
}
private:
amy::c3d::screen* m_top = nullptr;
};
int main() {
amy::registerCxxExceptionHandler();
amy::ctru::init();
amy::c3d::init();
auto top = amy::c3d::createScreen(GFX_TOP, GFX_LEFT);
amy::iron::init();
while (aptMainLoop()) {
amy::c3d::startFrame();
top->startDraw();
top->clear();
amy::c3d::endFrame();
}
amy::c3d::deleteScreen(top);
example app;
app.run();
return 0;
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <amethyst/app.hpp>
#include <amethyst/assets.hpp>
#include <amethyst/c3d.hpp>
#include <amethyst/ctru.hpp>

View File

@@ -1,6 +1,7 @@
#pragma once
#include <amethyst/asset.hpp>
#include <amethyst/types.hpp>
namespace amy {
class app {
@@ -8,8 +9,12 @@ class app {
app() {}
~app() {}
virtual void main() {}
void run();
private:
double delta() const { return m_delta; }
private:
ull m_last;
double m_delta;
};
} // namespace amy

View File

@@ -1,5 +1,7 @@
#pragma once
#include <amethyst/types.hpp>
namespace amy {
namespace ctru {
enum services {
@@ -10,5 +12,6 @@ enum services {
def = romfs | gfx_def
};
void init(unsigned int srv = def);
ull getTime();
} // namespace ctru
} // namespace amy

View File

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

View File

@@ -5,6 +5,8 @@
#include <amethyst/linearAlloc.hpp>
#include <amethyst/maths/mat.hpp>
#include <amethyst/maths/vec.hpp>
#include <amethyst/texture.hpp>
#include <amethyst/types.hpp>
namespace amy {
class iron {
@@ -23,12 +25,56 @@ class iron {
amy::fvec2 uv;
u32 color = 0;
};
class command {
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));
return *this;
}
std::vector<vertex> vertexBuf;
std::vector<u16> indexBuf;
ivec4 scissorRect;
bool scissorOn = false;
int layer;
int index;
texture* tex;
};
class drawlist {
public:
drawlist() { drawSolid(); }
~drawlist() { m_data.clear(); }
// required due to memory management
drawlist(const drawlist&) = delete;
drawlist& operator=(const drawlist&) = delete;
drawlist(drawlist&&) noexcept = default;
drawlist& operator=(drawlist&&) noexcept = default;
void merge(drawlist* list);
command::ref newCommand();
void push(commad* cmd);
void clear();
void drawSolid();
void drawTex(texture* tex) { m_tex = tex; }
private:
std::vector<command::ref> m_data;
texture* m_tex;
};
iron() = default;
~iron() = default;
static void init();
static void newFrame();
static void drawOn(c3d::screen* screen);
static void draw(const std::vector<command>& data);
private:
static void setupShader();

View File

@@ -13,7 +13,11 @@ using ui = unsigned int;
using ull = unsigned long long;
using str = std::string;
using cstr = const std::string;
template <typename T> using vec = std::vector<T>;
using ksr = const std::string&;
template <typename T>
using vec = std::vector<T>;
template <typename T>
using cvec = const std::vector<T>;
template <typename T>
using up = std::unique_ptr<T>;
} // namespace amy

15
source/app.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include <3ds.h>
#include <amethyst/app.hpp>
#include <amethyst/ctru.hpp>
namespace amy {
void app::run() {
while (aptMainLoop()) {
ull c = ctru::getTime();
m_delta = static_cast<double>(c) - static_cast<float>(m_last);
m_last = c;
main();
}
}
} // namespace amy

View File

@@ -12,5 +12,6 @@ void init(unsigned int srvs) {
gfxInitDefault();
}
}
ull getTime() { return osGetTime(); }
} // namespace ctru
} // namespace amy

View File

@@ -28,8 +28,7 @@ void image::load(cstr& path) {
void image::load(const std::vector<uc>& data) {
int c = 0;
uc* buf =
stbi_load_from_memory(data.data(), data.size(), &m_w, &m_h, &c, 4);
uc* buf = stbi_load_from_memory(data.data(), data.size(), &m_w, &m_h, &c, 4);
if (c == 3) {
// Releoading the Image with tree channels requestet
// Still need to find a better way for this :(
@@ -107,8 +106,7 @@ void image::convert(image& img, const format& dst) {
convert(img, RGB565);
} else if (img.m_fmt == RGB && dst == RGB565) {
// Inlined make pixel 565 func
auto f = [](uc r, uc g,
uc b) -> unsigned short {
auto f = [](uc r, uc g, uc b) -> unsigned short {
unsigned short _r = (r >> 3);
unsigned short _g = (g >> 2);
unsigned short _b = (b >> 3);
@@ -129,8 +127,7 @@ void image::convert(image& img, const format& dst) {
}
}
void image::retile(image& img,
std::function<ui(int x, int y, int w)> src,
void image::retile(image& img, std::function<ui(int x, int y, int w)> src,
std::function<ui(int x, int y, int w)> dst) {
std::vector<uc> cpy = img.m_buffer;
/** could use fmt here but for 565 that woulnt work as it is not supported by