diff --git a/Common/Animator/ssplayer_animedecode.cpp b/Common/Animator/ssplayer_animedecode.cpp index b694c552..86e1fa7c 100644 --- a/Common/Animator/ssplayer_animedecode.cpp +++ b/Common/Animator/ssplayer_animedecode.cpp @@ -41,6 +41,12 @@ SsAnimeDecoder::SsAnimeDecoder() : curAnimeTotalFrame(0), nowPlatTime(0) , nowPlatTimeOld(0), + frameDelta(0), + curAnimation(nullptr), + curSequence(nullptr), + myModel(nullptr), + project(nullptr), + stateNum(0), curCellMapManager(), partState(), instancePartsHide(false), diff --git a/Common/Animator/ssplayer_cellmap.h b/Common/Animator/ssplayer_cellmap.h index 4f7ff8a4..32ec23df 100644 --- a/Common/Animator/ssplayer_cellmap.h +++ b/Common/Animator/ssplayer_cellmap.h @@ -21,9 +21,11 @@ struct SsCellValue SsTexFilterMode::_enum filterMode; ///< テクスチャのフィルタモード SsCellValue() : - cell(0) , - texture(0) - {} + cell(nullptr) , + texture(nullptr), + filterMode(SsTexFilterMode::_enum::nearlest), + wrapMode(SsTexWrapMode::_enum::clamp) + {} }; class SsCelMapLinker diff --git a/Common/Animator/ssplayer_effect.h b/Common/Animator/ssplayer_effect.h index ebfd7a5b..3feade1e 100644 --- a/Common/Animator/ssplayer_effect.h +++ b/Common/Animator/ssplayer_effect.h @@ -72,31 +72,46 @@ class SsEffectRenderAtom public: - SsEffectRenderAtom() : - parent(0), - m_isInit(false), - m_isLive(true), - _lifetime(10.0f), - _life(1.0f), - rotation(0), - position(0,0,0), - scale(1.0f,1.0f), - m_isCreateChild(false) - { - } + SsEffectRenderAtom() + { + init(); + } + + SsEffectRenderAtom( SsEffectNode* refdata , SsEffectRenderAtom* _p) + { + init(); - SsEffectRenderAtom( SsEffectNode* refdata , SsEffectRenderAtom* _p){ data = refdata; setParent(_p); _lifetime = 0; - position = SsVector3(0,0,0); scale = SsVector2(0,0); - rotation = 0.0f; } virtual ~SsEffectRenderAtom(){} + // コンストラクタの共通初期化処理 + void init() + { + position = SsVector3(0, 0, 0); + rotation = 0; + scale = SsVector2(1.0f, 1.0f); + + parent = nullptr; + data = nullptr; + + m_isLive = true; + m_isInit = false; + m_isCreateChild = false; + + _lifetime = 10.0f; + _exsitTime = 0.0f; + _life = 1.0f; + + undead = false; + alpha = 1.0f; + } + void setParent( SsEffectRenderAtom* _p ){ parent = _p; } SsRenderType::_enum getMyType(){ return SsRenderType::BaseNode;} @@ -169,7 +184,7 @@ class SsEffectDrawBatch std::list drawlist; - SsEffectDrawBatch() : priority(0) , dispCell(0),targetNode(0) {} + SsEffectDrawBatch() : priority(0) , dispCell(nullptr), targetNode(nullptr), blendType(SsRenderBlendType::_enum::Mix) {} ~SsEffectDrawBatch(){} void drawSetting(); diff --git a/Common/Animator/ssplayer_effect2.cpp b/Common/Animator/ssplayer_effect2.cpp index af2c0423..6aca4fcc 100644 --- a/Common/Animator/ssplayer_effect2.cpp +++ b/Common/Animator/ssplayer_effect2.cpp @@ -625,6 +625,7 @@ void SsEffectRenderV2::particleDraw(SsEffectEmitter* e , double time , SsEffectE lp.stime = drawe->stime; lp.lifetime = drawe->endtime; lp.pid = 0; + lp.rot = 0; if ( parent )lp.pid = plp->id; @@ -643,8 +644,10 @@ void SsEffectRenderV2::particleDraw(SsEffectEmitter* e , double time , SsEffectE pp.pid = plp->pid; //パーティクルが発生した時間の親の位置を取る + #if 0 // memo: ptime は参照されない。2025/07/09 int ptime = lp.stime + pp.stime; if ( ptime > lp.lifetime ) ptime = lp.lifetime; + #endif //逆算はデバッグしずらいかもしれない parent->updateParticle( (float)lp.stime + pp.stime , &pp); @@ -843,8 +846,9 @@ void SsEffectRenderV2::reload() layoutScale.y = (float)(this->effectData->layoutScaleY) / 100.0f; //MEMO: cnumはスコープ内ワークなので、スマートポインタ化していません。 - int* cnum = new int[list.size()]; - for(size_t i=0; icreate(); } public: - SSTextureFactory(){} + SSTextureFactory(): auto_release_baseclass(true) {} SSTextureFactory(ISSTexture* texture_base_class , bool auto_release_baseclass = true) { m_myInst = this ; m_texture_base_class = texture_base_class; diff --git a/Common/Helper/sshTask.h b/Common/Helper/sshTask.h index c7a6ab7f..53490f9e 100644 --- a/Common/Helper/sshTask.h +++ b/Common/Helper/sshTask.h @@ -73,7 +73,9 @@ class treeitem : public __myclass if ( l > 32 ) l = 32; for ( size_t i = 0 ; i < l ; i++ ) m_ident[i] = _ident[i]; - m_ident[l+1] = 0; + // 1バイトのオーバーラン修正 + //m_ident[l+1] = 0; + m_ident[l] = 0; } @@ -176,7 +178,7 @@ class treeitem : public __myclass } } - if ( root->child == sub ) + if ( root->child == sub && sub != nullptr) { treeitem* temp = root->child; if ( temp ) @@ -187,8 +189,7 @@ class treeitem : public __myclass temp->sibling_next->parent = root; } } - root->child = root->child->sibling_next; - + root->child = root->child ? root->child->sibling_next : nullptr; } if ( root->sibling_next ) diff --git a/Common/Loader/SsEffectBehavior.cpp b/Common/Loader/SsEffectBehavior.cpp index f698fd68..bb5598e5 100644 --- a/Common/Loader/SsEffectBehavior.cpp +++ b/Common/Loader/SsEffectBehavior.cpp @@ -20,23 +20,23 @@ SsEffectElementBase* SsEffectBehavior::Factory(const char* name , libXML::XMLEle SsEffectElementBase * ret = 0; if ( strcmp( name , "Basic" ) == 0 ) ret = new ParticleElementBasic(); - if ( strcmp( name , "OverWriteSeed" ) == 0 ) ret = new ParticleElementRndSeedChange(); - if ( strcmp( name , "Delay" ) == 0 ) ret = new ParticleElementDelay(); - if ( strcmp( name , "Gravity" ) == 0 ) ret = new ParticleElementGravity(); - if ( strcmp( name , "init_position" ) == 0 ) ret = new ParticleElementPosition(); -// if ( strcmp( name , "trans_position" ) == 0 ) ret = new ParticleElementTransPosition(); - if ( strcmp( name , "init_rotation" ) == 0 ) ret = new ParticleElementRotation(); - if ( strcmp( name , "trans_rotation" ) == 0 ) ret = new ParticleElementRotationTrans(); - if ( strcmp( name , "trans_speed" ) == 0 ) ret = new ParticleElementTransSpeed(); - if ( strcmp( name , "add_tangentiala" ) == 0 ) ret = new ParticleElementTangentialAcceleration(); - if ( strcmp( name , "init_vertexcolor" ) == 0 ) ret = new ParticleElementInitColor(); - if ( strcmp( name , "trans_vertexcolor" ) == 0 ) ret = new ParticleElementTransColor(); - if ( strcmp( name , "trans_colorfade" ) == 0 ) ret = new ParticleElementAlphaFade(); - if ( strcmp( name , "init_size" ) == 0 ) ret = new ParticleElementSize(); - if ( strcmp( name , "trans_size" ) == 0 ) ret = new ParticleElementTransSize(); - if ( strcmp( name , "add_pointgravity" ) == 0 ) ret = new ParticlePointGravity(); - if ( strcmp( name , "TurnToDirection" ) == 0 ) ret = new ParticleTurnToDirectionEnabled(); - if ( strcmp( name , "InfiniteEmit" ) == 0 ) ret = new ParticleInfiniteEmitEnabled(); + else if ( strcmp( name , "OverWriteSeed" ) == 0 ) ret = new ParticleElementRndSeedChange(); + else if ( strcmp( name , "Delay" ) == 0 ) ret = new ParticleElementDelay(); + else if ( strcmp( name , "Gravity" ) == 0 ) ret = new ParticleElementGravity(); + else if ( strcmp( name , "init_position" ) == 0 ) ret = new ParticleElementPosition(); +// else if ( strcmp( name , "trans_position" ) == 0 ) ret = new ParticleElementTransPosition(); + else if ( strcmp( name , "init_rotation" ) == 0 ) ret = new ParticleElementRotation(); + else if ( strcmp( name , "trans_rotation" ) == 0 ) ret = new ParticleElementRotationTrans(); + else if ( strcmp( name , "trans_speed" ) == 0 ) ret = new ParticleElementTransSpeed(); + else if ( strcmp( name , "add_tangentiala" ) == 0 ) ret = new ParticleElementTangentialAcceleration(); + else if ( strcmp( name , "init_vertexcolor" ) == 0 ) ret = new ParticleElementInitColor(); + else if ( strcmp( name , "trans_vertexcolor" ) == 0 ) ret = new ParticleElementTransColor(); + else if ( strcmp( name , "trans_colorfade" ) == 0 ) ret = new ParticleElementAlphaFade(); + else if ( strcmp( name , "init_size" ) == 0 ) ret = new ParticleElementSize(); + else if ( strcmp( name , "trans_size" ) == 0 ) ret = new ParticleElementTransSize(); + else if ( strcmp( name , "add_pointgravity" ) == 0 ) ret = new ParticlePointGravity(); + else if ( strcmp( name , "TurnToDirection" ) == 0 ) ret = new ParticleTurnToDirectionEnabled(); + else if ( strcmp( name , "InfiniteEmit" ) == 0 ) ret = new ParticleInfiniteEmitEnabled(); if ( ret ) { diff --git a/Common/Loader/SsEffectElement.h b/Common/Loader/SsEffectElement.h index 03f76dae..6e2ba1fc 100644 --- a/Common/Loader/SsEffectElement.h +++ b/Common/Loader/SsEffectElement.h @@ -4,6 +4,7 @@ #include "sstypes.h" #include "ssarchiver.h" +#include "ssstring_uty.h" #include "SsEffectElement.h" namespace spritestudio6 @@ -119,8 +120,8 @@ typedef VarianceValue SsU8cVValue; template<> inline bool VarianceValue::inputString( SsString _value , SsString _subvalue ) { - value = (float)atof(_value.c_str()); - subvalue = (float)atof(_subvalue.c_str()); + value = (float)double_from_string(_value.c_str()); + subvalue = (float)double_from_string(_subvalue.c_str()); return true; } diff --git a/Common/Loader/ssarchiver.cpp b/Common/Loader/ssarchiver.cpp index 11d974ab..f56489a2 100644 --- a/Common/Loader/ssarchiver.cpp +++ b/Common/Loader/ssarchiver.cpp @@ -1,6 +1,7 @@ #include "ssarchiver.h" #include "ssstring_uty.h" #include "sscharconverter.h" +#include namespace spritestudio6 { @@ -47,7 +48,7 @@ bool SsXmlIArchiver::dc( const char* name , float& member ) SPRITESTUDIO6SDK_AR_SELF_CHECK(); SsString str; dc( name , str ); - member = (float)atof( str.c_str() ); + member = (float)double_from_string( str.c_str() ); if (str == "") { return false; @@ -178,10 +179,10 @@ bool SsXmlIArchiver::dc( const char* name , SsCurve& member ) { return false; }else{ - member.startTime = (float)atof( str_list[0].c_str() ); - member.startValue = (float)atof( str_list[1].c_str() ); - member.endTime = (float)atof( str_list[2].c_str() ); - member.endValue = (float)atof( str_list[3].c_str() ); + member.startTime = (float)double_from_string( str_list[0].c_str() ); + member.startValue = (float)double_from_string( str_list[1].c_str() ); + member.endTime = (float)double_from_string( str_list[2].c_str() ); + member.endValue = (float)double_from_string( str_list[3].c_str() ); return true; } @@ -234,8 +235,8 @@ bool SsXmlIArchiver::dc(const char* name, SsBoneBind& member) } else { - member.boneIndex = (float)atof(str_list[0].c_str()); - member.blend = (float)atof(str_list[1].c_str()); + member.boneIndex = (float)double_from_string(str_list[0].c_str()); + member.blend = (float)double_from_string(str_list[1].c_str()); return true; } @@ -296,8 +297,8 @@ bool StringToPoint2( const std::string& str , SsPoint2& point ) point.y = 0; return false; }else{ - point.x = (float)atof( str_list[0].c_str() ); - point.y = (float)atof( str_list[1].c_str() ); + point.x = (float)double_from_string( str_list[0].c_str() ); + point.y = (float)double_from_string( str_list[1].c_str() ); } return true; @@ -316,10 +317,10 @@ bool StringToIRect( const std::string& str , SsIRect& rect ) rect.h = 0; return false; }else{ - rect.x = (int)atof( str_list[0].c_str() ); - rect.y = (int)atof( str_list[1].c_str() ); - rect.w = (int)atof( str_list[2].c_str() ); - rect.h = (int)atof( str_list[3].c_str() ); + rect.x = (int)double_from_string( str_list[0].c_str() ); + rect.y = (int)double_from_string( str_list[1].c_str() ); + rect.w = (int)double_from_string( str_list[2].c_str() ); + rect.h = (int)double_from_string( str_list[3].c_str() ); } return true; diff --git a/Common/Loader/ssarchiver.h b/Common/Loader/ssarchiver.h index b4e13d5c..33c30e88 100644 --- a/Common/Loader/ssarchiver.h +++ b/Common/Loader/ssarchiver.h @@ -7,6 +7,9 @@ #include #include +#include "../Helper/DebugPrint.h" + + // MEMO: 定義順の関係でここでusingしてしまうと問題が発生する // using namespace tinyxml2; @@ -23,7 +26,7 @@ namespace EnumSsArchiver { enum Type { - unkown = 0, //不明 + unknown = 0, //不明 in, //Input out, //Output }; @@ -50,10 +53,10 @@ class ISsXmlArchiver public: - virtual EnumSsArchiver::Type getType(){ return EnumSsArchiver::unkown;} + virtual EnumSsArchiver::Type getType(){ return EnumSsArchiver::unknown;} - ISsXmlArchiver(){} + ISsXmlArchiver(): m_xml(nullptr) {} virtual ~ISsXmlArchiver(){} libXML::XMLElement* getxml(){ return m_xml;} diff --git a/Common/Loader/ssattribute.cpp b/Common/Loader/ssattribute.cpp index a0aa3f0e..1ac805db 100644 --- a/Common/Loader/ssattribute.cpp +++ b/Common/Loader/ssattribute.cpp @@ -1,6 +1,7 @@ #include "ssloader.h" #include "sstypes.h" #include "ssattribute.h" +#include "ssstring_uty.h" #include "../Helper/DebugPrint.h" namespace spritestudio6 @@ -359,8 +360,8 @@ void GetSsDeformAnime(const SsKeyframe* key, SsDeformAttr& v) if (cnt < datasize) { int idx = (int)atoi(str_list[1 + (cnt * 3)].c_str()); //index - float x = (float)atof(str_list[2 + (cnt * 3)].c_str()); //x - float y = (float)atof(str_list[3 + (cnt * 3)].c_str()); //y + float x = (float)double_from_string(str_list[2 + (cnt * 3)].c_str()); //x + float y = (float)double_from_string(str_list[3 + (cnt * 3)].c_str()); //y if (i == idx) diff --git a/Common/Loader/ssattribute.h b/Common/Loader/ssattribute.h index 83c75f97..91d78bb7 100644 --- a/Common/Loader/ssattribute.h +++ b/Common/Loader/ssattribute.h @@ -58,7 +58,7 @@ class SsAttribute //Tag毎に存在する AttributeKeyDic key_dic; public: - SsAttribute(){} + SsAttribute(): tag(SsAttributeKind::_enum::invalid) {} virtual ~SsAttribute(){ for ( AttributeKeyList::iterator itr = key.begin() ; itr != key.end() ; itr ++ ) delete (*itr); diff --git a/Common/Loader/ssloader_ssae.cpp b/Common/Loader/ssloader_ssae.cpp index e0a266d2..b615fe0e 100644 --- a/Common/Loader/ssloader_ssae.cpp +++ b/Common/Loader/ssloader_ssae.cpp @@ -4,6 +4,19 @@ namespace spritestudio6 { +// アニメーション設定。初期値はエディタ(v7.4.2時点)に合わせた。 +SsAnimationSettings::SsAnimationSettings() + : fps(30) + , frameCount(11) + , sortMode(SsPartsSortMode::_enum::prio) + , canvasSize(320, 320) + , pivot(0, 0) + , startFrame(0) + , endFrame(10) +{ +} + + SsAnimePack* ssloader_ssae::Parse(const char* xmlstr , size_t len) { libXML::XMLDocument xml; diff --git a/Common/Loader/ssloader_ssae.h b/Common/Loader/ssloader_ssae.h index 3c30b81d..0b11ce2a 100644 --- a/Common/Loader/ssloader_ssae.h +++ b/Common/Loader/ssloader_ssae.h @@ -28,7 +28,7 @@ class SsAnimationSettings int startFrame; //!< アニメーションの開始フレーム int endFrame; //!< アニメーションの終了フレーム - SsAnimationSettings(){} + SsAnimationSettings(); virtual ~SsAnimationSettings(){} public: @@ -109,7 +109,11 @@ class SsPart public: SsPart() : - name("") , arrayIndex(0), parentIndex(0) , show(0) , locked(0) , maskInfluence(true) + name("") , arrayIndex(0), parentIndex(0) , show(0) , locked(0) , maskInfluence(true), + type(SsPartType::_enum::invalid), + boundsType(SsBoundsType::_enum::none), + inheritType(SsInheritType::_enum::parent), + alphaBlendType(SsBlendType::_enum::mix) { refEffectName = ""; boneLength = 0; @@ -266,7 +270,7 @@ class SsModel public: - SsModel(){} + SsModel(): setupAnimation(nullptr) {} virtual~ SsModel() { for ( std::vector::iterator itr = partList.begin() ; @@ -320,6 +324,8 @@ class SsLabel SsString name; ///< 名前 [変数名変更禁止] int time; ///< 設置された時間(フレーム) [変数名変更禁止] + SsLabel(): time(0) {} + SPRITESTUDIO6SDK_SERIALIZE_BLOCK { SPRITESTUDIO6SDK_SSAR_DECLARE( name ); @@ -342,7 +348,7 @@ class SsAnimation bool isSetup; ///< セットアップアニメか? public: - SsAnimation(){} + SsAnimation(): overrideSettings(false), isSetup(false) {} virtual ~SsAnimation() { for ( std::vector::iterator itr = partAnimes.begin() ; diff --git a/Common/Loader/ssloader_ssce.h b/Common/Loader/ssloader_ssce.h index 99c0e5f3..cfb4a839 100644 --- a/Common/Loader/ssloader_ssce.h +++ b/Common/Loader/ssloader_ssce.h @@ -37,7 +37,7 @@ class SsCell int divw; int divh; - SsCell(){} + SsCell(): rotated(false), ismesh(false), divtype(SsMeshDivType::_enum::polyline_base), divw(1), divh(1) {} virtual ~SsCell() { /* for (std::vector::iterator itr = innerPoint.begin(); @@ -102,7 +102,7 @@ class SsCellMap SsString loadFilepath; ///<実際にロードした場所 - SsCellMap(){} + SsCellMap(): overrideTexSettings(false), wrapMode(SsTexWrapMode::_enum::clamp), filterMode(SsTexFilterMode::_enum::nearlest) {} virtual ~SsCellMap() { for ( std::vector::iterator itr = cells.begin() ; diff --git a/Common/Loader/ssloader_ssee.h b/Common/Loader/ssloader_ssee.h index 989bac11..93c7d1cd 100644 --- a/Common/Loader/ssloader_ssee.h +++ b/Common/Loader/ssloader_ssee.h @@ -90,8 +90,8 @@ class SsEffectNode : public SimpleTree public: SsEffectNode() : - arrayIndex(0), parentIndex(0), - type(SsEffectNodeType::invalid) + arrayIndex(0), parentIndex(0), type(SsEffectNodeType::invalid), visible(true) + {} ~SsEffectNode(){} @@ -129,7 +129,7 @@ class SsEffectModel public: - SsEffectModel() : root(0) + SsEffectModel() : root(nullptr), lockRandSeed(false), isLockRandSeed(false), fps(30), layoutScaleX(1), layoutScaleY(1) {} virtual ~SsEffectModel(){ diff --git a/Common/Loader/ssloader_sspj.cpp b/Common/Loader/ssloader_sspj.cpp index 1ad69c69..2e4640bc 100644 --- a/Common/Loader/ssloader_sspj.cpp +++ b/Common/Loader/ssloader_sspj.cpp @@ -162,8 +162,7 @@ SsProject* ssloader_sspj::Parse_ProjectOnly(const char* xmlstr , size_t len) proj->__Serialize( &ar ); return proj; } - - return 0; + return nullptr; } SsProject* ssloader_sspj::Load(const std::string& filename ) { diff --git a/Common/Loader/ssloader_sspj.h b/Common/Loader/ssloader_sspj.h index c2336a45..5b2a8a22 100644 --- a/Common/Loader/ssloader_sspj.h +++ b/Common/Loader/ssloader_sspj.h @@ -53,7 +53,7 @@ class SsProjectSetting int vertexAnimeFloat; //!< 頂点変形アトリビュートの少数対応 - SsProjectSetting() + SsProjectSetting(): wrapMode(SsTexWrapMode::_enum::clamp), filterMode(SsTexFilterMode::_enum::nearlest), queryExportBaseDirectory(false) { vertexAnimeFloat = false; //!< SpriteStudio6.1以前のデータの場合は存在しないのでOFFを初期値とする } diff --git a/Common/Loader/ssloader_ssqe.h b/Common/Loader/ssloader_ssqe.h index eec21cb1..11a7b0ea 100644 --- a/Common/Loader/ssloader_ssqe.h +++ b/Common/Loader/ssloader_ssqe.h @@ -23,7 +23,7 @@ class SsSequenceItem int repeatCount; /// 繰り返し再生回数 public: - SsSequenceItem(){} + SsSequenceItem(): repeatCount(1) {} virtual ~SsSequenceItem() { } @@ -46,7 +46,7 @@ class SsSequence std::vector list; /// このシーケンスがもつアイテムのリスト public: - SsSequence(){} + SsSequence(): index(0), type(SsSequenceType::_enum::last) {} virtual ~SsSequence() { for ( std::vector::iterator itr = list.begin() ; diff --git a/Common/Loader/ssstring_uty.cpp b/Common/Loader/ssstring_uty.cpp index 3e6d39ff..e6cbc41b 100644 --- a/Common/Loader/ssstring_uty.cpp +++ b/Common/Loader/ssstring_uty.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "../Helper/DebugPrint.h" #ifdef _WIN32 #include @@ -71,21 +72,26 @@ std::string path2file(const std::string &path) { -bool is_digit_string( std::string &in_str , bool* is_priod ) +bool is_digit_string( std::string &in_str , bool* has_period ) { std::istringstream in(in_str); char c; - if ( is_priod != NULL )*is_priod = false; + if ( has_period != NULL ) *has_period = false; - while (in) + if (in_str.empty()) + { + // 空文字列は数字ではない + return false; + } + + while (in.get(c)) { - in.get(c); if ( c < 0 ) return false; if ( c =='.' ) { - if ( is_priod != NULL )*is_priod = true; + if ( has_period != NULL ) *has_period = true; } if ( !(isdigit( c ) || c =='.' || c=='-' || c=='+' ) ) { @@ -261,5 +267,36 @@ bool checkFileVersion(std::string fileVersion, std::string nowVersion) return ret; } +double double_from_string(const char* str, bool* success) +{ + if (success) + *success = false; + + if (str == nullptr || *str == '\0') + { + // Invalid input + return 0.0f; + } + errno = 0; + char* endptr; + double result = strtod(str, &endptr); + if (endptr == str) + { + // No conversion could be performed + //SS_WARN_PRINT("No conversion could be performed"); + //SS_WARN_PRINT(str); + return 0.0f; + } + if (errno == ERANGE) + { + // Underflow or overflow occurred but result is still valid + return result; + } + + if (success) + *success = true; + + return result; +} } // namespace spritestudio6 diff --git a/Common/Loader/ssstring_uty.h b/Common/Loader/ssstring_uty.h index e4777c15..6dbedc87 100644 --- a/Common/Loader/ssstring_uty.h +++ b/Common/Loader/ssstring_uty.h @@ -63,6 +63,13 @@ std::string nomarizeFilename( std::string str ); */ bool checkFileVersion(std::string fileVersion, std::string nowVersion); +/* +* @brief 文字列をdouble型に変換します。 +* @param[in] str 変換する文字列 +* @param[out] success 変換に成功したかどうかを示すフラグ +* retval 変換したdouble値 +*/ +double double_from_string(const char* str, bool* success = nullptr); class SsStringTokenizer @@ -73,7 +80,7 @@ class SsStringTokenizer int tokennum; public: - SsStringTokenizer() {} + SsStringTokenizer(): tokenIndex(0), tokennum(0) {} virtual ~SsStringTokenizer() {} SsStringTokenizer(std::string src_str , char token ) { @@ -95,7 +102,7 @@ class SsStringTokenizer { if (isEnd()) return false; std::string str = string_array[tokenIndex]; - *out = (float)atof(str.c_str()); + *out = (float)double_from_string(str.c_str()); tokenIndex++; return !isEnd(); } diff --git a/Common/Loader/sstypes.h b/Common/Loader/sstypes.h index f9f25f4b..eed107f9 100644 --- a/Common/Loader/sstypes.h +++ b/Common/Loader/sstypes.h @@ -366,7 +366,7 @@ class SsCurve bool syncStartEnd; ///< [編集用パラメータ]カーブエディタでの編集時に始点・終点ハンドルを同期して動かすか? - SsCurve() : startTime(0.f), startValue(0.f), endTime(0.f), endValue(0.f), startKeyTime(0.f), endKeyTime(0.f){} + SsCurve() : startTime(0.f), startValue(0.f), endTime(0.f), endValue(0.f), startKeyTime(0.f), endKeyTime(0.f), syncStartEnd(true) {} ~SsCurve(){} }; @@ -792,8 +792,9 @@ struct SsRefCell int mapid; std::string name; - + SsRefCell(): mapid(0) {} }; + class SsUserDataAnime { public: @@ -811,7 +812,8 @@ class SsUserDataAnime useInteger(false), usePoint(false), useRect(false), - useString(false) + useString(false), + integer(0) {} }; diff --git a/Common/Loader/ssvalue.h b/Common/Loader/ssvalue.h index db2abc3f..93f5b180 100644 --- a/Common/Loader/ssvalue.h +++ b/Common/Loader/ssvalue.h @@ -23,7 +23,7 @@ void SsValueSeriarizer( ISsXmlArchiver* ar , SsValue& v , const std::string key class SsValue{ public: enum{ - unkown, + unknown, string_type, int_type, float_type, @@ -44,6 +44,7 @@ class SsValue{ bool _bool; SsArray* _array; SsHash* _hash; + void* _ptr; }; int _int_temp; @@ -51,101 +52,112 @@ class SsValue{ bool _bool_temp; - SsValue() : type(unkown) , _str(0){} + SsValue(): type(unknown) { init(); } - explicit SsValue(bool b ) : type(boolean_type) { _bool = b; } + explicit SsValue(bool b) : type(boolean_type) { init(); _bool = b; } explicit SsValue(int n, char* org = 0) : type(int_type) { + init(); _int = n; if (org) org_txt = SsString(org); } explicit SsValue(float n, char* org = 0) : type(float_type) { + init(); _float = n; if (org) org_txt = SsString(org); } - explicit SsValue(SsString& str) { type = string_type; _str = new SsString(str); } - explicit SsValue(const char* str) { type = string_type; _str = new SsString(str); } + explicit SsValue(SsString& str) { init(); type = string_type; _str = new SsString(str); } + explicit SsValue(const char* str) { init(); type = string_type; _str = new SsString(str); } explicit SsValue(SsArray& n) - { - type = array_type; - _array = new SsArray(n); - } + { + init(); + type = array_type; + _array = new SsArray(n); + } - explicit SsValue(SsHash& n) { type = hash_type; _hash = new SsHash(n); } + explicit SsValue(SsHash& n) { init(); type = hash_type; _hash = new SsHash(n); } SsValue(const SsValue& x) { - - switch( x.type ) - { - case string_type: - _str = new SsString( *x._str ); - _float_temp = (float)atof( _str->c_str() ); - _int_temp = atoi( _str->c_str() ); - break; - case int_type: - _int = x._int; - _float_temp = (float)_int; - _bool_temp = _int == 1 ? true : false; - break; - case float_type: - _float = x._float; - _int_temp = (int)_float; - _bool_temp = _int > 0 ? true : false; - break; - case boolean_type: - _bool = x._bool; - break; - case array_type: - _array = new SsArray( *x._array); - break; - case hash_type: - _hash = new SsHash( *x._hash); - break; - } - type = x.type; - org_txt = x.org_txt; - + *this = x; } SsValue& operator=(const SsValue& x) { - if (this != &x) { - this->release(); - new (this) SsValue(x); + type = x.type; + name = x.name; + org_txt = x.org_txt; + + // This is not enough because temp values must be determined by the value of my type which is string, int, float and boolean. + _int_temp = x._int_temp; + _float_temp = x._float_temp; + _bool_temp = x._bool_temp; + + switch (x.type) + { + default: + case unknown: + _ptr = x._ptr; + break; + case string_type: + _str = new SsString(*x._str); + _float_temp = (float)double_from_string(x._str->c_str()); + _int_temp = atoi(_str->c_str()); + break; + case int_type: + _int = x._int; + _float_temp = (float)_int; + _bool_temp = _int == 1 ? true : false; + break; + case float_type: + _float = x._float; + _int_temp = (int)_float; + _bool_temp = _float > 0.0f ? true : false; + break; + case boolean_type: + _bool = x._bool; + _int_temp = _bool ? 1 : 0; + _float_temp = _bool ? 1.0f : 0.0f; + break; + case hash_type: + _hash = new SsHash(*x._hash); + break; + case array_type: + _array = new SsArray(*x._array); + break; } return *this; } - void release() + void init() { - name.~SsString(); - org_txt.~SsString(); + _ptr = nullptr; + _int_temp = 0; + _float_temp = 0.0f; + _bool_temp = false; + } - if(type == string_type && _str) { + virtual ~SsValue() { + if (type == string_type && _str) { delete _str; return; } - if(type == array_type && _array) { + if (type == array_type && _array) { delete _array; return; } - if(type == hash_type && _hash) + if (type == hash_type && _hash) { delete _hash; return; } } - virtual ~SsValue() { - release(); - } - template bool is() const; template const T& get() const; template T& get(); @@ -315,13 +327,13 @@ template <> inline bool SsValue::is() const { inline static SsValue SsValueSeriarizer__MakeValue( const char* v ) { std::string temp = v; - bool is_priod; + bool has_period; - if ( is_digit_string( temp , &is_priod) ) + if ( is_digit_string( temp , &has_period) ) { - if ( is_priod ) + if ( has_period ) { - return SsValue( (float)atof( v ) , (char*)v ); + return SsValue( (float)double_from_string( v ) , (char*)v ); } return SsValue( (int)atoi( v ), (char*)v);