Repository navigation
[Network] Feature Implementation
Building on the packet choices discussed in the previous section, this page explains how to create new features like packets within the Dimension library. By defining custom packets for example, developers can introduce new game features and expand the library’s functionality to suit unique project requirements.
This guide covers the steps to implement and integrate features, maintaining compatibility with Dimension’s modular, game-agnostic structure.
Note: All the steps explanations take place into RType directory. Feel free to move the Dimension library directory in your personal workspace.
In the directory engine/libs/dimension/src/dimension/packet/basics, you have to create your .cpp, .hpp packet file (Example: HelloWorld.cpp & HelloWorld.hpp)
Each .hpp packet file contains at least this structure:
#pragma once
#include "APacket.hpp"
namespace dimension
{
class HelloWorld : public dimension::APacket
{
public:
HelloWorld(uint8_t type);
//Construct new object with serialized data by deserializing them.
HelloWorld(std::vector<char> &buffer);
~HelloWorld();
public:
// Serialize class data to binary to make it sendable.
std::vector<char> serializeData() const
};
} // namespace dimensionEach .cpp packet file contains at least this structure:
#include "HelloWorld.hpp"
namespace dimension
{
HelloWorld::HellowWorld(uint8_t type) : APacket(type) { this->_packetDataSize = 0; }
HelloWorld::HelloWorld(std::vector<char> &buffer) : APacket(buffer) {}
HelloWorld::~HelloWorld(){};
std::vector<char> HelloWorld::serializeData() const
{
std::vector<char> buffer;
return buffer;
}
} // namespace dimensionNote: If you want to add custom data, take a look at more complex packets like CreateEntity to see how they're implemented.
To complete the creation of your packet, you need to register it to the packet factory.
To do it so, you have to include your packet into engine/libs/dimension/src/dimension/packet/PacketFactory.hpp:
#pragma once
...
#include "HelloWorld.hpp"
namespace dimension
{
class PacketFactory
{
...
};
} // namespace dimensionThen register your packet into engine/libs/dimension/src/dimension/packet/PacketFactory.cpp:
#include "PacketFactory.hpp"
namespace dimension
{
PacketFactory::PacketFactory()
{
...
this->_packetManager.registerPacket<HelloWorld>();
}
PacketFactory::~PacketFactory() {}
} // namespace dimensionYou can now use your packet into your project.
Previous page: Specifications
Next page: [Engine] Holtzman Engine Documentation
This project was developed and documented by the MarmotteurInc team.