gpt4 book ai didi

C++等待和休眠问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:14:30 25 4
gpt4 key购买 nike

好的,我正在处理一个菜单,它的工作原理是每 3 秒出现一个新选项,但我正在努力做到这一点,以便在这 3 秒内我可以按下一个按钮来激活一些东西现在看这里:

dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");
if (Key_Down(0, 0x02)) {
dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");
Sleep(1000);
dvar(-1, 0, "c \"^43\"");
Sleep(1000);
dvar(-1, 0, "c \"2\"");
Sleep(1000);
dvar(-1, 0, "c \"^41\"");
Sleep(1000);
}
Sleep(3000);

上面的问题是在“Set prestige one”之后跳到下一个 Sleep(3000) 和下一个选项,现在我需要找到一种方法来继续使用 if statement witch is a button within that 3 秒,而不是它休眠线程并使按钮不可用,除非您在文本加载之前按下它。

我几乎需要做的是让线程休眠,而不是让它等待那 3 秒,这样我仍然可以使用该 if 语句。

这是一个在 XBOX360 上运行的 DLL

当前正在使用的库

#include "stdafx.h"
#include < stdio.h >
#include <string>
#include <iostream>

最佳答案

我认为您会尝试用以下思想进行编程::

  1. 事件驱动。
  2. 多线程。使用系统计时器事件服务。
  3. 基于状态机。

伪代码是这样的::

int State = IDLE;
dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");

while (1)
{
switch (SomeEvent)
{
case ON_Key_down:
if (Key == 0x02)
{
if (State == IDLE || State == KEY_PRESSED_SET1stPRESTIGE_Finish)
{
State = KEY_PRESSED_SET1stPRESTIGE_1stSTEP;
dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");

Timer_Event_AfterMS(1000); // make request event after 1sec to system alarm service
}
else
{
// ignore do something
}
}
break;
case ON_Timer_SomeSec:
if (State == KEY_PRESSED_SET1stPRESTIGE_1stSTEP)
{
dvar(-1, 0, "c \"^43\"");
State = KEY_PRESSED_SET1stPRESTIGE_2ndSTEP;
Timer_Event_AfterMS(1000); // make request event after 1sec to system alarm service
}
else if (State == KEY_PRESSED_SET1stPRESTIGE_2ndSTEP)
{
dvar(-1, 0, "c \"2\"");
State = KEY_PRESSED_SET1stPRESTIGE_3rdSTEP;
Timer_Event_AfterMS(1000); // make request event after 1sec to system alarm service
}
else if (State == KEY_PRESSED_SET1stPRESTIGE_3rdSTEP)
{
dvar(-1, 0, "c \"^41\"");
State = KEY_PRESSED_SET1stPRESTIGE_4rdSTEP;
Timer_Event_AfterMS(1000); // make request event after 1sec to system alarm service
}
else if (State == KEY_PRESSED_SET1stPRESTIGE_4rdSTEP)
{
State = KEY_PRESSED_SET1stPRESTIGE_Need3SEC;
Timer_Event_AfterMS(3000); // make request event after 3sec to system alarm service
}
else if (State == KEY_PRESSED_SET1stPRESTIGE_Need3SEC)
{
State == KEY_PRESSED_SET1stPRESTIGE_Finish;
}
break;
default:
break;
}
}

关于C++等待和休眠问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12434955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com