From 7f136b65bba864dc06b4b460302b77e55e0a21ad Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 14:06:38 +0900 Subject: [PATCH 01/20] =?UTF-8?q?=5Fuint32=5Ft=E3=81=AE=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/common/Animator/xorshift32.h | 6 ++---- samples/DXLibrary/basic/sssample.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/xorshift32.h b/samples/DXLibrary/basic/SSPlayer/common/Animator/xorshift32.h index 53af414..d2467fe 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/xorshift32.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/xorshift32.h @@ -2,11 +2,9 @@ #ifndef __XORSHIFT32__ #define __XORSHIFT32__ -#ifdef WIN32 - #ifndef uint32_t - typedef unsigned int _uint32_t; - #endif +#ifndef uint32_t + typedef unsigned int _uint32_t; #else typedef uint32_t _uint32_t; #endif diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index 3df2656..50e58f6 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -23,7 +23,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine { //DXライブラリの初期化 ChangeWindowMode(true); //ウインドウモード - SetGraphMode(1280, 720, GetColorBitDepth() ); + SetGraphMode(800, 600, GetColorBitDepth() ); if (DxLib_Init() == -1) // DXライブラリ初期化処理 { return -1; // エラーが起きたら直ちに終了 @@ -88,7 +88,7 @@ void init( void ) ssplayer->play("character_template_3head/stance"); // アニメーション名を指定(ssae名/アニメーション名も可能、詳しくは後述) //表示位置を設定 - ssplayer->setPosition(1280/2, 300); + ssplayer->setPosition(800/2, 100); //スケール設定 ssplayer->setScale(0.5f, 0.5f); //回転を設定 From 1a8e9ac36d35d0ef72daccdd80788d2960ee4321 Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 14:51:03 +0900 Subject: [PATCH 02/20] =?UTF-8?q?CellCache=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 185 +----------------- .../common/SS5PlayerLibs/SS5CellCache.cpp | 178 +++++++++++++++++ .../common/SS5PlayerLibs/SS5CellCache.h | 62 ++++++ 3 files changed, 241 insertions(+), 184 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 836597d..3ed5f7e 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -6,6 +6,7 @@ #include "common/SS5PlayerLibs/SS5PlayerTypes.h" #include "common/SS5PlayerLibs/SS5PlayerToPointer.h" #include "common/SS5PlayerLibs/SS5PlayerDataArrayReader.h" +#include "common/SS5PlayerLibs/SS5CellCache.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" @@ -101,190 +102,6 @@ unsigned int getRandomSeed() } -/** - * CellRef - */ -struct CellRef -{ - const Cell* cell; - TextuerData texture; - SSRect rect; - std::string texname; -}; - - -/** - * CellCache - */ -class CellCache -{ -public: - CellCache() - { - } - ~CellCache() - { - releseReference(); - } - - static CellCache* create(const ProjectData* data, const std::string& imageBaseDir) - { - CellCache* obj = new CellCache(); - if (obj) - { - obj->init(data, imageBaseDir); - } - return obj; - } - - CellRef* getReference(int index) - { - if (index < 0 || index >= (int)_refs.size()) - { - SSLOGERROR("Index out of range > %d", index); - SS_ASSERT(0); - } - CellRef* ref = _refs.at(index); - return ref; - } - - //指定した名前のセルの参照テクスチャを変更する - bool setCellRefTexture(const ProjectData* data, const char* cellName, long texture) - { - bool rc = false; - - ToPointer ptr(data); - const Cell* cells = static_cast(ptr.toCell(data)); - - //名前からインデックスの取得 - int cellindex = -1; - for (int i = 0; i < data->numCells; i++) - { - const Cell* cell = &cells[i]; - const CellMap* cellMap = static_cast(ptr.toCellMap(cell)); - const char* name = ptr.toString(cellMap->name); - if (strcmp(cellName, name) == 0) - { - CellRef* ref = getReference(i); - ref->texture.handle = texture; - rc = true; - } - } - - return(rc); - } - - //指定したデータのテクスチャを破棄する - bool releseTexture(const ProjectData* data) - { - bool rc = false; - - for (int i = 0; i < data->numCells; i++) - { - CellRef* ref = _refs.at(i); - if (ref->texture.handle != -1 ) - { - SSTextureRelese(ref->texture.handle); - ref->texture.handle = -1; - rc = true; - } - } - return(rc); - } - -protected: - void init(const ProjectData* data, const std::string& imageBaseDir) - { - - SS_ASSERT2(data != NULL, "Invalid data"); - - _textures.clear(); - _refs.clear(); - _texname.clear(); - - ToPointer ptr(data); - const Cell* cells = ptr.toCell(data); - - for (int i = 0; i < data->numCells; i++) - { - const Cell* cell = &cells[i]; - const CellMap* cellMap = ptr.toCellMap(cell); - - if (cellMap->index >= (int)_textures.size()) - { - const char* imagePath = ptr.toString(cellMap->imagePath); - addTexture(imagePath, imageBaseDir, (SsTexWrapMode::_enum)cellMap->wrapmode, (SsTexFilterMode::_enum)cellMap->filtermode); - } - - //セル情報だけ入れておく - //テクスチャの読み込みはゲーム側に任せる - CellRef* ref = new CellRef(); - ref->cell = cell; - ref->texture = _textures.at(cellMap->index); - ref->texname = _texname.at(cellMap->index); - ref->rect = SSRect(cell->x, cell->y, cell->width, cell->height); - _refs.push_back(ref); - } - - } - //キャッシュの削除 - void releseReference(void) - { - for (int i = 0; i < _refs.size(); i++) - { - CellRef* ref = _refs.at(i); - if (ref->texture.handle != -1 ) - { - SSTextureRelese(ref->texture.handle); - ref->texture.handle = -1; - } - delete ref; - } - _refs.clear(); - } - - void addTexture(const std::string& imagePath, const std::string& imageBaseDir, SsTexWrapMode::_enum wrapmode, SsTexFilterMode::_enum filtermode) - { - std::string path = ""; - - if (isAbsolutePath(imagePath)) - { - // 絶対パスのときはそのまま扱う - path = imagePath; - } - else - { - // 相対パスのときはimageBaseDirを付与する - path.append(imageBaseDir); - size_t pathLen = path.length(); - if (pathLen && path.at(pathLen-1) != '/' && path.at(pathLen-1) != '\\') - { - path.append("/"); - } - path.append(imagePath); - } - - //テクスチャの読み込み - long tex = SSTextureLoad(path.c_str(), wrapmode, filtermode); - SSLOG("load: %s", path.c_str()); - TextuerData texdata; - texdata.handle = tex; - int w; - int h; - SSGetTextureSize(texdata.handle, w, h); - texdata.size_w = w; - texdata.size_h = h; - - _textures.push_back(texdata); - _texname.push_back(path); - - } - -protected: - std::vector _texname; - std::vector _textures; - std::vector _refs; -}; /** diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp new file mode 100644 index 0000000..4496fd8 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp @@ -0,0 +1,178 @@ +#include "SS5CellCache.h" +#include "SS5PlayerToPointer.h" +#include "SS5PlayerPlatform.h" +#include "common/Loader/sstypes.h" + +namespace ss{ + + +CellCache* CellCache::create(const ProjectData* data, const std::string& imageBaseDir) +{ + CellCache* obj = new CellCache(); + if (obj){ + obj->init(data, imageBaseDir); + } + return obj; +} + + +CellCache::CellCache() +{ +} + +CellCache::~CellCache() +{ + releseReference(); +} + + + +CellRef* CellCache::getReference(int index) +{ + if (index < 0 || index >= (int)_refs.size()) + { + SSLOGERROR("Index out of range > %d", index); + SS_ASSERT(0); + } + CellRef* ref = _refs.at(index); + return ref; +} + +//指定した名前のセルの参照テクスチャを変更する +bool CellCache::setCellRefTexture(const ProjectData* data, const char* cellName, long texture) +{ + bool rc = false; + + ToPointer ptr(data); + const Cell* cells = static_cast(ptr.toCell(data)); + + //名前からインデックスの取得 + int cellindex = -1; + for (int i = 0; i < data->numCells; i++) + { + const Cell* cell = &cells[i]; + const CellMap* cellMap = static_cast(ptr.toCellMap(cell)); + const char* name = ptr.toString(cellMap->name); + if (strcmp(cellName, name) == 0) + { + CellRef* ref = getReference(i); + ref->texture.handle = texture; + rc = true; + } + } + + return(rc); +} + +//指定したデータのテクスチャを破棄する +bool CellCache::releseTexture(const ProjectData* data) +{ + bool rc = false; + + for (int i = 0; i < data->numCells; i++) + { + CellRef* ref = _refs.at(i); + if (ref->texture.handle != -1) + { + SSTextureRelese(ref->texture.handle); + ref->texture.handle = -1; + rc = true; + } + } + return(rc); +} + + +void CellCache::init(const ProjectData* data, const std::string& imageBaseDir) +{ + + SS_ASSERT2(data != NULL, "Invalid data"); + + _textures.clear(); + _refs.clear(); + _texname.clear(); + + ToPointer ptr(data); + const Cell* cells = ptr.toCell(data); + + for (int i = 0; i < data->numCells; i++) + { + const Cell* cell = &cells[i]; + const CellMap* cellMap = ptr.toCellMap(cell); + + if (cellMap->index >= (int)_textures.size()) + { + const char* imagePath = ptr.toString(cellMap->imagePath); + addTexture(imagePath, imageBaseDir, (SsTexWrapMode::_enum)cellMap->wrapmode, (SsTexFilterMode::_enum)cellMap->filtermode); + } + + //セル情報だけ入れておく + //テクスチャの読み込みはゲーム側に任せる + CellRef* ref = new CellRef(); + ref->cell = cell; + ref->texture = _textures.at(cellMap->index); + ref->texname = _texname.at(cellMap->index); + ref->rect = SSRect(cell->x, cell->y, cell->width, cell->height); + _refs.push_back(ref); + } + +} + + +//キャッシュの削除 +void CellCache::releseReference(void) +{ + for (int i = 0; i < _refs.size(); i++) + { + CellRef* ref = _refs.at(i); + if (ref->texture.handle != -1) + { + SSTextureRelese(ref->texture.handle); + ref->texture.handle = -1; + } + delete ref; + } + _refs.clear(); +} + +void CellCache::addTexture(const std::string& imagePath, const std::string& imageBaseDir, SsTexWrapMode::_enum wrapmode, SsTexFilterMode::_enum filtermode) +{ + std::string path = ""; + + if (isAbsolutePath(imagePath)) + { + // 絶対パスのときはそのまま扱う + path = imagePath; + } + else + { + // 相対パスのときはimageBaseDirを付与する + path.append(imageBaseDir); + size_t pathLen = path.length(); + if (pathLen && path.at(pathLen - 1) != '/' && path.at(pathLen - 1) != '\\') + { + path.append("/"); + } + path.append(imagePath); + } + + //テクスチャの読み込み + long tex = SSTextureLoad(path.c_str(), wrapmode, filtermode); + SSLOG("load: %s", path.c_str()); + TextuerData texdata; + texdata.handle = tex; + int w; + int h; + SSGetTextureSize(texdata.handle, w, h); + texdata.size_w = w; + texdata.size_h = h; + + _textures.push_back(texdata); + _texname.push_back(path); + +} + + + + +} //namespace ss diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h new file mode 100644 index 0000000..cd8f8e5 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h @@ -0,0 +1,62 @@ +#pragma once +#include +#include +#include "SS5PlayerTypes.h" +#include "common/Loader/sstypes.h" + + +namespace ss{ +class Cell; +struct ProjectData; + + +/** + * CellRef + */ +struct CellRef{ + const Cell* cell; + TextuerData texture; + SSRect rect; + std::string texname; +}; + + +/** + * CellCache + */ +class CellCache{ +public: + CellCache(); + ~CellCache(); + + static CellCache* create(const ProjectData* data, const std::string& imageBaseDir); + + CellRef* getReference(int index); + + //指定した名前のセルの参照テクスチャを変更する + bool setCellRefTexture(const ProjectData* data, const char* cellName, long texture); + + + //指定したデータのテクスチャを破棄する + bool releseTexture(const ProjectData* data); + +private: + void init(const ProjectData* data, const std::string& imageBaseDir); + + //キャッシュの削除 + void releseReference(void); + + void addTexture(const std::string& imagePath, const std::string& imageBaseDir, SsTexWrapMode::_enum wrapmode, SsTexFilterMode::_enum filtermode); + +protected: + std::vector _texname; + std::vector _textures; + std::vector _refs; +}; + + + + +} //namespace ss; + + From e5f137dfd6e531b10446154e98752141e46e62ff Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 15:09:46 +0900 Subject: [PATCH 03/20] =?UTF-8?q?AnimCache=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 131 +----------------- .../common/SS5PlayerLibs/SS5AnimCache.cpp | 115 +++++++++++++++ .../common/SS5PlayerLibs/SS5AnimCache.h | 58 ++++++++ .../common/SS5PlayerLibs/SS5CellCache.h | 4 +- 4 files changed, 176 insertions(+), 132 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 3ed5f7e..cf6d643 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -7,6 +7,7 @@ #include "common/SS5PlayerLibs/SS5PlayerToPointer.h" #include "common/SS5PlayerLibs/SS5PlayerDataArrayReader.h" #include "common/SS5PlayerLibs/SS5CellCache.h" +#include "common/SS5PlayerLibs/SS5AnimCache.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" @@ -580,136 +581,6 @@ class EffectCache -/** - * AnimeRef - */ -struct AnimeRef -{ - std::string packName; - std::string animeName; - const AnimationData* animationData; - const AnimePackData* animePackData; -}; - - -/** - * AnimeCache - */ -class AnimeCache -{ -public: - AnimeCache() - { - } - ~AnimeCache() - { - releseReference(); - } - static AnimeCache* create(const ProjectData* data) - { - AnimeCache* obj = new AnimeCache(); - if (obj) - { - obj->init(data); - } - return obj; - } - - /** - * packNameとanimeNameを指定してAnimeRefを得る - */ - AnimeRef* getReference(const std::string& packName, const std::string& animeName) - { - std::string key = toPackAnimeKey(packName, animeName); - AnimeRef* ref = _dic.at(key); - return ref; - } - - /** - * animeNameのみ指定してAnimeRefを得る - */ - AnimeRef* getReference(const std::string& animeName) - { - AnimeRef* ref = _dic.at(animeName); - return ref; - } - - void dump() - { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - SSLOG("%s", (*it).second); - ++it; - } - } - -protected: - void init(const ProjectData* data) - { - SS_ASSERT2(data != NULL, "Invalid data"); - - ToPointer ptr(data); - const AnimePackData* animePacks = ptr.toAnimePackData(data); - - for (int packIndex = 0; packIndex < data->numAnimePacks; packIndex++) - { - const AnimePackData* pack = &animePacks[packIndex]; - const AnimationData* animations = ptr.toAnimationData(pack); - const char* packName = ptr.toString(pack->name); - - for (int animeIndex = 0; animeIndex < pack->numAnimations; animeIndex++) - { - const AnimationData* anime = &animations[animeIndex]; - const char* animeName = ptr.toString(anime->name); - - AnimeRef* ref = new AnimeRef(); - ref->packName = packName; - ref->animeName = animeName; - ref->animationData = anime; - ref->animePackData = pack; - - // packName + animeNameでの登録 - std::string key = toPackAnimeKey(packName, animeName); - SSLOG("anime key: %s", key.c_str()); - _dic.insert(std::map::value_type(key, ref)); - - // animeNameのみでの登録 -// _dic.insert(std::map::value_type(animeName, ref)); - - } - } - } - - static std::string toPackAnimeKey(const std::string& packName, const std::string& animeName) - { - return Format("%s/%s", packName.c_str(), animeName.c_str()); - } - - //キャッシュの削除 - void releseReference(void) - { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - AnimeRef* ref = it->second; - if (ref) - { - delete ref; - it->second = 0; - } - it++; - } - _dic.clear(); - } - -protected: - std::map _dic; -}; - - - - /** * ResourceSet diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp new file mode 100644 index 0000000..f64a798 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp @@ -0,0 +1,115 @@ +#include "SS5AnimCache.h" +#include "SS5Player.h" +#include "SS5PlayerToPointer.h" + +namespace ss{ + + +AnimeCache* AnimeCache::create(const ProjectData* data) +{ + AnimeCache* obj = new AnimeCache(); + if (obj) + { + obj->init(data); + } + return obj; +} + + +AnimeCache::AnimeCache() +{ +} + +AnimeCache::~AnimeCache() +{ + releseReference(); +} + +//packNameとanimeNameを指定してAnimeRefを得る +AnimeRef* AnimeCache::getReference(const std::string& packName, const std::string& animeName) +{ + std::string key = toPackAnimeKey(packName, animeName); + AnimeRef* ref = _dic.at(key); + return ref; +} + + +//animeNameのみ指定してAnimeRefを得る +AnimeRef* AnimeCache::getReference(const std::string& animeName) +{ + AnimeRef* ref = _dic.at(animeName); + return ref; +} + +void AnimeCache::dump() +{ + std::map::iterator it = _dic.begin(); + while (it != _dic.end()) + { + SSLOG("%s", (*it).second); + ++it; + } +} + + +void AnimeCache::init(const ProjectData* data) +{ + SS_ASSERT2(data != NULL, "Invalid data"); + + ToPointer ptr(data); + const AnimePackData* animePacks = ptr.toAnimePackData(data); + + for (int packIndex = 0; packIndex < data->numAnimePacks; packIndex++) + { + const AnimePackData* pack = &animePacks[packIndex]; + const AnimationData* animations = ptr.toAnimationData(pack); + const char* packName = ptr.toString(pack->name); + + for (int animeIndex = 0; animeIndex < pack->numAnimations; animeIndex++) + { + const AnimationData* anime = &animations[animeIndex]; + const char* animeName = ptr.toString(anime->name); + + AnimeRef* ref = new AnimeRef(); + ref->packName = packName; + ref->animeName = animeName; + ref->animationData = anime; + ref->animePackData = pack; + + // packName + animeNameでの登録 + std::string key = toPackAnimeKey(packName, animeName); + SSLOG("anime key: %s", key.c_str()); + _dic.insert(std::map::value_type(key, ref)); + + // animeNameのみでの登録 + // _dic.insert(std::map::value_type(animeName, ref)); + + } + } +} + +std::string AnimeCache::toPackAnimeKey(const std::string& packName, const std::string& animeName) +{ + return packName + "/" + animeName; //return Format("%s/%s", packName.c_str(), animeName.c_str()); +} + +//キャッシュの削除 +void AnimeCache::releseReference(void) +{ + std::map::iterator it = _dic.begin(); + while (it != _dic.end()) + { + AnimeRef* ref = it->second; + if (ref) + { + delete ref; + it->second = 0; + } + it++; + } + _dic.clear(); +} + + +} //namespace ss; + diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h new file mode 100644 index 0000000..bd67e92 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h @@ -0,0 +1,58 @@ +#pragma once +#include +#include + +namespace ss{ +struct AnimationData; +struct AnimePackData; +struct ProjectData; + +/** + * AnimeRef + */ +struct AnimeRef{ + std::string packName; + std::string animeName; + const AnimationData* animationData; + const AnimePackData* animePackData; +}; + + +/** + * AnimeCache + */ +class AnimeCache{ +public: + AnimeCache(); + ~AnimeCache(); + static AnimeCache* create(const ProjectData* data); + + /** + * packNameとanimeNameを指定してAnimeRefを得る + */ + AnimeRef* getReference(const std::string& packName, const std::string& animeName); + + /** + * animeNameのみ指定してAnimeRefを得る + */ + AnimeRef* getReference(const std::string& animeName); + + void dump(); + +private: + void init(const ProjectData* data); + + static std::string toPackAnimeKey(const std::string& packName, const std::string& animeName); + + //キャッシュの削除 + void releseReference(void); + +private: + std::map _dic; +}; + + + + +} //namespace ss + diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h index cd8f8e5..2d0d93e 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h @@ -6,7 +6,7 @@ namespace ss{ -class Cell; +struct Cell; struct ProjectData; @@ -48,7 +48,7 @@ class CellCache{ void addTexture(const std::string& imagePath, const std::string& imageBaseDir, SsTexWrapMode::_enum wrapmode, SsTexFilterMode::_enum filtermode); -protected: +private: std::vector _texname; std::vector _textures; std::vector _refs; From f4b67ef1870903f23ab04d5286fb70c15285be91 Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 15:28:16 +0900 Subject: [PATCH 04/20] =?UTF-8?q?EffectCache=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 477 +---------------- .../common/SS5PlayerLibs/SS5EffectCache.cpp | 480 ++++++++++++++++++ .../common/SS5PlayerLibs/SS5EffectCache.h | 37 ++ 3 files changed, 518 insertions(+), 476 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index cf6d643..3e6a527 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -8,6 +8,7 @@ #include "common/SS5PlayerLibs/SS5PlayerDataArrayReader.h" #include "common/SS5PlayerLibs/SS5CellCache.h" #include "common/SS5PlayerLibs/SS5AnimCache.h" +#include "common/SS5PlayerLibs/SS5EffectCache.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" @@ -105,482 +106,6 @@ unsigned int getRandomSeed() -/** -* EffectCache -*/ -class EffectCache -{ -public: - EffectCache() - { - } - ~EffectCache() - { - releseReference(); - } - - static EffectCache* create(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) - { - EffectCache* obj = new EffectCache(); - if (obj) - { - obj->init(data, imageBaseDir, cellCache); - // obj->autorelease(); - } - return obj; - } - - /** - * エフェクトファイル名を指定してEffectRefを得る - */ - SsEffectModel* getReference(const std::string& name) - { - SsEffectModel* ref = _dic.at(name); - return ref; - } - - void dump() - { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - SSLOG("%s", (*it).second); - ++it; - } - } -protected: - void init(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) - { - SS_ASSERT2(data != NULL, "Invalid data"); - - ToPointer ptr(data); - - //ssbpからエフェクトファイル配列を取得 - const EffectFile* effectFileArray = static_cast(ptr(data->effectFileList)); - - for (int listindex = 0; listindex < data->numEffectFileList; listindex++) - { - //エフェクトファイル配列からエフェクトファイルを取得 - const EffectFile* effectFile = &effectFileArray[listindex]; - - //保持用のエフェクトファイル情報を作成 - SsEffectModel *effectmodel = new SsEffectModel(); - std::string effectFileName = static_cast(ptr(effectFile->name)); - - //エフェクトファイルからエフェクトノード配列を取得 - const EffectNode* effectNodeArray = static_cast(ptr(effectFile->effectNode)); - for (int nodeindex = 0; nodeindex < effectFile->numNodeList; nodeindex++) - { - const EffectNode* effectNode = &effectNodeArray[nodeindex]; //エフェクトノード配列からエフェクトノードを取得 - - SsEffectNode *node = new SsEffectNode(); - node->arrayIndex = effectNode->arrayIndex; - node->parentIndex = effectNode->parentIndex; - node->type = (SsEffectNodeType::_enum)effectNode->type; - node->visible = true; - - SsEffectBehavior behavior; - //セル情報を作成 - behavior.CellIndex = effectNode->cellIndex; - CellRef* cellRef = behavior.CellIndex >= 0 ? cellCache->getReference(behavior.CellIndex) : NULL; - if (cellRef) - { - behavior.refCell.pivot_X = cellRef->cell->pivot_X; - behavior.refCell.pivot_Y = cellRef->cell->pivot_Y; - behavior.refCell.texture = cellRef->texture; - behavior.refCell.texname = cellRef->texname; - behavior.refCell.rect = cellRef->rect; - behavior.refCell.cellIndex = behavior.CellIndex; - std::string name = static_cast(ptr(cellRef->cell->name)); - behavior.refCell.cellName = name; - - } - // behavior.CellName; - // behavior.CellMapName; - behavior.blendType = (SsRenderBlendType::_enum)effectNode->blendType; - - //エフェクトノードからビヘイビア配列を取得 - const ss_offset* behaviorArray = static_cast(ptr(effectNode->Behavior)); - for (int behaviorindex = 0; behaviorindex < effectNode->numBehavior; behaviorindex++) - { - //ビヘイビア配列からビヘイビアを取得 - const ss_u16* behavior_adr = static_cast(ptr(behaviorArray[behaviorindex])); - DataArrayReader reader(behavior_adr); - - //パラメータを作ってpush_backで登録していく - int type = reader.readS32(); - switch (type) - { - case SsEffectFunctionType::Basic: - { - //基本情報 - EffectParticleElementBasic readparam; - readparam.priority = reader.readU32(); //表示優先度 - readparam.maximumParticle = reader.readU32(); //最大パーティクル数 - readparam.attimeCreate = reader.readU32(); //一度に作成するパーティクル数 - readparam.interval = reader.readU32(); //生成間隔 - readparam.lifetime = reader.readU32(); //エミッター生存時間 - readparam.speedMinValue = reader.readFloat(); //初速最小 - readparam.speedMaxValue = reader.readFloat(); //初速最大 - readparam.lifespanMinValue = reader.readU32(); //パーティクル生存時間最小 - readparam.lifespanMaxValue = reader.readU32(); //パーティクル生存時間最大 - readparam.angle = reader.readFloat(); //射出方向 - readparam.angleVariance = reader.readFloat(); //射出方向範囲 - - ParticleElementBasic *effectParam = new ParticleElementBasic(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->priority = readparam.priority; //表示優先度 - effectParam->maximumParticle = readparam.maximumParticle; //最大パーティクル数 - effectParam->attimeCreate = readparam.attimeCreate; //一度に作成するパーティクル数 - effectParam->interval = readparam.interval; //生成間隔 - effectParam->lifetime = readparam.lifetime; //エミッター生存時間 - effectParam->speed.setMinMax(readparam.speedMinValue, readparam.speedMaxValue); //初速 - effectParam->lifespan.setMinMax(readparam.lifespanMinValue, readparam.lifespanMaxValue); //パーティクル生存時間 - effectParam->angle = readparam.angle; //射出方向 - effectParam->angleVariance = readparam.angleVariance; //射出方向範囲 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::RndSeedChange: - { - //シード上書き - EffectParticleElementRndSeedChange readparam; - readparam.Seed = reader.readU32(); //上書きするシード値 - - ParticleElementRndSeedChange *effectParam = new ParticleElementRndSeedChange(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Seed = readparam.Seed; //上書きするシード値 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::Delay: - { - //発生:タイミング - EffectParticleElementDelay readparam; - readparam.DelayTime = reader.readU32(); //遅延時間 - - ParticleElementDelay *effectParam = new ParticleElementDelay(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->DelayTime = readparam.DelayTime; //遅延時間 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::Gravity: - { - //重力を加える - EffectParticleElementGravity readparam; - readparam.Gravity_x = reader.readFloat(); //X方向の重力 - readparam.Gravity_y = reader.readFloat(); //Y方向の重力 - - ParticleElementGravity *effectParam = new ParticleElementGravity(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Gravity.x = readparam.Gravity_x; //X方向の重力 - effectParam->Gravity.y = readparam.Gravity_y; //Y方向の重力 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::Position: - { - //座標:生成時 - EffectParticleElementPosition readparam; - readparam.OffsetXMinValue = reader.readFloat(); //X座標に加算最小 - readparam.OffsetXMaxValue = reader.readFloat(); //X座標に加算最大 - readparam.OffsetYMinValue = reader.readFloat(); //X座標に加算最小 - readparam.OffsetYMaxValue = reader.readFloat(); //X座標に加算最大 - - ParticleElementPosition *effectParam = new ParticleElementPosition(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->OffsetX.setMinMax(readparam.OffsetXMinValue, readparam.OffsetXMaxValue); //X座標に加算最小 - effectParam->OffsetY.setMinMax(readparam.OffsetYMinValue, readparam.OffsetYMaxValue); //X座標に加算最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::Rotation: - { - //Z回転を追加 - EffectParticleElementRotation readparam; - readparam.RotationMinValue = reader.readFloat(); //角度初期値最小 - readparam.RotationMaxValue = reader.readFloat(); //角度初期値最大 - readparam.RotationAddMinValue = reader.readFloat(); //角度初期加算値最小 - readparam.RotationAddMaxValue = reader.readFloat(); //角度初期加算値最大 - - ParticleElementRotation *effectParam = new ParticleElementRotation(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Rotation.setMinMax(readparam.RotationMinValue, readparam.RotationMaxValue); //角度初期値最小 - effectParam->RotationAdd.setMinMax(readparam.RotationAddMinValue, readparam.RotationAddMaxValue); //角度初期加算値最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TransRotation: - { - //Z回転速度変更 - EffectParticleElementRotationTrans readparam; - readparam.RotationFactor = reader.readFloat(); //角度目標加算値 - readparam.EndLifeTimePer = reader.readFloat(); //到達時間 - - ParticleElementRotationTrans *effectParam = new ParticleElementRotationTrans(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->RotationFactor = readparam.RotationFactor; //角度目標加算値 - effectParam->EndLifeTimePer = readparam.EndLifeTimePer; //到達時間 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TransSpeed: - { - //速度:変化 - EffectParticleElementTransSpeed readparam; - readparam.SpeedMinValue = reader.readFloat(); //速度目標値最小 - readparam.SpeedMaxValue = reader.readFloat(); //速度目標値最大 - - ParticleElementTransSpeed *effectParam = new ParticleElementTransSpeed(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Speed.setMinMax(readparam.SpeedMinValue, readparam.SpeedMaxValue); //速度目標値最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TangentialAcceleration: - { - //接線加速度 - EffectParticleElementTangentialAcceleration readparam; - readparam.AccelerationMinValue = reader.readFloat(); //設定加速度最小 - readparam.AccelerationMaxValue = reader.readFloat(); //設定加速度最大 - - ParticleElementTangentialAcceleration *effectParam = new ParticleElementTangentialAcceleration(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Acceleration.setMinMax(readparam.AccelerationMinValue, readparam.AccelerationMaxValue); //設定加速度最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::InitColor: - { - //カラーRGBA:生成時 - EffectParticleElementInitColor readparam; - readparam.ColorMinValue = reader.readU32(); //設定カラー最小 - readparam.ColorMaxValue = reader.readU32(); //設定カラー最大 - - ParticleElementInitColor *effectParam = new ParticleElementInitColor(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - - int a = (readparam.ColorMinValue & 0xFF000000) >> 24; - int r = (readparam.ColorMinValue & 0x00FF0000) >> 16; - int g = (readparam.ColorMinValue & 0x0000FF00) >> 8; - int b = (readparam.ColorMinValue & 0x000000FF) >> 0; - SsU8Color mincol(r, g, b, a); - a = (readparam.ColorMaxValue & 0xFF000000) >> 24; - r = (readparam.ColorMaxValue & 0x00FF0000) >> 16; - g = (readparam.ColorMaxValue & 0x0000FF00) >> 8; - b = (readparam.ColorMaxValue & 0x000000FF) >> 0; - SsU8Color maxcol(r, g, b, a); - effectParam->Color.setMinMax(mincol, maxcol); //設定カラー最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TransColor: - { - //カラーRGB:変化 - EffectParticleElementTransColor readparam; - readparam.ColorMinValue = reader.readU32(); //設定カラー最小 - readparam.ColorMaxValue = reader.readU32(); //設定カラー最大 - - ParticleElementTransColor *effectParam = new ParticleElementTransColor(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - - int a = (readparam.ColorMinValue & 0xFF000000) >> 24; - int r = (readparam.ColorMinValue & 0x00FF0000) >> 16; - int g = (readparam.ColorMinValue & 0x0000FF00) >> 8; - int b = (readparam.ColorMinValue & 0x000000FF) >> 0; - SsU8Color mincol(r, g, b, a); - a = (readparam.ColorMaxValue & 0xFF000000) >> 24; - r = (readparam.ColorMaxValue & 0x00FF0000) >> 16; - g = (readparam.ColorMaxValue & 0x0000FF00) >> 8; - b = (readparam.ColorMaxValue & 0x000000FF) >> 0; - SsU8Color maxcol(r, g, b, a); - effectParam->Color.setMinMax(mincol, maxcol); //設定カラー最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::AlphaFade: - { - //フェード - EffectParticleElementAlphaFade readparam; - readparam.disprangeMinValue = reader.readFloat(); //表示区間開始 - readparam.disprangeMaxValue = reader.readFloat(); //表示区間終了 - - ParticleElementAlphaFade *effectParam = new ParticleElementAlphaFade(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->disprange.setMinMax(readparam.disprangeMinValue, readparam.disprangeMaxValue); //表示区間開始 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::Size: - { - //スケール:生成時 - EffectParticleElementSize readparam; - readparam.SizeXMinValue = reader.readFloat(); //幅倍率最小 - readparam.SizeXMaxValue = reader.readFloat(); //幅倍率最大 - readparam.SizeYMinValue = reader.readFloat(); //高さ倍率最小 - readparam.SizeYMaxValue = reader.readFloat(); //高さ倍率最大 - readparam.ScaleFactorMinValue = reader.readFloat(); //倍率最小 - readparam.ScaleFactorMaxValue = reader.readFloat(); //倍率最大 - - ParticleElementSize *effectParam = new ParticleElementSize(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->SizeX.setMinMax(readparam.SizeXMinValue, readparam.SizeXMaxValue); //幅倍率最小 - effectParam->SizeY.setMinMax(readparam.SizeYMinValue, readparam.SizeYMaxValue); //高さ倍率最小 - effectParam->ScaleFactor.setMinMax(readparam.ScaleFactorMinValue, readparam.ScaleFactorMaxValue); //倍率最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TransSize: - { - //スケール:変化 - EffectParticleElementTransSize readparam; - readparam.SizeXMinValue = reader.readFloat(); //幅倍率最小 - readparam.SizeXMaxValue = reader.readFloat(); //幅倍率最大 - readparam.SizeYMinValue = reader.readFloat(); //高さ倍率最小 - readparam.SizeYMaxValue = reader.readFloat(); //高さ倍率最大 - readparam.ScaleFactorMinValue = reader.readFloat(); //倍率最小 - readparam.ScaleFactorMaxValue = reader.readFloat(); //倍率最大 - - ParticleElementTransSize *effectParam = new ParticleElementTransSize(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->SizeX.setMinMax(readparam.SizeXMinValue, readparam.SizeXMaxValue); //幅倍率最小 - effectParam->SizeY.setMinMax(readparam.SizeYMinValue, readparam.SizeYMaxValue); //高さ倍率最小 - effectParam->ScaleFactor.setMinMax(readparam.ScaleFactorMinValue, readparam.ScaleFactorMaxValue); //倍率最小 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::PointGravity: - { - //重力点の追加 - EffectParticlePointGravity readparam; - readparam.Position_x = reader.readFloat(); //重力点X - readparam.Position_y = reader.readFloat(); //重力点Y - readparam.Power = reader.readFloat(); //パワー - - ParticlePointGravity *effectParam = new ParticlePointGravity(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - effectParam->Position.x = readparam.Position_x; //重力点X - effectParam->Position.y = readparam.Position_y; //重力点Y - effectParam->Power = readparam.Power; //パワー - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::TurnToDirectionEnabled: - { - //進行方向に向ける - EffectParticleTurnToDirectionEnabled readparam; - readparam.Rotation = reader.readFloat(); //フラグ - - ParticleTurnToDirectionEnabled *effectParam = new ParticleTurnToDirectionEnabled(); - effectParam->Rotation = readparam.Rotation; - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - case SsEffectFunctionType::InfiniteEmitEnabled: - { - EffectParticleInfiniteEmitEnabled readparam; - readparam.flag = reader.readS32(); //フラグ - - ParticleInfiniteEmitEnabled *effectParam = new ParticleInfiniteEmitEnabled(); - effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 - - behavior.plist.push_back(effectParam); //パラメータを追加 - break; - } - default: - break; - } - } - node->behavior = behavior; - effectmodel->nodeList.push_back(node); - if (nodeindex == 0) - { - } - } - //ツリーの構築 - if (effectmodel->nodeList.size() > 0) - { - effectmodel->root = effectmodel->nodeList[0]; //rootノードを追加 - for (size_t i = 1; i < effectmodel->nodeList.size(); i++) - { - int pi = effectmodel->nodeList[i]->parentIndex; - if (pi >= 0) - { - effectmodel->nodeList[pi]->addChildEnd(effectmodel->nodeList[i]); - } - } - } - effectmodel->lockRandSeed = effectFile->lockRandSeed; // ランダムシード固定値 - effectmodel->isLockRandSeed = effectFile->isLockRandSeed; // ランダムシードを固定するか否か - effectmodel->fps = effectFile->fps; // - effectmodel->effectName = effectFileName; - effectmodel->layoutScaleX = effectFile->layoutScaleX; //レイアウトスケールX - effectmodel->layoutScaleY = effectFile->layoutScaleY; //レイアウトスケールY - - - - SSLOG("effect key: %s", effectFileName.c_str()); - _dic.insert(std::map::value_type(effectFileName, effectmodel)); - } - } - //エフェクトファイル情報の削除 - void releseReference(void) - { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - SsEffectModel* effectmodel = it->second; - - if (effectmodel) - { - for (int nodeindex = 0; nodeindex < effectmodel->nodeList.size(); nodeindex++) - { - SsEffectNode* node = effectmodel->nodeList.at(nodeindex); - for (int behaviorindex = 0; behaviorindex < node->behavior.plist.size(); behaviorindex++) - { - SsEffectElementBase* eb = node->behavior.plist.at(behaviorindex); - delete eb; - } - node->behavior.plist.clear(); - } - if (effectmodel->nodeList.size() > 0) - { - SsEffectNode* node = effectmodel->nodeList.at(0); - delete node; - effectmodel->nodeList.clear(); - } - effectmodel->root = 0; - - } - delete effectmodel; - it++; - } - _dic.clear(); - } -protected: - std::map _dic; -}; - - - /** * ResourceSet diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp new file mode 100644 index 0000000..5c07505 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp @@ -0,0 +1,480 @@ +#include "SS5EffectCache.h" +#include "SS5Player.h" +#include "SS5PlayerToPointer.h" +#include "SS5CellCache.h" +#include "SS5PlayerDataArrayReader.h" + +namespace ss{ + + +EffectCache* EffectCache::create(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) +{ + EffectCache* obj = new EffectCache(); + if (obj) + { + obj->init(data, imageBaseDir, cellCache); + // obj->autorelease(); + } + return obj; +} + + +EffectCache::EffectCache() +{ +} + +EffectCache::~EffectCache() +{ + releseReference(); +} + + +//エフェクトファイル名を指定してEffectRefを得る +SsEffectModel* EffectCache::getReference(const std::string& name) +{ + SsEffectModel* ref = _dic.at(name); + return ref; +} + +void EffectCache::dump() +{ + std::map::iterator it = _dic.begin(); + while (it != _dic.end()) + { + SSLOG("%s", (*it).second); + ++it; + } +} + + +void EffectCache::init(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) +{ + SS_ASSERT2(data != NULL, "Invalid data"); + + ToPointer ptr(data); + + //ssbpからエフェクトファイル配列を取得 + const EffectFile* effectFileArray = static_cast(ptr(data->effectFileList)); + + for (int listindex = 0; listindex < data->numEffectFileList; listindex++) + { + //エフェクトファイル配列からエフェクトファイルを取得 + const EffectFile* effectFile = &effectFileArray[listindex]; + + //保持用のエフェクトファイル情報を作成 + SsEffectModel *effectmodel = new SsEffectModel(); + std::string effectFileName = static_cast(ptr(effectFile->name)); + + //エフェクトファイルからエフェクトノード配列を取得 + const EffectNode* effectNodeArray = static_cast(ptr(effectFile->effectNode)); + for (int nodeindex = 0; nodeindex < effectFile->numNodeList; nodeindex++) + { + const EffectNode* effectNode = &effectNodeArray[nodeindex]; //エフェクトノード配列からエフェクトノードを取得 + + SsEffectNode *node = new SsEffectNode(); + node->arrayIndex = effectNode->arrayIndex; + node->parentIndex = effectNode->parentIndex; + node->type = (SsEffectNodeType::_enum)effectNode->type; + node->visible = true; + + SsEffectBehavior behavior; + //セル情報を作成 + behavior.CellIndex = effectNode->cellIndex; + CellRef* cellRef = behavior.CellIndex >= 0 ? cellCache->getReference(behavior.CellIndex) : NULL; + if (cellRef) + { + behavior.refCell.pivot_X = cellRef->cell->pivot_X; + behavior.refCell.pivot_Y = cellRef->cell->pivot_Y; + behavior.refCell.texture = cellRef->texture; + behavior.refCell.texname = cellRef->texname; + behavior.refCell.rect = cellRef->rect; + behavior.refCell.cellIndex = behavior.CellIndex; + std::string name = static_cast(ptr(cellRef->cell->name)); + behavior.refCell.cellName = name; + + } + // behavior.CellName; + // behavior.CellMapName; + behavior.blendType = (SsRenderBlendType::_enum)effectNode->blendType; + + //エフェクトノードからビヘイビア配列を取得 + const ss_offset* behaviorArray = static_cast(ptr(effectNode->Behavior)); + for (int behaviorindex = 0; behaviorindex < effectNode->numBehavior; behaviorindex++) + { + //ビヘイビア配列からビヘイビアを取得 + const ss_u16* behavior_adr = static_cast(ptr(behaviorArray[behaviorindex])); + DataArrayReader reader(behavior_adr); + + //パラメータを作ってpush_backで登録していく + int type = reader.readS32(); + switch (type) + { + case SsEffectFunctionType::Basic: + { + //基本情報 + EffectParticleElementBasic readparam; + readparam.priority = reader.readU32(); //表示優先度 + readparam.maximumParticle = reader.readU32(); //最大パーティクル数 + readparam.attimeCreate = reader.readU32(); //一度に作成するパーティクル数 + readparam.interval = reader.readU32(); //生成間隔 + readparam.lifetime = reader.readU32(); //エミッター生存時間 + readparam.speedMinValue = reader.readFloat(); //初速最小 + readparam.speedMaxValue = reader.readFloat(); //初速最大 + readparam.lifespanMinValue = reader.readU32(); //パーティクル生存時間最小 + readparam.lifespanMaxValue = reader.readU32(); //パーティクル生存時間最大 + readparam.angle = reader.readFloat(); //射出方向 + readparam.angleVariance = reader.readFloat(); //射出方向範囲 + + ParticleElementBasic *effectParam = new ParticleElementBasic(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->priority = readparam.priority; //表示優先度 + effectParam->maximumParticle = readparam.maximumParticle; //最大パーティクル数 + effectParam->attimeCreate = readparam.attimeCreate; //一度に作成するパーティクル数 + effectParam->interval = readparam.interval; //生成間隔 + effectParam->lifetime = readparam.lifetime; //エミッター生存時間 + effectParam->speed.setMinMax(readparam.speedMinValue, readparam.speedMaxValue); //初速 + effectParam->lifespan.setMinMax(readparam.lifespanMinValue, readparam.lifespanMaxValue); //パーティクル生存時間 + effectParam->angle = readparam.angle; //射出方向 + effectParam->angleVariance = readparam.angleVariance; //射出方向範囲 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::RndSeedChange: + { + //シード上書き + EffectParticleElementRndSeedChange readparam; + readparam.Seed = reader.readU32(); //上書きするシード値 + + ParticleElementRndSeedChange *effectParam = new ParticleElementRndSeedChange(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Seed = readparam.Seed; //上書きするシード値 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::Delay: + { + //発生:タイミング + EffectParticleElementDelay readparam; + readparam.DelayTime = reader.readU32(); //遅延時間 + + ParticleElementDelay *effectParam = new ParticleElementDelay(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->DelayTime = readparam.DelayTime; //遅延時間 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::Gravity: + { + //重力を加える + EffectParticleElementGravity readparam; + readparam.Gravity_x = reader.readFloat(); //X方向の重力 + readparam.Gravity_y = reader.readFloat(); //Y方向の重力 + + ParticleElementGravity *effectParam = new ParticleElementGravity(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Gravity.x = readparam.Gravity_x; //X方向の重力 + effectParam->Gravity.y = readparam.Gravity_y; //Y方向の重力 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::Position: + { + //座標:生成時 + EffectParticleElementPosition readparam; + readparam.OffsetXMinValue = reader.readFloat(); //X座標に加算最小 + readparam.OffsetXMaxValue = reader.readFloat(); //X座標に加算最大 + readparam.OffsetYMinValue = reader.readFloat(); //X座標に加算最小 + readparam.OffsetYMaxValue = reader.readFloat(); //X座標に加算最大 + + ParticleElementPosition *effectParam = new ParticleElementPosition(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->OffsetX.setMinMax(readparam.OffsetXMinValue, readparam.OffsetXMaxValue); //X座標に加算最小 + effectParam->OffsetY.setMinMax(readparam.OffsetYMinValue, readparam.OffsetYMaxValue); //X座標に加算最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::Rotation: + { + //Z回転を追加 + EffectParticleElementRotation readparam; + readparam.RotationMinValue = reader.readFloat(); //角度初期値最小 + readparam.RotationMaxValue = reader.readFloat(); //角度初期値最大 + readparam.RotationAddMinValue = reader.readFloat(); //角度初期加算値最小 + readparam.RotationAddMaxValue = reader.readFloat(); //角度初期加算値最大 + + ParticleElementRotation *effectParam = new ParticleElementRotation(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Rotation.setMinMax(readparam.RotationMinValue, readparam.RotationMaxValue); //角度初期値最小 + effectParam->RotationAdd.setMinMax(readparam.RotationAddMinValue, readparam.RotationAddMaxValue); //角度初期加算値最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TransRotation: + { + //Z回転速度変更 + EffectParticleElementRotationTrans readparam; + readparam.RotationFactor = reader.readFloat(); //角度目標加算値 + readparam.EndLifeTimePer = reader.readFloat(); //到達時間 + + ParticleElementRotationTrans *effectParam = new ParticleElementRotationTrans(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->RotationFactor = readparam.RotationFactor; //角度目標加算値 + effectParam->EndLifeTimePer = readparam.EndLifeTimePer; //到達時間 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TransSpeed: + { + //速度:変化 + EffectParticleElementTransSpeed readparam; + readparam.SpeedMinValue = reader.readFloat(); //速度目標値最小 + readparam.SpeedMaxValue = reader.readFloat(); //速度目標値最大 + + ParticleElementTransSpeed *effectParam = new ParticleElementTransSpeed(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Speed.setMinMax(readparam.SpeedMinValue, readparam.SpeedMaxValue); //速度目標値最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TangentialAcceleration: + { + //接線加速度 + EffectParticleElementTangentialAcceleration readparam; + readparam.AccelerationMinValue = reader.readFloat(); //設定加速度最小 + readparam.AccelerationMaxValue = reader.readFloat(); //設定加速度最大 + + ParticleElementTangentialAcceleration *effectParam = new ParticleElementTangentialAcceleration(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Acceleration.setMinMax(readparam.AccelerationMinValue, readparam.AccelerationMaxValue); //設定加速度最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::InitColor: + { + //カラーRGBA:生成時 + EffectParticleElementInitColor readparam; + readparam.ColorMinValue = reader.readU32(); //設定カラー最小 + readparam.ColorMaxValue = reader.readU32(); //設定カラー最大 + + ParticleElementInitColor *effectParam = new ParticleElementInitColor(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + + int a = (readparam.ColorMinValue & 0xFF000000) >> 24; + int r = (readparam.ColorMinValue & 0x00FF0000) >> 16; + int g = (readparam.ColorMinValue & 0x0000FF00) >> 8; + int b = (readparam.ColorMinValue & 0x000000FF) >> 0; + SsU8Color mincol(r, g, b, a); + a = (readparam.ColorMaxValue & 0xFF000000) >> 24; + r = (readparam.ColorMaxValue & 0x00FF0000) >> 16; + g = (readparam.ColorMaxValue & 0x0000FF00) >> 8; + b = (readparam.ColorMaxValue & 0x000000FF) >> 0; + SsU8Color maxcol(r, g, b, a); + effectParam->Color.setMinMax(mincol, maxcol); //設定カラー最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TransColor: + { + //カラーRGB:変化 + EffectParticleElementTransColor readparam; + readparam.ColorMinValue = reader.readU32(); //設定カラー最小 + readparam.ColorMaxValue = reader.readU32(); //設定カラー最大 + + ParticleElementTransColor *effectParam = new ParticleElementTransColor(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + + int a = (readparam.ColorMinValue & 0xFF000000) >> 24; + int r = (readparam.ColorMinValue & 0x00FF0000) >> 16; + int g = (readparam.ColorMinValue & 0x0000FF00) >> 8; + int b = (readparam.ColorMinValue & 0x000000FF) >> 0; + SsU8Color mincol(r, g, b, a); + a = (readparam.ColorMaxValue & 0xFF000000) >> 24; + r = (readparam.ColorMaxValue & 0x00FF0000) >> 16; + g = (readparam.ColorMaxValue & 0x0000FF00) >> 8; + b = (readparam.ColorMaxValue & 0x000000FF) >> 0; + SsU8Color maxcol(r, g, b, a); + effectParam->Color.setMinMax(mincol, maxcol); //設定カラー最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::AlphaFade: + { + //フェード + EffectParticleElementAlphaFade readparam; + readparam.disprangeMinValue = reader.readFloat(); //表示区間開始 + readparam.disprangeMaxValue = reader.readFloat(); //表示区間終了 + + ParticleElementAlphaFade *effectParam = new ParticleElementAlphaFade(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->disprange.setMinMax(readparam.disprangeMinValue, readparam.disprangeMaxValue); //表示区間開始 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::Size: + { + //スケール:生成時 + EffectParticleElementSize readparam; + readparam.SizeXMinValue = reader.readFloat(); //幅倍率最小 + readparam.SizeXMaxValue = reader.readFloat(); //幅倍率最大 + readparam.SizeYMinValue = reader.readFloat(); //高さ倍率最小 + readparam.SizeYMaxValue = reader.readFloat(); //高さ倍率最大 + readparam.ScaleFactorMinValue = reader.readFloat(); //倍率最小 + readparam.ScaleFactorMaxValue = reader.readFloat(); //倍率最大 + + ParticleElementSize *effectParam = new ParticleElementSize(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->SizeX.setMinMax(readparam.SizeXMinValue, readparam.SizeXMaxValue); //幅倍率最小 + effectParam->SizeY.setMinMax(readparam.SizeYMinValue, readparam.SizeYMaxValue); //高さ倍率最小 + effectParam->ScaleFactor.setMinMax(readparam.ScaleFactorMinValue, readparam.ScaleFactorMaxValue); //倍率最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TransSize: + { + //スケール:変化 + EffectParticleElementTransSize readparam; + readparam.SizeXMinValue = reader.readFloat(); //幅倍率最小 + readparam.SizeXMaxValue = reader.readFloat(); //幅倍率最大 + readparam.SizeYMinValue = reader.readFloat(); //高さ倍率最小 + readparam.SizeYMaxValue = reader.readFloat(); //高さ倍率最大 + readparam.ScaleFactorMinValue = reader.readFloat(); //倍率最小 + readparam.ScaleFactorMaxValue = reader.readFloat(); //倍率最大 + + ParticleElementTransSize *effectParam = new ParticleElementTransSize(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->SizeX.setMinMax(readparam.SizeXMinValue, readparam.SizeXMaxValue); //幅倍率最小 + effectParam->SizeY.setMinMax(readparam.SizeYMinValue, readparam.SizeYMaxValue); //高さ倍率最小 + effectParam->ScaleFactor.setMinMax(readparam.ScaleFactorMinValue, readparam.ScaleFactorMaxValue); //倍率最小 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::PointGravity: + { + //重力点の追加 + EffectParticlePointGravity readparam; + readparam.Position_x = reader.readFloat(); //重力点X + readparam.Position_y = reader.readFloat(); //重力点Y + readparam.Power = reader.readFloat(); //パワー + + ParticlePointGravity *effectParam = new ParticlePointGravity(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + effectParam->Position.x = readparam.Position_x; //重力点X + effectParam->Position.y = readparam.Position_y; //重力点Y + effectParam->Power = readparam.Power; //パワー + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::TurnToDirectionEnabled: + { + //進行方向に向ける + EffectParticleTurnToDirectionEnabled readparam; + readparam.Rotation = reader.readFloat(); //フラグ + + ParticleTurnToDirectionEnabled *effectParam = new ParticleTurnToDirectionEnabled(); + effectParam->Rotation = readparam.Rotation; + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + case SsEffectFunctionType::InfiniteEmitEnabled: + { + EffectParticleInfiniteEmitEnabled readparam; + readparam.flag = reader.readS32(); //フラグ + + ParticleInfiniteEmitEnabled *effectParam = new ParticleInfiniteEmitEnabled(); + effectParam->setType((SsEffectFunctionType::enum_)type); //コマンドの種類 + + behavior.plist.push_back(effectParam); //パラメータを追加 + break; + } + default: + break; + } + } + node->behavior = behavior; + effectmodel->nodeList.push_back(node); + if (nodeindex == 0) + { + } + } + //ツリーの構築 + if (effectmodel->nodeList.size() > 0) + { + effectmodel->root = effectmodel->nodeList[0]; //rootノードを追加 + for (size_t i = 1; i < effectmodel->nodeList.size(); i++) + { + int pi = effectmodel->nodeList[i]->parentIndex; + if (pi >= 0) + { + effectmodel->nodeList[pi]->addChildEnd(effectmodel->nodeList[i]); + } + } + } + effectmodel->lockRandSeed = effectFile->lockRandSeed; // ランダムシード固定値 + effectmodel->isLockRandSeed = effectFile->isLockRandSeed; // ランダムシードを固定するか否か + effectmodel->fps = effectFile->fps; // + effectmodel->effectName = effectFileName; + effectmodel->layoutScaleX = effectFile->layoutScaleX; //レイアウトスケールX + effectmodel->layoutScaleY = effectFile->layoutScaleY; //レイアウトスケールY + + + + SSLOG("effect key: %s", effectFileName.c_str()); + _dic.insert(std::map::value_type(effectFileName, effectmodel)); + } +} + + +//エフェクトファイル情報の削除 +void EffectCache::releseReference(void) +{ + std::map::iterator it = _dic.begin(); + while (it != _dic.end()) + { + SsEffectModel* effectmodel = it->second; + + if (effectmodel) + { + for (int nodeindex = 0; nodeindex < effectmodel->nodeList.size(); nodeindex++) + { + SsEffectNode* node = effectmodel->nodeList.at(nodeindex); + for (int behaviorindex = 0; behaviorindex < node->behavior.plist.size(); behaviorindex++) + { + SsEffectElementBase* eb = node->behavior.plist.at(behaviorindex); + delete eb; + } + node->behavior.plist.clear(); + } + if (effectmodel->nodeList.size() > 0) + { + SsEffectNode* node = effectmodel->nodeList.at(0); + delete node; + effectmodel->nodeList.clear(); + } + effectmodel->root = 0; + + } + delete effectmodel; + it++; + } + _dic.clear(); +} + + +} //namespace ss diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h new file mode 100644 index 0000000..d325fcd --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h @@ -0,0 +1,37 @@ +#pragma once +#include +#include + +namespace ss{ +struct ProjectData; +class SsEffectModel; +class CellCache; + +/** + * EffectCache + */ +class EffectCache{ +public: + EffectCache(); + ~EffectCache(); + static EffectCache* create(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache); + + /** + * エフェクトファイル名を指定してEffectRefを得る + */ + SsEffectModel* getReference(const std::string& name); + + void dump(); + +private: + void init(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache); + + //エフェクトファイル情報の削除 + void releseReference(void); + +private: + std::map _dic; +}; + + +} //namespace ss From b29ae5b25c79cf9a8396af52ebc95a1efca00e55 Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 15:32:12 +0900 Subject: [PATCH 05/20] =?UTF-8?q?ResourceSet=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 40 +-------------- .../common/SS5PlayerLibs/SS5ResourceSet.h | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 3e6a527..00fa379 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -9,6 +9,7 @@ #include "common/SS5PlayerLibs/SS5CellCache.h" #include "common/SS5PlayerLibs/SS5AnimCache.h" #include "common/SS5PlayerLibs/SS5EffectCache.h" +#include "common/SS5PlayerLibs/SS5ResourceSet.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" @@ -105,45 +106,6 @@ unsigned int getRandomSeed() - - -/** - * ResourceSet - */ -struct ResourceSet -{ - const ProjectData* data; - bool isDataAutoRelease; - EffectCache* effectCache; - CellCache* cellCache; - AnimeCache* animeCache; - - virtual ~ResourceSet() - { - if (isDataAutoRelease) - { - delete data; - data = NULL; - } - if (animeCache) - { - delete animeCache; - animeCache = NULL; - } - if (cellCache) - { - delete cellCache; - cellCache = NULL; - } - if (effectCache) - { - delete effectCache; - effectCache = NULL; - } - } -}; - - /** * ResourceManager */ diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h new file mode 100644 index 0000000..450d6b6 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -0,0 +1,49 @@ +#pragma once +#include "SS5PlayerData.h" +#include "SS5EffectCache.h" +#include "SS5CellCache.h" +#include "SS5AnimCache.h" + +namespace ss{ + + +/** + * ResourceSet + */ +class ResourceSet{ +public: + const ProjectData* data; + bool isDataAutoRelease; + EffectCache* effectCache; + CellCache* cellCache; + AnimeCache* animeCache; + + virtual ~ResourceSet() + { + if (isDataAutoRelease) + { + delete data; + data = NULL; + } + if (animeCache) + { + delete animeCache; + animeCache = NULL; + } + if (cellCache) + { + delete cellCache; + cellCache = NULL; + } + if (effectCache) + { + delete effectCache; + effectCache = NULL; + } + } +}; + + + +} //namespace ss + From 538b4bf495ad84874e326ef91e472753d481809f Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:03:27 +0900 Subject: [PATCH 06/20] =?UTF-8?q?ResourceManager=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 281 +----------------- samples/DXLibrary/basic/SSPlayer/SS5Player.h | 138 +-------- .../basic/SSPlayer/SS5PlayerPlatform.cpp | 4 +- .../basic/SSPlayer/SS5ResourceManager.cpp | 259 ++++++++++++++++ .../basic/SSPlayer/SS5ResourceManager.h | 120 ++++++++ .../basic/SSPlayer/common/Helper/Util.h | 70 +++++ samples/DXLibrary/basic/sssample.cpp | 1 + 7 files changed, 456 insertions(+), 417 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp create mode 100644 samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h create mode 100644 samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 00fa379..0486a01 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -2,6 +2,7 @@ // SS5Player.cpp // #include "SS5Player.h" +#include "SS5ResourceManager.h" #include "common/SS5PlayerLibs/SS5PlayerData.h" #include "common/SS5PlayerLibs/SS5PlayerTypes.h" #include "common/SS5PlayerLibs/SS5PlayerToPointer.h" @@ -10,71 +11,13 @@ #include "common/SS5PlayerLibs/SS5AnimCache.h" #include "common/SS5PlayerLibs/SS5EffectCache.h" #include "common/SS5PlayerLibs/SS5ResourceSet.h" +#include "common/Helper/Util.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" namespace ss { -/** - * definition - */ - -static const ss_u32 DATA_ID = 0x42505353; -static const ss_u32 DATA_VERSION = 4; - - -/** - * utilites - */ -static void splitPath(std::string& directoty, std::string& filename, const std::string& path) -{ - std::string f = path; - std::string d = ""; - - size_t pos = path.find_last_of("/"); - if (pos == std::string::npos) pos = path.find_last_of("\\"); // for win - - if (pos != std::string::npos) - { - d = path.substr(0, pos+1); - f = path.substr(pos+1); - } - - directoty = d; - filename = f; -} - -// printf 形式のフォーマット -#ifndef va_copy -# define va_copy(dest, src) ((dest) = (src)) -#endif -static std::string Format(const char* format, ...){ - - static std::vector tmp(1000); - - va_list args, source; - va_start(args, format); - va_copy( source , args ); - - while (1) - { - va_copy( args , source ); - //Windows - if (_vsnprintf(&tmp[0], tmp.size(), format, args) == -1) - { - tmp.resize(tmp.size() * 2); - } - else - { - break; - } - } - tmp.push_back('\0'); - std::string ret = &(tmp[0]); - va_end(args); - return ret; -} //座標回転処理 //指定した座標を中心に回転後した座標を取得します @@ -106,226 +49,6 @@ unsigned int getRandomSeed() -/** - * ResourceManager - */ - -static ResourceManager* defaultInstance = NULL; -const std::string ResourceManager::s_null; - -ResourceManager* ResourceManager::getInstance() -{ - if (!defaultInstance) - { - defaultInstance = ResourceManager::create(); - } - return defaultInstance; -} - -ResourceManager::ResourceManager(void) -{ -} - -ResourceManager::~ResourceManager() -{ - removeAllData(); -} - -ResourceManager* ResourceManager::create() -{ - ResourceManager* obj = new ResourceManager(); - return obj; -} - -ResourceSet* ResourceManager::getData(const std::string& dataKey) -{ - ResourceSet* rs = _dataDic.at(dataKey); - return rs; -} - -std::string ResourceManager::addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir) -{ - SS_ASSERT2(data != NULL, "Invalid data"); - SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); - SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); - - // imageBaseDirの指定がないときコンバート時に指定されたパスを使用する - std::string baseDir = imageBaseDir; - if (imageBaseDir == s_null && data->imageBaseDir) - { - ToPointer ptr(data); - const char* dir = ptr.toString(data->imageBaseDir); - baseDir = dir; - } - - //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある - CellCache* cellCache = CellCache::create(data, baseDir); - - EffectCache* effectCache = EffectCache::create(data, baseDir, cellCache); // - - AnimeCache* animeCache = AnimeCache::create(data); - - ResourceSet* rs = new ResourceSet(); - rs->data = data; - rs->isDataAutoRelease = false; - rs->cellCache = cellCache; - rs->animeCache = animeCache; - rs->effectCache = effectCache; - _dataDic.insert(std::map::value_type(dataKey, rs)); - - return dataKey; -} - -std::string ResourceManager::addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir) -{ - - std::string fullpath = ssbpFilepath; - - unsigned long nSize = 0; - void* loadData = SSFileOpen(fullpath.c_str(), "rb", &nSize); - if (loadData == NULL) - { - std::string msg = "Can't load project data > " + fullpath; - SS_ASSERT2(loadData != NULL, msg.c_str()); - } - - const ProjectData* data = static_cast(loadData); - SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); - SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); - - std::string baseDir = imageBaseDir; - if (imageBaseDir == s_null) - { - // imageBaseDirの指定がないとき - if (data->imageBaseDir) - { - // コンバート時に指定されたパスを使用する - ToPointer ptr(data); - const char* dir = ptr.toString(data->imageBaseDir); - baseDir = dir; - } - else - { - // プロジェクトファイルと同じディレクトリを指定する - std::string directory; - std::string filename; - splitPath(directory, filename, ssbpFilepath); - baseDir = directory; - } - //SSLOG("imageBaseDir: %s", baseDir.c_str()); - } - - addData(dataKey, data, baseDir); - - // リソースが破棄されるとき一緒にロードしたデータも破棄する - ResourceSet* rs = getData(dataKey); - SS_ASSERT2(rs != NULL, ""); - rs->isDataAutoRelease = true; - - return dataKey; -} - -std::string ResourceManager::addData(const std::string& ssbpFilepath, const std::string& imageBaseDir) -{ - // ファイル名を取り出す - std::string directory; - std::string filename; - splitPath(directory, filename, ssbpFilepath); - - // 拡張子を取る - std::string dataKey = filename; - size_t pos = filename.find_last_of("."); - if (pos != std::string::npos) - { - dataKey = filename.substr(0, pos); - } - - //登録されている名前か判定する - std::map::iterator it = _dataDic.find(dataKey); - if (it != _dataDic.end()) - { - //登録されている場合は処理を行わない - std::string str = ""; - return str; - } - - return addDataWithKey(dataKey, ssbpFilepath, imageBaseDir); -} - -void ResourceManager::removeData(const std::string& dataKey) -{ - ResourceSet* rs = getData(dataKey); - - //テクスチャの解放 - releseTexture(dataKey); - - //バイナリデータの削除 - delete rs; - _dataDic.erase(dataKey); -} - -void ResourceManager::removeAllData() -{ - //全リソースの解放 - while (!_dataDic.empty()) - { - std::map::iterator it = _dataDic.begin(); - std::string ssbpName = it->first; - removeData(ssbpName); - } - _dataDic.clear(); -} - -//データ名、セル名を指定して、セルで使用しているテクスチャを変更する -bool ResourceManager::changeTexture(char* ssbpName, char* ssceName, long texture) -{ - bool rc = false; - - ResourceSet* rs = getData(ssbpName); - rc = rs->cellCache->setCellRefTexture(rs->data, ssceName, texture); - - return(rc); -} - -//指定したデータのテクスチャを破棄します -bool ResourceManager::releseTexture(std::string ssbpName) -{ - - ResourceSet* rs = getData(ssbpName); - bool rc = rs->cellCache->releseTexture(rs->data); - - return(rc); -} - -//アニメーションの総フレーム数を取得する -int ResourceManager::getMaxFrame(std::string ssbpName, std::string animeName) -{ - int rc = -1; - - ResourceSet* rs = getData(ssbpName); - AnimeRef* animeRef = rs->animeCache->getReference(animeName); - if (animeRef == NULL) - { - std::string msg = Format("Not found animation > anime=%s", animeName.c_str()); - SS_ASSERT2(animeRef != NULL, msg.c_str()); - } - rc = animeRef->animationData->numFrames; - - return(rc); -} - -//ssbpファイルが登録されているかを調べる -bool ResourceManager::isDataKeyExists(const std::string& dataKey) { - // 登録されている名前か判定する - std::map::iterator it = _dataDic.find(dataKey); - if (it != _dataDic.end()) { - //登録されている - return true; - } - - return false; -} - /** * Player */ diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.h b/samples/DXLibrary/basic/SSPlayer/SS5Player.h index 2203e3f..aa15489 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.h @@ -105,36 +105,11 @@ class ResourceSet; struct ProjectData; class SSSize; class Player; +class ResourceManager; //関数定義 extern void get_uv_rotation(float *u, float *v, float cu, float cv, float deg); -/** -* 定数 -*/ - -#define __SSPI__ (3.14159265358979323846f) -#define __SS2PI__ (__SSPI__ * 2) - -#define SS_SAFE_DELETE(p) do { if(p) { delete (p); (p) = 0; } } while(0) -#define SS_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = 0; } } while(0) -#define SS_SAFE_FREE(p) do { if(p) { free(p); (p) = 0; } } while(0) -#define SS_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) -#define SS_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = 0; } } while(0) -#define SS_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) -#define SS_BREAK_IF(cond) if(cond) break - -#ifdef _DEBUG - #define SSLOG(...) do {} while (0) - #define SS_ASSERT(cond) assert(cond) - #define SS_ASSERT2(cond, msg) SS_ASSERT(cond) - #define SSLOGERROR(format,...) do {} while (0) -#else - #define SSLOG(...) do {} while (0) - #define SS_ASSERT(cond) - #define SS_ASSERT2(cond, msg) ((void)(cond)) - #define SSLOGERROR(format,...) do {} while (0) -#endif /** @@ -288,117 +263,6 @@ class CustomSprite }; -/** - * ResourceManager - */ -//class ResourceManager : public Ref -class ResourceManager -{ -public: - static const std::string s_null; - - /** - * デフォルトインスタンスを取得します. - * - * @return デフォルトのResourceManagerインスタンス - */ - static ResourceManager* getInstance(); - - /** - * ssbpファイルを読み込み管理対象とします. - * dataKeyはssbpのファイル名(拡張子なし)になります. - * - * @param ssbpFilepath ssbpファイルのパス - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addData(const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); - - /** - * ssbpファイルを読み込み管理対象とします. - * - * @param dataKey dataKeyの指定 - * @param ssbpFilepath ssbpファイルのパス - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); - - /** - * 指定されたssbpデータを管理対象とします. - * - * @param dataKey dataKeyの指定 - * @param data ssbpデータ - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir = s_null); - - /** - * 指定データを解放します. - * パス、拡張子を除いたssbp名を指定してください。 - * - * @param dataKey - */ - void removeData(const std::string& dataKey); - - /** - * 全てのデータを解放します. - */ - void removeAllData(); - - /** - * 名前に対応するデータ取得します. - */ - ResourceSet* getData(const std::string& dataKey); - - /** - * 指定したセルのテクスチャを変更します. - * @param ssbpName ssbp名(拡張子を除くファイル名) - * @param ssceName ssce名(拡張子を除くファイル名) - * @param texture 変更後のテクスチャハンドル - * @return 変更を行ったか - */ - bool changeTexture(char* ssbpName, char* ssceName, long texture); - - /** - * 指定したデータのテクスチャを破棄します。 - * @param dataName ssbp名(拡張子を除くファイル名) - * @return 成功失敗 - */ - bool releseTexture(std::string); - - /** - * 読み込んでいるssbpからアニメーションの総フレーム数を取得します。 - * @param ssbpName ssbp名(拡張子を除くファイル名) - * @param animeName ssae/モーション名 - * @return アニメーションの総フレーム(存在しない場合はアサート) - */ - int getMaxFrame(std::string ssbpName, std::string animeName); - - /** - * 名前が登録されていればtrueを返します - * - * @param dataKey - * @return - */ - bool isDataKeyExists(const std::string& dataKey); - - /** - * 新たなResourceManagerインスタンスを構築します. - * - * @return ResourceManagerインスタンス - */ - static ResourceManager* create(); - -public: - ResourceManager(void); - virtual ~ResourceManager(); - -protected: - std::map _dataDic; -}; - /** diff --git a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp index 559d3d8..593d709 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp @@ -24,7 +24,9 @@ namespace ss { // read the file from hardware FILE *fp = fopen(pszFileName, pszMode); - SS_BREAK_IF(!fp); + if(!fp){ + break; + } fseek(fp,0,SEEK_END); *pSize = ftell(fp); diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp new file mode 100644 index 0000000..f5a20ab --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -0,0 +1,259 @@ +#include "SS5ResourceManager.h" +#include "SS5Player.h" +#include "common/SS5PlayerLibs/SS5PlayerToPointer.h" +#include "common/SS5PlayerLibs/SS5CellCache.h" +#include "common/SS5PlayerLibs/SS5AnimCache.h" +#include "common/SS5PlayerLibs/SS5EffectCache.h" +#include "common/SS5PlayerLibs/SS5ResourceSet.h" +#include "common/Helper/Util.h" + +namespace ss{ + +/** + * definition + */ +static const ss_u32 DATA_ID = 0x42505353; +static const ss_u32 DATA_VERSION = 4; + +/** + * utilites + */ +static void splitPath(std::string& directoty, std::string& filename, const std::string& path) +{ + std::string f = path; + std::string d = ""; + + size_t pos = path.find_last_of("/"); + if (pos == std::string::npos) pos = path.find_last_of("\\"); // for win + + if (pos != std::string::npos) + { + d = path.substr(0, pos + 1); + f = path.substr(pos + 1); + } + + directoty = d; + filename = f; +} + + + +static ResourceManager* s_defaultInstance = NULL; +const std::string ResourceManager::s_null; + +ResourceManager* ResourceManager::getInstance() +{ + if (!s_defaultInstance) + { + s_defaultInstance = ResourceManager::create(); + } + return s_defaultInstance; +} + +ResourceManager::ResourceManager(void) +{ +} + +ResourceManager::~ResourceManager() +{ + removeAllData(); +} + +ResourceManager* ResourceManager::create() +{ + ResourceManager* obj = new ResourceManager(); + return obj; +} + +ResourceSet* ResourceManager::getData(const std::string& dataKey) +{ + ResourceSet* rs = _dataDic.at(dataKey); + return rs; +} + +std::string ResourceManager::addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir) +{ + SS_ASSERT2(data != NULL, "Invalid data"); + SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); + SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); + + // imageBaseDirの指定がないときコンバート時に指定されたパスを使用する + std::string baseDir = imageBaseDir; + if (imageBaseDir == s_null && data->imageBaseDir) + { + ToPointer ptr(data); + const char* dir = ptr.toString(data->imageBaseDir); + baseDir = dir; + } + + //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある + CellCache* cellCache = CellCache::create(data, baseDir); + + EffectCache* effectCache = EffectCache::create(data, baseDir, cellCache); // + + AnimeCache* animeCache = AnimeCache::create(data); + + ResourceSet* rs = new ResourceSet(); + rs->data = data; + rs->isDataAutoRelease = false; + rs->cellCache = cellCache; + rs->animeCache = animeCache; + rs->effectCache = effectCache; + _dataDic.insert(std::map::value_type(dataKey, rs)); + + return dataKey; +} + +std::string ResourceManager::addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir) +{ + + std::string fullpath = ssbpFilepath; + + unsigned long nSize = 0; + void* loadData = SSFileOpen(fullpath.c_str(), "rb", &nSize); + if (loadData == NULL) + { + std::string msg = "Can't load project data > " + fullpath; + SS_ASSERT2(loadData != NULL, msg.c_str()); + } + + const ProjectData* data = static_cast(loadData); + SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); + SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); + + std::string baseDir = imageBaseDir; + if (imageBaseDir == s_null) + { + // imageBaseDirの指定がないとき + if (data->imageBaseDir) + { + // コンバート時に指定されたパスを使用する + ToPointer ptr(data); + const char* dir = ptr.toString(data->imageBaseDir); + baseDir = dir; + } + else + { + // プロジェクトファイルと同じディレクトリを指定する + std::string directory; + std::string filename; + splitPath(directory, filename, ssbpFilepath); + baseDir = directory; + } + //SSLOG("imageBaseDir: %s", baseDir.c_str()); + } + + addData(dataKey, data, baseDir); + + // リソースが破棄されるとき一緒にロードしたデータも破棄する + ResourceSet* rs = getData(dataKey); + SS_ASSERT2(rs != NULL, ""); + rs->isDataAutoRelease = true; + + return dataKey; +} + +std::string ResourceManager::addData(const std::string& ssbpFilepath, const std::string& imageBaseDir) +{ + // ファイル名を取り出す + std::string directory; + std::string filename; + splitPath(directory, filename, ssbpFilepath); + + // 拡張子を取る + std::string dataKey = filename; + size_t pos = filename.find_last_of("."); + if (pos != std::string::npos) + { + dataKey = filename.substr(0, pos); + } + + //登録されている名前か判定する + std::map::iterator it = _dataDic.find(dataKey); + if (it != _dataDic.end()) + { + //登録されている場合は処理を行わない + std::string str = ""; + return str; + } + + return addDataWithKey(dataKey, ssbpFilepath, imageBaseDir); +} + +void ResourceManager::removeData(const std::string& dataKey) +{ + ResourceSet* rs = getData(dataKey); + + //テクスチャの解放 + releseTexture(dataKey); + + //バイナリデータの削除 + delete rs; + _dataDic.erase(dataKey); +} + +void ResourceManager::removeAllData() +{ + //全リソースの解放 + while (!_dataDic.empty()) + { + std::map::iterator it = _dataDic.begin(); + std::string ssbpName = it->first; + removeData(ssbpName); + } + _dataDic.clear(); +} + +//データ名、セル名を指定して、セルで使用しているテクスチャを変更する +bool ResourceManager::changeTexture(char* ssbpName, char* ssceName, long texture) +{ + bool rc = false; + + ResourceSet* rs = getData(ssbpName); + rc = rs->cellCache->setCellRefTexture(rs->data, ssceName, texture); + + return(rc); +} + +//指定したデータのテクスチャを破棄します +bool ResourceManager::releseTexture(std::string ssbpName) +{ + + ResourceSet* rs = getData(ssbpName); + bool rc = rs->cellCache->releseTexture(rs->data); + + return(rc); +} + +//アニメーションの総フレーム数を取得する +int ResourceManager::getMaxFrame(std::string ssbpName, std::string animeName) +{ + int rc = -1; + + ResourceSet* rs = getData(ssbpName); + AnimeRef* animeRef = rs->animeCache->getReference(animeName); + if (animeRef == NULL) + { + std::string msg = Format("Not found animation > anime=%s", animeName.c_str()); + SS_ASSERT2(animeRef != NULL, msg.c_str()); + } + rc = animeRef->animationData->numFrames; + + return(rc); +} + +//ssbpファイルが登録されているかを調べる +bool ResourceManager::isDataKeyExists(const std::string& dataKey) { + // 登録されている名前か判定する + std::map::iterator it = _dataDic.find(dataKey); + if (it != _dataDic.end()) { + //登録されている + return true; + } + + return false; +} + + +} //namespace ss + diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h new file mode 100644 index 0000000..38e082e --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h @@ -0,0 +1,120 @@ +#pragma once +#include +#include + +namespace ss{ +struct ProjectData; +class ResourceSet; + +/** + * ResourceManager + */ +class ResourceManager{ +public: + static const std::string s_null; + + /** + * デフォルトインスタンスを取得します. + * + * @return デフォルトのResourceManagerインスタンス + */ + static ResourceManager* getInstance(); + + /** + * ssbpファイルを読み込み管理対象とします. + * dataKeyはssbpのファイル名(拡張子なし)になります. + * + * @param ssbpFilepath ssbpファイルのパス + * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. + * @return dataKey + */ + std::string addData(const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); + + /** + * ssbpファイルを読み込み管理対象とします. + * + * @param dataKey dataKeyの指定 + * @param ssbpFilepath ssbpファイルのパス + * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. + * @return dataKey + */ + std::string addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); + + /** + * 指定されたssbpデータを管理対象とします. + * + * @param dataKey dataKeyの指定 + * @param data ssbpデータ + * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. + * @return dataKey + */ + std::string addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir = s_null); + + /** + * 指定データを解放します. + * パス、拡張子を除いたssbp名を指定してください。 + * + * @param dataKey + */ + void removeData(const std::string& dataKey); + + /** + * 全てのデータを解放します. + */ + void removeAllData(); + + /** + * 名前に対応するデータ取得します. + */ + ResourceSet* getData(const std::string& dataKey); + + /** + * 指定したセルのテクスチャを変更します. + * @param ssbpName ssbp名(拡張子を除くファイル名) + * @param ssceName ssce名(拡張子を除くファイル名) + * @param texture 変更後のテクスチャハンドル + * @return 変更を行ったか + */ + bool changeTexture(char* ssbpName, char* ssceName, long texture); + + /** + * 指定したデータのテクスチャを破棄します。 + * @param dataName ssbp名(拡張子を除くファイル名) + * @return 成功失敗 + */ + bool releseTexture(std::string); + + /** + * 読み込んでいるssbpからアニメーションの総フレーム数を取得します。 + * @param ssbpName ssbp名(拡張子を除くファイル名) + * @param animeName ssae/モーション名 + * @return アニメーションの総フレーム(存在しない場合はアサート) + */ + int getMaxFrame(std::string ssbpName, std::string animeName); + + /** + * 名前が登録されていればtrueを返します + * + * @param dataKey + * @return + */ + bool isDataKeyExists(const std::string& dataKey); + + /** + * 新たなResourceManagerインスタンスを構築します. + * + * @return ResourceManagerインスタンス + */ + static ResourceManager* create(); + +public: + ResourceManager(void); + virtual ~ResourceManager(); + +protected: + std::map _dataDic; +}; + + +} //namespace ss + diff --git a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h new file mode 100644 index 0000000..c17a288 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h @@ -0,0 +1,70 @@ +#pragma once +#include +#include +#include + +/** + * 定数 + */ + +#define __SSPI__ (3.14159265358979323846f) +#define __SS2PI__ (__SSPI__ * 2) + +#define SS_SAFE_DELETE(p) do { if(p) { delete (p); (p) = 0; } } while(0) +#define SS_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = 0; } } while(0) +#define SS_SAFE_FREE(p) do { if(p) { free(p); (p) = 0; } } while(0) +#define SS_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) +#define SS_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = 0; } } while(0) +#define SS_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) + +#ifdef _DEBUG + #define SSLOG(...) do {} while (0) + #define SS_ASSERT(cond) assert(cond) + #define SS_ASSERT2(cond, msg) SS_ASSERT(cond) + #define SSLOGERROR(format,...) do {} while (0) +#else + #define SSLOG(...) do {} while (0) + #define SS_ASSERT(cond) + #define SS_ASSERT2(cond, msg) ((void)(cond)) + #define SSLOGERROR(format,...) do {} while (0) +#endif + + + +namespace ss{ + + +// printf 形式のフォーマット +#ifndef va_copy +# define va_copy(dest, src) ((dest) = (src)) +#endif +static std::string Format(const char* format, ...){ + + static std::vector tmp(1000); + + va_list args, source; + va_start(args, format); + va_copy(source, args); + + while (1) + { + va_copy(args, source); + //Windows + if (_vsnprintf(&tmp[0], tmp.size(), format, args) == -1) + { + tmp.resize(tmp.size() * 2); + } + else + { + break; + } + } + tmp.push_back('\0'); + std::string ret = &(tmp[0]); + va_end(args); + return ret; +} + + + +} //namespace sss diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index 50e58f6..a5176ec 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -1,5 +1,6 @@ #include "DxLib.h" #include "SSPlayer/SS5Player.h" +#include "SSPlayer/SS5ResourceManager.h" static int previousTime; static int waitTime; From 2b16f32527d3031c3ab3d1d4b1f28ad58a66d593 Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:05:29 +0900 Subject: [PATCH 07/20] =?UTF-8?q?=E4=BE=BF=E5=88=A9=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/common/Helper/Util.h | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h index c17a288..b36a98a 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h @@ -67,4 +67,33 @@ static std::string Format(const char* format, ...){ +//配列のサイズを返す +template +size_t lengthof(const TYPE(&ar)[N]){ + return N; +} + +//[minVal:maxVal]の範囲にする +template +T clamp(T val, T minVal, T maxVal){ + assert(minVal <= maxVal); + return std::min(std::max(val, minVal), maxVal); +} + +//[minVal:maxVal)の範囲でループさせる +template +T wrap(T val, T minVal, T maxVal){ + assert(minVal < maxVal); + int n = (val - minVal) % (maxVal - minVal); + return (n >= 0) ? (n + minVal) : (n + maxVal); +} + +template +T fwrap(T val, T minVal, T maxVal){ + assert(minVal < maxVal); + double n = fmod(val - minVal, maxVal - minVal); + return (n >= 0) ? (n + minVal) : (n + maxVal); +} + + } //namespace sss From 1512ab437523566b88b0230845a79156bdfb407e Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:07:26 +0900 Subject: [PATCH 08/20] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E3=83=9E?= =?UTF-8?q?=E3=82=AF=E3=83=AD=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h index b36a98a..9dfd8c4 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h @@ -12,10 +12,6 @@ #define SS_SAFE_DELETE(p) do { if(p) { delete (p); (p) = 0; } } while(0) #define SS_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = 0; } } while(0) -#define SS_SAFE_FREE(p) do { if(p) { free(p); (p) = 0; } } while(0) -#define SS_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) -#define SS_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = 0; } } while(0) -#define SS_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) #ifdef _DEBUG #define SSLOG(...) do {} while (0) From 37951f22c3711bcd44efb6ee8dc15ed2275b963f Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:26:02 +0900 Subject: [PATCH 09/20] =?UTF-8?q?CustomSprite=E5=88=86=E9=9B=A2=20=5Fvsnpr?= =?UTF-8?q?intf=E3=82=92=5Fvsnprintf=5Fs=E3=81=AB=E7=BD=AE=E3=81=8D?= =?UTF-8?q?=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 63 +------ samples/DXLibrary/basic/SSPlayer/SS5Player.h | 153 ----------------- .../common/Animator/ssplayer_PartState.h | 1 + .../common/Animator/ssplayer_effect.cpp | 1 + .../common/Animator/ssplayer_effect2.cpp | 1 + .../basic/SSPlayer/common/Helper/Util.h | 2 +- .../common/SS5PlayerLibs/SS5CustomSprite.cpp | 70 ++++++++ .../common/SS5PlayerLibs/SS5CustomSprite.h | 162 ++++++++++++++++++ 8 files changed, 237 insertions(+), 216 deletions(-) create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.cpp create mode 100644 samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.h diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 0486a01..d1d6497 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -11,6 +11,7 @@ #include "common/SS5PlayerLibs/SS5AnimCache.h" #include "common/SS5PlayerLibs/SS5EffectCache.h" #include "common/SS5PlayerLibs/SS5ResourceSet.h" +#include "common/SS5PlayerLibs/SS5CustomSprite.h" #include "common/Helper/Util.h" #include "common/Animator/ssplayer_matrix.h" #include "common/Animator/ssplayer_macro.h" @@ -2118,67 +2119,5 @@ void Player::update_matrix_ss4(CustomSprite *sprite, CustomSprite *parent, const } -/** - * CustomSprite - */ - //カラーブレンド用のシェーダー処理は汎用的に使用する事ができないためすべてコメントにしてあります。 - //カラーブレンドを再現するための参考にしてください。 - -//static const GLchar * ssPositionTextureColor_frag = -//#include "ssShader_frag.h" - -CustomSprite::CustomSprite(): -// : _defaultShaderProgram(NULL) - _useCustomShaderProgram(false) - , _opacity(1.0f) - , _colorBlendFuncNo(0) - , _liveFrame(0.0f) - , _hasPremultipliedAlpha(0) - , refEffect(0) - , _ssplayer(0) - ,effectAttrInitialized(false) - ,effectTimeTotal(0) -{ - _temp_position = SsVector3(0, 0, 0); - _temp_rotation = SsVector3(0, 0, 0); - _temp_scale = SsVector2(1.0f, 1.0f); -} - -CustomSprite::~CustomSprite() -{ - //エフェクトクラスがある場合は解放する - SS_SAFE_DELETE(refEffect); - SS_SAFE_DELETE(_ssplayer); -} - -CustomSprite* CustomSprite::create() -{ - CustomSprite *pSprite = new CustomSprite(); - if (pSprite) - { - pSprite->initState(); - return pSprite; - } - SS_SAFE_DELETE(pSprite); - return NULL; -} - -void CustomSprite::setFlippedX(bool flip) -{ - _flipX = flip; -} -void CustomSprite::setFlippedY(bool flip) -{ - _flipY = flip; -} -bool CustomSprite::isFlippedX() -{ - return (_flipX); -} -bool CustomSprite::isFlippedY() -{ - return (_flipY); -} - }; diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.h b/samples/DXLibrary/basic/SSPlayer/SS5Player.h index aa15489..c7a596d 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.h @@ -112,159 +112,6 @@ extern void get_uv_rotation(float *u, float *v, float cu, float cv, float deg); -/** -* CustomSprite -*/ -class CustomSprite -{ -private: - bool _useCustomShaderProgram; - float _opacity; - int _hasPremultipliedAlpha; - int _colorBlendFuncNo; - bool _flipX; - bool _flipY; - -public: - SSMatrix _mat; - State _state; - bool _isStateChanged; - CustomSprite* _parent; - Player* _ssplayer; - float _liveFrame; - - //エフェクト用パラメータ - SsEffectRenderV2* refEffect; - SsPartState partState; - - //モーションブレンド用ステータス - State _orgState; - - //エフェクト制御用ワーク - bool effectAttrInitialized; - float effectTimeTotal; - - //Ver4互換用ワーク - SsVector3 _temp_position; - SsVector3 _temp_rotation; - SsVector2 _temp_scale; - -public: - CustomSprite(); - virtual ~CustomSprite(); - - static CustomSprite* create(); - - void initState() - { - _state.init(); - _isStateChanged = true; - } - - void setStateValue(float& ref, float value) - { - if (ref != value) - { - ref = value; - _isStateChanged = true; - } - } - - void setStateValue(int& ref, int value) - { - if (ref != value) - { - ref = value; - _isStateChanged = true; - } - } - - void setStateValue(bool& ref, bool value) - { - if (ref != value) - { - ref = value; - _isStateChanged = true; - } - } - - void setStateValue(SSV3F_C4B_T2F_Quad& ref, SSV3F_C4B_T2F_Quad value) - { - // if (ref != value) - { - ref = value; - _isStateChanged = true; - } - } - - void setState(const State& state) - { - setStateValue(_state.flags, state.flags); - setStateValue(_state.cellIndex, state.cellIndex); - setStateValue(_state.x, state.x); - setStateValue(_state.y, state.y); - setStateValue(_state.z, state.z); - setStateValue(_state.pivotX, state.pivotX); - setStateValue(_state.pivotY, state.pivotY); - setStateValue(_state.rotationX, state.rotationX); - setStateValue(_state.rotationY, state.rotationY); - setStateValue(_state.rotationZ, state.rotationZ); - setStateValue(_state.scaleX, state.scaleX); - setStateValue(_state.scaleY, state.scaleY); - setStateValue(_state.opacity, state.opacity); - setStateValue(_state.size_X, state.size_X); - setStateValue(_state.size_Y, state.size_Y); - setStateValue(_state.uv_move_X, state.uv_move_X); - setStateValue(_state.uv_move_Y, state.uv_move_Y); - setStateValue(_state.uv_rotation, state.uv_rotation); - setStateValue(_state.uv_scale_X, state.uv_scale_X); - setStateValue(_state.uv_scale_Y, state.uv_scale_Y); - setStateValue(_state.boundingRadius, state.boundingRadius); - setStateValue(_state.isVisibled, state.isVisibled); - setStateValue(_state.flipX, state.flipX); - setStateValue(_state.flipY, state.flipY); - setStateValue(_state.blendfunc, state.blendfunc); - setStateValue(_state.colorBlendFunc, state.colorBlendFunc); - setStateValue(_state.colorBlendType, state.colorBlendType); - - setStateValue(_state.quad, state.quad); - _state.texture = state.texture; - _state.rect = state.rect; - _state.mat = state.mat; - - setStateValue(_state.instanceValue_curKeyframe, state.instanceValue_curKeyframe); - setStateValue(_state.instanceValue_startFrame, state.instanceValue_startFrame); - setStateValue(_state.instanceValue_endFrame, state.instanceValue_endFrame); - setStateValue(_state.instanceValue_loopNum, state.instanceValue_loopNum); - setStateValue(_state.instanceValue_speed, state.instanceValue_speed); - setStateValue(_state.instanceValue_loopflag, state.instanceValue_loopflag); - setStateValue(_state.effectValue_curKeyframe, state.effectValue_curKeyframe); - setStateValue(_state.effectValue_startTime, state.effectValue_startTime); - setStateValue(_state.effectValue_speed, state.effectValue_speed); - setStateValue(_state.effectValue_loopflag, state.effectValue_loopflag); - - _state.Calc_rotationX = state.Calc_rotationX; - _state.Calc_rotationY = state.Calc_rotationY; - _state.Calc_rotationZ = state.Calc_rotationZ; - _state.Calc_scaleX = state.Calc_scaleX; - _state.Calc_scaleY = state.Calc_scaleY; - _state.Calc_opacity = state.Calc_opacity; - - } - - - // original functions - void setFlippedX(bool flip); - void setFlippedY(bool flip); - bool isFlippedX(); - bool isFlippedY(); - -public: -}; - - - - /** * UserData */ diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_PartState.h b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_PartState.h index 3d40e93..45b4205 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_PartState.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_PartState.h @@ -3,6 +3,7 @@ //#include "../loader/ssloader.h" //#include "../Helper/ssHelper.h" +#include "common/Loader/sstypes.h" namespace ss { diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect.cpp b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect.cpp index a15f545..cba0373 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect.cpp @@ -9,6 +9,7 @@ #include "ssplayer_effectfunction.h" #include "../../SS5PlayerPlatform.h" +#include "common/SS5PlayerLibs/SS5CustomSprite.h" namespace ss diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect2.cpp b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect2.cpp index ad2eb03..b02129d 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect2.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_effect2.cpp @@ -10,6 +10,7 @@ #include "ssplayer_effectfunction.h" #include "../../SS5PlayerPlatform.h" +#include "common/SS5PlayerLibs/SS5CustomSprite.h" #define DEBUG_DISP (0) diff --git a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h index 9dfd8c4..7f00a1f 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h @@ -46,7 +46,7 @@ static std::string Format(const char* format, ...){ { va_copy(args, source); //Windows - if (_vsnprintf(&tmp[0], tmp.size(), format, args) == -1) + if (_vsnprintf_s(&tmp[0], tmp.size(), _TRUNCATE, format, args) == -1) { tmp.resize(tmp.size() * 2); } diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.cpp new file mode 100644 index 0000000..41b4584 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.cpp @@ -0,0 +1,70 @@ +#include "SS5CustomSprite.h" +#include "common/Helper/Util.h" + +namespace ss{ + + +/** + * CustomSprite + */ +//カラーブレンド用のシェーダー処理は汎用的に使用する事ができないためすべてコメントにしてあります。 +//カラーブレンドを再現するための参考にしてください。 + +//static const GLchar * ssPositionTextureColor_frag = +//#include "ssShader_frag.h" + +CustomSprite::CustomSprite() : +// : _defaultShaderProgram(NULL) +_useCustomShaderProgram(false) +, _opacity(1.0f) +, _colorBlendFuncNo(0) +, _liveFrame(0.0f) +, _hasPremultipliedAlpha(0) +, refEffect(0) +, _ssplayer(0) +, effectAttrInitialized(false) +, effectTimeTotal(0) +{ + _temp_position = SsVector3(0, 0, 0); + _temp_rotation = SsVector3(0, 0, 0); + _temp_scale = SsVector2(1.0f, 1.0f); +} + +CustomSprite::~CustomSprite() +{ + //エフェクトクラスがある場合は解放する + SS_SAFE_DELETE(refEffect); + SS_SAFE_DELETE(_ssplayer); +} + +CustomSprite* CustomSprite::create() +{ + CustomSprite *pSprite = new CustomSprite(); + if (pSprite) + { + pSprite->initState(); + return pSprite; + } + SS_SAFE_DELETE(pSprite); + return NULL; +} + +void CustomSprite::setFlippedX(bool flip) +{ + _flipX = flip; +} +void CustomSprite::setFlippedY(bool flip) +{ + _flipY = flip; +} +bool CustomSprite::isFlippedX() +{ + return (_flipX); +} +bool CustomSprite::isFlippedY() +{ + return (_flipY); +} + + +} //namespace ss diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.h new file mode 100644 index 0000000..9c98d8c --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CustomSprite.h @@ -0,0 +1,162 @@ +#pragma once +#include "common/Animator/ssplayer_matrix.h" +#include "common/SS5PlayerLibs/SS5PlayerPartState.h" +#include "common/Animator/ssplayer_PartState.h" +#include "common/Loader/sstypes.h" + +namespace ss{ +class Player; +class SsEffectRenderV2; + +/** + * CustomSprite + */ +class CustomSprite +{ +private: + bool _useCustomShaderProgram; + float _opacity; + int _hasPremultipliedAlpha; + int _colorBlendFuncNo; + bool _flipX; + bool _flipY; + +public: + SSMatrix _mat; + State _state; + bool _isStateChanged; + CustomSprite* _parent; + Player* _ssplayer; + float _liveFrame; + + //エフェクト用パラメータ + SsEffectRenderV2* refEffect; + SsPartState partState; + + //モーションブレンド用ステータス + State _orgState; + + //エフェクト制御用ワーク + bool effectAttrInitialized; + float effectTimeTotal; + + //Ver4互換用ワーク + SsVector3 _temp_position; + SsVector3 _temp_rotation; + SsVector2 _temp_scale; + +public: + CustomSprite(); + virtual ~CustomSprite(); + + static CustomSprite* create(); + + void initState() + { + _state.init(); + _isStateChanged = true; + } + + void setStateValue(float& ref, float value) + { + if (ref != value) + { + ref = value; + _isStateChanged = true; + } + } + + void setStateValue(int& ref, int value) + { + if (ref != value) + { + ref = value; + _isStateChanged = true; + } + } + + void setStateValue(bool& ref, bool value) + { + if (ref != value) + { + ref = value; + _isStateChanged = true; + } + } + + void setStateValue(SSV3F_C4B_T2F_Quad& ref, SSV3F_C4B_T2F_Quad value) + { + // if (ref != value) + { + ref = value; + _isStateChanged = true; + } + } + + void setState(const State& state) + { + setStateValue(_state.flags, state.flags); + setStateValue(_state.cellIndex, state.cellIndex); + setStateValue(_state.x, state.x); + setStateValue(_state.y, state.y); + setStateValue(_state.z, state.z); + setStateValue(_state.pivotX, state.pivotX); + setStateValue(_state.pivotY, state.pivotY); + setStateValue(_state.rotationX, state.rotationX); + setStateValue(_state.rotationY, state.rotationY); + setStateValue(_state.rotationZ, state.rotationZ); + setStateValue(_state.scaleX, state.scaleX); + setStateValue(_state.scaleY, state.scaleY); + setStateValue(_state.opacity, state.opacity); + setStateValue(_state.size_X, state.size_X); + setStateValue(_state.size_Y, state.size_Y); + setStateValue(_state.uv_move_X, state.uv_move_X); + setStateValue(_state.uv_move_Y, state.uv_move_Y); + setStateValue(_state.uv_rotation, state.uv_rotation); + setStateValue(_state.uv_scale_X, state.uv_scale_X); + setStateValue(_state.uv_scale_Y, state.uv_scale_Y); + setStateValue(_state.boundingRadius, state.boundingRadius); + setStateValue(_state.isVisibled, state.isVisibled); + setStateValue(_state.flipX, state.flipX); + setStateValue(_state.flipY, state.flipY); + setStateValue(_state.blendfunc, state.blendfunc); + setStateValue(_state.colorBlendFunc, state.colorBlendFunc); + setStateValue(_state.colorBlendType, state.colorBlendType); + + setStateValue(_state.quad, state.quad); + _state.texture = state.texture; + _state.rect = state.rect; + _state.mat = state.mat; + + setStateValue(_state.instanceValue_curKeyframe, state.instanceValue_curKeyframe); + setStateValue(_state.instanceValue_startFrame, state.instanceValue_startFrame); + setStateValue(_state.instanceValue_endFrame, state.instanceValue_endFrame); + setStateValue(_state.instanceValue_loopNum, state.instanceValue_loopNum); + setStateValue(_state.instanceValue_speed, state.instanceValue_speed); + setStateValue(_state.instanceValue_loopflag, state.instanceValue_loopflag); + setStateValue(_state.effectValue_curKeyframe, state.effectValue_curKeyframe); + setStateValue(_state.effectValue_startTime, state.effectValue_startTime); + setStateValue(_state.effectValue_speed, state.effectValue_speed); + setStateValue(_state.effectValue_loopflag, state.effectValue_loopflag); + + _state.Calc_rotationX = state.Calc_rotationX; + _state.Calc_rotationY = state.Calc_rotationY; + _state.Calc_rotationZ = state.Calc_rotationZ; + _state.Calc_scaleX = state.Calc_scaleX; + _state.Calc_scaleY = state.Calc_scaleY; + _state.Calc_opacity = state.Calc_opacity; + + } + + + // original functions + void setFlippedX(bool flip); + void setFlippedY(bool flip); + bool isFlippedX(); + bool isFlippedY(); + +public: +}; + +} //namespace ss + From b36c092f19315ae598088321e8292708f48576ff Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:38:18 +0900 Subject: [PATCH 10/20] =?UTF-8?q?new=E3=82=92=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E7=AE=87=E6=89=80=E3=82=92=E6=98=8E=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=80=81Create?= =?UTF-8?q?=E3=82=92=E5=BB=83=E6=AD=A2=E3=81=97=E3=81=A6=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88=E3=83=A9=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=81=AB=E4=BB=BB=E3=81=9B=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5ResourceManager.cpp | 6 +++--- .../common/SS5PlayerLibs/SS5AnimCache.cpp | 14 ++------------ .../SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h | 3 +-- .../common/SS5PlayerLibs/SS5CellCache.cpp | 13 ++----------- .../SSPlayer/common/SS5PlayerLibs/SS5CellCache.h | 4 +--- .../common/SS5PlayerLibs/SS5EffectCache.cpp | 15 ++------------- .../common/SS5PlayerLibs/SS5EffectCache.h | 5 ++--- 7 files changed, 13 insertions(+), 47 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index f5a20ab..fa25f59 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -87,11 +87,11 @@ std::string ResourceManager::addData(const std::string& dataKey, const ProjectDa } //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある - CellCache* cellCache = CellCache::create(data, baseDir); + CellCache* cellCache = new CellCache(data, baseDir); - EffectCache* effectCache = EffectCache::create(data, baseDir, cellCache); // + EffectCache* effectCache = new EffectCache(data, baseDir, cellCache); // - AnimeCache* animeCache = AnimeCache::create(data); + AnimeCache* animeCache = new AnimeCache(data); ResourceSet* rs = new ResourceSet(); rs->data = data; diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp index f64a798..ce24709 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp @@ -5,19 +5,9 @@ namespace ss{ -AnimeCache* AnimeCache::create(const ProjectData* data) -{ - AnimeCache* obj = new AnimeCache(); - if (obj) - { - obj->init(data); - } - return obj; -} - - -AnimeCache::AnimeCache() +AnimeCache::AnimeCache(const ProjectData* data) { + init(data); } AnimeCache::~AnimeCache() diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h index bd67e92..069affb 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h @@ -23,9 +23,8 @@ struct AnimeRef{ */ class AnimeCache{ public: - AnimeCache(); + AnimeCache(const ProjectData* data); ~AnimeCache(); - static AnimeCache* create(const ProjectData* data); /** * packNameとanimeNameを指定してAnimeRefを得る diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp index 4496fd8..9fd328b 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp @@ -6,18 +6,9 @@ namespace ss{ -CellCache* CellCache::create(const ProjectData* data, const std::string& imageBaseDir) -{ - CellCache* obj = new CellCache(); - if (obj){ - obj->init(data, imageBaseDir); - } - return obj; -} - - -CellCache::CellCache() +CellCache::CellCache(const ProjectData* data, const std::string& imageBaseDir) { + init(data, imageBaseDir); } CellCache::~CellCache() diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h index 2d0d93e..d9de293 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h @@ -26,10 +26,8 @@ struct CellRef{ */ class CellCache{ public: - CellCache(); + CellCache(const ProjectData* data, const std::string& imageBaseDir); ~CellCache(); - - static CellCache* create(const ProjectData* data, const std::string& imageBaseDir); CellRef* getReference(int index); diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp index 5c07505..fac4180 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp @@ -7,20 +7,9 @@ namespace ss{ -EffectCache* EffectCache::create(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) -{ - EffectCache* obj = new EffectCache(); - if (obj) - { - obj->init(data, imageBaseDir, cellCache); - // obj->autorelease(); - } - return obj; -} - - -EffectCache::EffectCache() +EffectCache::EffectCache(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) { + init(data, imageBaseDir, cellCache); } EffectCache::~EffectCache() diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h index d325fcd..7ec795c 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h @@ -12,10 +12,9 @@ class CellCache; */ class EffectCache{ public: - EffectCache(); + EffectCache(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache); ~EffectCache(); - static EffectCache* create(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache); - + /** * エフェクトファイル名を指定してEffectRefを得る */ From 7d603983ffdbe669309a0ae2143d39facce0a47d Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 16:54:50 +0900 Subject: [PATCH 11/20] =?UTF-8?q?=E3=83=A1=E3=83=A2=E3=83=AA=E3=83=AA?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=81=AE=E3=83=81=E3=82=A7=E3=83=83=E3=82=AB?= =?UTF-8?q?=E3=83=BC=E3=82=92=E4=BB=95=E8=BE=BC=E3=81=BF=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/DXLibrary/basic/sssample.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index a5176ec..9fe3ba5 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -2,6 +2,14 @@ #include "SSPlayer/SS5Player.h" #include "SSPlayer/SS5ResourceManager.h" +//メモリリークチェック用--------------------------------------------------------- +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#define new new(_NORMAL_BLOCK, __FILE__, __LINE__) +#endif +//----------------------------------------------------------------------------- + static int previousTime; static int waitTime; int mGameExec; @@ -22,6 +30,11 @@ ss::ResourceManager *resman; */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + //メモリリークチェック用 +#ifdef _DEBUG + _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF); +#endif + //DXライブラリの初期化 ChangeWindowMode(true); //ウインドウモード SetGraphMode(800, 600, GetColorBitDepth() ); From 793cb2ba3ab6c1e1b29a75513b8c47b4386f449e Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 17:00:09 +0900 Subject: [PATCH 12/20] =?UTF-8?q?AddData=E3=81=AE=E7=9B=B4=E5=BE=8C?= =?UTF-8?q?=E3=81=A7=E5=BF=85=E3=81=9Atrue=E3=81=AB=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81ResourceSet::isDataAutoRelease?= =?UTF-8?q?=E3=81=AF=E5=BB=83=E6=AD=A2=E3=81=97=E3=81=BE=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp | 2 -- .../basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h | 9 +++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index fa25f59..38793f7 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -95,7 +95,6 @@ std::string ResourceManager::addData(const std::string& dataKey, const ProjectDa ResourceSet* rs = new ResourceSet(); rs->data = data; - rs->isDataAutoRelease = false; rs->cellCache = cellCache; rs->animeCache = animeCache; rs->effectCache = effectCache; @@ -148,7 +147,6 @@ std::string ResourceManager::addDataWithKey(const std::string& dataKey, const st // リソースが破棄されるとき一緒にロードしたデータも破棄する ResourceSet* rs = getData(dataKey); SS_ASSERT2(rs != NULL, ""); - rs->isDataAutoRelease = true; return dataKey; } diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h index 450d6b6..538e47a 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -13,18 +13,15 @@ namespace ss{ class ResourceSet{ public: const ProjectData* data; - bool isDataAutoRelease; EffectCache* effectCache; CellCache* cellCache; AnimeCache* animeCache; virtual ~ResourceSet() { - if (isDataAutoRelease) - { - delete data; - data = NULL; - } + delete data; + data = NULL; + if (animeCache) { delete animeCache; From 2d2a92ce94c5803fa4f548ac353068bfed15f78c Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 17:09:47 +0900 Subject: [PATCH 13/20] =?UTF-8?q?ResourceSet=E3=81=AE=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=90=E3=81=ABprefix=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 42 +++++++++---------- .../basic/SSPlayer/SS5ResourceManager.cpp | 14 +++---- .../common/SS5PlayerLibs/SS5ResourceSet.h | 32 +++++++------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index d1d6497..4469f6a 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -225,11 +225,11 @@ void Player::setData(const std::string& dataKey) _rootPartFunctionAsVer4 = false; _dontUseMatrixForTransform = false; #ifdef USE_VER4TRANSFORM - if ((rs->data->flags & HEAD_FLAG_rootPartFunctionAsVer4) != 0) + if ((rs->m_data->flags & HEAD_FLAG_rootPartFunctionAsVer4) != 0) { _rootPartFunctionAsVer4 = true; //不透明度・反転・非表示アトリビュートの継承方法をVer.4と同様にする } - if ((rs->data->flags & HEAD_FLAG_dontUseMatrixForTransform) != 0) + if ((rs->m_data->flags & HEAD_FLAG_dontUseMatrixForTransform) != 0) { _dontUseMatrixForTransform = true; //親子の座標変換にマトリックスを使用しない(Ver4互換) } @@ -257,7 +257,7 @@ void Player::play(const std::string& animeName, int loop, int startFrameNo) { SS_ASSERT2(_currentRs != NULL, "Not select data"); - AnimeRef* animeRef = _currentRs->animeCache->getReference(animeName); + AnimeRef* animeRef = _currentRs->m_animeCache->getReference(animeName); if (animeRef == NULL) { std::string msg = Format("Not found animation > anime=%s", animeName.c_str()); @@ -361,7 +361,7 @@ void Player::update(float dt) void Player::updateFrame(float dt) { if (!_currentAnimeRef) return; - if (!_currentRs->data) return; + if (!_currentRs->m_data) return; int startFrame = 0; int endFrame = _currentAnimeRef->animationData->numFrames; @@ -531,7 +531,7 @@ void Player::releaseParts() if (_currentAnimeRef) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); if (_parts.size() > 0) @@ -552,7 +552,7 @@ void Player::setPartsParentage() { if (!_currentAnimeRef) return; - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); @@ -595,7 +595,7 @@ void Player::setPartsParentage() std::string refeffectName = ptr.toString(partData->effectfilename); if (refeffectName != "") { - SsEffectModel* effectmodel = _currentRs->effectCache->getReference(refeffectName); + SsEffectModel* effectmodel = _currentRs->m_effectCache->getReference(refeffectName); if (effectmodel) { //エフェクトクラスにパラメータを設定する @@ -617,7 +617,7 @@ void Player::setPartsParentage() //再生しているアニメーションに含まれるパーツ数を取得 int Player::getPartsCount(void) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; return packData->numParts; } @@ -625,7 +625,7 @@ int Player::getPartsCount(void) //indexからパーツ名を取得 const char* Player::getPartName(int partId) const { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; SS_ASSERT2(partId >= 0 && partId < packData->numParts, "partId is out of range."); @@ -677,7 +677,7 @@ bool Player::getPartState(ResluteState& result, const char* name, int frameNo) setFrame(frameNo); } - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); @@ -800,7 +800,7 @@ int Player::getLabelToFrame(char* findLabelName) { int rc = -1; - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimationData* animeData = _currentAnimeRef->animationData; if (!animeData->labelData) return -1; @@ -840,7 +840,7 @@ void Player::setPartVisible(std::string partsname, bool flg) bool rc = false; if (_currentAnimeRef) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); @@ -866,17 +866,17 @@ void Player::setPartCell(std::string partsname, std::string sscename, std::strin bool rc = false; if (_currentAnimeRef) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); int changeCellIndex = -1; if ((sscename != "") && (cellname != "")) { //セルマップIDを取得する - const Cell* cells = ptr.toCell(_currentRs->data); + const Cell* cells = ptr.toCell(_currentRs->m_data); //名前からインデックスの取得 int cellindex = -1; - for (int i = 0; i < _currentRs->data->numCells; i++) + for (int i = 0; i < _currentRs->m_data->numCells; i++) { const Cell* cell = &cells[i]; const char* name1 = ptr.toString(cell->name); @@ -919,7 +919,7 @@ bool Player::changeInstanceAnime(std::string partsname, std::string animename, b bool rc = false; if (_currentAnimeRef) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); @@ -1028,7 +1028,7 @@ int Player::getDrawSpriteCount(void) void Player::setFrame(int frameNo, float dt) { if (!_currentAnimeRef) return; - if (!_currentRs->data) return; + if (!_currentRs->m_data) return; bool forceUpdate = false; { @@ -1045,7 +1045,7 @@ void Player::setFrame(int frameNo, float dt) //インスタンスアニメがあるので毎フレーム更新するためコメントに変更 // if (!forceUpdate && frameNo == _prevDrawFrameNo) return; - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const PartData* parts = ptr.toPartData(packData); @@ -1148,7 +1148,7 @@ void Player::setFrame(int frameNo, float dt) } //セルの原点設定を反映させる - CellRef* cellRef = cellIndex >= 0 ? _currentRs->cellCache->getReference(cellIndex) : nullptr; + CellRef* cellRef = cellIndex >= 0 ? _currentRs->m_cellCache->getReference(cellIndex) : nullptr; if (cellRef) { float cpx = 0; @@ -1823,7 +1823,7 @@ void Player::draw() if (!_currentAnimeRef) return; _draw_count = 0; //表示スプライト数クリア - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; for (int index = 0; index < packData->numParts; index++) @@ -1869,7 +1869,7 @@ void Player::draw() void Player::checkUserData(int frameNo) { - ToPointer ptr(_currentRs->data); + ToPointer ptr(_currentRs->m_data); const AnimePackData* packData = _currentAnimeRef->animePackData; const AnimationData* animeData = _currentAnimeRef->animationData; diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index 38793f7..c646952 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -94,10 +94,10 @@ std::string ResourceManager::addData(const std::string& dataKey, const ProjectDa AnimeCache* animeCache = new AnimeCache(data); ResourceSet* rs = new ResourceSet(); - rs->data = data; - rs->cellCache = cellCache; - rs->animeCache = animeCache; - rs->effectCache = effectCache; + rs->m_data = data; + rs->m_cellCache = cellCache; + rs->m_animeCache = animeCache; + rs->m_effectCache = effectCache; _dataDic.insert(std::map::value_type(dataKey, rs)); return dataKey; @@ -208,7 +208,7 @@ bool ResourceManager::changeTexture(char* ssbpName, char* ssceName, long texture bool rc = false; ResourceSet* rs = getData(ssbpName); - rc = rs->cellCache->setCellRefTexture(rs->data, ssceName, texture); + rc = rs->m_cellCache->setCellRefTexture(rs->m_data, ssceName, texture); return(rc); } @@ -218,7 +218,7 @@ bool ResourceManager::releseTexture(std::string ssbpName) { ResourceSet* rs = getData(ssbpName); - bool rc = rs->cellCache->releseTexture(rs->data); + bool rc = rs->m_cellCache->releseTexture(rs->m_data); return(rc); } @@ -229,7 +229,7 @@ int ResourceManager::getMaxFrame(std::string ssbpName, std::string animeName) int rc = -1; ResourceSet* rs = getData(ssbpName); - AnimeRef* animeRef = rs->animeCache->getReference(animeName); + AnimeRef* animeRef = rs->m_animeCache->getReference(animeName); if (animeRef == NULL) { std::string msg = Format("Not found animation > anime=%s", animeName.c_str()); diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h index 538e47a..f93f7df 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -12,30 +12,30 @@ namespace ss{ */ class ResourceSet{ public: - const ProjectData* data; - EffectCache* effectCache; - CellCache* cellCache; - AnimeCache* animeCache; + const ProjectData* m_data; + EffectCache* m_effectCache; + CellCache* m_cellCache; + AnimeCache* m_animeCache; - virtual ~ResourceSet() + ~ResourceSet() { - delete data; - data = NULL; + delete m_data; + m_data = NULL; - if (animeCache) + if (m_animeCache) { - delete animeCache; - animeCache = NULL; + delete m_animeCache; + m_animeCache = NULL; } - if (cellCache) + if (m_cellCache) { - delete cellCache; - cellCache = NULL; + delete m_cellCache; + m_cellCache = NULL; } - if (effectCache) + if (m_effectCache) { - delete effectCache; - effectCache = NULL; + delete m_effectCache; + m_effectCache = NULL; } } }; From ffa45f959cf8921beca1f83aab935daa26778af3 Mon Sep 17 00:00:00 2001 From: kagematya Date: Thu, 3 Nov 2016 17:34:51 +0900 Subject: [PATCH 14/20] =?UTF-8?q?ResourceSet=E3=81=AE=E3=82=B3=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=A9=E3=82=AF=E3=82=BF=E3=81=AB=E3=82=BB?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5ResourceManager.cpp | 14 ++------ .../common/SS5PlayerLibs/SS5ResourceSet.h | 35 +++++++++---------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index c646952..35713f5 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -86,18 +86,8 @@ std::string ResourceManager::addData(const std::string& dataKey, const ProjectDa baseDir = dir; } - //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある - CellCache* cellCache = new CellCache(data, baseDir); - - EffectCache* effectCache = new EffectCache(data, baseDir, cellCache); // - - AnimeCache* animeCache = new AnimeCache(data); - - ResourceSet* rs = new ResourceSet(); - rs->m_data = data; - rs->m_cellCache = cellCache; - rs->m_animeCache = animeCache; - rs->m_effectCache = effectCache; + + ResourceSet* rs = new ResourceSet(data, baseDir); _dataDic.insert(std::map::value_type(dataKey, rs)); return dataKey; diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h index f93f7df..2bd0ff0 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -1,4 +1,5 @@ #pragma once +#include #include "SS5PlayerData.h" #include "SS5EffectCache.h" #include "SS5CellCache.h" @@ -13,30 +14,26 @@ namespace ss{ class ResourceSet{ public: const ProjectData* m_data; - EffectCache* m_effectCache; - CellCache* m_cellCache; - AnimeCache* m_animeCache; + std::unique_ptr m_effectCache; + std::unique_ptr m_cellCache; + std::unique_ptr m_animeCache; + + ResourceSet(const ProjectData* data, const std::string &imageBaseDir) + : m_data(data) + , m_effectCache(nullptr) + , m_cellCache(nullptr) + , m_animeCache(nullptr) + { + //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある + m_cellCache.reset(new CellCache(data, imageBaseDir)); + m_effectCache.reset(new EffectCache(data, imageBaseDir, m_cellCache.get())); + m_animeCache.reset(new AnimeCache(data)); + } ~ResourceSet() { delete m_data; m_data = NULL; - - if (m_animeCache) - { - delete m_animeCache; - m_animeCache = NULL; - } - if (m_cellCache) - { - delete m_cellCache; - m_cellCache = NULL; - } - if (m_effectCache) - { - delete m_effectCache; - m_effectCache = NULL; - } } }; From 0c62438057122ca4299a3cd57dd86193a45b028b Mon Sep 17 00:00:00 2001 From: kagematya Date: Sat, 5 Nov 2016 02:28:40 +0900 Subject: [PATCH 15/20] =?UTF-8?q?=E3=83=A1=E3=83=A2=E3=83=AA=E3=83=AA?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 68 ++++--------------- samples/DXLibrary/basic/SSPlayer/SS5Player.h | 9 --- .../basic/SSPlayer/SS5ResourceManager.cpp | 4 -- 3 files changed, 13 insertions(+), 68 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 4469f6a..d6857c3 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -101,9 +101,7 @@ Player::~Player() } releaseParts(); - releaseData(); releaseResourceManager(); - releaseAnime(); } Player* Player::create(ResourceManager* resman) @@ -215,11 +213,7 @@ void Player::setData(const std::string& dataKey) SS_ASSERT2(rs != NULL, msg.c_str()); } - if (_currentRs != rs) - { -// releaseData(); - _currentRs = rs; - } + _currentRs = rs; //Ver4互換設定 _rootPartFunctionAsVer4 = false; @@ -236,16 +230,6 @@ void Player::setData(const std::string& dataKey) #endif } -void Player::releaseData() -{ - releaseAnime(); -} - - -void Player::releaseAnime() -{ - releaseParts(); -} void Player::play(const std::string& ssaeName, const std::string& motionName, int loop, int startFrameNo) { @@ -499,50 +483,24 @@ void Player::updateFrame(float dt) void Player::allocParts(int numParts) { - for (int i = 0; i < _parts.size(); i++) - { - CustomSprite* sprite = _parts.at(i); - if (sprite) - { - delete sprite; - sprite = 0; - } - } - - _parts.clear(); //すべてのパーツを消す - { - // パーツ数だけCustomSpriteを作成する -// // create CustomSprite objects. - for (int i = 0; i < numParts; i++) - { - CustomSprite* sprite = CustomSprite::create(); - sprite->_ssplayer = NULL; - _parts.push_back(sprite); - } + releaseParts(); //すべてのパーツを消す + + // パーツ数だけCustomSpriteを作成する + for (int i = 0; i < numParts; i++){ + CustomSprite* sprite = CustomSprite::create(); + sprite->_ssplayer = NULL; + _parts.push_back(sprite); } } void Player::releaseParts() { - // パーツの子CustomSpriteを全て削除 - // remove children CCSprite objects. - if (_currentRs) - { - if (_currentAnimeRef) - { + SS_ASSERT(_currentRs); + SS_ASSERT(_currentAnimeRef); - ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); - if (_parts.size() > 0) - { - for (int partIndex = 0; partIndex < packData->numParts; partIndex++) - { - CustomSprite* sprite = static_cast(_parts.at(partIndex)); - SS_SAFE_DELETE(sprite->_ssplayer); - } - } - } + // パーツの子CustomSpriteを全て削除 + for(CustomSprite *sprite : _parts){ + SS_SAFE_DELETE(sprite); } _parts.clear(); diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.h b/samples/DXLibrary/basic/SSPlayer/SS5Player.h index c7a596d..15b1ab6 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.h @@ -442,15 +442,6 @@ class Player */ void setData(const std::string& dataKey); - /** - * 設定されているssbpデータを解放します. - */ - void releaseData(); - - /** - * 設定されているアニメーションを解放します. - */ - void releaseAnime(); /** * アニメーションの再生を開始します. diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index 35713f5..ead99e1 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -134,10 +134,6 @@ std::string ResourceManager::addDataWithKey(const std::string& dataKey, const st addData(dataKey, data, baseDir); - // リソースが破棄されるとき一緒にロードしたデータも破棄する - ResourceSet* rs = getData(dataKey); - SS_ASSERT2(rs != NULL, ""); - return dataKey; } From 0ce83c0d99330e50c9f7b77a157309e366f8b32c Mon Sep 17 00:00:00 2001 From: kagematya Date: Sun, 6 Nov 2016 13:25:53 +0900 Subject: [PATCH 16/20] =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF=E9=83=A8=E5=88=86=E3=82=92=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=81=AE=E5=A4=96=E5=81=B4?= =?UTF-8?q?=E3=81=A7=E8=A1=8C=E3=81=88=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82=20=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=99=E3=82=8B=E3=82=AD=E3=83=BC=E3=82=92=E6=98=8E?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E3=81=AB=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=80=81=E3=82=AD=E3=83=BC=E6=8C=87=E5=AE=9A=E3=81=AE?= =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=AB=E3=81=8C=E5=88=86=E3=81=8B=E3=82=8A?= =?UTF-8?q?=E3=82=84=E3=81=99=E3=81=8F=E3=81=AA=E3=82=8A=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5ResourceManager.cpp | 57 ++++++++++++++++--- .../basic/SSPlayer/SS5ResourceManager.h | 17 +++++- .../common/SS5PlayerLibs/SS5ResourceSet.h | 34 +++++++---- samples/DXLibrary/basic/sssample.cpp | 24 +++++++- 4 files changed, 109 insertions(+), 23 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index ead99e1..9a39857 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -9,11 +9,6 @@ namespace ss{ -/** - * definition - */ -static const ss_u32 DATA_ID = 0x42505353; -static const ss_u32 DATA_VERSION = 4; /** * utilites @@ -71,11 +66,12 @@ ResourceSet* ResourceManager::getData(const std::string& dataKey) return rs; } +#if 0 std::string ResourceManager::addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir) { SS_ASSERT2(data != NULL, "Invalid data"); - SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); - SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); +// SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); +// SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); // imageBaseDirの指定がないときコンバート時に指定されたパスを使用する std::string baseDir = imageBaseDir; @@ -107,8 +103,8 @@ std::string ResourceManager::addDataWithKey(const std::string& dataKey, const st } const ProjectData* data = static_cast(loadData); - SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); - SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); +// SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); +// SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); std::string baseDir = imageBaseDir; if (imageBaseDir == s_null) @@ -163,6 +159,49 @@ std::string ResourceManager::addData(const std::string& ssbpFilepath, const std: return addDataWithKey(dataKey, ssbpFilepath, imageBaseDir); } +#endif + +bool ResourceManager::addData(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir) +{ + SS_ASSERT2(data, "Invalid data"); + SS_ASSERT2(dataSize > 0, "dataSize is zero"); + //登録済みかどうかの判定 + if(_dataDic.find(dataKey) != _dataDic.end()){ + return false; + } + + /***** 新規登録 *****/ + + //画像ファイルのディレクトリパスを作る + std::string baseDir = getImageBaseDir(imageBaseDir, static_cast(data)); + + //データを作って登録 + ResourceSet* rs = new ResourceSet(static_cast(data), dataSize, baseDir); + + _dataDic.insert(std::make_pair(dataKey, rs)); + return true; +} + + +std::string ResourceManager::getImageBaseDir(const std::string &imageBaseDir, const ProjectData *data) const +{ + if(imageBaseDir == s_null){ // imageBaseDirの指定がないときはパスを作る + + if(data->imageBaseDir){ + // コンバート時に指定されたパスを使用する + ToPointer ptr(data); + return ptr.toString(data->imageBaseDir); + } + + //// プロジェクトファイルと同じディレクトリを指定する + //std::string directory; + //std::string filename; + //splitPath(directory, filename, ssbpFilepath); + //return directory; + } + return imageBaseDir; +} + void ResourceManager::removeData(const std::string& dataKey) { diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h index 38e082e..4888dd0 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h @@ -20,6 +20,7 @@ class ResourceManager{ */ static ResourceManager* getInstance(); +#if 0 /** * ssbpファイルを読み込み管理対象とします. * dataKeyはssbpのファイル名(拡張子なし)になります. @@ -49,6 +50,17 @@ class ResourceManager{ * @return dataKey */ std::string addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir = s_null); +#endif + + /** + * ssbpファイルを登録します + * + * @param data ssbpのデータ(中でコピーされます) + * @param dataSize dataのサイズ + * @param dataKey 登録名 + * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はコンバート時に指定されたパスを使用する + */ + bool addData(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir = s_null); /** * 指定データを解放します. @@ -111,7 +123,10 @@ class ResourceManager{ ResourceManager(void); virtual ~ResourceManager(); -protected: +private: + //imageBaseDirの指定がないときはdataの中を見てディレクトリを返す + std::string getImageBaseDir(const std::string &imageBaseDir, const ProjectData *data) const; + std::map _dataDic; }; diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h index 2bd0ff0..587bd79 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "SS5PlayerData.h" #include "SS5EffectCache.h" #include "SS5CellCache.h" @@ -12,28 +13,41 @@ namespace ss{ * ResourceSet */ class ResourceSet{ +private: + static const ss_u32 DATA_ID = 0x42505353; //データのチェック値 + static const ss_u32 DATA_VERSION = 4; //データのチェック値 + + std::vector m_src; //データの実体 + public: - const ProjectData* m_data; + const ProjectData* m_data; //データを指すだけ std::unique_ptr m_effectCache; - std::unique_ptr m_cellCache; - std::unique_ptr m_animeCache; + std::unique_ptr m_cellCache; //cell周りの構造へのアクセサ + std::unique_ptr m_animeCache; //anim周りの構造へのアクセサ - ResourceSet(const ProjectData* data, const std::string &imageBaseDir) - : m_data(data) + /** dataはコピーされます */ + ResourceSet(const char *data, size_t dataSize, const std::string &imageBaseDir) + : m_src(data, data + dataSize) //コピー + , m_data(nullptr) , m_effectCache(nullptr) , m_cellCache(nullptr) , m_animeCache(nullptr) { + SS_ASSERT2(data, "Invalid data"); + SS_ASSERT2(dataSize > 0, "dataSize is zero"); + + m_data = reinterpret_cast(&m_src[0]); + SS_ASSERT2(m_data->dataId == DATA_ID, "Not data id matched"); + SS_ASSERT2(m_data->version == DATA_VERSION, "Version number of data does not match"); + //アニメはエフェクトを参照し、エフェクトはセルを参照するのでこの順番で生成する必要がある - m_cellCache.reset(new CellCache(data, imageBaseDir)); - m_effectCache.reset(new EffectCache(data, imageBaseDir, m_cellCache.get())); - m_animeCache.reset(new AnimeCache(data)); + m_cellCache.reset(new CellCache(m_data, imageBaseDir)); + m_effectCache.reset(new EffectCache(m_data, imageBaseDir, m_cellCache.get())); + m_animeCache.reset(new AnimeCache(m_data)); } ~ResourceSet() { - delete m_data; - m_data = NULL; } }; diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index 9fe3ba5..6a6c960 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -1,7 +1,7 @@ #include "DxLib.h" +#include #include "SSPlayer/SS5Player.h" #include "SSPlayer/SS5ResourceManager.h" - //メモリリークチェック用--------------------------------------------------------- #ifdef _DEBUG #define _CRTDBG_MAP_ALLOC @@ -87,6 +87,19 @@ void init( void ) **********************************************************************************/ + //ssbpファイルの読み込み + ifstream ifs("Resources/character_template_comipo/character_template1.ssbp", ios::in|ios::binary); + if(!ifs){ + return; + } + ifs.seekg(0, fstream::end); + size_t filesize = ifs.tellg(); + ifs.seekg(0, fstream::beg); + + vector buf(filesize, 0); + ifs.read(buf.data(), filesize); + + //リソースマネージャの作成 resman = ss::ResourceManager::getInstance(); //プレイヤーの作成 @@ -95,9 +108,14 @@ void init( void ) //アニメデータをリソースに追加 //それぞれのプラットフォームに合わせたパスへ変更してください。 - resman->addData("Resources/character_template_comipo/character_template1.ssbp"); + resman->addData( + buf.data(), buf.size(), + "character_template1", //登録名 + "Resources/character_template_comipo/" //画像ファイルの読み込み元ルートパス + ); + //プレイヤーにリソースを割り当て - ssplayer->setData("character_template1"); // ssbpファイル名(拡張子不要) + ssplayer->setData("character_template1"); //addDataで指定した登録名 //再生するモーションを設定 ssplayer->play("character_template_3head/stance"); // アニメーション名を指定(ssae名/アニメーション名も可能、詳しくは後述) From 2e8d746f3aec101aa54f313abdb9b1477b9e5b1a Mon Sep 17 00:00:00 2001 From: kagematya Date: Sun, 6 Nov 2016 13:55:36 +0900 Subject: [PATCH 17/20] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E6=95=B4?= =?UTF-8?q?=E7=90=86=20addData/removeData=E3=82=92=E3=80=81regist/unregist?= =?UTF-8?q?=E3=81=AB=E5=90=8D=E5=89=8D=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5PlayerPlatform.cpp | 35 ----- .../basic/SSPlayer/SS5PlayerPlatform.h | 1 - .../basic/SSPlayer/SS5ResourceManager.cpp | 135 +----------------- .../basic/SSPlayer/SS5ResourceManager.h | 45 +----- samples/DXLibrary/basic/sssample.cpp | 2 +- 5 files changed, 11 insertions(+), 207 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp index 593d709..2fe0554 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp @@ -12,41 +12,6 @@ namespace ss { - /** - * ファイル読み込み - */ - unsigned char* SSFileOpen(const char* pszFileName, const char* pszMode, unsigned long * pSize) - { - unsigned char * pBuffer = NULL; - SS_ASSERT2(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invalid parameters."); - *pSize = 0; - do - { - // read the file from hardware - FILE *fp = fopen(pszFileName, pszMode); - if(!fp){ - break; - } - - fseek(fp,0,SEEK_END); - *pSize = ftell(fp); - fseek(fp,0,SEEK_SET); - pBuffer = new unsigned char[*pSize]; - *pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp); - fclose(fp); - } while (0); - if (! pBuffer) - { - - std::string msg = "Get data from file("; - msg.append(pszFileName).append(") failed!"); - - SSLOG("%s", msg.c_str()); - - } - return pBuffer; - } - /** * テクスチャの読み込み */ diff --git a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.h b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.h index 886e7b0..638291f 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.h @@ -15,7 +15,6 @@ namespace ss struct UserData; class Player; - extern unsigned char* SSFileOpen(const char* pszFileName, const char* pszMode, unsigned long * pSize); extern long SSTextureLoad(const char* pszFileName, SsTexWrapMode::_enum wrapmode, SsTexFilterMode::_enum filtermode); extern bool SSTextureRelese(long handle); extern bool isAbsolutePath(const std::string& strPath); diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index 9a39857..85b8566 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -10,28 +10,6 @@ namespace ss{ -/** - * utilites - */ -static void splitPath(std::string& directoty, std::string& filename, const std::string& path) -{ - std::string f = path; - std::string d = ""; - - size_t pos = path.find_last_of("/"); - if (pos == std::string::npos) pos = path.find_last_of("\\"); // for win - - if (pos != std::string::npos) - { - d = path.substr(0, pos + 1); - f = path.substr(pos + 1); - } - - directoty = d; - filename = f; -} - - static ResourceManager* s_defaultInstance = NULL; const std::string ResourceManager::s_null; @@ -45,13 +23,13 @@ ResourceManager* ResourceManager::getInstance() return s_defaultInstance; } -ResourceManager::ResourceManager(void) +ResourceManager::ResourceManager() { } ResourceManager::~ResourceManager() { - removeAllData(); + unregistAll(); } ResourceManager* ResourceManager::create() @@ -66,102 +44,7 @@ ResourceSet* ResourceManager::getData(const std::string& dataKey) return rs; } -#if 0 -std::string ResourceManager::addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir) -{ - SS_ASSERT2(data != NULL, "Invalid data"); -// SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); -// SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); - - // imageBaseDirの指定がないときコンバート時に指定されたパスを使用する - std::string baseDir = imageBaseDir; - if (imageBaseDir == s_null && data->imageBaseDir) - { - ToPointer ptr(data); - const char* dir = ptr.toString(data->imageBaseDir); - baseDir = dir; - } - - - ResourceSet* rs = new ResourceSet(data, baseDir); - _dataDic.insert(std::map::value_type(dataKey, rs)); - - return dataKey; -} - -std::string ResourceManager::addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir) -{ - - std::string fullpath = ssbpFilepath; - - unsigned long nSize = 0; - void* loadData = SSFileOpen(fullpath.c_str(), "rb", &nSize); - if (loadData == NULL) - { - std::string msg = "Can't load project data > " + fullpath; - SS_ASSERT2(loadData != NULL, msg.c_str()); - } - - const ProjectData* data = static_cast(loadData); -// SS_ASSERT2(data->dataId == DATA_ID, "Not data id matched"); -// SS_ASSERT2(data->version == DATA_VERSION, "Version number of data does not match"); - - std::string baseDir = imageBaseDir; - if (imageBaseDir == s_null) - { - // imageBaseDirの指定がないとき - if (data->imageBaseDir) - { - // コンバート時に指定されたパスを使用する - ToPointer ptr(data); - const char* dir = ptr.toString(data->imageBaseDir); - baseDir = dir; - } - else - { - // プロジェクトファイルと同じディレクトリを指定する - std::string directory; - std::string filename; - splitPath(directory, filename, ssbpFilepath); - baseDir = directory; - } - //SSLOG("imageBaseDir: %s", baseDir.c_str()); - } - - addData(dataKey, data, baseDir); - - return dataKey; -} - -std::string ResourceManager::addData(const std::string& ssbpFilepath, const std::string& imageBaseDir) -{ - // ファイル名を取り出す - std::string directory; - std::string filename; - splitPath(directory, filename, ssbpFilepath); - - // 拡張子を取る - std::string dataKey = filename; - size_t pos = filename.find_last_of("."); - if (pos != std::string::npos) - { - dataKey = filename.substr(0, pos); - } - - //登録されている名前か判定する - std::map::iterator it = _dataDic.find(dataKey); - if (it != _dataDic.end()) - { - //登録されている場合は処理を行わない - std::string str = ""; - return str; - } - - return addDataWithKey(dataKey, ssbpFilepath, imageBaseDir); -} -#endif - -bool ResourceManager::addData(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir) +bool ResourceManager::regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir) { SS_ASSERT2(data, "Invalid data"); SS_ASSERT2(dataSize > 0, "dataSize is zero"); @@ -192,18 +75,12 @@ std::string ResourceManager::getImageBaseDir(const std::string &imageBaseDir, co ToPointer ptr(data); return ptr.toString(data->imageBaseDir); } - - //// プロジェクトファイルと同じディレクトリを指定する - //std::string directory; - //std::string filename; - //splitPath(directory, filename, ssbpFilepath); - //return directory; } return imageBaseDir; } -void ResourceManager::removeData(const std::string& dataKey) +void ResourceManager::unregist(const std::string& dataKey) { ResourceSet* rs = getData(dataKey); @@ -215,14 +92,14 @@ void ResourceManager::removeData(const std::string& dataKey) _dataDic.erase(dataKey); } -void ResourceManager::removeAllData() +void ResourceManager::unregistAll() { //全リソースの解放 while (!_dataDic.empty()) { std::map::iterator it = _dataDic.begin(); std::string ssbpName = it->first; - removeData(ssbpName); + unregist(ssbpName); } _dataDic.clear(); } diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h index 4888dd0..d6376d7 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h @@ -20,38 +20,6 @@ class ResourceManager{ */ static ResourceManager* getInstance(); -#if 0 - /** - * ssbpファイルを読み込み管理対象とします. - * dataKeyはssbpのファイル名(拡張子なし)になります. - * - * @param ssbpFilepath ssbpファイルのパス - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addData(const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); - - /** - * ssbpファイルを読み込み管理対象とします. - * - * @param dataKey dataKeyの指定 - * @param ssbpFilepath ssbpファイルのパス - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addDataWithKey(const std::string& dataKey, const std::string& ssbpFilepath, const std::string& imageBaseDir = s_null); - - /** - * 指定されたssbpデータを管理対象とします. - * - * @param dataKey dataKeyの指定 - * @param data ssbpデータ - * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はssbpのある場所をルートとします. - * @return dataKey - */ - std::string addData(const std::string& dataKey, const ProjectData* data, const std::string& imageBaseDir = s_null); -#endif - /** * ssbpファイルを登録します * @@ -60,20 +28,15 @@ class ResourceManager{ * @param dataKey 登録名 * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はコンバート時に指定されたパスを使用する */ - bool addData(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir = s_null); + bool regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir = s_null); - /** - * 指定データを解放します. - * パス、拡張子を除いたssbp名を指定してください。 - * - * @param dataKey - */ - void removeData(const std::string& dataKey); + /** 指定データを解放します。登録名を指定してください */ + void unregist(const std::string& dataKey); /** * 全てのデータを解放します. */ - void removeAllData(); + void unregistAll(); /** * 名前に対応するデータ取得します. diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index 6a6c960..d487adb 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -108,7 +108,7 @@ void init( void ) //アニメデータをリソースに追加 //それぞれのプラットフォームに合わせたパスへ変更してください。 - resman->addData( + resman->regist( buf.data(), buf.size(), "character_template1", //登録名 "Resources/character_template_comipo/" //画像ファイルの読み込み元ルートパス From 857ca007a961d1aa957650718d3907f9974c34c7 Mon Sep 17 00:00:00 2001 From: kagematya Date: Sun, 6 Nov 2016 20:06:11 +0900 Subject: [PATCH 18/20] =?UTF-8?q?=E5=90=8C=E4=B8=80=E3=82=AD=E3=83=BC?= =?UTF-8?q?=E3=81=A7regist/unregist=E3=81=95=E3=82=8C=E3=81=9F=E6=99=82?= =?UTF-8?q?=E3=81=AB=E5=82=99=E3=81=88=E3=81=A6=E3=80=81=E5=86=85=E9=83=A8?= =?UTF-8?q?=E3=81=A7=E7=99=BB=E9=8C=B2=E6=95=B0=E3=82=92=E3=82=AB=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5ResourceManager.cpp | 39 ++++++++++++------- .../basic/SSPlayer/SS5ResourceManager.h | 34 +++++++++++++--- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp index 85b8566..eccd68e 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -40,17 +40,22 @@ ResourceManager* ResourceManager::create() ResourceSet* ResourceManager::getData(const std::string& dataKey) { - ResourceSet* rs = _dataDic.at(dataKey); - return rs; + auto it = _dataDic.find(dataKey); + SS_ASSERT(it != _dataDic.end()); + + RefcountResourceSet* rrs = it->second; + return rrs->getResourceSet(); } -bool ResourceManager::regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir) +int ResourceManager::regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir) { SS_ASSERT2(data, "Invalid data"); SS_ASSERT2(dataSize > 0, "dataSize is zero"); //登録済みかどうかの判定 if(_dataDic.find(dataKey) != _dataDic.end()){ - return false; + RefcountResourceSet* ref = _dataDic.at(dataKey); + ref->incCount(); //登録済みの場合はカウントアップするだけ。dataの内容は無視(最初に登録されてたもの優先) + return ref->getCount(); } /***** 新規登録 *****/ @@ -59,10 +64,10 @@ bool ResourceManager::regist(const void *data, size_t dataSize, const std::strin std::string baseDir = getImageBaseDir(imageBaseDir, static_cast(data)); //データを作って登録 - ResourceSet* rs = new ResourceSet(static_cast(data), dataSize, baseDir); + RefcountResourceSet* rs = new RefcountResourceSet(static_cast(data), dataSize, baseDir); _dataDic.insert(std::make_pair(dataKey, rs)); - return true; + return rs->getCount(); } @@ -82,14 +87,20 @@ std::string ResourceManager::getImageBaseDir(const std::string &imageBaseDir, co void ResourceManager::unregist(const std::string& dataKey) { - ResourceSet* rs = getData(dataKey); + auto it = _dataDic.find(dataKey); + SS_ASSERT(it != _dataDic.end()); + + RefcountResourceSet* ref = it->second; + ref->decCount(); + SS_ASSERT(ref->getCount() >= 0); //マイナスにはならない - //テクスチャの解放 - releseTexture(dataKey); + if(ref->getCount() == 0){ + //消してOKなので消す + releseTexture(dataKey); //テクスチャの解放 - //バイナリデータの削除 - delete rs; - _dataDic.erase(dataKey); + SS_SAFE_DELETE(ref); + _dataDic.erase(it); + } } void ResourceManager::unregistAll() @@ -97,7 +108,7 @@ void ResourceManager::unregistAll() //全リソースの解放 while (!_dataDic.empty()) { - std::map::iterator it = _dataDic.begin(); + auto it = _dataDic.begin(); std::string ssbpName = it->first; unregist(ssbpName); } @@ -145,7 +156,7 @@ int ResourceManager::getMaxFrame(std::string ssbpName, std::string animeName) //ssbpファイルが登録されているかを調べる bool ResourceManager::isDataKeyExists(const std::string& dataKey) { // 登録されている名前か判定する - std::map::iterator it = _dataDic.find(dataKey); + auto it = _dataDic.find(dataKey); if (it != _dataDic.end()) { //登録されている return true; diff --git a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h index d6376d7..975f640 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include "common/SS5PlayerLibs/SS5ResourceSet.h" namespace ss{ struct ProjectData; @@ -28,14 +30,12 @@ class ResourceManager{ * @param dataKey 登録名 * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はコンバート時に指定されたパスを使用する */ - bool regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir = s_null); + int regist(const void *data, size_t dataSize, const std::string &dataKey, const std::string &imageBaseDir = s_null); /** 指定データを解放します。登録名を指定してください */ void unregist(const std::string& dataKey); - /** - * 全てのデータを解放します. - */ + /** 全てのデータを解放します. */ void unregistAll(); /** @@ -90,7 +90,31 @@ class ResourceManager{ //imageBaseDirの指定がないときはdataの中を見てディレクトリを返す std::string getImageBaseDir(const std::string &imageBaseDir, const ProjectData *data) const; - std::map _dataDic; + + /** regist数をカウントするための構造 */ + class RefcountResourceSet{ + public: + RefcountResourceSet(const char *data, size_t dataSize, const std::string &imageBaseDir) + : m_refCount(0), m_resourceSet(new ResourceSet(data, dataSize, imageBaseDir)){ + incCount(); + } + ~RefcountResourceSet(){} + + int getCount() const{ return m_refCount; } + void incCount(){ ++m_refCount; } + void decCount(){ --m_refCount; } + + ResourceSet* getResourceSet() const{ + return m_resourceSet.get(); + } + + private: + int m_refCount; + std::unique_ptr m_resourceSet; + }; + + + std::map _dataDic; //ここにデータを登録する }; From 7832618c3533f00d9f6fca70a9f4ddd00f4621e2 Mon Sep 17 00:00:00 2001 From: kagematya Date: Mon, 7 Nov 2016 01:11:55 +0900 Subject: [PATCH 19/20] =?UTF-8?q?ToPointer=E7=B5=8C=E7=94=B1=E3=81=AE?= =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=82=92AnimeCache?= =?UTF-8?q?=E3=82=92=E5=88=A9=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DXLibrary/basic/SSPlayer/SS5Player.cpp | 84 +++++++------------ .../common/SS5PlayerLibs/SS5AnimCache.cpp | 80 +++++++----------- .../common/SS5PlayerLibs/SS5AnimCache.h | 27 +++--- 3 files changed, 76 insertions(+), 115 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index d6857c3..548ccab 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -258,7 +258,7 @@ void Player::play(AnimeRef* animeRef, int loop, int startFrameNo) { _currentAnimeRef = animeRef; - allocParts(animeRef->animePackData->numParts); + allocParts(animeRef->numParts); setPartsParentage(); } _playingFrame = static_cast(startFrameNo); @@ -511,11 +511,11 @@ void Player::setPartsParentage() if (!_currentAnimeRef) return; ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + int numParts = _currentAnimeRef->numParts; + const PartData* parts = _currentAnimeRef->partDatas; //親子関係を設定 - for (int partIndex = 0; partIndex < packData->numParts; partIndex++) + for (int partIndex = 0; partIndex < numParts; partIndex++) { const PartData* partData = &parts[partIndex]; CustomSprite* sprite = static_cast(_parts.at(partIndex)); @@ -575,9 +575,7 @@ void Player::setPartsParentage() //再生しているアニメーションに含まれるパーツ数を取得 int Player::getPartsCount(void) { - ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - return packData->numParts; + return _currentAnimeRef->numParts; } //indexからパーツ名を取得 @@ -585,23 +583,19 @@ const char* Player::getPartName(int partId) const { ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - SS_ASSERT2(partId >= 0 && partId < packData->numParts, "partId is out of range."); + SS_ASSERT2(partId >= 0 && partId < _currentAnimeRef->numParts, "partId is out of range."); - const PartData* partData = ptr.toPartData(packData); - const char* name = ptr.toString(partData[partId].name); + const PartData* parts = _currentAnimeRef->partDatas; + const char* name = ptr.toString(parts[partId].name); return name; } //パーツ名からindexを取得 int Player::indexOfPart(const char* partName) const { - const AnimePackData* packData = _currentAnimeRef->animePackData; - for (int i = 0; i < packData->numParts; i++) - { + for (int i = 0; i < _currentAnimeRef->numParts; i++){ const char* name = getPartName(i); - if (strcmp(partName, name) == 0) - { + if (strcmp(partName, name) == 0){ return i; } } @@ -637,10 +631,9 @@ bool Player::getPartState(ResluteState& result, const char* name, int frameNo) ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + const PartData* parts = _currentAnimeRef->partDatas; - for (int index = 0; index < packData->numParts; index++) + for (int index = 0; index < _currentAnimeRef->numParts; index++) { int partIndex = _partIndex[index]; @@ -795,26 +788,9 @@ int Player::getLabelToFrame(char* findLabelName) //プライオリティでソートされた後、上に配置された順にソートされて決定されます。 void Player::setPartVisible(std::string partsname, bool flg) { - bool rc = false; - if (_currentAnimeRef) - { - ToPointer ptr(_currentRs->m_data); - - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); - - for (int index = 0; index < packData->numParts; index++) - { - int partIndex = _partIndex[index]; - - const PartData* partData = &parts[partIndex]; - const char* partName = ptr.toString(partData->name); - if (strcmp(partName, partsname.c_str()) == 0) - { - _partVisible[index] = flg; - break; - } - } + int index = indexOfPart(partsname.c_str()); + if(index >= 0){ + _partVisible[index] = flg; } } @@ -851,10 +827,10 @@ void Player::setPartCell(std::string partsname, std::string sscename, std::strin } } - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + int numParts = _currentAnimeRef->numParts; + const PartData* parts = _currentAnimeRef->partDatas; - for (int index = 0; index < packData->numParts; index++) + for (int index = 0; index < numParts; index++) { int partIndex = _partIndex[index]; @@ -879,10 +855,10 @@ bool Player::changeInstanceAnime(std::string partsname, std::string animename, b { ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + int numParts = _currentAnimeRef->numParts; + const PartData* parts = _currentAnimeRef->partDatas; - for (int index = 0; index < packData->numParts; index++) + for (int index = 0; index < numParts; index++) { int partIndex = _partIndex[index]; @@ -1005,8 +981,7 @@ void Player::setFrame(int frameNo, float dt) ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + const PartData* parts = _currentAnimeRef->partDatas; const AnimationData* animeData = _currentAnimeRef->animationData; const ss_offset* frameDataIndex = static_cast(ptr(animeData->frameData)); @@ -1019,7 +994,7 @@ void Player::setFrame(int frameNo, float dt) State state; - for (int index = 0; index < packData->numParts; index++) + for (int index = 0; index < _currentAnimeRef->numParts; index++) { int partIndex = reader.readS16(); const PartData* partData = &parts[partIndex]; @@ -1572,7 +1547,7 @@ void Player::setFrame(int frameNo, float dt) // 親に変更があるときは自分も更新するようフラグを設定する - for (int partIndex = 1; partIndex < packData->numParts; partIndex++) + for (int partIndex = 1; partIndex < _currentAnimeRef->numParts; partIndex++) { const PartData* partData = &parts[partIndex]; CustomSprite* sprite = static_cast(_parts.at(partIndex)); @@ -1585,7 +1560,7 @@ void Player::setFrame(int frameNo, float dt) } // 行列の更新 - for (int partIndex = 0; partIndex < packData->numParts; partIndex++) + for (int partIndex = 0; partIndex < _currentAnimeRef->numParts; partIndex++) { const PartData* partData = &parts[partIndex]; CustomSprite* sprite = static_cast(_parts.at(partIndex)); @@ -1699,7 +1674,7 @@ void Player::setFrame(int frameNo, float dt) } // 特殊パーツのアップデート - for (int partIndex = 0; partIndex < packData->numParts; partIndex++) + for (int partIndex = 0; partIndex < _currentAnimeRef->numParts; partIndex++) { const PartData* partData = &parts[partIndex]; CustomSprite* sprite = static_cast(_parts.at(partIndex)); @@ -1781,10 +1756,8 @@ void Player::draw() if (!_currentAnimeRef) return; _draw_count = 0; //表示スプライト数クリア - ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - for (int index = 0; index < packData->numParts; index++) + for (int index = 0; index < _currentAnimeRef->numParts; index++) { int partIndex = _partIndex[index]; //スプライトの表示 @@ -1829,9 +1802,8 @@ void Player::checkUserData(int frameNo) { ToPointer ptr(_currentRs->m_data); - const AnimePackData* packData = _currentAnimeRef->animePackData; const AnimationData* animeData = _currentAnimeRef->animationData; - const PartData* parts = ptr.toPartData(packData); + const PartData* parts = _currentAnimeRef->partDatas; if (!animeData->userData) return; const ss_offset* userDataIndex = static_cast(ptr(animeData->userData)); diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp index ce24709..865955b 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp @@ -12,14 +12,13 @@ AnimeCache::AnimeCache(const ProjectData* data) AnimeCache::~AnimeCache() { - releseReference(); } //packNameとanimeNameを指定してAnimeRefを得る AnimeRef* AnimeCache::getReference(const std::string& packName, const std::string& animeName) { std::string key = toPackAnimeKey(packName, animeName); - AnimeRef* ref = _dic.at(key); + AnimeRef* ref = &(_dic.at(key)); return ref; } @@ -27,17 +26,14 @@ AnimeRef* AnimeCache::getReference(const std::string& packName, const std::strin //animeNameのみ指定してAnimeRefを得る AnimeRef* AnimeCache::getReference(const std::string& animeName) { - AnimeRef* ref = _dic.at(animeName); + AnimeRef* ref = &(_dic.at(animeName)); return ref; } void AnimeCache::dump() { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - SSLOG("%s", (*it).second); - ++it; + for(auto &str_aref : _dic){ + SSLOG("%s", str_aref.first); } } @@ -49,55 +45,41 @@ void AnimeCache::init(const ProjectData* data) ToPointer ptr(data); const AnimePackData* animePacks = ptr.toAnimePackData(data); - for (int packIndex = 0; packIndex < data->numAnimePacks; packIndex++) - { + for(int packIndex = 0; packIndex < data->numAnimePacks; packIndex++){ const AnimePackData* pack = &animePacks[packIndex]; - const AnimationData* animations = ptr.toAnimationData(pack); - const char* packName = ptr.toString(pack->name); - - for (int animeIndex = 0; animeIndex < pack->numAnimations; animeIndex++) - { - const AnimationData* anime = &animations[animeIndex]; - const char* animeName = ptr.toString(anime->name); - - AnimeRef* ref = new AnimeRef(); - ref->packName = packName; - ref->animeName = animeName; - ref->animationData = anime; - ref->animePackData = pack; - - // packName + animeNameでの登録 - std::string key = toPackAnimeKey(packName, animeName); - SSLOG("anime key: %s", key.c_str()); - _dic.insert(std::map::value_type(key, ref)); - - // animeNameのみでの登録 - // _dic.insert(std::map::value_type(animeName, ref)); - - } + addAnimationData(ptr, pack); //ssaeからAnimationDataを登録する } } -std::string AnimeCache::toPackAnimeKey(const std::string& packName, const std::string& animeName) +//ssaeからAnimationDataを登録する +void AnimeCache::addAnimationData(ToPointer ptr, const AnimePackData* pack) { - return packName + "/" + animeName; //return Format("%s/%s", packName.c_str(), animeName.c_str()); + const char* packName = ptr.toString(pack->name); + + const PartData* partDatas = ptr.toPartData(pack); //array + const AnimationData* animations = ptr.toAnimationData(pack); //array + + for (int animeIndex = 0; animeIndex < pack->numAnimations; animeIndex++){ + const AnimationData* anime = &animations[animeIndex]; + const char* animeName = ptr.toString(anime->name); + + AnimeRef ref = { + packName, animeName, anime, partDatas, pack->numParts + }; + + // packName + animeNameでの登録 + std::string key = toPackAnimeKey(packName, animeName); + SSLOG("anime key: %s", key.c_str()); + _dic.insert(std::make_pair(key, ref)); + + // animeNameのみでの登録 + _dic.insert(std::make_pair(animeName, ref)); + } } -//キャッシュの削除 -void AnimeCache::releseReference(void) +std::string AnimeCache::toPackAnimeKey(const std::string& packName, const std::string& animeName) { - std::map::iterator it = _dic.begin(); - while (it != _dic.end()) - { - AnimeRef* ref = it->second; - if (ref) - { - delete ref; - it->second = 0; - } - it++; - } - _dic.clear(); + return packName + "/" + animeName; //return Format("%s/%s", packName.c_str(), animeName.c_str()); } diff --git a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h index 069affb..1e2e0ad 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h @@ -5,49 +5,56 @@ namespace ss{ struct AnimationData; struct AnimePackData; +struct PartData; struct ProjectData; +class ToPointer; /** * AnimeRef + * AnimationDataへのアクセスを提供 + * パーツデータはssae単位で共通のものだが、利便性のためここで抱えておく */ struct AnimeRef{ std::string packName; std::string animeName; const AnimationData* animationData; - const AnimePackData* animePackData; + + //const AnimePackData* animePackData; //属するパッケージ + const PartData* partDatas; //パーツデータへのショートカット aniemPackData->partDatas[] + int numParts; //パーツデータ数 }; /** * AnimeCache + * ProjectDataからAnimationDataへのアクセスを構築する */ class AnimeCache{ public: + /** dataを元にAnimeRefを構築 */ AnimeCache(const ProjectData* data); ~AnimeCache(); - /** - * packNameとanimeNameを指定してAnimeRefを得る - */ + /** packNameとanimeNameを指定してAnimeRefを得る */ AnimeRef* getReference(const std::string& packName, const std::string& animeName); - /** - * animeNameのみ指定してAnimeRefを得る - */ + /** animeNameのみ指定してAnimeRefを得る */ AnimeRef* getReference(const std::string& animeName); + /** デバッグ用 */ void dump(); private: + /** dataを元にAnimeRefを構築 */ void init(const ProjectData* data); + void addAnimationData(ToPointer ptr, const AnimePackData* pack); + /** ファイルパス生成 */ static std::string toPackAnimeKey(const std::string& packName, const std::string& animeName); - //キャッシュの削除 - void releseReference(void); private: - std::map _dic; + std::map _dic; }; From d853024a89b93b1534537403ade7488bbf7649c7 Mon Sep 17 00:00:00 2001 From: kagematya Date: Mon, 7 Nov 2016 02:00:55 +0900 Subject: [PATCH 20/20] =?UTF-8?q?vertex=E3=81=ABmatrix=E3=82=92=E6=8E=9B?= =?UTF-8?q?=E3=81=91=E3=82=8B=E3=81=A0=E3=81=91=E3=81=A7=E6=B8=88=E3=82=80?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E3=81=9D=E3=81=AE=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/SSPlayer/SS5PlayerPlatform.cpp | 30 ++++--------------- .../common/Animator/ssplayer_matrix.cpp | 27 +++++++++++++++-- .../common/Animator/ssplayer_matrix.h | 3 ++ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp index 2fe0554..b8baf71 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp @@ -197,31 +197,11 @@ namespace ss quad.br.vertices.x += cx; quad.br.vertices.y += cy; - float x, y; - SSMatrix t; - t.setupTranslation(quad.tl.vertices.x, quad.tl.vertices.y, 0.0f); - t *= state.mat; - t.getTranslation(&x, &y); - quad.tl.vertices.x = x; - quad.tl.vertices.y = y; - - t.setupTranslation(quad.tr.vertices.x, quad.tr.vertices.y, 0.0f); - t *= state.mat; - t.getTranslation(&x, &y); - quad.tr.vertices.x = x; - quad.tr.vertices.y = y; - - t.setupTranslation(quad.bl.vertices.x, quad.bl.vertices.y, 0.0f); - t *= state.mat; - t.getTranslation(&x, &y); - quad.bl.vertices.x = x; - quad.bl.vertices.y = y; - - t.setupTranslation(quad.br.vertices.x, quad.br.vertices.y, 0.0f); - t *= state.mat; - t.getTranslation(&x, &y); - quad.br.vertices.x = x; - quad.br.vertices.y = y; + + quad.vertexForeach([&](SSVertex3F &v){ + v *= state.mat; + }); + #else float x, y; state.mat.getTranslation(&x, &y); /// 表示座標はマトリクスから取得します。 float rotationZ = state.Calc_rotationZ; /// 回転値 diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.cpp b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.cpp index 9fb101e..7a41d38 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.cpp +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.cpp @@ -1,5 +1,6 @@ #include "ssplayer_matrix.h" #include +#include "common/SS5PlayerLibs/SS5PlayerTypes.h" namespace ss { @@ -130,10 +131,10 @@ SSMatrix SSMatrix::getRotationMatrix() const /* スケールS, 回転R, 平行移動T の行列はこうなってる - SxR00, SxR01, SxR02, 0 + SxR00, SxR01, SxR02, 0 mat = SyR10, SyR11, SyR12, 0 - SzR20, SzR21, SzR22, 0 - Tx, Ty, Tz, 1 + SzR20, SzR21, SzR22, 0 + Tx, Ty, Tz, 1 要素を打ち消してR成分だけにする */ @@ -186,6 +187,26 @@ SSMatrix& SSMatrix::operator*=(const SSMatrix &o) { } + +//頂点変換 +SSVertex3F operator*(const SSVertex3F &p, const SSMatrix &m){ + + //(x,y,z,w=1)*matrix の計算。実際にはwはないのでごまかしつつ計算 + return SSVertex3F( + p.x*m._m[0] + p.y*m._m[4] + p.z*m._m[8] + m._m[12], + p.x*m._m[1] + p.y*m._m[5] + p.z*m._m[9] + m._m[13], + p.x*m._m[2] + p.y*m._m[6] + p.z*m._m[10] + m._m[14] + ); +} + +SSVertex3F &operator*=(SSVertex3F &p, const SSMatrix &m){ + p = p * m; + return p; +} + + + + void IdentityMatrix( float* matrix ) { diff --git a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.h b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.h index 7d4a7d7..52dccca 100644 --- a/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.h +++ b/samples/DXLibrary/basic/SSPlayer/common/Animator/ssplayer_matrix.h @@ -3,6 +3,7 @@ #include +#include "common/SS5PlayerLibs/SS5PlayerTypes.h" namespace ss { @@ -44,6 +45,8 @@ class SSMatrix { }; +SSVertex3F operator*(const SSVertex3F &p, const SSMatrix &m); +SSVertex3F &operator*=(SSVertex3F &p, const SSMatrix &m);