diff options
Diffstat (limited to 'src/candy_gear')
| -rw-r--r-- | src/candy_gear/candy_gear.cpp | 41 | ||||
| -rw-r--r-- | src/candy_gear/core.cpp | 7 | ||||
| -rw-r--r-- | src/candy_gear/key.cpp | 54 | ||||
| -rw-r--r-- | src/candy_gear/main.cpp | 18 | ||||
| -rw-r--r-- | src/candy_gear/sound.cpp | 3 | ||||
| -rw-r--r-- | src/candy_gear/sound.hpp | 1 | ||||
| -rw-r--r-- | src/candy_gear/sprite.cpp | 11 | ||||
| -rw-r--r-- | src/candy_gear/vector_4d.cpp | 12 | ||||
| -rw-r--r-- | src/candy_gear/view.cpp (renamed from src/candy_gear/view_3d.cpp) | 62 | ||||
| -rw-r--r-- | src/candy_gear/view.hpp (renamed from src/candy_gear/view_3d.hpp) | 12 | ||||
| -rw-r--r-- | src/candy_gear/view_2d.cpp | 90 | ||||
| -rw-r--r-- | src/candy_gear/view_2d.hpp | 33 |
12 files changed, 100 insertions, 244 deletions
diff --git a/src/candy_gear/candy_gear.cpp b/src/candy_gear/candy_gear.cpp index b1758a4..7b5a9d9 100644 --- a/src/candy_gear/candy_gear.cpp +++ b/src/candy_gear/candy_gear.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,7 @@ #include <mruby/string.h> #include "core.hpp" -#include "view_2d.hpp" -#include "view_3d.hpp" +#include "view.hpp" static mrb_value cg_mCandyGear_set_game_name(mrb_state *mrb, mrb_value self) @@ -36,40 +35,28 @@ cg_mCandyGear_set_game_name(mrb_state *mrb, mrb_value self) } static mrb_value -cg_mCandyGear_set_views(mrb_state *mrb, mrb_value self) +cg_mCandyGear_change_views(mrb_state *mrb, mrb_value self) { - struct RClass *cg_m, *cg_cView2D, *cg_cView3D; + struct RClass *cg_m, *cg_cView; mrb_value *array; mrb_int array_len; + mrb_float width, height; - std::vector<std::shared_ptr<BluCat::GRA::View2D>> views_2d; - std::vector<std::shared_ptr<BluCat::GRA::View3D>> views_3d; + std::vector<std::shared_ptr<BluCat::GRA::View>> views; cg_m = mrb_module_get(mrb, "CandyGear"); - cg_cView2D = mrb_class_get_under(mrb, cg_m, "View2D"); - cg_cView3D = mrb_class_get_under(mrb, cg_m, "View3D"); + cg_cView = mrb_class_get_under(mrb, cg_m, "View"); - mrb_get_args(mrb, "a", &array, &array_len); + mrb_get_args(mrb, "aff", &array, &array_len, &width, &height); for(mrb_int i{0}; i < array_len; i++) { - if(mrb_obj_is_kind_of(mrb, array[i], cg_cView2D)) - { - auto v = (std::shared_ptr<BluCat::GRA::View2D>*)DATA_PTR(array[i]); - views_2d.push_back(*v); - } - else if(mrb_obj_is_kind_of(mrb, array[i], cg_cView3D)) - { - auto v = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(array[i]); - views_3d.push_back(*v); - } + auto v = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(array[i]); + views.push_back(*v); } - // A Renderer need at least one view to work. - if(views_2d.size() > 0 || views_3d.size() > 0) - { - delete BluCat::INT::core.vk_renderer; - BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer({views_2d, views_3d}); - } + delete BluCat::INT::core.vk_renderer; + BluCat::INT::core.vk_renderer = new BluCat::GRA::Renderer( + {views, static_cast<F32>(width), static_cast<F32>(height)}); return self; } @@ -138,7 +125,7 @@ cg_candy_gear_init(mrb_state *mrb) cg_m = mrb_module_get(mrb, "CandyGear"); mrb_define_class_method( - mrb, cg_m, "views=", cg_mCandyGear_set_views, MRB_ARGS_REQ(1)); + mrb, cg_m, "change_views", cg_mCandyGear_change_views, MRB_ARGS_REQ(3)); mrb_define_class_method( mrb, cg_m, "log", cg_mCandyGear_log, MRB_ARGS_REQ(2)); mrb_define_class_method( diff --git a/src/candy_gear/core.cpp b/src/candy_gear/core.cpp index 6897921..16782fd 100644 --- a/src/candy_gear/core.cpp +++ b/src/candy_gear/core.cpp @@ -31,8 +31,7 @@ #include "texture.hpp" #include "vector_3d.hpp" #include "vector_4d.hpp" -#include "view_2d.hpp" -#include "view_3d.hpp" +#include "view.hpp" #ifdef DEBUG #include <sstream> @@ -111,14 +110,12 @@ load_mruby_interface(void *obj) cg_skeletal_mesh_init(cg_core.mrb); cg_static_model_init(cg_core.mrb); cg_static_mesh_init(cg_core.mrb); - cg_sound_init(cg_core.mrb); cg_sprite_init(cg_core.mrb); cg_sprite_3d_init(cg_core.mrb); cg_texture_init(cg_core.mrb); cg_vector_3d_init(cg_core.mrb); cg_vector_4d_init(cg_core.mrb); - cg_view_2d_init(cg_core.mrb); - cg_view_3d_init(cg_core.mrb); + cg_view_init(cg_core.mrb); } } diff --git a/src/candy_gear/key.cpp b/src/candy_gear/key.cpp index 615119c..74c2181 100644 --- a/src/candy_gear/key.cpp +++ b/src/candy_gear/key.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,32 +24,32 @@ cg_key_init(mrb_state *mrb) cg_m = mrb_module_get(mrb, "CandyGear"); cg_mKey = mrb_define_module_under(mrb, cg_m, "Key"); - mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_a)); - mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_b)); - mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_c)); - mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_d)); - mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_e)); - mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_f)); - mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_g)); - mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_h)); - mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_i)); - mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_j)); - mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_k)); - mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_l)); - mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_m)); - mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_n)); - mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_o)); - mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_p)); - mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_q)); - mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_r)); - mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_s)); - mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_t)); - mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_u)); - mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_v)); - mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_w)); - mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_x)); - mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_y)); - mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_z)); + mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_A)); + mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_B)); + mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_C)); + mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_D)); + mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_E)); + mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_F)); + mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_G)); + mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_H)); + mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_I)); + mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_J)); + mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_K)); + mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_L)); + mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_M)); + mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_N)); + mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_O)); + mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_P)); + mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_Q)); + mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_R)); + mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_S)); + mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_T)); + mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_U)); + mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_V)); + mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_W)); + mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_X)); + mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_Y)); + mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_Z)); mrb_define_const(mrb, cg_mKey, "UP", mrb_int_value(mrb, SDLK_UP)); mrb_define_const(mrb, cg_mKey, "DOWN", mrb_int_value(mrb, SDLK_DOWN)); diff --git a/src/candy_gear/main.cpp b/src/candy_gear/main.cpp index 353b6bf..bc38e9e 100644 --- a/src/candy_gear/main.cpp +++ b/src/candy_gear/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,23 +63,23 @@ int main(int argc, char *argv[]) { switch(event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: mrb_funcall_id( cg_core.mrb, main_obj, cg_core.sym_key_down, 1, - mrb_int_value(cg_core.mrb, event.key.keysym.sym)); + mrb_int_value(cg_core.mrb, event.key.key)); break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: mrb_funcall_id( cg_core.mrb, main_obj, cg_core.sym_key_up, 1, - mrb_int_value(cg_core.mrb, event.key.keysym.sym)); + mrb_int_value(cg_core.mrb, event.key.key)); break; - case SDL_MOUSEMOTION: + case SDL_EVENT_MOUSE_MOTION: break; - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_DOWN: break; - case SDL_MOUSEBUTTONUP: + case SDL_EVENT_MOUSE_BUTTON_UP: break; - case SDL_QUIT: + case SDL_EVENT_QUIT: mrb_funcall_id(cg_core.mrb, main_obj, cg_core.sym_quit, 0); break; } diff --git a/src/candy_gear/sound.cpp b/src/candy_gear/sound.cpp index 0b3518f..3a3282b 100644 --- a/src/candy_gear/sound.cpp +++ b/src/candy_gear/sound.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +/* #include "sound.hpp" void @@ -71,3 +72,5 @@ cg_sound_init(mrb_state *mrb) mrb, cg_cSound, "initialize", cg_cSound_initialize, MRB_ARGS_REQ(1)); mrb_define_method(mrb, cg_cSound, "play", cg_cSound_play, MRB_ARGS_NONE()); } + +*/ diff --git a/src/candy_gear/sound.hpp b/src/candy_gear/sound.hpp index 2f483e3..ad8c47f 100644 --- a/src/candy_gear/sound.hpp +++ b/src/candy_gear/sound.hpp @@ -14,6 +14,7 @@ * limitations under the License. */ +/* #ifndef CANDY_GEAR_SOUND_H #define CANDY_GEAR_SOUND_H 1 diff --git a/src/candy_gear/sprite.cpp b/src/candy_gear/sprite.cpp index daf96a8..2847d76 100644 --- a/src/candy_gear/sprite.cpp +++ b/src/candy_gear/sprite.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ #include "texture.hpp" #include "vector_4d.hpp" -#include "view_2d.hpp" #include "../blu_cat/gra/sprite.hpp" void @@ -61,17 +60,13 @@ cg_cSprite_initialize(mrb_state *mrb, mrb_value self) static mrb_value cg_cSprite_draw(mrb_state *mrb, mrb_value self) { - mrb_value view_value; - BluCat::GRA::View2D *view_2d; mrb_float x, y, w, h, z_index{0.0}; auto ptr = (std::shared_ptr<BluCat::GRA::Sprite>*)DATA_PTR(self); - mrb_get_args(mrb, "offff|f", &view_value, &x, &y, &w, &h, &z_index); - - view_2d = cg_cView_to_view_2d(mrb, view_value); + mrb_get_args(mrb, "ffff|f", &x, &y, &w, &h, &z_index); glm::vec4 rect(x, y, x + w, y + h); - auto &sprites_to_draw = view_2d->sprites_to_draw[ + auto &sprites_to_draw = BluCat::INT::core.vk_renderer->sprites_to_draw[ BluCat::INT::core.vk_swapchain->current_frame]; sprites_to_draw.emplace_back(*ptr, rect, z_index); diff --git a/src/candy_gear/vector_4d.cpp b/src/candy_gear/vector_4d.cpp index b44b612..5ee674d 100644 --- a/src/candy_gear/vector_4d.cpp +++ b/src/candy_gear/vector_4d.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ #include <mruby/array.h> #include "vector_3d.hpp" -#include "view_2d.hpp" +#include "view.hpp" namespace { @@ -347,19 +347,15 @@ cg_cVector4D_collide(mrb_state *mrb, mrb_value self) static mrb_value cg_cVector4D_draw_rectangle(mrb_state *mrb, mrb_value self) { - mrb_value view_value; - BluCat::GRA::View2D *view_2d; std::shared_ptr<glm::vec3> *color; auto ptr = (std::shared_ptr<glm::vec4>*)DATA_PTR(self); - mrb_get_args(mrb, "od", &view_value, &color, &cg_vector_3d_type); - - view_2d = cg_cView_to_view_2d(mrb, view_value); + mrb_get_args(mrb, "d", &color, &cg_vector_3d_type); glm::vec4 position( (*ptr)->x, (*ptr)->y, (*ptr)->x + (*ptr)->z, (*ptr)->y + (*ptr)->w); BluCat::GRA::Rectangle rect{position, (**color)}; - auto &rectangles = view_2d->rectangles_to_draw[ + auto &rectangles = BluCat::INT::core.vk_renderer->rectangles_to_draw[ BluCat::INT::core.vk_swapchain->current_frame]; rectangles.push_back(rect); diff --git a/src/candy_gear/view_3d.cpp b/src/candy_gear/view.cpp index b829cca..40a03a8 100644 --- a/src/candy_gear/view_3d.cpp +++ b/src/candy_gear/view.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,53 +14,53 @@ * limitations under the License. */ -#include "view_3d.hpp" +#include "view.hpp" #include "sprite.hpp" #include "orientation_3d.hpp" #include "vector_3d.hpp" #include "vector_4d.hpp" #include "../blu_cat/gra/sprite.hpp" -#include "../blu_cat/gra/view_3d.hpp" +#include "../blu_cat/gra/view.hpp" void -cg_free_view_3d(mrb_state *mrb, void* obj) +cg_free_view(mrb_state *mrb, void* obj) { - auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View3D>*>(obj); + auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View>*>(obj); ptr->~shared_ptr(); mrb_free(mrb, ptr); } -const struct mrb_data_type cg_view_3d_type = { "CG_View3D", cg_free_view_3d }; +const struct mrb_data_type cg_view_type = { "CG_View", cg_free_view }; static mrb_value -cg_cView3D_initialize(mrb_state *mrb, mrb_value self) +cg_cView_initialize(mrb_state *mrb, mrb_value self) { std::shared_ptr<glm::vec4> *region; mrb_float projection_width, projection_height; - std::shared_ptr<BluCat::GRA::View3D> *ptr; + std::shared_ptr<BluCat::GRA::View> *ptr; mrb_get_args(mrb, "dff", ®ion, &cg_vector_4d_type, &projection_width, &projection_height); - ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self); + ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self); if(ptr) mrb_free(mrb, ptr); - ptr = (std::shared_ptr<BluCat::GRA::View3D>*)mrb_malloc( - mrb, sizeof(std::shared_ptr<BluCat::GRA::View3D>)); + ptr = (std::shared_ptr<BluCat::GRA::View>*)mrb_malloc( + mrb, sizeof(std::shared_ptr<BluCat::GRA::View>)); - new(ptr)std::shared_ptr<BluCat::GRA::View3D>( - std::make_shared<BluCat::GRA::View3D>( + new(ptr)std::shared_ptr<BluCat::GRA::View>( + std::make_shared<BluCat::GRA::View>( *region->get(), projection_width, projection_height)); - mrb_data_init(self, ptr, &cg_view_3d_type); + mrb_data_init(self, ptr, &cg_view_type); return self; } static mrb_value -cg_cView3D_set_camera_position(mrb_state *mrb, mrb_value self) +cg_cView_set_camera_position(mrb_state *mrb, mrb_value self) { std::shared_ptr<glm::vec3> *camera_position; - auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self); + auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self); mrb_get_args(mrb, "d", &camera_position, &cg_vector_3d_type); (*ptr)->camera_position = (*camera_position); @@ -69,10 +69,10 @@ cg_cView3D_set_camera_position(mrb_state *mrb, mrb_value self) } static mrb_value -cg_cView3D_set_camera_orientation(mrb_state *mrb, mrb_value self) +cg_cView_set_camera_orientation(mrb_state *mrb, mrb_value self) { std::shared_ptr<glm::quat> *camera_orientation; - auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self); + auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self); mrb_get_args(mrb, "d", &camera_orientation, &cg_orientation_3d_type); (*ptr)->camera_orientation = (*camera_orientation); @@ -81,9 +81,9 @@ cg_cView3D_set_camera_orientation(mrb_state *mrb, mrb_value self) } static mrb_value -cg_cView3D_get_field_of_view(mrb_state *mrb, mrb_value self) +cg_cView_get_field_of_view(mrb_state *mrb, mrb_value self) { - auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self); + auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self); return mrb_float_value(mrb, (*ptr)->field_of_view); @@ -91,10 +91,10 @@ cg_cView3D_get_field_of_view(mrb_state *mrb, mrb_value self) } static mrb_value -cg_cView3D_set_field_of_view(mrb_state *mrb, mrb_value self) +cg_cView_set_field_of_view(mrb_state *mrb, mrb_value self) { mrb_float fov; - auto ptr = (std::shared_ptr<BluCat::GRA::View3D>*)DATA_PTR(self); + auto ptr = (std::shared_ptr<BluCat::GRA::View>*)DATA_PTR(self); mrb_get_args(mrb, "f", &fov); (*ptr)->field_of_view = fov; @@ -103,25 +103,25 @@ cg_cView3D_set_field_of_view(mrb_state *mrb, mrb_value self) } void -cg_view_3d_init(mrb_state *mrb) +cg_view_init(mrb_state *mrb) { - struct RClass *cg_m, *cg_cView3D; + struct RClass *cg_m, *cg_cView; cg_m = mrb_module_get(mrb, "CandyGear"); - cg_cView3D = mrb_define_class_under(mrb, cg_m, "View3D", mrb->object_class); - MRB_SET_INSTANCE_TT(cg_cView3D, MRB_TT_DATA); + cg_cView = mrb_define_class_under(mrb, cg_m, "View", mrb->object_class); + MRB_SET_INSTANCE_TT(cg_cView, MRB_TT_DATA); mrb_define_method( - mrb, cg_cView3D, "initialize", cg_cView3D_initialize, MRB_ARGS_REQ(3)); + mrb, cg_cView, "initialize", cg_cView_initialize, MRB_ARGS_REQ(3)); mrb_define_method( - mrb, cg_cView3D, "camera_position=", cg_cView3D_set_camera_position, + mrb, cg_cView, "camera_position=", cg_cView_set_camera_position, MRB_ARGS_REQ(1)); mrb_define_method( - mrb, cg_cView3D, "camera_orientation=", cg_cView3D_set_camera_orientation, + mrb, cg_cView, "camera_orientation=", cg_cView_set_camera_orientation, MRB_ARGS_REQ(1)); mrb_define_method( - mrb, cg_cView3D, "field_of_view", cg_cView3D_get_field_of_view, + mrb, cg_cView, "field_of_view", cg_cView_get_field_of_view, MRB_ARGS_NONE()); mrb_define_method( - mrb, cg_cView3D, "field_of_view=", cg_cView3D_set_field_of_view, + mrb, cg_cView, "field_of_view=", cg_cView_set_field_of_view, MRB_ARGS_REQ(1)); } diff --git a/src/candy_gear/view_3d.hpp b/src/candy_gear/view.hpp index 22aa084..ce1b556 100644 --- a/src/candy_gear/view_3d.hpp +++ b/src/candy_gear/view.hpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2025 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef CANDY_GEAR_VIEW_3D_H -#define CANDY_GEAR_VIEW_3D_H 1 +#ifndef CANDY_GEAR_VIEW_H +#define CANDY_GEAR_VIEW_H 1 #include "core.hpp" -extern const struct mrb_data_type cg_view_3d_type; +extern const struct mrb_data_type cg_view_type; void -cg_view_3d_init(mrb_state *mrb); +cg_view_init(mrb_state *mrb); -#endif /* CANDY_GEAR_VIEW_3D_H */ +#endif /* CANDY_GEAR_VIEW_H */ diff --git a/src/candy_gear/view_2d.cpp b/src/candy_gear/view_2d.cpp deleted file mode 100644 index e0dc8a1..0000000 --- a/src/candy_gear/view_2d.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2022-2024 Frederico de Oliveira Linhares - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "view_2d.hpp" - -#include "sprite.hpp" -#include "vector_4d.hpp" -#include "view_3d.hpp" -#include "../blu_cat/gra/sprite.hpp" -#include "../blu_cat/gra/view_2d.hpp" - -void -cg_free_view_2d(mrb_state *mrb, void* obj) -{ - auto ptr = static_cast<std::shared_ptr<BluCat::GRA::View2D>*>(obj); - - ptr->~shared_ptr(); - mrb_free(mrb, ptr); -} - -const struct mrb_data_type cg_view_2d_type = { "CG_View2D", cg_free_view_2d }; - -static mrb_value -cg_cView2D_initialize(mrb_state *mrb, mrb_value self) -{ - std::shared_ptr<glm::vec4> *region; - mrb_float projection_width, projection_height; - std::shared_ptr<BluCat::GRA::View2D> *ptr; - - mrb_get_args(mrb, "dff", ®ion, &cg_vector_4d_type, - &projection_width, &projection_height); - ptr = (std::shared_ptr<BluCat::GRA::View2D>*)DATA_PTR(self); - if(ptr) mrb_free(mrb, ptr); - ptr = (std::shared_ptr<BluCat::GRA::View2D>*)mrb_malloc( - mrb, sizeof(std::shared_ptr<BluCat::GRA::View2D>)); - - new(ptr)std::shared_ptr<BluCat::GRA::View2D>( - std::make_shared<BluCat::GRA::View2D>( - *region->get(), projection_width, projection_height)); - - mrb_data_init(self, ptr, &cg_view_2d_type); - return self; -} - -BluCat::GRA::View2D* -cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value) -{ - BluCat::GRA::View2D* view_2d; - const mrb_data_type *type = DATA_TYPE(view_value); - - if(type == &cg_view_2d_type) - view_2d = static_cast<std::shared_ptr<BluCat::GRA::View2D>*>( - DATA_PTR(view_value))->get(); - else if (type == &cg_view_3d_type) - view_2d = static_cast<BluCat::GRA::View2D*>( - static_cast<std::shared_ptr<BluCat::GRA::View3D>*>( - DATA_PTR(view_value))->get()); - else - mrb_raisef( - mrb, E_TYPE_ERROR, "wrong argument type %s (expected %s or %s)", - type->struct_name, cg_view_2d_type.struct_name, - cg_view_3d_type.struct_name); - - return view_2d; -} - -void -cg_view_2d_init(mrb_state *mrb) -{ - struct RClass *cg_m, *cg_cView2D; - - cg_m = mrb_module_get(mrb, "CandyGear"); - cg_cView2D = mrb_define_class_under(mrb, cg_m, "View2D", mrb->object_class); - MRB_SET_INSTANCE_TT(cg_cView2D, MRB_TT_DATA); - mrb_define_method( - mrb, cg_cView2D, "initialize", cg_cView2D_initialize, MRB_ARGS_REQ(3)); -} diff --git a/src/candy_gear/view_2d.hpp b/src/candy_gear/view_2d.hpp deleted file mode 100644 index 9b742a0..0000000 --- a/src/candy_gear/view_2d.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2022-2024 Frederico de Oliveira Linhares - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CANDY_GEAR_VIEW_2D_H -#define CANDY_GEAR_VIEW_2D_H 1 - -#include "core.hpp" - -extern const struct mrb_data_type cg_view_2d_type; - -// Receives a mrb_value that points to a View2D or a View3D and returns a -// pointer to View2D. If the mrb_value points to a View3D, the view will be -// cast to a BluCat::GRA::View2D. -BluCat::GRA::View2D* -cg_cView_to_view_2d(mrb_state *mrb, mrb_value view_value); - -void -cg_view_2d_init(mrb_state *mrb); - -#endif /* CANDY_GEAR_VIEW_2D_H */ |
