17#ifndef _FGE_EXTRA_FUNCTION_HPP_INCLUDED
18#define _FGE_EXTRA_FUNCTION_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_event.hpp"
22#include "FastEngine/C_rect.hpp"
23#include "FastEngine/graphic/C_color.hpp"
24#include "FastEngine/graphic/C_renderTarget.hpp"
25#include "FastEngine/graphic/C_view.hpp"
28#define GLM_ENABLE_EXPERIMENTAL
29#include "glm/gtx/rotate_vector.hpp"
34#define FGE_MATH_SQRT2 1.41421356237309504880
35#define FGE_MATH_PI 3.14159265358979323846
41using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
45 inline Line() =
default;
46 inline Line(fge::Vector2f
const& start, fge::Vector2f
const& end) :
50 inline Line(fge::Vector2f
const& origin, fge::Vector2f
const& direction,
float length) :
52 _end(origin + direction * length)
55 [[nodiscard]]
inline fge::Vector2f getDirection()
const {
return glm::normalize(this->_end - this->_start); }
56 [[nodiscard]]
inline float getLength()
const {
return glm::length(this->_end - this->_start); }
78[[nodiscard]]
inline char UnicodeToChar(uint32_t unicode);
80[[nodiscard]] FGE_API
bool IsEngineBuiltInDebugMode();
82FGE_API
bool SetSystemCursor(SDL_SystemCursor
id);
84FGE_API std::size_t GetFilesInFolder(std::list<std::string>& buffer,
85 std::filesystem::path
const& path,
86 std::string
const& regexFilter =
".+",
87 bool ignoreDirectory =
true,
88 bool onlyFilename =
true,
89 bool recursive =
false);
91FGE_API
bool SetVirtualTerminalSequenceSupport();
92FGE_API
void SetConsoleCmdTitle(
char const* title);
94[[nodiscard]] FGE_API
void* AlignedAlloc(std::size_t size, std::size_t alignment);
95FGE_API
void AlignedFree(
void* data);
97FGE_API
void Sleep(std::chrono::microseconds time);
101 void operator()(
void* p)
const { AlignedFree(p); };
109[[nodiscard]] FGE_API std::size_t Hash(
void const* key, std::size_t len, std::size_t seed = 0xc70f6907UL);
111template<
typename TFloat>
112[[nodiscard]]
inline TFloat LimitRangeAngle(TFloat angleDegree);
115#ifndef FGE_DEF_SERVER
117[[nodiscard]] FGE_API
bool IsMouseOn(fge::Vector2f
const& mousePos,
fge::RectFloat const& zone);
119[[nodiscard]] FGE_API
bool IsPressed(
fge::Event const& evt,
120 fge::Vector2f
const& mouse_pos,
122 uint8_t button = SDL_BUTTON_LEFT);
125enum class IntersectionOptions
128 I_STRICT_NORM_LIMITS,
131 I_DEFAULT = I_NORM_LIMITS
134[[nodiscard]] FGE_API std::optional<fge::Intersection>
137 IntersectionOptions option = IntersectionOptions::I_DEFAULT);
138[[nodiscard]] FGE_API std::optional<fge::Intersection>
139CheckIntersection(fge::Vector2f
const& position,
140 fge::Vector2f
const& direction,
142 IntersectionOptions option = IntersectionOptions::I_DEFAULT);
144[[nodiscard]]
inline bool IsVertexInCone(
fge::Line const& line1,
146 fge::Vector2f
const& origin,
147 fge::Vector2f
const& vertex);
148[[nodiscard]]
inline bool IsVertexInCone(
float coneAngle,
149 fge::Vector2f
const& direction,
150 fge::Vector2f
const& origin,
151 fge::Vector2f
const& vertex);
155[[nodiscard]]
fge::Rect<T> ToRect(fge::Vector2<T>
const& pos1, fge::Vector2<T>
const& pos2);
157[[nodiscard]]
fge::Rect<T> ToRect(std::vector<fge::Vector2<T>>
const& pos);
159[[nodiscard]]
fge::Rect<T> ToRect(fge::Vector2<T>
const* pos, std::size_t size);
168[[nodiscard]] FGE_API fge::Vector2f
169ReachVector(fge::Vector2f
const& position, fge::Vector2f
const& target,
float speed,
float deltaTime);
170[[nodiscard]] FGE_API
float
171ReachRotation(
float rotation,
float target,
float speed,
float deltaTime, fge::TurnMode turnMode);
174[[nodiscard]] T ReachValue(T value, T target, T speed,
float deltaTime);
177[[nodiscard]]
inline constexpr float Cross2d(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
178[[nodiscard]]
inline fge::Vector2f GetSegmentNormal(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
179[[nodiscard]]
inline constexpr float GetAngle(fge::Vector2f
const& vec);
180[[nodiscard]]
inline constexpr float GetAngleBetween(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
181[[nodiscard]]
inline float GetDistanceBetween(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
182[[nodiscard]]
inline float
183GetShortestDistanceBetween(fge::Vector2f
const& point, fge::Vector2f
const& lineStart, fge::Vector2f
const& lineEnd);
185template<
typename TIterator>
186[[nodiscard]] TIterator
187GetNearestPoint(fge::Vector2f
const& point, TIterator
const& pointsBegin, TIterator
const& pointsEnd);
189[[nodiscard]]
inline constexpr fge::Vector2f GetForwardVector(
float angle);
190[[nodiscard]]
inline constexpr fge::Vector2f GetBackwardVector(
float angle);
191[[nodiscard]]
inline constexpr fge::Vector2f GetLeftVector(
float angle);
192[[nodiscard]]
inline constexpr fge::Vector2f GetRightVector(
float angle);
194[[nodiscard]]
inline constexpr float DotSquare(fge::Vector2f
const& vec);
196[[nodiscard]]
inline constexpr float
197GetHandedness(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2, fge::Vector2f
const& vec3);
200[[nodiscard]]
inline constexpr float ConvertRange(
float x,
float xMin,
float xMax,
float yMin,
float yMax);
201[[nodiscard]]
inline constexpr fge::Vector2f ConvertRange(fge::Vector2f
const& x,
202 fge::Vector2f
const& xMin,
203 fge::Vector2f
const& xMax,
204 fge::Vector2f
const& yMin,
205 fge::Vector2f
const& yMax);
207[[nodiscard]]
inline constexpr fge::Vector2f MapCircleToSquareCoords(fge::Vector2f
const& circleCoords);
208[[nodiscard]]
inline constexpr fge::Vector2f MapSquareToCircleCoords(fge::Vector2f
const& squareCoords);
215FGE_API
void GetConvexHull(std::vector<fge::Vector2f>
const& input, std::vector<fge::Vector2f>& output);
218[[nodiscard]] FGE_API fge::Vector2f GetViewSizePercentage(
fge::View const& view,
fge::View const& defaultView);
219[[nodiscard]] FGE_API fge::Vector2f SetViewSizePercentage(
float percentage,
fge::View const& defaultView);
220[[nodiscard]] FGE_API fge::Vector2f SetViewSizePercentage(fge::Vector2f
const& percentage,
223[[nodiscard]] FGE_API fge::Vector2f
224TransposePointFromAnotherView(
fge::View const& pointView, fge::Vector2f
const& point,
fge::View const& newView);
226enum class ClipClampModes
236 fge::ClipClampModes clampMode);
244[[nodiscard]]
inline float DurationToSecondFloat(T duration);
247FGE_API
bool LoadJsonFromFile(std::filesystem::path
const& path, nlohmann::json& j);
248FGE_API
bool LoadOrderedJsonFromFile(std::filesystem::path
const& path, nlohmann::ordered_json& j);
249FGE_API
bool SaveJsonToFile(std::filesystem::path
const& path, nlohmann::json
const& j,
int fieldWidth = 2);
252[[nodiscard]] FGE_API std::filesystem::path MakeRelativePathToBasePathIfExist(std::filesystem::path
const& basePath,
253 std::filesystem::path
const& path);
257#include "extra_function.inl"
Definition C_color.hpp:35
This class is a wrapper for SDL events.
Definition C_event.hpp:59
Definition C_renderTarget.hpp:56
Define a camera in a 2D scene.
Definition C_view.hpp:43
Definition extra_function.hpp:100
Definition extra_function.hpp:63
Definition extra_function.hpp:44