From 3b32c34b12e44385d9c096129854a608c7cd34f2 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 16 Jan 2023 17:32:54 +0900 Subject: [PATCH] Impl working game (missing animations) --- src/3d/obj.cc | 4 + src/3d/obj.h | 2 + src/3d_renderer.cc | 211 +++++++++++++++++++++++++++++---------------- src/3d_renderer.h | 12 ++- 4 files changed, 152 insertions(+), 77 deletions(-) diff --git a/src/3d/obj.cc b/src/3d/obj.cc index 7ebaf1e..bdb050d 100644 --- a/src/3d/obj.cc +++ b/src/3d/obj.cc @@ -21,6 +21,8 @@ void Object3D::set_model(Model *model) { const A3F &Object3D::get_pos() const { return pos; } +A3F &Object3D::get_pos() { return pos; } + void Object3D::set_pos(const A3F &pos) { this->pos = pos; } void Object3D::set_pos(A3F &&pos) { this->pos = std::forward(pos); } @@ -33,6 +35,8 @@ void Object3D::set_pos_z(float z) { pos[2] = z; } const A4C &Object3D::get_color() const { return color; } +A4C &Object3D::get_color() { return color; } + void Object3D::set_color(const A4C &color) { this->color = color; } void Object3D::set_color(A4C &&color) { diff --git a/src/3d/obj.h b/src/3d/obj.h index e6f5f97..193ee4c 100644 --- a/src/3d/obj.h +++ b/src/3d/obj.h @@ -22,6 +22,7 @@ class Object3D { void set_model(Model *model); const A3F &get_pos() const; + A3F &get_pos(); void set_pos(const A3F &pos); void set_pos(A3F &&pos); void set_pos_x(float x); @@ -29,6 +30,7 @@ class Object3D { void set_pos_z(float z); const A4C &get_color() const; + A4C &get_color(); void set_color(const A4C &color); void set_color(A4C &&color); void set_color_r(unsigned char r); diff --git a/src/3d_renderer.cc b/src/3d_renderer.cc index 352a7a2..dd45911 100644 --- a/src/3d_renderer.cc +++ b/src/3d_renderer.cc @@ -1,12 +1,13 @@ #include "3d_renderer.h" // standard library includes -#include - #include #include #include +// third party includes +#include + // local includes #include "3d/a3f_conv.h" #include "constants.h" @@ -16,12 +17,14 @@ Renderer3D::Renderer3D() : qms{}, root_pos{0.0F, 0.0F, 0.0F}, - p1_pos{-1.0F, 0.0F, 0.0F}, - p2_pos{1.0F, 0.0F, 0.0F}, overview_timer(OVERVIEW_TIMER_MAX), button_color_timer(BUTTON_COLOR_TIME), + received_pos(0), choices{'?', '?', '?'}, opponent_choices{'?', '?', '?'} { + qms.at(0).set_pos_x(-1.0F); + qms.at(1).set_pos_x(1.0F); + camera.position.x = 0.0F; camera.position.y = 5.0F; camera.position.z = 10.0F; @@ -68,7 +71,6 @@ Renderer3D::Renderer3D() flags.set(1); flags.set(4); flags.set(5); - flags.set(7); qms.at(0).set_model(&qm_model); qms.at(0).set_pos({-1.0F, 0.0F, 0.0F}); @@ -81,6 +83,8 @@ Renderer3D::Renderer3D() } Renderer3D::~Renderer3D() { + UnloadTexture(spriteSheet); + UnloadTexture(skybox_texture); UnloadTexture(platform_texture); UnloadTexture(qm_texture); @@ -113,6 +117,37 @@ void Renderer3D::update_state(const char *playerOne, const char *playerTwo, flags.reset(2); flags.set(3); } + + flags.set(9, first_ready); + flags.set(10, second_ready); + + flags.set(12); + + if (flags.test(2)) { + std::cout << "got pos: " << pos << std::endl; + std::cout << "got matchup_idx: " << matchup_idx << std::endl; + std::cout << "camera.target.x: " << camera.target.x << std::endl; + } + + received_pos = pos; + received_matchup_idx = matchup_idx; + + if (second_first != '?') { + opponent_choices.at(0) = second_first; + opponent_choices.at(1) = second_second; + opponent_choices.at(2) = second_third; + } + + if (flags.test(11) && first_first == '?' && second_first == '?') { + choices.at(0) = '?'; + choices.at(1) = '?'; + choices.at(2) = '?'; + opponent_choices.at(0) = '?'; + opponent_choices.at(1) = '?'; + opponent_choices.at(2) = '?'; + flags.reset(11); + flags.reset(8); + } } void Renderer3D::do_update() { @@ -188,79 +223,86 @@ void Renderer3D::update_impl() { UpdateCamera(&camera); - if (flags.test(7)) { - qms.at(0).set_pos(RV3ToA3F(p1_pos)); - qms.at(1).set_pos(RV3ToA3F(p2_pos)); - flags.reset(7); - } for (auto &obj : qms) { obj.update(dt); } if (IsMouseButtonPressed(0)) { - if (GetTouchX() >= (triple_single_width - actual_width) / 2.0F && - GetTouchX() <= - triple_single_width - (triple_single_width - actual_width) / 2.0F && - GetTouchY() >= GetScreenHeight() - height && - GetTouchY() <= GetScreenHeight()) { - if (choices.at(0) == '?') { - choices.at(0) = 'r'; - } else if (choices.at(1) == '?') { - choices.at(1) = 'r'; - } else { - choices.at(2) = 'r'; - } - } else if (GetTouchX() >= triple_single_width + - (triple_single_width - actual_width) / 2.0F && - GetTouchX() <= triple_single_width * 2.0F - - (triple_single_width - actual_width) / 2.0F && - GetTouchY() >= GetScreenHeight() - height && - GetTouchY() <= GetScreenHeight()) { - if (choices.at(0) == '?') { - choices.at(0) = 'p'; - } else if (choices.at(1) == '?') { - choices.at(1) = 'p'; - } else { - choices.at(2) = 'p'; - } - } else if (GetTouchX() >= GetScreenWidth() - triple_single_width + - (triple_single_width - actual_width) / 2.0F && - GetTouchX() <= GetScreenWidth() - - (triple_single_width - actual_width) / 2.0F && - GetTouchY() >= GetScreenHeight() - height && - GetTouchY() <= GetScreenHeight()) { - if (choices.at(0) == '?') { - choices.at(0) = 's'; - } else if (choices.at(1) == '?') { - choices.at(1) = 's'; - } else { - choices.at(2) = 's'; + if (!flags.test(8)) { + if (GetTouchX() >= (triple_single_width - actual_width) / 2.0F && + GetTouchX() <= triple_single_width - + (triple_single_width - actual_width) / 2.0F && + GetTouchY() >= GetScreenHeight() - height && + GetTouchY() <= GetScreenHeight()) { + if (choices.at(0) == '?') { + choices.at(0) = 'r'; + } else if (choices.at(1) == '?') { + choices.at(1) = 'r'; + } else { + choices.at(2) = 'r'; + } + } else if (GetTouchX() >= + triple_single_width + + (triple_single_width - actual_width) / 2.0F && + GetTouchX() <= + triple_single_width * 2.0F - + (triple_single_width - actual_width) / 2.0F && + GetTouchY() >= GetScreenHeight() - height && + GetTouchY() <= GetScreenHeight()) { + if (choices.at(0) == '?') { + choices.at(0) = 'p'; + } else if (choices.at(1) == '?') { + choices.at(1) = 'p'; + } else { + choices.at(2) = 'p'; + } + } else if (GetTouchX() >= + GetScreenWidth() - triple_single_width + + (triple_single_width - actual_width) / 2.0F && + GetTouchX() <= + GetScreenWidth() - + (triple_single_width - actual_width) / 2.0F && + GetTouchY() >= GetScreenHeight() - height && + GetTouchY() <= GetScreenHeight()) { + if (choices.at(0) == '?') { + choices.at(0) = 's'; + } else if (choices.at(1) == '?') { + choices.at(1) = 's'; + } else { + choices.at(2) = 's'; + } + } else if (GetTouchX() >= (triple_single_width - actual_width2) / 2.0F && + GetTouchX() <= + triple_single_width - + (triple_single_width - actual_width2) / 2.0F && + GetTouchY() >= GetScreenHeight() - height - height2 && + GetTouchY() <= GetScreenHeight() - height) { + choices.at(0) = '?'; + } else if (GetTouchX() >= + triple_single_width + + (triple_single_width - actual_width2) / 2.0F && + GetTouchX() <= + triple_single_width * 2.0F - + (triple_single_width - actual_width2) / 2.0F && + GetTouchY() >= GetScreenHeight() - height - height2 && + GetTouchY() <= GetScreenHeight() - height) { + choices.at(1) = '?'; + } else if (GetTouchX() >= + GetScreenWidth() - triple_single_width + + (triple_single_width - actual_width2) / 2.0F && + GetTouchX() <= + GetScreenWidth() - + (triple_single_width - actual_width2) / 2.0F && + GetTouchY() >= GetScreenHeight() - height - height2 && + GetTouchY() <= GetScreenHeight() - height) { + choices.at(2) = '?'; + } else if (choices.at(0) != '?' && choices.at(1) != '?' && + choices.at(2) != '?' && GetTouchX() >= 0 && + GetTouchX() <= GetScreenWidth() && GetTouchY() >= 0 && + GetTouchY() <= triple_single_width) { + flags.set(8); + call_js_set_ready(); } - } else if (GetTouchX() >= (triple_single_width - actual_width2) / 2.0F && - GetTouchX() <= - triple_single_width - - (triple_single_width - actual_width2) / 2.0F && - GetTouchY() >= GetScreenHeight() - height - height2 && - GetTouchY() <= GetScreenHeight() - height) { - choices.at(0) = '?'; - } else if (GetTouchX() >= - triple_single_width + - (triple_single_width - actual_width2) / 2.0F && - GetTouchX() <= - triple_single_width * 2.0F - - (triple_single_width - actual_width2) / 2.0F && - GetTouchY() >= GetScreenHeight() - height - height2 && - GetTouchY() <= GetScreenHeight() - height) { - choices.at(1) = '?'; - } else if (GetTouchX() >= - GetScreenWidth() - triple_single_width + - (triple_single_width - actual_width2) / 2.0F && - GetTouchX() <= - GetScreenWidth() - - (triple_single_width - actual_width2) / 2.0F && - GetTouchY() >= GetScreenHeight() - height - height2 && - GetTouchY() <= GetScreenHeight() - height) { - choices.at(2) = '?'; } } @@ -268,6 +310,27 @@ void Renderer3D::update_impl() { if (button_color_timer <= 0.0F) { button_color_timer += BUTTON_COLOR_TIME; } + + if (flags.test(12)) { + if (flags.test(8) && flags.test(11)) { + call_js_set_ready(); + call_js_request_update(); + } else if (flags.test(8) && flags.test(9) && flags.test(10) && + !flags.test(11)) { + char buf[6] = {(char)choices.at(0), 0, (char)choices.at(1), 0, + (char)choices.at(2), 0}; + call_js_set_choices(&buf[0], &buf[2], &buf[4]); + flags.set(11); + } + } + + flags.reset(12); + + qms.at(0).get_pos().at(0) += + ((received_pos * 2.0F - 1.0F) - qms.at(0).get_pos().at(0)) / 50.0F; + qms.at(1).get_pos().at(0) += + ((received_pos * 2.0F + 1.0F) - qms.at(1).get_pos().at(0)) / 50.0F; + camera.target.x += (received_pos * 2.0F - camera.target.x) / 50.0F; } void Renderer3D::draw_impl() { @@ -281,7 +344,7 @@ void Renderer3D::draw_impl() { } EndMode3D(); - if (!flags.test(3)) { + if (!flags.test(3) && !flags.test(8)) { const float triple_single_width = GetScreenWidth() / 3.0F; float actual_width = triple_single_width; if (actual_width > (float)ICON_MAX_WIDTH) { @@ -414,7 +477,7 @@ void Renderer3D::draw_impl() { } } } else { - DrawText("Spectating...", 0, 0, 20, RAYWHITE); + DrawText("Waiting...", 0, 0, 20, RAYWHITE); } EndDrawing(); diff --git a/src/3d_renderer.h b/src/3d_renderer.h index d010ad7..b2a3e47 100644 --- a/src/3d_renderer.h +++ b/src/3d_renderer.h @@ -54,8 +54,6 @@ class Renderer3D : public GameRenderer { Model scissors_model; Vector3 root_pos; - Vector3 p1_pos; - Vector3 p2_pos; /* * 0 - focus view if true, overview view if false @@ -73,13 +71,21 @@ class Renderer3D : public GameRenderer { * 101 - UNUSED * 110 - UNUSED * 111 - UNUSED - * 7 - p1_pos/p2_pos dirty + * 7 - UNUSED + * 8 - choices locked + * 9 - p1 ready + * 10 - p2 ready + * 11 - choices submitted + * 12 - update received */ std::bitset<64> flags; float overview_timer; float button_color_timer; + int received_pos; + int received_matchup_idx; + std::array choices; std::array opponent_choices; }; -- 2.49.0