Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5938d3d
Attempt to quickly clean up another packet (it failed dramatically)
kimden Mar 15, 2025
acf854c
One more commit trying to do stuff
kimden Mar 22, 2025
da14f6d
More small packets
kimden Mar 26, 2025
ebb90b7
A few more unfinished packets for today
kimden Mar 28, 2025
a6f43f2
Process simple packets in the bottom half of ServerLobby
kimden Apr 2, 2025
6b08222
Even more packets in ServerLobby
kimden Apr 3, 2025
e70f076
Seemingle finished SL packets, some other reworks
kimden Apr 5, 2025
695563d
Process packets from worlds, start editing client lobby
kimden Apr 5, 2025
578289d
Packets from various files
kimden Apr 6, 2025
b80b854
More packets, some macro redefinitions
kimden Apr 8, 2025
70a1935
Macro changes, added PROTOCOL_TYPE, more CL packets
kimden Apr 9, 2025
21e6278
Own optional, more refactors, including CL
kimden Apr 10, 2025
2ead0b7
Compilable but not linkable state without some packets
kimden Apr 12, 2025
f7210c6
Linkable version (won't work tho)
kimden Apr 13, 2025
ed7dd0d
Try to fix some compilation errors (2)
kimden Apr 13, 2025
86e0431
Fix more warnings and errors (hopefully)
kimden Apr 13, 2025
f0d625c
Read optionals if possible, remove unnecessary assets packet
kimden Apr 13, 2025
98e8b6e
Fixes allowing joining and playing
kimden Apr 15, 2025
c4432f0
Processed some packets in client lobby
kimden Apr 17, 2025
9e4ec72
Hide NetworkString inside packet while sending to peer
kimden Apr 18, 2025
65719d9
Even fewer NetworkStrings, fix templates
kimden Apr 19, 2025
44fdae9
Fix inability to join, rework aux fields
kimden Apr 19, 2025
72e4396
Some client fixes, then a bit of packets cleanup in ClientLobby
kimden Apr 20, 2025
1531632
More processed packets, started doing something about rewind, compila…
kimden Apr 21, 2025
529537e
Small packet processing attempts
kimden Apr 25, 2025
b430f48
Blind max speed packet processing
kimden Apr 25, 2025
e7620bb
Saving progress (one more packet)...
kimden Apr 26, 2025
f801353
Packet id + some packets
kimden May 5, 2025
6947e42
Add a fake int24
kimden May 16, 2025
cd5c413
Flyable and abstract animation packets, modify int24, remove unneeded…
kimden Jun 14, 2025
f89d8fa
A few more flyable packets, then it becomes harder
kimden Jun 15, 2025
7196df9
Fix a bit of mess in sendXXXToYYY functions
kimden Jul 8, 2025
d5ab3cf
Some packets in GameEventsProtocol and GameProtocol, unfinished
kimden Jul 9, 2025
211fc19
A lot of stuff in GameProtocol, and being helpless
kimden Jul 10, 2025
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
65 changes: 45 additions & 20 deletions src/items/flyable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,58 +664,77 @@ void Flyable::moveToInfinity(bool set_moveable_trans)
} // moveToInfinity

// ----------------------------------------------------------------------------
BareNetworkString* Flyable::saveState(std::vector<std::string>* ru)

FlyablePacket Flyable::saveState(std::vector<std::string>* ru)
{
FlyablePacket packet;

if (m_has_hit_something)
return NULL;
return packet;

ru->push_back(getUniqueIdentity());

BareNetworkString* buffer = new BareNetworkString();
uint16_t ticks_since_thrown_animation = (m_ticks_since_thrown & 32767) |
(hasAnimation() ? 32768 : 0);
buffer->addUInt16(ticks_since_thrown_animation);
packet.ticks_since_thrown_animation =
(m_ticks_since_thrown & 32767) | (hasAnimation() ? 32768 : 0);

if (m_do_terrain_info)
buffer->addUInt32(m_compressed_gravity_vector);
packet.compressed_gravity_vector = m_compressed_gravity_vector;

if (hasAnimation())
m_animation->saveState(buffer);
{
AbstractKartAnimationPacket subpacket = m_animation->saveState();
packet.animation = subpacket;
}
else
{
CompressNetworkBody::compress(
m_body.get(), m_motion_state.get(), buffer);
packet.compressed_network_body = CompressNetworkBody::compress(
m_body.get(), m_motion_state.get());
}
return buffer;
} // saveState

return packet;
} // saveState
// ----------------------------------------------------------------------------
void Flyable::restoreState(BareNetworkString *buffer, int count)

void Flyable::restoreState(const FlyablePacket& packet, int count)
{
uint16_t ticks_since_thrown_animation = buffer->getUInt16();
// kimden: nonvirtual: in which cases there can be nothing?
if (!packet.ticks_since_thrown_animation.has_value())
return;

uint16_t ticks_since_thrown_animation = packet.ticks_since_thrown_animation.get_value();
bool has_animation_in_state =
(ticks_since_thrown_animation >> 15 & 1) == 1;

if (m_do_terrain_info)
m_compressed_gravity_vector = buffer->getUInt32();
{
// kimden: nonvirtual: what if there's no value
if (packet.compressed_gravity_vector.has_value())
m_compressed_gravity_vector = packet.compressed_gravity_vector.get_value();
}

if (has_animation_in_state)
{
// kimden: nonvirtual: what if there's no value
AbstractKartAnimationPacket subpacket;
if (packet.animation.has_value())
subpacket = packet.animation.get_value();

// At the moment we only have cannon animation for rubber ball
if (!m_animation)
{
try
{
CannonAnimation* ca = new CannonAnimation(this, buffer);
CannonAnimation* ca = new CannonAnimation(this, subpacket);
setAnimation(ca);
}
catch (const KartAnimationCreationException& kace)
catch (const std::exception& kace)
{
Log::error("Flyable", "Kart animation creation error: %s",
kace.what());
buffer->skip(kace.getSkippingOffset());
}
}
else
m_animation->restoreState(buffer);
m_animation->restoreState(subpacket);
}
else
{
Expand All @@ -725,8 +744,14 @@ void Flyable::restoreState(BareNetworkString *buffer, int count)
// will set m_animation to null
delete m_animation;
}

// kimden: nonvirtual: what if there's no value
CompressedNetworkBodyPacket subpacket;
if (packet.compressed_network_body.has_value())
subpacket = packet.compressed_network_body.get_value();

CompressNetworkBody::decompress(
buffer, m_body.get(), m_motion_state.get());
subpacket, m_body.get(), m_motion_state.get());
m_transform = m_body->getWorldTransform();
}
m_ticks_since_thrown = ticks_since_thrown_animation & 32767;
Expand Down
8 changes: 5 additions & 3 deletions src/items/flyable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
#ifndef HEADER_FLYABLE_HPP
#define HEADER_FLYABLE_HPP

#define nonvirtual

#include "items/powerup_manager.hpp"
#include "karts/moveable.hpp"
#include "network/rewinder.hpp"
#include "tracks/terrain_info.hpp"
#include "utils/cpp2011.hpp"
#include "network/packet_types.hpp"

#include <irrString.h>
namespace irr
Expand Down Expand Up @@ -259,10 +262,9 @@ class Flyable : public Moveable, public TerrainInfo,
// ------------------------------------------------------------------------
virtual void computeError() OVERRIDE;
// ------------------------------------------------------------------------
virtual BareNetworkString* saveState(std::vector<std::string>* ru)
OVERRIDE;
nonvirtual FlyablePacket saveState(std::vector<std::string>* ru);
// ------------------------------------------------------------------------
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
nonvirtual void restoreState(const FlyablePacket& packet, int count);
// ------------------------------------------------------------------------
/* Return true if still in game state, or otherwise can be deleted. */
bool hasServerState() const { return m_has_server_state; }
Expand Down
58 changes: 33 additions & 25 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "items/item_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "modes/world.hpp"
#include "network/packet_types.hpp"
#include "network/network_string.hpp"
#include "network/rewind_manager.hpp"
#include "tracks/arena_graph.hpp"
Expand Down Expand Up @@ -67,21 +68,21 @@ ItemState::ItemState(ItemType type, const AbstractKart *owner, int id)
//-----------------------------------------------------------------------------
/** Constructor to restore item state at current ticks in client for live join
*/
ItemState::ItemState(const BareNetworkString& buffer)
ItemState::ItemState(const ItemStatePacket& packet)
{
m_type = (ItemType)buffer.getUInt8();
m_original_type = (ItemType)buffer.getUInt8();
m_ticks_till_return = buffer.getUInt32();
m_item_id = buffer.getUInt32();
m_deactive_ticks = buffer.getUInt32();
m_used_up_counter = buffer.getUInt32();
m_xyz = buffer.getVec3();
m_original_rotation = buffer.getQuat();
m_type = (ItemType)packet.type;
m_original_type = (ItemType)packet.original_type;
m_ticks_till_return = packet.ticks_till_return;
m_item_id = packet.item_id;
m_deactive_ticks = packet.deactive_ticks;
m_used_up_counter = packet.used_up_counter;
m_xyz = packet.original_xyz_rotation.xyz;
m_original_rotation = packet.original_xyz_rotation.rotation;
m_previous_owner = NULL;
int8_t kart_id = buffer.getUInt8();
int8_t kart_id = packet.previous_owner;
if (kart_id != -1)
m_previous_owner = World::getWorld()->getKart(kart_id);
} // ItemState(const BareNetworkString& buffer)
} // ItemState(const ItemStatePacket& packet)

// ------------------------------------------------------------------------
/** Sets the disappear counter depending on type. */
Expand Down Expand Up @@ -185,24 +186,31 @@ void ItemState::collected(const AbstractKart *kart)
// ----------------------------------------------------------------------------
/** Returns the graphical type of this item should be using (takes nolok into
* account). */
Item::ItemType ItemState::getGrahpicalType() const
Item::ItemType ItemState::getGraphicalType() const
{
return m_previous_owner && m_previous_owner->getIdent() == "nolok" &&
getType() == ITEM_BUBBLEGUM ?
ITEM_BUBBLEGUM_NOLOK : getType();
} // getGrahpicalType
} // getGraphicalType

//-----------------------------------------------------------------------------
/** Save item state at current ticks in server for live join
*/
void ItemState::saveCompleteState(BareNetworkString* buffer) const
ItemStatePacket ItemState::saveCompleteState() const
{
buffer->addUInt8((uint8_t)m_type).addUInt8((uint8_t)m_original_type)
.addUInt32(m_ticks_till_return).addUInt32(m_item_id)
.addUInt32(m_deactive_ticks).addUInt32(m_used_up_counter)
.add(m_xyz).add(m_original_rotation)
.addUInt8(m_previous_owner ?
(int8_t)m_previous_owner->getWorldKartId() : (int8_t)-1);
ItemStatePacket packet;
packet.type = m_type;
packet.original_type = m_original_type;
packet.ticks_till_return = m_ticks_till_return;
packet.item_id = m_item_id;
packet.deactive_ticks = m_deactive_ticks;
packet.used_up_counter = m_used_up_counter;
packet.original_xyz_rotation.xyz = m_xyz;
packet.original_xyz_rotation.rotation = m_original_rotation;
packet.previous_owner = m_previous_owner ?
m_previous_owner->getWorldKartId() : -1;

return packet;
} // saveCompleteState

// ============================================================================
Expand All @@ -228,7 +236,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
m_animation_start_ticks = -9999;
m_distance_2 = 1.2f;
initItem(type, xyz, normal);
m_graphical_type = getGrahpicalType();
m_graphical_type = getGraphicalType();

m_node = NULL;
if (mesh && !GUIEngine::isNoGraphics())
Expand Down Expand Up @@ -256,7 +264,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
m_appear_anime_node = irr_driver->getSceneManager()->addEmptySceneNode(m_node);
}
setType(type);
handleNewMesh(getGrahpicalType());
handleNewMesh(getGraphicalType());

if (!m_node)
return;
Expand Down Expand Up @@ -442,10 +450,10 @@ void Item::updateGraphics(float dt)
if (m_node == NULL)
return;

if (m_graphical_type != getGrahpicalType())
if (m_graphical_type != getGraphicalType())
{
handleNewMesh(getGrahpicalType());
m_graphical_type = getGrahpicalType();
handleNewMesh(getGraphicalType());
m_graphical_type = getGraphicalType();
}

auto& stk_config = STKConfig::get();
Expand Down
10 changes: 5 additions & 5 deletions src/items/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

#include <line3d.h>

class BareNetworkString;
class AbstractKart;
class LODNode;
class ItemStatePacket;

namespace irr
{
Expand Down Expand Up @@ -145,9 +145,9 @@ class ItemState

public:
// ------------------------------------------------------------------------
ItemState(ItemType type, const AbstractKart *owner=NULL, int id = -1);
ItemState(ItemType type, const AbstractKart *owner=NULL, int id = -1);
// ------------------------------------------------------------------------
ItemState(const BareNetworkString& buffer);
ItemState(const ItemStatePacket& packet);
// ------------------------------------------------------------------------
void initItem(ItemType type, const Vec3& xyz, const Vec3& normal);
void update(int ticks);
Expand Down Expand Up @@ -266,7 +266,7 @@ class ItemState
/** Returns the type of this item. */
ItemType getType() const { return m_type; }
// ------------------------------------------------------------------------
ItemType getGrahpicalType() const;
ItemType getGraphicalType() const;
// ------------------------------------------------------------------------
/** Returns the original type of this item. */
ItemType getOriginalType() const { return m_original_type; }
Expand Down Expand Up @@ -313,7 +313,7 @@ class ItemState
return m_original_rotation;
}
// ------------------------------------------------------------------------
void saveCompleteState(BareNetworkString* buffer) const;
ItemStatePacket saveCompleteState() const;
}; // class ItemState

// ============================================================================
Expand Down
29 changes: 17 additions & 12 deletions src/items/network_item_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "network/network_string.hpp"
#include "network/packet_types.hpp"
#include "network/protocols/game_protocol.hpp"
#include "network/rewind_manager.hpp"
#include "network/stk_host.hpp"
Expand Down Expand Up @@ -519,43 +520,47 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
//-----------------------------------------------------------------------------
/** Save all current items at current ticks in server for live join
*/
void NetworkItemManager::saveCompleteState(BareNetworkString* buffer) const
NimCompleteStatePacket NetworkItemManager::saveCompleteState() const
{
NimCompleteStatePacket packet;
const uint32_t all_items = (uint32_t)m_all_items.size();
buffer->addUInt32(World::getWorld()->getTicksSinceStart())
.addUInt32(m_switch_ticks).addUInt32(all_items);
packet.ticks_since_start = World::getWorld()->getTicksSinceStart();
packet.switch_ticks = m_switch_ticks;
packet.all_items_size = all_items;
for (unsigned i = 0; i < all_items; i++)
{
packet.all_items.emplace_back();
if (m_all_items[i])
{
buffer->addUInt8(1);
m_all_items[i]->saveCompleteState(buffer);
packet.all_items.back().has_item = true;
packet.all_items.back().item_state = m_all_items[i]->saveCompleteState();
}
else
buffer->addUInt8(0);
packet.all_items.back().has_item = false;
}
return packet;
} // saveCompleteState

//-----------------------------------------------------------------------------
/** Restore all current items at current ticks in client for live join
* or at the start of a race.
*/
void NetworkItemManager::restoreCompleteState(const BareNetworkString& buffer)
void NetworkItemManager::restoreCompleteState(const NimCompleteStatePacket& packet)
{
m_confirmed_state_time = buffer.getUInt32();
m_confirmed_switch_ticks = buffer.getUInt32();
uint32_t all_items = buffer.getUInt32();
m_confirmed_state_time = packet.ticks_since_start;
m_confirmed_switch_ticks = packet.switch_ticks;
uint32_t all_items = packet.all_items_size;
for (ItemState* is : m_confirmed_state)
{
delete is;
}
m_confirmed_state.clear();
for (unsigned i = 0; i < all_items; i++)
{
const bool has_item = buffer.getUInt8() == 1;
const bool has_item = packet.all_items[i].has_item;
if (has_item)
{
ItemState* is = new ItemState(buffer);
ItemState* is = new ItemState(packet.all_items[i].item_state.get_value());
m_confirmed_state.push_back(is);
}
else
Expand Down
12 changes: 7 additions & 5 deletions src/items/network_item_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <mutex>

class STKPeer;
class NimCompleteStatePacket;

#define nonvirtual

/** \ingroup items
* The network item manager is responsible for handling all network related
Expand Down Expand Up @@ -81,9 +84,8 @@ class NetworkItemManager : public Rewinder, public ItemManager
const AbstractKart *kart,
const Vec3 *server_xyz = NULL,
const Vec3 *server_normal = NULL) OVERRIDE;
virtual BareNetworkString* saveState(std::vector<std::string>* ru)
OVERRIDE;
virtual void restoreState(BareNetworkString *buffer, int count) OVERRIDE;
nonvirtual BareNetworkString* saveState(std::vector<std::string>* ru);
nonvirtual void restoreState(BareNetworkString *buffer, int count);
// ------------------------------------------------------------------------
virtual void rewindToEvent(BareNetworkString *bns) OVERRIDE {};
// ------------------------------------------------------------------------
Expand All @@ -107,9 +109,9 @@ class NetworkItemManager : public Rewinder, public ItemManager
m_last_confirmed_item_ticks.erase(peer);
}
// ------------------------------------------------------------------------
void saveCompleteState(BareNetworkString* buffer) const;
NimCompleteStatePacket saveCompleteState() const;
// ------------------------------------------------------------------------
void restoreCompleteState(const BareNetworkString& buffer);
void restoreCompleteState(const NimCompleteStatePacket& packet);
// ------------------------------------------------------------------------
void initServer();

Expand Down
Loading