diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-07 13:30:32 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-07 13:30:32 +0100 |
commit | 5356fc4701eeccc5f5c85df2890f60f0cdf99a4b (patch) | |
tree | d9a565117954d0c6bc74ba358e3540b5a8fbda11 | |
parent | c981a77fd21c9220587ca3889fb99a05dcc1f6c3 (diff) | |
download | YAGE-5356fc4701eeccc5f5c85df2890f60f0cdf99a4b.tar.gz YAGE-5356fc4701eeccc5f5c85df2890f60f0cdf99a4b.zip |
Removing rapidjson dependency
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | yage/core/spritesheet.cpp | 79 | ||||
-rw-r--r-- | yage/core/spritesheet.h | 69 | ||||
-rw-r--r-- | yage/core/texturecache.h | 1 | ||||
-rw-r--r-- | yage/yage.h | 1 |
5 files changed, 1 insertions, 152 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d519358b..695f64ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,8 +51,7 @@ add_library(yage target_include_directories(yage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/yage - ${EXTERNAL_DIR}/glm - ${EXTERNAL_DIR}/rapidjson/include) + ${EXTERNAL_DIR}/glm) target_link_libraries(yage glfw diff --git a/yage/core/spritesheet.cpp b/yage/core/spritesheet.cpp deleted file mode 100644 index f3f99619..00000000 --- a/yage/core/spritesheet.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: spritesheet.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -/// @file - -#include "spritesheet.h" - -#include <rapidjson/document.h> -#include <yage/core/imageloader.h> - -#include <cassert> -#include <fstream> -#include <sstream> -#include <stdexcept> - -#include <iostream> - -using rapidjson::Document; -using yage::details::Coordinate; -using yage::details::SpriteMap; - -using std::cout; - -namespace yage -{ - -SpriteSheet::SpriteSheet(std::string pngFileName, std::string jsonFileName) -{ - int jsonWidth, jsonHeight; - - fileLocations_ = - parseJson(jsonWidth, jsonHeight, fileContent(jsonFileName)); - texture_ = ImageLoader::loadPng(pngFileName); - if (texture_.width != jsonWidth) { - throw std::runtime_error("JSON width does not match texture width"); - } - if (texture_.height != jsonHeight) { - throw std::runtime_error("JSON height does not match texture height"); - } -} - -std::string SpriteSheet::fileContent(std::string jsonFileName) const -{ - std::ifstream inputFile(jsonFileName); - - std::stringstream stream; - stream << inputFile.rdbuf(); - - return stream.str(); -} - -SpriteMap SpriteSheet::parseJson(int &width, int &height, - std::string jsonContent) const -{ - SpriteMap spriteMap; - Document jsonAtlas; - jsonAtlas.Parse(jsonContent.c_str()); - width = jsonAtlas["width"].GetInt(); - height = jsonAtlas["height"].GetInt(); - - Coordinate coord; - for(auto &texture : jsonAtlas["sprites"].GetObject()) { - auto texVal = texture.value.GetObject(); - coord.x = texVal["x"].GetInt(); - coord.y = texVal["y"].GetInt(); - coord.width = texVal["width"].GetInt(); - coord.height = texVal["height"].GetInt(); - spriteMap[texture.name.GetString()] = coord; - } - - return spriteMap; -} - -} // namespace yage diff --git a/yage/core/spritesheet.h b/yage/core/spritesheet.h deleted file mode 100644 index ea1db44b..00000000 --- a/yage/core/spritesheet.h +++ /dev/null @@ -1,69 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: spritesheet.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -/// @file - -#ifndef YAGE_SPRITESHEET_H -#define YAGE_SPRITESHEET_H - -/** @todo think of removing this, by, for example, using a pointer - * This could be more efficient when copying the texture out of the - * spritesheet. - */ -#include "../data/texture.h" -#include "../util/noncopyable.h" - -#include <rapidjson/reader.h> - -#include <map> -#include <string> - -namespace yage -{ - -namespace details -{ - -struct Coordinate { - int x; - int y; - int width; - int height; - - Coordinate() = default; - - Coordinate(int x_i, int y_i, int width_i, int height_i) - : x(x_i), y(y_i), width(width_i), height(height_i) - { - } -}; - -typedef std::map<std::string, details::Coordinate> SpriteMap; - -} // namespace details - -class SpriteSheet : public NonCopyable -{ -public: - SpriteSheet() = default; - SpriteSheet(std::string pngFileName, std::string jsonFileName); - - void sprite(std::string spriteName) const; - std::string fileContent(std::string jsonFileName) const; - -private: - Texture texture_; - details::SpriteMap fileLocations_; - - details::SpriteMap parseJson(int &width, int &height, - std::string jsonContent) const; -}; - -} // namespace yage - -#endif diff --git a/yage/core/texturecache.h b/yage/core/texturecache.h index fbedab9d..8b34d39e 100644 --- a/yage/core/texturecache.h +++ b/yage/core/texturecache.h @@ -25,7 +25,6 @@ public: TextureCache() = default; Texture getTexture(const std::string &texture_path, int x = 1, int y = 1); - Texture getTextureFromSpriteSheet(); }; } // namespace yage diff --git a/yage/yage.h b/yage/yage.h index 038acbec..465ecfde 100644 --- a/yage/yage.h +++ b/yage/yage.h @@ -17,7 +17,6 @@ #include "core/iomanager.h" #include "core/logger.h" #include "core/resourcemanager.h" -#include "core/spritesheet.h" #include "core/window.h" /** |