diff --git a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp index 836597d..548ccab 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.cpp @@ -2,75 +2,23 @@ // SS5Player.cpp // #include "SS5Player.h" +#include "SS5ResourceManager.h" #include "common/SS5PlayerLibs/SS5PlayerData.h" #include "common/SS5PlayerLibs/SS5PlayerTypes.h" #include "common/SS5PlayerLibs/SS5PlayerToPointer.h" #include "common/SS5PlayerLibs/SS5PlayerDataArrayReader.h" +#include "common/SS5PlayerLibs/SS5CellCache.h" +#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" 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; -} //座標回転処理 //指定した座標を中心に回転後した座標を取得します @@ -101,1055 +49,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; -}; - - -/** -* 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; -}; - - - -/** - * 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 - */ -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 - */ - -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 @@ -1202,9 +101,7 @@ Player::~Player() } releaseParts(); - releaseData(); releaseResourceManager(); - releaseAnime(); } Player* Player::create(ResourceManager* resman) @@ -1316,37 +213,23 @@ 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; _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互換) } #endif } -void Player::releaseData() -{ - releaseAnime(); -} - - -void Player::releaseAnime() -{ - releaseParts(); -} void Player::play(const std::string& ssaeName, const std::string& motionName, int loop, int startFrameNo) { @@ -1358,7 +241,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()); @@ -1375,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); @@ -1462,7 +345,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; @@ -1600,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->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(); @@ -1653,12 +510,12 @@ void Player::setPartsParentage() { if (!_currentAnimeRef) return; - ToPointer ptr(_currentRs->data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - const PartData* parts = ptr.toPartData(packData); + ToPointer ptr(_currentRs->m_data); + 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)); @@ -1696,7 +553,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) { //エフェクトクラスにパラメータを設定する @@ -1718,33 +575,27 @@ void Player::setPartsParentage() //再生しているアニメーションに含まれるパーツ数を取得 int Player::getPartsCount(void) { - ToPointer ptr(_currentRs->data); - const AnimePackData* packData = _currentAnimeRef->animePackData; - return packData->numParts; + return _currentAnimeRef->numParts; } //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."); + 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; } } @@ -1778,12 +629,11 @@ 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); + 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]; @@ -1901,7 +751,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; @@ -1938,26 +788,9 @@ int Player::getLabelToFrame(char* findLabelName) //プライオリティでソートされた後、上に配置された順にソートされて決定されます。 void Player::setPartVisible(std::string partsname, bool flg) { - bool rc = false; - if (_currentAnimeRef) - { - ToPointer ptr(_currentRs->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; } } @@ -1967,17 +800,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); @@ -1994,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]; @@ -2020,12 +853,12 @@ 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); + 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]; @@ -2129,7 +962,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; { @@ -2146,10 +979,9 @@ 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); + const PartData* parts = _currentAnimeRef->partDatas; const AnimationData* animeData = _currentAnimeRef->animationData; const ss_offset* frameDataIndex = static_cast(ptr(animeData->frameData)); @@ -2162,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]; @@ -2249,7 +1081,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; @@ -2715,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)); @@ -2728,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)); @@ -2842,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)); @@ -2924,10 +1756,8 @@ void Player::draw() if (!_currentAnimeRef) return; _draw_count = 0; //表示スプライト数クリア - ToPointer ptr(_currentRs->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]; //スプライトの表示 @@ -2970,11 +1800,10 @@ 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; - const PartData* parts = ptr.toPartData(packData); + const PartData* parts = _currentAnimeRef->partDatas; if (!animeData->userData) return; const ss_offset* userDataIndex = static_cast(ptr(animeData->userData)); @@ -3220,67 +2049,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 2203e3f..15b1ab6 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5Player.h +++ b/samples/DXLibrary/basic/SSPlayer/SS5Player.h @@ -105,300 +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 - - -/** -* 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: -}; - - -/** - * 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; -}; - /** @@ -731,15 +442,6 @@ class Player */ void setData(const std::string& dataKey); - /** - * 設定されているssbpデータを解放します. - */ - void releaseData(); - - /** - * 設定されているアニメーションを解放します. - */ - void releaseAnime(); /** * アニメーションの再生を開始します. diff --git a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp index 559d3d8..b8baf71 100644 --- a/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp +++ b/samples/DXLibrary/basic/SSPlayer/SS5PlayerPlatform.cpp @@ -12,39 +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); - SS_BREAK_IF(!fp); - - 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; - } - /** * テクスチャの読み込み */ @@ -230,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/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 new file mode 100644 index 0000000..eccd68e --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.cpp @@ -0,0 +1,170 @@ +#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{ + + + +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() +{ +} + +ResourceManager::~ResourceManager() +{ + unregistAll(); +} + +ResourceManager* ResourceManager::create() +{ + ResourceManager* obj = new ResourceManager(); + return obj; +} + +ResourceSet* ResourceManager::getData(const std::string& dataKey) +{ + auto it = _dataDic.find(dataKey); + SS_ASSERT(it != _dataDic.end()); + + RefcountResourceSet* rrs = it->second; + return rrs->getResourceSet(); +} + +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()){ + RefcountResourceSet* ref = _dataDic.at(dataKey); + ref->incCount(); //登録済みの場合はカウントアップするだけ。dataの内容は無視(最初に登録されてたもの優先) + return ref->getCount(); + } + + /***** 新規登録 *****/ + + //画像ファイルのディレクトリパスを作る + std::string baseDir = getImageBaseDir(imageBaseDir, static_cast(data)); + + //データを作って登録 + RefcountResourceSet* rs = new RefcountResourceSet(static_cast(data), dataSize, baseDir); + + _dataDic.insert(std::make_pair(dataKey, rs)); + return rs->getCount(); +} + + +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); + } + } + return imageBaseDir; +} + + +void ResourceManager::unregist(const std::string& dataKey) +{ + auto it = _dataDic.find(dataKey); + SS_ASSERT(it != _dataDic.end()); + + RefcountResourceSet* ref = it->second; + ref->decCount(); + SS_ASSERT(ref->getCount() >= 0); //マイナスにはならない + + if(ref->getCount() == 0){ + //消してOKなので消す + releseTexture(dataKey); //テクスチャの解放 + + SS_SAFE_DELETE(ref); + _dataDic.erase(it); + } +} + +void ResourceManager::unregistAll() +{ + //全リソースの解放 + while (!_dataDic.empty()) + { + auto it = _dataDic.begin(); + std::string ssbpName = it->first; + unregist(ssbpName); + } + _dataDic.clear(); +} + +//データ名、セル名を指定して、セルで使用しているテクスチャを変更する +bool ResourceManager::changeTexture(char* ssbpName, char* ssceName, long texture) +{ + bool rc = false; + + ResourceSet* rs = getData(ssbpName); + rc = rs->m_cellCache->setCellRefTexture(rs->m_data, ssceName, texture); + + return(rc); +} + +//指定したデータのテクスチャを破棄します +bool ResourceManager::releseTexture(std::string ssbpName) +{ + + ResourceSet* rs = getData(ssbpName); + bool rc = rs->m_cellCache->releseTexture(rs->m_data); + + return(rc); +} + +//アニメーションの総フレーム数を取得する +int ResourceManager::getMaxFrame(std::string ssbpName, std::string animeName) +{ + int rc = -1; + + ResourceSet* rs = getData(ssbpName); + AnimeRef* animeRef = rs->m_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) { + // 登録されている名前か判定する + auto 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..975f640 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/SS5ResourceManager.h @@ -0,0 +1,122 @@ +#pragma once +#include +#include +#include +#include "common/SS5PlayerLibs/SS5ResourceSet.h" + +namespace ss{ +struct ProjectData; +class ResourceSet; + +/** + * ResourceManager + */ +class ResourceManager{ +public: + static const std::string s_null; + + /** + * デフォルトインスタンスを取得します. + * + * @return デフォルトのResourceManagerインスタンス + */ + static ResourceManager* getInstance(); + + /** + * ssbpファイルを登録します + * + * @param data ssbpのデータ(中でコピーされます) + * @param dataSize dataのサイズ + * @param dataKey 登録名 + * @param imageBaseDir 画像ファイルの読み込み元ルートパス. 省略時はコンバート時に指定されたパスを使用する + */ + 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(); + + /** + * 名前に対応するデータ取得します. + */ + 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(); + +private: + //imageBaseDirの指定がないときはdataの中を見てディレクトリを返す + std::string getImageBaseDir(const std::string &imageBaseDir, const ProjectData *data) const; + + + /** 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; //ここにデータを登録する +}; + + +} //namespace ss + 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/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); 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/SSPlayer/common/Helper/Util.h b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h new file mode 100644 index 0000000..7f00a1f --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/Helper/Util.h @@ -0,0 +1,95 @@ +#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) + +#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_s(&tmp[0], tmp.size(), _TRUNCATE, format, args) == -1) + { + tmp.resize(tmp.size() * 2); + } + else + { + break; + } + } + tmp.push_back('\0'); + std::string ret = &(tmp[0]); + va_end(args); + return ret; +} + + + +//配列のサイズを返す +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 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..865955b --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.cpp @@ -0,0 +1,87 @@ +#include "SS5AnimCache.h" +#include "SS5Player.h" +#include "SS5PlayerToPointer.h" + +namespace ss{ + + +AnimeCache::AnimeCache(const ProjectData* data) +{ + init(data); +} + +AnimeCache::~AnimeCache() +{ +} + +//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() +{ + for(auto &str_aref : _dic){ + SSLOG("%s", str_aref.first); + } +} + + +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]; + addAnimationData(ptr, pack); //ssaeからAnimationDataを登録する + } +} + +//ssaeからAnimationDataを登録する +void AnimeCache::addAnimationData(ToPointer ptr, const AnimePackData* pack) +{ + 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)); + } +} + +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()); +} + + +} //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..1e2e0ad --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5AnimCache.h @@ -0,0 +1,64 @@ +#pragma once +#include +#include + +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 PartData* partDatas; //パーツデータへのショートカット aniemPackData->partDatas[] + int numParts; //パーツデータ数 +}; + + +/** + * AnimeCache + * ProjectDataからAnimationDataへのアクセスを構築する + */ +class AnimeCache{ +public: + /** dataを元にAnimeRefを構築 */ + AnimeCache(const ProjectData* data); + ~AnimeCache(); + + /** packNameとanimeNameを指定してAnimeRefを得る */ + AnimeRef* getReference(const std::string& packName, const std::string& animeName); + + /** 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); + + +private: + std::map _dic; +}; + + + + +} //namespace ss + 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..9fd328b --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.cpp @@ -0,0 +1,169 @@ +#include "SS5CellCache.h" +#include "SS5PlayerToPointer.h" +#include "SS5PlayerPlatform.h" +#include "common/Loader/sstypes.h" + +namespace ss{ + + +CellCache::CellCache(const ProjectData* data, const std::string& imageBaseDir) +{ + init(data, imageBaseDir); +} + +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..d9de293 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5CellCache.h @@ -0,0 +1,60 @@ +#pragma once +#include +#include +#include "SS5PlayerTypes.h" +#include "common/Loader/sstypes.h" + + +namespace ss{ +struct Cell; +struct ProjectData; + + +/** + * CellRef + */ +struct CellRef{ + const Cell* cell; + TextuerData texture; + SSRect rect; + std::string texname; +}; + + +/** + * CellCache + */ +class CellCache{ +public: + CellCache(const ProjectData* data, const std::string& imageBaseDir); + ~CellCache(); + + 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); + +private: + std::vector _texname; + std::vector _textures; + std::vector _refs; +}; + + + + +} //namespace ss; + + 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 + 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..fac4180 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.cpp @@ -0,0 +1,469 @@ +#include "SS5EffectCache.h" +#include "SS5Player.h" +#include "SS5PlayerToPointer.h" +#include "SS5CellCache.h" +#include "SS5PlayerDataArrayReader.h" + +namespace ss{ + + +EffectCache::EffectCache(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache) +{ + init(data, imageBaseDir, cellCache); +} + +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..7ec795c --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5EffectCache.h @@ -0,0 +1,36 @@ +#pragma once +#include +#include + +namespace ss{ +struct ProjectData; +class SsEffectModel; +class CellCache; + +/** + * EffectCache + */ +class EffectCache{ +public: + EffectCache(const ProjectData* data, const std::string& imageBaseDir, CellCache* cellCache); + ~EffectCache(); + + /** + * エフェクトファイル名を指定して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 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..587bd79 --- /dev/null +++ b/samples/DXLibrary/basic/SSPlayer/common/SS5PlayerLibs/SS5ResourceSet.h @@ -0,0 +1,57 @@ +#pragma once +#include +#include +#include "SS5PlayerData.h" +#include "SS5EffectCache.h" +#include "SS5CellCache.h" +#include "SS5AnimCache.h" + +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; //データを指すだけ + std::unique_ptr m_effectCache; + std::unique_ptr m_cellCache; //cell周りの構造へのアクセサ + std::unique_ptr m_animeCache; //anim周りの構造へのアクセサ + + /** 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(m_data, imageBaseDir)); + m_effectCache.reset(new EffectCache(m_data, imageBaseDir, m_cellCache.get())); + m_animeCache.reset(new AnimeCache(m_data)); + } + + ~ResourceSet() + { + } +}; + + + +} //namespace ss + diff --git a/samples/DXLibrary/basic/sssample.cpp b/samples/DXLibrary/basic/sssample.cpp index 3df2656..d487adb 100644 --- a/samples/DXLibrary/basic/sssample.cpp +++ b/samples/DXLibrary/basic/sssample.cpp @@ -1,5 +1,14 @@ #include "DxLib.h" +#include #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; @@ -21,9 +30,14 @@ 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(1280, 720, GetColorBitDepth() ); + SetGraphMode(800, 600, GetColorBitDepth() ); if (DxLib_Init() == -1) // DXライブラリ初期化処理 { return -1; // エラーが起きたら直ちに終了 @@ -73,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(); //プレイヤーの作成 @@ -81,14 +108,19 @@ void init( void ) //アニメデータをリソースに追加 //それぞれのプラットフォームに合わせたパスへ変更してください。 - resman->addData("Resources/character_template_comipo/character_template1.ssbp"); + resman->regist( + 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名/アニメーション名も可能、詳しくは後述) //表示位置を設定 - ssplayer->setPosition(1280/2, 300); + ssplayer->setPosition(800/2, 100); //スケール設定 ssplayer->setScale(0.5f, 0.5f); //回転を設定