diff options
author | Frederico Linhares <fred@linhares.blue> | 2022-08-02 16:52:33 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2022-08-02 16:52:33 -0300 |
commit | f88712a929ee3543f8e1d45c6071f676df339cdb (patch) | |
tree | ad4c9272ead49eb205b1c655bb1d878654863e26 /src/main.cpp | |
parent | 9c6a166fa2b00a1ab177d9e9216a839b87e36ca7 (diff) |
refa Use Vulkan for graphics
This is a partial refactory. Some functionalities implemented in
SDL were removed and need reimplementation.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/main.cpp b/src/main.cpp index 900bb11..3876db0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,26 +14,26 @@ * limitations under the License. */ -#include "candy_gear.h" -#include "color.h" -#include "core.h" -#include "font.h" -#include "graphic.h" -#include "key.h" -#include "log.h" -#include "palette.h" -#include "point.h" -#include "rect.h" -#include "sound.h" -#include "sprite.h" -#include "texture.h" +#ifdef DEBUG +#include <iostream> +#endif + +#include "camera.hpp" +#include "candy_gear.hpp" +#include "core.hpp" +#include "key.hpp" +#include "log.hpp" +#include "model.hpp" +#include "model/instance.hpp" +#include "sound.hpp" +#include "texture.hpp" cg_sCore cg_core; static void handle_error(mrb_state *mrb) { mrb_print_error(mrb); - cg_core.quit_game = SDL_TRUE; + cg_core.quit_game = true; } int main(int argc, char *argv[]) @@ -41,31 +41,34 @@ int main(int argc, char *argv[]) SDL_Event event; Uint32 frame_start; + // Random numbers + random_number_generator.seed(random_seed()); + mrb_state *mrb = mrb_open(); mrb_value main_obj; mrb_sym sym_init, sym_key_down, sym_key_up, sym_quit, sym_tick; FILE *fp; - LoaderStack core_loader; - cg_core.config_file = argv[1]; - cg_Core_init(&core_loader); - if(!cg_Core_load(&core_loader)) return 1; + try{ cg_sCore::loader.execute(nullptr); } + catch(const CommandError &error) + { +#ifdef DEBUG + std::cout << error.what() << std::endl; +#endif + return 1; + } if (!mrb) { /* handle error */ } mrb_define_module(mrb, "CandyGear"); + cg_camera_init(mrb); cg_candy_gear_init(mrb); - cg_color_init(mrb); - cg_font_init(mrb); - cg_graphic_init(mrb); cg_key_init(mrb); cg_log_init(mrb); - cg_palette_init(mrb); - cg_point_init(mrb); - cg_rect_init(mrb); + cg_model_init(mrb); + cg_model_instance_init(mrb); cg_sound_init(mrb); - cg_sprite_init(mrb); cg_texture_init(mrb); main_obj = mrb_obj_iv_inspect(mrb, mrb->top_self); @@ -118,19 +121,10 @@ int main(int argc, char *argv[]) } } - // Clear buffer. - SDL_SetRenderDrawColor(cg_core.renderer, 0x00, 0x00, 0x00, 0xff); - SDL_RenderClear(cg_core.renderer); - mrb_funcall_id(mrb, main_obj, sym_tick, 0); if (mrb->exc) handle_error(mrb); - // Copy buffer to the screen and display it. - SDL_SetRenderTarget(cg_core.renderer, NULL); - SDL_RenderCopy( - cg_core.renderer, cg_core.pre_screen_buffer, NULL, &cg_core.screen_rect); - SDL_RenderPresent(cg_core.renderer); - SDL_SetRenderTarget(cg_core.renderer, cg_core.pre_screen_buffer); + cg_core.vk_graphics_pipeline->draw(); // Timer { @@ -148,7 +142,7 @@ int main(int argc, char *argv[]) } mrb_close(mrb); - cg_Core_unload(&core_loader); + cg_sCore::loader.revert(nullptr); return 0; } |