Port Sheet and SptAnim to SMART_CTOR
 New Logger
This commit is contained in:
2024-06-10 19:50:12 +02:00
parent 93f0ed44e8
commit ddf06eb18e
10 changed files with 140 additions and 129 deletions

View File

@ -1,50 +1,49 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdarg.h>
#include <unistd.h>
#include <string>
/// @brief Log Class
class Log {
public:
/// @brief Constructor
Log();
/// @brief Deconstructor
~Log();
/// @brief Init the Logger
/// @param filename Filename[_data_time.log]
void Init(const char *filename);
/// @brief Write a String to the File
/// @param debug_text string
void Write(std::string debug_text);
/// @brief Get the Date
/// @return Date as string fmt[data_time]
std::string logDate(void);
/// @brief Format a string like sprintf
/// @param fmt_str the string wich defines the fmt
/// @param ... Additional Data
/// @return Formatted String
std::string format(const std::string &fmt_str, ...);
private:
/// \param filename the name of the logfile
std::string filename;
};
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <fstream>
#include <renderd7/smart_ctor.hpp>
#include <string>
#include <vector>
namespace RenderD7 {
/// @brief Logger base Class
class LoggerBase {
public:
/// @brief Constructor
LoggerBase() = default;
/// @brief Deconstructor
~LoggerBase();
RD7_SMART_CTOR(LoggerBase)
/// @brief Init the Logger
/// @param filename name[_date_time.txt]
void Init(const std::string& name, bool fileless = false);
/// @brief Write a String to the File
/// @param debug_text string
void Write(const std::string& debug_text);
private:
/// \param filename the name of the logfile
std::string filename;
std::string log_path;
std::ofstream _log;
std::vector<std::string> lines;
};
} // namespace RenderD7

View File

@ -21,6 +21,7 @@
#include <citro2d.h>
#include <citro3d.h>
#include <renderd7/smart_ctor.hpp>
#include <string>
namespace RenderD7 {
@ -33,6 +34,7 @@ class Sheet {
~Sheet() {
if (spritesheet) Free();
}
RD7_SMART_CTOR(Sheet);
/// @brief Load A Spritesheet File
/// @param path Path to the t3x
/// @return Result Code

View File

@ -37,7 +37,7 @@ class Sprite {
/// \brief Load a Sprite From SpriteSheet
/// \param sheet the Sheet to load from.(RenderD7::Sheet)
/// \param index the number of the Sprite in the Sheet
void FromSheet(RenderD7::Sheet *sheet, size_t index);
void FromSheet(RenderD7::Sheet::Ref sheet, size_t index);
/// \brief Load a Sprite From SpriteSheet
/// \param img the Image to load from.(RenderD7::Image)
void FromImage(RenderD7::Image::Ref img);

View File

@ -23,6 +23,7 @@
#include <renderd7/Sheet.hpp>
#include <renderd7/Sprite.hpp>
#include <renderd7/smart_ctor.hpp>
namespace RenderD7 {
/// @brief SpriteSheetAnimation Class
@ -32,13 +33,14 @@ class SpriteSheetAnimation : public RenderD7::Sprite {
SpriteSheetAnimation();
/// @brief Deconstructor
~SpriteSheetAnimation();
RD7_SMART_CTOR(SpriteSheetAnimation);
/// @brief Setup an Animation
/// @param sheet Input Spritesheet
/// @param imagecount Count of Images
/// @param startimage Where to Start the Loop
/// @param frame_begin Current Time (Should be 0)
/// @param frame_finish Time Length
void Setup(RenderD7::Sheet *sheet, size_t imagecount, size_t startimage,
void Setup(RenderD7::Sheet::Ref sheet, size_t imagecount, size_t startimage,
float frame_begin, float frame_finish);
/// @brief Play the Animation
/// @param timespeed Speed of the animation
@ -52,7 +54,7 @@ class SpriteSheetAnimation : public RenderD7::Sprite {
/// @param D_totaltime Current Time
float D_totaltime;
/// @param sheet The Sheet of Images
RenderD7::Sheet *sheet;
RenderD7::Sheet::Ref sheet;
/// @param time Total Time from frame_finish
float time;
};

View File

@ -37,6 +37,7 @@
#include <renderd7/Color.hpp>
#include <renderd7/FunctionTrace.hpp>
#include <renderd7/Hardware.hpp>
#include <renderd7/Log2.hpp>
#include <renderd7/Memory.hpp>
#include <renderd7/Overlays.hpp>
#include <renderd7/Ovl.hpp>
@ -69,6 +70,8 @@ extern bool rd7_enable_scene_system;
namespace RenderD7 {
// Reference to the New Renderer
R2Base::Ref R2();
// Reference to Global Logger
LoggerBase::Ref Logger();
/// @brief Get Deltatime
/// @return Deltatime
float GetDeltaTime();