summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sprite.cpp23
-rw-r--r--src/vk/sprite.cpp11
-rw-r--r--src/vk/sprite.hpp2
3 files changed, 20 insertions, 16 deletions
diff --git a/src/sprite.cpp b/src/sprite.cpp
index c72f7c5..8f25f03 100644
--- a/src/sprite.cpp
+++ b/src/sprite.cpp
@@ -35,19 +35,24 @@ const struct mrb_data_type cg_sprite_type = { "CG_Sprite", cg_free_sprite };
static mrb_value
cg_cSprite_initialize(mrb_state *mrb, mrb_value self)
{
- std::shared_ptr<glm::vec4> *vector_4d;
+ mrb_float x, y, w, h;
+ glm::vec4 vector_4d;
std::shared_ptr<VK::Texture> *texture;
std::shared_ptr<VK::Sprite> *ptr;
mrb_get_args(
- mrb, "dd", &texture, &cg_texture_type, &vector_4d, &cg_vector_4d_type);
+ mrb, "dffff", &texture, &cg_texture_type, &x, &y, &w, &h);
ptr = (std::shared_ptr<VK::Sprite>*)DATA_PTR(self);
if(ptr) mrb_free(mrb, ptr);
ptr = (std::shared_ptr<VK::Sprite>*)mrb_malloc(
mrb, sizeof(std::shared_ptr<VK::Sprite>));
+ vector_4d.x = x;
+ vector_4d.y = y;
+ vector_4d.z = w;
+ vector_4d.w = h;
new(ptr)std::shared_ptr<VK::Sprite>(
- std::make_shared<VK::Sprite>(*texture, *vector_4d->get()));
+ std::make_shared<VK::Sprite>(*texture, vector_4d));
mrb_data_init(self, ptr, &cg_sprite_type);
return self;
@@ -58,16 +63,14 @@ cg_cSprite_draw(mrb_state *mrb, mrb_value self)
{
mrb_value view_value;
VK::View2D *view_2d;
- std::shared_ptr<glm::vec4> *position;
+ mrb_float x, y, w, h;
auto ptr = (std::shared_ptr<VK::Sprite>*)DATA_PTR(self);
- mrb_get_args(mrb, "od", &view_value, &position, &cg_vector_4d_type);
+ mrb_get_args(mrb, "offff", &view_value, &x, &y, &w, &h);
view_2d = cg_cView_to_view_2d(mrb, view_value);
- glm::vec4 rect(
- (*position)->x, (*position)->y,
- (*position)->x + (*position)->z, (*position)->y + (*position)->w);
+ glm::vec4 rect(x, y, x + w, y + h);
auto &positions = view_2d->sprites_to_draw[
cg_core.vk_swapchain->current_frame][*ptr];
positions.push_back(rect);
@@ -84,6 +87,6 @@ cg_sprite_init(mrb_state *mrb)
cg_cSprite = mrb_define_class_under(mrb, cg_m, "Sprite", mrb->object_class);
MRB_SET_INSTANCE_TT(cg_cSprite, MRB_TT_DATA);
mrb_define_method(
- mrb, cg_cSprite, "initialize", cg_cSprite_initialize, MRB_ARGS_REQ(2));
- mrb_define_method(mrb, cg_cSprite, "draw", cg_cSprite_draw, MRB_ARGS_REQ(2));
+ mrb, cg_cSprite, "initialize", cg_cSprite_initialize, MRB_ARGS_REQ(5));
+ mrb_define_method(mrb, cg_cSprite, "draw", cg_cSprite_draw, MRB_ARGS_REQ(5));
}
diff --git a/src/vk/sprite.cpp b/src/vk/sprite.cpp
index bc9cb57..069bf6a 100644
--- a/src/vk/sprite.cpp
+++ b/src/vk/sprite.cpp
@@ -28,12 +28,12 @@ namespace
struct SpriteBuilder
{
VK::Sprite *sprite;
- glm::vec4 rect;
+ glm::vec4 &rect;
- SpriteBuilder(VK::Sprite *sprite, glm::vec4 rect);
+ SpriteBuilder(VK::Sprite *sprite, glm::vec4 &rect);
};
-SpriteBuilder::SpriteBuilder(VK::Sprite *sprite, glm::vec4 rect):
+SpriteBuilder::SpriteBuilder(VK::Sprite *sprite, glm::vec4 &rect):
sprite{sprite},
rect{rect}
{
@@ -172,7 +172,7 @@ static const CommandChain loader{
namespace VK
{
-Sprite::Sprite(std::shared_ptr<Texture> texture, glm::vec4 rect):
+Sprite::Sprite(std::shared_ptr<Texture> texture, glm::vec4 &rect):
texture{texture}
{
SpriteBuilder sprite_builder(this, rect);
@@ -181,7 +181,8 @@ Sprite::Sprite(std::shared_ptr<Texture> texture, glm::vec4 rect):
Sprite::~Sprite()
{
- SpriteBuilder sprite_builder(this, glm::vec4());
+ glm::vec4 vector_4d{};
+ SpriteBuilder sprite_builder(this, vector_4d);
loader.revert(&sprite_builder);
}
diff --git a/src/vk/sprite.hpp b/src/vk/sprite.hpp
index e053bba..5934501 100644
--- a/src/vk/sprite.hpp
+++ b/src/vk/sprite.hpp
@@ -44,7 +44,7 @@ struct Sprite
std::shared_ptr<Texture> texture;
- Sprite(std::shared_ptr<Texture> texture, glm::vec4 rect);
+ Sprite(std::shared_ptr<Texture> texture, glm::vec4 &rect);
~Sprite();
};