initial import, >900commits predate this

This commit is contained in:
2020-09-29 13:47:50 +02:00
commit e74154ccee
352 changed files with 108120 additions and 0 deletions

View File

@ -0,0 +1,52 @@
#include "./default_service.hpp"
namespace MM::Services {
// TODO: error handling
bool DefaultService::enable(Engine& engine) {
{
_func_handles[0] = engine.addUpdate([this](Engine& e) { this->preSceneUpdate(e); });
auto tmp_lock = _func_handles[0].lock();
tmp_lock->priority = 1;
tmp_lock->name = "DefaultService::preSceneUpdate";
}
{
_func_handles[1] = engine.addUpdate([this](Engine& e) { this->postSceneUpdate(e); });
auto tmp_lock = _func_handles[1].lock();
tmp_lock->priority = -1;
tmp_lock->name = "DefaultService::postSceneUpdate";
}
{
_func_handles[2] = engine.addFixedUpdate([this](Engine& e) { this->preSceneFixedUpdate(e); });
auto tmp_lock = _func_handles[2].lock();
tmp_lock->priority = 1;
tmp_lock->name = "DefaultService::preSceneFixedUpdate";
}
{
_func_handles[3] = engine.addFixedUpdate([this](Engine& e) { this->postSceneFixedUpdate(e); });
auto tmp_lock = _func_handles[3].lock();
tmp_lock->priority = -1;
tmp_lock->name = "DefaultService::postSceneFixedUpdate";
}
return true;
}
void DefaultService::disable(Engine& engine) {
engine.removeUpdate(_func_handles[0]);
engine.removeUpdate(_func_handles[1]);
engine.removeFixedUpdate(_func_handles[2]);
engine.removeFixedUpdate(_func_handles[3]);
_func_handles[0].reset();
_func_handles[1].reset();
_func_handles[2].reset();
_func_handles[3].reset();
}
} // MM::Services

View File

@ -0,0 +1,26 @@
#pragma once
#include "./service.hpp"
#include <mm/engine.hpp>
namespace MM::Services {
class DefaultService : public Service {
private:
Engine::FunctionDataHandle _func_handles[4];
public:
virtual const char* name(void) override { return "DefaultService"; }
virtual bool enable(Engine& engine) override;
virtual void disable(Engine& engine) override;
virtual void preSceneUpdate(Engine&) {}
virtual void postSceneUpdate(Engine&) {}
virtual void preSceneFixedUpdate(Engine&) {}
virtual void postSceneFixedUpdate(Engine&) {}
};
} //MM::Services

View File

@ -0,0 +1,77 @@
#pragma once
#include <mm/engine.hpp>
#include <vector>
#include <set>
namespace MM::Services {
class NetChanneledInterface : public Service {
public:
using channel_id = uint8_t;
enum class channel_type {
LOSSY,
LOSSLESS
};
using peer_id = uint64_t; // might be truncated by backends
using packet_type = uint16_t; // can be aliased to an enum by the user
protected:
std::set<peer_id> _peer_list;
public: // support querrys
// returns the number (highest number??) maximum channels supported by backend
virtual channel_id getMaxChannels(void) = 0;
// returns wether the channel type is supported
virtual bool getSupportedChannelType(channel_type type) = 0;
virtual size_t getMaxPacketSize(void) = 0;
// TODO: add set channel type utils
public:
// ok , we manage the peer list now
virtual bool addPeer(peer_id peer) { return _peer_list.emplace(peer).second; }
virtual bool removePeer(peer_id peer) { return _peer_list.erase(peer); }
virtual void clearPeerlist(void) { _peer_list.clear(); }
// calls fn for each peer
virtual void forEachPeer(std::function<void(peer_id)> fn) {
for (peer_id peer : _peer_list) {
fn(peer);
}
}
public: // send/recv
// sends a packet of max getMaxPacketSize() bytes
virtual bool sendPacket(peer_id peer, channel_id channel, uint8_t* data, size_t data_size) = 0;
// sends a packet, automatically split if too big
// !! only on lossless channels
virtual bool sendPacketLarge(peer_id peer, channel_id channel, uint8_t* data, size_t data_size) = 0;
// TODO: broadcast?
// has any?
//virtual bool getPacket
// calls fn for each packet and fills in peer, channel, data_ptr, and data_size
// returns number of fn calls
virtual size_t forEachPacket(std::function<void(peer_id, channel_id, uint8_t*, size_t)> fn) = 0;
// calls fn for each packet and fills in channel, data_ptr, and data_size
// returns number of fn calls
virtual size_t forEachPacketPeer(peer_id peer, std::function<void(peer_id, channel_id, uint8_t*, size_t)> fn) = 0;
// calls fn for each packet and fills in data_ptr, and data_size
// returns number of fn calls
virtual size_t forEachPacketPeerChannel(peer_id peer, channel_id channel, std::function<void(peer_id, channel_id, uint8_t*, size_t)> fn) = 0;
};
} // MM::Services

View File

@ -0,0 +1,27 @@
#include "./scene_service_interface.hpp"
#include <entt/entity/registry.hpp>
namespace MM {
struct DefaultSystemsContainer {
// list of callables, expecting a Scene (ecs) and a step size (delta)
std::vector<std::function<void(Scene&, float)>> systems;
};
void AddSystemToScene(::MM::Scene& scene, ::MM::System fn) {
auto& sc = scene.ctx_or_set<DefaultSystemsContainer>();
sc.systems.emplace_back(std::move(fn));
}
void EachSystemInScene(::MM::Scene& scene, std::function<void(::MM::Scene&, ::MM::System&)> fn) {
auto* sc = scene.try_ctx<DefaultSystemsContainer>();
if (sc != nullptr) {
for (auto& system : sc->systems) {
fn(scene, system);
}
}
}
} // MM

View File

@ -0,0 +1,44 @@
#pragma once
#include <mm/engine.hpp>
#include <entt/entity/fwd.hpp>
namespace MM {
using Entity = entt::entity;
using Scene = entt::basic_registry<::MM::Entity>;
using System = std::function<void(::MM::Scene&, float)>;
// opaque way to add a System to a Scene
void AddSystemToScene(::MM::Scene& scene, ::MM::System fn);
// opaque way to iterate over the Systems
void EachSystemInScene(::MM::Scene& scene, std::function<void(::MM::Scene&, ::MM::System&)> fn);
} // MM
namespace MM::Services {
class SceneServiceInterface : public Service {
public: // Scene stuff
// get current Scene
virtual ::MM::Scene& getScene(void) = 0;
// enques a new Scene to be put in place
virtual void changeScene(std::unique_ptr<::MM::Scene> new_scene) = 0;
// sets the new Scene to be provided.
// dont use, except for when you know what you are doing!
// be carefull of that one (lol)
virtual void changeSceneNow(std::unique_ptr<::MM::Scene> new_scene) = 0;
// adds a System to current Scene.
// default impl. will use getScene() !
inline virtual void addSystemToScene(::MM::System fn) {
::MM::AddSystemToScene(getScene(), std::move(fn));
}
};
} // MM::Services

View File

@ -0,0 +1,24 @@
#pragma once
namespace MM {
class Engine;
namespace Services {
class Service {
public:
virtual ~Service(void) {}
virtual const char* name(void) { return "UnNamedService"; }
//virtual const char* name(void) = 0; // use this to find unnamed services
// required
virtual bool enable(Engine& engine) = 0;
virtual void disable(Engine& engine) = 0;
};
} // Services
} //MM