Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvarwow69 committed Nov 15, 2023
1 parent 9b309f9 commit 36e081e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions includes/components/Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ namespace sw {
/// \return A reference to the sprite
Sprite &setTexture(std::string name);

/// \brief Define a rect displayed applied on the texture
/// \brief Define a sub-rectangle of the texture displayed on the Sprite
///
/// \param rect Dimension of the rect
/// \param rect Dimension (width, height) of the rect
/// \return A reference to the sprite
Sprite &setTextureRect(sw::FloatRect rect);

Expand Down
21 changes: 9 additions & 12 deletions includes/components/SpriteAnimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ namespace sw {

class SW_MODULE_EXPORT SpriteAnimator : public sw::Component {
public:

/// \brief Define the type of the animation
enum AnimType {
ANIM_SPRITE,
ANIM_LINE
ANIM_SPRITE, // One animation on the whole texture
ANIM_LINE // One animation per line
};

public:
/// \brief Default constructor
///
/// \param gameObject Reference to the gameObject
Expand All @@ -40,14 +38,14 @@ namespace sw {
/// \brief Reset your animation (set on first frame)
void reset();

/// \brief Return a bool if the animation is playing
/// \brief Return a bool if the animation is currently playing
///
/// \return bool
[[nodiscard]] bool isPlaying() const;

/// \brief Set your animation in loop or not
/// \brief Define if your animation loop
///
/// \param loop
/// \param loop boolean
/// \param delay delay between two animation
/// \return reference to your sprite SpriteAnimator
SpriteAnimator &setLoop(bool loop, float delay = 0);
Expand All @@ -63,13 +61,13 @@ namespace sw {

/// \brief Define the displayed rect on your texture
///
/// \param rect
/// \param rect Rect's size (width, height)
/// \return reference to your sprite SpriteAnimator
SpriteAnimator &setRect(sw::Vector2u rect);

/// \brief Define the speed (number of frame per second) of your animation
///
/// \param fps
/// \param fps float
/// \return reference to your sprite
SpriteAnimator &setFPS(float fps);

Expand All @@ -85,8 +83,7 @@ namespace sw {
/// \return reference to your sprite
SpriteAnimator &setPlayOnStart(bool value);


/// \brief Get id the animation is set to loop
/// \brief Get if the animation loop
///
/// \return bool
[[nodiscard]]const bool &isLoop() const;
Expand All @@ -103,7 +100,7 @@ namespace sw {

/// \brief Get the speed of your animation
///
/// \return float In Frame per second
/// \return float Frame per second
[[nodiscard]]const float &getFPS() const;

/// \brief Get the type of your animation
Expand Down
2 changes: 1 addition & 1 deletion includes/core/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "core/window/Window.hpp"
#include "scene/sceneManager/SceneManager.hpp"
#include "resources/ResourcesManager.hpp"
#include "utils/Chronos.hpp"
#include "utils/Chrono.hpp"

namespace sw {

Expand Down
7 changes: 6 additions & 1 deletion includes/managers/SpriteAnimatorManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ namespace sw {
private:

/// \brief Update Animation following rules defined for the Type
/// sw::Animator::ANIM_LINE
/// sw::SpriteAnimator::ANIM_LINE
///
/// \param animator Reference to the animator
/// \param current_time get total time
static void animLine(SpriteAnimator &animator, double &current_time);

/// \brief Update Animation following rules defined for the Type
/// sw::SpriteAnimator::ANIM_SPRITE
///
/// \param animator Reference to the animator
/// \param current_time get total time
static void animSprite(SpriteAnimator &animator, double &current_time);


Expand Down
48 changes: 23 additions & 25 deletions includes/utils/Chronos.hpp → includes/utils/Chrono.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
/*
** ShipWreck Engine v0.1, graphical library made to create games
** Current file: Chrono.hpp
** Current file: chrono.hpp
*/

#ifndef SHIPWRECK_ENGINE_CHRONOS_HPP
#define SHIPWRECK_ENGINE_CHRONOS_HPP
#ifndef SHIPWRECK_ENGINE_CHRONO_HPP
#define SHIPWRECK_ENGINE_CHRONO_HPP

#include <chrono>

namespace sw {

class Chronos {
class Chrono {

public:
enum State {
Wait, Lauch
WAIT, LAUNCH
};

/// @brief Default @c Constructor of a @b Chrono.
/// @brief Default Constructor
/// You can define the constructor status, whether or not it should
/// be run when created.
///
/// @param state 'Lauch' if you want to start the chrono directly after
/// have been created, 'Wait' otherwise.
explicit Chronos(State state = Wait);
/// @param state 'LAUNCH' if you want to start the chrono directly after
/// have been created, 'WAIT' otherwise.
explicit Chrono(State state = WAIT);

/// @brief Default @c Destructor of a @b Chrono.
~Chronos() = default;
/// @brief Default Destructor of a chrono.
~Chrono() = default;

/// @brief Start the @b Chrono.
/// @brief Start the chrono.
void start();

/// @brief Stop the @b Chrono. Then, if you try get the time, it will
/// not change.
/// @brief Stop the chrono.
void stop();

/// @brief Make a checkpoint. Then, you can either get the time since
Expand All @@ -44,40 +43,39 @@ namespace sw {
/// @return The time in second.
double getElapsedTime() const;

/// @brief Get the time since the start of the @b Chrono
/// (call to the start function).
/// @brief Get the time since the start of the chrono (call to the start function).
///
/// @return The time in second.
double getTotalTime() const;

/// @brief Get the status of the @b Chrono.
/// @brief Get the status of the chrono.
///
/// @return True if it is running, false otherwise.
[[nodiscard]] bool isRunning() const;

private:
/// @brief The start time point of a @b Chrono.
/// @brief The start time point of a chrono.
/// It is set at all call to the start method.
std::chrono::time_point <std::chrono::steady_clock> m_start;

/// @brief The tour time point of a @b Chrono.
/// @brief The tour time point of a chrono.
/// It is set at all call to the tour method.
std::chrono::time_point <std::chrono::steady_clock> m_tour;

/// @brief The last time point of a @b Chrono. It is corresponding to
/// either the current time or the time you stoped or paused the @b Chrono.
/// @brief The last time point of a chrono. It is corresponding to
/// either the current time or the time you stoped or paused the chrono.
/// It is set when the time is get.
mutable std::chrono::time_point <std::chrono::steady_clock> m_end;

/// @brief The status of the chrono.
/// If it is true, the chrono is running. If it is false, the chrono
/// is either paused or stoped.
/// is either paused or stopped.
bool m_isRunning;

}; // class Chronos
}; // class Chrono

#include "Chronos.inl"
#include "Chrono.inl"

} // SW

#endif //SHIPWRECK_ENGINE_CHRONOS_HPP
#endif //SHIPWRECK_ENGINE_CHRONO_HPP
18 changes: 9 additions & 9 deletions includes/utils/Chronos.inl → includes/utils/Chrono.inl
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
/*
** ShipWreck Engine v0.1, graphical library made to create games
** Current file: Chronos.inl
** Current file: Chrono.inl
*/

inline sw::Chronos::Chronos(State state) :
inline sw::Chrono::Chrono(State state) :
m_isRunning(false)
{
if (state == Lauch) {
if (state == LAUNCH) {
m_isRunning = true;
start();
}
}

inline void sw::Chronos::start()
inline void sw::Chrono::start()
{
m_start = std::chrono::steady_clock::now();
m_end = m_start;
m_tour = m_start;
m_isRunning = true;
}

inline void sw::Chronos::stop()
inline void sw::Chrono::stop()
{
m_end = std::chrono::steady_clock::now();
m_isRunning = false;
}

inline void sw::Chronos::tour()
inline void sw::Chrono::tour()
{
m_tour = std::chrono::steady_clock::now();
}

inline double sw::Chronos::getElapsedTime() const
inline double sw::Chrono::getElapsedTime() const
{
if (m_isRunning)
m_end = std::chrono::steady_clock::now();
double step = (double)std::chrono::duration_cast<std::chrono::milliseconds>(m_end - m_tour).count();
return (step / 1000);
}

inline double sw::Chronos::getTotalTime() const
inline double sw::Chrono::getTotalTime() const
{
if (m_isRunning)
m_end = std::chrono::steady_clock::now();
double step = (double)std::chrono::duration_cast<std::chrono::milliseconds>(m_end - m_start).count();
return (step / 1000);
}

inline bool sw::Chronos::isRunning() const
inline bool sw::Chrono::isRunning() const
{
return (m_isRunning);
}
32 changes: 16 additions & 16 deletions includes/utils/Shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@

namespace sw {
class SW_MODULE_EXPORT Shader {
private:
unsigned int m_id;
ShaderFile m_fragment;
ShaderFile m_vertex;
std::string m_fragmentPath;
std::string m_vertexPath;
int m_success;
char m_info[512];
bool m_loaded;

/// @brief Get location of a variable from a shader
///
/// \param name name of the uniform variable
/// \return location as int
int getUniLocation(std::string &name) const;

public:
Shader(Shader const &) = delete;
Shader(Shader &&) = delete;
Expand Down Expand Up @@ -110,6 +94,22 @@ namespace sw {

/// @brief update Opengl shader information
void update();

private:
unsigned int m_id;
ShaderFile m_fragment;
ShaderFile m_vertex;
std::string m_fragmentPath;
std::string m_vertexPath;
int m_success;
char m_info[512];
bool m_loaded;

/// @brief Get location of a variable from a shader
///
/// \param name name of the uniform variable
/// \return location as int
int getUniLocation(std::string &name) const;
}; // class Shader
} // SW

Expand Down
4 changes: 2 additions & 2 deletions sources/core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

SW_MODULE_EXPORT sw::SceneManager sw::Core::m_sceneManager{};
SW_MODULE_EXPORT sw::ResourcesManager sw::Core::m_resourceManager{};
SW_MODULE_EXPORT sw::Chronos sw::Core::m_chronos(sw::Chronos::Wait);
SW_MODULE_EXPORT sw::Chronos sw::Core::m_chronosWindow(sw::Chronos::Wait);
SW_MODULE_EXPORT sw::Chronos sw::Core::m_chronos(sw::Chronos::WAIT);
SW_MODULE_EXPORT sw::Chronos sw::Core::m_chronosWindow(sw::Chronos::WAIT);
SW_MODULE_EXPORT double sw::Core::m_frameRate{1.0/60.0};

void sw::Core::Start()
Expand Down

0 comments on commit 36e081e

Please sign in to comment.