added entitydef class
This commit is contained in:
parent
95b1821636
commit
1cfb024d04
51
src/common/world/entity_def.cpp
Normal file
51
src/common/world/entity_def.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
PolyGun
|
||||||
|
|
||||||
|
Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/world/entity_def.hpp"
|
||||||
|
|
||||||
|
#include "common/network/network_packet.hpp"
|
||||||
|
|
||||||
|
using namespace polygun::world;
|
||||||
|
|
||||||
|
EntityDef::EntityDef() :
|
||||||
|
m_string_id(),
|
||||||
|
m_model_filename(),
|
||||||
|
m_texture_filename()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void EntityDef::serialize(network::NetworkPacket& packet) const {
|
||||||
|
packet.write(m_string_id);
|
||||||
|
packet.write(m_model_filename);
|
||||||
|
packet.write(m_texture_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EntityDef::deserialize(network::NetworkPacket& packet) {
|
||||||
|
if(!packet.read(m_string_id))
|
||||||
|
return false;
|
||||||
|
if(!packet.read(m_model_filename))
|
||||||
|
return false;
|
||||||
|
if(!packet.read(m_texture_filename))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
@ -25,16 +25,28 @@ SOFTWARE.
|
|||||||
#ifndef POLYGUN_WORLD_ENTITY_DEF_HPP
|
#ifndef POLYGUN_WORLD_ENTITY_DEF_HPP
|
||||||
#define POLYGUN_WORLD_ENTITY_DEF_HPP
|
#define POLYGUN_WORLD_ENTITY_DEF_HPP
|
||||||
|
|
||||||
namespace polygun::world {
|
|
||||||
class EntityDef {
|
|
||||||
public:
|
|
||||||
EntityDef() = default;
|
|
||||||
~EntityDef() = default;
|
|
||||||
|
|
||||||
virtual void start();
|
#include "common/network/network_serializable.hpp"
|
||||||
virtual void render();
|
#include <cstdint>
|
||||||
virtual void update();
|
#include <string>
|
||||||
};
|
|
||||||
|
namespace polygun::world {
|
||||||
|
class EntityDef {
|
||||||
|
public:
|
||||||
|
std::string m_string_id;
|
||||||
|
std::string m_model_filename;
|
||||||
|
std::string m_texture_filename;
|
||||||
|
std::string m_display_icon;
|
||||||
|
|
||||||
|
// Not serialized
|
||||||
|
uint16_t m_id;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EntityDef();
|
||||||
|
|
||||||
|
virtual void serialize(network::NetworkPacket& packet) const;
|
||||||
|
virtual bool deserialize(network::NetworkPacket& packet);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // POLYGUN_WORLD_ENTITY_DEF_HPP
|
#endif // POLYGUN_WORLD_ENTITY_DEF_HPP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user