Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cocos2dx(Ver2)が闇な話

 Cocos2dx(Ver2)が闇な話

Cocos2dx(Ver2)が如何に闇かCCArrayというCocos2dx(Ver2)の闇の凝縮体の解説を元に暴く

ぽんこつ

June 28, 2014
Tweet

More Decks by ぽんこつ

Other Decks in Technology

Transcript

  1. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ࣗݾ঺հ ΆΜͭ͜Ͱ͢ (@ponkotuy) ܳऀ౦ژΤϯλʔςΠϝϯτͰήʔϜ࡞ͬͯ·͢ C++͡Όͳͯ͘

    Scala ͷਓͰ͢ ΏͱΓϓϩάϥϚʹ C++ͱϝϞϦ؅ཧ͸ແཧա͗ͨ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  2. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ࿩͢಺༰ Cocos2dx(Ver2) ͕ਏ͍࿩Λ͠·͢ C++03 Ҏલͷ࿩

    No Constexpr, No Template ·ͱ΋ͳ C++ͷ࿩Λظ଴͍ͯ͠Δํ͸ٳܜ࣌ؒͰ͢ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  3. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ιγϟή։ൃͷݱ৔ Wanted ϦονͳεϚʔτϑΥϯΞϓϦ (ωΠςΟϒ) Required

    ϚϧνϓϥοτϑΥʔϜ (ಛʹ iOS + Android) Must σβΠφʔͱͷ࿈ܞ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  4. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ Cocos2dx ͷݱ࣮ Cocos2dx ͸ Objective-C

    ൛ Cocos2d ͷ C++Ҡ২ ݁࿦ͱͯ͠͸։ൃऀ͕ C++෼͔ͬͯͳ͍ ࣮ମ͸ྼԽ Objective-C ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  5. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ Cocos2dx(Ver2) ͷ৅௃CCArray Cocos2dx ໰୊ͷ৅௃ CCArray

    class Objective-C Ͱ͸ NSArray ΑΓߴ଎ͱͯ͠࢖༻Λਪ঑ زΒ͔ͷඪ४ͷϝιου͕ CCArray Λฦͯ͘͠Δ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  6. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ CCArray ͷAPI Create static CCArray*

    create(); Insert void addObject(CCObject* object); CCObject ͱ͔͍͏Կ͔͓ͧ·͍͠΋ͷ͕ ཁૉ͸ CCObject ͷܧঝ͕Ϛετ CCObject ͸ Java ͷશͯͷجఈΫϥε Object Έ͍ͨͳ Cocos2dx ͷΫϥε͸ຆͲશͯ CCObject Λܧঝ͍ͯ͠Δ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  7. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ CCArray ͷAPI ͦͷ2 ϧʔϓͷճ͠ํ CCARRAY_FOREACH(ccArray,

    obj) { CCNode* node = static_cast<CCNode*>(obj); ... } CCARRAY_FOREACH ͱ͍͏ಾϚΫϩ Ұ୴ CCObject ʹม׵͞ΕΔͷͰϒνյ͞ΕΔܕ৘ใ ͪͳΈʹ iterator ͸࣮૷͞Εͯͳ͍ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  8. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ CCArray ͱstd::vector ͷൺֱ std::vector ͱҎԼͷૢ࡞Ͱൺֱ͢Δ

    oat ܕͰ 0 ͔Β n ·ͰίϯςφʹಥͬࠐΉ ˢΛ଍ͯ͠߹ܭ஋Λग़͢ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  9. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ std::vectorʢC++03ʣͷ৔߹ float stdVectorSum(float count) {

    std::vector<float> vec; for(float f = 0.0f; f < count; ++f) vec.push_back(f); return std::accumulate( vec.begin(), vec.end(), 0.0f); } ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  10. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ CCArray ͷ৔߹ float ccArraySum(float count)

    { CCArray* array = CCArray::create(); for(float f = 0.0f; f < count; ++f) array->addObject(new CCFloat(f)); float sum = 0.0f; CCObject* elem = NULL; CCARRAY_FOREACH(array, elem) { CCFloat* f = static_cast<CCFloat*>(elem); sum += f->getValue(); } return sum; } ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  11. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ CCArray ͷͭΒ͍ͱ͜Ζ CCFloat ͱ͍͏ CCObject

    Λܧঝͨ͠ class ͕ඞཁ STL ͷΞϧΰϦζϜ͕࢖͑ͳ͍ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  12. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ଎౓ൺֱ CPU Core i5-4570S 2.90GHz

    OS Ubuntu 14.04 CXX g++4.8.2 CXXFLAGS -O3 Ͱ 10000000 ສཁૉɺઌఔͷίʔυΛճͨ݁͠Ռ͕ CCArray 0.569s std::vector<oat> 0.057s std::vector<CCFloat> 0.397s ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  13. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ଎౓݁࿦ CCArray 0.569s std::vector<oat> 0.057s

    std::vector<CCFloat> 0.397s CCArray ͷ஗͍ͷ͸ CCFloat ͷ boxingɺunboxing ͕ݪҼ ͨͩ͠ std::vector<CCFloat>Ͱ΋ CCArray ͷํ͕஗͍ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  14. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ͪͳΈʹ array->addObject(new CCFloat(f)); ͜Ε͸ϦʔΫͯ͠·ͤΜɻ CCObject

    ͸ࢀরΧ΢ϯτํࣜͷࣗಈղ์Λ࣋ͭ addObject Ͱ retain Λൃߦ (ࢀরΧ΢ϯτ͕+1 removeObject Ͱ release Λൃߦ (ࢀরΧ΢ϯτ͕-1 ͞ΕΔҝͰ͢ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩
  15. ͸͡Ίʹ Cocos2dx ͱ͸ CCArray ݁࿦ ݁࿦ ॳظͷεϚϗήʔϜ։ൃͰڧྗͩͬͨ Cocos2dx Cocos2dx(Ver2) ͷશମతʹ

    CCArray Ϩϕϧͷ࢒೦ઃܭ boxingɺunboxing ͜Θ͍ɺ஗͍ ·ͣ͸ͪΌΜͱ STL ࢖͓͏ Unity(C#) ͔ Cocos2dx(Ver3) ࢖͍͍ͨ ΆΜͭ͜ Cocos2dx(Ver2) ͕ҋͳ࿩