mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 21:25:24 +00:00
[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.13 版本
This commit is contained in:
@@ -273,19 +273,31 @@ void OpenHarmonyPlatform::onSurfaceChanged(OH_NativeXComponent* component, void*
|
||||
void OpenHarmonyPlatform::onSurfaceDestroyed(OH_NativeXComponent* component, void* window) {
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::tick() {
|
||||
static std::chrono::steady_clock::time_point prevTime;
|
||||
static std::chrono::steady_clock::time_point now;
|
||||
static float dt = 0.f;
|
||||
static float dtSum = 0.f;
|
||||
static uint32_t jsbInvocationTotalCount = 0;
|
||||
static uint32_t jsbInvocationTotalFrames = 0;
|
||||
std::shared_ptr<Scheduler> scheduler = g_app->getScheduler();
|
||||
scheduler->update(dt);
|
||||
EventDispatcher::dispatchTickEvent(dt);
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
now = std::chrono::steady_clock::now();
|
||||
dt = std::chrono::duration_cast<std::chrono::microseconds>(now - prevTime).count() / 1000000.f;
|
||||
prevTime = std::chrono::steady_clock::now();
|
||||
void OpenHarmonyPlatform::setPreferedFramePersecond(int fps) {
|
||||
if (fps == 0) {
|
||||
return;
|
||||
}
|
||||
_prefererredNanosecondsPerFrame = static_cast<long>(1.0 / fps * NANOSECONDS_PER_SECOND); // NOLINT(google-runtime-int)
|
||||
}
|
||||
|
||||
void OpenHarmonyPlatform::tick() {
|
||||
static std::chrono::steady_clock::time_point prevTime;
|
||||
static std::chrono::steady_clock::time_point now;
|
||||
static float dt = 0.f;
|
||||
static double dtNS = NANOSECONDS_60FPS;
|
||||
if (dtNS < static_cast<double>(_prefererredNanosecondsPerFrame)) {
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(
|
||||
_prefererredNanosecondsPerFrame - static_cast<int64_t>(dtNS)));
|
||||
dtNS = static_cast<double>(_prefererredNanosecondsPerFrame);
|
||||
}
|
||||
prevTime = std::chrono::steady_clock::now();
|
||||
std::shared_ptr<Scheduler> scheduler = g_app->getScheduler();
|
||||
scheduler->update(dt);
|
||||
EventDispatcher::dispatchTickEvent(dt);
|
||||
PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
now = std::chrono::steady_clock::now();
|
||||
dtNS = dtNS * 0.1 + 0.9 * static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(now - prevTime).count());
|
||||
dt = static_cast<float>(dtNS) / NANOSECONDS_PER_SECOND;
|
||||
}
|
||||
|
||||
}; // namespace cc
|
||||
|
@@ -78,7 +78,9 @@ public:
|
||||
static void onMessageCallback(const uv_async_t* req);
|
||||
static void timerCb(uv_timer_t* handle);
|
||||
void tick();
|
||||
void setPreferedFramePersecond(int fps);
|
||||
|
||||
int64_t _prefererredNanosecondsPerFrame{NANOSECONDS_60FPS};
|
||||
OH_NativeXComponent* _component{nullptr};
|
||||
OH_NativeXComponent_Callback _callback;
|
||||
uv_timer_t _timerHandle;
|
||||
|
@@ -121,7 +121,8 @@ void Application::onResume()
|
||||
void Application::setPreferredFramesPerSecond(int fps)
|
||||
{
|
||||
_fps = fps;
|
||||
// setPreferredFramesPerSecondJNI(_fps);
|
||||
cocos2d::OpenHarmonyPlatform* platform = cocos2d::OpenHarmonyPlatform::getInstance();
|
||||
platform->setPreferedFramePersecond(_fps);
|
||||
}
|
||||
|
||||
bool Application::isDisplayStats() {
|
||||
|
Reference in New Issue
Block a user