Skip to content

Commit 99b568d

Browse files
committed
CCTimer and CCScheduler bindings
1 parent bc95a88 commit 99b568d

File tree

3 files changed

+178
-24
lines changed

3 files changed

+178
-24
lines changed

bindings/2.2081/Cocos2d.bro

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,31 +3693,31 @@ class cocos2d::CCScheduler : cocos2d::CCObject {
36933693
// float getTimeScale();
36943694
// void setTimeScale(float);
36953695
// CCScheduler(cocos2d::CCScheduler const&);
3696-
CCScheduler();
3697-
virtual ~CCScheduler();
3696+
CCScheduler() = m1 0x3b35b0, imac 0x441f20, ios 0x1aa21c;
3697+
virtual ~CCScheduler() = m1 0x3b35ec, imac 0x441f70, ios 0x1aa258;
36983698

36993699
virtual void update(float) = imac 0x443db0, m1 0x3b5480, ios 0x1abb2c;
37003700

3701-
void appendIn(cocos2d::_listEntry**, cocos2d::CCObject*, bool);
3702-
bool isTargetPaused(cocos2d::CCObject*);
3703-
cocos2d::CCSet* pauseAllTargets();
3704-
cocos2d::CCSet* pauseAllTargetsWithMinPriority(int);
3701+
void appendIn(cocos2d::_listEntry**, cocos2d::CCObject*, bool) = m1 0x3b4104, imac 0x442a50, ios 0x1aacc8;
3702+
bool isTargetPaused(cocos2d::CCObject*) = m1 0x3b50a8, imac 0x4439b0, ios inline;
3703+
cocos2d::CCSet* pauseAllTargets() = m1 0x3b52b4, imac 0x443be0, ios inline;
3704+
cocos2d::CCSet* pauseAllTargetsWithMinPriority(int) = m1 0x3b52bc, imac 0x443bf0, ios inline;
37053705
void pauseTarget(cocos2d::CCObject*) = imac 0x443780, m1 0x3b4eb4, ios 0x1ab938;
3706-
void priorityIn(cocos2d::_listEntry**, cocos2d::CCObject*, int, bool);
3707-
void removeHashElement(cocos2d::_hashSelectorEntry*);
3708-
void removeUpdateFromHash(cocos2d::_listEntry*);
3706+
void priorityIn(cocos2d::_listEntry**, cocos2d::CCObject*, int, bool) = m1 0x3b3d64, imac 0x4426d0, ios 0x1aa944;
3707+
void removeHashElement(cocos2d::_hashSelectorEntry*) = m1 0x3b36c4, imac 0x442070, ios 0x1aa2bc;
3708+
void removeUpdateFromHash(cocos2d::_listEntry*) = m1 0x3b458c, imac 0x442ed0, ios 0x1ab12c;
37093709
void resumeTarget(cocos2d::CCObject*) = imac 0x443550, m1 0x3b4cc8, ios 0x1ab74c;
3710-
void resumeTargets(cocos2d::CCSet*);
3711-
unsigned int scheduleScriptFunc(unsigned int, float, bool);
3710+
void resumeTargets(cocos2d::CCSet*) = m1 0x3b53ec, imac 0x443d20, ios inline;
3711+
unsigned int scheduleScriptFunc(unsigned int, float, bool) = m1 0x3b4c00, imac 0x4434b0, ios inline;
37123712
void scheduleSelector(cocos2d::SEL_SCHEDULE, cocos2d::CCObject*, float, bool) = imac 0x442180, m1 0x3b37ec, ios 0x1aa3e4;
37133713
void scheduleSelector(cocos2d::SEL_SCHEDULE, cocos2d::CCObject*, float, unsigned int, float, bool) = imac 0x4421a0, m1 0x3b37fc, ios 0x1aa3f4;
37143714
void scheduleUpdateForTarget(cocos2d::CCObject*, int, bool) = imac 0x442d80, m1 0x3b4450, ios 0x1aaff8;
37153715
void unscheduleAll() = imac 0x441fc0, m1 0x3b3630, ios 0x1aa29c;
37163716
void unscheduleAllForTarget(cocos2d::CCObject*) = imac 0x443320, m1 0x3b4a5c, ios 0x1ab5a8;
3717-
void unscheduleAllWithMinPriority(int);
3718-
void unscheduleScriptEntry(unsigned int);
3717+
void unscheduleAllWithMinPriority(int) = m1 0x3b4970, imac 0x443230, ios 0x1ab4c8;
3718+
void unscheduleScriptEntry(unsigned int) = m1 0x3b4c6c, imac 0x443500, ios inline;
37193719
void unscheduleSelector(cocos2d::SEL_SCHEDULE, cocos2d::CCObject*) = imac 0x441cb0, m1 0x3b3320, ios 0x1a9ffc;
3720-
void unscheduleUpdateForTarget(cocos2d::CCObject const*);
3720+
void unscheduleUpdateForTarget(cocos2d::CCObject const*) = m1 0x3b4844, imac 0x443110, ios 0x1ab39c;
37213721
}
37223722

37233723
[[link(win, android)]]
@@ -4507,20 +4507,20 @@ class cocos2d::CCTime {
45074507

45084508
[[link(win, android)]]
45094509
class cocos2d::CCTimer : cocos2d::CCObject {
4510-
CCTimer();
4510+
CCTimer() = m1 0x3b2eb0, imac 0x441850, ios inline;
45114511

4512-
static cocos2d::CCTimer* timerWithScriptHandler(int, float);
4513-
static cocos2d::CCTimer* timerWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE);
4514-
static cocos2d::CCTimer* timerWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE, float);
4512+
static cocos2d::CCTimer* timerWithScriptHandler(int, float) = m1 0x3b3068, imac 0x441a20, ios inline;
4513+
static cocos2d::CCTimer* timerWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE) = m1 0x3b2ef0, imac 0x4418a0, ios inline;
4514+
static cocos2d::CCTimer* timerWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE, float) = m1 0x3b2fc0, imac 0x441970, ios inline;
45154515

45164516
virtual void update(float) = imac 0x441b00, m1 0x3b3134, ios 0x1a9e18;
45174517

4518-
float getInterval() const;
4519-
cocos2d::SEL_SCHEDULE getSelector() const;
4520-
bool initWithScriptHandler(int, float);
4521-
bool initWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE);
4522-
bool initWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE, float, unsigned int, float);
4523-
void setInterval(float);
4518+
float getInterval() const = m1 0x3b3558, imac 0x441ea0, ios inline;
4519+
cocos2d::SEL_SCHEDULE getSelector() const = m1 0x3b3568, imac 0x441ec0, ios inline;
4520+
bool initWithScriptHandler(int, float) = m1 0x3b30f0, imac 0x441ab0, ios inline;
4521+
bool initWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE) = m1 0x3b3108, imac 0x441ad0, ios inline;
4522+
bool initWithTarget(cocos2d::CCObject*, cocos2d::SEL_SCHEDULE, float, unsigned int, float) = m1 0x3b2f88, imac 0x441930, ios inline;
4523+
void setInterval(float) = m1 0x3b3560, imac 0x441eb0, ios inline;
45244524
}
45254525

45264526
[[link(win, android)]]

bindings/2.2081/inline/CCScheduler.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Geode/Bindings.hpp>
2+
#include <Geode/cocos/support/data_support/utlist.h>
23

34

45
#if defined(GEODE_IS_WINDOWS) || defined(GEODE_IS_IOS)
@@ -8,5 +9,90 @@
89
#endif
910

1011
#if defined(GEODE_IS_IOS)
12+
typedef struct cocos2d::_listEntry {
13+
_listEntry* prev;
14+
_listEntry* next;
15+
CCObject* target;
16+
int priority;
17+
bool paused;
18+
bool markedForDeletion;
19+
} tListEntry;
20+
21+
typedef struct cocos2d::_hashUpdateEntry {
22+
tListEntry** list;
23+
tListEntry* entry;
24+
CCObject* target;
25+
UT_hash_handle hh;
26+
} tHashUpdateEntry;
27+
28+
typedef struct cocos2d::_hashSelectorEntry {
29+
ccArray* timers;
30+
CCObject* target;
31+
unsigned int timerIndex;
32+
CCTimer* currentTimer;
33+
bool currentTimerSalvaged;
34+
bool paused;
35+
UT_hash_handle hh;
36+
} tHashTimerEntry;
37+
38+
bool cocos2d::CCScheduler::isTargetPaused(cocos2d::CCObject* target) {
39+
tHashTimerEntry* element = nullptr;
40+
HASH_FIND_INT(m_pHashForTimers, &target, element);
41+
if (element) return element->paused;
42+
43+
tHashUpdateEntry* elementUpdate = nullptr;
44+
HASH_FIND_INT(m_pHashForUpdates, &target, elementUpdate);
45+
if (elementUpdate) return elementUpdate->entry->paused;
46+
47+
return false;
48+
}
49+
50+
cocos2d::CCSet* cocos2d::CCScheduler::pauseAllTargets() {
51+
return this->pauseAllTargetsWithMinPriority(kCCPrioritySystem);
52+
}
53+
54+
cocos2d::CCSet* cocos2d::CCScheduler::pauseAllTargetsWithMinPriority(int minPriority) {
55+
auto idsWithSelectors = new CCSet();
56+
idsWithSelectors->autorelease();
57+
58+
for (auto element = m_pHashForTimers; element != nullptr; element = static_cast<tHashTimerEntry*>(element->hh.next)) {
59+
element->paused = true;
60+
idsWithSelectors->addObject(element->target);
61+
}
62+
63+
tListEntry* entry;
64+
tListEntry* tmp;
65+
66+
if (minPriority < 0) {
67+
DL_FOREACH_SAFE(m_pUpdatesNegList, entry, tmp) {
68+
if (entry->priority >= minPriority) {
69+
entry->paused = true;
70+
idsWithSelectors->addObject(entry->target);
71+
}
72+
}
73+
}
74+
75+
if (minPriority <= 0) {
76+
DL_FOREACH_SAFE(m_pUpdates0List, entry, tmp) {
77+
entry->paused = true;
78+
idsWithSelectors->addObject(entry->target);
79+
}
80+
}
81+
82+
DL_FOREACH_SAFE(m_pUpdatesPosList, entry, tmp) {
83+
if (entry->priority >= minPriority) {
84+
entry->paused = true;
85+
idsWithSelectors->addObject(entry->target);
86+
}
87+
}
88+
89+
return idsWithSelectors;
90+
}
91+
92+
void cocos2d::CCScheduler::resumeTargets(cocos2d::CCSet* pTargetsToResume) {
93+
for (auto obj : *pTargetsToResume) {
94+
this->resumeTarget(obj);
95+
}
96+
}
1197
#endif
1298

bindings/2.2081/inline/CCTimer.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,73 @@
88
#endif
99

1010
#if defined(GEODE_IS_IOS)
11+
cocos2d::CCTimer::CCTimer() {
12+
m_pTarget = nullptr;
13+
m_fElapsed = -1.f;
14+
m_bRunForever = false;
15+
m_bUseDelay = false;
16+
m_uTimesExecuted = 0;
17+
m_uRepeat = 0;
18+
m_fDelay = 0.f;
19+
m_fInterval = 0.f;
20+
m_pfnSelector = nullptr;
21+
m_nScriptHandler = 0;
22+
}
23+
24+
float cocos2d::CCTimer::getInterval() const {
25+
return m_fInterval;
26+
}
27+
28+
cocos2d::SEL_SCHEDULE cocos2d::CCTimer::getSelector() const {
29+
return m_pfnSelector;
30+
}
31+
32+
bool cocos2d::CCTimer::initWithScriptHandler(int handler, float seconds) {
33+
m_nScriptHandler = handler;
34+
m_fElapsed = -1.f;
35+
m_fInterval = seconds;
36+
return true;
37+
}
38+
39+
bool cocos2d::CCTimer::initWithTarget(cocos2d::CCObject* target, cocos2d::SEL_SCHEDULE selector) {
40+
return this->initWithTarget(target, selector, 0.f, kCCRepeatForever, 0.f);
41+
}
42+
43+
bool cocos2d::CCTimer::initWithTarget(cocos2d::CCObject* target, cocos2d::SEL_SCHEDULE selector, float seconds, unsigned int repeat, float delay) {
44+
m_pTarget = target;
45+
m_pfnSelector = selector;
46+
m_fElapsed = -1.f;
47+
m_fInterval = seconds;
48+
m_fDelay = delay;
49+
m_bUseDelay = delay > 0.f;
50+
m_uRepeat = repeat;
51+
m_bRunForever = repeat == kCCRepeatForever;
52+
return true;
53+
}
54+
55+
void cocos2d::CCTimer::setInterval(float interval) {
56+
m_fInterval = interval;
57+
}
58+
59+
cocos2d::CCTimer* cocos2d::CCTimer::timerWithTarget(cocos2d::CCObject* target, cocos2d::SEL_SCHEDULE selector) {
60+
auto ret = new CCTimer();
61+
ret->initWithTarget(target, selector, 0.f, kCCRepeatForever, 0.f);
62+
ret->autorelease();
63+
return ret;
64+
}
65+
66+
cocos2d::CCTimer* cocos2d::CCTimer::timerWithTarget(cocos2d::CCObject* target, cocos2d::SEL_SCHEDULE selector, float seconds) {
67+
auto ret = new CCTimer();
68+
ret->initWithTarget(target, selector, seconds, kCCRepeatForever, 0.f);
69+
ret->autorelease();
70+
return ret;
71+
}
72+
73+
cocos2d::CCTimer* cocos2d::CCTimer::timerWithScriptHandler(int handler, float seconds) {
74+
auto ret = new CCTimer();
75+
ret->initWithScriptHandler(handler, seconds);
76+
ret->autorelease();
77+
return ret;
78+
}
1179
#endif
1280

0 commit comments

Comments
 (0)