remove Sprite class

This commit is contained in:
ohsqueezy 2023-06-08 20:04:40 -04:00
parent c16d71222d
commit 6371f9c279
13 changed files with 20 additions and 1293 deletions

View File

@ -58,9 +58,7 @@ $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
$(SB_SRC_DIR)extension.o: $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Node.o: $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Sprite.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Game.o: $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Game.o: $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Animation.o: $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
$(SB_SRC_DIR)Recorder.o: $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
$(SB_SRC_DIR)Input.o: $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)

View File

@ -56,9 +56,7 @@ $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
$(SB_SRC_DIR)extension.o : $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Node.o : $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Sprite.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Animation.o : $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
$(SB_SRC_DIR)Recorder.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
$(SB_SRC_DIR)Input.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)

View File

@ -64,9 +64,7 @@ $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
$(SB_SRC_DIR)extension.o : $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Node.o : $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Sprite.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Animation.o : $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
$(SB_SRC_DIR)Recorder.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
$(SB_SRC_DIR)Input.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)

View File

@ -56,8 +56,7 @@ $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
$(SB_SRC_DIR)extension.o : $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Node.o : $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Sprite.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp Log.hpp)
$(SB_SRC_DIR)Animation.o : $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
$(SB_SRC_DIR)Recorder.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
$(SB_SRC_DIR)Input.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)

View File

@ -64,9 +64,7 @@ $(GLEW_DIR)%.o: $(GLEW_DIR)%.c $(GLEW_DIR)%.h
$(SB_SRC_DIR)extension.o : $(addprefix $(SB_SRC_DIR),Box.hpp Segment.hpp Color.hpp filesystem.hpp Pixels.hpp)
$(SB_SRC_DIR)Node.o : $(addprefix $(SB_SRC_DIR),Game.hpp Configuration.hpp Delegate.hpp Display.hpp Input.hpp Box.hpp Audio.hpp)
$(SB_SRC_DIR)Sprite.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Box.hpp Animation.hpp Color.hpp extension.hpp Pixels.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Sprite.hpp Recorder.hpp Input.hpp Configuration.hpp \
Delegate.hpp Audio.hpp)
$(SB_SRC_DIR)Game.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Recorder.hpp Input.hpp Configuration.hpp Delegate.hpp Audio.hpp)
$(SB_SRC_DIR)Animation.o : $(addprefix $(SB_SRC_DIR),Node.hpp Timer.hpp)
$(SB_SRC_DIR)Recorder.o : $(addprefix $(SB_SRC_DIR),Node.hpp Game.hpp Configuration.hpp Delegate.hpp Animation.hpp extension.hpp)
$(SB_SRC_DIR)Input.o : $(addprefix $(SB_SRC_DIR),Node.hpp Animation.hpp Configuration.hpp Delegate.hpp)

View File

@ -79,7 +79,7 @@ void Configuration::set_defaults()
{"mp4-pixel-format", "yuv444p"}
};
config["animation"] = {
{"all-frames-frameset-name", "all"}
{"all frames frameset name", "all"}
};
config["log"] = {
{"enabled", false},

View File

@ -81,13 +81,10 @@ public:
nlohmann::json& operator[](const std::string& key);
/*!
* Get a read-only JSON object corresponding to a key in configuration.
* Get a read-only JSON object reference to the specified keys, each given as a separate argument. If no keys are given,
* a reference to the entire configuration JSON object is returned.
*
* The JSON object's value can be used directly if it can be implictly type-cast. Otherwise, use the JSON object's
* get method with a template parameter. See https://nlohmann.github.io/json/api/basic_json/ for further information.
*
* @param key Top level key corresponding to a section of the SPACEBOX configuration JSON
* @return Read-only JSON object
* @return read-only JSON object reference
*/
const nlohmann::json& operator[](const std::string& key) const;
@ -114,8 +111,8 @@ public:
* @param keys hierarchy of keys used to look up a specific value in the config JSON
* @return read-only reference to value specified by keys
*/
template<typename ReturnType = nlohmann::json, typename... Key>
const ReturnType& operator()(const Key&... keys) const
template<typename... Key>
const nlohmann::json& operator()(const Key&... keys) const
{
return access(config, keys...);
}
@ -212,7 +209,7 @@ namespace std::filesystem
namespace std
{
/*!
* Add the entire JSON when the stream operator is called.
* Stream the entire JSON when the stream operator is called.
*
* @param out Output stream
* @param configuration Configuration object being output to the stream
@ -220,3 +217,10 @@ namespace std
*/
std::ostream& operator<<(std::ostream& out, const Configuration& configuration);
}
/* Add Configuration class to the sb namespace. This should be the default location, but Configuration is left in the global namespace
* for backward compatibility. */
namespace sb
{
using ::Configuration;
}

View File

@ -46,7 +46,6 @@
#include "Configuration.hpp"
#include "Delegate.hpp"
#include "Recorder.hpp"
#include "Sprite.hpp"
#include "Audio.hpp"
#include "Log.hpp"
#include "filesystem.hpp"

View File

@ -22,8 +22,6 @@
#include "extension.hpp"
#include "math.hpp"
class Sprite;
struct Pixels
{
@ -39,8 +37,6 @@ struct Pixels
Pixels(SDL_Renderer*, SDL_Texture* texture, const Box&);
Pixels(SDL_Renderer*, SDL_Texture* texture);
Pixels(SDL_Renderer*);
Pixels(Sprite&);
Pixels(Sprite&, const Box&);
int get_bytes_per_row() const;
Color get(int x, int y);
void set(const SDL_Color&, int x, int y);

View File

@ -26,6 +26,7 @@
#include "json/json.hpp"
#include "filesystem.hpp"
#include "Node.hpp"
#include "Configuration.hpp"
#include "Animation.hpp"
#include "Log.hpp"

View File

@ -18,7 +18,6 @@
#include "glm/vec2.hpp"
class Box;
class Sprite;
class Segment
{
@ -33,7 +32,6 @@ public:
Segment();
Segment(const glm::vec2&);
Segment(const Box&, const Box&);
Segment(const Sprite&, const Sprite&);
glm::vec2 start() const;
void start(const glm::vec2&);
glm::vec2 end() const;

File diff suppressed because it is too large Load Diff

View File

@ -1,213 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <utility>
#include <list>
#include <stdexcept>
#include "SDL.h"
#include "SDL_image.h"
#include "Node.hpp"
#include "Box.hpp"
#include "Animation.hpp"
#include "Color.hpp"
#include "Log.hpp"
class Game;
class Sprite : public Node
{
public:
class Frameset;
class Child;
std::vector<SDL_Texture*> frames;
std::vector<fs::path> frame_paths;
std::vector<Box> boxes = {{{0, 0}, {0, 0}}};
Animation frame_animation = Animation(&Sprite::advance_frame, this),
blink_animation = Animation(&Sprite::toggle_hidden, this, 500),
wipe_animation = Animation(&Sprite::advance_wipe_frame, this, 40),
toggle_hidden_animation = Animation(&Sprite::toggle_hidden, this);
glm::vec2 step = {0, 0}, child_relative_position;
float scale = 1.0f, bottom_save;
std::string scale_quality = "nearest";
std::uint8_t alpha_mod = 255;
SDL_Color color_mod = {255, 255, 255, 255};
std::map<std::string, Frameset> framesets;
std::string current_frameset_name;
glm::bvec2 wrap = {false, false};
int texture_access = SDL_TEXTUREACCESS_TARGET, wipe_index = 0, wipe_increment = -1;
Box wrap_frame, unscaled_subsection;
bool leave_memory_allocated = false, hidden = false, draw_children_on_frame = true, draw_floating = true;
std::vector<std::vector<Box>> wipe_blinds;
SDL_Rect subsection_int_rect, subsection_destination;
std::list<Child> children = {};
Sprite();
Sprite(Node*);
Sprite(Node*, std::string);
virtual void reset();
virtual void associate(std::string);
virtual void load();
void load_file(fs::path);
void add_frames(SDL_Texture*);
void add_frames(const std::vector<SDL_Texture*>&);
const std::vector<SDL_Texture*>& get_frames() const;
Frameset& get_all_frames_frameset();
Frameset& add_frameset(std::string);
virtual Frameset& set_frameset(std::string);
Frameset& get_current_frameset();
void set_frame_length(float);
const Frameset& get_current_frameset() const;
SDL_Texture* get_current_frame() const;
const Box& get_box(int = 0) const;
const std::vector<Box>& get_boxes() const;
void add_box(glm::vec2, bool = false);
void update_size(bool = false);
void set_scale(float);
void set_scale_quality(const std::string&);
float get_scale() const;
bool is_loaded() const;
virtual void unload();
void advance_frame();
void hide();
void unhide();
void toggle_hidden();
bool is_hidden() const;
void set_step(glm::vec2);
void set_alpha_mod(Uint8);
Uint8 get_alpha_mod() const;
void set_color_mod(const SDL_Color&);
const SDL_Color& get_color_mod() const;
float get_w() const;
float get_h() const;
glm::vec2 get_size() const;
float get_top(int = 0) const;
float get_right(int = 0) const;
float get_bottom(int = 0) const;
float get_left(int = 0) const;
float get_center_x(int = 0) const;
float get_center_y(int = 0) const;
glm::vec2 get_nw(int = 0) const;
glm::vec2 get_north(int = 0) const;
glm::vec2 get_ne(int = 0) const;
glm::vec2 get_east(int = 0) const;
glm::vec2 get_se(int = 0) const;
glm::vec2 get_south(int = 0) const;
glm::vec2 get_sw(int = 0) const;
glm::vec2 get_west(int = 0) const;
glm::vec2 get_center(int = 0) const;
void set_top(float);
void set_right(float);
void set_bottom(float);
void set_left(float);
void set_center_x(float);
void set_center_y(float);
void set_nw(const glm::vec2&);
void set_north(const glm::vec2&);
void set_ne(const glm::vec2&);
void set_se(const glm::vec2&);
void set_south(const glm::vec2&);
void set_sw(const glm::vec2&);
void set_west(const glm::vec2&);
void set_center(const glm::vec2&);
void add_wrap(bool, bool);
void add_wrap(bool, bool, Box);
void add_hue_shift_frames(int);
virtual glm::vec2 move(const glm::vec2&);
virtual glm::vec2 move_weighted(const glm::vec2&);
bool collide(const glm::vec2&, bool = false) const;
bool collide(const Segment&, glm::vec2* = NULL, bool = false) const;
bool collide(const Segment&, glm::vec2&, bool = false) const;
bool collide(const Box&, bool = false, Box* = NULL, bool = false, SDL_Texture* = NULL) const;
bool collide(const Box&, Box&, bool = false, bool = false) const;
bool collide(const Sprite&, bool = false, Box* = NULL, bool = false, bool = false) const;
bool collide(const Sprite&, Box&, bool = false, bool = false, bool = false) const;
void wipe(float = 0.0f);
void advance_wipe_frame();
const std::vector<Box>& get_current_wipe_blinds() const;
void reverse_wipe_direction();
Sprite& insert_child(std::string, std::list<Child>::iterator);
Sprite& insert_child(std::string, std::string);
Sprite& insert_child(std::string, int);
Sprite& insert_child(std::string);
Sprite& get_child(std::string);
bool has_child(std::string) const;
void remove_child(std::string);
void set_draw_children_on_frame(bool);
virtual void update(float timestamp, const std::vector<Box>&);
virtual void update(float timestamp);
void render_subsection(SDL_Renderer*, SDL_Texture*, const Box&, const Box&);
void set_to_leave_memory_allocated();
void set_to_deallocate_memory();
virtual std::string class_name() const { return "Sprite"; }
};
class Sprite::Child
{
public:
std::string name;
Sprite sprite;
Child(std::string name, Node* parent) : name(name), sprite(Sprite(parent)) {}
inline bool operator==(const std::string& name) const
{
return this->name == name;
}
};
class Sprite::Frameset
{
public:
Sprite* sprite;
std::vector<int> order;
int order_index = 0;
float frame_length = 0;
bool reversed = false;
glm::vec2 size = {0, 0};
Frameset();
Frameset(Sprite*);
void add_frame_indicies(int);
void set_frame_length(float);
float get_frame_length() const;
void reset();
void clear();
int get_order_index() const;
void set_order_index(int);
int get_current_frame_index() const;
glm::vec2 measure() const;
void set_size();
void set_size(const glm::vec2&);
const glm::vec2& get_size() const;
void step();
void increment_index();
void increment_index(int);
int get_frame_count() const;
void reverse();
template <typename N>
void add_frame_indicies(const std::vector<N>& indicies)
{
for (const N& index : indicies)
{
add_frame_indicies(index);
}
}
};
#include "Pixels.hpp"
#include "extension.hpp"