| 1 | #include "Library/Area/AreaObj.h" |
| 2 | |
| 3 | #include "Library/Area/AreaInitInfo.h" |
| 4 | #include "Library/Area/AreaObjGroup.h" |
| 5 | #include "Library/Area/AreaShape.h" |
| 6 | #include "Library/Placement/PlacementFunction.h" |
| 7 | #include "Library/Placement/PlacementInfo.h" |
| 8 | #include "Library/Stage/StageSwitchKeeper.h" |
| 9 | #include "Library/Stage/StageSwitchUtil.h" |
| 10 | #include "Library/Thread/FunctorV0M.h" |
| 11 | |
| 12 | namespace al { |
| 13 | |
| 14 | AreaObj::AreaObj(const char* name) : mName(name) {} |
| 15 | |
| 16 | void AreaObj::initStageSwitchKeeper() { |
| 17 | mStageSwitchKeeper = new StageSwitchKeeper(); |
| 18 | } |
| 19 | |
| 20 | void AreaObj::init(const AreaInitInfo& initInfo) { |
| 21 | using AreaObjFunctor = FunctorV0M<AreaObj*, void (AreaObj::*)()>; |
| 22 | |
| 23 | mPlacementInfo = new PlacementInfo(initInfo); |
| 24 | mSceneObjHolder = initInfo.getSceneObjHolder(); |
| 25 | tryGetMatrixTR(matrix: &mAreaTR, placementInfo: *mPlacementInfo); |
| 26 | tryGetArg(arg: &mPriority, placementInfo: *mPlacementInfo, key: "Priority" ); |
| 27 | |
| 28 | const char* modelName = nullptr; |
| 29 | alPlacementFunction::tryGetModelName(modelName: &modelName, placementInfo: *mPlacementInfo); |
| 30 | |
| 31 | AreaShapeFactory areaShapeFactory("エリアシェイプファクトリー" ); |
| 32 | AreaShapeCreatorFunction creatorFunc = nullptr; |
| 33 | areaShapeFactory.getEntryIndex(creationPtr: &creatorFunc, entryName: modelName); |
| 34 | mAreaShape = creatorFunc(); |
| 35 | |
| 36 | mAreaShape->setBaseMtxPtr(&mAreaTR); |
| 37 | sead::Vector3f scale = {1.0f, 1.0f, 1.0f}; |
| 38 | tryGetScale(scale: &scale, placementInfo: *mPlacementInfo); |
| 39 | mAreaShape->setScale(scale); |
| 40 | |
| 41 | initStageSwitch(user: this, stageSwitchDirector: initInfo.getStageSwitchDirector(), placementInfo: initInfo); |
| 42 | if (listenStageSwitchOnOffAppear(user: this, actionOn: AreaObjFunctor(this, &AreaObj::invalidate), |
| 43 | actionOff: AreaObjFunctor(this, &AreaObj::validate))) |
| 44 | invalidate(); |
| 45 | |
| 46 | if (listenStageSwitchOnKill(user: this, action: AreaObjFunctor(this, &AreaObj::validate))) |
| 47 | validate(); |
| 48 | } |
| 49 | |
| 50 | bool AreaObj::isInVolume(const sead::Vector3f& position) const { |
| 51 | if (!mIsValid) |
| 52 | return false; |
| 53 | return mAreaShape->isInVolume(position); |
| 54 | } |
| 55 | |
| 56 | bool AreaObj::isInVolumeOffset(const sead::Vector3f& position, f32 offset) const { |
| 57 | if (!mIsValid) |
| 58 | return false; |
| 59 | return mAreaShape->isInVolumeOffset(position, offset); |
| 60 | } |
| 61 | |
| 62 | } // namespace al |
| 63 | |