Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
Showing
with 861 additions and 155 deletions
//----------------------------------------------------------------------------------------
//
// siv::PerlinNoise
// Perlin noise library for modern C++
//
// Copyright (C) 2013-2021 Ryo Suzuki <reputeless@gmail.com>
//
// 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.
//
//----------------------------------------------------------------------------------------
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
# pragma once
# include <cstdint>
......
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 27/08/22.
//
#ifndef FGGL_DEMO_INCLUDE_GRID_HPP
#define FGGL_DEMO_INCLUDE_GRID_HPP
#include <memory>
#include "fggl/scenes/game.hpp"
#include "fggl/entity/gridworld/zone.hpp"
#include "fggl/animation/animator.hpp"
#include "fggl/gui/gui.hpp"
#include "robot/programmer.hpp"
namespace demo {
constexpr int GRID_SIZE = 255;
using DemoGrid = fggl::entity::grid::Area2D<GRID_SIZE, GRID_SIZE>;
struct LevelRules {
fggl::math::vec2i startingPos;
uint32_t startingDirection;
uint32_t startingPower;
};
struct CellPos {
fggl::math::vec2i pos;
uint8_t direction;
fggl::math::vec2f drawOffset{0.0F, 0.0F};
float rotationOffset{0.0F};
};
struct RobotState {
uint32_t power = 64;
};
class GridScene : public fggl::scenes::GameBase {
public:
explicit GridScene(fggl::App& app);
void activate() override;
void deactivate() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
// level
LevelRules m_levelRules;
fggl::entity::grid::TileSet m_tiles;
std::unique_ptr<DemoGrid> m_grid;
// control
fggl::entity::EntityID m_player = fggl::entity::INVALID;
robot::Program m_program;
// UI
fggl::gui::Container m_canvas;
fggl::animation::FrameAnimator m_animator;
void resetPuzzle();
void tickPlayer();
void checkVictory();
inline void forward() {
auto& cell = m_grid->entities().get<CellPos>(m_player);
fggl::math::vec2i moveDir{0,0};
if ( cell.direction == 0) {
moveDir.y = 1;
} else if (cell.direction == 1) {
moveDir.x = 1;
} else if (cell.direction == 2) {
moveDir.y = -1;
} else if (cell.direction == 3) {
moveDir.x = -1;
}
if ( m_grid->canMove(cell.pos, moveDir) ) {
cell.pos += moveDir;
}
}
inline void rotate(bool clockwise) {
auto& cell = m_grid->entities().get<CellPos>(m_player);
int direction = clockwise ? +1 : -1;
cell.direction = (cell.direction + 4 + direction) % 4;
}
};
}
#endif //FGGL_DEMO_INCLUDE_GRID_HPP
......@@ -13,27 +13,22 @@
*/
//
// Created by webpigeon on 22/06/22.
// Created by webpigeon on 10/12/22.
//
#ifndef FGGL_ECS_TYPES_HPP
#define FGGL_ECS_TYPES_HPP
#ifndef FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP
#define FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP
#include <cstdint>
namespace fggl::ecs {
namespace demo::hexboard {
struct entity {
const std::uint32_t id;
};
constexpr const entity NULL_ENTITY = {0};
constexpr const entity MAX_ENTITY = {0xFFFFFFFF};
constexpr uint64_t NO_SELECTION{0};
struct componentID {
const std::uint32_t id;
struct SelectionModel {
uint64_t m_hover = NO_SELECTION;
};
constexpr const entity NULL_COMPONENT = {0};
}
} // namespace demo::hexboard
#endif //FGGL_ECS_TYPES_HPP
#endif //FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 02/01/23.
//
#ifndef FGGL_DEMO_INCLUDE_HEXBOARD_CAMERA_HPP
#define FGGL_DEMO_INCLUDE_HEXBOARD_CAMERA_HPP
#include "fggl/math/types.hpp"
namespace demo::hexboard {
constexpr float TRAUMA_DECAY = 0.01F;
constexpr float TRAUMA_LARGE = 0.5F;
constexpr float TRAUMA_SMALL = 0.1F;
constexpr float SPEED_SLOW = 0.01F;
constexpr float SPEED_MEDIUM = 0.1F;
constexpr float SPEED_FAST = 0.5F;
constexpr fggl::math::vec2 ndc_to_screen(fggl::math::vec2 ndcPos, fggl::math::vec2 screenSize) {
return fggl::math::vec2(
fggl::math::rescale_ndc(ndcPos.x, 0, screenSize.x),
fggl::math::rescale_ndc(ndcPos.y, 0, screenSize.y)
);
}
/**
* A 2D 'juiced' camera for grid worlds.
*
* This camera is based on HexBoard, and the GDC talk around this concept. Many of the ideas implemented here
* come from that source.
*
* @see https://www.youtube.com/watch?v=tu-Qe66AvtY
*/
class Camera2D {
public:
using Point = fggl::math::vec2;
/**
* Apply active camera effects.
*
* This method must be called once per frame of the camera's visual effects are to be animated.
*
* @param delta the amount of time that has passed
*/
void update(float delta);
inline fggl::math::vec2 unproject(fggl::math::vec2 screenPos) const {
auto location = screenPos;
location.x += 1920/2.0F;
location.y += 1080/2.0F;
return location + m_location;
// return screenPos + m_location;
}
inline fggl::math::vec2 project(fggl::math::vec2 worldPos) const {
return worldPos - m_location;
}
/**
* Move the camera to a new location.
*
* This will apply any movement effects the camera has applied to it. As a result movement to the location
* will not be instantaneous.
*
* @param newTarget the new target location
*/
inline void moveTo(Point newTarget) {
m_target = newTarget;
}
/**
* Move the camera by a defined amount.
*
* This will apply any movement effects the camera has applied to it. As a result movement to the location
* will not be instantaneous.
*
* @param delta the amount to add to the target, negative values will subject from the target location
*/
inline void moveBy(Point delta) {
m_target += delta;
}
/**
* Instantaneously move the camera to a new location.
*
* @param the new camera location
*/
inline void teleportTo(Point newTarget) {
m_location = newTarget;
m_target = newTarget;
}
/**
* Instantaneously adjust the camera location.
*
* @param delta the amount to adjust the camera location by
*/
inline void teleportBy(Point delta) {
m_location += delta;
m_target = m_location;
}
/**
* Get the current view offset of this camera.
*
* @return the current location this camera is pointing at
*/
inline Point getFocusLocation() const {
auto offset = m_location;
offset.x += 1920/2.0F;
offset.y += 1080/2.0F;
return -offset;
}
private:
Point m_location;
Point m_target;
float m_trauma;
float m_scale = SPEED_MEDIUM;
};
}
#endif //FGGL_DEMO_INCLUDE_HEXBOARD_CAMERA_HPP
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 10/12/22.
//
#ifndef FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H
#define FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H
#include <memory>
#include <optional>
#include "fggl/scenes/game.hpp"
#include "fggl/grid/hexgrid.hpp"
#include "fggl/grid/layout.hpp"
#include "camera.hpp"
namespace demo::hexboard {
struct SelectionModel {
std::optional<fggl::grid::IntHex> selected;
std::optional<fggl::grid::IntHex> hover;
};
class Scene : public fggl::scenes::GameBase {
public:
explicit Scene(fggl::App& app);
void activate() override;
void deactivate() override;
void update(float delta) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
std::unique_ptr<fggl::grid::HexGrid> m_board;
std::unique_ptr<fggl::grid::Layout> m_layout;
std::unique_ptr<SelectionModel> m_selections;
std::unique_ptr<Camera2D> m_camera;
fggl::math::vec2 m_screen;
std::optional<fggl::math::vec2> m_dragging;
void drawGrid(fggl::gfx::Paint&);
void drawSelections(fggl::gfx::Paint&);
};
} // namespace demo::hexboard
#endif //FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 18/10/22.
//
#ifndef FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
#define FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
#include "fggl/scenes/game.hpp"
#include "fggl/assets/types.hpp"
namespace demo {
class Viewer : public fggl::scenes::Game {
public:
explicit Viewer(fggl::App& app);
void activate() override;
void deactivate() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
fggl::entity::EntityID m_model = fggl::entity::INVALID;
std::vector< fggl::assets::AssetID> m_assets;
uint64_t m_lastAsset = 0;
bool m_debug = false;
void cycleAsset(uint64_t asset);
};
}
#endif //FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 04/09/22.
//
#ifndef FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
#define FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
#include <functional>
#include "fggl/gui/containers.hpp"
namespace demo::robot {
struct Instruction {
const char* name;
std::function<void(void)> m_func;
};
struct Program {
std::vector<Instruction> m_instructions;
uint32_t m_currInstruction;
bool playing = false;
inline std::size_t size() {
return m_instructions.size();
}
inline void step() {
m_instructions[ m_currInstruction ].m_func();
m_currInstruction++;
}
inline void stop() {
playing = false;
m_currInstruction = 0;
}
};
class Timeline : public fggl::gui::Panel {
public:
explicit Timeline(Program& program);
void update(float deltaTime) override;
void render(fggl::gfx::Paint& paint) override;
protected:
void renderInstructions(fggl::gfx::Paint& paint);
private:
std::vector<std::reference_wrapper<Program>> m_tracks;
};
}
#endif //FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
......@@ -26,6 +26,8 @@
#define DEMO_ROLLBALL_HPP
#include "fggl/scenes/game.hpp"
#include "fggl/phys/service.hpp"
#include "fggl/script/engine.hpp"
namespace demo {
......@@ -36,14 +38,10 @@ namespace demo {
};
struct RollState {
fggl::ecs::entity_t player = fggl::ecs::NULL_ENTITY;
fggl::ecs::entity_t closestPickup;
fggl::entity::EntityID player = fggl::entity::INVALID;
fggl::entity::EntityID closestPickup;
DebugMode mode = DebugMode::NORMAL;
std::array<fggl::ecs3::entity_t, 3> collectables {
fggl::ecs::NULL_ENTITY,
fggl::ecs::NULL_ENTITY,
fggl::ecs::NULL_ENTITY };
std::vector<fggl::entity::EntityID> collectables;
float time = 0.0f;
};
......@@ -54,17 +52,20 @@ namespace demo {
explicit RollBall(fggl::App& app);
void activate() override;
void deactivate() override;
void update() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
constexpr static fggl::math::vec3 HINT_COLOUR{0.5f, 0.0f, 0.0f};
RollState state;
fggl::phys::PhysicsEngine* m_phys;
fggl::script::ScriptEngine* m_scripts;
fggl::math::vec3 cameraOffset = {-15.0F, 15.0F, 0.0F};
void closestPickup(fggl::ecs3::World& world);
void spinCubes(fggl::ecs3::World& world, float dt);
void closestPickup(fggl::entity::EntityManager& world);
void spinCubes(fggl::entity::EntityManager& world, float dt);
};
}
......
......@@ -29,7 +29,7 @@ namespace demo {
explicit TopDown(fggl::App& app);
void activate() override;
void update() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
......
......@@ -979,7 +979,7 @@ EXCLUDE_PATTERNS =
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories use the pattern */test/*
EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = "YAML" "glm" "dd"
# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
......
......@@ -5,12 +5,14 @@ file(GLOB_RECURSE HEADER_LIST CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/include/fgg
# Should be shared linkage for legal reasons (LGPL)
add_library(fggl ${HEADER_LIST})
target_link_libraries(fggl PUBLIC entt)
# we need to tell people using the library about our headers
target_include_directories(fggl
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
)
# users of this library need at least C++20
target_compile_features(fggl PUBLIC cxx_std_20)
......@@ -34,20 +36,19 @@ endif ()
# the important stuff everything else uses
add_subdirectory(math)
add_subdirectory(util)
add_subdirectory(grid)
add_subdirectory(assets)
add_subdirectory(phys)
target_sources(${PROJECT_NAME}
PRIVATE
PRIVATE
app.cpp
data/model.cpp
data/procedural.cpp
data/heightmap.cpp
ecs/ecs.cpp
ecs3/module/module.cpp
ecs3/fast/Container.cpp
ecs3/prototype/loader.cpp
ecs3/prototype/world.cpp
data/module.cpp
scenes/menu.cpp
scenes/game.cpp
......@@ -55,27 +56,17 @@ target_sources(${PROJECT_NAME}
input/input.cpp
input/mouse.cpp
input/camera_input.cpp
gui/widget.cpp
gui/widgets.cpp
gui/containers.cpp
gui/fonts.cpp
)
# GUI support
add_subdirectory(gui)
# yaml-cpp for configs and storage
find_package(yaml-cpp)
target_link_libraries(fggl PUBLIC yaml-cpp)
# model loading
find_package(assimp CONFIG)
if ( MSVC )
target_link_libraries(${PROJECT_NAME} PUBLIC assimp::assimp)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC assimp)
endif()
find_package(Freetype)
target_link_libraries(${PROJECT_NAME} PUBLIC Freetype::Freetype)
add_subdirectory(data/assimp)
# Graphics backend
add_subdirectory(gfx)
......@@ -88,11 +79,12 @@ add_subdirectory(debug)
# platform integrations
add_subdirectory(platform)
add_subdirectory(entity)
##
# begin windows support
##
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
endif()
if (MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
endif ()
......@@ -13,80 +13,79 @@
*/
#include <cstdlib>
#include <memory>
#include <spdlog/spdlog.h>
#include <fggl/app.hpp>
#include <fggl/ecs3/types.hpp>
#include "fggl/ecs/component_fwd.hpp"
#include "fggl/ecs3/module/module.hpp"
namespace fggl {
App::App(modules::Manager* services, const Identifer& name) : App::App( services, name, name ) {
}
App::App(modules::Manager *services, const Identifer &name) : App::App(services, name, name) {
}
App::App(modules::Manager* services, const Identifer& name, const Identifer& folder ) :
m_running(true),
m_types(std::make_unique<ecs3::TypeRegistry>()),
m_modules(std::make_unique<ecs3::ModuleManager>(*m_types)),
App::App(modules::Manager *services, const Identifer & /*name*/, const Identifer & /*folder*/ ) :
m_running(true),
m_window(nullptr),
m_states(),
m_subsystems(services){}
m_states(),
m_subsystems(services) {}
int App::run(int argc, const char** argv) {
auto* windowing = m_subsystems->get<display::WindowService>();
auto App::run(int /*argc*/, const char **/*argv*/) -> int {
auto *windowing = m_subsystems->get<display::WindowService>();
{
// activate the first state
auto& state = m_states.active();
{
// activate the first state
auto &state = m_states.active();
m_expectedScene = m_states.activeID();
state.activate();
}
state.activate();
}
auto lastTime = glfwGetTime();
while (m_running) {
auto currTime = glfwGetTime();
auto delta = currTime - lastTime;
lastTime = currTime;
while ( m_running ) {
// trigger a state change if expected
if ( m_expectedScene != m_states.activeID() ) {
if (m_expectedScene != m_states.activeID()) {
auto result = m_states.change(m_expectedScene);
if ( !result ) {
if (!result) {
m_expectedScene = m_states.activeID();
}
}
// process window events
if ( windowing != nullptr) {
if (windowing != nullptr) {
windowing->pollEvents();
}
m_modules->onUpdate();
//m_modules->onUpdate();
auto& state = m_states.active();
state.update();
auto &state = m_states.active();
state.update((float)delta);
// window rendering to frame buffer
if ( m_window != nullptr ) {
m_modules->onFrameStart();
// window rendering to frame buffer
if (m_window != nullptr) {
// m_modules->onFrameStart();
m_window->frameStart();
// get draw instructions
auto& graphics = m_window->graphics();
state.render(graphics);
// get draw instructions
auto &graphics = m_window->graphics();
state.render(graphics);
m_window->frameEnd();
m_modules->onFrameEnd();
m_window->frameEnd();
// m_modules->onFrameEnd();
m_running = m_running && !m_window->wantClose();
}
}
}
}
{
// shutdown last state
auto& state = m_states.active();
state.deactivate();
}
{
// shutdown last state
auto &state = m_states.active();
state.deactivate();
}
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
} //namespace fggl
target_sources(fggl PRIVATE
module.cpp
types.cpp
packed/module.cpp
)
\ No newline at end of file
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 20/08/22.
//
#include "fggl/assets/module.hpp"
namespace fggl::assets {
auto AssetFolders::factory(modules::ServiceName service, modules::Services &services) -> bool {
if (service == Loader::service) {
auto *storage = services.get<data::Storage>();
auto *checkin = services.get<CheckinAdapted>();
services.create<Loader>(storage, checkin);
return true;
}
if (service == AssetManager::service) {
services.create<AssetManager>();
return true;
}
return false;
}
} // namespace fggl::assets
\ No newline at end of file
......@@ -12,39 +12,26 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FGGL_ECS3_UTILS_HPP
#define FGGL_ECS3_UTILS_HPP
//
// Created by webpigeon on 20/08/22.
//
#include <cstddef>
#include "fggl/assets/packed/module.hpp"
namespace fggl::utils {
namespace fggl::assets {
template<typename T>
std::size_t search(const T *data, const std::size_t size, const T &v) {
// empty list == not found
if (size == 0) {
return size;
auto PackedAssets::factory(modules::ServiceName service, modules::Services &services) -> bool {
if (service == RawCheckin::service) {
services.create<RawCheckin>();
return true;
}
std::size_t left = 0;
std::size_t right = size - 1;
while (left <= right) {
std::size_t m = (left + right) / 2;
if (data[m] == v) {
return m;
} else if (v < data[m]) {
if (m == 0) {
return size;
}
right = m - 1;
} else {
left = m + 1;
}
if (service == CheckinAdapted::service) {
auto* storage = services.get<data::Storage>();
auto* rawCheckin = services.get<RawCheckin>();
services.create<CheckinAdapted>(storage, rawCheckin);
return true;
}
return size;
return false;
}
}
#endif
} // namespace fggl::assets
\ No newline at end of file
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 19/11/22.
//
#include <stack>
#include <vector>
#include <memory>
#include <set>
#include <map>
#include <concepts>
#include "fggl/util/guid.hpp"
namespace fggl::assets {
using AssetName = util::OpaqueName<uint64_t, struct AssetRefStruct>;
/**
* The base class representing an asset.
*
* This can be combined with the templated version.
*/
class Asset {
public:
Asset(AssetName name) : m_name(name) {}
virtual ~Asset() = default;
inline void release() {
releaseImpl();
}
bool operator==(const Asset& asset) const {
return m_name == asset.m_name;
}
bool operator!=(const Asset& asset) const {
return m_name != asset.m_name;
}
private:
AssetName m_name;
virtual void releaseImpl() = 0;
};
/**
* Wrapper for types that cannot extend Asset themselves.
*
* @tparam T the asset to wrap
*/
template<typename T>
class AssetBox : public Asset {
public:
AssetBox(T* ptr) : m_ptr(ptr) {}
~AssetBox() override {
release();
}
T* ptr() {
return m_ptr;
}
private:
T* m_ptr;
void releaseImpl() override {
delete m_ptr;
m_ptr = nullptr;
}
};
/**
* Asset Library.
*
* The currently usable set of assets loaded into the engine.
*/
class AssetLibrary {
public:
void load(AssetName name);
void unload(AssetName name);
template<typename T>
requires std::derived_from<T, Asset>
void store(AssetName name, T* ptr) {
m_assets[name] = std::make_unique<T>(ptr);
}
template<typename T>
requires std::derived_from<T, Asset>
void get(AssetName name) const {
Asset* asset = m_assets.at(name).get();
return dynamic_cast<T>(asset);
}
inline Asset* get(AssetName name) const {
return m_assets.at( name ).get();
}
private:
std::map<AssetName, std::unique_ptr<Asset>> m_assets;
};
struct AssetRecord {
AssetName id;
std::vector<AssetName> dependencies;
bool hasDepends(AssetName name) const;
void addDepend(AssetName name);
};
class AssetGraph {
public:
AssetGraph(AssetLibrary* loader);
/**
*
*
* @param name
*/
void require(AssetName& name) {
if ( m_loaded.find(name) != m_loaded.end() ) {
return;
}
m_required.push(name);
}
/**
*
*
* @return
*/
[[nodiscard]]
inline bool isLoadComplete() const {
return m_required.empty();
}
/**
*
*
* @param name
* @return
*/
[[nodiscard]]
inline bool isLoaded(AssetName name) const {
return m_loaded.find(name) != m_loaded.end();
}
/**
*
* @param name
* @param description
*/
void addDependency(AssetName& name, AssetName& description) {
auto& assets = m_assets.at(name);
assets.addDepend(description);
}
/**
*
* @param name
* @param dependency
* @return
*/
[[nodiscard]]
bool hasDependency(AssetName& name , AssetName& dependency) const {
try {
auto &assets = m_assets.at(name);
return assets.hasDepends(dependency);
} catch ( std::out_of_range& ) {
return false;
}
}
/**
*
*/
void process() {
auto asset = m_required.top();
m_loader->load( asset );
m_required.pop();
}
/**
*
*/
void finishLoading() {
while ( !m_loaded.empty() ) {
process();
}
}
private:
std::stack<AssetName> m_required;
std::set<AssetName> m_loaded;
std::map<AssetName, AssetRecord> m_assets;
AssetLibrary* m_loader;
};
} // namespace fggl::assets
\ No newline at end of file
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 20/11/22.
//
#include "fggl/assets/types.hpp"
namespace fggl::assets {
auto make_asset_id_rt(const std::string &pack, const std::string &path, const std::string &view) -> AssetID {
auto fullPath = pack + ":" + path;
if (!view.empty()) {
fullPath += "[" + view + "]";
}
#ifndef NDEBUG
util::intern_string(fullPath.c_str());
#endif
auto hash = util::hash_fnv1a_64(fullPath.c_str());
return AssetID::make(hash);
}
auto asset_from_user(const std::string &input, const std::string &pack) -> AssetID {
if (input.find(':') != std::string::npos ) {
// probably fully qualified
#ifndef NDEBUG
util::intern_string(input.c_str());
#endif
auto hash = util::hash_fnv1a_64(input.c_str());
return AssetID::make(hash);
}
// probably local
return make_asset_id_rt(pack, input);
}
}
\ No newline at end of file
target_sources(fggl
PRIVATE
types.cpp
)
types.cpp
)
add_subdirectory(openal)
\ No newline at end of file
add_subdirectory(openal)
add_subdirectory(fallback)
\ No newline at end of file
target_sources(fggl
PRIVATE
audio.cpp
)