Skip to content

Commit

Permalink
Merge pull request #5 from NicholasLogan/master
Browse files Browse the repository at this point in the history
GetAllItemID
  • Loading branch information
nazjun authored Dec 15, 2021
2 parents 6c3dd2f + c293609 commit 11f90d8
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
18 changes: 18 additions & 0 deletions source/TouhouDanmakufu/Common/StgEnemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ StgEnemyManager::StgEnemyManager(StgStageController* stageController) {

stageController_ = stageController;

rcDeleteClip_ = DxRect<LONG>(-64, -64, 64, 64);

FileManager::GetBase()->AddLoadThreadListener(this);
}
StgEnemyManager::~StgEnemyManager() {
Expand Down Expand Up @@ -146,6 +148,7 @@ StgEnemyObject::StgEnemyObject(StgStageController* stageController) : StgMoveObj

intersectedPlayerShotCount_ = 0U;

bAutoDelete_ = false;
bEnableGetIntersectionPositionFetch_ = true;
}
StgEnemyObject::~StgEnemyObject() {
Expand All @@ -162,6 +165,21 @@ void StgEnemyObject::Work() {
damageAccumFrame_ = 0;

_Move();

_DeleteInAutoClip();
}
void StgEnemyObject::_DeleteInAutoClip() {
if (!bAutoDelete_) return;
DirectGraphics* graphics = DirectGraphics::GetBase();

DxRect<LONG>* const rcStgFrame = stageController_->GetStageInformation()->GetStgFrameRect();
DxRect<LONG>* const rcClipBase = stageController_->GetEnemyManager()->GetEnemyDeleteClip();

bool bDelete = ((LONG)posX_ < rcClipBase->left) || ((LONG)posX_ > rcStgFrame->GetWidth() + rcClipBase->right)
|| ((LONG)posY_ > rcStgFrame->GetHeight() + rcClipBase->bottom);
if (!bDelete) return;

stageController_->GetMainObjectManager()->DeleteObject(this);
}
void StgEnemyObject::_Move() {
StgMoveObject::_Move();
Expand Down
9 changes: 9 additions & 0 deletions source/TouhouDanmakufu/Common/StgEnemy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class StgEnemyManager : public FileManager::LoadThreadListener {
std::list<ref_unsync_ptr<StgEnemyObject>> listEnemy_;

ref_unsync_ptr<StgEnemyBossSceneObject> objBossScene_;
protected:
DxRect<LONG> rcDeleteClip_;
public:
StgEnemyManager(StgStageController* stageController);
virtual ~StgEnemyManager();
Expand All @@ -37,6 +39,9 @@ class StgEnemyManager : public FileManager::LoadThreadListener {
void AddEnemy(ref_unsync_ptr<StgEnemyObject> obj) { listEnemy_.push_back(obj); }
size_t GetEnemyCount() { return listEnemy_.size(); }

void SetEnemyDeleteClip(const DxRect<LONG>& clip) { rcDeleteClip_ = clip; }
DxRect<LONG>* GetEnemyDeleteClip() { return &rcDeleteClip_; }

void SetBossSceneObject(ref_unsync_ptr<StgEnemyBossSceneObject> obj);
ref_unsync_ptr<StgEnemyBossSceneObject> GetBossSceneObject();
std::list<ref_unsync_ptr<StgEnemyObject>>& GetEnemyList() { return listEnemy_; }
Expand All @@ -63,11 +68,13 @@ class StgEnemyObject : public DxScriptSpriteObject2D, public StgMoveObject, publ

size_t intersectedPlayerShotCount_;

bool bAutoDelete_;
bool bEnableGetIntersectionPositionFetch_;

std::vector<ref_unsync_weak_ptr<StgIntersectionTarget>> ptrIntersectionToShot_;
std::vector<ref_unsync_weak_ptr<StgIntersectionTarget>> ptrIntersectionToPlayer_;

void _DeleteInAutoClip();
virtual void _Move();
virtual void _AddRelativeIntersection();
public:
Expand All @@ -85,6 +92,8 @@ class StgEnemyObject : public DxScriptSpriteObject2D, public StgMoveObject, publ

ref_unsync_ptr<StgEnemyObject> GetOwnObject();

void SetAutoDelete(bool b) { bAutoDelete_ = b; }

double GetLife() { return life_; }
double GetLifeDelta() { return lifeDelta_; }
void SetLife(double life) { life_ = lifePrev_ = life; }
Expand Down
20 changes: 17 additions & 3 deletions source/TouhouDanmakufu/Common/StgItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,29 @@ void StgItemManager::CancelCollectItems() {
bCancelToPlayer_ = true;
}

std::vector<int> StgItemManager::GetItemIdInCircle(int cx, int cy, int radius, int* itemType) {
int rr = radius * radius;
std::vector<int> StgItemManager::GetItemIdInCircle(int cx, int cy, int* radius, int* itemType) {
int r = radius ? *radius : 0;
int rr = r * r;

int rect_x1 = cx - r;
int rect_y1 = cy - r;
int rect_x2 = cx + r;
int rect_y2 = cy + r;

std::vector<int> res;
for (ref_unsync_ptr<StgItemObject>& obj : listObj_) {
if (obj->IsDeleted()) continue;
if (itemType != nullptr && (*itemType != obj->GetItemType())) continue;

if (Math::HypotSq<int>(cx - obj->GetPositionX(), cy - obj->GetPositionY()) <= rr)
int sx = obj->GetPositionX();
int sy = obj->GetPositionY();

bool bInCircle = radius == nullptr;
if (!bInCircle) {
bool bPassAABB = (sx > rect_x1 && sy > rect_y1) && (sx < rect_x2 && sy < rect_y2);
bInCircle = bPassAABB && Math::HypotSq<int64_t>(cx - sx, cy - sy) <= rr;
}
if (bInCircle)
res.push_back(obj->GetObjectID());
}

Expand Down
2 changes: 1 addition & 1 deletion source/TouhouDanmakufu/Common/StgItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StgItemManager {
void CollectItemsInCircle(const DxCircle& circle);
void CancelCollectItems();

std::vector<int> GetItemIdInCircle(int cx, int cy, int radius, int* itemType);
std::vector<int> GetItemIdInCircle(int cx, int cy, int* radius, int* itemType);

bool IsDefaultBonusItemEnable() { return bDefaultBonusItemEnable_; }
void SetDefaultBonusItemEnable(bool bEnable) { bDefaultBonusItemEnable_ = bEnable; }
Expand Down
2 changes: 1 addition & 1 deletion source/TouhouDanmakufu/Common/StgShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ std::vector<int> StgShotManager::GetShotIdInCircle(int typeOwner, int cx, int cy

bool bInCircle = radius == nullptr;
if (!bInCircle) {
bool bPassAABB = (sx > rect_x1 && sy > rect_y1) && (sx < rect_x2&& sy < rect_y2);
bool bPassAABB = (sx > rect_x1 && sy > rect_y1) && (sx < rect_x2 && sy < rect_y2);
bInCircle = bPassAABB && Math::HypotSq<int64_t>(cx - sx, cy - sy) <= rr;
}
if (bInCircle)
Expand Down
35 changes: 33 additions & 2 deletions source/TouhouDanmakufu/Common/StgStageScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ static const std::vector<function> stgStageFunction = {
{ "GetEnemyIntersectionPosition", StgStageScript::Func_GetEnemyIntersectionPosition, 3 },
{ "GetEnemyIntersectionPositionByIdA1", StgStageScript::Func_GetEnemyIntersectionPositionByIdA1, 1 },
{ "GetEnemyIntersectionPositionByIdA2", StgStageScript::Func_GetEnemyIntersectionPositionByIdA2, 3 },
{ "SetEnemyAutoDeleteClip", StgStageScript::Func_SetEnemyAutoDeleteClip, 4 },
{ "LoadEnemyShotData", StgStageScript::Func_LoadEnemyShotData, 1 },
{ "ReloadEnemyShotData", StgStageScript::Func_ReloadEnemyShotData, 1 },

Expand Down Expand Up @@ -354,6 +355,7 @@ static const std::vector<function> stgStageFunction = {
{ "SetDefaultBonusItemEnable", StgStageScript::Func_SetDefaultBonusItemEnable, 1 },
{ "LoadItemData", StgStageScript::Func_LoadItemData, 1 },
{ "ReloadItemData", StgStageScript::Func_ReloadItemData, 1 },
{ "GetAllItemID", StgStageScript::Func_GetAllItemID, 0 },
{ "GetItemIdInCircleA1", StgStageScript::Func_GetItemIdInCircleA1, 3 },
{ "GetItemIdInCircleA2", StgStageScript::Func_GetItemIdInCircleA2, 4 },
{ "SetItemAutoDeleteClip", StgStageScript::Func_SetItemAutoDeleteClip, 4 },
Expand Down Expand Up @@ -436,6 +438,7 @@ static const std::vector<function> stgStageFunction = {
//STG共通関数:敵オブジェクト操作
{ "ObjEnemy_Create", StgStageScript::Func_ObjEnemy_Create, 1 },
{ "ObjEnemy_Regist", StgStageScript::Func_ObjEnemy_Regist, 1 },
{ "ObjEnemy_SetAutoDelete", StgStageScript::Func_ObjEnemy_SetAutoDelete, 2 },
{ "ObjEnemy_GetInfo", StgStageScript::Func_ObjEnemy_GetInfo, 2 },
{ "ObjEnemy_SetLife", StgStageScript::Func_ObjEnemy_SetLife, 2 },
{ "ObjEnemy_AddLife", StgStageScript::Func_ObjEnemy_AddLife<false>, 2 },
Expand Down Expand Up @@ -1457,6 +1460,17 @@ gstd::value StgStageScript::Func_GetEnemyIntersectionPositionByIdA2(gstd::script
return script->CreateValueArrayValue(listV);
}

gstd::value StgStageScript::Func_SetEnemyAutoDeleteClip(gstd::script_machine* machine, int argc, const gstd::value* argv) {
StgStageScript* script = (StgStageScript*)machine->data;
StgStageController* stageController = script->stageController_;

DxRect<LONG> rect(-argv[0].as_int(), -argv[1].as_int(),
argv[2].as_int(), argv[3].as_int());
stageController->GetEnemyManager()->SetEnemyDeleteClip(rect);

return value();
}

gstd::value StgStageScript::Func_LoadEnemyShotData(gstd::script_machine* machine, int argc, const gstd::value* argv) {
StgStageScript* script = (StgStageScript*)machine->data;
StgStageController* stageController = script->stageController_;
Expand Down Expand Up @@ -2372,6 +2386,13 @@ gstd::value StgStageScript::Func_ReloadItemData(gstd::script_machine* machine, i
bool res = itemManager->LoadItemData(path, true);
return script->CreateBooleanValue(res);
}
gstd::value StgStageScript::Func_GetAllItemID(gstd::script_machine* machine, int argc, const gstd::value* argv) {
StgStageScript* script = (StgStageScript*)machine->data;
StgItemManager* itemManager = script->stageController_->GetItemManager();

std::vector<int> listID = itemManager->GetItemIdInCircle(0, 0, nullptr, nullptr);
return script->CreateIntArrayValue(listID);
}
gstd::value StgStageScript::Func_GetItemIdInCircleA1(gstd::script_machine* machine, int argc, const gstd::value* argv) {
StgStageScript* script = (StgStageScript*)machine->data;
StgItemManager* itemManager = script->stageController_->GetItemManager();
Expand All @@ -2380,7 +2401,7 @@ gstd::value StgStageScript::Func_GetItemIdInCircleA1(gstd::script_machine* machi
int py = argv[1].as_real();
int radius = argv[2].as_real();

std::vector<int> listID = itemManager->GetItemIdInCircle(px, py, radius, nullptr);
std::vector<int> listID = itemManager->GetItemIdInCircle(px, py, &radius, nullptr);
return script->CreateIntArrayValue(listID);
}
gstd::value StgStageScript::Func_GetItemIdInCircleA2(gstd::script_machine* machine, int argc, const gstd::value* argv) {
Expand All @@ -2392,7 +2413,7 @@ gstd::value StgStageScript::Func_GetItemIdInCircleA2(gstd::script_machine* machi
int radius = argv[2].as_real();
int type = argv[3].as_int();

std::vector<int> listID = itemManager->GetItemIdInCircle(px, py, radius, &type);
std::vector<int> listID = itemManager->GetItemIdInCircle(px, py, &radius, &type);
return script->CreateIntArrayValue(listID);
}
gstd::value StgStageScript::Func_SetItemAutoDeleteClip(gstd::script_machine* machine, int argc, const gstd::value* argv) {
Expand Down Expand Up @@ -3442,6 +3463,16 @@ gstd::value StgStageScript::Func_ObjEnemy_Regist(gstd::script_machine* machine,

return value();
}
gstd::value StgStageScript::Func_ObjEnemy_SetAutoDelete(gstd::script_machine* machine, int argc, const gstd::value* argv) {
StgStageScript* script = (StgStageScript*)machine->data;
int id = argv[0].as_int();
StgEnemyObject* obj = script->GetObjectPointerAs<StgEnemyObject>(id);
if (obj) {
bool bAutoDelete = argv[1].as_boolean();
obj->SetAutoDelete(bAutoDelete);
}
return value();
}
gstd::value StgStageScript::Func_ObjEnemy_GetInfo(gstd::script_machine* machine, int argc, const gstd::value* argv) {
DxScript* script = (DxScript*)machine->data;
int id = argv[0].as_int();
Expand Down
3 changes: 3 additions & 0 deletions source/TouhouDanmakufu/Common/StgStageScript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class StgStageScript : public StgControlScript {
static gstd::value Func_GetEnemyIntersectionPosition(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_GetEnemyIntersectionPositionByIdA1(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_GetEnemyIntersectionPositionByIdA2(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_SetEnemyAutoDeleteClip(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_LoadEnemyShotData(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ReloadEnemyShotData(gstd::script_machine* machine, int argc, const gstd::value* argv);

Expand Down Expand Up @@ -298,6 +299,7 @@ class StgStageScript : public StgControlScript {
static gstd::value Func_SetDefaultBonusItemEnable(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_LoadItemData(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ReloadItemData(gstd::script_machine* machine, int argc, const gstd::value* argv);
DNH_FUNCAPI_DECL_(Func_GetAllItemID);
DNH_FUNCAPI_DECL_(Func_GetItemIdInCircleA1);
DNH_FUNCAPI_DECL_(Func_GetItemIdInCircleA2);
DNH_FUNCAPI_DECL_(Func_SetItemAutoDeleteClip);
Expand Down Expand Up @@ -380,6 +382,7 @@ class StgStageScript : public StgControlScript {
//STG共通関数:敵オブジェクト操作
static gstd::value Func_ObjEnemy_Create(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ObjEnemy_Regist(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ObjEnemy_SetAutoDelete(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ObjEnemy_GetInfo(gstd::script_machine* machine, int argc, const gstd::value* argv);
static gstd::value Func_ObjEnemy_SetLife(gstd::script_machine* machine, int argc, const gstd::value* argv);
template<bool CHECK_MAX_DMG>
Expand Down

0 comments on commit 11f90d8

Please sign in to comment.