我正在使用SDL 1.3框架将使用SDL 1.2框架编写的OS X应用程序移植到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取代。我很难理解如何使用这些新参数重写代码。
答案 0 :(得分:2)
SDL 1.3,如您所述,使用事件范围而不是事件掩码。此代码应与SDL 1.3一起使用:
SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_USEREVENT, SDL_NUMEVENTS - 1); // Peek events in the user range
另一个美化的东西 - 您不必检查if for boolean变量然后返回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;
}