Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions client/controller/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions client/controller/render/boxitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions client/model/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
1 change: 1 addition & 0 deletions server/acceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 1 addition & 3 deletions server/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -204,6 +201,7 @@ void Game::check_for_winner(const std::vector<uint8_t> &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<uint8_t> possible_winners;
Expand Down
2 changes: 2 additions & 0 deletions server/game/gun/gun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions server/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(snapshot.ducks.size());
send_data(ducks_lenght);
for (const DuckSnapshot &duck : snapshot.ducks)
Expand All @@ -167,9 +169,11 @@ void ServerProtocol::send_snapshot(const Snapshot &snapshot)

const uint16_t sound_lenght = static_cast<uint16_t>(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<uint16_t>(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);
Expand All @@ -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)
{
Expand Down