RTYPE TECHNICAL DOCUMENTATION
  • Introduction
  • Classes
    • utils::InputMap
    • utils::Window
    • utils::constant::ButtonValue
    • network::Client
    • network::LockedQueue
    • network::Server
    • ecs::EnemyFactory
    • ecs::Engine
    • ecs::Entity
    • ecs::Event
    • ecs::Registry
    • ecs::SparseArray
    • ecs::World
    • ecs::WorldManager
    • ecs::component::Activable
    • ecs::component::Animated
    • ecs::component::Animated::AnimFrame
    • ecs::component::AttackAI
    • ecs::component::AttackAI::Action
    • ecs::component::AttackAI::AI
    • ecs::component::AttackAI::AI::Pattern
    • ecs::component::Controllable
    • ecs::component::Direction
    • ecs::component::Drawable
    • ecs::component::EntityType
    • ecs::component::Faction
    • ecs::component::FollowEntity
    • ecs::component::Health
    • ecs::component::Hitbox
    • ecs::component::MovementAI
    • ecs::component::MovementAI::AI
    • ecs::component::NetworkId
    • ecs::component::Parallax
    • ecs::component::Position
    • ecs::component::Projectile
    • ecs::component::Score
    • ecs::component::Shootable
    • ecs::component::Size
    • ecs::component::Text
    • ecs::component::textColor
    • ecs::component::Velocity
    • ecs::component::Weapon
    • audio::AudioManager
    • asset::AssetLoader
    • anim::Animation
  • Namespaces
    • utils
    • utils::constant
    • network
    • ecs
    • ecs::component
    • ecs::systems
    • audio
    • asset
    • anim
  • Modules
    • Input
  • Files
    • src
    • src/client
    • Animation.cpp
    • Animation.hpp
    • AssetLoader.cpp
    • AssetLoader.hpp
    • AudioManager.cpp
    • AudioManager.hpp
    • entrypoint.cpp
    • GetWorld.cpp
    • GetWorld.hpp
    • NetworkClient.cpp
    • NetworkClient.hpp
    • src/ecs
    • src/ecs/components
    • src/ecs/components/client
    • Activable.hpp
    • Animated.hpp
    • Controllable.hpp
    • Drawable.hpp
    • Hitbox.hpp
    • Parallax.hpp
    • Shootable.hpp
    • Text.hpp
    • src/ecs/components/server
    • AttackAI.cpp
    • AttackAI.hpp
    • FollowEntity.hpp
    • Projectile.hpp
    • Direction.hpp
    • EntityType.hpp
    • Faction.hpp
    • Health.hpp
    • MovementAI.cpp
    • MovementAI.hpp
    • NetworkId.hpp
    • Position.hpp
    • Score.hpp
    • Size.hpp
    • Velocity.hpp
    • Weapon.hpp
    • src/ecs/systems
    • src/ecs/systems/client
    • Animate.hpp
    • Draw.hpp
    • ExecuteOnce.hpp
    • HandleIncomingMessages.hpp
    • HandleParallaxBounds.hpp
    • HandleSFMLEvents.hpp
    • HandleSFMLKeys.hpp
    • HealthBar.hpp
    • MenuSelect.hpp
    • ScoreUpdate.hpp
    • SendDirection.hpp
    • src/ecs/systems/server
    • DeathUpdate.hpp
    • FollowEntitySystem.hpp
    • HandleIncomingMessage.hpp
    • PlayerHealthUpdate.hpp
    • PositionUpdate.hpp
    • ProjectileCollision.hpp
    • RunAttackAI.hpp
    • Waves.hpp
    • ManageClientEvents.hpp
    • Movement.hpp
    • PositionLogger.hpp
    • RunMovementAI.hpp
    • EnemyFactory.cpp
    • EnemyFactory.hpp
    • Engine.hpp
    • Entity.hpp
    • Event.hpp
    • LockedQueue.hpp
    • Registry.hpp
    • SparseArray.hpp
    • World.hpp
    • WorldManager.cpp
    • WorldManager.hpp
    • src/server
    • entrypoint.cpp
    • Server.cpp
    • Server.hpp
    • src/utils
    • Constant.hpp
    • InputMap.cpp
    • InputMap.hpp
    • Window.cpp
    • README.md
  • Pages
    • deprecated
  • GitHub
Powered by GitBook
On this page
  • Functions
  • Attributes
  • Functions Documentation
  • function movePacketHandle
  • function firstMessageHandle
  • function deathMessageHandle
  • function playerHealthHandle
  • function createPlayer
  • function movePlayer
  • function playerShoot
  • Attributes Documentation
  • variable animate
  • variable draw
  • variable executeOnce
  • variable selfId
  • variable packetTypeFunction
  • variable HandleIncomingMessages
  • variable HandleParallaxBounds
  • variable handleSFMLEvents
  • variable handleSFMLKeys
  • variable healthBar
  • variable menuSelect
  • variable scoreUpdate
  • variable SendDirection
  • variable manageClientEvents
  • variable movement
  • variable positionLogger
  • variable runMovementAI
  • variable deathUpdate
  • variable followEntitySystem
  • variable clientNumToId
  • variable packetTypeFunction
  • variable playerHealthUpdate
  • variable PositionUpdate
  • variable projectileCollision
  • variable runAttackAI
  • variable waves
  1. Namespaces

ecs::systems

Functions

Name

void

void

void

void

void

void

void

Attributes

Name

size_t

std::map< unsigned int, size_t >

Functions Documentation

function movePacketHandle

static void movePacketHandle(
    World & world,
    network::Message & msg
)

function firstMessageHandle

static void firstMessageHandle(
    World & world,
    network::Message & msg
)

function deathMessageHandle

static void deathMessageHandle(
    World & world,
    network::Message & msg
)

function playerHealthHandle

static void playerHealthHandle(
    World & world,
    network::Message & msg
)

function createPlayer

static void createPlayer(
    World & world,
    network::ClientMessage & msg
)

Parameters:

  • world The world in which we want to operate

  • msg The message of a new player coming on the server

In goal of create a player, first, we need to add every components of the player. Specify to the server that there is a new connection and check if the request has been accepted

function movePlayer

static void movePlayer(
    World & world,
    network::ClientMessage & msg
)

Parameters:

  • world The world we want to operate

  • msg The message containing the new position of the player

Updating the player position according to the given msg

function playerShoot

static void playerShoot(
    World & world,
    network::ClientMessage & msg
)

Parameters:

  • world The world we want to operate

  • msg Only used to compare ID and select the correct player

Used to make the player shoot from the given message

Attributes Documentation

variable animate

std::function< void(World &)> animate = [](World &world) {
        auto &animateds = world.registry.getComponents<component::Animated>();

        using chrono = std::chrono::high_resolution_clock;
        using chronoDuration = std::chrono::duration<double, std::milli>;
        for (size_t i = 0; i < animateds.size(); ++i) {
            auto &anim = animateds[i];

            if (anim) {
                if (chrono::now().time_since_epoch().count() - anim.value().lastSwitch
                    > static_cast<size_t>(anim.value().getFrame().delay) * 1000000) {
                    anim.value().nextFrame();
                    anim.value().lastSwitch = chrono::now().time_since_epoch().count();
                }
            }
        }
    };

variable draw

std::function< void(World &)> draw;

Used to set the scale, the position and the texture of the entity before display it

variable executeOnce

std::function< void(World &)> executeOnce = [](World &world) {
        static bool executed = false;

        if (!executed) {
            network::Message msg;
            msg.fill(0);
            network::Client::connect();
            network::Client::getOutgoingMessages().push(msg);
            executed = true;
        }
    };

Login to the server only once

variable selfId

static size_t selfId = 0;

variable packetTypeFunction

static std::unordered_map< char, std::function< void(World &, network::Message &msg)> > packetTypeFunction = {
        {utils::constant::getPacketTypeKey(utils::constant::PacketType::ENTITY_MOVE), movePacketHandle},
        {0, firstMessageHandle},
        {utils::constant::getPacketTypeKey(utils::constant::PacketType::ENTITY_DEATH), deathMessageHandle},
        {utils::constant::getPacketTypeKey(utils::constant::PacketType::HEALTH_UPDATE), playerHealthHandle}};

variable HandleIncomingMessages

std::function< void(World &)> HandleIncomingMessages = [](World &world) {
        while (!network::Client::getReceivedMessages().empty()) {
            network::Message msg = network::Client::getReceivedMessages().pop();
            if (packetTypeFunction.find(msg[0]) != packetTypeFunction.end())
                packetTypeFunction[msg[0]](world, msg);
        }
    };

variable HandleParallaxBounds

std::function< void(World &)> HandleParallaxBounds = [](World &world) {
        auto &parallaxes = world.registry.getComponents<component::Parallax>();
        auto &positions = world.registry.getComponents<component::Position>();

        for (size_t i = 0; i < parallaxes.size() && i < positions.size(); i++) {
            if (!parallaxes[i] || !positions[i])
                continue;
            if (positions[i].value().x < parallaxes[i].value().threshold) {
                positions[i].value().x += parallaxes[i].value().position;
            }
        }
    };

variable handleSFMLEvents

std::function< void(World &)> handleSFMLEvents;

Used to manage Sfml events Currently able to manage the following actions: Close the window KeyPressed, in this case, we check if the bind is known from sfml: if yes, we had it on world's events' stack, nothing otherwise

variable handleSFMLKeys

std::function< void(World &)> handleSFMLKeys;

variable healthBar

std::function< void(World &)> healthBar = [](World &world) {

        auto const &positions = world.registry.getComponents<component::Position>();
        auto &sizes = world.registry.getComponents<component::Size>();
        auto const &healths = world.registry.getComponents<component::Health>();

        for (size_t i = 0; i < positions.size() && i < sizes.size() && i < healths.size(); i++) {
            auto const &pos = positions[i];
            auto &size = sizes[i];
            auto const &health = healths[i];

            if (pos && size && health) {
                if (health->health >= 0 && health->health < utils::constant::maxPlayerHealth) {
                    size.value().width = utils::constant::sizeHealthBar * health->health / 100;
                } else if (health->health < 0)
                    size.value().width = 0;
                else
                    size.value().width = utils::constant::sizeHealthBar;
            }

        }
    };

variable menuSelect

std::function< void(World &)> menuSelect;

variable scoreUpdate

std::function< void(World &)> scoreUpdate = [](World &world) {
      auto &texts = world.registry.getComponents<component::Text>();
      auto &scores = world.registry.getComponents<component::Score>();

      for (size_t i = 0; i < texts.size() || i < scores.size(); i++) {
          auto &text = texts[i];
          auto &score = scores[i];

          if (text && score) {
              std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
              auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() / 10;
              auto elapsed = std::to_string(time);
              const std::string string = "Score: ";

              text->setContent(0, string);
              text->setContent(1, elapsed);
              score->setScore(time);
          }
      }
    };

Used to set the score of the player

variable SendDirection

std::function< void(World &)> SendDirection = [](World &world) {
        auto const &controllables = world.registry.getComponents<component::Controllable>();
        auto &directions = world.registry.getComponents<component::Direction>();

        static auto clock = utils::constant::chrono::now();
        if (utils::constant::chronoDuration(utils::constant::chrono::now() - clock).count() > 10) {
            clock = utils::constant::chrono::now();
            for (size_t i = 0; i < controllables.size() && i < directions.size(); i++) {
                if (!controllables[i] || !directions[i])
                    continue;

                if (directions[i].value().hasMoved) {
                    network::Message msg;
                    msg.fill(0);
                    msg[0] = utils::constant::PLAYER_MOVE;
                    msg[1] = directions[i].value().x;
                    msg[2] = directions[i].value().y;
                    network::Client::getOutgoingMessages().push(msg);
                    directions[i].value().hasMoved = false;
                }
            }
        }
    };

Send direction system used to fill the array of messages to the server regarding the direction of the player

variable manageClientEvents

std::function< void(World &)> manageClientEvents;

Used to manage every client' events Refer to SFMLEvents.hpp documentation to learn more about managed events

variable movement

std::function< void(World &)> movement;

Used to apply the values of the velocity component to the position component according to the internal clock of the system

variable positionLogger

std::function< void(World &)> positionLogger = [](World &world) {
        auto const &positions = world.registry.getComponents<component::Position>();
        auto const &velocities = world.registry.getComponents<component::Velocity>();

        for (size_t i = 0; i < positions.size() && i < velocities.size(); ++i) {
            auto const &pos = positions[i];
            auto const &vel = velocities[i];
            if (pos && vel) {
                std ::cerr << i << ": Position = { " << pos.value().x << ", " << pos.value().y << " }, Velocity = { "
                           << vel.value().x << ", " << vel.value().y << " } " << std ::endl;
            }
        };
    };

Used to display, as a logger, all the value of the Position & Velocity component

variable runMovementAI

std::function< void(World &)> runMovementAI = [](World &world) {
        auto &directions = world.registry.getComponents<component::Direction>();
        auto &movementAIs = world.registry.getComponents<component::MovementAI>();

        using chrono = std::chrono::high_resolution_clock;
        using chronoDuration = std::chrono::duration<double, std::milli>;

        for (size_t i = 0; i < directions.size() && i < movementAIs.size(); ++i) {
            auto &dir = directions[i];
            auto &movAI = movementAIs[i];

            if (dir && movAI) {
                if ((chrono::now().time_since_epoch().count() - movAI.value().getLastMovement()) / 10000000
                    > static_cast<size_t>(movAI.value().getDelay())) {
                    auto &tmpDir = movAI.value().getNextDirection();
                    dir.value().x = tmpDir.first;
                    dir.value().y = tmpDir.second;
                    dir.value().hasMoved = true;
                    movAI.value().setLastMovement(chrono::now().time_since_epoch().count());
                }
            }
        };
    };

Runs the AIs stored in the enities

variable deathUpdate

std::function< void(World &)> deathUpdate;

System used to push death of entity message to the server outgoing queue when is life as gone under 0.

variable followEntitySystem

std::function< void(World &)> followEntitySystem = [](World &world) {
        auto &positions = world.registry.getComponents<component::Position>();
        auto const &follows = world.registry.getComponents<component::FollowEntity>();

        for (std::size_t i = 0; i < positions.size() && i < follows.size(); i++) {
            auto &pos = positions[i];
            auto const &fol = follows[i];

            if (pos && fol) {
                if (fol.value().entityId < positions.size()) {
                    if (positions[fol.value().entityId]) {
                        pos.value().x = positions[fol.value().entityId].value().x - 50;
                        pos.value().y = positions[fol.value().entityId].value().y + 50;
                    }
                }
            }
        }
    };

variable clientNumToId

static std::map< unsigned int, size_t > clientNumToId = {};

variable packetTypeFunction

static std::unordered_map< char, std::function< void(World &, network::ClientMessage &msg)> > packetTypeFunction = {
        {0, createPlayer}, {utils::constant::PLAYER_MOVE, movePlayer}, {utils::constant::PLAYER_SHOT, playerShoot}};

variable playerHealthUpdate

std::function< void(World &)> playerHealthUpdate = [](World &world) {
        auto &healths = world.registry.getComponents<component::Health>();
        auto &networkId = world.registry.getComponents<component::NetworkId>();
        auto &entity = world.registry.getComponents<component::EntityType>();
        for (size_t i = 0; i < healths.size(); ++i) {
            auto &health = healths[i];
            if (health && health.value().health != health.value().lastHealth) {
                if (i < entity.size() && i < networkId.size()) {
                    auto &type = entity[i];
                    auto &id = networkId[i];
                    if (type && id && type.value().type == component::EntityType::Types::Player) {
                        health.value().lastHealth = health.value().health;
                        std::array<char, 2> idBin = id.value().serialize();
                        network::Message msg;
                        msg[0] = utils::constant::getPacketTypeKey(utils::constant::PacketType::HEALTH_UPDATE);
                        msg[1] = idBin[0];
                        msg[2] = idBin[1];
                        msg[3] = health.value().health;
                        network::Server::getOutgoingMessages().push(
                            network::ServerMessage(msg, std::vector<unsigned int>()));
                    }
                }
            }
        }
    };

System used to push death of entity message to the server outgoing queue when is life as gone under 0.

variable PositionUpdate

std::function< void(World &)> PositionUpdate;

System used to push updated position of entity to the server outgoing queue.

variable projectileCollision

std::function< void(World &)> projectileCollision;

variable runAttackAI

std::function< void(World &)> runAttackAI;

Runs the AIs stored in the enities

variable waves

std::function< void(World &)> waves;

Updated on 2022-11-13 at 17:21:37 +0100

Previousecs::componentNextaudio

Last updated 2 years ago

( & world, & msg)

( & world, & msg)

( & world, & msg)

( & world, & msg)

( & world, & msg)

( & world, & msg)

( & world, & msg)

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::unordered_map< char, std::function< void( &, &msg)> >

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::unordered_map< char, std::function< void( &, &msg)> >

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

std::function< void( &)>

Used to manage every action ordered by Sfml input by the user Refer to the documentation to learn more about managed input

Controllable.hpp
movePacketHandle
World
network::Message
firstMessageHandle
World
network::Message
deathMessageHandle
World
network::Message
playerHealthHandle
World
network::Message
createPlayer
World
network::ClientMessage
movePlayer
World
network::ClientMessage
playerShoot
World
network::ClientMessage
World
animate
World
draw
World
executeOnce
selfId
World
network::Message
packetTypeFunction
World
HandleIncomingMessages
World
HandleParallaxBounds
World
handleSFMLEvents
World
handleSFMLKeys
World
healthBar
World
menuSelect
World
scoreUpdate
World
SendDirection
World
manageClientEvents
World
movement
World
positionLogger
World
runMovementAI
World
deathUpdate
World
followEntitySystem
clientNumToId
World
network::ClientMessage
packetTypeFunction
World
playerHealthUpdate
World
PositionUpdate
World
projectileCollision
World
runAttackAI
World
waves