gpt4 book ai didi

c++ - 将 SDL_PeepEvents 从 SDL 1.2.14 迁移到 SDL 1.3

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:16 25 4
gpt4 key购买 nike

我正在将使用 SDL 1.2 框架用 C++ 编写的 OS X 应用程序移植到使用 SDL 1.3 框架的 iOS。方法发生了一些变化,我在重写几段代码时遇到了麻烦。以下是 1.2.14 中 SDL_PeepEvents 方法的注释和声明:

/**
* Checks the event queue for messages and optionally returns them.
*
* If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to
* the back of the event queue.
* If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front
* of the event queue, matching 'mask', will be returned and will not
* be removed from the queue.
* If 'action' is SDL_GETEVENT, up to 'numevents' events at the front
* of the event queue, matching 'mask', will be returned and will be
* removed from the queue.
*
* @return
* This function returns the number of events actually stored, or -1
* if there was an error.
*
* This function is thread-safe.
*/
extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents,
SDL_eventaction action, Uint32 mask);

这是 1.3 中相同方法的声明:

/**
* Checks the event queue for messages and optionally returns them.
*
* If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
* the back of the event queue.
*
* If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
* of the event queue, within the specified minimum and maximum type,
* will be returned and will not be removed from the queue.
*
* If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
* of the event queue, within the specified minimum and maximum type,
* will be returned and will be removed from the queue.
*
* \return The number of events actually stored, or -1 if there was an error.
*
* This function is thread-safe.
*/
extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
SDL_eventaction action,
Uint32 minType, Uint32 maxType);

最后,这是我要重写的方法:

/**
* Returns true if the queue is empty of events that match 'mask'.
*/
bool EventHandler::timerQueueEmpty() {
SDL_Event event;

if (SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_USEREVENT)))
return false;
else
return true;
}

它目前在编译时抛出以下错误 - “SDL_EVENTMASK”未在此范围内声明。我完全理解错误的发生是因为 SDL_EVENTMASK 不再是 SDL_PeepEvents 函数的参数。我也了解到Uint32Mask已经被Uint32 minType, Uint32 maxType取代了。我只是很难理解如何使用这些新参数重写代码。

最佳答案

正如您所说,SDL 1.3 使用事件范围而不是事件掩码。此代码应适用于 SDL 1.3:

SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_USEREVENT, SDL_NUMEVENTS - 1);  // Peek events in the user range

另一个装饰性的东西 - 你不必检查 bool 变量的 if 然后返回 true/false:

/**
* Returns true if the queue is empty of events that match 'mask'.
*/
bool EventHandler::timerQueueEmpty() {
SDL_Event event;

return SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_USEREVENT, SDL_NUMEVENTS - 1) != 0;
}

关于c++ - 将 SDL_PeepEvents 从 SDL 1.2.14 迁移到 SDL 1.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4178655/

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