| 1 | #include "Library/Scene/SceneObjHolder.h" |
|---|---|
| 2 | |
| 3 | #include "Library/Scene/ISceneObj.h" |
| 4 | |
| 5 | namespace al { |
| 6 | |
| 7 | SceneObjHolder::SceneObjHolder(ISceneObj* (*creator)(s32), s32 size) |
| 8 | : mCreator(creator), mArraySize(size) { |
| 9 | mSceneObjArray = new ISceneObj*[size]; |
| 10 | |
| 11 | for (s32 i = 0; i < mArraySize; i++) |
| 12 | mSceneObjArray[i] = nullptr; |
| 13 | } |
| 14 | |
| 15 | ISceneObj* SceneObjHolder::create(s32 index) { |
| 16 | if (mSceneObjArray[index]) // already exists |
| 17 | return mSceneObjArray[index]; |
| 18 | |
| 19 | mSceneObjArray[index] = mCreator(index); |
| 20 | mSceneObjArray[index]->initSceneObj(); |
| 21 | return mSceneObjArray[index]; |
| 22 | } |
| 23 | |
| 24 | ISceneObj* SceneObjHolder::tryGetObj(s32 index) const { |
| 25 | return mSceneObjArray[index]; |
| 26 | } |
| 27 | |
| 28 | ISceneObj* SceneObjHolder::getObj(s32 index) const { |
| 29 | return mSceneObjArray[index]; |
| 30 | } |
| 31 | |
| 32 | bool SceneObjHolder::isExist(s32 index) const { |
| 33 | return mSceneObjArray[index] != nullptr; |
| 34 | } |
| 35 | |
| 36 | void SceneObjHolder::setSceneObj(ISceneObj* obj, s32 index) { |
| 37 | mSceneObjArray[index] = obj; |
| 38 | } |
| 39 | |
| 40 | void SceneObjHolder::initAfterPlacementSceneObj(const ActorInitInfo& info) { |
| 41 | for (s32 i = 0; i < mArraySize; i++) |
| 42 | if (mSceneObjArray[i]) |
| 43 | mSceneObjArray[i]->initAfterPlacementSceneObj(info); |
| 44 | } |
| 45 | |
| 46 | } // namespace al |
| 47 |