Mercurial > pygame
comparison src/_gcommand.h @ 1849:301bc61643a9 math_module
merged changes from trunk
| author | lorenz |
|---|---|
| date | Mon, 16 Nov 2009 18:31:40 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1848:bbc21cd6faeb | 1849:301bc61643a9 |
|---|---|
| 1 /* | |
| 2 pygame - Python Game Library | |
| 3 | |
| 4 This library is free software; you can redistribute it and/or | |
| 5 modify it under the terms of the GNU Library General Public | |
| 6 License as published by the Free Software Foundation; either | |
| 7 version 2 of the License, or (at your option) any later version. | |
| 8 | |
| 9 This library is distributed in the hope that it will be useful, | |
| 10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 Library General Public License for more details. | |
| 13 | |
| 14 You should have received a copy of the GNU Library General Public | |
| 15 License along with this library; if not, write to the Free | |
| 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | |
| 18 */ | |
| 19 | |
| 20 /* | |
| 21 * _movie - movie support for pygame with ffmpeg | |
| 22 * Author: Tyler Laing | |
| 23 * | |
| 24 * This module allows for the loading of, playing, pausing, stopping, and so on | |
| 25 * of a video file. Any format supported by ffmpeg is supported by this | |
| 26 * video player. Any bugs, please email trinioler@gmail.com :) | |
| 27 */ | |
| 28 | |
| 29 | |
| 30 #ifndef _GCOMMAND_H_ | |
| 31 #define _GCOMMAND_H_ | |
| 32 #include <SDL.h> | |
| 33 #include <SDL_thread.h> | |
| 34 #include <Python.h> | |
| 35 | |
| 36 | |
| 37 /* Documentation: Command Queue Infrastructure | |
| 38 * This lower-level infrastructure code is meant to provide greater stability and | |
| 39 * thread safety to the _movie module. Since we cannot manipulate the SDL event queue | |
| 40 * we have to use our own hand-rolled solution. It is just a singly linked list, | |
| 41 * with references to the first and last item, allowing us to do a | |
| 42 * simple push/pop implementation. The items in the list are structs that have | |
| 43 * all the first members of the default Command struct, making it safe to | |
| 44 * cast the pointers from the pseudo-Command structs to a pointer to | |
| 45 * Command struct. Realistically, you can cast any pointer to any other kind of | |
| 46 * pointer(as long as they are the same size!), and C will let you. This is dangerous, | |
| 47 * and should only be done very, very carefully. This facility is only useful | |
| 48 * when you need a OO approach, like we did here. | |
| 49 * | |
| 50 * When making new commands, use the FULL_COMMAND macro, and add a line to registerCommands | |
| 51 * in _gmovie.c to add a new type value. This also enables future proofing as any changes to | |
| 52 * the Command struct will be opaque to the user... mostly. | |
| 53 * | |
| 54 * -Tyler Laing, August 4th, 2009 | |
| 55 */ | |
| 56 | |
| 57 typedef struct Command | |
| 58 { | |
| 59 int type; | |
| 60 struct Command *next; | |
| 61 } Command; | |
| 62 | |
| 63 #define FULL_COMMAND \ | |
| 64 int type;\ | |
| 65 struct Command *next; | |
| 66 | |
| 67 typedef struct CommandQueue | |
| 68 { | |
| 69 int size; | |
| 70 SDL_mutex *q_mutex; | |
| 71 Command *first; | |
| 72 Command *last; | |
| 73 int registry[1024]; | |
| 74 int reg_ix; | |
| 75 } CommandQueue; | |
| 76 | |
| 77 | |
| 78 void addCommand(CommandQueue *q, Command *comm); | |
| 79 Command *getCommand(CommandQueue *q); | |
| 80 int hasCommand(CommandQueue *q); | |
| 81 void flushCommands(CommandQueue *q); | |
| 82 int registerCommand(CommandQueue *q); | |
| 83 | |
| 84 //convience function for allocating a new command, and ensuring its type is set properly. | |
| 85 #define ALLOC_COMMAND(command, name) command* name = (command *)PyMem_Malloc(sizeof(command)); name->type=movie->command##Type; | |
| 86 | |
| 87 #endif /*_GCOMMAND_H_*/ |
