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
116[[nodiscard]] FGE_API
bool IsMouseOn(
fge::RenderTarget const& target, fge::RectFloat
const& zone);
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,
121 fge::RectFloat
const& zone,
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);
162[[nodiscard]] FGE_API fge::Vector2f
163ReachVector(fge::Vector2f
const& position, fge::Vector2f
const& target,
float speed,
float deltaTime);
164[[nodiscard]] FGE_API
float
165ReachRotation(
float rotation,
float target,
float speed,
float deltaTime, fge::TurnMode turnMode);
168[[nodiscard]] T ReachValue(T value, T target, T speed,
float deltaTime);
171[[nodiscard]]
inline constexpr float Cross2d(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
172[[nodiscard]]
inline fge::Vector2f GetSegmentNormal(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
173[[nodiscard]]
inline constexpr float GetAngle(fge::Vector2f
const& vec);
174[[nodiscard]]
inline constexpr float GetAngleBetween(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
175[[nodiscard]]
inline float GetDistanceBetween(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2);
176[[nodiscard]]
inline float
177GetShortestDistanceBetween(fge::Vector2f
const& point, fge::Vector2f
const& lineStart, fge::Vector2f
const& lineEnd);
179template<
typename TIterator>
180[[nodiscard]] TIterator
181GetNearestPoint(fge::Vector2f
const& point, TIterator
const& pointsBegin, TIterator
const& pointsEnd);
183[[nodiscard]]
inline constexpr fge::Vector2f GetForwardVector(
float angle);
184[[nodiscard]]
inline constexpr fge::Vector2f GetBackwardVector(
float angle);
185[[nodiscard]]
inline constexpr fge::Vector2f GetLeftVector(
float angle);
186[[nodiscard]]
inline constexpr fge::Vector2f GetRightVector(
float angle);
188[[nodiscard]]
inline constexpr float DotSquare(fge::Vector2f
const& vec);
190[[nodiscard]]
inline constexpr float
191GetHandedness(fge::Vector2f
const& vec1, fge::Vector2f
const& vec2, fge::Vector2f
const& vec3);
194[[nodiscard]]
inline constexpr float ConvertRange(
float x,
float xMin,
float xMax,
float yMin,
float yMax);
195[[nodiscard]]
inline constexpr fge::Vector2f ConvertRange(fge::Vector2f
const& x,
196 fge::Vector2f
const& xMin,
197 fge::Vector2f
const& xMax,
198 fge::Vector2f
const& yMin,
199 fge::Vector2f
const& yMax);
201[[nodiscard]]
inline constexpr fge::Vector2f MapCircleToSquareCoords(fge::Vector2f
const& circleCoords);
202[[nodiscard]]
inline constexpr fge::Vector2f MapSquareToCircleCoords(fge::Vector2f
const& squareCoords);
209FGE_API
void GetConvexHull(std::vector<fge::Vector2f>
const& input, std::vector<fge::Vector2f>& output);
212[[nodiscard]] FGE_API fge::Vector2f GetViewSizePercentage(
fge::View const& view,
fge::View const& defaultView);
213[[nodiscard]] FGE_API fge::Vector2f SetViewSizePercentage(
float percentage,
fge::View const& defaultView);
214[[nodiscard]] FGE_API fge::Vector2f SetViewSizePercentage(fge::Vector2f
const& percentage,
217[[nodiscard]] FGE_API fge::Vector2f
218TransposePointFromAnotherView(
fge::View const& pointView, fge::Vector2f
const& point,
fge::View const& newView);
220enum class ClipClampModes
227[[nodiscard]] FGE_API fge::View ClipView(fge::View
const& view,
228 fge::RenderTarget
const& target,
229 fge::RectFloat
const& worldCoordClipRect,
230 fge::ClipClampModes clampMode);
233[[nodiscard]] FGE_API fge::RectFloat GetScreenRect(fge::RenderTarget
const& target);
234[[nodiscard]] FGE_API fge::RectFloat GetScreenRect(fge::RenderTarget
const& target, fge::View
const& view);
238[[nodiscard]]
inline float DurationToSecondFloat(T duration);
241FGE_API
bool LoadJsonFromFile(std::filesystem::path
const& path, nlohmann::json& j);
242FGE_API
bool LoadOrderedJsonFromFile(std::filesystem::path
const& path, nlohmann::ordered_json& j);
243FGE_API
bool SaveJsonToFile(std::filesystem::path
const& path, nlohmann::json
const& j,
int fieldWidth = 2);
246[[nodiscard]] FGE_API std::filesystem::path MakeRelativePathToBasePathIfExist(std::filesystem::path
const& basePath,
247 std::filesystem::path
const& path);
251#include "extra_function.inl"
This class is a wrapper for SDL events.
Definition C_event.hpp:59
Data wrapper representing an Object in a Scene.
Definition C_scene.hpp:170
Definition C_renderTarget.hpp:56
Define a camera in a 2D scene.
Definition C_view.hpp:49
Definition extra_function.hpp:100
Definition extra_function.hpp:63
Definition extra_function.hpp:44