diff --git a/client/controller/game.cpp b/client/controller/game.cpp index 8778fbe..b9ce82c 100644 --- a/client/controller/game.cpp +++ b/client/controller/game.cpp @@ -33,32 +33,29 @@ void Game::set_renderer(int frame_ticks) render_storage.get_scene().render(); Snapshot snapshot; - if (!session.get_queue_receiver().try_pop(snapshot)) - { - if (!started) - loading_screen.render(); + // aca quieren poppear mas de un snapshot por loop (y quedarse con el ultimo) + // esto es lo que les genera input lag + while (session.get_queue_receiver().try_pop(snapshot)); + if (!started) { + loading_screen.render(); + started = true; return; } - else - started = true; - if (started) - { - for (MapComponent &component : snapshot.map.components) - render_storage.get_map_drawer().render_component(component, snapshot.map.style); - for (BoxSnapshot &box : snapshot.map.boxes) - render_storage.get_box_item().render(box); - for (Position &position : snapshot.map.gun_spawns) - render_storage.get_map_drawer().render_spawn_in_map(position); - for (DuckSnapshot &duck_snapshot : snapshot.ducks) - render_storage.get_duck().render(duck_snapshot, frame_ticks); - for (GunNoEquippedSnapshot &gun : snapshot.guns) - render_storage.get_item().render(gun); - for (ProjectileSnapshot &projectile : snapshot.projectiles) - render_storage.get_projectile_drawer().render(projectile); - // for (SoundSnapshot &sound_snapshot : snapshot.sounds) - // music_box.play_sound(sound_snapshot); - } + for (MapComponent &component : snapshot.map.components) + render_storage.get_map_drawer().render_component(component, snapshot.map.style); + for (BoxSnapshot &box : snapshot.map.boxes) + render_storage.get_box_item().render(box); + for (Position &position : snapshot.map.gun_spawns) + render_storage.get_map_drawer().render_spawn_in_map(position); + for (DuckSnapshot &duck_snapshot : snapshot.ducks) + render_storage.get_duck().render(duck_snapshot, frame_ticks); + for (GunNoEquippedSnapshot &gun : snapshot.guns) + render_storage.get_item().render(gun); + for (ProjectileSnapshot &projectile : snapshot.projectiles) + render_storage.get_projectile_drawer().render(projectile); + // for (SoundSnapshot &sound_snapshot : snapshot.sounds) + // music_box.play_sound(sound_snapshot); } void Game::step(unsigned int current_step) diff --git a/client/controller/render/boxitem.cpp b/client/controller/render/boxitem.cpp index 0f899bf..6f50c6a 100644 --- a/client/controller/render/boxitem.cpp +++ b/client/controller/render/boxitem.cpp @@ -10,6 +10,9 @@ BoxItem::BoxItem(SDL2pp::Renderer &renderer) : Renderer(renderer) void BoxItem::render(BoxSnapshot &box) { + // esto lo comento acá pero va para todos los renderizables + // si el renderizable no esta en la vista de la camara (esto va a tomar mas relevancia cuando hagan el zoom) + // entonces NO lo rendericen if (box.status == Box::NONE) return; SDL2pp::Texture &texture = get_texture(TextureFigure::Box_T); diff --git a/client/model/protocol.cpp b/client/model/protocol.cpp index 0d88f86..aab4fc7 100755 --- a/client/model/protocol.cpp +++ b/client/model/protocol.cpp @@ -245,6 +245,7 @@ void ClientProtocol::recv(void *data, size_t size) skt.recvall(data, size, &was_closed); if (was_closed) { + // LibError es para excepciones de las libs del sistema operativo, no para el protocol throw LibError(errno, "Error al intentar recibir datos del servidor"); } } diff --git a/server/acceptor.cpp b/server/acceptor.cpp index 6f274a0..eda1d49 100755 --- a/server/acceptor.cpp +++ b/server/acceptor.cpp @@ -36,6 +36,7 @@ void Acceptor::run() } void Acceptor::remove_disconnected_sessions() { + // std::remove_if for (auto it = sessions.begin(); it != sessions.end(); ) { auto session = it->second; if (!session || !session->is_alive()) { diff --git a/server/game/game.cpp b/server/game/game.cpp index a66d477..c963731 100644 --- a/server/game/game.cpp +++ b/server/game/game.cpp @@ -62,9 +62,6 @@ void Game::process(ClientCommand &command) break; case ClientActionType::STOP_MOVING_LEFT: - duck.stop_moving(); - break; - case ClientActionType::STOP_MOVING_RIGHT: duck.stop_moving(); break; @@ -204,6 +201,7 @@ void Game::check_for_winner(const std::vector &ducks_alive) if (n_ducks_alive == 1) { ++victories[ducks_alive[0]]; + // esto podría estar en la configuracion del juego if ((round >= 5) && (round % 5 == 0)) { // Check if somebody won every five rounds std::vector possible_winners; diff --git a/server/game/gun/gun.h b/server/game/gun/gun.h index 2138437..74bf407 100644 --- a/server/game/gun/gun.h +++ b/server/game/gun/gun.h @@ -38,6 +38,8 @@ class Gun : public Hitbox } public: + // esto es leaky respecto al cliente. Por que hay informacion de la textura y del tamaño/altura del arma? + // eso paracece responsabilidad del cliente, no del servidor explicit Gun(const uint16_t &id, const GunType &type, const Position &p, const Size &size, const TextureFigure &texture) : Hitbox(p, size), id(id), type(type), is_equipped(false), is_grounded(false), angle(ANGLE_DEFAULT), diff --git a/server/protocol.cpp b/server/protocol.cpp index ec79135..e328a79 100755 --- a/server/protocol.cpp +++ b/server/protocol.cpp @@ -152,6 +152,8 @@ void ServerProtocol::send_box(const BoxSnapshot &box) void ServerProtocol::send_snapshot(const Snapshot &snapshot) { + // es bastante "chatty" el protocolo (muchos mensajes para mandar una sola cosa) + // una alternativa es armar un buffer entero y mandarlo de una const uint16_t ducks_lenght = static_cast(snapshot.ducks.size()); send_data(ducks_lenght); for (const DuckSnapshot &duck : snapshot.ducks) @@ -167,9 +169,11 @@ void ServerProtocol::send_snapshot(const Snapshot &snapshot) const uint16_t sound_lenght = static_cast(snapshot.sounds.size()); send_data(sound_lenght); + // los sonidos los podría computar el cliente (esa logica esta bien que la tenga el cliente) for (SoundSnapshot sound_snapshot : snapshot.sounds) send_data(static_cast(sound_snapshot.sound)); + // esto deberían mandarlo una sola vez send_data(snapshot.map.style); send_data(snapshot.map.size_x); send_data(snapshot.map.size_y); @@ -183,6 +187,7 @@ void ServerProtocol::send_snapshot(const Snapshot &snapshot) for (const BoxSnapshot &box : snapshot.map.boxes) send_box(box); + // idem el mapa, los spawns no deberían ser enviados multiples veces send_data(snapshot.map.gun_spawns.size()); for (const Position &position : snapshot.map.gun_spawns) {