首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将SDL_PeepEvents从SDL1.2.14迁移到SDL1.3

将SDL_PeepEvents从SDL1.2.14迁移到SDL1.3
EN

Stack Overflow用户
提问于 2010-11-15 01:24:09
回答 1查看 1.1K关注 0票数 2

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

代码语言:javascript
复制
/**
 *  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中相同方法的声明:

代码语言:javascript
复制
/**
 *  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);

最后,下面是我尝试重写的方法:

代码语言:javascript
复制
/**
 * 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取代。我只是很难理解如何用这些新参数重写代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-15 05:16:51

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

代码语言:javascript
复制
SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_USEREVENT, SDL_NUMEVENTS - 1);  // Peek events in the user range

另一件美化的事情--你不需要用if检查布尔变量,然后返回true/false:

代码语言:javascript
复制
/**
 * 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;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4178655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档