2010-11-14 2 views
2

Je transfère vers iOS une application OS X écrite en C++ avec le framework SDL 1.2 en utilisant le framework SDL 1.3. Il y a eu quelques changements aux méthodes, et j'ai du mal à réécrire quelques morceaux de code. Voici les commentaires et déclarations pour la méthode de SDL_PeepEvents 1.2.14:Migration de SDL_PeepEvents de SDL 1.2.14 à SDL 1.3

/** 
* 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); 

Voici la déclaration pour la même méthode 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); 

Enfin, la méthode est ici, je suis en train de réécrire:

/** 
* 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; 
} 

Il lance actuellement l'erreur suivante lors de la compilation - « SDL_EVENTMASK » n'a pas été déclarée dans ce champ. Je comprends parfaitement que l'erreur se produit parce que SDL_EVENTMASK n'est plus un paramètre de la fonction SDL_PeepEvents. Je comprends également que Uint32Mask a été remplacé par Uint32 minType, Uint32 maxType. J'ai juste du mal à comprendre comment réécrire le code avec ces nouveaux paramètres.

Répondre

2

SDL 1.3, comme vous l'avez indiqué, utilise la plage d'événements au lieu du masque d'événement. Ce code devrait fonctionner avec SDL 1.3:

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

Une autre chose cosmétique - vous n'avez pas à vérifier avec un si pour les variables booléennes puis return 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; 
}