diff --git a/.gitignore b/.gitignore index 15d45fc4..344b4bd4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ SDLPerl.app SDL_perl.c SDL_perl.xs stage -MANIFEST +!MANIFEST !MANIFEST.skip *META.yml *META.json @@ -39,3 +39,4 @@ Build.bat *.def *.exp *.lds +*.obj diff --git a/.perltidyrc b/.perltidyrc new file mode 100644 index 00000000..48b7e5b7 --- /dev/null +++ b/.perltidyrc @@ -0,0 +1 @@ +-pbp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..2b552bf7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: perl +perl: + - "5.8" + - "5.10" + - "5.12" + - "5.14" + - "5.16" + - "5.18" + +before_install: +# install Alien:SDL + - sudo apt-get install automake + - git clone https://github.com/PerlGameDev/Alien-SDL + - cd Alien-SDL + - cat ./cpan-deps | cpanm --sudo --notest + - perl ./Build.PL --travis + - sudo ./Build install + - prove -v + - cd .. +# success!! + +# install SDL_Perl +install: + - cpanm --sudo --notest Test::Most Tie::Simple + - perl ./Build.PL + - sudo ./Build install + +script: prove -v + +notifications: + irc: irc.perl.org#sdl diff --git a/Build.PL b/Build.PL index 688d2215..f2d16aad 100644 --- a/Build.PL +++ b/Build.PL @@ -229,6 +229,7 @@ my %subsystems = ( to => 'lib/SDLx/Layer.xs', }, libraries => [qw( SDL SDL_image )], + load_libs => [qw( z png jpeg tiff )], }, AudioSpec => { file => { @@ -249,7 +250,8 @@ my %subsystems = ( from => 'src/Mixer/Mixer.xs', to => 'lib/SDL/Mixer.xs', }, - libraries => [qw( SDL SDL_mixer )], + libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixerSamples => { file => { @@ -257,6 +259,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/Samples.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixerChannels => { file => { @@ -264,6 +267,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/Channels.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixerGroups => { file => { @@ -271,6 +275,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/Groups.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixerMusic => { file => { @@ -278,6 +283,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/Music.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixerEffects => { file => { @@ -285,6 +291,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/Effects.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixChunk => { file => { @@ -292,6 +299,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/MixChunk.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, MixMusic => { file => { @@ -299,6 +307,7 @@ my %subsystems = ( to => 'lib/SDL/Mixer/MixMusic.xs', }, libraries => [qw( SDL SDL_mixer )], + load_libs => [qw( vorbisfile flac mikmod smpeg )], }, Palette => { file => { @@ -383,6 +392,7 @@ my %subsystems = ( to => 'lib/SDL/Image.xs', }, libraries => [qw( SDL SDL_image )], + load_libs => [qw( z png jpeg tiff )], }, SFont => { file => { @@ -390,6 +400,7 @@ my %subsystems = ( to => 'lib/SDLx/SFont.xs', }, libraries => [qw( SDL SDL_image )], + load_libs => [qw( z png jpeg tiff )], }, # SMPEG => { @@ -520,6 +531,11 @@ my %libraries = ( header => 'SDL_Pango.h', lib => 'SDL_Pango', }, + z => { + define => 'HAVE_Z', + header => 'zlib.h', + lib => 'z', + }, png => { define => 'HAVE_PNG', header => 'png.h', @@ -535,7 +551,15 @@ my %libraries = ( header => 'tiff.h', lib => 'tiff', }, - + vorbisfile => { + lib => 'vorbisfile', + }, + flac => { + lib => 'FLAC', + }, + mikmod => { + lib => 'mikmod', + }, smpeg => { define => 'HAVE_SMPEG', header => 'smpeg/smpeg.h', @@ -568,26 +592,24 @@ my $build = $package->new( license => 'lgpl', dist_version_from => 'lib/SDL.pm', configure_requires => { + 'Module::Build' => '0', 'ExtUtils::CBuilder' => '0.260301', - 'Alien::SDL' => '1.426', + 'Alien::SDL' => '1.444', 'File::Find' => '0', 'File::ShareDir' => '1.0', - 'Tie::Simple' => '0', 'Capture::Tiny' => '0', }, build_requires => { 'Test::Simple' => '0.88', 'Capture::Tiny' => '0', 'Test::Most' => '0.21', - 'Alien::SDL' => '1.426', + 'Alien::SDL' => '1.444', 'File::Find' => '0', 'File::ShareDir' => '1.0', - 'Tie::Simple' => '0', 'Scalar::Util' => '0', }, requires => { 'Scalar::Util' => '0', - 'Tie::Simple' => '0', 'File::ShareDir' => '1.0', 'CPAN' => '1.92', 'perl' => '5.008000', @@ -606,7 +628,7 @@ my $build = $package->new( #create_readme => 1, ### make sense only if there is some POD doc in the file specified by dist_version_from meta_merge => { resources => { - bugtracker => 'http://sdlperl.ath.cx/projects/SDLPerl', + bugtracker => 'http://github.com/PerlGameDev/SDL/issues', repository => 'http://github.com/PerlGameDev/SDL' } }, diff --git a/CHANGELOG b/CHANGELOG index e5d1144a..bd4b1854 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,38 @@ -Revision history for Perl extension SDL_perl. +Revision history for Perl extension SDL Versioning rule: public releases are even numbers, dev releases are odd. (same like perl dist) -* 2.537_02 Feb 13 2012 +* 2.544 May 14 2014 + - Updated Alien::SDL's version we depend on to get an OpenBSD/pthread fix [FROGGS] + - Fix segfault in cleanup of MixChunks on windows [FROGGS] + - Adjusting test for SDL_gfx >= 2.0.24 [FROGGS] + +* 2.540 May 26 2012 + - Removed all non-pod changes introduced in 2.538 [jtpalmer] + - Fixed bugtracker link [FROGGS] + - Added SDL::Platform pod [pktm] + +* 2.538 May 22 2012 + - Pod updates [mig0] + - SDLx::App made the docs a lot better [Blaizer] + - SDLx::App changed around shortcut names in the constructor [Blaizer] + - SDLx::App added and improved parameters of the constructor, see docs [Blaizer] + - SDLx::App updated methods resize, title, icon, error, show_cursor, grab_input [Blaizer] + - SDLx::App fullscreen method works better [Blaizer] + - SDLx::App new init method does our initializing right [Blaizer] + - SDLx::App new set_video_mode method does set_video_mode for SDLx::App [Blaizer] + - SDLx::App new screen_size method returns the user's screen size [Blaizer] + - SDLx::App warp method renamed to warp_cursor, attribute renamed to gl_attribute [Blaizer] + - SDLx::App fix to return the user's resolution to normal when a fullscreen app closes [FROGGS] + - SDLx::App removed delay method and deprecated get_ticks [Blaizer] + - SDLx::Controller removed eoq, its action is on by default and implemented by stop_handler [Blaizer] + - SDLx::Controller made the docs a lot better, even proofread them [Blaizer] + - SDLx::Controller pause works by stopping the app [Blaizer] + - SDLx::Controller added stopped and paused methods to tell what the app is doing [Blaizer] + - SDLx::Controller added max_t param, by default slows down apps going at less than 10 FPS [Blaizer] + - SDLx::Controller added time and sleep methods to replace get_ticks and delay [Blaizer] + - SDLx::Controller added some tests for pausing and events [Blaizer] + - SDLx::Controller removed current_time parameter [Blaizer] - t/core_cd.t: gnu hurd 0.3 handles devices like cdrom strange (skipping tests) [FROGGS] - t/sdlx_fps.t: seems better to try to get 5 fps (slow vm's) [FROGGS] - SDLx::Controller::Interface: weaken tests [FROGGS] diff --git a/COPYING b/COPYING index 191a97fe..d159169d 100644 --- a/COPYING +++ b/COPYING @@ -1,25 +1,22 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -30,347 +27,195 @@ in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE +modification follow. + + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, +identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of +on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. +entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or -collective works based on the Library. +collective works based on the Program. -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are +distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying -the Library or works based on it. +the Program or works based on it. - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. - - 11. If, as a consequence of a court judgment or allegation of patent + + 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. +refrain entirely from distribution of the Program. -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is +integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that @@ -381,57 +226,114 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - 12. If the distribution and/or use of the Library is restricted in + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 00000000..b5bdede6 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,362 @@ +Build.PL +CHANGELOG +COPYING +examples/cookbook/1.pl +examples/cookbook/openglapp.pl +examples/cookbook/pdl.pl +examples/cookbook/pogl_sdl_texture.pl +examples/GFX/script_roto.pl +examples/pixel_operations/fast_pixel_write.pl +examples/pixel_operations/sols/ch02.pl +examples/pixel_operations/starry.pl +examples/pixel_operations/tie_matrix.pl +examples/SDLx/app.pl +examples/SDLx/music.pl +examples/SDLx/pong.pl +examples/SDLx/SDLx_C_Interface.pl +examples/SDLx/SDLx_controller_two_squares.pl +examples/SDLx/SDLx_LayerManager_Chess.pl +examples/SDLx/SDLx_Sound.pl +examples/SDLx/SDLx_sprite.pl +examples/SDLx/SDLx_sprite_animated.pl +examples/SDLx/SDLx_text.pl +examples/SDLx/SDLx_text_shadow.pl +examples/SDLx/SDLx_text_styles.pl +examples/SDLx/SDLx_text_wordwrap.pl +examples/SDLx/SDLx_text_zoom.pl +inc/My/Builder.pm +inc/My/Builder/Darwin.pm +inc/My/Builder/Unix.pm +inc/My/Builder/Windows.pm +INSTALL +lib/Module/Build/SDL.pm +lib/pods/SDL.pod +lib/pods/SDL/Audio.pod +lib/pods/SDL/AudioCVT.pod +lib/pods/SDL/AudioSpec.pod +lib/pods/SDL/CD.pod +lib/pods/SDL/CDROM.pod +lib/pods/SDL/CDTrack.pod +lib/pods/SDL/Color.pod +lib/pods/SDL/Cookbook.pod +lib/pods/SDL/Cookbook/OpenGL.pod +lib/pods/SDL/Cookbook/PDL.pod +lib/pods/SDL/Credits.pod +lib/pods/SDL/Cursor.pod +lib/pods/SDL/Deprecated.pod +lib/pods/SDL/Event.pod +lib/pods/SDL/Events.pod +lib/pods/SDL/GFX/BlitFunc.pod +lib/pods/SDL/GFX/FPSManager.pod +lib/pods/SDL/GFX/Framerate.pod +lib/pods/SDL/GFX/ImageFilter.pod +lib/pods/SDL/GFX/Primitives.pod +lib/pods/SDL/GFX/Rotozoom.pod +lib/pods/SDL/Image.pod +lib/pods/SDL/Joystick.pod +lib/pods/SDL/Mixer.pod +lib/pods/SDL/Mixer/Channels.pod +lib/pods/SDL/Mixer/Effects.pod +lib/pods/SDL/Mixer/Groups.pod +lib/pods/SDL/Mixer/MixChunk.pod +lib/pods/SDL/Mixer/MixMusic.pod +lib/pods/SDL/Mixer/Music.pod +lib/pods/SDL/Mixer/Samples.pod +lib/pods/SDL/Mouse.pod +lib/pods/SDL/MPEG.pod +lib/pods/SDL/MultiThread.pod +lib/pods/SDL/Overlay.pod +lib/pods/SDL/Palette.pod +lib/pods/SDL/Pango.pod +lib/pods/SDL/Pango/Context.pod +lib/pods/SDL/PixelFormat.pod +lib/pods/SDL/Platform.pod +lib/pods/SDL/Rect.pod +lib/pods/SDL/RWOps.pod +lib/pods/SDL/SMPEG.pod +lib/pods/SDL/Surface.pod +lib/pods/SDL/Time.pod +lib/pods/SDL/TTF.pod +lib/pods/SDL/TTF/Font.pod +lib/pods/SDL/Tutorial.pod +lib/pods/SDL/Tutorial/Animation.pod +lib/pods/SDL/Tutorial/LunarLander.pod +lib/pods/SDL/Version.pod +lib/pods/SDL/Video.pod +lib/pods/SDL/VideoInfo.pod +lib/pods/SDLx/App.pod +lib/pods/SDLx/Controller.pod +lib/pods/SDLx/Controller/Interface.pod +lib/pods/SDLx/Controller/State.pod +lib/pods/SDLx/Layer.pod +lib/pods/SDLx/LayerManager.pod +lib/pods/SDLx/Music.pod +lib/pods/SDLx/Rect.pod +lib/pods/SDLx/SFont.pod +lib/pods/SDLx/Sound.pod +lib/pods/SDLx/Sprite.pod +lib/pods/SDLx/Sprite/Animated.pod +lib/pods/SDLx/Surface.pod +lib/pods/SDLx/Text.pod +lib/SDL.pm +lib/SDL/Audio.pm +lib/SDL/AudioCVT.pm +lib/SDL/AudioSpec.pm +lib/SDL/CD.pm +lib/SDL/CDROM.pm +lib/SDL/CDTrack.pm +lib/SDL/Color.pm +lib/SDL/Config.pm +lib/SDL/Constants.pm +lib/SDL/Cursor.pm +lib/SDL/Event.pm +lib/SDL/Events.pm +lib/SDL/GFX.pm +lib/SDL/GFX/BlitFunc.pm +lib/SDL/GFX/FPSManager.pm +lib/SDL/GFX/Framerate.pm +lib/SDL/GFX/ImageFilter.pm +lib/SDL/GFX/Primitives.pm +lib/SDL/GFX/Rotozoom.pm +lib/SDL/Image.pm +lib/SDL/Internal/Loader.pm +lib/SDL/Joystick.pm +lib/SDL/Mixer.pm +lib/SDL/Mixer/Channels.pm +lib/SDL/Mixer/Effects.pm +lib/SDL/Mixer/Groups.pm +lib/SDL/Mixer/MixChunk.pm +lib/SDL/Mixer/MixMusic.pm +lib/SDL/Mixer/Music.pm +lib/SDL/Mixer/Samples.pm +lib/SDL/Mouse.pm +lib/SDL/MultiThread.pm +lib/SDL/Net.pm +lib/SDL/Net/IPaddress.pm +lib/SDL/Net/TCP.pm +lib/SDL/Net/UDP.pm +lib/SDL/Overlay.pm +lib/SDL/Palette.pm +lib/SDL/Pango.pm +lib/SDL/Pango/Context.pm +lib/SDL/PixelFormat.pm +lib/SDL/Rect.pm +lib/SDL/RWOps.pm +lib/SDL/SMPEG.pm +lib/SDL/SMPEG/Info.pm +lib/SDL/Surface.pm +lib/SDL/Time.pm +lib/SDL/TTF.pm +lib/SDL/TTF/Font.pm +lib/SDL/TTFont.pm +lib/SDL/Tutorial.pm +lib/SDL/Tutorial/Animation.pm +lib/SDL/Tutorial/LunarLander.pm +lib/SDL/Version.pm +lib/SDL/Video.pm +lib/SDL/VideoInfo.pm +lib/SDL_perl.pm +lib/SDLx/App.pm +lib/SDLx/Controller.pm +lib/SDLx/Controller/Interface.pm +lib/SDLx/Controller/State.pm +lib/SDLx/Controller/Timer.pm +lib/SDLx/FPS.pm +lib/SDLx/Layer.pm +lib/SDLx/LayerManager.pm +lib/SDLx/Music.pm +lib/SDLx/Music/Data.pm +lib/SDLx/Music/Default.pm +lib/SDLx/Rect.pm +lib/SDLx/SFont.pm +lib/SDLx/Sound.pm +lib/SDLx/Sprite.pm +lib/SDLx/Sprite/Animated.pm +lib/SDLx/Surface.pm +lib/SDLx/Surface/TiedMatrix.pm +lib/SDLx/Surface/TiedMatrixRow.pm +lib/SDLx/Text.pm +lib/SDLx/TTF.pm +lib/SDLx/Validate.pm +MacOSX/Info.plist +MacOSX/main.c +MacOSX/Makefile.test +MacOSX/SDLPerl.icns +MANIFEST This list of files +META.json +META.yml +OFL-FAQ.txt +OFL.txt +README +scripts/auto_constants.pl +scripts/const.pl +scripts/gl_const.pl +scripts/MultiThreadPOC.pl +scripts/sdl_const.pl +scripts/sdl_module_maker.pl +scripts/SDLpp.pl +share/GenBasR.ttf +src/Core/Audio.xs +src/Core/CDROM.xs +src/Core/Events.xs +src/Core/Joystick.xs +src/Core/Mouse.xs +src/Core/MultiThread.xs +src/Core/objects/AudioCVT.xs +src/Core/objects/AudioSpec.xs +src/Core/objects/CD.xs +src/Core/objects/CDTrack.xs +src/Core/objects/Color.xs +src/Core/objects/Cursor.xs +src/Core/objects/Event.xs +src/Core/objects/keysym.xs +src/Core/objects/Overlay.xs +src/Core/objects/Palette.xs +src/Core/objects/PixelFormat.xs +src/Core/objects/Rect.xs +src/Core/objects/RWOps.xs +src/Core/objects/Surface.xs +src/Core/objects/typemap +src/Core/objects/Version.xs +src/Core/objects/VideoInfo.xs +src/Core/Time.xs +src/Core/Video.xs +src/defines.h +src/GFX/BlitFunc.xs +src/GFX/CHANGELOG +src/GFX/FPSManager.xs +src/GFX/Framerate.xs +src/GFX/GFX.xs +src/GFX/ImageFilter.xs +src/GFX/Primitives.xs +src/GFX/README +src/GFX/Rotozoom.xs +src/helper.h +src/Image.xs +src/Mixer/Channels.xs +src/Mixer/Effects.xs +src/Mixer/Groups.xs +src/Mixer/Mixer.xs +src/Mixer/Music.xs +src/Mixer/objects/MixChunk.xs +src/Mixer/objects/MixMusic.xs +src/Mixer/README +src/Mixer/Samples.xs +src/Pango/objects/Context.xs +src/Pango/Pango.xs +src/ppport.h +src/SDL.xs +src/SDLx/Controller/Interface.h +src/SDLx/Controller/Interface.xs +src/SDLx/Controller/State.xs +src/SDLx/Layer.h +src/SDLx/Layer.xs +src/SDLx/LayerManager.h +src/SDLx/LayerManager.xs +src/SDLx/SFont.h +src/SDLx/SFont.xs +src/SDLx/Surface.xs +src/SDLx/Timer.h +src/SDLx/Timer.xs +src/SDLx/Validate.h +src/SDLx/Validate.xs +src/SMPEG.xs +src/SMPEG/Info.xs +src/support/darwin_support.h +src/support/darwin_support.m +src/support/win32.c +src/TTF/objects/Font.xs +src/TTF/README +src/TTF/TTF.xs +t/00-load.t +t/colorpm.t +t/config.t +t/core.t +t/core_audio.t +t/core_audiospec.t +t/core_cd.t +t/core_error.t +t/core_events.t +t/core_joystick.t +t/core_mouse.t +t/core_multi.t +t/core_overlay.t +t/core_palette.t +t/core_rect.t +t/core_rwops.t +t/core_surface.t +t/core_timer.t +t/core_version.t +t/core_video.t +t/core_video_convert_surface.t +t/core_video_gamma.t +t/extendingrect.t +t/gfx.t +t/gfx_fpsmanager.t +t/gfx_framerate.t +t/gfx_imagefilter.t +t/gfx_primitives.t +t/gfx_primitives2.t +t/gfx_rotozoom.t +t/image.t +t/image_xpm_array.t +t/lib/SDL/TestTool.pm +t/mixer.t +t/mixer_channels.t +t/mixer_effects.t +t/mixer_groups.t +t/mixer_mixchunk.t +t/mixer_mixmusic.t +t/mixer_music.t +t/mixer_samples.t +t/pango.t +t/release-pod-syntax.t +t/sdlgamerect.t +t/sdlx_app.t +t/sdlx_controller.t +t/sdlx_controller_interface.t +t/sdlx_fps.t +t/sdlx_layermanager.t +t/sdlx_music.t +t/sdlx_rect.t +t/sdlx_sfont.t +t/sdlx_sound.t +t/sdlx_sprite.t +t/sdlx_sprite_animated.t +t/sdlx_surface.t +t/sdlx_text.t +t/sdlx_validate.t +t/smpeg.t +t/ttf.t +t/ttf_font.t +test/data/24P_Arial_NeonYellow.png +test/data/24P_Copperplate_Blue.png +test/data/5x7.fnt +test/data/button_dark.png +test/data/button_light.png +test/data/chest.png +test/data/electrohar.ttf +test/data/font.bmp +test/data/font.png +test/data/hero.bmp +test/data/hero.png +test/data/highlight.png +test/data/icon.bmp +test/data/LargeFont.bmp +test/data/logo.png +test/data/menu.png +test/data/pattern_red_white_2x2.bmp +test/data/picture.bmp +test/data/picture.jpg +test/data/picture.tif +test/data/README +test/data/sample.ogg +test/data/sample.wav +test/data/silence.ogg +test/data/silence.wav +test/data/test-mpeg.mpg +test/data/tribe_i.wav +test/data/wood_dark.png +test/data/wood_light.png +TODO +typemap diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index a7b69177..f1ad0d32 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -1,4 +1,5 @@ ~$ \.o$ +\.obj$ \.bak$ -^(?!typemap|share|scripts/\w+\.pl|src/[^\.]|test/data/[^\.]|MacOSX/[^\.]|examples/[^\.]+|lib/[\/\w]+\.p(m|od)|inc/|t/[\w\d-]+\.t|t/lib/SDL/TestTool\.pm|Build.PL$|INSTALL$|README$|MANIFEST$|CHANGELOG$|TODO$|CONTRIBUTORS$|COPYING$|OFL-FAQ.txt|OFL.txt|META.yml|$) +^(?!typemap|share|scripts/\w+\.pl|src/[^\.]|test/data/[^\.]|MacOSX/[^\.]|examples/[^\.]+|lib/[\/\w]+\.p(m|od)|inc/|t/[\w\d-]+\.t|t/lib/SDL/TestTool\.pm|Build.PL$|INSTALL$|README$|MANIFEST$|CHANGELOG$|TODO$|CONTRIBUTORS$|COPYING$|OFL-FAQ.txt|OFL.txt|META.(yml|json)|$) diff --git a/examples/SDLx/SDLx_C_Interface.pl b/examples/SDLx/SDLx_C_Interface.pl index f371cba2..41ce6995 100644 --- a/examples/SDLx/SDLx_C_Interface.pl +++ b/examples/SDLx/SDLx_C_Interface.pl @@ -34,14 +34,6 @@ $app->draw_rect( [ 100 - $state->x, $state->y, 2, 2 ], 0xFF0FFF ); }; -#an event handler to exit -my $event = sub { - $_[1]->stop if $_[0]->type == SDL_QUIT; -}; - - -$app->add_event_handler($event); - #clear the screen $app->add_show_handler( sub { $app->draw_rect( [ 0, 0, $app->w, $app->h ], 0x000000 ) } ); diff --git a/examples/SDLx/SDLx_Sound.pl b/examples/SDLx/SDLx_Sound.pl index d95a615f..efdc543a 100644 --- a/examples/SDLx/SDLx_Sound.pl +++ b/examples/SDLx/SDLx_Sound.pl @@ -44,7 +44,6 @@ # pause or resume on keydown $app->add_event_handler( sub{ my $e = $_[0]; - $_[1]->stop() if $e->type == SDL_QUIT; if( $e->type == SDL_KEYDOWN ) { print "Ai\n"; diff --git a/examples/SDLx/SDLx_controller_two_squares.pl b/examples/SDLx/SDLx_controller_two_squares.pl index 19fe7d8a..8e3016bf 100644 --- a/examples/SDLx/SDLx_controller_two_squares.pl +++ b/examples/SDLx/SDLx_controller_two_squares.pl @@ -101,8 +101,6 @@ sub on_event { $ball->{x_vel} += $ball->{vel} if $key == SDLK_LEFT; $ball->{x_vel} -= $ball->{vel} if $key == SDLK_RIGHT; - } elsif ( $event->type == SDL_QUIT ) { - $_[0]->stop; } } diff --git a/examples/SDLx/SDLx_text.pl b/examples/SDLx/SDLx_text.pl index 57f2abcc..46568400 100644 --- a/examples/SDLx/SDLx_text.pl +++ b/examples/SDLx/SDLx_text.pl @@ -5,7 +5,7 @@ use SDLx::App; use SDLx::Text; -my $app = SDLx::App->new( eoq => 1 ); +my $app = SDLx::App->new(); my $text = SDLx::Text->new; diff --git a/examples/SDLx/SDLx_text_shadow.pl b/examples/SDLx/SDLx_text_shadow.pl index ee318961..780143e1 100644 --- a/examples/SDLx/SDLx_text_shadow.pl +++ b/examples/SDLx/SDLx_text_shadow.pl @@ -7,7 +7,7 @@ use SDLx::App; use SDLx::Text; -my $app = SDLx::App->new( eoq => 1 ); +my $app = SDLx::App->new(); my $normal = SDLx::Text->new; my $shadow = SDLx::Text->new( shadow => 1 ); diff --git a/examples/SDLx/SDLx_text_styles.pl b/examples/SDLx/SDLx_text_styles.pl index f30bf8d8..b92311d7 100644 --- a/examples/SDLx/SDLx_text_styles.pl +++ b/examples/SDLx/SDLx_text_styles.pl @@ -5,7 +5,7 @@ use SDLx::App; use SDLx::Text; -my $app = SDLx::App->new( eoq => 1 ); +my $app = SDLx::App->new(); my $text = SDLx::Text->new; diff --git a/examples/SDLx/SDLx_text_wordwrap.pl b/examples/SDLx/SDLx_text_wordwrap.pl index bc6a7f5d..8c99d74a 100644 --- a/examples/SDLx/SDLx_text_wordwrap.pl +++ b/examples/SDLx/SDLx_text_wordwrap.pl @@ -5,7 +5,7 @@ use SDLx::App; use SDLx::Text; -my $app = SDLx::App->new( eoq => 1 ); +my $app = SDLx::App->new(); my $text = SDLx::Text->new( word_wrap => 450 ); diff --git a/examples/SDLx/SDLx_text_zoom.pl b/examples/SDLx/SDLx_text_zoom.pl index 8ea200cf..e41b149b 100644 --- a/examples/SDLx/SDLx_text_zoom.pl +++ b/examples/SDLx/SDLx_text_zoom.pl @@ -7,7 +7,7 @@ use SDLx::App; use SDLx::Text; -my $app = SDLx::App->new( eoq => 1, width => 400, height => 100 ); +my $app = SDLx::App->new( width => 400, height => 100 ); my $text = SDLx::Text->new; diff --git a/examples/SDLx/app.pl b/examples/SDLx/app.pl index 0358f381..07789727 100644 --- a/examples/SDLx/app.pl +++ b/examples/SDLx/app.pl @@ -7,15 +7,11 @@ height => 480, ); +sub draw_lines { + $app->draw_line( [ rand $app->w, rand $app->h ], [ rand $app->w, rand $app->h ], 0xFFFFFFFF ); + $app->update(); +} - -sub draw_lines { $app->draw_line( [ 0, 0 ], [ rand( $app->w ), rand( $app->h ) ], 0xFFFFFFFF ); $app->update(); } - -sub event_handle { my $e = shift; $_[0]->stop if ( $e->type == SDL_QUIT ); } - -$app->add_event_handler( \&event_handle ); $app->add_show_handler( \&draw_lines ); $app->run(); - - diff --git a/examples/SDLx/music.pl b/examples/SDLx/music.pl index 62d5b6d2..3cdae1c9 100644 --- a/examples/SDLx/music.pl +++ b/examples/SDLx/music.pl @@ -4,4 +4,4 @@ $music->data( sam => "test/data/sample.wav" ); $sam = $music->data("sam"); $music->play($sam); -while ( $music->playing ) { print "playing\n" } +while ( $music->playing ) { print "playing\n"; sleep 1; } diff --git a/examples/SDLx/pong.pl b/examples/SDLx/pong.pl index fe1b278a..a4bf6b3b 100644 --- a/examples/SDLx/pong.pl +++ b/examples/SDLx/pong.pl @@ -29,7 +29,7 @@ y => 0, w => 20, h => 80, - vel => 250, + vel => 130, y_vel => 0, }; @@ -143,8 +143,6 @@ sub on_event { my $key = $event->key_sym; $paddle->{y_vel} += $paddle->{vel} if $key == SDLK_UP; $paddle->{y_vel} -= $paddle->{vel} if $key == SDLK_DOWN; - } elsif ( $event->type == SDL_QUIT ) { - exit; } } diff --git a/examples/cookbook/pdl2surface.pl b/examples/cookbook/pdl2surface.pl new file mode 100644 index 00000000..1e18b513 --- /dev/null +++ b/examples/cookbook/pdl2surface.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use SDL; +use SDL::Surface; +use SDLx::App; +use SDLx::Surface; +use PDL; +use Data::Dumper; + +my $app = SDLx::App->new( + title => "PDL and SDL aplication", + width => 640, height => 640, eoq => 1 +); + +sub make_surface_piddle { + my $piddle = rpic('test/data/picture.jpg'); + my ($bytes_per_pixel,$width,$height) = $piddle->dims; + + my $surface = SDLx::Surface->new( width => $width, height => $height, depth => 32 ); + + SDL::Video::lock_surface($surface); + + my @pix = $piddle->list; + my $y = $height; + my $x = 0; + while( my @p = splice( @pix, 0, 3 ) ) { + unless( $x % $width ) { + $x = 0; + $y--; + } + $surface->set_pixel( $y, $x++, \@p ); + } + + SDL::Video::unlock_surface($surface); + + warn "Made surface of $width, $height and ". $surface->format->BytesPerPixel; + + return ( $piddle, $surface ); +} + +my ( $piddle, $surface ) = make_surface_piddle(); + +$app->add_show_handler( sub { + $surface->blit( $app, [0,0,$surface->w,$surface->h], [10,10,0,0] ); + $app->update(); +} ); + +$app->run(); diff --git a/inc/My/Builder.pm b/inc/My/Builder.pm index 040e7e26..eebc703c 100644 --- a/inc/My/Builder.pm +++ b/inc/My/Builder.pm @@ -80,7 +80,9 @@ sub find_subsystems { $found{$_} = 1 foreach (@$h); $param->{libs}->{$library} = 1; push @{ $param->{defines} }, "-D$libraries->{$library}{define}"; - push @{ $param->{links} }, "-l$libraries->{$library}{lib}"; + push @{ $param->{links} }, Alien::SDL::ConfigData->config('build_cc') eq 'cl' + ? "lib$libraries->{$library}{lib}.lib" + : "-l$libraries->{$library}{lib}"; } else { # I disabled that, so the libs are compiled but the HAVE_* defines are not set @@ -106,7 +108,7 @@ sub translate_table { $p =~ s|^lib/(.*)\.xs|$1|; $p =~ s|/|::|g; my @list = - map ( $libraries->{$_}->{lib}, @{ $subsystems->{$m}->{libraries} } ); + map ( $libraries->{$_}->{lib}, @{ $subsystems->{$m}->{libraries} }, @{ $subsystems->{$m}->{load_libs} } ); $ret{$p} = \@list; } return \%ret; @@ -152,6 +154,16 @@ sub set_file_flags { $self->notes( 'file_flags' => \%file_flags ); } +sub process_pod_files { + my ($self, $ext) = @_; + + my $files = $self->_find_file_by_type($ext, 'lib'); + while (my ($file, $dest) = each %$files) { + $dest =~ s!^(lib/)pods/!$1!; + $self->copy_if_modified(from => $file, to => File::Spec->catfile($self->blib, $dest)); + } +} + # override the following functions in My::Builder:: if necessary sub ACTION_build { my $self = shift; diff --git a/inc/My/Builder/Darwin.pm b/inc/My/Builder/Darwin.pm index 964f10e8..918cdd23 100644 --- a/inc/My/Builder/Darwin.pm +++ b/inc/My/Builder/Darwin.pm @@ -9,6 +9,7 @@ use Data::Dumper; use Cwd; use Config; use File::Copy; +use File::Spec use base 'My::Builder'; sub special_build_settings { @@ -111,8 +112,7 @@ sub _find_file { #hide warning "Can't opendir(...): Permission denied - fix for http://rt.cpan.org/Public/Bug/Display.html?id=57232 no warnings; find( - { - wanted => sub { push @files, rel2abs($_) if /$re/ }, + { wanted => sub { push @files, File::Spec->rel2abs($_) if /$re/ }, follow => 1, no_chdir => 1, follow_skip => 2 diff --git a/lib/Module/Build/SDL.pm b/lib/Module/Build/SDL.pm index 8aae1005..19b88481 100644 --- a/lib/Module/Build/SDL.pm +++ b/lib/Module/Build/SDL.pm @@ -348,4 +348,4 @@ subdir only via L =back -=cut \ No newline at end of file +=cut diff --git a/lib/SDL.pm b/lib/SDL.pm index 3189b995..11205f77 100644 --- a/lib/SDL.pm +++ b/lib/SDL.pm @@ -54,7 +54,7 @@ our %EXPORT_TAGS = ( defaults => $SDL::Constants::EXPORT_TAGS{'SDL/defaults'} ); -our $VERSION = '2.537_02'; +our $VERSION = '2.544'; $VERSION = eval $VERSION; print "$VERSION" if ( defined( $ARGV[0] ) && ( $ARGV[0] eq '--SDLperl' ) ); diff --git a/lib/SDL/Constants.pm b/lib/SDL/Constants.pm index d8015132..97204d60 100644 --- a/lib/SDL/Constants.pm +++ b/lib/SDL/Constants.pm @@ -1,10 +1,14 @@ #!/usr/bin/env perl package SDL::Constants; +use strict; use warnings; use base 'Exporter'; use Config; +our $VERSION = '2.541_10'; +$VERSION = eval $VERSION; + our @EXPORT_OK = (); our %EXPORT_TAGS = ( 'SDL/defaults' => [ @@ -1030,6 +1034,11 @@ use constant { KMOD_META => ( KMOD_LMETA | KMOD_RMETA ), }; # SDL::Events/keymod +use constant { + SDL_DEFAULT_REPEAT_DELAY => 500, + SDL_DEFAULT_REPEAT_INTERVAL => 30, +}; # SDL::Events/repeat + use constant { SMOOTHING_OFF => 0, SMOOTHING_ON => 1, @@ -1217,8 +1226,6 @@ use constant { FPS_LOWER_LIMIT => 1, FPS_DEFAULT => 30, SDL_ALL_HOTKEYS => 0xFFFFFFFF, - SDL_DEFAULT_REPEAT_DELAY => 500, - SDL_DEFAULT_REPEAT_INTERVAL => 30, }; use constant { diff --git a/lib/SDL/Event.pm b/lib/SDL/Event.pm index e236181e..753cc22f 100644 --- a/lib/SDL/Event.pm +++ b/lib/SDL/Event.pm @@ -24,7 +24,8 @@ our %EXPORT_TAGS = ( app => $SDL::Constants::EXPORT_TAGS{'SDL::Events/app'}, button => $SDL::Constants::EXPORT_TAGS{'SDL::Events/button'}, keysym => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keysym'}, - keymod => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keymod'} + keymod => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keymod'}, + repeat => $SDL::Constants::EXPORT_TAGS{'SDL::Events/repeat'} ); 1; diff --git a/lib/SDL/Events.pm b/lib/SDL/Events.pm index 9ff75e53..42e105a0 100644 --- a/lib/SDL/Events.pm +++ b/lib/SDL/Events.pm @@ -24,7 +24,8 @@ our %EXPORT_TAGS = ( app => $SDL::Constants::EXPORT_TAGS{'SDL::Events/app'}, button => $SDL::Constants::EXPORT_TAGS{'SDL::Events/button'}, keysym => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keysym'}, - keymod => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keymod'} + keymod => $SDL::Constants::EXPORT_TAGS{'SDL::Events/keymod'}, + repeat => $SDL::Constants::EXPORT_TAGS{'SDL::Events/repeat'} ); 1; diff --git a/lib/SDL/GFX/ImageFilter.pm b/lib/SDL/GFX/ImageFilter.pm index 19324bf8..963ebab6 100644 --- a/lib/SDL/GFX/ImageFilter.pm +++ b/lib/SDL/GFX/ImageFilter.pm @@ -19,4 +19,6 @@ our %EXPORT_TAGS = ( smoothing => $SDL::Constants::EXPORT_TAGS{'SDL::GFX/smoothing'} ); +MMX_on(); + 1; diff --git a/lib/SDL/Tutorial/LunarLander.pm b/lib/SDL/Tutorial/LunarLander.pm index 2d01d53b..c3b19d33 100644 --- a/lib/SDL/Tutorial/LunarLander.pm +++ b/lib/SDL/Tutorial/LunarLander.pm @@ -1,4 +1,6 @@ package SDL::Tutorial::LunarLander; +use strict; +use warnings; sub import { my ( $class, $filename ) = (@_); diff --git a/lib/SDL_perl.pm b/lib/SDL_perl.pm index 54662b60..4d516f67 100644 --- a/lib/SDL_perl.pm +++ b/lib/SDL_perl.pm @@ -30,7 +30,10 @@ package SDL_perl; -@ISA = qw/ DynaLoader /; +use strict; +use warnings; + +our @ISA = qw/ DynaLoader /; require DynaLoader; use SDL::Internal::Loader; diff --git a/lib/SDLx/App.pm b/lib/SDLx/App.pm index b5dc05ce..efaf84ae 100644 --- a/lib/SDLx/App.pm +++ b/lib/SDLx/App.pm @@ -1,234 +1,353 @@ -#!/usr/bin/env perl -# -# App.pm -# - package SDLx::App; use strict; use warnings; -use Carp; -use SDL; - -use SDL::Rect; -use SDL::Video; -use SDL::Event; -use SDL::Events; -use SDL::Surface; -use SDL::PixelFormat; -use SDL::VideoInfo; -use SDLx::Surface; -use Data::Dumper; -use Scalar::Util 'refaddr'; + +# SDL modules actually used here +use SDL (); +use SDL::Video (); +use SDL::Mouse (); +use SDL::Event (); +use SDL::Surface (); +use SDL::VideoInfo (); +use SDLx::Validate (); use base qw/SDLx::Surface SDLx::Controller/; -my $screen_w; -my $screen_h; -my $screen_d; +# SDL modules used for other reasons +# Please verify their usefulness here +use SDL::Rect (); +use SDL::Events (); +use SDL::PixelFormat (); + +use Carp (); +use Scalar::Util qw/refaddr/; + +my %_stash; +my $_screen_w; +my $_screen_h; +my $_screen_d; + +$SDLx::App::USING_OPENGL = 0; sub new { - my $proto = shift; - my $class = ref($proto) || $proto; - my %options = @_; + my $class = shift; + + my %o = @_; + + # undef is not a valid input + my $w = defined $o{width} ? $o{width} : defined $o{w} ? $o{w} : 640; + my $h = defined $o{height} ? $o{height} : defined $o{h} ? $o{h} : 480; + my $d = defined $o{depth} ? $o{depth} : defined $o{d} ? $o{d} : undef; + my $f = defined $o{flags} ? $o{flags} : defined $o{f} ? $o{f} : 0; + my $pos = defined $o{position} ? $o{position} : defined $o{pos} ? $o{pos} : undef; + my $ico = $o{icon}; + + # undef is a valid input + my $t = exists $o{title} ? $o{title} : $o{t}; + my $it = $o{icon_title}; + my $init = exists $o{initialize} ? $o{initialize} : $o{init}; + my $s = exists $o{stash} ? $o{stash} : {}; + my $icc = exists $o{icon_alpha_key} ? $o{icon_alpha_key} : $o{icon_color_key}; + + # boolean + my $sw = $o{software_surface} || $o{sw_surface} || $o{sw}; + my $hw = $o{hardware_surface} || $o{hw_surface} || $o{hw}; + my $ab = $o{asynchronous_blit} || $o{async_blit}; + my $af = $o{any_format}; + my $hwp = $o{hardware_palette} || $o{hw_palette}; + my $db = $o{double_buffer} || $o{double_buf} || $o{dbl_buf}; + my $fs = $o{full_screen} || $o{fullscreen} || $o{full}; + my $gl = $o{open_gl} || $o{opengl} || $o{gl}; + my $rs = $o{resizable} || $o{resizeable}; # it's a hard word to spell :-) + my $nf = $o{no_frame}; + my $ncur = $o{hide_cursor} || $o{no_cursor}; + my $cen = $o{centered} || $o{center}; + my $gi = $o{grab_input}; + my $nc = $o{no_controller}; + + unless ( defined $d ) { + # specify SDL_ANYFORMAT flag if depth isn't defined + $d = 32; + $af = 1; + } - unless($screen_w && $screen_h && $screen_d) { + # used to say unless no_init here. I don't think we need it anymore + if( !defined $init ) { + SDLx::App->init( SDL::SDL_INIT_EVERYTHING ); + } + else { + if( ref $init ) { + push @$init, "video"; + } + else { + $init |= SDL::SDL_INIT_VIDEO; + } + SDLx::App->init( $init ); + } + + # keep the screen's original res so we can set the app to that when we're done + unless(defined $_screen_w && defined $_screen_h && defined $_screen_d) { my $video_info = SDL::Video::get_video_info(); if($video_info) { - $screen_w = $video_info->current_w; - $screen_h = $video_info->current_h; - $screen_d = $video_info->vfmt->BitsPerPixel; + $_screen_w = $video_info->current_w; + $_screen_h = $video_info->current_h; + $_screen_d = $video_info->vfmt->BitsPerPixel; } } - # SDL_INIT_VIDEO() is 0, so check defined instead of truth. - unless ( exists( $options{noinit} ) ) # we shouldn't do init always - { - my $init = - defined $options{init} - ? $options{init} - : SDL::SDL_INIT_EVERYTHING; - - SDL::init($init); - } - - my $t = $options{title} || $options{t} || $0; - my $it = $options{icon_title} || $options{it} || $t; - my $ic = $options{icon} || $options{i} || ""; - my $w = $options{width} || $options{w} || 800; - my $h = $options{height} || $options{h} || 600; - my $d = $options{depth} || $options{d} || 16; - my $f = $options{flags} || $options{f} || SDL::Video::SDL_ANYFORMAT; - my $r = $options{red_size} || $options{r} || 5; - my $g = $options{green_size} || $options{g} || 5; - my $b = $options{blue_size} || $options{b} || 5; - my $a = $options{alpha_size} || $options{a} || 0; - my $ras = $options{red_accum_size} || $options{ras} || 0; - my $gas = $options{green_accum_size} || $options{gas} || 0; - my $bas = $options{blue_accum_size} || $options{bas} || 0; - my $aas = $options{alpha_accum_size} || $options{aas} || 0; - my $db = $options{double_buffer} || $options{db} || 0; - - my $bs = $options{buffer_size} || $options{bs} || 0; - my $st = $options{stencil_size} || $options{st} || 0; - my $async = $options{asyncblit} || 0; - - $f |= SDL::Video::SDL_OPENGL if ( $options{gl} || $options{opengl} ); - $f |= SDL::Video::SDL_FULLSCREEN - if ( $options{fullscreen} || $options{full} ); - $f |= SDL::Video::SDL_RESIZABLE if ( $options{resizeable} ); - $f |= SDL::Video::SDL_DOUBLEBUF if ($db); - $f |= SDL::Video::SDL_ASYNCBLIT if ($async); - - if ( $f & SDL::Video::SDL_OPENGL ) { + $f |= SDL::Video::SDL_SWSURFACE if $sw; + $f |= SDL::Video::SDL_HWSURFACE if $hw; + $f |= SDL::Video::SDL_ASYNCBLIT if $ab; + $f |= SDL::Video::SDL_ANYFORMAT if $af; + $f |= SDL::Video::SDL_HWPALETTE if $hwp; + $f |= SDL::Video::SDL_DOUBLEBUF if $db; + $f |= SDL::Video::SDL_FULLSCREEN if $fs; + $f |= SDL::Video::SDL_OPENGL if $gl; + $f |= SDL::Video::SDL_RESIZABLE if $rs; + $f |= SDL::Video::SDL_NOFRAME if $nf; + + # we'll let SDL decide which takes priority and set both if both are specified + $ENV{SDL_VIDEO_CENTERED} = $cen if $cen; + $ENV{SDL_VIDEO_WINDOW_POS} = $pos if $pos; + + if ( $gl ) { $SDLx::App::USING_OPENGL = 1; - SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_RED_SIZE(), $r ) - if ($r); - SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_GREEN_SIZE(), $g ) - if ($g); - SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_BLUE_SIZE(), $b ) - if ($b); - SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_ALPHA_SIZE(), $a ) - if ($a); - - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_RED_ACCUM_SIZE(), - $ras - ) if ($ras); - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_GREEN_ACCUM_SIZE(), - $gas - ) if ($gas); - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_BLUE_ACCUM_SIZE(), - $bas - ) if ($bas); - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_ALPHA_ACCUM_SIZE(), - $aas - ) if ($aas); - - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_DOUBLEBUFFER(), - $db - ) if ($db); - SDL::Video::GL_set_attribute( - SDL::Constants::SDL_GL_BUFFER_SIZE(), - $bs - ) if ($bs); - SDL::Video::GL_set_attribute( SDL::Constants::SDL_GL_DEPTH_SIZE(), $d ); - } else { - $SDLx::App::USING_OPENGL = 0; + + my $r = defined $o{gl_red_size} ? $o{gl_red_size} : defined $o{gl_red} ? $o{gl_red} : 5; + my $g = defined $o{gl_green_size} ? $o{gl_green_size} : defined $o{gl_green} ? $o{gl_green} : 5; + my $b = defined $o{gl_blue_size} ? $o{gl_blue_size} : defined $o{gl_blue} ? $o{gl_blue} : 5; + my $a = defined $o{gl_alpha_size} ? $o{gl_alpha_size} : defined $o{gl_alpha} ? $o{gl_alpha} : undef; + my $ra = defined $o{gl_accum_red_size} ? $o{gl_accum_red_size} : defined $o{gl_accum_red} ? $o{gl_accum_red} : undef; + my $ga = defined $o{gl_accum_green_size} ? $o{gl_accum_green_size} : defined $o{gl_accum_green} ? $o{gl_accum_green} : undef; + my $ba = defined $o{gl_accum_blue_size} ? $o{gl_accum_blue_size} : defined $o{gl_accum_blue} ? $o{gl_accum_blue} : undef; + my $aa = defined $o{gl_accum_alpha_size} ? $o{gl_accum_alpha_size} : defined $o{gl_accum_alpha} ? $o{gl_accum_alpha} : undef; + my $bs = defined $o{gl_buffer_size} ? $o{gl_buffer_size} : defined $o{gl_buffer} ? $o{gl_buffer} : undef; + my $ss = defined $o{gl_stencil_size} ? $o{gl_stencil_size} : defined $o{gl_stencil} ? $o{gl_stencil} : undef; + my $msb = defined $o{gl_multi_sample_buffers} ? $o{gl_multi_sample_buffers} : undef; + my $mss = defined $o{gl_multi_sample_samples} ? $o{gl_multi_sample_samples} : undef; + + # boolean + my $s = $o{gl_stereo}; + my $sc = $o{gl_swap_control}; + my $av = $o{gl_accelerated_visual}; + + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_RED_SIZE, $r ) if defined $r; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_GREEN_SIZE, $g ) if defined $g; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_BLUE_SIZE, $b ) if defined $b; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ALPHA_SIZE, $a ) if defined $a; + + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCUM_RED_SIZE, $ra ) if defined $ra; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCUM_GREEN_SIZE, $ga ) if defined $ga; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCUM_BLUE_SIZE, $ba ) if defined $ba; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCUM_ALPHA_SIZE, $aa ) if defined $aa; + + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_BUFFER_SIZE, $bs ) if defined $bs; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_DOUBLEBUFFER, $db ) if defined $db; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_DEPTH_SIZE, $d ); + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_STENCIL_SIZE, $ss ) if defined $ss; + + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_STEREO, $s ) if defined $s; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_MULTISAMPLEBUFFERS, $msb ) if defined $msb; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_MULTISAMPLESAMPLES, $mss ) if defined $mss; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_SWAP_CONTROL, $sc ) if defined $sc; + SDL::Video::GL_set_attribute( SDL::Video::SDL_GL_ACCELERATED_VISUAL, $av ) if defined $av; } + # icon must be set before set_video_mode + SDLx::App->icon( $ico, $icc ) if defined $ico; + + my $self = $class->set_video_mode( $w, $h, $d, $f ); + $self->SDLx::Controller::new( %o ) unless $nc; + + $t = defined $it ? $it : $0 unless defined $t; + $it = $t unless defined $it; + $self->title( $t, $it ); + + $self->show_cursor( 0 ) if $ncur; + $self->grab_input( $gi ) if $gi; + $self->stash = $s; + + $self; +} + +sub set_video_mode { + my ( $self, $w, $h, $d, $f ) = @_; my $surface = SDL::Video::set_video_mode( $w, $h, $d, $f ) - or Carp::confess SDL::get_error(); - $options{surface} = $surface; + or Carp::confess( "set_video_mode failed: ", SDL::get_error() ); + $surface = SDLx::Surface->new( surface => $surface ); + + # if we already have an app + if( ref $self ) { + return $self; + } + return bless $surface, $self; +} - my $self = SDLx::Surface->new(%options); +sub DESTROY { + my ( $self ) = @_; - if ( $ic and -e $ic ) { - my $icon = SDL::Video::load_BMP($ic); - SDL::Video::wm_set_icon($icon); + # set original screen size when app ends + if(defined $_screen_w && defined $_screen_h && defined $_screen_d) { + SDL::Video::set_video_mode( $_screen_w, $_screen_h, $_screen_d, $self->flags ); } - SDL::Video::wm_set_caption( $t, $it ); - $self = $self->SDLx::Controller::new(%options); - bless $self, $class; + my $ref = refaddr($self); + delete $_stash{ $ref }; +} - return $self; +sub stash :lvalue { + $_stash{ refaddr( $_[0] ) }; +} + +sub init { + my ( undef, $init ) = @_; + + if ( ref $init ) { + # make a hash with keys of the values in the init array + my %init = map { $_ => 1 } @$init; + undef $init; + + $init |= SDL::SDL_INIT_TIMER if $init{timer}; + $init |= SDL::SDL_INIT_AUDIO if $init{audio}; + $init |= SDL::SDL_INIT_VIDEO if $init{video}; + $init |= SDL::SDL_INIT_CDROM if $init{cd_rom} || $init{cdrom}; + $init |= SDL::SDL_INIT_JOYSTICK if $init{joystick}; + $init |= SDL::SDL_INIT_EVERYTHING if $init{everything} || $init{all}; + $init |= SDL::SDL_INIT_NOPARACHUTE if $init{no_parachute}; + $init |= SDL::SDL_INIT_EVENTTHREAD if $init{event_thread}; + } + + # if anything is already inited, only init specified extra subsystems + if ( SDL::was_init( SDL::SDL_INIT_EVERYTHING ) ) { + SDL::init_sub_system( $init ) + and Carp::cluck( "SDL init_sub_system failed: ", SDL::get_error() ); + } + else { + SDL::init( $init ) + and Carp::confess( "SDL init failed: ", SDL::get_error() ); + } +} + +sub screen_size { + SDLx::App->init( SDL::SDL_INIT_VIDEO ); + + my $video_info = SDL::Video::get_video_info(); + + return( $video_info->current_w, $video_info->current_h, $video_info->vfmt->BitsPerPixel ); } sub resize { my ( $self, $w, $h ) = @_; - my $flags = $self->flags; - if ( $flags & SDL::Video::SDL_RESIZABLE ) { - my $bpp = $self->format->BitsPerPixel; - $self = SDL::Video::set_video_mode( $w, $h, $bpp, $flags ) - or die "SDL cannot set video:" . SDL::get_error; - } else { - die "Application surface not resizable"; - } + + my $d = $self->format->BitsPerPixel; + my $f = $self->flags; + + $self->set_video_mode( $w, $h, $d, $f ); } sub title { - my $self = shift; - my ( $title, $icon ); - if (@_) { - $title = shift; - $icon = shift || $title; - SDL::Video::wm_set_caption( $title, $icon ); + my ( $self, $title, $icon_title ) = @_; + my $video_info = SDL::Video::get_video_info(); + return if $video_info && !$video_info->wm_available(); + + if ( @_ > 1 ) { + my ($t, $it) = SDL::Video::wm_get_caption; + $title = $t unless defined $title; + $icon_title = $it unless defined $icon_title; + return SDL::Video::wm_set_caption( $title, $icon_title ); } - return SDL::Video::wm_get_caption(); + SDL::Video::wm_get_caption; } -sub delay { - my $self = shift; - my $delay = shift; - SDL::delay($delay); +sub icon { + my ( undef, $icon, $color ) = @_; + SDLx::App->init( SDL::SDL_INIT_VIDEO ); + unless( UNIVERSAL::isa( $icon, "SDL::Surface" ) ) { + $icon = SDL::Video::load_BMP( $icon ); + $icon or Carp::confess( "Could not load_BMP icon: ", SDL::get_error() ); + } + if( defined $color ) { + $color = SDLx::Validate::map_rgb( $color, $icon->format ); + SDL::Video::set_color_key( $icon, SDL::Video::SDL_SRCCOLORKEY, $color ); + } + SDL::Video::wm_set_icon( $icon ); } -sub ticks { - return SDL::get_ticks(); +sub error { + shift; + if ( @_ == 1 and !defined $_[0] ) { + return SDL::clear_error; + } + if ( @_ ) { + return SDL::set_error_real( @_ ); + } + SDL::get_error; } -sub error { - return SDL::get_error(); +sub warp_cursor { + my ( undef, $x, $y ) = @_; + SDL::Mouse::warp_mouse( $x || 0, $y || 0 ); } -sub warp { - my $self = shift; - SDL::Mouse::warp_mouse(@_); +sub show_cursor { + my ( undef, $show ) = @_; + if ( @_ > 1 ) { + return SDL::Mouse::show_cursor( SDL::Event::SDL_ENABLE ) if $show and $show ne SDL::Event::SDL_QUERY; + return SDL::Mouse::show_cursor( SDL::Event::SDL_DISABLE ) unless $show; + } + SDL::Mouse::show_cursor( SDL::Event::SDL_QUERY ); } sub fullscreen { - my $self = shift; - SDL::Video::wm_toggle_fullscreen($self); + my ( $self ) = @_; + return 1 if SDL::Video::wm_toggle_fullscreen( $self ); + + # fallback to doing it with set_video_mode() + my $d = $self->format->BitsPerPixel; + my $f = $self->flags; + + eval { $self->set_video_mode( 0, 0, $d, $f ^ SDL::Video::SDL_FULLSCREEN ) }; + return 1 unless $@; + + # failed going fullscreen, let's revert back + $self->set_video_mode( 0, 0, $d, $f ); + + # report failure to go fullscreen + return 0; } sub iconify { - my $self = shift; - SDL::Video::wm_iconify_window(); + SDL::Video::wm_iconify_window; } sub grab_input { - my ( $self, $mode ) = @_; - SDL::Video::wm_grab_input($mode); -} - -sub sync { - my $self = shift; - if ($SDLx::App::USING_OPENGL) { - SDL::Video::GL_swap_buffers(); - } else { - $self->flip(); + my ( undef, $grab ) = @_; + if (@_ > 1) { + return SDL::Video::wm_grab_input( SDL::Video::SDL_GRAB_ON ) if $grab and $grab ne SDL::Video::SDL_GRAB_QUERY; + return SDL::Video::wm_grab_input( SDL::Video::SDL_GRAB_OFF ) unless $grab; } + SDL::Video::wm_grab_input( SDL::Video::SDL_GRAB_QUERY ); } -sub attribute { - my ( $self, $mode, $value ) = @_; - return undef unless ($SDLx::App::USING_OPENGL); - if ( defined $value ) { - SDL::Video::GL_set_attribute( $mode, $value ); +sub sync { + my ( $self ) = @_; + if ( $SDLx::App::USING_OPENGL ) { + return SDL::Video::GL_swap_buffers; } - my $returns = SDL::Video::GL_get_attribute($mode); - Carp::confess "SDLx::App::attribute failed to get GL attribute" - if ( $$returns[0] < 0 ); - $$returns[1]; + SDL::Video::flip( $self ); } +sub gl_attribute { + my ( undef, $mode, $value ) = @_; - -my %_stash; -sub stash :lvalue{ - my $ref = refaddr($_[0]); - $_stash{ $ref } = {} unless $_stash{ $ref }; - return $_stash{ $ref } -} - -sub DESTROY { - if($screen_w && $screen_h && $screen_d) { - SDL::Video::set_video_mode( $screen_w, $screen_h, $screen_d, SDL_ANYFORMAT ); + return unless $SDLx::App::USING_OPENGL; + if ( @_ > 2 ) { + return SDL::Video::GL_set_attribute( $mode, $value ); } + my $returns = SDL::Video::GL_get_attribute( $mode ); + Carp::cluck( "SDL::Video::GL_get_attribute failed to get GL attribute" ) + if $returns->[0] < 0; + $returns->[1]; } 1; diff --git a/lib/SDLx/Controller.pm b/lib/SDLx/Controller.pm index 867778c0..23eaeefd 100644 --- a/lib/SDLx/Controller.pm +++ b/lib/SDLx/Controller.pm @@ -1,36 +1,45 @@ package SDLx::Controller; use strict; use warnings; -use Carp; -use Time::HiRes; -use SDL; -use SDL::Event; -use SDL::Events; -use SDL::Video; +use Carp (); +use Time::HiRes (); +use SDL (); +use SDL::Event (); +use SDL::Events (); +use SDL::Video (); use SDLx::Controller::Interface; use SDLx::Controller::State; use Scalar::Util 'refaddr'; -# inside out, so this can work as the superclass of another -# SDL::Surface subclass +# inside out, so this can work as the superclass of another class my %_dt; my %_min_t; -my %_current_time; +my %_max_t; my %_stop; my %_event; my %_event_handlers; my %_move_handlers; my %_show_handlers; -my %_sleep_cycle; -my %_eoq; +my %_delay; my %_paused; +my %_time; +my %_stop_handler; +my %_before_pause; +my %_after_pause; +my %_event_handler; +my %_move_handler; +my %_show_handler; + +use constant { + STOP => '1', + PAUSE => '0', # pause is defined but false +}; sub new { my ($self, %args) = @_; - if(ref $self) { - bless $self, ref $self; - } - else { + + # if $self is blessed then it has to isa controller, so let's not even bless it to this class + unless(ref $self) { my $a; $self = bless \$a, $self; } @@ -39,142 +48,200 @@ sub new { $_dt{ $ref } = defined $args{dt} ? $args{dt} : 0.1; $_min_t{ $ref } = defined $args{min_t} ? $args{min_t} : 1 / 60; -# $_current_time{ $ref } = $args{current_time} || 0; #no point - $_stop{ $ref } = $args{stop}; + $_max_t{ $ref } = defined $args{max_t} ? $args{max_t} : 0.1; + $_stop{ $ref } = STOP; $_event{ $ref } = $args{event} || SDL::Event->new(); $_event_handlers{ $ref } = $args{event_handlers} || []; $_move_handlers{ $ref } = $args{move_handlers} || []; $_show_handlers{ $ref } = $args{show_handlers} || []; - $_sleep_cycle{ $ref } = $args{delay}; - $_eoq{$ref} = $args{exit_on_quit} || $args{eoq} || 0; -# $_paused{ $ref } = $args{paused}; #read only + # delay accepts seconds or ticks + $_delay{ $ref } = defined $args{delay} ? ($args{delay} >= 1 ? $args{delay} / 1000 : $args{delay}) : 0; +# $_paused{ $ref } = undef; + $_time{ $ref } = $args{time} || 0; + $_stop_handler{ $ref } = exists $args{stop_handler} ? $args{stop_handler} : \&default_stop_handler; + $_before_pause{ $ref } = $args{before_pause}; + $_after_pause{ $ref } = $args{after_pause}; + $_event_handler{ $ref } = $args{event_handler} || \&default_event_handler; + $_move_handler{ $ref } = $args{move_handler} || \&default_move_handler; + $_show_handler{ $ref } = $args{show_handler} || \&default_show_handler; return $self; } - -sub delay { - my $self = shift; - my $delay = shift; - my $ref = refaddr $self; - - $_sleep_cycle{ $ref } = $delay if $delay; - return $self; -} - sub DESTROY { my $self = shift; my $ref = refaddr $self; delete $_dt{ $ref}; delete $_min_t{ $ref}; - delete $_current_time{ $ref}; + delete $_max_t{ $ref }; delete $_stop{ $ref}; delete $_event{ $ref}; delete $_event_handlers{ $ref}; delete $_move_handlers{ $ref}; delete $_show_handlers{ $ref}; - delete $_sleep_cycle { $ref }; - delete $_eoq{$ref}; - delete $_paused{$ref}; + delete $_delay { $ref}; + delete $_paused{ $ref}; + delete $_time{ $ref}; + delete $_stop_handler{ $ref}; + delete $_before_pause{ $ref }; + delete $_after_pause{ $ref }; + delete $_event_handler{ $ref }; + delete $_move_handler{ $ref }; + delete $_show_handler{ $ref }; } sub run { my ($self) = @_; my $ref = refaddr $self; - my $dt = $_dt{ $ref }; - my $min_t = $_min_t{ $ref }; - my $t = 0.0; - - #Allows us to do stop and run - $_stop{ $ref } = 0; - - $_current_time{ $ref } = Time::HiRes::time; - while ( !$_stop{ $ref } ) { - $self->_event($ref); - my $new_time = Time::HiRes::time; - my $delta_time = $new_time - $_current_time{ $ref }; - next if $delta_time < $min_t; - $_current_time{ $ref} = $new_time; - my $delta_copy = $delta_time; + # these keep their old value until the end of the cycle + my ($dt, $delay, $min_t); + + # you have to stop and rerun the app to update these + my $event_handler = $_event_handler{ $ref }; + my $move_handler = $_move_handler{ $ref }; + my $show_handler = $_show_handler{ $ref }; + my $stop_handler = $_stop_handler{ $ref }; + + # alows us to do stop and run + delete $_stop{ $ref }; + delete $_paused{ $ref }; + + my $current_time = Time::HiRes::time(); + Time::HiRes::sleep( 0.001 ); # sleep at least a millisecond + + until ( defined $_stop{ $ref } ) { + my $new_time = Time::HiRes::time(); + my $delta_time = my $delta_copy = $new_time - $current_time; + $current_time = $new_time; + $delta_time = $_max_t{ $ref } if $delta_time > $_max_t{ $ref }; + + # these can change during the cycle + $dt = $_dt{ $ref }; + $delay = $_delay{ $ref }; + $min_t = $_min_t{ $ref }; + + # we keep this completely up-to-date + my $time_ref = \$_time{ $ref}; + + my $event = $_event{ $ref }; + SDL::Events::pump_events(); + while ( SDL::Events::poll_event( $event ) ) { + $stop_handler ->( $event, $self ) if $stop_handler; + $event_handler->( $event, $self ) if $event_handler; + } while ( $delta_copy > $dt ) { - $self->_move( $ref, 1, $t ); #a full move + $move_handler->( 1, $self, $$time_ref ) if $move_handler; # a full move $delta_copy -= $dt; - $t += $dt; + $$time_ref += $dt; } my $step = $delta_copy / $dt; - $self->_move( $ref, $step, $t ); #a partial move - $t += $dt * $step; + $move_handler->( $step, $self, $$time_ref ) if $move_handler; # a partial move + $$time_ref += $dt * $step; + + $show_handler->( $delta_time, $self ) if $show_handler; - $self->_show( $ref, $delta_time ); + # one or the other of delay or min_t is good + Time::HiRes::sleep( $delay ) if $delay > 0; - $dt = $_dt{ $ref}; #these can change - $min_t = $_min_t{ $ref}; #during the cycle - SDL::delay( $_sleep_cycle{ $ref } ) if $_sleep_cycle{ $ref }; + if($min_t > 0) { + my $min_t_delay = $min_t - (Time::HiRes::time - $new_time); + Time::HiRes::sleep($min_t_delay) if $min_t_delay > 0; + } } + # pause works by stopping the app and running it again + if( $_paused{ $ref } ) { + $_before_pause{ $ref }->($self) if $_before_pause{ $ref }; + $self->_pause($ref); + $_after_pause{ $ref }->($self) if $_after_pause{ $ref }; + + return if $_stop{ $ref }; + + # exit out of this sub before going back in so we don't recurse deeper and deeper + goto $self->can('run'); + } } -sub exit_on_quit { - my ($self, $value) = @_; +sub stop { + my ($self, $arg) = @_; + my $ref = refaddr $self; - my $ref = refaddr $self; - if (defined $value) { - $_eoq{$ref} = $value; - } + $_stop{ $ref } = @_ > 1 ? $arg : STOP; - return $_eoq{$ref}; + # if we're going to stop we don't want to pause + delete $_paused{ $ref } if defined $_stop{ $ref } and $_stop{ $ref } eq STOP; +} +sub stopped { + # returns true if the app is stopped or about to stop + $_stop{ refaddr $_[0]}; } -*eoq = \&exit_on_quit; # alias +sub _pause { + my ($self, $ref) = @_; + my $event = $_event{ $ref}; + my $stop_handler = $_stop_handler{ $ref}; + my $callback = $_paused{ $ref}; + my $stop = delete $_stop{ $ref }; + + do { + SDL::Events::pump_events(); # don't know if we need this + SDL::Events::wait_event( $event ) or Carp::confess("pause failed waiting for an event"); + $stop_handler->( $event, $self ) if $stop_handler; + } + until + $_stop{ $ref } # stop set by stop_handler + or $callback->( $event, $self ) + or $_stop{ $ref } # stop set by callback + ; + + $_stop{ $ref } ||= $stop if $stop; + delete $_paused{ $ref }; +} sub pause { my ($self, $callback) = @_; my $ref = refaddr $self; - $callback ||= sub {1}; - my $event = SDL::Event->new(); - $_paused{ $ref} = 1; - while(1) { - SDL::Events::wait_event($event) or Carp::confess("pause failed waiting for an event"); - if($callback->($event, $self)) { - $_current_time{ $ref} = Time::HiRes::time; #so run doesn't catch up with the time paused - last; - } + my $stop = $_stop{ $ref }; + + unless( $callback ) { + delete $_paused{ $ref }; + return; } - delete $_paused{ $ref}; + + # if we're going to stop we don't want to pause + return if !$_paused{ $ref } and defined $stop and $stop eq STOP; + + $_stop{ $ref } = PAUSE unless $stop; + $_paused{ $ref} = $callback; +} +sub paused { + # returns the callback (always true) if the app is paused or about to pause + $_paused{ refaddr $_[0]}; } -sub _event { - my ($self, $ref) = @_; - SDL::Events::pump_events(); - while ( SDL::Events::poll_event( $_event{ $ref} ) ) { - $self->_exit_on_quit( $_event{ $ref} ) if $_eoq{$ref}; - foreach my $event_handler ( @{ $_event_handlers{ $ref} } ) { - next unless $event_handler; - $event_handler->( $_event{ $ref}, $self ); - } +sub default_event_handler { + my ($event, $self) = @_; + foreach my $event_handler ( @{$_event_handlers{ refaddr $self }} ) { + $event_handler->( $event, $self ) if $event_handler; } } -sub _move { - my ($self, $ref, $move_portion, $t) = @_; - foreach my $move_handler ( @{ $_move_handlers{ $ref} } ) { - next unless $move_handler; - $move_handler->( $move_portion, $self, $t ); +sub default_move_handler { + my ($move_portion, $self, $t) = @_; + foreach my $move_handler ( @{$_move_handlers{ refaddr $self }} ) { + $move_handler->( $move_portion, $self, $t ) if $move_handler; } } -sub _show { - my ($self, $ref, $delta_ticks) = @_; - foreach my $show_handler ( @{ $_show_handlers{ $ref} } ) { - next unless $show_handler; - $show_handler->( $delta_ticks, $self ); +sub default_show_handler { + my ($delta_time, $self) = @_; + foreach my $show_handler ( @{$_show_handlers{ refaddr $self }} ) { + $show_handler->( $delta_time, $self ) if $show_handler; } } -sub stop { $_stop{ refaddr $_[0] } = 1 } - sub _add_handler { my ( $arr_ref, $handler ) = @_; push @{$arr_ref}, $handler; @@ -236,15 +303,15 @@ sub remove_all_handlers { } sub remove_all_move_handlers { - $_move_handlers{ refaddr $_[0] } = []; + @{ $_move_handlers{ refaddr $_[0] } } = (); } sub remove_all_event_handlers { - $_event_handlers{ refaddr $_[0] } = []; + @{ $_event_handlers{ refaddr $_[0] } } = (); } sub remove_all_show_handlers { - $_show_handlers{ refaddr $_[0] } = []; + @{ $_show_handlers{ refaddr $_[0] } } = (); } sub move_handlers { $_move_handlers{ refaddr $_[0] } } @@ -267,26 +334,99 @@ sub min_t { $_min_t{ $ref}; } -sub current_time { +sub max_t { my ($self, $arg) = @_; my $ref = refaddr $self; - $_current_time{ $ref} = $arg if defined $arg; + $_max_t{ $ref } = $arg if defined $arg; - $_current_time{ $ref}; + $_max_t{ $ref }; } -sub paused { - $_paused{ refaddr $_[0]}; +sub delay { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_delay{ $ref} = $arg if defined $arg; + + $_delay{ $ref}; } -sub _exit_on_quit { - my ($self, $event) = @_; +sub event_handler { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_event_handler{ $ref } = $arg if @_ > 1; - $self->stop() if $event->type == SDL_QUIT; + $_event_handler{ $ref }; } -1; +sub move_handler { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_move_handler{ $ref } = $arg if @_ > 1; -__END__ + $_move_handler{ $ref }; +} +sub show_handler { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_show_handler{ $ref } = $arg if @_ > 1; + + $_show_handler{ $ref }; +} +sub stop_handler { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_stop_handler{ $ref} = $arg if @_ > 1; + + $_stop_handler{ $ref}; +} + +sub before_pause { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_before_pause{ $ref } = $arg if @_ > 1; + + $_before_pause{ $ref }; +} + +sub after_pause { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_after_pause{ $ref } = $arg if @_ > 1; + + $_after_pause{ $ref }; +} + +sub default_stop_handler { + my ($event, $self) = @_; + + $self->stop() if $event->type == SDL::Events::SDL_QUIT; +} + +sub event { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_event{ $ref} = $arg if defined $arg; + + $_event{ $ref}; +} + +# replacements for SDLx::App::get_ticks() and SDLx::App::delay() +sub time { + my ($self, $arg) = @_; + my $ref = refaddr $self; + $_time{ $ref} = $arg if defined $arg; + + $_time{ $ref}; +} +sub sleep { + return Time::HiRes::sleep( $_[1] ); +} + +# deprecated +sub ticks { + return SDL::get_ticks(); +} + +1; diff --git a/lib/SDLx/Music/Data.pm b/lib/SDLx/Music/Data.pm index 5bb0b7fe..e11427c5 100644 --- a/lib/SDLx/Music/Data.pm +++ b/lib/SDLx/Music/Data.pm @@ -1,5 +1,8 @@ package SDLx::Music::Data; +use strict; +use warnings; + sub volume { $_[0]->{volume} = $_[1] if $_[1]; diff --git a/lib/SDLx/Rect.pm b/lib/SDLx/Rect.pm index facf5414..f1b2a0c3 100644 --- a/lib/SDLx/Rect.pm +++ b/lib/SDLx/Rect.pm @@ -4,7 +4,8 @@ use warnings; use Carp; use base 'SDL::Rect'; -our $VERSION = '0.01'; +our $VERSION = '2.541_10'; +$VERSION = eval $VERSION; sub new { my $class = shift; diff --git a/lib/SDLx/Sound.pm b/lib/SDLx/Sound.pm index 7cb2ede1..46ea844c 100644 --- a/lib/SDLx/Sound.pm +++ b/lib/SDLx/Sound.pm @@ -12,6 +12,9 @@ use SDL::Mixer::Music; #use SDL::Mixer::Samples; #use SDL::Mixer::MixChunk; +our $VERSION = '2.541_10'; +$VERSION = eval $VERSION; + # SDL::Mixer must be inited only one time my $audioInited = undef; diff --git a/lib/SDLx/Surface.pm b/lib/SDLx/Surface.pm index a2e9ce6e..42d665db 100644 --- a/lib/SDLx/Surface.pm +++ b/lib/SDLx/Surface.pm @@ -16,7 +16,6 @@ use SDL::PixelFormat; use SDL::GFX::Primitives; -use Tie::Simple; use SDLx::Validate; use SDLx::Surface::TiedMatrix; @@ -152,9 +151,11 @@ sub height { $_[0]->h } #WRAPPING sub clip_rect { - - SDL::Video::set_clip_rect( $_[1] ) if $_[1] && $_[1]->isa('SDL::Rect'); - SDL::Video::get_clip_rect( $_[0] ); + + SDL::Video::set_clip_rect( @_[0,1] ) if $_[1] && $_[1]->isa('SDL::Rect'); + my $r = $_[1] || SDL::Rect->new (0,0,0,0) ; + SDL::Video::get_clip_rect( $_[0], $r ); + return $r ; } diff --git a/lib/SDLx/Text.pm b/lib/SDLx/Text.pm index 4e90c839..e4dfd948 100644 --- a/lib/SDLx/Text.pm +++ b/lib/SDLx/Text.pm @@ -342,16 +342,20 @@ sub write_xy { foreach my $i ( 0 .. $#{$surfaces}) { if (my $surface = $surfaces->[$i]) { + my $tx ; $y += ($linebreaks * $surface->h); $linebreaks = 0; if ($self->{h_align} eq 'center' ) { # $x = ($target->w / 2) - ($surface->w / 2); - $x -= $surface->w / 2; + $tx = $x + ($self->w -$surface->w) / 2; } elsif ($self->{h_align} eq 'right' ) { # $x = $target->w - $surface->w; - $x -= $surface->w; + $tx = $x + $self->w - $surface->w; + } + else { + $tx = $x ; } # blit the shadow @@ -361,14 +365,14 @@ sub write_xy { SDL::Video::blit_surface( $shadow, SDL::Rect->new(0,0,$shadow->w, $shadow->h), - $target, SDL::Rect->new($x + $offset, $y + $offset, 0, 0) + $target, SDL::Rect->new($tx + $offset, $y + $offset, 0, 0) ); } # blit the text SDL::Video::blit_surface( $surface, SDL::Rect->new(0,0,$surface->w, $surface->h), - $target, SDL::Rect->new($x, $y, 0, 0) + $target, SDL::Rect->new($tx, $y, 0, 0) ); } $linebreaks++; diff --git a/lib/pods/SDL.pod b/lib/pods/SDL.pod index a33b7aae..bb94a502 100644 --- a/lib/pods/SDL.pod +++ b/lib/pods/SDL.pod @@ -88,7 +88,7 @@ C doesn't return any values. my $flags = SDL::was_init( $flags ); -C allows you to see which SDL subsytems have been initialized. +C allows you to see which SDL subsystems have been initialized. The C<$flags> tell C which subsystems to check, and are taken in the same way as C. C returns a mask of the initialized subsystems it checks. @@ -263,8 +263,9 @@ And request access to the github repository. Or drop us a line on #sdl over at i Copyright 2002-2010 SDL Authors as listed above, all rights reserved. -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. +This is free software, licensed under: + + The GNU Library General Public License, Version 2.0, June 1991 =head1 DISCLAIMER OF WARRANTY diff --git a/lib/pods/SDL/Audio.pod b/lib/pods/SDL/Audio.pod index 2c8c352c..6244e873 100644 --- a/lib/pods/SDL/Audio.pod +++ b/lib/pods/SDL/Audio.pod @@ -189,7 +189,7 @@ Converts audio data to a desired audio format. C takes as first parameter C, which was previously initialized. Initializing a C is a two step process. First of all, the structure must be created via Cbuild> along with source and destination format parameters. Secondly, -the C and C fields must be setup. C should point to the audio data buffer beeing source and destination at +the C and C fields must be setup. C should point to the audio data buffer being source and destination at once and C should be set to the buffer length in bytes. Remember, the length of the buffer pointed to by buf should be C bytes in length. @@ -256,7 +256,7 @@ Example: # And now we're ready to convert SDL::Audio::convert($wav_cvt, $wav_buf, $wav_len); - # We can freeto original WAV data now + # We can free original WAV data now SDL::Audio::free_wav($wav_buf); B: What to do with it? How to use callback? See http://www.libsdl.org/cgi/docwiki.cgi/SDL_ConvertAudio diff --git a/lib/pods/SDL/AudioSpec.pod b/lib/pods/SDL/AudioSpec.pod index b9aca813..dc7f04d2 100644 --- a/lib/pods/SDL/AudioSpec.pod +++ b/lib/pods/SDL/AudioSpec.pod @@ -29,7 +29,7 @@ Core, Audio, Structure # do something here } -=head1 DESCIPTION +=head1 DESCRIPTION The C structure is used to describe the format of some audio data. This structure is used by C and C. diff --git a/lib/pods/SDL/CD.pod b/lib/pods/SDL/CD.pod index a91ebe44..77f3ce27 100644 --- a/lib/pods/SDL/CD.pod +++ b/lib/pods/SDL/CD.pod @@ -170,7 +170,7 @@ Current track on the CD; my $track = $CD->track($number); -Retrives track description of track $number in CD. See L. +Retrieves track description of track $number in CD. See L. =head2 FRAMES_TO_MSF diff --git a/lib/pods/SDL/Cookbook/OpenGL.pod b/lib/pods/SDL/Cookbook/OpenGL.pod index 5bc715d7..e70e4550 100644 --- a/lib/pods/SDL/Cookbook/OpenGL.pod +++ b/lib/pods/SDL/Cookbook/OpenGL.pod @@ -11,9 +11,9 @@ Cookbook =head1 DESCRIPTION -As of release 2.5 SDL no longer maintains it's own bindings of openGL. Support for openGL has been moved over to a more mature implementation. +As of release 2.5 SDL no longer maintains it's own bindings of OpenGL. Support for OpenGL has been moved over to a more mature implementation. -This implementation is the POGL project. L is faster and more complete; and works with SDL seemlessly. +This implementation is the POGL project. L is faster and more complete; and works with SDL seamlessly. =head2 EXAMPLE @@ -37,7 +37,7 @@ You can use OpenGL as needed here. $| = 1; $WIDTH = 1024; $HEIGHT = 768; - $SDLAPP = SDLx::App->new(title => "Opengl App", width => $WIDTH, height => $HEIGHT, gl => 1); + $SDLAPP = SDLx::App->new(title => "OpenGL App", width => $WIDTH, height => $HEIGHT, gl => 1); $SDLEVENT = SDL::Event->new; SDLx::App can start an OpenGL application with the parameter gl => 1. @@ -48,7 +48,7 @@ SDLx::App can start an OpenGL application with the parameter gl => 1. gluPerspective(60, $WIDTH / $HEIGHT, 1, 1000); glTranslatef(0, 0, -20); -Above we enable GL and set the correct prespective +Above we enable GL and set the correct perspective while (1) { &handlepolls; diff --git a/lib/pods/SDL/Cookbook/PDL.pod b/lib/pods/SDL/Cookbook/PDL.pod index c58b45dc..05aec389 100644 --- a/lib/pods/SDL/Cookbook/PDL.pod +++ b/lib/pods/SDL/Cookbook/PDL.pod @@ -38,7 +38,7 @@ Create a normal $piddle with zeros, byte format and the Bpp x width x height dim my $pointer = $piddle->get_dataref(); -Here is where we get the acutal data the piddle is pointing to. We will have SDL create a new surface from this function. +Here is where we get the actual data the piddle is pointing to. We will have SDL create a new surface from this function. my $surface = SDL::Surface->new_from( $pointer, $width, $height, 32, $width * $bytes_per_pixel ); @@ -48,7 +48,7 @@ Using the same dimensions we create the surface using new_form. The width * Bpp warn "Made surface of $width, $height and ". $surface->format->BytesPerPixel; return ( $piddle, $surface ); -Finally make sure that the surface acutally has the correct dimensions we gave. +Finally make sure that the surface actually has the correct dimensions we gave. B $surface->format->BytesPerPixel must return 1,2,3,4. !! @@ -79,7 +79,7 @@ When blitting the new surface check for the return value to see if there has bee die "Could not blit: " . SDL::get_error() if ( $b == -1 ); -If the error message is 'Blit combination not supported' that means that the BPP is incorrect or incosistent with the dimensions. +If the error message is 'Blit combination not supported' that means that the BPP is incorrect or inconsistent with the dimensions. After that a simple update_rect will so your new surface on the screen. =head1 AUTHORS diff --git a/lib/pods/SDL/Deprecated.pod b/lib/pods/SDL/Deprecated.pod index 154f4bf1..20733114 100644 --- a/lib/pods/SDL/Deprecated.pod +++ b/lib/pods/SDL/Deprecated.pod @@ -11,6 +11,36 @@ Core =head1 RELEASES +=head2 2.xxx + +SDLx::App had a full rewrite and SDLx::Controller was updated. + +=over + +=item SDLx::App + +Shortcut aliases in the constructor have been changed and removed. The main ones people use are still there like +C, C and C. These lesser used ones no longer work: C, C, C, C, C, C, C, C, C. + +C was renamed to C, but this method wasn't documented before anyway. + +All OpenGL parameters for the constructor now have a C prefix. These were never documented, +so they're not listed here. + +The OpenGL method C is now called C. + +C has been removed and replaced with SDLx::Controller's C. C has been deprecated, but left in +for backcompat. + +=item SDLx::Controller + +The C parameter and method have been removed. The exit on quit (stop on quit) action is now enabled by default. +The C parameter and method are now used to change and disable the quit action of the app. + +C will now slow the application down if it runs at less than 10 FPS, by default. + +=back + =head2 2.517 Major changes to C. @@ -28,7 +58,7 @@ C will limit apps to a framerate of 60 by default. =item SDLx::App -C is depreceated. +C is deprecated. =back @@ -56,7 +86,7 @@ Has drastically changed, and is still volatile. =item SDL::App -SDL::App has migrated to SDLx::App namespace. The reason for this is because it is an extenstion and not a 1:1 XS/Constant Module to the c library. +SDL::App has migrated to SDLx::App namespace. The reason for this is because it is an extension and not a 1:1 XS/Constant Module to the c library. =item SDL::Game::Rect diff --git a/lib/pods/SDL/Event.pod b/lib/pods/SDL/Event.pod index 0527abd1..e2e0fd2d 100644 --- a/lib/pods/SDL/Event.pod +++ b/lib/pods/SDL/Event.pod @@ -56,8 +56,8 @@ and it is then up to the application to process the information stored with them =head2 new -C creates an empty event-object, which can be used store information. -Either by calling C that transferes one event from the queue into our object +C creates an empty event-object, which can be used to store information. +Either by calling C that transfers one event from the queue into our object or by setting all the needed data manually in order to push the event to the queue. use SDL::Event; @@ -105,7 +105,7 @@ L - Joystick axis motion event structur =item * -L - Joystick trackball motion event structure +L - Joystick trackball motion event structure =item * @@ -329,7 +329,7 @@ If the high 9 bits of the character are 0, then this maps to the equivalent ASCI print("An International Character.\n"); } -UNICODE translation does create a slight overhead so don't enable it unless its needed. +UNICODE translation does create a slight overhead, so don't enable it unless it's needed. NOTE: Key release events (SDL_KEYUP) won't necessarily (ever?) contain unicode information. See L @@ -361,7 +361,7 @@ This is currently only implemented on Windows and Linux/Unix-alikes. When a mouse button press or release is detected, the number of the button pressed (from 1 to 255, with 1 usually being the left button and 2 the right) is placed into C. The position of the mouse -when this event occured is stored in the C and the C fields. Like a keyboard event, +when this event occurred is stored in the C and the C fields. Like a keyboard event, information on whether the event was a press or a release event is stored in both the C and C fields, but this should be obvious. @@ -395,7 +395,7 @@ The field C is the index of the joystick that reported the event. =head3 jaxis_axis -The C is the index of the axis (for a more detailed explaination see the Joystick section). +The C is the index of the axis (for a more detailed explanation see the Joystick section). =head3 jaxis_value @@ -482,7 +482,7 @@ C =back -=head2 Joystrick trackball events +=head2 Joystick trackball events A C event occurs when a user moves a trackball on the joystick. diff --git a/lib/pods/SDL/Events.pod b/lib/pods/SDL/Events.pod index d5ce2a75..070bd7df 100644 --- a/lib/pods/SDL/Events.pod +++ b/lib/pods/SDL/Events.pod @@ -1,4 +1,3 @@ - =head1 NAME SDL::Events - Bindings to the Events Category in SDL API @@ -15,7 +14,7 @@ Most likely you just want to know how to get events for you app. use SDL::Event; use SDL::Events ':all'; - SDL::init(SDL_INIT_VIDEO); # Event can only be grabbed in the same thread as this + SDL::init(SDL_INIT_VIDEO); # Event can only be grabbed in the same thread as this ... @@ -27,7 +26,7 @@ Most likely you just want to know how to get events for you app. while( SDL::Events::poll_event($event) ) { #check by event type - on_active() if $event->type == SDL_ACTIVEEVENT; + on_active() if $event->type == SDL_ACTIVEEVENT; ... } } @@ -198,6 +197,11 @@ Export tag ':keymod' KMOD_MODE KMOD_RESERVED +Export tag ':repeat' + + SDL_DEFAULT_REPEAT_DELAY + SDL_DEFAULT_REPEAT_INTERVAL + =head1 METHODS =head2 pump_events @@ -206,24 +210,24 @@ Pumps the event loop, gathering events from the input devices. pump_events(); -pump_events gathers all the pending input information from devices and places it on the event queue. Without calls to pump_events no events would -ever be placed on the queue. -Often the need for calls to pump_events is hidden from the user since L and L implicitly call pump_events. +pump_events gathers all the pending input information from devices and places it on the event queue. Without calls to pump_events no events would +ever be placed on the queue. +Often the need for calls to pump_events is hidden from the user since L and L implicitly call pump_events. However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call pump_events to force an event queue update. -=head2 peep_events (event, num_events, action, mask) +=head2 peep_events (event, num_events, action, mask) -Checks the event queue for messages and optionally returns them. +Checks the event queue for messages and optionally returns them. my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS); -If action is SDL_ADDEVENT, up to numevents events will be added to the back of the event queue. +If action is SDL_ADDEVENT, up to num_events 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 +If action is SDL_PEEKEVENT, up to num_events 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 +If action is SDL_GETEVENT, up to num_events events at the front of the event queue, matching mask, will be returned and will be removed from the queue. The mask parameter is a bitwise OR of SDL::Events::SDL_EVENTMASK(event_type), for all event types you are interested in @@ -239,14 +243,14 @@ Examples of mask: =item SDL_EVENTMASK (SDL_KEYUP) =item (SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN) | SDL_EVENTMASK (SDL_MOUSEBUTTONUP)) - + =item SDL_ALLEVENTS - + =item SDL_KEYUPMASK - + =item SDL_ALLEVENTS ^ SDL_QUITMASK -=back +=back =head3 RETURN @@ -254,26 +258,26 @@ Number of Events actually stored or -1 if there was an error =head2 poll_event($event) -Polls for currently pending events. +Polls for currently pending events. If $event is not NULL, the next event is removed from the queue and stored in the L structure pointed to by $event. -As this function implicitly calls pump_events, you can only call this function in the thread that set the video mode with -L. +As this function implicitly calls pump_events, you can only call this function in the thread that set the video mode with +L. =head3 RETURN -Returns 1 if there are any pending events, or 0 if there are none available. +Returns 1 if there are any pending events, or 0 if there are none available. =head2 push_event($event) -Pushes an event onto the event queue +Pushes an event onto the event queue -The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push -their own events onto it. event is a pointer to the event structure you wish to push onto the queue. +The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push +their own events onto it. event is a pointer to the event structure you wish to push onto the queue. The event is copied into the queue, and the caller may dispose of the memory pointed to after push_event returns. -Note: Pushing device input events onto the queue doesn't modify the state of the device within SDL. +Note: Pushing device input events onto the queue doesn't modify the state of the device within SDL. This function is thread safe, and can be called from other threads safely. @@ -287,8 +291,8 @@ Waits indefinitely for the next available $event, returning 0 if there was an er If $event is not NULL, the next event is removed from the queue and stored in $event. -As this function implicitly calls SDL_PumpEvents, you can only call this function in the thread that -L. +As this function implicitly calls SDL_PumpEvents, you can only call this function in the thread that +L. =head3 RETURN @@ -296,7 +300,7 @@ L. =head2 set_event_filter -Sets up a filter to process all events +Sets up a filter to process all events my $filter = sub { if($_[0]->type == SDL_ACTIVEEVENT){ return 0} else{ return 1; }}; @@ -308,15 +312,15 @@ set_event_filter takes a coderef that it checks all events again. The callback g sub { my $event_to_test = shift; ...} -to filter the event return a 0, to pass the filter return a 1. +to filter the event return a 0, to pass the filter return a 1. -One B is if you are filtering SDL_QUIT the event will be filtered if it is non-intterupt call ( Window closes normally ). If it is a +One B is if you are filtering SDL_QUIT the event will be filtered if it is non-interrupt call ( Window closes normally ). If it is a interrupt SDL_QUIT it will be process on the next event poll. -Events pushed onto to the queue with L or L +Events pushed onto to the queue with L or L do not get filtered. -This callback may run in a different thread. +This callback may run in a different thread. =head2 get_key_state @@ -328,7 +332,7 @@ Get a snapshot of the current keyboard state Use L to update the state array. -This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you +This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you process events, then the pressed state will never show up in the get_key_state call. This function doesn't take into account whether shift has been pressed or not. @@ -345,19 +349,19 @@ Return value is an OR'd combination of KMOD_* my $mod_state = SDL::Events::get_mod_state(); - # Check which ones are pressed with + # Check which ones are pressed with # no mod pressed? - + print 'no_mod' if ( $mod_state & KMOD_NONE ); - # CTRL or ALT + # CTRL or ALT print 'ctrl alt' if ($mod_state & KMOD_CTRL || $mod_state & KMOD_ALT ); =head3 MOD VALUES -=over +=over =item KMOD_NONE @@ -383,7 +387,7 @@ Return value is an OR'd combination of KMOD_* =item KMOD_MODE -=item KMOD_CTRL +=item KMOD_CTRL same as KMOD_LCTRL|KMOD_RCTRL @@ -414,7 +418,7 @@ Simply pass your desired modifier states into $modstate. This value can be a OR' Any KMOD_* constant see L for constants. SDL::Events::set_mod_state( $modstate ); -=head2 event_state +=head2 event_state Allows you to set the state of processing certain events @@ -454,7 +458,7 @@ Gets the name of the a SDL virtual keysym Returns a string with the name of the key sym. -=head2 enable_unicode +=head2 enable_unicode Enable/Disable UNICODE translation @@ -462,63 +466,63 @@ Enable/Disable UNICODE translation $previous_translation_mode = SDL::Events::enable_unicode( 0 ); #disables To obtain the character codes corresponding to received keyboard events, Unicode translation must first be turned on using this function. The -translation incurs a slight overhead for each keyboard event and is therefore disabled by default. For each subsequently recieved key down event, +translation incurs a slight overhead for each keyboard event and is therefore disabled by default. For each subsequently received key down event, the unicode member of the L provided structure will be then contain the corresponding character code, or otherwise zero. -A value of 1 for enabling, 0 for disabling and -1 for unchanged. -1 is usefull for querying the current translation mode. +A value of 1 for enabling, 0 for disabling and -1 for unchanged. -1 is useful for querying the current translation mode. Only key press events will be translated not release events. Returns the previous translation mode as (1,0). -=head2 enable_key_repeat +=head2 enable_key_repeat Sets keyboard repeat rate my $success = SDL::Events::enable_key_repeat( $delay, $interval ); -Enables or disables the keyboard repeat rate. $delay specifies how long the key must be pressed before it begins repeating, it then repleats at the +Enables or disables the keyboard repeat rate. $delay specifies how long the key must be pressed before it begins repeating, it then repeats at the speed specified by $interval. Both $delay and $interval are expressed in milliseconds. Setting $delay to 0 disables key repeating completely. Good default values are SDL_DEFAULT_REPEAT_DELAY and SDL_DEFAULT_REPEAT_INTERVAL. Return 0 on success and -1 on fail. -=head2 get_mouse_state +=head2 get_mouse_state -Retrives the current state of the mouse +Retrieves the current state of the mouse my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) }; - print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); + print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); - print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); + print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); - print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); + print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); print $x.','.$y; -The current button state is returned as a button $bitmask, which can be tested using the the above constants +The current button state is returned as a button $bitmask, which can be tested using the the above constants -=head2 get_relative_mouse_state +=head2 get_relative_mouse_state -Retrives the current relative state of the mouse +Retrieves the current relative state of the mouse my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) }; - print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); + print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); - print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); + print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); - print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); + print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); - print $x.','.$y; # this is relative to the last postion of the mouse + print $x.','.$y; # this is relative to the last position of the mouse -The current button state is returned as a button $bitmask, which can be tested using the the above constants +The current button state is returned as a button $bitmask, which can be tested using the the above constants -=head2 get_app_state +=head2 get_app_state Gets the state of the application @@ -526,7 +530,7 @@ Gets the state of the application The $app_state is a bitwise combination of: -=over +=over =item SDL_APPMOUSEFOCUS @@ -547,22 +551,22 @@ Application is visible warn 'Application Visible' if $app_state & SDL_APPACTIVE -=back +=back -=head2 joystick_event_state +=head2 joystick_event_state Enable/disable joystick event polling my $status = SDL::Events::joystick_event_state( $state ); -This function is used to enable or disable joystick event processing. With joystick event processing disabled you will have to update joystick +This function is used to enable or disable joystick event processing. With joystick event processing disabled you will have to update joystick states with L and read the joystick information manually. $state can be: -=over +=over =item SDL_QUERY -=item SDL_ENABLE +=item SDL_ENABLE =item SDL_IGNORE diff --git a/lib/pods/SDL/GFX/Framerate.pod b/lib/pods/SDL/GFX/Framerate.pod index 670a3dac..ecc11dac 100644 --- a/lib/pods/SDL/GFX/Framerate.pod +++ b/lib/pods/SDL/GFX/Framerate.pod @@ -41,8 +41,8 @@ Get the currently set framerate of the manager. SDL::GFX::Framerate::delay($fps); -Generate a delay to accomodate currently set framerate. Call once in thegraphics/rendering loop. -If the computer cannot keep up with the rate (i.e.drawing too slow), the delay is zero and the delay interpolation is reset. +Generate a delay to accommodate the currently set framerate. Call once in the graphics/rendering loop. +If the computer cannot keep up with the rate (i.e. drawing too slow), the delay is zero and the delay interpolation is reset. =head1 AUTHORS diff --git a/lib/pods/SDL/GFX/Primitives.pod b/lib/pods/SDL/GFX/Primitives.pod index 1f3880ac..1f9c8ecf 100644 --- a/lib/pods/SDL/GFX/Primitives.pod +++ b/lib/pods/SDL/GFX/Primitives.pod @@ -9,7 +9,7 @@ GFX =head1 DESCRIPTION -All functions take an SDL::Surface object as first parameter. This can be a new surface that will be blittet afterwads, can be an surface +All functions take an SDL::Surface object as first parameter. This can be a new surface that will be blitted afterwards, can be an surface obtained by L or can be an L. The C values for the C<_color> functions are C<0xRRGGBBAA> (32bit), even if the surface uses e. g. 8bit colors. @@ -30,7 +30,7 @@ Draws a pixel at point C/C<$y>. You can pass the color by C<0xRRGGBBAA> or by my $surface = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE); - SDL::GFX::Primitives::pixel_color($surface, 2, 2, 0xFF0000FF); # red pixcel + SDL::GFX::Primitives::pixel_color($surface, 2, 2, 0xFF0000FF); # red pixel SDL::GFX::Primitives::pixel_RGBA( $surface, 4, 4, 0x00, 0xFF, 0x00, 0xFF); # green pixel =head2 hline diff --git a/lib/pods/SDL/MPEG.pod b/lib/pods/SDL/MPEG.pod index 5d37a63b..247a898b 100644 --- a/lib/pods/SDL/MPEG.pod +++ b/lib/pods/SDL/MPEG.pod @@ -15,7 +15,7 @@ TODO =head1 DESCRIPTION -C provides an interface to quering the status +C provides an interface to querying the status of a SMPEG stream. =head2 METHODS @@ -48,7 +48,7 @@ C returns the offset into the clip in bytes =item * -C returns the offset into the clip in fames +C returns the offset into the clip in frames =item * diff --git a/lib/pods/SDL/Mixer.pod b/lib/pods/SDL/Mixer.pod index 6f761536..b16dd88f 100644 --- a/lib/pods/SDL/Mixer.pod +++ b/lib/pods/SDL/Mixer.pod @@ -163,7 +163,7 @@ B: Only available for SDL_mixer >= 1.2.10 SDL::Mixer::quit(); -This function unloads the liraries previously loaded with L. +This function unloads the libraries previously loaded with L. B: Only available for SDL_mixer >= 1.2.10 diff --git a/lib/pods/SDL/Mixer/Channels.pod b/lib/pods/SDL/Mixer/Channels.pod index 6eca76e1..4dc10e42 100644 --- a/lib/pods/SDL/Mixer/Channels.pod +++ b/lib/pods/SDL/Mixer/Channels.pod @@ -17,7 +17,7 @@ Mixer my $ret = SDL::Mixer::Channels::allocate_channels( $number_of_channels ); -Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels arestopped. +Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels are stopped. This function returns the new number of allocated channels. Example @@ -142,7 +142,7 @@ Example 2: my $playing = SDL::Mixer::Channels::playing( $channel ); -Returns C<1> if the given channel is playing sound, otherwise C<0>. It does'nt check if the channel is paused. +Returns C<1> if the given channel is playing sound, otherwise C<0>. It doesn't check if the channel is paused. B: If you pass C<-1> you will get the number of playing channels. diff --git a/lib/pods/SDL/Mixer/Groups.pod b/lib/pods/SDL/Mixer/Groups.pod index 6e1676bd..347ba880 100644 --- a/lib/pods/SDL/Mixer/Groups.pod +++ b/lib/pods/SDL/Mixer/Groups.pod @@ -92,7 +92,7 @@ C returns the channel number which started to play at last. Fades out the channels by the given group id. The fade-out-time is specified by C<$ms>. -Retuns the number of affected channels. +Returns the number of affected channels. =head2 halt_group @@ -100,7 +100,7 @@ Retuns the number of affected channels. Halts the channels by the given group id. -Retuns C<0>. +Returns C<0>. =head1 AUTHORS diff --git a/lib/pods/SDL/Mixer/Music.pod b/lib/pods/SDL/Mixer/Music.pod index e862548e..0fefbd3b 100644 --- a/lib/pods/SDL/Mixer/Music.pod +++ b/lib/pods/SDL/Mixer/Music.pod @@ -240,7 +240,7 @@ Returns C<1> if the music is paused, otherwise C<0>. my $playing_music = SDL::Mixer::Music::playing_music(); -Returns C<1> if the music is playing sound, otherwise C<0>. It does'nt check if the music is paused. +Returns C<1> if the music is playing sound, otherwise C<0>. It doesn't check if the music is paused. =head1 AUTHORS diff --git a/lib/pods/SDL/Mouse.png b/lib/pods/SDL/Mouse.png deleted file mode 100644 index 73b42e64..00000000 Binary files a/lib/pods/SDL/Mouse.png and /dev/null differ diff --git a/lib/pods/SDL/Overlay.pod b/lib/pods/SDL/Overlay.pod index 4c465271..7ecc8cef 100644 --- a/lib/pods/SDL/Overlay.pod +++ b/lib/pods/SDL/Overlay.pod @@ -17,7 +17,7 @@ First import the following modules to get access to constants and functions need use SDL::Video; use SDL::Overlay; -Init the video susbsystem. +Init the video subsystem. SDL::Init(SDL_INIT_VIDEO); diff --git a/lib/pods/SDL/Pango.pod b/lib/pods/SDL/Pango.pod index beb8bd71..e50cc1dc 100644 --- a/lib/pods/SDL/Pango.pod +++ b/lib/pods/SDL/Pango.pod @@ -25,7 +25,7 @@ Pango my $context = SDL::Pango::Context->new; SDL::Pango::set_default_color($context, 0xA7C344FF, 0); - SDL::Pango::set_markup($context, 'Hallo World!', -1); + SDL::Pango::set_markup($context, 'Hello World!', -1); SDL::init(SDL_INIT_VIDEO); @@ -110,7 +110,7 @@ Returns: always C<0>. my $was_init = SDL::Pango::was_init(); -Query the initilization status of the Glib and Pango API. You may, of course, use this before L to avoid initilizing twice +Query the initialization status of the Glib and Pango API. You may, of course, use this before L to avoid initializing twice in a row. Returns: Non-zero when already initialized. Zero when not initialized. @@ -212,7 +212,7 @@ Draws the text or markup to an existing surface at position C<$x>/C<$y>. SDL::Pango::set_surface_create_args($context, $flags, $bits, $r_mask, $g_mask, $b_mask, $a_mask); -Sets the argumet that are used when creating a surface via L. +Sets the argument that are used when creating a surface via L. Example: diff --git a/lib/pods/SDL/Platform.pod b/lib/pods/SDL/Platform.pod new file mode 100644 index 00000000..d71a5094 --- /dev/null +++ b/lib/pods/SDL/Platform.pod @@ -0,0 +1,112 @@ + +=pod + +=head1 NAME + +SDL::Platform - Platform Specific Informations about SDL Perl + +=head1 CATEGORY + +Documentation + +=head1 DESCRIPTION + +This document describes OS specific informations regading the installation and use of L. + +=head2 General (all OS) + +You need to install L to acquire all prerequisites of L. + +On Windows, L will get you zip-files containing prebuilt libs. + +On Unixes you can choose between compiling libs or use libs provided by the dist. +The different options on Unixes are availale when requirements are met. Like having specific libs installed. + +There is some additional documentation in the L. +You definitively want to look there, if you want to know how to install L from the latest sources (e.g. in an unfinished, unreleased state). + +=head1 Windows + +=head2 Installation + +We recommend Strawberry Perl. You can get it L. + +Once you installed Strawberry Perl, you can access the cpan shell via the start menu. + +Open up the cpan shell and type C. Please follow the dialog and answer the questions to the best of your knowledge. + +=head1 Mac OS X + +=head2 Installation + +You will need a newer version of Perl that you can install with L. + +Once you have a newer Perl installed please use C to install L (and of course L). + +=head2 Using SDL on Mac OS X + +You can't use the C executable to run SDL scripts on Mac OS X, you need to use C. +When you install L, a program named C is installed. It should be in your path. + +Using Mac OS X, your SDL Perl script have to look like this: + + #!SDLPerl + + use strict; + use warnings; + use SDL; + # your code here ... + +Using the wrong Perl executable, you might encounter a lot of error messages resulting in C. +cf. the corresponding L. + +=head1 SEE ALSO + +=over + +=item * L + +=item * L + +=back + +=head1 AUTHORS + +See list of module authors in L. + +If you would like to contribute to SDL Perl, please post a message on the mailing list: + +sdl-devel@perl.org + +And request access to the github repository. Or drop us a line on #sdl over at irc.perl.org + +=head1 COPYRIGHT & LICENSE + +Copyright 2002-2010 SDL Authors as listed above, all rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=head1 DISCLAIMER OF WARRANTY + +BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE +ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH +YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR, OR CORRECTION. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE +LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, +OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE +THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + diff --git a/lib/pods/SDL/RWOps.pod b/lib/pods/SDL/RWOps.pod index 7d22e0ed..b9c57c24 100644 --- a/lib/pods/SDL/RWOps.pod +++ b/lib/pods/SDL/RWOps.pod @@ -3,7 +3,7 @@ =head1 NAME -SDL::RWOps -- SDL Bindings to SDL_RWOPs +SDL::RWOps -- SDL Bindings to SDL_RWops =head1 CATEGORY @@ -13,7 +13,7 @@ TODO, Core, Structure =head1 SYNOPSIS # The following example will load several png's from a single file to an array of SDL::Surface's. - # Usefull for e.g. levelfiles. + # Useful for e.g. levelfiles. use SDL; use SDL::Image; use SDL::RWOps; @@ -46,15 +46,16 @@ SDL::RWOps is an "undocumented" feature of SDL, allowing you to use pointers to An example usage would be to put a bunch of resources in a zip file and use Zziplib to access them easily. +B: All methods except C and C are still TODO. =head1 METHODS -=head2 rw_from_file(file,mode) +=head2 new_file(file,mode) -rw_from_file creates a new SDL::RWops structure for reading from and/or writing to a named file. +C creates a new SDL::RWOps structure for reading from and/or writing to a named file. The mode string is treated the same as in a call to the C library's fopen(). -SDL::rw_from_file() returns a SDL::RWops structure on succés or undef on failure. +SDL::rw_from_file() returns a SDL::RWOps structure on success or undef on failure. Mode Strings: @@ -78,71 +79,71 @@ This additional "b" character can either be appended at the end of the string (t -=head2 rw_from_fp(fp,autoclose) +=head2 new_FP(fp,autoclose) -SDL::rw_from_fp creates a new SDL::RWops structure from a file pointer, opened with stdio. If autoclose is nonzero, the file will be automatically closed when the SDL::RWops structure is closed. -It returns a SDL::RWops on succés or undef on error. +SDL::rw_from_fp creates a new SDL::RWOps structure from a file pointer, opened with stdio. If autoclose is nonzero, the file will be automatically closed when the SDL::RWOps structure is closed. +It returns a SDL::RWOps on success or undef on error. Note: This is not available under Win32, since files opened in an application on that platform cannot be used by a dynamically linked library. -=head2 rw_from_mem(mem,size) +=head2 new_mem(mem,size) -SDL::rw_from_mem sets up a SDL::RWops struct based on a chunk of memory of a certain size. -It returns a SDL::Rwops on succés or undef on error. +SDL::rw_from_mem sets up a SDL::RWOps struct based on a chunk of memory of a certain size. +It returns a SDL::RWOps on success or undef on error. Note: If the memory is not writable, use SDL::rw_from_const_mem instead. -=head2 from_const_mem +=head2 new_const_mem - my $rw = SDL::RWOps->from_const_mem( $image_data ); - my $rw = SDL::RWOps->from_const_mem( $image_data, $size ); + my $rw = SDL::RWOps->new_const_mem( $image_data ); + my $rw = SDL::RWOps->new_const_mem( $image_data, $size ); -C sets up a SDL::RWOps object based on a memory area of a certain size. The C<$size> parameter is optional. +C sets up a SDL::RWOps object based on a memory area of a certain size. The C<$size> parameter is optional. It assumes the memory area is not writable. It returns a SDL::RWOps on success or undef on error. -=head2 alloc_rw() +=head2 alloc() -alloc_rw allocates an empty, unpopulated SDL::RWops structure. You must fill out the fields yourself. -It returns a SDL::RWops structure on succés or undef on error. +alloc_rw allocates an empty, unpopulated SDL::RWOps structure. You must fill out the fields yourself. +It returns a SDL::RWOps structure on success or undef on error. Note: You must free any memory allocated with SDL::alloc_rw with SDL::free_rw. -=head2 free_rw(context) +=head2 free(context) -SDL::free_rw frees an SDL::RWops structure previously allocated by SDL::alloc_rw. Only use it on memory allocated by SDL::alloc_rw. -It doesn't returns anything. +SDL::free_rw frees an SDL::RWOps structure previously allocated by SDL::alloc_rw. Only use it on memory allocated by SDL::alloc_rw. +It doesn't return anything. -=head2 rw_seek(ctx,offset,whence) +=head2 seek(ctx,offset,whence) SDL::rw_seek calls the seek function pointer in an SDL::RWOps structure. It takes the same 3 parameters as the function pointer: - 1. A pointer to an SDL::rwops structure + 1. A pointer to an SDL::RWOps structure 2. An offset in bytes. This can be a negative value. 3.SEEK_SET, SEEK_CUR, or SEEK_END. SEEK_SET seeks from the beginning of the file, SEEK_CUR from the current position, and SEEK_END from the end of the file. SDL::rw_seek returns the final offset in the data source. -=head2 rw_tell(ctx) +=head2 tell(ctx) SDL::rw_tell performs a do-nothing seek to get the current offset in an SDL::RWOps stream ctx. It takes one parameter, a pointer to an SDL::RWOps structure. It returns the offset in the stream. -=head2 rw_read(ctx,ptr,size,n) +=head2 read(ctx,ptr,size,n) SDL_RWread calls the function pointed to by an SDL::RWOps structure's read member. It takes the same 4 parameters as the function pointer: 1. A pointer to an SDL::RWOps structure 2. A pointer to an area of memory to read data into 3. The size of each block of memory to read - 4. The maxinum number of memory blocks to read(it may read less) + 4. The maximum number of memory blocks to read(it may read less) It returns the number of memory blocks read, or -1 if the read failed. -=head2 rw_write(ctx,ptr,size,n) +=head2 write(ctx,ptr,size,n) SDL_RWwrite calls the write function in an SDL::RWOps structure. It takes the same parameters as the write function given in the SDL::RWOps structure: @@ -155,7 +156,7 @@ SDL_RWwrite calls the write function in an SDL::RWOps structure. It takes the sa If it couldn't write that exact number of blocks, or the write didn't work at all, it returns -1. -=head2 rw_close(ctx) +=head2 close(ctx) SDL::rw_close calls the close function in an SDL::RWOps structure. It only takes one parameter, an SDL::RWOps structure. Returns 0 on success, -1 on error. diff --git a/lib/pods/SDL/SMPEG.pod b/lib/pods/SDL/SMPEG.pod index e9bd1baf..6c8f51b0 100644 --- a/lib/pods/SDL/SMPEG.pod +++ b/lib/pods/SDL/SMPEG.pod @@ -18,7 +18,7 @@ TODO C adds support for MPEG video to your SDL Perl application. SMPEGs are objects bound to -surfaces, whose playback is controled through the +surfaces, whose playback is controlled through the object's interface. =head2 METHODS diff --git a/lib/pods/SDL/Surface.pod b/lib/pods/SDL/Surface.pod index 864a8256..15082f1a 100644 --- a/lib/pods/SDL/Surface.pod +++ b/lib/pods/SDL/Surface.pod @@ -83,6 +83,12 @@ SDL::Surface width is defined at construction so this is read-only. Returns the height of the surface. SDL::Surface height is defined at construction so this is read-only. +=head2 flags + + my $flags = $surface->flags; + +Returns the flags of the surface (bitwise OR-ed L). + =head2 format my $format = $surface->format; diff --git a/lib/pods/SDL/TTF.pod b/lib/pods/SDL/TTF.pod index ebcc07ba..abc75406 100644 --- a/lib/pods/SDL/TTF.pod +++ b/lib/pods/SDL/TTF.pod @@ -107,7 +107,7 @@ Returns: C<0> on success, C<-1> on any error. my $was_init = SDL::TTF::was_init(); -Query the initilization status of the truetype font API. +Query the initialization status of the truetype font API. You may, of course, use this before L to avoid initializing twice in a row. Or use this to determine if you need to call L. @@ -456,7 +456,7 @@ Note that the first example uses the same text as in the LATIN1 example, that is Examples: - ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hallo World!') }; # plain text, if your script is in utf8 or ansi-format + ($width, $height) = @{ SDL::TTF::size_utf8($font, 'Hello World!') }; # plain text, if your script is in utf8 or ansi-format # or @@ -465,7 +465,7 @@ Examples: # or use Unicode::String; - my $unicode = utf8($data_from_somwhere); + my $unicode = utf8($data_from_somewhere); ($width, $height) = @{ SDL::TTF::size_utf8($font, $unicode->utf8) }; # utf8 via Unicode::String =head4 size_unicode @@ -481,15 +481,15 @@ C<$text> has to be: =item UTF16BE without BOM -"hallo" will look like "\0h\0a\0l\0l\0o" +"hello" will look like "\0h\0e\0l\0l\0o" =item UTF16BE with BOM -"hallo" will look like "\xFE\xFF\0h\0a\0l\0l\0o" +"hello" will look like "\xFE\xFF\0h\0e\0l\0l\0o" =item UTF16LE with BOM -"hallo" will look like "\xFF\xFEh\0a\0l\0l\0o\0" +"hello" will look like "\xFF\xFEh\0e\0l\0l\0o\0" =back @@ -532,7 +532,7 @@ Example: my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE); my $font = SDL::TTF::open_font('somefont.ttf', '24'); die 'Coudnt make font '. SDL::get_error if !$font; - my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', SDL::Color->new(0xFF,0xFF,0xFF)); + my $surface = SDL::TTF::render_text_solid($font, 'Hello!', SDL::Color->new(0xFF,0xFF,0xFF)); SDL::Video::blit_surface($surface, SDL::Rect->new(0, 0, 640, 480), $display, SDL::Rect->new(10, 10, 640, 480)); SDL::Video::update_rect($display, 0, 0, 0, 0); SDL::delay(5000); @@ -591,7 +591,7 @@ Example: my $font = SDL::TTF::open_font('arial.ttf', '24'); my $white = SDL::Color->new(0xFF, 0xFF, 0xFF); my $black = SDL::Color->new(0x00, 0x00, 0x00); - my $surface = SDL::TTF::render_text_solid($font, 'Hallo!', $white, $black); + my $surface = SDL::TTF::render_text_solid($font, 'Hello!', $white, $black); SDL::Video::blit_surface($surface, SDL::Rect->new(0, 0, 640, 480), $display, SDL::Rect->new(10, 10, 640, 480)); SDL::Video::update_rect($display, 0, 0, 0, 0); @@ -644,7 +644,7 @@ Example: my $display = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE); my $font = SDL::TTF::open_font('arial.ttf', '24'); - my $surface = SDL::TTF::render_text_blended($font, 'Hallo!', SDL::Color->new(0xFF,0xFF,0xFF)); + my $surface = SDL::TTF::render_text_blended($font, 'Hello!', SDL::Color->new(0xFF,0xFF,0xFF)); SDL::Video::blit_surface($surface, SDL::Rect->new(0, 0, 640, 480), $display, SDL::Rect->new(10, 10, 640, 480)); SDL::Video::update_rect($display, 0, 0, 0, 0); diff --git a/lib/pods/SDL/Tutorial/LunarLander.pod b/lib/pods/SDL/Tutorial/LunarLander.pod index 6b604ad3..514fd3db 100644 --- a/lib/pods/SDL/Tutorial/LunarLander.pod +++ b/lib/pods/SDL/Tutorial/LunarLander.pod @@ -146,7 +146,7 @@ So the middle section of the program will become: if ( $up{$t} ) { my $a = $up{$t}; - print "(accellerating $a m/s^2)\n"; + print "(accelerating $a m/s^2)\n"; $velocity = $velocity - $a; } diff --git a/lib/pods/SDL/Video.png b/lib/pods/SDL/Video.png deleted file mode 100644 index 921e25ff..00000000 Binary files a/lib/pods/SDL/Video.png and /dev/null differ diff --git a/lib/pods/SDL/Video.pod b/lib/pods/SDL/Video.pod index f90eed93..fef90458 100644 --- a/lib/pods/SDL/Video.pod +++ b/lib/pods/SDL/Video.pod @@ -65,11 +65,11 @@ Export tag: ':video' NOTE: This option is kept for compatibility only, and is not recommended for new code. SDL_RESIZABLE Resizable surface SDL_NOFRAME No window caption or edge frame - SDL_HWACCEL Use Hardware acceleration blit + SDL_HWACCEL Use hardware acceleration blit SDL_SRCCOLORKEY Use colorkey blitting SDL_RLEACCELOK Private flag SDL_RLEACCEL Accelerated colorkey blitting with RLE - SDL_SRCALPHA Use alpha blending blit + SDL_SRCALPHA Use alpha blending blit (per-surface alpha) SDL_PREALLOC Use preallocated memory Export tag ':overlay' @@ -84,13 +84,13 @@ Export tag ':palette' SDL_LOGPAL Logical palette, which controls how blits are mapped to/from the surface SDL_PHYSPAL Physical palette, which controls how pixels look on the screen - + Export tag ':grab' SDL_GRAB_QUERY SDL_GRAB_OFF SDL_GRAB_ON - SDL_GRAB_FULLSCREEN Used interally + SDL_GRAB_FULLSCREEN Used internally Export tag ':gl' @@ -248,7 +248,7 @@ Sets up a video mode with the specified width, height, bits-per-pixel and flags. C returns a L on success otherwise it returns undef on error, the error message is retrieved using C. -=head3 List of avalaibles flags +=head3 List of available flags =over 4 @@ -337,19 +337,19 @@ each call to L, for example for a mu Creates a new SDL::surface of the specified L, and then copies and maps the given surface to it. It is also useful for making a copy of a surface. - + The flags parameter is passed to LC<-Enew> and has those semantics. This function is used internally by L. This function can only be called after C. - + it returns a L on success or C on error. - + =head2 display_format $new_surface = SDL::Video::display_format( $surface ); This function takes a surface and copies it to a new surface of the pixel format and colors of the video framebuffer, suitable for fast -blitting onto the display surface. It calls L. +blitting onto the display surface. It calls L. If you want to take advantage of hardware colorkey or alpha blit acceleration, you should set the colorkey and alpha value before calling this function. @@ -438,7 +438,7 @@ C returns C<0> on success or C<-1> on error. =head2 set_alpha - $set_alpha = SDL::Video::set_alpha( $surface, $flag, $key ); + $set_alpha = SDL::Video::set_alpha( $surface, $flag, $alpha ); C is used for setting the per-surface alpha value and/or enabling and disabling alpha blending. @@ -626,11 +626,11 @@ a matching unlock. SDL::Video::unlock_surface( $surface ); -Surfaces that were previously locked using L must be unlocked with C. +Surfaces that were previously locked using L must be unlocked with C. Surfaces should be unlocked as soon as possible. C doesn't return anything. -B: Since 1.1.8, the surface locks are recursive. See L for more information. +B: Since 1.1.8, the surface locks are recursive. See L for more information. =head2 MUSTLOCK @@ -649,7 +649,7 @@ rectangle will be drawn into. The rectangle pointed to by rect will be clipped to the edges of the surface so that the clip rectangle for a surface can never fall outside the edges of the surface. If rect is NULL the clipping rectangle will be set to the full size of the surface. -C doesn't returns anything. +C doesn't return anything. =head2 get_clip_rect @@ -658,7 +658,7 @@ C doesn't returns anything. Gets the clipping rectangle for the given L. When this surface is the destination of a blit, only the area within the clip rectangle is drawn into. The rectangle pointed to by rect will be filled with the clipping rectangle of the surface. -C doesn't returns anything; +C doesn't return anything; use SDL; use SDL::Video; @@ -692,8 +692,27 @@ but this is not the case with C. Like most surface man with OpenGL. The results of blitting operations vary greatly depending on whether C is set or not. See L -for an explanation of how this affects your results. Colorkeying and alpha attributes also interact with surface blitting. -C doesn't returns anything. +for an explanation of how this affects your results. Colorkeying and alpha attributes also interact with surface blitting, as the following pseudo-code should hopefully explain. + + if (source surface has SDL_SRCALPHA set) { + if (source surface has alpha channel (that is, surface->format->Amask != 0)) + blit using per-pixel alpha, ignoring any colour key + else { + if (source surface has SDL_SRCCOLORKEY set) + blit using the colour key AND the per-surface alpha value + else + blit using the per-surface alpha value + } + } else { + if (source surface has SDL_SRCCOLORKEY set) + blit using the colour key + else + ordinary opaque rectangular blit + } + +See L for details on C<< surface->format->Amask >>. + +C doesn't return anything. For an example see L. @@ -703,7 +722,7 @@ For an example see L. Makes sure the given area is updated on the given screen. The rectangle must be confined within the screen boundaries because there's no clipping. -update_rect doesn't returns any value. +update_rect doesn't return any value. B: This function should not be called while screen is locked by L @@ -717,7 +736,7 @@ For an example see L Makes sure the given list of rectangles is updated on the given screen. The rectangle must be confined within the screen boundaries because there's no clipping. -C doesn't returns any value. +C doesn't return any value. B: This function should not be called while screen is locked by L. @@ -826,7 +845,7 @@ Sets a portion of the palette for the given 8-bit surface. Palettized (8-bit) screen surfaces with the C flag have two palettes, a logical palette that is used for mapping blits to/from the surface and a physical palette (that determines how the hardware will map the colors to the display). -Non screen surfaces have a logical palette only. L always uses the logical palette when blitting surfaces (if it has to +Non screen surfaces have a logical palette only. L always uses the logical palette when blitting surfaces (if it has to convert between surface pixel formats). Because of this, it is often useful to modify only one or the other palette to achieve various special color effects (e.g., screen fading, color flashes, screen dimming). @@ -919,7 +938,7 @@ C returns -1 on error. if( -1 == $ret ) { - print( "an error occoured" ); + print( "an error occurred" ); } else { @@ -962,7 +981,7 @@ Example: if( -1 == $ret ) { - print( "an error occoured" ); + print( "an error occurred" ); } else { @@ -1189,7 +1208,7 @@ Example: SDL::Video::GL_swap_buffers(); Swap the OpenGL buffers, if double-buffering is supported. -C doesn't returns any value. +C doesn't return any value. =head1 Video Overlay Functions @@ -1206,7 +1225,7 @@ It returns C<0> on success or C<-1> on error. SDL::Video::unlock_YUV_overlay( $overlay ); -The opposite to L. Unlocks a previously locked overlay. An overlay must be unlocked before it +The opposite to L. Unlocks a previously locked overlay. An overlay must be unlocked before it can be displayed. C does not return anything. =head2 display_YUV_overlay diff --git a/lib/pods/SDL/Video_lock_surface.png b/lib/pods/SDL/Video_lock_surface.png deleted file mode 100644 index 3ed93177..00000000 Binary files a/lib/pods/SDL/Video_lock_surface.png and /dev/null differ diff --git a/lib/pods/SDL/Video_thumb.png b/lib/pods/SDL/Video_thumb.png deleted file mode 100644 index c05ea9fb..00000000 Binary files a/lib/pods/SDL/Video_thumb.png and /dev/null differ diff --git a/lib/pods/SDL_thumb.png b/lib/pods/SDL_thumb.png deleted file mode 100644 index 613e48fd..00000000 Binary files a/lib/pods/SDL_thumb.png and /dev/null differ diff --git a/lib/pods/SDLx/App.pod b/lib/pods/SDLx/App.pod index 98a3a41c..7951b6e5 100644 --- a/lib/pods/SDLx/App.pod +++ b/lib/pods/SDLx/App.pod @@ -1,9 +1,8 @@ - =pod =head1 NAME -SDLx::App - a SDL perl extension +SDLx::App - The root window of an SDL application =head1 CATEGORY @@ -11,169 +10,428 @@ Extension =head1 SYNOPSIS - use SDL; - use SDLx::App; - use SDL::Event; - use SDL::Events; - - my $app = SDLx::App->new( - title => 'Application Title', - width => 640, - height => 480, - depth => 32 - ); - -This is the manual way of doing things - - my $event = SDL::Event->new; # create a new event - - SDL::Events::pump_events(); - - while ( SDL::Events::poll_event($event) ) { - my $type = $event->type(); # get event type - print $type; - exit if $type == SDL_QUIT; - } - -An alternative to the manual Event processing is through the L module. L is a Controller so see the CALLBACKS section below. + use SDL; + use SDLx::App; + use SDL::Event; + use SDL::Events; + + # this is all the code we need to have a working app! + my $app = SDLx::App->new; + + # we can also specify many useful things in the constructor + my $app = SDLx::App->new( + title => 'My Great Game', + width => 1024, + height => 600, + dt => 0.05, + centered => 1, + no_frame => 1, + async_blit => 1, + ); + + # our app also comes with an SDLx::Controller + + # add a handler handle events such as keypresses + $app->add_event_handler( sub{ + my ($event, $app) = @_; + return $_[0]->type == SDL_QUIT ? 0 : 1; + }); + + # add a handler to move our objects in response to time + $app->add_move_handler( sub{ + my ($step, $app, $t) = @_; + #calc your physics here + } ); + + # add a handler to show our objects on the screen + $app->add_show_handler( sub{ + my ($delta, $app) = @_; + $app->update; + } ); + + # finally, start the app run loop with the added handlers + $app->run(); + +For a full explanation of the L loop and other Controller related methods, +please see L. =head1 DESCRIPTION -L controls the root window of the of your SDL based application. -It extends the L class, and provides an interface to the window -manager oriented functions. +The C provides methods for the root window of your SDL application, +as well as many related convenience methods. +It is a subclass of both L and L, +providing all the methods they both provide. =head1 METHODS =head2 new -C initializes the SDL, creates a new screen, -and initializes some of the window manager properties. -C takes a series of named parameters: + my $app = SDLx::App->new( + width => 640, + height => 480, + depth => 32, + + title => "Application Title", + icon_title => "App Title", + icon => "icon.bmp", + icon_alpha_key => [255, 255, 0], + + # two ways to do init. init video is assumed regardless + init => SDL_INIT_AUDIO | SDL_INIT_JOYSTICK, + init => [ 'audio', 'joystick' ], + + # normal libsdl access to flags + flags => SDL_SWSURFACE | SDL_ANYFORMAT, + # or parameter access to flags + sw_surface => 1, + hw_surface => 1, + async_blit => 1, + any_format => 1, + hw_palette => 1, + double_buf => 1, + fullscreen => 1, + open_gl => 1, + resizable => 1, + no_frame => 1, + + # window position + centered => 1, + position => [ 150, 100 ], + + # mouse stuff + hide_cursor => 1, + grab_input => 1, + + # don't initialize an SDLx::Controller for the app + no_controller => 1, + + # store your goodies in the app if you like + stash => {}, + + # and everything from SDLx::Controller + dt => 0.1, + min_t => 1 / 60, + max_t => 0.1, + delay => 0, + stop_handler => \&SDLx::Controller::default_stop_handler, + event => SDL::Event->new(), + event_handlers => [], + move_handlers => [], + show_handlers => [], + before_pause => sub {}, + after_pause => sub {}, + time => 0, + ); + +Initializes SDL with L, +creates the root window with L, +initializes an L belonging to the app, +and performs many other app management tasks all as specified by named parameters. +Returns an L of the new app. + +The complete set of parameters are shown in the code above and explained in detail below. +When constructing the app's L all parameters specified are also given to +L<< SDLx::Controller->new|SDLx::Controller/new >>, so should be specified here. See +L. + +=over + +=item width + +The window width, in pixels. Defaults to 640. Alias: C. + +=item height + +The window height, in pixels. Defaults to 480. Alias: C. + +=item depth + +The surface's color depth, in bits per pixel. Should be 8, 16, 24 or 32. +If not defined, defaults to 32 and specifies the +L flag. Alias: C. + +=item title + +The window's title, as a string. Defaults to the L if defined, or the file name. +Alias: C. + +=item icon_title + +The application's icon title, as a string. Defaults to the L if defined, or the file name. +This will only have an effect under certain operating systems. + +=item icon + +The application's icon. Set with the L method. + +=item icon_alpha_key + +You can optionally use this when specifying the C parameter to set its color key (transparent pixel). +Alias: C. + +=item init + +The SDL subsystems to initialize, as a product of the L or an array ref. +The video subsystem is initialized no matter what, and does not need to be specified. +The specified value is passed to L, so see that for more details. +Defaults to L. Alias: C. + +=item flags + +L to specify when calling +L. +Flags should be bitwise I together when passing more than one (C FOO|BAR>). +All flags have a corresponding named parameter which can be used instead of specifying them here, +and are explained below. +Defaults to no flags, or to L if the C parameter was undefined. +Alias: C. -=over 4 +=item sw_surface -=item * title -the window title. Defaults to the file name. Shorter alias: 't' +The L flag, as a boolean. If true, creates the surface in +system memory. This is best used when you plan to do per-pixel manipulations, +or blit surfaces with alpha channels. Aliases: C, C. -=item * icon_title -the icon title. Defaults to file name. Shortcut: 'it' +=item hw_surface -=item * icon -the icon itself. Defaults to none. Shortcut: 'i' +The L flag, as a boolean. If true, creates the surface in +video memory. This is best used when the surfaces you'll be blitting are also hardware surfaces. +SDL copies the surfaces from video memory to system memory when you L them, +and back when you L them, which can cause a major performance hit. +If the video driver does not support hardware surfaces, a software surface will be returned instead. +Many platforms can only provide hardware surfaces when using L. +Aliases: C, C. -=item * width -Window width, in pixels. Defaults to 800. Shortcut: 'w' +=item async_blit -=item * height -Window height, in pixels. Defaults to 600. Shortcut: 'h' +The L flag, as a boolean. If true, enables the use of asynchronous updates +of the display surface. This will usually slow down blitting on single-CPU machines, but can speed up blitting +on multi-CPU machines. Alias: C. -=item * depth -Screen depth. Defaults to 16. Shortcut: 'd'. +=item any_format -=item * flags -Any flags you want to pass to L upon initialization. Defaults to SDL_ANYFORMAT. Flags should be I together if you're passing more than one (flags => FOO|BAR). Shortcut: 'f'. +The L flag, as a boolean. If a video surface of the requested +bits-per-pixel (bpp) is not available SDL will normally emulate one with a shadow surface. +Passing a true value prevents this and causes SDL to use the video surface, regardless of its pixel depth. +This flag is specified automatically when the L parameter is undefined. -=item * resizeable -Set this to a true value to make the window resizeable by the user. Default is off. +=item hw_palette -=item * exit_on_quit -Set this to a true value to make the app exit if a SDL_QUIT event is triggered. Shortcut: 'eoq'. +The L flag, as a boolean. If true, gives SDL exclusive palette access. +Without this flag you may not always get the exact colors you request with +L or L. +Alias: C. + +=item double_buf + +The L flag, as a boolean. If true, enables hardware double buffering; +faster, but only valid with a hardware surface. L should be used to flip the buffers +and update the screen. All drawing will take place on the surface that is not being displayed. +If double buffering could not be enabled then L will just perform an +L on the entire screen. Aliases: C, C. + +=item fullscreen + +The L flag, as a boolean. If true, SDL will attempt to use a fullscreen mode, +changing the hardware resolution to the resolution of the display surface. +If, for whatever reason, this change is not possible the next higher resolution will be used +and the display surface centered on a black background. Aliases: C, C. + +=item open_gl + +The L flag, as a boolean. If true, creates an OpenGL rendering context. +This uses any C attributes specified and any others set with L. Aliases: C, C. + +=item resizable + +The L flag, as a boolean. If true, creates a resizable window. +When the window is resized by the user a L event +is generated and L should be called with the new size. + +=item no_frame + +The L flag, as a boolean. If true, SDL attempts to create a window +with no title bar or frame decoration. Fullscreen modes automatically have this flag set. + +=item centered + +A boolean value. If true, creates the window centered on the screen. +SDL does this with the C environment variable which is set using C<$ENV{SDL_VIDEO_CENTERED}>. +Alias: C
. + +=item position + +The position of the window on the screen, as an array ref. The array ref should be two elements long, +specifying C and C values, in pixels, used to position the window on the screen. +Implemented using C<$ENV{SDL_VIDEO_WINDOW_POS}>. Alias: C. + +=item hide_cursor + +A boolean value. If true, hides the cursor on the video surface using L. +A surface can then instead be blitted to the display at the location of the cursor. +Alias: C. + +=item grab_input + +A boolean value. If true, SDL attempts to confine the cursor to the window using L. +Also, nearly all keyboard input will be passed directly to the application, +and not interpreted by any window manager present. + +=item no_controller + +A boolean value. If true, does not initialize an L for the app. +Care should then be taken to not use any of Ls methods. + +=item stash + +A place to store any information you need the app to hold. This can then be returned and set with +L. If not specified, defaults to an empty hash ref. =back -=head1 METHODS +=head2 init -=head2 title() + SDLx::App->init( SDL::SDL_INIT_TIMER | SDL::SDL_INIT_AUDIO | ... ); + SDLx::App->init( [ 'timer', 'audio', 'video', 'cd_rom', 'cdrom', 'joystick', + 'everything', 'all', 'no_parachute', 'event_thread' ] ); -=head2 title( $new_title ) +This is used internally by L to init SDL with +L. If any subsystems are already initialized, it will use +L instead. You should use this whenever you need to +init anything outside calls to L, as it will always do what you want. -=head2 title( $window_title, $icon_title ) +If a number is specified, it will initialize SDL in the same way as L describes. +If an array ref is specified, each element should be a string corresponding to a flag to specify. +The strings and their corresponding flags are shown in the table below. See L for +descriptions of what each flag does. -C takes 0, 1, or 2 arguments. If no parameter is given, -it returns the current application window title. If one parameter is -passed, both the window title and icon title will be set to its value. -If two parameters are passed the window title will be set to the first, -and the icon title to the second. + flag string alias + ==================== ============ ====== + SDL_INIT_TIMER timer + SDL_INIT_AUDIO audio + SDL_INIT_VIDEO video + SDL_INIT_CDROM cd_rom cdrom + SDL_INIT_JOYSTICK joystick + SDL_INIT_EVERYTHING everything all + SDL_INIT_NOPARACHUTE no_parachute + SDL_INIT_EVENTTHREAD event_thread -=head2 delay( $ms ) +=head2 screen_size -C takes 1 argument, and will sleep the application for -that many ms. + my ($screen_w, $screen_h, $screen_d) = SDLx::App->screen_size(); -=head2 ticks +Returns the width, height and depth of the user's screen using +L. +This can be called before or after calling L. +Initializing the video subsystem will be handled correctly no matter what thanks to +L. -C returns the number of ms since the application began. +=head2 set_video_mode -=head2 error + my $app = SDLx::App->set_video_mode( $w, $h, $d, $f ); + $app->set_video_mode( $w, $h, $d, $f ); + +The first form is used internally by L to create the new SDL display surface. +The second form can be used to change the video mode of an existing app. +See L for a description on what the +four arguments do. -C returns the last error message set by the SDL. +=head2 resize -=head2 resize( $width, $height ) + $app->resize( $w, $h ); -C takes a new width and height of the application. Only -works if the application was originally created with the resizable option. +Resizes the app to the specified width and height. The surface's depth and flags will remain the same. =head2 fullscreen -C toggles the application in and out of fullscreen mode. + $app->fullscreen(); + +Toggles the app in and out of fullscreen mode in a cross-platform-friendly way. +Returns false if the app fails to go fullscreen for some reason. Otherwise, returns true. =head2 iconify -C iconifies the application window. + $app->iconify(); -=head2 grab_input( $CONSTANT ) +Attempts to minimize the window with L. +The exact behavior depends on the operating system. -C can be used to change the input focus behavior of -the application. It takes one argument, which should be one of the following: +=head2 title -=over 4 + my ( $title, $icon_title ) = $app->title(); + $app->title( $title, $icon_title ); -=item * SDL_GRAB_QUERY +If no arguments are specified, returns a list of the title and the icon title. +If arguments are specified, the titles will be set instead. Specify undef to keep the title or +icon title the same, or a string to modify them. -=item * SDL_GRAB_ON +=head2 icon -=item * SDL_GRAB_OFF + SDLx::App->icon( $filename, $color ); + SDLx::App->icon( $surface, $color ); -=back +Sets the window's icon. +This must be called before creating the display surface, so SDL::Image can not be used. +If a filename is specified, it is loaded with L. +Otherwise, the first argument should be a surface. Win32 icons must be 32x32. +The C<$color> argument is optional and, if specified, is used to set the icon's color key (transparent pixel). +It should be an RGB color as either a number or array ref. -=head2 sync +=head2 error -C encapsulates the various methods of syncronizing the screen with the -current video buffer. C will do a fullscreen update, using the double buffer -or OpenGL buffer if applicable. This is prefered to calling flip on the application window. + my $error = $app->error(); + $app->error( @error ); + $app->error( undef ); -=head2 attribute( $attr ) +With no arguments, returns the current SDL error using L. +With one or more arguments, sets the SDL error to the C formatted string. +With C as the one and only argument, clears the SDL error. This can be used +when you are done with the error. -=head2 attribute( $attr, $value ) +=head2 warp_cursor -C allows one to get and set GL attributes. By passing a value -in addition to the attribute selector, the value will be set. C -always returns the current value of the given attribute, or Carp::confesss on failure. + $app->warp_cursor( $x, $y ); -=head1 CALLBACKS +Moves the cursor to the specified coordinates on the application window. If an argument +is not specified, it will default to 0. -C is a C. Use the event, show and handlers to run the app. +=head2 show_cursor - use SDL; - use SDLx::App; - - use SDL::Event; #Where ever the event call back is processed + my $is_cursor_shown = $app->show_cursor(); + $app->show_cursor( $show ); - my $app = SDLx::App->new( width => 200, height => 200); +With no arguments, returns a value that will be true if the cursor +is currently being shown or false otherwise. With an argument, the cursor will be +shown if it is true or hidden otherwise. - $app->add_event_handler( sub{ return 0 if $_[0]->type == SDL_QUIT; return 1}); +=head2 grab_input - $app->add_show_handler( sub{ $app->update() } ); + my $is_grabbing_input = $app->grab_input(); + $app->grab_input( $grab ); - $app->add_move_handler( - sub{ - #calc your physics here - } ); +Grab input attempts to confine the cursor to the window. +Also, nearly all keyboard input will be passed directly to the application, +and not interpreted by any window manager present. +If no arguments are specified, returns a boolean that will be true if +grab input is on or false if it is off. If an argument is specified, grab input will be turned on +if it is true or off otherwise. + +=head2 sync + + $app->sync(); + +Swaps the OpenGL buffers and does a full update of the screen with +L if OpenGL is being used. +This is preferable to swapping the SDL buffers. Otherwise, just swaps the SDL buffers using L. + +=head2 gl_attribute - $app->run(); + my $value = $app->( $attribute ); + $app->gl_attribute( $attribute, $value ); -see L for more details. +With one argument, returns the value of the specified attribute using L. With a value argument, sets the specified attribute to the specified value using L. +The attribute argument should be one of the L. +See L for more details. =head1 AUTHORS @@ -181,6 +439,6 @@ See L. =head1 SEE ALSO -L L L L +L, L, L, L, L =cut diff --git a/lib/pods/SDLx/Controller.pod b/lib/pods/SDLx/Controller.pod index 19fdec8e..50464d8a 100644 --- a/lib/pods/SDLx/Controller.pod +++ b/lib/pods/SDLx/Controller.pod @@ -1,4 +1,3 @@ - =head1 NAME SDLx::Controller - Handles the loops for events, movement and rendering @@ -13,8 +12,8 @@ Extension, Controller # create our controller object my $app = SDLx::Controller->new; - - # we could also do: + + # but we usually do: my $app = SDLx::App->new; # because App is also a controller @@ -32,246 +31,490 @@ The core of an SDL application/game is the main loop, where you handle events and display your elements on the screen until something signals the end of the program. This usually goes in the form of: - while (1) { - ... - } + while (1) { + ... + } -The problem most developers face, besides the repetitive work, is to ensure +The problem most developers face, besides the repetitive work, is ensuring that the screen update is independent of the frame rate. Otherwise, your game will -run at different speeds on different machines and this is never good (old +run at different speeds on different machines, which is never a good thing (old MS-DOS games, anyone?). -One way to circumveint this is by capping the frame rate so it's the same no +One way to circumvent this is by capping the frame rate so it's the same no matter what, but this is not the right way to do it as it penalizes better hardware. This module provides an industry-proven standard for frame independent movement. It calls the movement handlers based on time (hi-res seconds) rather -than frame rate. You can add/remove handlers and control your main loop with -ease. +than frame rate. You can add/remove these handlers and control your main loop with +ease. This module also provides methods for your other timing needs, +such as pausing the game. =head1 METHODS =head2 new SDLx::Controller->new( - dt => 0.5, - min_t => 0, - event => $event_object, + dt => 0.05, + min_t => 0, + max_t => 1e9999, + delay => 1 / 200, + event_handlers => [ @event_callbacks ], + move_handlers => [ @move_callbacks ], + show_handlers => [ @show_callbacks ], + stop_handler => \&stop_handler, + event => $event, + time => 99, ); -The C
parameter specifies the length, in seconds, of a full movement step, and defaults to 0.1. -The C
can be anything and the game can still look the same. -It is only when you change the C
without changing all the things in the movement step that are being multiplied by the first move argument that it will make a difference. +Creates and returns a new controller object with the specified params. +All params are optional and have sane defaults. + +=over + +=item dt + +The time, in seconds, of a full movement step. Defaults to 0.1. +In most cases, the C
could be set to any number and the game could run almost identically +(except for floating-point precision differences). This is because B is an enforcement of the maximum time +between calling movement handlers>. The actual time between calling move handlers may be much less, as the movement handlers +are called at least once per frame. The specifics of this are explained in L. + +Usually you wouldn't need this value to be lower than the time it takes an average +computer to complete a cycle and render the frame. When you do need to run multiple move handlers per frame though, +such as if you were checking collision between fast-moving objects, you can set the C
to some low value +(less than 1/60). Otherwise, leaving it at 0.1 is fine. + +Regardless of whether you need to enforce a maximum time between move handlers, this system has its benefits. +Modifying the C
without touching any of the other code in your program will result in a time-scaling effect. If you lower the C
, everything will move faster than it did with it set higher, and vice-versa. -This is useful to add slo-mo and fast-forward features to the game, all you would have to do is change the C
. +This is useful to add slo-mo and fast-forward features to the game. All you would have to do is change the C
. -C specifies the minimum time, in seconds, that has to accumulate before any move or show handlers are called, and defaults to 1 / 60. -Having the C at 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second. -A "V-Sync" such as this is necessary to prevent video "tear", which occurs when the app is updating faster than the monitor can display. -Setting it to 0, as seen above, will let the app run as fast as it possibly can. +=item min_t -C specifies a loop delay in millisecs to place on the controller loop. B Picking a good delay based on the needs can help reduce CPU load and pressure. +The minimum time, in seconds, that has to accumulate before any move or show handlers are called. Defaults to 1 / 60. +A C of 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second. +A "V-Sync" such as this is necessary to prevent video "tear", which occurs when the app is updating faster than the monitor +can display. Setting it to 0, as seen above, will not delay the loop at all. -C is a SDL::Event object that events going to the event callbacks are polled in to. It defaults to C<< SDL::Event->new() >>. +=item max_t -All parameters are optional. +The maximum time, in seconds, that the movement handlers are allowed to handle in a single cycle of the run loop. +If more time has passed since the last cycle, this time will not be handled and the game will slow down. +This is to protect against the slippery slope effect that happens when lag causes more movement handlers to be called +which, in turn, causes more lag. Setting C to the same value as C
guarantees that movement handlers will each +only be called once per frame. Defaults to 0.1, meaning the game will slow down if it is running at lower than 10 FPS. +Setting it to 1e9999 (or infinity), as seen above, will disable this action. -Returns the new object. +=item delay -=head2 run +The time, in seconds or milliseconds, to delay after every full L loop. Defaults to 0. +If you specify a number greater than or equal to 1, it will be treated as milliseconds instead of seconds. +B Picking an appropriate delay based on the needs of your game can greatly reduce CPU load. -After creating and setting up your handlers (see below), call this method to -activate the main loop. The main loop will run until C is called. +=item event_handlers -All hooked functions will be called during the main loop, in this order: +=item move_handlers -=over 4 +=item show_handlers -=item 1. Events +An array ref of the corresponding handler callbacks. All default to []. +This is basically a shortcut way of adding handlers. +They would otherwise be added with their corresponding C method. +See below for a full explanation of the L loop and handlers. -=item 2. Movements +=item stop_handler -=item 3. Displaying +An extra, but separate, event callback to handle all L of the app. +It is the same in almost every aspect to an event handler (see L): same received arguments, +called in the same place. + +One difference is that it is called in L so that the app can be stopped while paused. +Another difference is that it should always apply to the app; while you add, remove and clear handlers, +it won't be touched. This is good, because you'd (probably) always want your app to able to be stopped. +Because of this, it's a good idea to use the stop handler regardless of whether you will be using L. + +Defaults to C<\&SDLx::Controller::default_stop_handler>: a callback that L the event loop on an C event. +Specify a code ref to use a different callback to handle stopping, or a false value to not use a stop handler. +If you want to provide your own stop handler, you should give it the code of the default stop handler: + + my ($event, $self) = @_; + $self->stop() if $event->type == SDL_QUIT; + +followed by any other code to handle events also triggering the app to stop, such as the user pressing Esc. + +=item event + +The L object that events going to the event callbacks are L in to. +Defaults to C<< SDL::Event->new() >>. + +=item time + +The time, in seconds, that you want the L loop to say it has been going for. +This has no effect on the run loop. All it will do is alter what L returns. See L. +Defaults to 0. You'll seldom have to set this param. =back -Please refer to each handler below for information on received arguments. -Note that the second argument every callback recieves is the C object. +=head2 run -=head2 stop + $app->run; -Returns from the C loop. +After creating and setting up your handlers (see below), call this method to enter the main loop. +This loop will run until L is called. -=head2 pause +All added handlers will be called during the run loop, in this order: -Attempts to pause the application with a call to C. See L. +=over -Takes 1 argument which is a callback. The application waits for the next event with C. -When one is recieved, it is passed to the callback as the first argument, along with the C object as the second argument. -If the callback then returns a true value, C will return. -If the callback returns a false value, C will repeat the process. +=item 1. Events -This can be used to easily implement a pause when the app loses focus: +=item 2. Movements - sub window { - my ($e, $app) = @_; - if($e->type == SDL_QUIT) { - $app->stop; - # quit handling is here so that the app - # can be stopped while paused - } - elsif($e->type == SDL_ACTIVEEVENT) { - if($e->active_state & SDL_APPINPUTFOCUS) { - if($e->active_gain) { - return 1; - } - else { - $app->pause(\&window); - # recursive, but only once since the window - # can't lose focus again without gaining it first - } - } - } - return 0; - } +=item 3. Displaying -Note: if you implement your own pause function, remember to update C to the current time when the application unpauses. -This should be done with C. -Otherwise, time will accumulate while the application is paused, and many movement steps will be called all at once when it unpauses. +=back -Note 2: a pause will be potentially dangerous to the C cycle (even if you implement your own) unless called by an C callback. +Please refer to each handler below for full information on what they do. +Note that the second argument every callback receives is the app object. -=head2 paused +=head2 add_event_handler -Returns 1 if the app is paused, undef otherwise. -This is only useful when used within code that will be run by C: - - sub pause { - # press P to toggle pause - - my ($e, $app) = @_; - if($e->type == SDL_QUIT) { - $app->stop; - # quit handling is here so that the app - # can be stopped while paused - } - elsif($e->type == SDL_KEYDOWN) { - if($e->key_sym == SDLK_p) { - # We're paused, so end pause - return 1 if $app->paused; - - # We're not paused, so pause - $app->pause(\&pause); - } + my $index = $app->add_event_handler( + sub { + my ($event, $app) = @_; + # handle event ... } - return 0; - } + ); -=head2 add_event_handler +Adds a callback to the end of the event handler list. You can add as many subs as you need. For each L from the user, all registered callbacks will be called in order and supplied with it. +Returns the index of the added callback. -Register a callback to handle events. You can add as many subs as you need. -Whenever a SDL::Event occurs, all registered callbacks will be triggered in -order. Returns the order queue number of the added callback. +More specifically: events from the user will, one by one, be L into the app's L object. This event will then be passed to all of the registered callbacks as the first argument. The second argument is the app. -The first argument passed to registered callbacks is the L<< SDL::Event >> object. -The second is the C object. +Below is an example of an event handler that sets a variable to true when the left mouse button is pressed, and back to false when it is lifted. - sub stop { - my ($event, $app) = @_; - if($event->type == SDL_QUIT) { - $app->stop; - } + our $click = 0; + + sub on_click { + my ($event, $app) = @_; + my $state = + $event->type == SDL_MOUSEBUTTONDOWN ? 1 : + $event->type == SDL_MOUSEBUTTONUP ? 0 : undef + ; + return unless defined $state; # not a mouse click + + if($event->button_button == SDL_BUTTON_LEFT) { + $click = $state; + } } - $app->add_event_handler(\&stop); + $app->add_event_handler(\&on_click); + +For full details on the event object passed to the event handlers, see L. +For other event related functions and a full list of the event constants, see L. =head2 add_move_handler -Register a callback to update your objects. You can add as many subs as -you need. Returns the order queue number of the added callback. + my $index = $app->add_move_handler( + sub { + my ($step, $app, $time) = @_; + # handle moving ... + } + ); +Adds a callback to the end of the movement handler list. +You can add as many subs as you need. All registered callbacks will be triggered in order for as many C
as have happened between calls, -and once more for any remaining time less than C
. -The first argument passed to the callbacks is the portion of the step, which will be 1 for a full step, and less than 1 for a partial step. -Movement values should be multiplied by this value. -The full steps correspond to the amount of C
passed between calls, and the partial step corresponds to the call with the remaining time less than C
. -The argument can be 0 if no time has passed since the last cycle. If you need to protect against this, set a C, or put a C<< return unless $_[0] >> at the start of every move handler. +and once more for the remaining time less than C
. +A reasonable C
for a game will usually be a number greater than +the time you would ever expect to have passed between frames. This means that your movement handlers will ordinarily +only be called once per frame. See the discussion of C
in L. +Returns the index of the added callback. + +The first argument passed to the callbacks is the fraction of C
time that the move callback should handle. +This will be 1 for a full step and less than 1 for a partial step. +Inversely, the time that each move callback should handle is equal to the step argument multiplied by the C
. +All movement values should be multiplied by the step value. + +It is possible for the argument to be 0 if no time has passed since the last cycle. +It's best to protect against this by supplying the app a small L value. + +The second argument passed to the callbacks is the app object. -The second argument passed to the callbacks is the C object. -The third is the total amount of time passed since the call of C. +The third is the value returned by L. See L. You should use these handlers to update your in-game objects, check collisions, etc. -so you can check and/or update it as necessary. +Below is an example of how you might move an object. Note that the movement value, a velocity in this case, +is multiplied by the step argument. + + our $ball = MyBall->new; sub move_ball { my ($step, $app, $t) = @_; $ball->move_x( $ball->x_vel * $step ); $ball->move_y( $ball->y_vel * $step ); } + $app->add_move_handler(\&move_ball); =head2 add_show_handler -Register a callback to render objects. You can add as many subs as you need. -Returns the order queue number of the added callback. -All registered callbacks will be triggered in order, once per run of the C loop. + my $index = $app->add_show_handler( + sub { + my ($delta, $app) = @_; + # handle showing ... + } + ); + +Adds a callback to the end of the rendering handler list. +You can add as many subs as you need. +All registered callbacks will be triggered in order, once per cycle of the L loop. +Returns the index of the added callback. -The first argument passed is the time, in seconds, since the previous call. -The second is the C object. +The first argument passed is the time, in seconds, since the previous show. +This can be used to display a rough FPS value by dividing 1 by it. + +The second argument is the app object. + + our $ball = MyBall->new; sub show_ball { my ($delta, $app) = @_; - $app->draw_rect( - [ $ball->x, $ball->y, $ball->size, $ball->size ], - $ball->colour + + # the drawing below works if the app is an SDLx::App + # and not just a controller + $app->draw_circle_filled( + [ $ball->x, $ball->y ], $ball->radius, + $ball->color ); } + $app->add_show_handler(\&show_ball); + +=head2 event_handlers + +=head2 move_handlers + +=head2 show_handlers + + my $event_handlers = $app->event_handlers; + my $move_handlers = $app->move_handlers; + my $show_handlers = $app->show_handlers; + +Returns the corresponding array ref so that you can directly modify the handler list. -=head2 remove_move_handler( $index ) +=head2 remove_event_handler -=head2 remove_event_handler( $index ) +=head2 remove_move_handler -=head2 remove_show_handler( $index ) +=head2 remove_show_handler -Removes the handler with the given index from the respective calling queue. + my $removed_handler = $app->remove_event_handler( $index ); + my $removed_handler = $app->remove_event_handler( $callback ); + my $removed_handler = $app->remove_move_handler( $index ); + my $removed_handler = $app->remove_move_handler( $callback ); + my $removed_handler = $app->remove_show_handler( $index ); + my $removed_handler = $app->remove_show_handler( $callback ); + +Removes the handler with the given index from the respective handler list. You can also pass a coderef. -The first coderef in the handler list that this matches will be removed. +The first coderef in the handler list that matches this will be removed. Returns the removed handler. -=head2 remove_all_move_handlers - =head2 remove_all_event_handlers +=head2 remove_all_move_handlers + =head2 remove_all_show_handlers -Removes all handlers from the respective calling queue. + $app->remove_all_event_handlers(); + $app->remove_all_move_handlers(); + $app->remove_all_show_handlers(); + +Removes all handlers from the respective handler list. None of these will remove the app's L. =head2 remove_all_handlers -Quick access to removing all handlers at once. + $app->remove_all_handlers(); + +Shortcut to remove all handlers at once. This will not remove the app's L. + +=head2 stop + + $app->stop; + +Tells the controller to end the run loop. This only has meaning when called from within a +handler of the run loop. The L loop will complete the current cycle +(handling events, moves and shows) and then return. This graceful way of ending the game loop +is preferred and it is the way the default L does it. + +Once the L loop has been stopped, it can be started again without problems. +This technique should be used to do operations that take a long time outside of the timing of the app. + + $app->run; + + do_something_that_takes_a_long_time(); + + $app->run; + +This code snippet could be used to play the first part of a game, then load the next part +and resume playing. When the first run loop is stopped, the expensive operation will be executed. +Once that has completed, the second run loop will resume the game, ignoring the time that passed outside the run loop. +If the expensive operation was performed from within the run loop, +upon completing the operation the move handlers would take into account all the time passed. + +=head2 stopped + + my $stopped = $app->stopped; + +Returns true if the run loop is stopped (before and after being in the run loop). +Also returns true when the run loop is about to stop. +That is, true when the app will complete the current run cycle before stopping. + +=head2 pause + + $app->pause( + sub { + my ($event, $app) = @_; + # handle event ... + + return 1 if ... ; # unpause + return; # stay paused + } + ); + +Pauses the application with a call to C. This only has meaning when called +from within a handler of the run loop. Events can then be used to +unpause the app. This is done outside the timing of the app with the same technique as explained in L. + +Takes one argument, which is a callback. The application completes the current run loop, then starts waiting +for the next event with L. This means that C can be called by any kind of handler +in the run loop. If L is called during the same run cycle, before or after calling C, +the app will just stop instead of pausing. + +When L receives an event, it is passed to the callback as the first argument. +Just like an event handler, the second argument passed is the app. +If the callback then returns a true value, C will return. +If the callback returns a false value, the app will stay paused and the process will be repeated. + +If a L is defined, then each event will also be passed to that. This will allow the app to be stopped +while being paused. If the stop handler calls L, then the app will unpause and then stop. +If your app doesn't have a stop handler, then you'll have to handle stopping yourself in the pause callback. +The app will also unpause if the callback calls L, regardless of whether the callback then returns true or false. + +Below is an example of C used to implement a pause and unpause when the app loses and gains focus. +As a neat shortcut, the callback is recursively defined and used as both an event handler and the pause callback. + + sub window { + my ($event, $app) = @_; + if($event->type == SDL_ACTIVEEVENT) { + if($event->active_state & SDL_APPINPUTFOCUS) { + if($event->active_gain) { # gained focus + return 1; # unpause + } + else { + $app->pause(\&window); + # recursive, but only once since the window + # can't lose focus again without gaining it first + } + } + } + return; + } + $app->add_event_handler(\&window); + +=head2 paused + + my $paused = $app->paused; + +Returns true if the run loop is currently paused. Also returns true when the run loop is about to pause. +That is, true when the app will complete the current run cycle before pausing. + +Both of these cases can be useful for handling pausing. Being able to tell if the app is currently paused is useful +from within the L callback: + + sub toggle_pause { # press P to toggle pause + my ($event, $app) = @_; + if($event->type == SDL_KEYDOWN) { + if($event->key_sym == SDLK_p) { + # We're paused, so end pause + return 1 if $app->paused; + + # We're not paused, so pause + $app->pause(\&toggle_pause); + } + } + return; + } + $app->add_event_handler(\&toggle_pause); + +Knowing if the app is about to pause is useful from within the app's handlers. If L is called from within +an event handler, then the move and show handlers can check and respond to L in the remainder of the run cycle. +In this time, both C and L will return true. When the app is actually paused, only C will return true. +This true value is actually the callback you passed with L, and can be checked to tell between different pauses. +For example, a show handler could make the screen say PAUSED when L is true. This is preferred to having the +event handler display this, because L could be called in the meantime. =head2 dt =head2 min_t -=head2 current_time +=head2 delay -If an argument is passed, modifies the corresponding value to the argument. -C
and C will keep their old value until the beginning of the next C cycle. +=head2 stop_handler + +=head2 event + + my $dt = $app->dt; + my $min_t = $app->min_t; + my $max_t = $app->max_t; + my $delay = $app->delay; + my $stop_handler = $app->stop_handler; + my $event = $app->event; + $app->dt ($dt); + $app->min_t ($min_t); + $app->max_t ($max_t); + $app->delay ($delay); + $app->stop_handler($stop_handler); + $app->event ($event); + +If an argument is passed, modifies the corresponding parameter to the argument. +For each of these parameters the L loop will give the handlers its old value until the start of the next cycle. +The L callback, however, will always receive the new value. +See L for details on what these params do. Returns the corresponding value. +=head2 time + + my $time = $app->time; + $app->time($time); + +Returns the sum of all the C
s that have been handled by all move handlers. In other words, the total amount of time +that has passed in the run loop. When the run loop is L and resumed, this value is not reset. +This should be a useful value to have, but isn't a replacement for L. +Use L instead of L. + +Specify a value to count from that time. This will have no effect on the run loop itself, but may be useful for +the code in your handlers. + +=head2 sleep + + $app->sleep($time); + +Causes the app to sleep for the specified time, in hi-res seconds, or forever if no argument is specified. +Use this instead of L. + =head1 AUTHORS See L. -=head2 ACKNOWLEGDEMENTS +=head2 ACKNOWLEDGEMENTS -The idea and base for this module comes from Lazy Foo's L<< Frame Independent +The idea and base for the L loop comes from Lazy Foo's L<< Frame Independent Movement|http://www.lazyfoo.net/SDL_tutorials/lesson32/index.php >> tutorial, and Glenn Fiedler's L<< Fix Your Timestep|http://gafferongames.com/game-physics/fix-your-timestep/ >> article on timing. +=head1 SEE ALSO - - +L, L, L diff --git a/lib/pods/SDLx/Controller/Interface.pod b/lib/pods/SDLx/Controller/Interface.pod index 5782d686..9e65d456 100644 --- a/lib/pods/SDLx/Controller/Interface.pod +++ b/lib/pods/SDLx/Controller/Interface.pod @@ -49,7 +49,7 @@ Extension, Controller =head2 set_acceleration -Allows you to set the acceleration callback for defining the inferface's +Allows you to set the acceleration callback for defining the interface's behaviour in terms of x,y and rotation. $interface->set_acceleration ( @@ -60,7 +60,7 @@ behaviour in terms of x,y and rotation. } ); -These accelerations are arbitary and can be set to any frame of reference. +These accelerations are arbitrary and can be set to any frame of reference. Your render callback will handle how to interpret it. The callback will receive the time and the current state as a @@ -115,7 +115,7 @@ Interpolate the current state =head2 evaluate -Evaluate the new currrent and previous state. +Evaluate the new current and previous state. =head2 update diff --git a/lib/pods/SDLx/Layer.pod b/lib/pods/SDLx/Layer.pod index 682dc7ee..10dfd682 100644 --- a/lib/pods/SDLx/Layer.pod +++ b/lib/pods/SDLx/Layer.pod @@ -52,7 +52,7 @@ The layer object just pass it through. my $index = $layer->index; -The method C represents the z-index ot this layer within its layermanager. +The method C represents the z-index of this layer within its layermanager. =head2 x @@ -87,7 +87,7 @@ B: SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos ); -This method let you retrive the current or set a new surface. +This method let you retrieve the current or set a new surface. =head2 pos @@ -150,13 +150,13 @@ B: The z-index is not changed for the given layer. $layer->detach_xy( $x, $y ); -C detaches the prevously attached layer to the given coords. The upper left corner of this layer will be at C<$x> and C<$y>. +C detaches the previously attached layer to the given coords. The upper left corner of this layer will be at C<$x> and C<$y>. =head2 foreground $layer->foreground; -This method moves the given layer to the foreground so that it is blittet on top of the other layers. +This method moves the given layer to the foreground so that it is blitted on top of the other layers. =head1 BUGS diff --git a/lib/pods/SDLx/LayerManager.pod b/lib/pods/SDLx/LayerManager.pod index 1326e836..7168c56d 100644 --- a/lib/pods/SDLx/LayerManager.pod +++ b/lib/pods/SDLx/LayerManager.pod @@ -66,7 +66,7 @@ The method C returns all layers that were added before. my $layer = $layermanager->layer( $index ); -To obtain only one layer at index C<$index> use this function. C<$index> ranges from C<0> to C. +To obtain only one layer at index C<$index> use this function. C<$index> ranges from C<0> to C. =head2 length @@ -121,21 +121,21 @@ B: The z-index is not changed for the given layers. $layermanager->detach_xy( $x, $y ); -C detaches the prevously attached layers to the given coords. The upper left corner of the backmost layer will be at C<$x> and C<$y>. +C detaches the previously attached layers to the given coords. The upper left corner of the backmost layer will be at C<$x> and C<$y>. The other layers are positioned relative to the backmost layer just like before. =head2 detach_back $layermanager->detach_back( ); -C detaches the prevously attached layers back to the position where they were attached. +C detaches the previously attached layers back to the position where they were attached. =head2 foreground $layermanager->foreground( $layer ); $layermanager->foreground( @layers ); -This method moves the given layer(s) to the foreground so that they are blittet on top of the other layers. +This method moves the given layer(s) to the foreground so that they are blitted on top of the other layers. =head1 BUGS diff --git a/lib/pods/SDLx/Music.pod b/lib/pods/SDLx/Music.pod index 5b065e06..9715bdec 100644 --- a/lib/pods/SDLx/Music.pod +++ b/lib/pods/SDLx/Music.pod @@ -130,7 +130,7 @@ B do not mix use of this class with L if you wa -Creates the new music object. Inits audio with a call to L, if it isn't already (if you want more precise control over what is initialized, make sure you call L before you call thiihs method). Creates an empty default data object for object-wide defaults. If arguments are supplied, calls L with them to set up any initial data objects. Returns the new music object. +Creates the new music object. Inits audio with a call to L, if it isn't already (if you want more precise control over what is initialized, make sure you call L before you call this method). Creates an empty default data object for object-wide defaults. If arguments are supplied, calls L with them to set up any initial data objects. Returns the new music object. =head2 data @@ -149,7 +149,7 @@ With a hash of arguments: for each pair, and returns a L. Re $music->data_for( @names_or_data_objects ); -Calls L repeatedly, passing it one element of the list at a time, to initialise mulitiple empty names and/or add data objects. Returns C<$music>. +Calls L repeatedly, passing it one element of the list at a time, to initialise multiple empty names and/or add data objects. Returns C<$music>. =head2 has_data diff --git a/lib/pods/SDLx/Rect.pod b/lib/pods/SDLx/Rect.pod index 0c83af53..b9ace279 100644 --- a/lib/pods/SDLx/Rect.pod +++ b/lib/pods/SDLx/Rect.pod @@ -29,7 +29,7 @@ All C<< SDLx::Rect >> methods that change either position or size of a Rect retu =head2 ATTRIBUTES -All Rect attributes are acessors, meaning you can get them by name, and set them by passing a value: +All Rect attributes are accessors, meaning you can get them by name, and set them by passing a value: $rect->left(15); $rect->left; # 15 @@ -113,7 +113,7 @@ Same as C<> above, but moves the current Rect in place and returns nothing =head3 inflate(x, y) -Grows or shrinks the rectangle. Returns a new Rect with the size changed by the given offset. The rectangle remains centered around its current center. Negative values will return a shrinked rectangle instead. +Grows or shrinks the rectangle. Returns a new Rect with the size changed by the given offset. The rectangle remains centered around its current center. Negative values will return a shrunken rectangle instead. =head3 inflate_ip(x, y) diff --git a/lib/pods/SDLx/Sound.pod b/lib/pods/SDLx/Sound.pod index 09bcbfc2..da1a8e60 100644 --- a/lib/pods/SDLx/Sound.pod +++ b/lib/pods/SDLx/Sound.pod @@ -24,15 +24,15 @@ Extension # more sounds my %files = ( - chanell_01 => "/my_sound1.wav", - chanell_02 => "/my_sound2.ogg" + channel_01 => "/my_sound1.wav", + channel_02 => "/my_sound2.ogg" ); # times sounds bangs my %times = ( - chanell_01 => 0, # start - chanell_01 => 1256, # miliseconds - chanell_02 => 2345 + channel_01 => 0, # start + channel_01 => 1256, # milliseconds + channel_02 => 2345 ); # Load files in channels for realtime play @@ -43,17 +43,17 @@ Extension $snd->play(%times); # play loaded files at times $snd->play; # play again - # plays sound channel_01 at 578 miliseconds from now + # plays sound channel_01 at 578 milliseconds from now $snd->play('channel_01', 578); # fades sound $snd->fade('channel_02', 2345, 3456, -20); - # in a single act do the wole Sound + # in a single act do the whole Sound my $snd = SDLx::Sound->new( files => ( - chanell_01 => "/my_sound1.wav", - chanell_02 => "/my_sound2.ogg" + channel_01 => "/my_sound1.wav", + channel_02 => "/my_sound2.ogg" ), loud => ( @@ -61,19 +61,19 @@ Extension channel_02 => 75 ), times => ( - chanell_01 => 0, # start - chanell_01 => 1256, # miliseconds - chanell_02 => 2345 + channel_01 => 0, # start + channel_01 => 1256, # milliseconds + channel_02 => 2345 ), fade => ( - chanell_02 => [2345, 3456, -20] + channel_02 => [2345, 3456, -20] ) )->play(); =head1 DESCRIPTION -You can think about the SDLx::Sound at 2 aproaches. +You can think about the SDLx::Sound at 2 approaches. =over 4 @@ -83,9 +83,9 @@ You can think about the SDLx::Sound at 2 aproaches. =back -Your application will say what the best aproach. +Your application will say what the best approach. -In a taste that resembles to perl and to SDL, our SDLx:Sound hooks at SDL::Audio and SDL::Mixer with a gracefull and simple interface that can offer to monks a modern perlish way to manage sounds. +In a taste that resembles to perl and to SDL, our SDLx:Sound hooks at SDL::Audio and SDL::Mixer with a graceful and simple interface that can offer to monks a modern perlish way to manage sounds. An SDLx::Sound object can load sounds from filesystem, play it, adjust this loudness level or stops the sound. diff --git a/lib/pods/SDLx/Sprite.pod b/lib/pods/SDLx/Sprite.pod index 91105425..a195b735 100644 --- a/lib/pods/SDLx/Sprite.pod +++ b/lib/pods/SDLx/Sprite.pod @@ -105,7 +105,7 @@ Available options are: =item * image => $filename -Uses $filename as source image for the Sprite's surface. See suported +Uses $filename as source image for the Sprite's surface. See supported formats in L<< SDL::Image >>. This option B be used together with the 'surface' option (see below). diff --git a/lib/pods/SDLx/Sprite/Animated.pod b/lib/pods/SDLx/Sprite/Animated.pod index 143ad5d8..d06b0d65 100644 --- a/lib/pods/SDLx/Sprite/Animated.pod +++ b/lib/pods/SDLx/Sprite/Animated.pod @@ -43,7 +43,7 @@ Extension # just like a regular Sprite, we fetch our source rect from ->clip, # updating it on each call to ->next (or ->previous, or ->reset). - # If source rects for your animation are further appart (or less) + # If source rects for your animation are further apart (or less) # than the rect's width and height, you can adjust the animation # x/y offsets: $animation->step_x(15); diff --git a/lib/pods/SDLx/Surface.pod b/lib/pods/SDLx/Surface.pod index 9b38ba4c..49fb1ea2 100644 --- a/lib/pods/SDLx/Surface.pod +++ b/lib/pods/SDLx/Surface.pod @@ -118,7 +118,7 @@ Returns the new Surface. $sdlx_surface->blit( $dest, $src_rect, $dest_rect ); Blits C onto $dest surface. -$src_rect or $dest_rect are optional. If $src_rect is ommited, it will be the size of the entire surface. If $dest_rect is ommited, +$src_rect or $dest_rect are optional. If $src_rect is omitted, it will be the size of the entire surface. If $dest_rect is omitted, it will be blitted at C<(0, 0)>. $src_rect or $dest_rect can be array refs or C. $dest can be C or C. Note that the final blit rectangle is stored in $dest_rect after clipping is performed. @@ -158,7 +158,7 @@ Returns $self $sdlx_surface->draw_rect( [$x,$y,$w,$h], 0xFFFF00FF ); $sdlx_surface->draw_rect( SDL::Rect->new($x,$y,$w,$h), 0xFFFF00FF ); -Draws a rect on the surface with the given color. If the rect is ommited, the colored rect will be drawn to the entire surface. +Draws a rect on the surface with the given color. If the rect is omitted, the colored rect will be drawn to the entire surface. Returns $self @@ -235,8 +235,7 @@ Returns $self $sdlx_surface->draw_ellipse( [ $x, $y ], $rx, $ry, $color ); Draws an unfilled ellipse centered at C<($x,$y)> with horizontal radius $rx, -vetical radius $ry and $color. -Antialias is turned on if $antialias is true. +vertical radius $ry and $color. Returns $self @@ -245,7 +244,7 @@ Returns $self $sdlx_surface->draw_ellipse_filled( [ $x, $y ], $rx, $ry, $color ); Draws an B ellipse centered at C<($x,$y)> with horizontal radius $rx, -vetical radius $ry and $color. +vertical radius $ry and $color. Antialias is turned on automatically. Returns $self diff --git a/lib/pods/SDLx/Text.pod b/lib/pods/SDLx/Text.pod index d63d0cfc..02ce378e 100644 --- a/lib/pods/SDLx/Text.pod +++ b/lib/pods/SDLx/Text.pod @@ -147,7 +147,7 @@ Sets the font style to italic. Sets the font style to underline. -B: Due to libsdl design and depending on the chosen font, sometimes +B: Due to libSDL design and depending on the chosen font, sometimes the underline may be outside of the generated text surface, and thus not visible when blitted to the screen. In these cases, you should probably turn off the option and draw your own underlines in the target surface. @@ -156,7 +156,7 @@ off the option and draw your own underlines in the target surface. Sets the font style to strikethrough. -B: Due to libsdl design and depending on the chosen font, sometimes +B: Due to libSDL design and depending on the chosen font, sometimes the strikethrough may be outside of the generated text surface, and thus not visible when blitted to the screen. In these cases, you should probably turn off the option and draw your own strikethroughs in the target surface. diff --git a/src/Core/Audio.xs b/src/Core/Audio.xs index c81944bf..c3c8293e 100644 --- a/src/Core/Audio.xs +++ b/src/Core/Audio.xs @@ -13,7 +13,7 @@ MODULE = SDL::Audio PACKAGE = SDL::Audio PREFIX = audio_ int -audio_open ( desired, obtained ) +audio_open( desired, obtained ) SDL_AudioSpec *desired SDL_AudioSpec *obtained CODE: @@ -22,20 +22,20 @@ audio_open ( desired, obtained ) RETVAL void -audio_pause ( pause_on ) +audio_pause( pause_on ) int pause_on CODE: SDL_PauseAudio(pause_on); Uint32 -audio_get_status () +audio_get_status() CODE: RETVAL = SDL_GetAudioStatus (); OUTPUT: RETVAL void -audio_lock () +audio_lock() CODE: SDL_LockAudio(); @@ -45,20 +45,19 @@ audio_unlock () SDL_UnlockAudio(); AV * -audio_load_wav ( filename, spec ) +audio_load_wav( filename, spec ) char *filename SDL_AudioSpec *spec - CODE: - SDL_AudioSpec *temp = safemalloc(sizeof(SDL_AudioSpec)); + PREINIT: + SDL_AudioSpec *temp; Uint8 *buf; Uint32 len; - + CODE: + temp = safemalloc(sizeof(SDL_AudioSpec)); memcpy( temp, spec, sizeof(SDL_AudioSpec) ); temp = SDL_LoadWAV(filename,temp,&buf,&len); - if ( temp == NULL ) - { + if( temp == NULL ) croak("Error in SDL_LoadWAV: %s", SDL_GetError()); - } else { RETVAL = (AV*)sv_2mortal((SV*)newAV()); @@ -70,7 +69,7 @@ audio_load_wav ( filename, spec ) RETVAL void -audio_free_wav ( audio_buf ) +audio_free_wav( audio_buf ) Uint8 *audio_buf CODE: SDL_FreeWAV(audio_buf); @@ -85,27 +84,22 @@ audio_convert( cvt, data, len ) cvt->len = len; memcpy(cvt->buf, data, cvt->len); RETVAL = SDL_ConvertAudio(cvt); - - OUTPUT: RETVAL SV * -audio_audio_driver_name ( ... ) - CODE: +audio_audio_driver_name( ... ) + PREINIT: char buffer[1024]; - if ( SDL_AudioDriverName(buffer, 1024) != NULL ) - { - RETVAL = newSVpv(buffer, 0); - } - else - XSRETURN_UNDEF; + CODE: + if( SDL_AudioDriverName(buffer, 1024) != NULL ) + RETVAL = newSVpv(buffer, 0); + else + XSRETURN_UNDEF; OUTPUT: RETVAL - void -audio_close () +audio_close() CODE: SDL_CloseAudio(); - diff --git a/src/Core/Events.xs b/src/Core/Events.xs index faa7cfe6..17016dd4 100644 --- a/src/Core/Events.xs +++ b/src/Core/Events.xs @@ -109,19 +109,20 @@ AV * events_get_key_state() PREINIT: int value; - CODE: - Uint8* KeyArray = SDL_GetKeyState(&value); - RETVAL = (AV*)sv_2mortal((SV*)newAV()); + PREINIT: + Uint8* KeyArray; int i; - for( i = 0; i +#include void _uinta_free(Uint16* av, int len_from_av_len) { - if( av != NULL) - return; + if( av != NULL ) + return; safefree(av); } @@ -24,18 +25,14 @@ Uint16* av_to_uint16 (AV* av) if( len != -1) { int i; - Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len+1)); + Uint16 *table = (Uint16 *)safemalloc(sizeof(Uint16)*(len+1)); for ( i = 0; i < len+1 ; i++ ) { - SV ** temp = av_fetch(av,i,0); + SV **temp = av_fetch(av,i,0); if( temp != NULL ) - { table[i] = (Uint16) SvIV( *temp ); - } else - { table[i] = 0; - } } return table; } @@ -65,20 +62,17 @@ video_get_video_surface() OUTPUT: RETVAL - SDL_VideoInfo* video_get_video_info() PREINIT: char* CLASS = "SDL::VideoInfo"; CODE: RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo(); - OUTPUT: RETVAL SV * video_video_driver_name( ) - CODE: char buffer[1024]; if ( SDL_VideoDriverName(buffer, 1024) != NULL ) @@ -94,9 +88,9 @@ AV* video_list_modes ( format, flags ) Uint32 flags SDL_PixelFormat *format - - CODE: + PREINIT: SDL_Rect **mode; + CODE: RETVAL = newAV(); sv_2mortal((SV*)RETVAL); mode = SDL_ListModes(format,flags); @@ -106,13 +100,12 @@ video_list_modes ( format, flags ) av_push(RETVAL,newSVpv("none",0)); } else { int i; - for (i=0; mode[i]; ++i) + for( i = 0; mode[i]; ++i ) av_push(RETVAL, cpy2bag( (void *)mode[i], sizeof(SDL_Rect *), sizeof(SDL_Rect), "SDL::Rect" )); } OUTPUT: RETVAL - int video_video_mode_ok ( width, height, bpp, flags ) int width @@ -124,7 +117,6 @@ video_video_mode_ok ( width, height, bpp, flags ) OUTPUT: RETVAL - SDL_Surface * video_set_video_mode ( width, height, bpp, flags ) int width @@ -138,7 +130,6 @@ video_set_video_mode ( width, height, bpp, flags ) OUTPUT: RETVAL - void video_update_rect ( surface, x, y, w ,h ) SDL_Surface *surface @@ -152,20 +143,20 @@ video_update_rect ( surface, x, y, w ,h ) void video_update_rects ( surface, ... ) SDL_Surface *surface - CODE: + PREINIT: SDL_Rect* rects; - int num_rects,i; + int num_rects, i; + CODE: if ( items < 2 ) return; num_rects = items - 1; rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items); for(i=0;iw || !dest_rect->h)) + dest_rect = NULL; RETVAL = SDL_FillRect(dest,dest_rect,pixel); OUTPUT: RETVAL @@ -437,16 +436,16 @@ blit_surface ( src, src_rect_bag, dest, dest_rect_bag ) SDL_Surface *dest SV *src_rect_bag SV *dest_rect_bag + PREINIT: + SDL_Rect *src_rect; + SDL_Rect *dest_rect; CODE: - SDL_Rect *src_rect = NULL; - SDL_Rect *dest_rect = NULL; - + src_rect = NULL; + dest_rect = NULL; if(SvOK(src_rect_bag)) src_rect = (SDL_Rect *)bag2obj(src_rect_bag); - if(SvOK(dest_rect_bag)) dest_rect = (SDL_Rect *)bag2obj(dest_rect_bag); - RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect); OUTPUT: RETVAL @@ -465,8 +464,6 @@ get_clip_rect ( surface, rect ) CODE: SDL_GetClipRect(surface, rect); - - int video_lock_YUV_overlay ( overlay ) SDL_Overlay *overlay @@ -477,9 +474,9 @@ video_lock_YUV_overlay ( overlay ) void video_unlock_YUV_overlay ( overlay ) - SDL_Overlay *overlay - CODE: - SDL_UnlockYUVOverlay(overlay); + SDL_Overlay *overlay + CODE: + SDL_UnlockYUVOverlay(overlay); int video_display_YUV_overlay ( overlay, dstrect ) @@ -490,7 +487,6 @@ video_display_YUV_overlay ( overlay, dstrect ) OUTPUT: RETVAL - int video_GL_load_library ( path ) char *path @@ -514,19 +510,20 @@ video_GL_set_attribute ( attr, value ) CODE: RETVAL = SDL_GL_SetAttribute(attr, value); OUTPUT: - RETVAL + RETVAL AV * video_GL_get_attribute ( attr ) - int attr - CODE: + int attr + PREINIT: int value; + CODE: RETVAL = newAV(); sv_2mortal((SV*)RETVAL); av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value))); av_push(RETVAL,newSViv(value)); OUTPUT: - RETVAL + RETVAL void video_GL_swap_buffers () @@ -542,8 +539,9 @@ video_wm_set_caption ( title, icon ) AV * video_wm_get_caption () + PREINIT: + char *title, *icon; CODE: - char *title,*icon; SDL_WM_GetCaption(&title,&icon); RETVAL = newAV(); sv_2mortal((SV*)RETVAL); @@ -556,7 +554,21 @@ void video_wm_set_icon ( icon ) SDL_Surface *icon CODE: - SDL_WM_SetIcon(icon,NULL); + if (icon && icon->format->BytesPerPixel == 3) { + SDL_PixelFormat* format = SDL_malloc(sizeof(SDL_PixelFormat)); + memcpy(format, icon->format, sizeof(SDL_PixelFormat)); + format->BitsPerPixel = 32; + format->BytesPerPixel = 4; + format->palette = NULL; + + SDL_Surface* new_icon = SDL_ConvertSurface(icon, format, icon->flags); + if (new_icon) { + SDL_WM_SetIcon(new_icon, NULL); + SDL_FreeSurface(new_icon); + } + } + else + SDL_WM_SetIcon(icon, NULL); Uint32 video_wm_grab_input ( mode ) diff --git a/src/Core/objects/AudioSpec.xs b/src/Core/objects/AudioSpec.xs index a5f13673..fe8a1975 100644 --- a/src/Core/objects/AudioSpec.xs +++ b/src/Core/objects/AudioSpec.xs @@ -21,34 +21,38 @@ void audio_callback ( void* data, Uint8 *stream, int len ) { ENTER_TLS_CONTEXT; - dSP; - - char* string = (char*)stream; - - SV* sv = newSVpv("a",1); - SvCUR_set(sv,len * sizeof(Uint8)); - SvLEN_set(sv,len * sizeof(Uint8)); - void* old = SvPVX(sv); - SvPV_set(sv,string); - - ENTER; - SAVETMPS; - PUSHMARK(SP); + { + dSP; + char *string; + SV *sv; + void *old; + string = (char*)stream; + + sv = newSVpv("a",1); + SvCUR_set(sv,len * sizeof(Uint8)); + SvLEN_set(sv,len * sizeof(Uint8)); + old = SvPVX(sv); + SvPV_set(sv,string); + + ENTER; + SAVETMPS; + PUSHMARK(SP); - XPUSHs(sv_2mortal(newSViv(sizeof(Uint8)))); - XPUSHs(sv_2mortal(newSViv(len))); - XPUSHs(sv_2mortal(newRV_inc(sv))); + XPUSHs(sv_2mortal(newSViv(sizeof(Uint8)))); + XPUSHs(sv_2mortal(newSViv(len))); + XPUSHs(sv_2mortal(newRV_inc(sv))); - PUTBACK; - call_pv(data,G_VOID|G_DISCARD); + PUTBACK; + call_pv(data,G_VOID|G_DISCARD); - SvPV_set(sv,old); - SvCUR_set(sv,1); - SvLEN_set(sv,1); - sv_2mortal(sv); + SvPV_set(sv,old); + SvCUR_set(sv,1); + SvLEN_set(sv,1); + sv_2mortal(sv); - FREETMPS; - LEAVE; + FREETMPS; + LEAVE; + } LEAVE_TLS_CONTEXT; } diff --git a/src/Core/objects/Cursor.xs b/src/Core/objects/Cursor.xs index 687d11de..c7f4134e 100644 --- a/src/Core/objects/Cursor.xs +++ b/src/Core/objects/Cursor.xs @@ -26,32 +26,28 @@ cursor_new(CLASS, data, mask, w, h, x ,y ) int h int x int y - CODE: - int len = av_len(data); - Uint8 *_data = (Uint8 *)safemalloc(sizeof(Uint8)*(len)); - Uint8 *_mask = (Uint8 *)safemalloc(sizeof(Uint8)*(len)); + PREINIT: + int len; + Uint8 *_data; + Uint8 *_mask; int i; + CODE: + len = av_len(data); + _data = (Uint8 *)safemalloc(sizeof(Uint8)*(len)); + _mask = (Uint8 *)safemalloc(sizeof(Uint8)*(len)); for ( i = 0; i < len + 1; i++ ) { SV ** temp1 = av_fetch(data,i,0); SV ** temp2 = av_fetch(mask,i,0); if( temp1 != NULL) - { _data[i] = (Uint8)SvIV( *temp1 ); - } else - { _data[i] = 0; - } if( temp2 != NULL) - { _mask[i] = (Uint8)SvIV( *temp2 ); - } else - { _mask[i] = 0; - } } RETVAL = SDL_CreateCursor(_data, _mask, w, h, x, y); diff --git a/src/Core/objects/Event.xs b/src/Core/objects/Event.xs index 0bd8bef8..8acf9bd1 100644 --- a/src/Core/objects/Event.xs +++ b/src/Core/objects/Event.xs @@ -9,13 +9,12 @@ #include -SV* new_data( SV* thing ) +SV *new_data( SV *thing ) { - if ( SvROK( thing ) ) - return newRV_inc(SvRV(thing ) ); - else - return SvREFCNT_inc(thing); - + if( SvROK(thing) ) + return newRV_inc( SvRV(thing) ); + else + return SvREFCNT_inc(thing); } MODULE = SDL::Event PACKAGE = SDL::Event PREFIX = event_ @@ -48,11 +47,10 @@ SDL_Event * event_new (CLASS) char *CLASS CODE: - RETVAL = (SDL_Event *) safemalloc(sizeof (SDL_Event)); - /*set userdata to NULL for now */ - (RETVAL->user).data1 =(void *)NULL; - (RETVAL->user).data2 =(void *)NULL; - + RETVAL = (SDL_Event *)safemalloc( sizeof(SDL_Event) ); + /* set userdata to NULL for now */ + (RETVAL->user).data1 = (void *)NULL; + (RETVAL->user).data2 = (void *)NULL; OUTPUT: RETVAL @@ -61,10 +59,7 @@ event_type ( event, ... ) SDL_Event *event CODE: if( items > 1 ) - { event->type = SvUV( ST(1) ); - } - RETVAL = event->type; OUTPUT: RETVAL @@ -82,14 +77,12 @@ event_active ( event, ... ) Uint8 event_active_type ( event, ... ) SDL_Event *event - CODE: - SDL_ActiveEvent * a = &(event->active); - + PREINIT: + SDL_ActiveEvent *a; + CODE: + a = &(event->active); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -98,14 +91,12 @@ event_active_type ( event, ... ) Uint8 event_active_gain ( event, ... ) SDL_Event *event - CODE: - SDL_ActiveEvent * a = &(event->active); - + PREINIT: + SDL_ActiveEvent *a; + CODE: + a = &(event->active); if( items > 1 ) - { a->gain = SvUV( ST(1) ); - } - RETVAL = a->gain; OUTPUT: RETVAL @@ -113,14 +104,12 @@ event_active_gain ( event, ... ) Uint8 event_active_state ( event, ... ) SDL_Event *event - CODE: - SDL_ActiveEvent * a = &(event->active); - + PREINIT: + SDL_ActiveEvent *a; + CODE: + a = &(event->active); if( items > 1 ) - { a->state = SvUV( ST(1) ); - } - RETVAL = a->state; OUTPUT: RETVAL @@ -139,14 +128,12 @@ event_key ( event, ... ) Uint8 event_key_type ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - + PREINIT: + SDL_KeyboardEvent *a; + CODE: + a = &(event->key); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -154,14 +141,12 @@ event_key_type ( event, ... ) Uint8 event_key_state ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - + PREINIT: + SDL_KeyboardEvent *a; + CODE: + a = &(event->key); if( items > 1 ) - { a->state = SvUV( ST(1) ); - } - RETVAL = a->state; OUTPUT: RETVAL @@ -171,15 +156,16 @@ event_key_keysym ( event, ... ) SDL_Event *event PREINIT: char* CLASS = "SDL::keysym"; - CODE: - SDL_KeyboardEvent * a = &(event->key); - + PREINIT: + SDL_KeyboardEvent *a; + CODE: + a = &(event->key); if( items > 1 ) { - SDL_keysym * ksp = (SDL_keysym * )SvPV( ST(1), PL_na) ; + SDL_keysym *ksp; + ksp = (SDL_keysym *)SvPV( ST(1), PL_na); a->keysym = *ksp; } - RETVAL = &(a->keysym); OUTPUT: RETVAL @@ -187,15 +173,14 @@ event_key_keysym ( event, ... ) Uint8 event_key_scancode ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - SDL_keysym * b = &(a->keysym); - + PREINIT: + SDL_KeyboardEvent *a; + SDL_keysym *b; + CODE: + a = &(event->key); + b = &(a->keysym); if( items > 1 ) - { b->scancode = SvUV( ST(1) ); - } - RETVAL = b->scancode; OUTPUT: RETVAL @@ -203,15 +188,14 @@ event_key_scancode ( event, ... ) Uint16 event_key_sym ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - SDL_keysym * b = &(a->keysym); - + PREINIT: + SDL_KeyboardEvent *a; + SDL_keysym *b; + CODE: + a = &(event->key); + b = &(a->keysym); if( items > 1 ) - { b->sym = SvUV( ST(1) ); - } - RETVAL = b->sym; OUTPUT: RETVAL @@ -219,15 +203,14 @@ event_key_sym ( event, ... ) Uint16 event_key_mod ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - SDL_keysym * b = &(a->keysym); - + PREINIT: + SDL_KeyboardEvent *a; + SDL_keysym *b; + CODE: + a = &(event->key); + b = &(a->keysym); if( items > 1 ) - { b->mod = SvUV( ST(1) ); - } - RETVAL = b->mod; OUTPUT: RETVAL @@ -235,15 +218,14 @@ event_key_mod ( event, ... ) Uint16 event_key_unicode ( event, ... ) SDL_Event *event - CODE: - SDL_KeyboardEvent * a = &(event->key); - SDL_keysym * b = &(a->keysym); - + PREINIT: + SDL_KeyboardEvent *a; + SDL_keysym *b; + CODE: + a = &(event->key); + b = &(a->keysym); if( items > 1 ) - { b->unicode = SvUV( ST(1) ); - } - RETVAL = b->unicode; OUTPUT: RETVAL @@ -261,14 +243,12 @@ event_motion ( event, ... ) Uint8 event_motion_type ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -276,14 +256,12 @@ event_motion_type ( event, ... ) Uint8 event_motion_state ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->state = SvUV( ST(1) ); - } - RETVAL = a->state; OUTPUT: RETVAL @@ -291,14 +269,12 @@ event_motion_state ( event, ... ) Uint16 event_motion_x ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->x = SvUV( ST(1) ); - } - RETVAL = a->x; OUTPUT: RETVAL @@ -306,14 +282,12 @@ event_motion_x ( event, ... ) Uint16 event_motion_y ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->y = SvUV( ST(1) ); - } - RETVAL = a->y; OUTPUT: RETVAL @@ -321,14 +295,12 @@ event_motion_y ( event, ... ) Sint16 event_motion_xrel ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->xrel = SvIV( ST(1) ); - } - RETVAL = a->xrel; OUTPUT: RETVAL @@ -337,14 +309,12 @@ event_motion_xrel ( event, ... ) Sint16 event_motion_yrel ( event, ... ) SDL_Event *event - CODE: - SDL_MouseMotionEvent * a = &(event->motion); - + PREINIT: + SDL_MouseMotionEvent *a; + CODE: + a = &(event->motion); if( items > 1 ) - { a->yrel = SvIV( ST(1) ); - } - RETVAL = a->yrel; OUTPUT: RETVAL @@ -362,14 +332,12 @@ event_button ( event, ... ) Uint8 event_button_type ( event, ... ) SDL_Event *event - CODE: - SDL_MouseButtonEvent * a = &(event->button); - + PREINIT: + SDL_MouseButtonEvent *a; + CODE: + a = &(event->button); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -377,14 +345,12 @@ event_button_type ( event, ... ) Uint8 event_button_which ( event, ... ) SDL_Event *event - CODE: - SDL_MouseButtonEvent * a = &(event->button); - + PREINIT: + SDL_MouseButtonEvent *a; + CODE: + a = &(event->button); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->which; OUTPUT: RETVAL @@ -392,14 +358,12 @@ event_button_which ( event, ... ) Uint8 event_button_button ( event, ... ) SDL_Event *event + PREINIT: + SDL_MouseButtonEvent *a; CODE: - SDL_MouseButtonEvent * a = &(event->button); - - if( items > 1 ) - { + a = &(event->button); + if( items > 1 ) a->button = SvUV( ST(1) ); - } - RETVAL = a->button; OUTPUT: RETVAL @@ -407,14 +371,12 @@ event_button_button ( event, ... ) Uint8 event_button_state ( event, ... ) SDL_Event *event - CODE: - SDL_MouseButtonEvent * a = &(event->button); - + PREINIT: + SDL_MouseButtonEvent *a; + CODE: + a = &(event->button); if( items > 1 ) - { a->state = SvUV( ST(1) ); - } - RETVAL = a->state; OUTPUT: RETVAL @@ -422,14 +384,12 @@ event_button_state ( event, ... ) Uint16 event_button_x ( event, ... ) SDL_Event *event - CODE: - SDL_MouseButtonEvent * a = &(event->button); - + PREINIT: + SDL_MouseButtonEvent *a; + CODE: + a = &(event->button); if( items > 1 ) - { a->x = SvUV( ST(1) ); - } - RETVAL = a->x; OUTPUT: RETVAL @@ -437,14 +397,12 @@ event_button_x ( event, ... ) Uint16 event_button_y ( event, ... ) SDL_Event *event - CODE: - SDL_MouseButtonEvent * a = &(event->button); - + PREINIT: + SDL_MouseButtonEvent *a; + CODE: + a = &(event->button); if( items > 1 ) - { a->y = SvUV( ST(1) ); - } - RETVAL = a->y; OUTPUT: RETVAL @@ -462,14 +420,12 @@ event_jaxis ( event, ... ) Uint8 event_jaxis_type ( event, ... ) SDL_Event *event - CODE: - SDL_JoyAxisEvent * a = &(event->jaxis); - + PREINIT: + SDL_JoyAxisEvent *a; + CODE: + a = &(event->jaxis); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -477,14 +433,12 @@ event_jaxis_type ( event, ... ) Uint8 event_jaxis_which ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyAxisEvent *a; CODE: - SDL_JoyAxisEvent * a = &(event->jaxis); - + a = &(event->jaxis); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->which; OUTPUT: RETVAL @@ -492,13 +446,13 @@ event_jaxis_which ( event, ... ) Uint8 event_jaxis_axis ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyAxisEvent *a; CODE: - SDL_JoyAxisEvent * a = &(event->jaxis); + a = &(event->jaxis); - if( items > 1 ) - { + if( items > 1 ) a->axis = SvUV( ST(1) ); - } RETVAL = a->axis; OUTPUT: @@ -507,14 +461,12 @@ event_jaxis_axis ( event, ... ) Sint16 event_jaxis_value ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyAxisEvent *a; CODE: - SDL_JoyAxisEvent * a = &(event->jaxis); - + a = &(event->jaxis); if( items > 1 ) - { a->value = SvUV( ST(1) ); - } - RETVAL = a->value; OUTPUT: RETVAL @@ -532,14 +484,12 @@ event_jball ( event, ... ) Uint8 event_jball_type ( event, ... ) SDL_Event *event - CODE: - SDL_JoyBallEvent * a = &(event->jball); - + PREINIT: + SDL_JoyBallEvent *a; + CODE: + a = &(event->jball); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = event->type; OUTPUT: RETVAL @@ -547,14 +497,12 @@ event_jball_type ( event, ... ) Uint8 event_jball_which ( event, ... ) SDL_Event *event - CODE: - SDL_JoyBallEvent * a = &(event->jball); - + PREINIT: + SDL_JoyBallEvent *a; + CODE: + a = &(event->jball); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->which; OUTPUT: RETVAL @@ -562,14 +510,12 @@ event_jball_which ( event, ... ) Uint8 event_jball_ball ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyBallEvent *a; CODE: - SDL_JoyBallEvent * a = &(event->jball); - + a = &(event->jball); if( items > 1 ) - { a->ball = SvUV( ST(1) ); - } - RETVAL = a->ball; OUTPUT: RETVAL @@ -577,14 +523,12 @@ event_jball_ball ( event, ... ) Sint16 event_jball_xrel ( event, ... ) SDL_Event *event - CODE: - SDL_JoyBallEvent * a = &(event->jball); - + PREINIT: + SDL_JoyBallEvent *a; + CODE: + a = &(event->jball); if( items > 1 ) - { a->xrel = SvIV( ST(1) ); - } - RETVAL = a->xrel; OUTPUT: RETVAL @@ -592,14 +536,12 @@ event_jball_xrel ( event, ... ) Sint16 event_jball_yrel ( event, ... ) SDL_Event *event - CODE: - SDL_JoyBallEvent * a = &(event->jball); - + PREINIT: + SDL_JoyBallEvent *a; + CODE: + a = &(event->jball); if( items > 1 ) - { a->yrel = SvIV( ST(1) ); - } - RETVAL = a->yrel; OUTPUT: RETVAL @@ -611,22 +553,20 @@ event_jhat ( event, ... ) char *CLASS = "SDL::JoyHatEvent"; CODE: RETVAL = NULL; - if ( &event != NULL ) - RETVAL = &(event->jhat); + if ( &event != NULL ) + RETVAL = &(event->jhat); OUTPUT: RETVAL Uint8 event_jhat_type ( event, ... ) SDL_Event *event - CODE: - SDL_JoyHatEvent * a = &(event->jhat); - + PREINIT: + SDL_JoyHatEvent *a; + CODE: + a = &(event->jhat); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -634,14 +574,12 @@ event_jhat_type ( event, ... ) Uint8 event_jhat_which ( event, ... ) SDL_Event *event - CODE: - SDL_JoyHatEvent * a = &(event->jhat); - + PREINIT: + SDL_JoyHatEvent *a; + CODE: + a = &(event->jhat); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->which; OUTPUT: RETVAL @@ -649,14 +587,12 @@ event_jhat_which ( event, ... ) Uint8 event_jhat_hat ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyHatEvent *a; CODE: - SDL_JoyHatEvent * a = &(event->jhat); - + a = &(event->jhat); if( items > 1 ) - { a->hat = SvUV( ST(1) ); - } - RETVAL = a->hat; OUTPUT: RETVAL @@ -664,14 +600,12 @@ event_jhat_hat ( event, ... ) Uint8 event_jhat_value ( event, ... ) SDL_Event *event - CODE: - SDL_JoyHatEvent * a = &(event->jhat); - + PREINIT: + SDL_JoyHatEvent *a; + CODE: + a = &(event->jhat); if( items > 1 ) - { a->value = SvUV( ST(1) ); - } - RETVAL = a->value; OUTPUT: RETVAL @@ -684,21 +618,19 @@ event_jbutton ( event, ... ) CODE: RETVAL = NULL; if ( &event != NULL ) - RETVAL = &(event->jbutton); + RETVAL = &(event->jbutton); OUTPUT: RETVAL Uint8 event_jbutton_type ( event, ... ) SDL_Event *event + PREINIT: + SDL_JoyButtonEvent *a; CODE: - SDL_JoyButtonEvent * a = &(event->jbutton); - + a = &(event->jbutton); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -706,14 +638,12 @@ event_jbutton_type ( event, ... ) Uint8 event_jbutton_which ( event, ... ) SDL_Event *event - CODE: - SDL_JoyButtonEvent * a = &(event->jbutton); - + PREINIT: + SDL_JoyButtonEvent *a; + CODE: + a = &(event->jbutton); if( items > 1 ) - { a->which = SvUV( ST(1) ); - } - RETVAL = a->which; OUTPUT: RETVAL @@ -721,14 +651,12 @@ event_jbutton_which ( event, ... ) Uint8 event_jbutton_button ( event, ... ) SDL_Event *event - CODE: - SDL_JoyButtonEvent * a = &(event->jbutton); - + PREINIT: + SDL_JoyButtonEvent *a; + CODE: + a = &(event->jbutton); if( items > 1 ) - { a->button = SvUV( ST(1) ); - } - RETVAL = a->button; OUTPUT: RETVAL @@ -736,14 +664,12 @@ event_jbutton_button ( event, ... ) Uint8 event_jbutton_state ( event, ... ) SDL_Event *event - CODE: - SDL_JoyButtonEvent * a = &(event->jbutton); - + PREINIT: + SDL_JoyButtonEvent *a; + CODE: + a = &(event->jbutton); if( items > 1 ) - { a->state = SvUV( ST(1) ); - } - RETVAL = a->state; OUTPUT: RETVAL @@ -756,21 +682,19 @@ event_resize ( event, ... ) CODE: RETVAL = NULL; if ( &event != NULL ) - RETVAL = &(event->resize); + RETVAL = &(event->resize); OUTPUT: RETVAL Uint8 event_resize_type ( event, ... ) SDL_Event *event - CODE: - SDL_ResizeEvent * a = &(event->resize); - + PREINIT: + SDL_ResizeEvent *a; + CODE: + a = &(event->resize); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -778,13 +702,12 @@ event_resize_type ( event, ... ) int event_resize_w ( event, ... ) SDL_Event *event - CODE: - SDL_ResizeEvent * a = &(event->resize); + PREINIT: + SDL_ResizeEvent * a; + CODE: + a = &(event->resize); if( items > 1 ) - { a->w = SvUV( ST(1) ); - } - RETVAL = a->w; OUTPUT: RETVAL @@ -792,14 +715,12 @@ event_resize_w ( event, ... ) int event_resize_h ( event, ... ) SDL_Event *event - CODE: - SDL_ResizeEvent * a = &(event->resize); - + PREINIT: + SDL_ResizeEvent *a; + CODE: + a = &(event->resize); if( items > 1 ) - { a->h = SvUV( ST(1) ); - } - RETVAL = a->h; OUTPUT: RETVAL @@ -817,14 +738,12 @@ event_expose ( event, ... ) Uint8 event_expose_type ( event, ... ) SDL_Event *event - CODE: - SDL_ExposeEvent * a = &(event->expose); - + PREINIT: + SDL_ExposeEvent *a; + CODE: + a = &(event->expose); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -842,14 +761,12 @@ event_quit ( event, ... ) Uint8 event_quit_type ( event, ... ) SDL_Event *event - CODE: - SDL_QuitEvent * a = &(event->quit); - + PREINIT: + SDL_QuitEvent *a; + CODE: + a = &(event->quit); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -867,14 +784,12 @@ event_user ( event, ... ) Uint8 event_user_type ( event, ... ) SDL_Event *event - CODE: - SDL_UserEvent * a = &(event->user); - + PREINIT: + SDL_UserEvent *a; + CODE: + a = &(event->user); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -882,45 +797,47 @@ event_user_type ( event, ... ) int event_user_code ( event, ... ) SDL_Event *event - CODE: - SDL_UserEvent * a = &(event->user); - + PREINIT: + SDL_UserEvent *a; + CODE: + a = &(event->user); if( items > 1 ) - { a->code = SvUV( ST(1) ); - } - RETVAL = (int)a->code; OUTPUT: RETVAL -SV* +SV * event_user_data1 ( event, ... ) - SDL_Event *event - PPCODE: - SDL_UserEvent * a = &(event->user); - if ( items > 1) + SDL_Event *event + PREINIT: + SDL_UserEvent *a; + PPCODE: + a = &(event->user); + if( items > 1 ) a->data1 = new_data( ST(1) ); - if (!a->data1) - XSRETURN_EMPTY; - ST(0) = a->data1; - XSRETURN(1); + if( !a->data1 ) + XSRETURN_EMPTY; + ST(0) = a->data1; + XSRETURN(1); -SV* +SV * event_user_data2 ( event, ... ) - SDL_Event *event - PPCODE: - SDL_UserEvent * a = &(event->user); - if ( items > 1) + SDL_Event *event + PREINIT: + SDL_UserEvent *a; + PPCODE: + a = &(event->user); + if( items > 1 ) a->data2 = new_data( ST(1) ); - if (!a->data2) - XSRETURN_EMPTY; - ST(0) = a->data2; - XSRETURN(1); + if( !a->data2 ) + XSRETURN_EMPTY; + ST(0) = a->data1; + XSRETURN(1); SDL_SysWMEvent * event_syswm ( event, ... ) - SDL_Event * event + SDL_Event *event PREINIT: char *CLASS = "SDL::SysWMEvent"; CODE: @@ -931,14 +848,12 @@ event_syswm ( event, ... ) Uint8 event_syswm_type ( event, ... ) SDL_Event *event - CODE: - SDL_SysWMEvent * a = &(event->syswm); - + PREINIT: + SDL_SysWMEvent *a; + CODE: + a = &(event->syswm); if( items > 1 ) - { a->type = SvUV( ST(1) ); - } - RETVAL = a->type; OUTPUT: RETVAL @@ -947,41 +862,43 @@ SDL_SysWMmsg * event_syswm_msg ( event, ... ) SDL_Event *event PREINIT: - char* CLASS = "SDL::SysWMmsg"; + char *CLASS = "SDL::SysWMmsg"; + SDL_SysWMEvent *a; CODE: - SDL_SysWMEvent * a = &(event->syswm); - + a = &(event->syswm); if( items > 1 ) { - SDL_SysWMmsg * sysm = (SDL_SysWMmsg * )SvPV( ST(1), PL_na) ; + SDL_SysWMmsg *sysm; + sysm = (SDL_SysWMmsg *)SvPV( ST(1), PL_na ); a->msg = sysm; } - RETVAL = a->msg; OUTPUT: RETVAL void event_DESTROY(bag) - SV* bag - CODE: - if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) { - void** pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( bag ))); - SDL_Event* self = (SDL_Event*)(pointers[0]); - if (PERL_GET_CONTEXT == pointers[1]) { - /*warn("Freed surface %p and pixels %p \n", surface, surface->pixels); */ - if(self->type == SDL_USEREVENT) { - if( (self->user).data1 != NULL ) - SvREFCNT_dec( (self->user).data1); - if( (self->user).data2 != NULL ) - SvREFCNT_dec( (self->user).data2); - } - safefree(self); - safefree(pointers); - } - } else if (bag == 0) { - XSRETURN(0); - } else { - XSRETURN_UNDEF; - } - + SV *bag + PREINIT: + void **pointers; + SDL_Event *self; + CODE: + if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) { + pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( bag ))); + self = (SDL_Event*)(pointers[0]); + if (PERL_GET_CONTEXT == pointers[1]) { + /*warn("Freed surface %p and pixels %p \n", surface, surface->pixels); */ + if(self->type == SDL_USEREVENT) { + if( (self->user).data1 != NULL ) + SvREFCNT_dec( (self->user).data1); + if( (self->user).data2 != NULL ) + SvREFCNT_dec( (self->user).data2); + } + safefree(self); + safefree(pointers); + } + } else if (bag == 0) { + XSRETURN(0); + } else { + XSRETURN_UNDEF; + } diff --git a/src/Core/objects/Palette.xs b/src/Core/objects/Palette.xs index c1ed8874..f4d51a29 100644 --- a/src/Core/objects/Palette.xs +++ b/src/Core/objects/Palette.xs @@ -34,9 +34,10 @@ palette_ncolors ( palette ) AV * palette_colors ( palette ) SDL_Palette *palette + PREINIT: + int i; CODE: RETVAL = (AV*)sv_2mortal((SV*)newAV()); - int i; for(i = 0; i < palette->ncolors; i++) av_push( RETVAL, cpy2bag( (SDL_Color *)(palette->colors + i), sizeof(SDL_Color *), sizeof(SDL_Color), "SDL::Color" ) ); OUTPUT: @@ -52,9 +53,3 @@ palette_color_index ( palette, index ) RETVAL = cpy2bag( (SDL_Color *)(palette->colors + index), sizeof(SDL_Color *), sizeof(SDL_Color), "SDL::Color" ); OUTPUT: RETVAL - -void -palette_DESTROY ( bag ) - SV *bag - CODE: - objDESTROY(bag, safefree); diff --git a/src/Core/objects/Surface.xs b/src/Core/objects/Surface.xs index c067f21e..97fa8d37 100644 --- a/src/Core/objects/Surface.xs +++ b/src/Core/objects/Surface.xs @@ -67,8 +67,10 @@ surface_new_from (CLASS, pixels, width, height, depth, pitch, Rmask = 0xFF000000 Uint32 Bmask Uint32 Amask SV* pixels + PREINIT: + int* pix; CODE: - int* pix = (int *) SvRV ( (SV*) SvRV( pixels ) ); + pix = (int *) SvRV ( (SV*) SvRV( pixels ) ); RETVAL = SDL_CreateRGBSurfaceFrom ( (void *)pix, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask ); if( RETVAL == NULL) croak ("SDL_CreateRGBSurfaceFrom failed: %s", SDL_GetError()); @@ -146,9 +148,11 @@ surface_get_pixel(surface, offset) SV * surface_get_pixels_ptr(surface) SDL_Surface *surface + PREINIT: + SV *sv; CODE: if(!surface->pixels) croak("Incomplete surface"); - SV * sv = newSV_type(SVt_PV); + sv = newSV_type(SVt_PV); SvPV_set(sv, surface->pixels); SvPOK_on(sv); SvREADONLY(sv); diff --git a/src/GFX/Primitives.xs b/src/GFX/Primitives.xs index 319f5829..df1f5ee0 100644 --- a/src/GFX/Primitives.xs +++ b/src/GFX/Primitives.xs @@ -662,10 +662,13 @@ gfx_prim_polygon_color(dst, vx, vy, n, color) AV* vy int n Uint32 color + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); - RETVAL = polygonColor(dst, _vx, _vy, n, color); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); + RETVAL = polygonColor(dst, _vx, _vy, n, color); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); OUTPUT: @@ -681,9 +684,12 @@ gfx_prim_polygon_RGBA(dst, vx, vy, n, r, g, b, a) Uint8 g Uint8 b Uint8 a + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = polygonRGBA(dst, _vx, _vy, n, r, g, b, a); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -698,9 +704,12 @@ gfx_prim_aapolygon_color(dst, vx, vy, n, color) AV* vy int n Uint32 color + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = aapolygonColor(dst, _vx, _vy, n, color); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -718,9 +727,12 @@ gfx_prim_aapolygon_RGBA(dst, vx, vy, n, r, g, b, a) Uint8 g Uint8 b Uint8 a + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = aapolygonRGBA(dst, _vx, _vy, n, r, g, b, a); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -735,9 +747,12 @@ gfx_prim_filled_polygon_color(dst, vx, vy, n, color) AV* vy int n Uint32 color + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = filledPolygonColor(dst, _vx, _vy, n, color); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -755,9 +770,12 @@ gfx_prim_filled_polygon_RGBA(dst, vx, vy, n, r, g, b, a) Uint8 g Uint8 b Uint8 a + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = filledPolygonRGBA(dst, _vx, _vy, n, r, g, b, a); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -776,9 +794,12 @@ gfx_prim_textured_polygon(dst, vx, vy, n, texture, texture_dx, texture_dy) SDL_Surface * texture int texture_dx int texture_dy + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = texturedPolygon(dst, _vx, _vy, n, texture, texture_dx, texture_dy); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -816,9 +837,12 @@ gfx_prim_filled_polygon_color_MT(dst, vx, vy, n, color, polyInts, polyAllocated) Uint32 color int **polyInts int *polyAllocated + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = filledPolygonColorMT(dst, _vx, _vy, n, color, polyInts, polyAllocated); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -838,9 +862,12 @@ gfx_prim_filled_polygon_RGBA_MT(dst, vx, vy, n, r, g, b, a, polyInts, polyAlloca Uint8 a int **polyInts int *polyAllocated + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = filledPolygonRGBAMT(dst, _vx, _vy, n, r, g, b, a, polyInts, polyAllocated); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -859,9 +886,12 @@ gfx_prim_textured_polygon_MT(dst, vx, vy, n, texture, texture_dx, texture_dy, po int texture_dy int **polyInts int *polyAllocated + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = texturedPolygonMT(dst, _vx, _vy, n, texture, texture_dx, texture_dy, polyInts, polyAllocated); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -931,9 +961,12 @@ gfx_prim_bezier_color(dst, vx, vy, n, s, color) int n int s Uint32 color + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = bezierColor(dst, _vx, _vy, n, s, color); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); @@ -952,9 +985,12 @@ gfx_prim_bezier_RGBA(dst, vx, vy, n, s, r, g, b, a) Uint8 g Uint8 b Uint8 a + PREINIT: + Sint16 *_vx; + Sint16 *_vy; CODE: - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); RETVAL = bezierRGBA(dst, _vx, _vy, n, s, r, g, b, a); _svinta_free( _vx, av_len(vx) ); _svinta_free( _vy, av_len(vy) ); diff --git a/src/Image.xs b/src/Image.xs index e8ce41cb..c0a196c1 100644 --- a/src/Image.xs +++ b/src/Image.xs @@ -15,28 +15,19 @@ void test( char** xpm) { + int w, h, ncolors, cpp; + char *line; + char ***xpmlines = NULL; -int x, y; -int w, h, ncolors, cpp; -char *line; -char ***xpmlines = NULL; + xpmlines = &xpm; + line = *(*xpmlines)++; -xpmlines = &xpm; - -line = *(*xpmlines)++; - -if(sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4 - || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) { + if(sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4 + || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) warn( "Invalid format description %s \n %d %d %d %d", line, w, h, ncolors, cpp); - } - - } - - - MODULE = SDL::Image PACKAGE = SDL::Image PREFIX = image_ #ifdef HAVE_SDL_IMAGE @@ -45,15 +36,14 @@ const SDL_version* image_linked_version() PREINIT: char* CLASS = "SDL::Version"; - SDL_version *version; + SDL_version *version, *version_dont_free; CODE: - version = (SDL_version *) safemalloc ( sizeof(SDL_version) ); - SDL_version* version_dont_free = (SDL_version *)IMG_Linked_Version(); - - version->major = version_dont_free->major; - version->minor = version_dont_free->minor; - version->patch = version_dont_free->patch; - RETVAL = version; + version = (SDL_version *)safemalloc ( sizeof(SDL_version) ); + version_dont_free = (SDL_version *)IMG_Linked_Version(); + version->major = version_dont_free->major; + version->minor = version_dont_free->minor; + version->patch = version_dont_free->patch; + RETVAL = version; OUTPUT: RETVAL @@ -111,9 +101,9 @@ image_load_typed_rw(src, freesrc, type) SDL_Surface * image_load_ICO_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadICO_RW(src); OUTPUT: RETVAL @@ -122,9 +112,9 @@ image_load_ICO_rw(src) SDL_Surface * image_load_CUR_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadCUR_RW(src); OUTPUT: RETVAL @@ -134,9 +124,9 @@ image_load_CUR_rw(src) SDL_Surface * image_load_BMP_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadBMP_RW(src); OUTPUT: RETVAL @@ -144,9 +134,9 @@ image_load_BMP_rw(src) SDL_Surface * image_load_GIF_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadGIF_RW(src); OUTPUT: RETVAL @@ -154,9 +144,9 @@ image_load_GIF_rw(src) SDL_Surface * image_load_JPG_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadJPG_RW(src); OUTPUT: RETVAL @@ -164,9 +154,9 @@ image_load_JPG_rw(src) SDL_Surface * image_load_LBM_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadLBM_RW(src); OUTPUT: RETVAL @@ -174,9 +164,9 @@ image_load_LBM_rw(src) SDL_Surface * image_load_PCX_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadPCX_RW(src); OUTPUT: RETVAL @@ -184,9 +174,9 @@ image_load_PCX_rw(src) SDL_Surface * image_load_PNG_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadPNG_RW(src); OUTPUT: RETVAL @@ -194,9 +184,9 @@ image_load_PNG_rw(src) SDL_Surface * image_load_PNM_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadPNM_RW(src); OUTPUT: RETVAL @@ -204,9 +194,9 @@ image_load_PNM_rw(src) SDL_Surface * image_load_TGA_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadTGA_RW(src); OUTPUT: RETVAL @@ -214,9 +204,9 @@ image_load_TGA_rw(src) SDL_Surface * image_load_TIF_rw(src) SDL_RWops* src - PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + PREINIT: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadTIF_RW(src); OUTPUT: RETVAL @@ -225,54 +215,53 @@ SDL_Surface * image_load_XCF_rw(src) SDL_RWops* src PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadXCF_RW(src); OUTPUT: RETVAL SDL_Surface * image_load_XPM_rw(src) - SDL_RWops* src + SDL_RWops *src PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadXPM_RW(src); OUTPUT: RETVAL SDL_Surface * image_load_XV_rw(src) - SDL_RWops* src + SDL_RWops *src PREINIT: - char *CLASS = "SDL::Surface"; - CODE: + char *CLASS = "SDL::Surface"; + CODE: RETVAL = IMG_LoadXV_RW(src); OUTPUT: RETVAL int image_is_BMP(src) - SDL_RWops* src; + SDL_RWops *src; CODE: - RETVAL=IMG_isBMP(src); + RETVAL = IMG_isBMP(src); OUTPUT: RETVAL #if (SDL_IMAGE_MAJOR_VERSION >= 1) && (SDL_IMAGE_MINOR_VERSION >= 2) && (SDL_IMAGE_PATCHLEVEL >= 10) int image_is_CUR(src) - SDL_RWops* src; + SDL_RWops *src; CODE: - RETVAL=IMG_isCUR(src); + RETVAL = IMG_isCUR(src); OUTPUT: RETVAL - int image_is_ICO(src) - SDL_RWops* src; + SDL_RWops *src; CODE: - RETVAL=IMG_isICO(src); + RETVAL = IMG_isICO(src); OUTPUT: RETVAL @@ -280,118 +269,112 @@ int image_is_ICO(src) int image_is_GIF(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isGIF(src); + RETVAL = IMG_isGIF(src); OUTPUT: RETVAL int image_is_JPG(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isJPG(src); + RETVAL = IMG_isJPG(src); OUTPUT: RETVAL int image_is_LBM(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isLBM(src); + RETVAL = IMG_isLBM(src); OUTPUT: RETVAL int image_is_PCX(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isPCX(src); + RETVAL = IMG_isPCX(src); OUTPUT: RETVAL int image_is_PNG(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isPNG(src); + RETVAL = IMG_isPNG(src); OUTPUT: RETVAL int image_is_PNM(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isPNM(src); + RETVAL = IMG_isPNM(src); OUTPUT: RETVAL int image_is_TIF(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isTIF(src); + RETVAL = IMG_isTIF(src); OUTPUT: RETVAL int image_is_XCF(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isXCF(src); + RETVAL = IMG_isXCF(src); OUTPUT: RETVAL int image_is_XPM(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isXPM(src); + RETVAL = IMG_isXPM(src); OUTPUT: RETVAL int image_is_XV(src) - SDL_RWops * src; + SDL_RWops *src; CODE: - RETVAL=IMG_isXV(src); + RETVAL = IMG_isXV(src); OUTPUT: RETVAL - - SDL_Surface * image_read_XPM_from_array(array, w) int w AV* array PREINIT: - char* CLASS = "SDL::Surface"; + char *CLASS = "SDL::Surface"; + int x, len; + SV **elem; + char **src_x; + char *temp; CODE: /*make columns first */ - int x, len; - SV ** elem; - len = av_len(array) + 1; - char** src_x = safemalloc( len * sizeof(char*)); - char* temp; - for(x=0; x < len ; x++) + len = av_len(array) + 1; + src_x = safemalloc( len * sizeof(char*) ); + for(x = 0; x < len; x++) { - elem = av_fetch(array, x, 0) ; - temp = SvPV_nolen(*elem); - src_x[x] = safemalloc(w * sizeof(char) ); + elem = av_fetch(array, x, 0) ; + temp = SvPV_nolen(*elem); + src_x[x] = safemalloc( w * sizeof(char) ); memcpy( src_x[x], temp, w * sizeof(char) ); /*warn("put in %s", src_x[x]); */ } - /*test(src_x); */ - RETVAL = IMG_ReadXPMFromArray( src_x) ; - for(x=0; x < len; x++) - safefree(src_x[x]); + /*test(src_x); */ + RETVAL = IMG_ReadXPMFromArray( src_x ); + for(x = 0; x < len; x++) + safefree(src_x[x]); safefree(src_x); - OUTPUT: RETVAL - - - - #endif diff --git a/src/Mixer/Channels.xs b/src/Mixer/Channels.xs index a70e6e52..af40abd7 100644 --- a/src/Mixer/Channels.xs +++ b/src/Mixer/Channels.xs @@ -6,10 +6,6 @@ #include "defines.h" #include "helper.h" -#ifndef aTHX_ -#define aTHX_ -#endif - #include #ifdef HAVE_SDL_MIXER @@ -28,20 +24,26 @@ static SV * cb = (SV*)NULL; void callback(int channel) { - PERL_SET_CONTEXT(parent_perl); - dSP; - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(sv_2mortal(newSViv(channel))); - PUTBACK; - - if(cb) - call_sv(cb, G_VOID); - - FREETMPS; - LEAVE; + dTHX; + if(!aTHX) { + PERL_SET_CONTEXT(parent_perl); + } + + { + dSP; + ENTER; + SAVETMPS; + + PUSHMARK(SP); + XPUSHs(sv_2mortal(newSViv(channel))); + PUTBACK; + + if(cb) + call_sv(cb, G_VOID); + + FREETMPS; + LEAVE; + } } #endif @@ -214,8 +216,13 @@ mixchan_get_chunk(chan) char* CLASS = "SDL::Mixer::MixChunk"; CODE: Mix_Chunk *chunk = Mix_GetChunk(chan); +#ifdef _WIN32 + Mix_Chunk *copy = msvcrt_malloc(sizeof(Mix_Chunk)); + copy->abuf = msvcrt_malloc( chunk->alen ); +#else Mix_Chunk *copy = malloc(sizeof(Mix_Chunk)); copy->abuf = malloc( chunk->alen ); +#endif memcpy( copy->abuf, chunk->abuf, chunk->alen ); copy->alen = chunk->alen; copy->volume = chunk->volume; diff --git a/src/Mixer/Effects.xs b/src/Mixer/Effects.xs index ba417070..44f0e386 100644 --- a/src/Mixer/Effects.xs +++ b/src/Mixer/Effects.xs @@ -26,48 +26,47 @@ char* effect_func_done_cb = NULL; void effect_func(int chan, void *stream, int len, void *udata) { ENTER_TLS_CONTEXT; - Sint16 *buf = (Sint16 *)stream; - - len /= 2; /* 2 bytes ber sample */ - - dSP; /* initialize stack pointer */ - - ENTER; /* everything created after here */ - SAVETMPS; /* ...is a temporary variable. */ - - PUSHMARK(SP); /* remember the stack pointer */ - XPUSHs(sv_2mortal(newSViv(chan))); - XPUSHs(sv_2mortal(newSViv(len))); - XPUSHs(sv_2mortal(newSVsv(udata))); /* push something onto the stack */ - int i; - for(i = 0; i < len; i++) - XPUSHs(sv_2mortal(newSViv(buf[i]))); - - PUTBACK; /* make local stack pointer global */ - - /*if(cb != (SV*)NULL) */ { - int count = call_pv(effect_func_cb, G_ARRAY); /* call the function */ - SPAGAIN; /* refresh stack pointer */ - - if(count == len + 1) - *(SV *)udata = *(newSVsv(POPs)); - - if(count) + dSP; /* initialize stack pointer */ + int i; + Sint16 *buf = (Sint16 *)stream; + + len /= 2; /* 2 bytes ber sample */ + + ENTER; /* everything created after here */ + SAVETMPS; /* ...is a temporary variable. */ + + PUSHMARK(SP); /* remember the stack pointer */ + XPUSHs(sv_2mortal(newSViv(chan))); + XPUSHs(sv_2mortal(newSViv(len))); + XPUSHs(sv_2mortal(newSVsv(udata))); /* push something onto the stack */ + for(i = 0; i < len; i++) + XPUSHs(sv_2mortal(newSViv(buf[i]))); + + PUTBACK; /* make local stack pointer global */ + + /*if(cb != (SV*)NULL) */ { - memset(buf, 0, len * 2); /* clear the buffer */ - - for(i = len - 1; i >= 0; i--) + int count = call_pv(effect_func_cb, G_ARRAY); /* call the function */ + SPAGAIN; /* refresh stack pointer */ + + if(count == len + 1) + *(SV *)udata = *(newSVsv(POPs)); + + if(count) { - buf[i] = POPi; + memset(buf, 0, len * 2); /* clear the buffer */ + + for(i = len - 1; i >= 0; i--) + buf[i] = POPi; } + + PUTBACK; } - PUTBACK; + FREETMPS; /* free that return value */ + LEAVE; /* ...and the XPUSHed "mortal" args. */ } - - FREETMPS; /* free that return value */ - LEAVE; /* ...and the XPUSHed "mortal" args. */ LEAVE_TLS_CONTEXT; } @@ -79,15 +78,11 @@ void effect_pm_func(void *udata, Uint8 *stream, int len) void effect_done(int chan, void *udata) { ENTER_TLS_CONTEXT; - - dSP; /* initialize stack pointer */ - PUSHMARK(SP); /* remember the stack pointer */ - - /*if(fcb != (SV*)NULL) */ - /*warn ( "Called %s", effect_func_done_cb ); */ - - call_pv(effect_func_done_cb, G_DISCARD|G_VOID); /* call the function */ - + { + dSP; /* initialize stack pointer */ + PUSHMARK(SP); /* remember the stack pointer */ + call_pv(effect_func_done_cb, G_DISCARD|G_VOID); /* call the function */ + } LEAVE_TLS_CONTEXT; } @@ -107,26 +102,21 @@ mixeff_register(channel, func, done, arg) SV *arg CODE: if(effects == NULL) - { effects = safemalloc(MAX_EFFECTS* sizeof(void*)); - } if(effects_done == NULL) - { effects_done = safemalloc(MAX_EFFECTS* sizeof(void*)); - } GET_TLS_CONTEXT; - effect_func_cb = func; + effect_func_cb = func; effect_func_done_cb = done; if(registered_effects <= MAX_EFFECTS ) { - effects[registered_effects] = (void*)&effect_func; - effects_done[registered_effects] = (void*)&effect_done; + effects[registered_effects] = (void *)&effect_func; + effects_done[registered_effects] = (void *)&effect_done; if(0 != Mix_RegisterEffect(channel, effects[registered_effects], effects_done[registered_effects], arg)) { /*warn( "Registered %d %p %p", registered_effects, effects[registered_effects], effects_done[registered_effects]); */ - RETVAL = registered_effects; registered_effects++; } @@ -137,9 +127,7 @@ mixeff_register(channel, func, done, arg) } } else - { RETVAL = -1; - } OUTPUT: RETVAL @@ -163,25 +151,21 @@ int mixeff_unregister( channel, func ) int channel int func - CODE: - - + PREINIT: int check; + CODE: if( func <= registered_effects) { - check = Mix_UnregisterEffect(channel, effects[func]); - if (check == 0 ) - { - warn ("Error unregistering: %s", Mix_GetError() ); - } + check = Mix_UnregisterEffect(channel, effects[func]); + if( check == 0 ) + warn ("Error unregistering: %s", Mix_GetError() ); } else { warn (" Invalid effect id %d, currently %d effects registered", func, registered_effects); check = 0; } - - RETVAL = check; + RETVAL = check; OUTPUT: RETVAL @@ -239,11 +223,8 @@ mixeff_set_post_mix(func = NULL, arg = NULL) SV *arg CODE: GET_TLS_CONTEXT; - if(func != (SV *)NULL) - { Mix_SetPostMix(&effect_pm_func, arg); - } else Mix_SetPostMix(NULL, NULL); diff --git a/src/Mixer/Mixer.xs b/src/Mixer/Mixer.xs index 624b1b50..59201e1a 100644 --- a/src/Mixer/Mixer.xs +++ b/src/Mixer/Mixer.xs @@ -70,25 +70,23 @@ const SDL_version * mixer_linked_version () PREINIT: char* CLASS = "SDL::Version"; - SDL_version *version; + SDL_version *version, *version_dont_free; CODE: - version = (SDL_version *) safemalloc ( sizeof(SDL_version) ); - SDL_version* version_dont_free = (SDL_version *)Mix_Linked_Version(); - - version->major = version_dont_free->major; - version->minor = version_dont_free->minor; - version->patch = version_dont_free->patch; - RETVAL = version; + version = (SDL_version *)safemalloc( sizeof(SDL_version) ); + version_dont_free = (SDL_version *)Mix_Linked_Version(); + version->major = version_dont_free->major; + version->minor = version_dont_free->minor; + version->patch = version_dont_free->patch; + RETVAL = version; OUTPUT: RETVAL - int mixer_open_audio ( frequency, format, channels, chunksize ) int frequency Uint16 format int channels - int chunksize + int chunksize CODE: RETVAL = Mix_OpenAudio(frequency, format, channels, chunksize); OUTPUT: @@ -99,8 +97,6 @@ mixer_close_audio () CODE: Mix_CloseAudio(); - - AV * mixer_query_spec () CODE: diff --git a/src/Mixer/Music.xs b/src/Mixer/Music.xs index d87d15c7..e2e16e36 100644 --- a/src/Mixer/Music.xs +++ b/src/Mixer/Music.xs @@ -15,45 +15,46 @@ char *fcb = NULL; void mix_func(void *udata, Uint8 *stream, int len) { PERL_SET_CONTEXT(parent_perl); - dSP; /* initialize stack pointer */ - ENTER; /* everything created after here */ - SAVETMPS; /* ...is a temporary variable. */ + { + dSP; /* initialize stack pointer */ + ENTER; /* everything created after here */ + SAVETMPS; /* ...is a temporary variable. */ - PUSHMARK(SP); /* remember the stack pointer */ - XPUSHs(sv_2mortal(newSViv(*(int*)udata))); /* push something onto the stack */ - XPUSHs(sv_2mortal(newSViv(len))); - *(int*)udata = *(int*)udata + len; - PUTBACK; /* make local stack pointer global */ + PUSHMARK(SP); /* remember the stack pointer */ + XPUSHs(sv_2mortal(newSViv(*(int*)udata))); /* push something onto the stack */ + XPUSHs(sv_2mortal(newSViv(len))); + *(int*)udata = *(int*)udata + len; + PUTBACK; /* make local stack pointer global */ - if(cb != NULL) - { - int count = call_pv(cb, G_ARRAY); /* call the function */ - SPAGAIN; /* refresh stack pointer */ - - if(count == len + 1) + if(cb != NULL) { - int i; - - for(i=0; imajor = version_dont_free->major; - version->minor = version_dont_free->minor; - version->patch = version_dont_free->patch; - RETVAL = version; + version = (SDL_version *)safemalloc( sizeof(SDL_version) ); + version_dont_free = (SDL_version *)SDL_Linked_Version(); + version->major = version_dont_free->major; + version->minor = version_dont_free->minor; + version->patch = version_dont_free->patch; + RETVAL = version; OUTPUT: RETVAL @@ -276,7 +275,7 @@ getenv (name) test = SDL_getenv(name); #else test = getenv(name); -#endif +#endif RETVAL = test; OUTPUT: RETVAL @@ -294,7 +293,6 @@ get_ticks () OUTPUT: RETVAL - IV get_handle () CODE: @@ -306,8 +304,5 @@ get_handle () OUTPUT: RETVAL - MODULE = SDL PACKAGE = SDL PROTOTYPES : DISABLE - - diff --git a/src/SDLx/Controller/Interface.xs b/src/SDLx/Controller/Interface.xs index 3dc202b7..751afd05 100644 --- a/src/SDLx/Controller/Interface.xs +++ b/src/SDLx/Controller/Interface.xs @@ -14,14 +14,16 @@ AV *acceleration_cb( SDLx_Interface *obj, float t ) { SV *tmpsv; + AV *array; + int i; + int count; + SDLx_State *copyState; + dSP; if( !(SvROK(obj->acceleration) && (tmpsv = obj->acceleration) ) ) croak( "Interface doesn't not contain an acceleration callback" ); - dSP; - AV *array = newAV(); - int i; - int count; - SDLx_State *copyState = (SDLx_State *)safemalloc( sizeof(SDLx_State) ); + array = newAV(); + copyState = (SDLx_State *)safemalloc( sizeof(SDLx_State) ); copy_state( copyState, obj->current ); copyState->owned = 0; ENTER; @@ -50,12 +52,13 @@ AV *acceleration_cb( SDLx_Interface *obj, float t ) void evaluate(SDLx_Interface *obj, SDLx_Derivative *out, SDLx_State *initial, float t) { + AV *accel; + SV *temp; out->dx = initial->v_x; out->dy = initial->v_y; out->drotation = initial->ang_v; - AV *accel = acceleration_cb(obj, t); + accel = acceleration_cb(obj, t); - SV *temp; temp = av_pop(accel); out->dv_x = sv_nv(temp); SvREFCNT_dec(temp); @@ -74,6 +77,9 @@ void evaluate(SDLx_Interface *obj, SDLx_Derivative *out, SDLx_State *initial, fl void evaluate_dt(SDLx_Interface *obj, SDLx_Derivative *out, SDLx_State *initial, float t, float dt, SDLx_Derivative *d) { SDLx_State state; + AV *accel; + SV *temp; + state.x = initial->x + d->dx * dt; state.y = initial->y + d->dy * dt; state.rotation = initial->rotation + d->drotation * dt; @@ -86,9 +92,8 @@ void evaluate_dt(SDLx_Interface *obj, SDLx_Derivative *out, SDLx_State *initial, out->dy = state.v_y; out->drotation = state.ang_v; - AV *accel = acceleration_cb(obj, t+dt); + accel = acceleration_cb(obj, t+dt); - SV *temp; temp = av_pop(accel); out->dv_x = sv_nv(temp); SvREFCNT_dec(temp); @@ -106,30 +111,38 @@ void evaluate_dt(SDLx_Interface *obj, SDLx_Derivative *out, SDLx_State *initial, void integrate( SDLx_Interface *object, float t, float dt) { - SDLx_State *state = object->current; - SDLx_Derivative *a = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); - SDLx_Derivative *b = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); - SDLx_Derivative *c = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); - SDLx_Derivative *d = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); + SDLx_State *state; + SDLx_Derivative *a; + SDLx_Derivative *b; + SDLx_Derivative *c; + SDLx_Derivative *d; + + state = object->current; + a = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); + b = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); + c = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); + d = (SDLx_Derivative *)safemalloc( sizeof(SDLx_Derivative) ); evaluate(object, a, state, t); evaluate_dt(object, b, state, t, dt*0.5f, a); evaluate_dt(object, c, state, t, dt*0.5f, b); evaluate_dt(object, d, state, t, dt, c); - const float dxdt = 1.0f/6.0f * (a->dx + 2.0f * (b->dx + c->dx) + d->dx); - const float dv_xdt = 1.0f/6.0f * (a->dv_x + 2.0f * (b->dv_x + c->dv_x) + d->dv_x); - const float dydt = 1.0f/6.0f * (a->dy + 2.0f * (b->dy + c->dy) + d->dy); - const float dv_ydt = 1.0f/6.0f * (a->dv_y + 2.0f * (b->dv_y + c->dv_y) + d->dv_y); - const float drotationdt = 1.0f/6.0f * (a->drotation + 2.0f * (b->drotation + c->drotation) + d->drotation); - const float dv_angdt = 1.0f/6.0f * (a->dang_v + 2.0f * (b->dang_v + c->dang_v) + d->dang_v); - - state->x = state->x + dxdt * dt; - state->v_x = state->v_x + dv_xdt * dt; - state->y = state->y + dydt * dt; - state->v_y = state->v_y + dv_ydt * dt; - state->rotation = state->rotation + drotationdt * dt; - state->ang_v = state->ang_v + dv_angdt * dt; + { + const float dxdt = 1.0f/6.0f * (a->dx + 2.0f * (b->dx + c->dx) + d->dx); + const float dv_xdt = 1.0f/6.0f * (a->dv_x + 2.0f * (b->dv_x + c->dv_x) + d->dv_x); + const float dydt = 1.0f/6.0f * (a->dy + 2.0f * (b->dy + c->dy) + d->dy); + const float dv_ydt = 1.0f/6.0f * (a->dv_y + 2.0f * (b->dv_y + c->dv_y) + d->dv_y); + const float drotationdt = 1.0f/6.0f * (a->drotation + 2.0f * (b->drotation + c->drotation) + d->drotation); + const float dv_angdt = 1.0f/6.0f * (a->dang_v + 2.0f * (b->dang_v + c->dang_v) + d->dang_v); + + state->x = state->x + dxdt * dt; + state->v_x = state->v_x + dv_xdt * dt; + state->y = state->y + dydt * dt; + state->v_y = state->v_y + dv_ydt * dt; + state->rotation = state->rotation + drotationdt * dt; + state->ang_v = state->ang_v + dv_angdt * dt; + } safefree(a); safefree(b); @@ -172,9 +185,11 @@ void objx_set_acceleration(obj, callback) SDLx_Interface *obj SV *callback + PREINIT: + SV *tmpsv; CODE: - SV *tmpsv = NULL; - if( !(SvROK(callback) && (tmpsv = (SV*)SvRV(callback)) && SvTYPE(tmpsv) == SVt_PVCV ) ) + tmpsv = NULL; + if( !(SvROK(callback) && (tmpsv = (SV*)SvRV(callback)) && SvTYPE(tmpsv) == SVt_PVCV ) ) croak( "Acceleration callback needs to be a code ref, %p", callback ); obj->acceleration = SvRV( newRV_inc(callback) ); @@ -193,9 +208,10 @@ objx_interpolate(obj, alpha) SDLx_Interface *obj float alpha PREINIT: + SDLx_State *out; char *CLASS = "SDLx::Controller::State"; CODE: - SDLx_State *out = (SDLx_State *)safemalloc(sizeof(SDLx_State )); + out = (SDLx_State *)safemalloc(sizeof(SDLx_State )); interpolate( obj,out, alpha); out->owned = 0; /* condition free */ RETVAL = out; diff --git a/src/SDLx/Layer.xs b/src/SDLx/Layer.xs index 9877a862..352ee67c 100644 --- a/src/SDLx/Layer.xs +++ b/src/SDLx/Layer.xs @@ -218,8 +218,8 @@ layerx_foreground( bag ) SDLx_Layer *layer = (SDLx_Layer *)bag2obj(bag); SDLx_LayerManager *manager = layer->manager; int index = layer->index; /* we cant trust its value */ - layer->manager->saved = 0; int i; + layer->manager->saved = 0; for(i = 0; i <= av_len(manager->layers); i++) { diff --git a/src/SDLx/LayerManager.xs b/src/SDLx/LayerManager.xs index b9b1463d..621def88 100644 --- a/src/SDLx/LayerManager.xs +++ b/src/SDLx/LayerManager.xs @@ -98,23 +98,27 @@ AV * lmx_blit( manager, dest ) SDLx_LayerManager *manager SDL_Surface *dest + PREINIT: + int index, length, attached_layers, did_something; CODE: - manager->dest = dest; - RETVAL = newAV(); - int index = 0; - int length = av_len( manager->layers ) + 1; - int attached_layers = 0; - int did_something = 0; - + manager->dest = dest; + RETVAL = newAV(); + index = 0; + length = av_len( manager->layers ) + 1; + attached_layers = 0; + did_something = 0; + while(index < length) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); - + SDLx_Layer *layer; + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + if(layer->attached == 0) { if(layer->touched || manager->saved == 0) { - SDL_Rect *rect = (SDL_Rect *)safemalloc( sizeof(SDL_Rect) ); + SDL_Rect *rect; + rect = (SDL_Rect *)safemalloc( sizeof(SDL_Rect) ); rect->x = layer->pos->x; rect->y = layer->pos->y; rect->w = layer->clip->w; @@ -148,21 +152,23 @@ lmx_blit( manager, dest ) index = 0; while(index < length) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + SDLx_Layer *layer; + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); if(layer->attached == 1 || layer->attached == 2) { + SDL_Rect *rect; if(layer->attached == 1) { layer->pos->x = x + layer->attached_rel->x; layer->pos->y = y + layer->attached_rel->y; } - SDL_Rect *rect = (SDL_Rect *)safemalloc( sizeof(SDL_Rect) ); - rect->x = layer->pos->x; - rect->y = layer->pos->y; - rect->w = layer->clip->w; - rect->h = layer->clip->h; + rect = (SDL_Rect *)safemalloc( sizeof(SDL_Rect) ); + rect->x = layer->pos->x; + rect->y = layer->pos->y; + rect->w = layer->clip->w; + rect->h = layer->clip->h; SDL_BlitSurface(layer->surface, layer->clip, dest, rect); av_push(RETVAL, _sv_ref( rect, sizeof(SDL_Rect *), sizeof(SDL_Rect), "SDL::Rect" )); @@ -179,21 +185,28 @@ lmx_by_position( manager, x, y ) SDLx_LayerManager* manager int x int y - CODE: + PREINIT: int i; - SV *match = NULL; + SV *match; + CODE: + match = NULL; for( i = av_len( manager->layers ); i >= 0 && match == NULL; i-- ) { - SV *bag = *av_fetch(manager->layers, i, 0); - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(bag); - SDL_Rect *clip = layer->clip; - SDL_Rect *pos = layer->pos; - SDL_Surface *surf = layer->surface; + SV *bag; + SDLx_Layer *layer; + SDL_Rect *clip, *pos; + SDL_Surface *surf; + bag = *av_fetch(manager->layers, i, 0); + layer = (SDLx_Layer *)bag2obj(bag); + clip = layer->clip; + pos = layer->pos; + surf = layer->surface; if ( pos->x <= x && x <= pos->x + clip->w && pos->y <= y && y <= pos->y + clip->h) { Uint8 r, g, b, a; - Uint32 pixel = _get_pixel(surf, x - pos->x, y - pos->y); + Uint32 pixel; + pixel = _get_pixel(surf, x - pos->x, y - pos->y); SDL_GetRGBA( pixel, surf->format, &r, &g, &b, &a ); if(a > 0) @@ -215,9 +228,11 @@ AV * lmx_ahead( manager, index ) SDLx_LayerManager *manager int index + PREINIT: + SDLx_Layer *layer; CODE: - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); - RETVAL = layers_ahead( layer ); + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + RETVAL = layers_ahead( layer ); OUTPUT: RETVAL @@ -225,19 +240,23 @@ AV * lmx_behind( manager, index ) SDLx_LayerManager *manager int index + PREINIT: + SDLx_Layer *layer; CODE: - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); - RETVAL = layers_behind( layer ); + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + RETVAL = layers_behind( layer ); OUTPUT: RETVAL void lmx_attach( manager, ... ) SDLx_LayerManager *manager + PREINIT: + int x, y, i; CODE: manager->saved = 0; - int x = -1; - int y = -1; + x = -1; + y = -1; if(SvIOK(ST(items - 1))) { @@ -254,10 +273,10 @@ lmx_attach( manager, ... ) if(-1 == x || -1 == y) SDL_GetMouseState(&x, &y); - int i; for( i = 1; i < items; i++ ) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(ST(i)); + SDLx_Layer *layer; + layer = (SDLx_Layer *)bag2obj(ST(i)); layer->attached = 1; layer->attached_pos->x = layer->pos->x; layer->attached_pos->y = layer->pos->y; @@ -270,18 +289,19 @@ lmx_detach_xy( manager, x = -1, y = -1 ) SDLx_LayerManager *manager int x int y + PREINIT: + int index, length, lower_x, lower_y, offset_x, offset_y; CODE: - RETVAL = newAV(); - int index = 0; - int length = av_len( manager->layers ) + 1; - int lower_x; - int lower_y; - int offset_x = 0; - int offset_y = 0; + RETVAL = newAV(); + index = 0; + length = av_len( manager->layers ) + 1; + offset_x = 0; + offset_y = 0; while(index < length) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); - + SDLx_Layer *layer; + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + if(layer->attached == 1) { if(av_len(RETVAL) == -1) @@ -309,13 +329,16 @@ lmx_detach_xy( manager, x = -1, y = -1 ) void lmx_detach_back( manager ) SDLx_LayerManager *manager + PREINIT: + int index, length; CODE: - int index = 0; - int length = av_len( manager->layers ) + 1; + index = 0; + length = av_len( manager->layers ) + 1; while(index < length) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); - + SDLx_Layer *layer; + layer = (SDLx_Layer *)bag2obj(*av_fetch(manager->layers, index, 0)); + if(layer->attached == 1) { layer->attached = 0; @@ -323,7 +346,7 @@ lmx_detach_back( manager ) layer->pos->x = layer->attached_pos->x; layer->pos->y = layer->attached_pos->y; } - + index++; } manager->saved = 0; @@ -331,17 +354,20 @@ lmx_detach_back( manager ) AV * lmx_foreground( manager, ... ) SDLx_LayerManager *manager + PREINIT: + int x; CODE: RETVAL = newAV(); - int x; for(x = 1; x < items; x++) { - SDLx_Layer *layer = (SDLx_Layer *)bag2obj(ST(x)); - SDLx_LayerManager *manager = layer->manager; - int index = layer->index; /* we cant trust its value */ - int i; - + SDLx_Layer *layer; + SDLx_LayerManager *manager; + int index, i; SV *fetched; + layer = (SDLx_Layer *)bag2obj(ST(x)); + manager = layer->manager; + index = layer->index; /* we cant trust its value */ + for(i = 0; i <= av_len(manager->layers); i++) { fetched = *av_fetch(manager->layers, i, 0); @@ -356,7 +382,7 @@ lmx_foreground( manager, ... ) { AvARRAY(manager->layers)[i] = AvARRAY(manager->layers)[i + 1]; } - + AvARRAY(manager->layers)[i] = fetched; manager->saved = 0; } diff --git a/src/SDLx/Surface.xs b/src/SDLx/Surface.xs index f3fdb017..47a12e9f 100644 --- a/src/SDLx/Surface.xs +++ b/src/SDLx/Surface.xs @@ -18,15 +18,18 @@ SV * get_pixel32 (SDL_Surface *surface, int x, int y) { + Uint32 *pixels; + void* s; + SV* sv; /* Convert the pixels to 32 bit */ - Uint32 *pixels = (Uint32 *)surface->pixels; + pixels = (Uint32 *)surface->pixels; /* Get the requested pixel */ - void* s = pixels + _calc_offset(surface, x, y); + s = pixels + _calc_offset(surface, x, y); /* printf( " Pixel = %d, Ptr = %p \n", *((int*) s), s ); */ - SV* sv = newSV_type(SVt_PV); + sv = newSV_type(SVt_PV); SvPV_set(sv, s); SvPOK_on(sv); SvLEN_set(sv, 0); @@ -37,13 +40,15 @@ SV * get_pixel32 (SDL_Surface *surface, int x, int y) SV * construct_p_matrix ( SDL_Surface *surface ) { /* return get_pixel32( surface, 0, 0); */ - AV * matrix = newAV(); + AV * matrix; int i, j; - i = 0; - for( i =0 ; i < surface->w; i++ ) + i = 0; + matrix = newAV(); + for( i = 0; i < surface->w; i++ ) { - AV * matrix_row = newAV(); - for( j =0 ; j < surface->h; j++ ) + AV * matrix_row; + matrix_row = newAV(); + for( j = 0; j < surface->h; j++ ) av_push( matrix_row, get_pixel32(surface, i,j) ); av_push( matrix, newRV_noinc((SV *)matrix_row) ); @@ -106,26 +111,36 @@ surfacex_get_pixel_xs ( surface, x, y ) SDL_Surface *surface int x int y + PREINIT: + int offset; CODE: _int_range( &x, 0, surface->w ); _int_range( &y, 0, surface->h ); - int offset; offset = _calc_offset( surface, x, y); RETVAL = _get_pixel( surface, offset ); OUTPUT: RETVAL +void +surfacex_set_pixel_ptr ( surface, pointer ) + SDL_Surface *surface + void *pointer + CODE: + surface->pixels = pointer + + void surfacex_set_pixel_xs ( surface, x, y, value ) SDL_Surface *surface int x int y unsigned int value + PREINIT: + int offset; CODE: _int_range( &x, 0, surface->w ); _int_range( &y, 0, surface->h ); - int offset; offset = _calc_offset( surface, x, y); if(SDL_MUSTLOCK(surface) && SDL_LockSurface(surface) < 0) croak( "Locking surface in set_pixels failed: %s", SDL_GetError() ); @@ -150,9 +165,11 @@ surfacex_draw_rect ( surface, rt, color ) SDL_Surface *surface SV* rt SV* color - CODE: - Uint32 m_color = __map_rgba( color, surface->format ); + PREINIT: + Uint32 m_color; SDL_Rect r_rect; + CODE: + m_color = __map_rgba( color, surface->format ); if( SvOK(rt) ) r_rect = *(SDL_Rect*)bag2obj( create_mortal_rect( rt ) ); @@ -169,11 +186,15 @@ surfacex_draw_polygon ( surface, vectors, color, ... ) SV* surface AV* vectors Uint32 color + PREINIT: + SDL_Surface *_surface; + AV *vx, *vy, *vertex; + int n; + Sint16 *_vx, *_vy; CODE: - SDL_Surface * _surface = (SDL_Surface *)bag2obj(surface); - AV* vx = newAV(); - AV* vy = newAV(); - AV* vertex; + _surface = (SDL_Surface *)bag2obj(surface); + vx = newAV(); + vy = newAV(); while(av_len(vectors) >= 0) { vertex = (AV*)SvRV(av_shift(vectors)); @@ -181,9 +202,9 @@ surfacex_draw_polygon ( surface, vectors, color, ... ) av_push(vy, av_shift(vertex)); } - int n = av_len(vx) + 1; - Sint16 * _vx = av_to_sint16(vx); - Sint16 * _vy = av_to_sint16(vy); + n = av_len(vx) + 1; + _vx = av_to_sint16(vx); + _vy = av_to_sint16(vy); if ( items > 3 && SvTRUE( ST(3) ) ) aapolygonColor( _surface, _vx, _vy, n, color ); else @@ -200,15 +221,15 @@ void surfacex_blit( src, dest, ... ) SV *src SV *dest + PREINIT: + SDL_Surface *_src, *_dest; + SDL_Rect _src_rect, _dest_rect; CODE: assert_surface(src); assert_surface(dest); /* just return the pointer stored in the bag */ - SDL_Surface *_src = (SDL_Surface *)bag2obj(src); - SDL_Surface *_dest = (SDL_Surface *)bag2obj(dest); - - SDL_Rect _src_rect; - SDL_Rect _dest_rect; + _src = (SDL_Surface *)bag2obj(src); + _dest = (SDL_Surface *)bag2obj(dest); if( items > 2 && SvOK(ST(2)) ) _src_rect = *(SDL_Rect *)bag2obj( create_mortal_rect( ST(2) ) ); diff --git a/src/SDLx/Validate.h b/src/SDLx/Validate.h index 22ea235b..6bd40123 100644 --- a/src/SDLx/Validate.h +++ b/src/SDLx/Validate.h @@ -142,8 +142,9 @@ AV* __list_rgb( SV* color ) AV* RETVAL ; if ( 0 == strcmp("number", format) ) { - RETVAL = (AV*)sv_2mortal( (SV *) newAV() ); - unsigned int _color = SvUV(sv_2mortal(_color_number(color, newSVuv(0)))); + unsigned int _color; + RETVAL = (AV*)sv_2mortal( (SV *) newAV() ); + _color = SvUV(sv_2mortal(_color_number(color, newSVuv(0)))); av_push(RETVAL, newSVuv(_color >> 16 & 0xFF)); av_push(RETVAL, newSVuv(_color >> 8 & 0xFF)); av_push(RETVAL, newSVuv(_color & 0xFF)); @@ -155,8 +156,9 @@ AV* __list_rgb( SV* color ) } else if ( 0 == strcmp("SDL::Color", format) ) { - RETVAL = (AV*)sv_2mortal((SV *) newAV() ); - SDL_Color *_color = (SDL_Color *)bag2obj(color); + SDL_Color *_color; + RETVAL = (AV*)sv_2mortal((SV *) newAV() ); + _color = (SDL_Color *)bag2obj(color); av_push(RETVAL, newSVuv(_color->r)); av_push(RETVAL, newSVuv(_color->g)); av_push(RETVAL, newSVuv(_color->b)); @@ -174,12 +176,14 @@ AV* __list_rgb( SV* color ) AV* __list_rgba( SV* color ) { - char *format = _color_format(color); - AV* RETVAL ; + char *format; + AV* RETVAL; + format = _color_format(color); if ( 0 == strcmp("number", format) ) { - RETVAL = (AV*)sv_2mortal((SV *) newAV() ); - unsigned int _color = SvUV(sv_2mortal(_color_number(color, sv_2mortal(newSVuv(1))))); + unsigned int _color; + RETVAL = (AV*)sv_2mortal((SV *) newAV() ); + _color = SvUV(sv_2mortal(_color_number(color, sv_2mortal(newSVuv(1))))); av_push(RETVAL, newSVuv(_color >> 24 & 0xFF)); av_push(RETVAL, newSVuv(_color >> 16 & 0xFF)); av_push(RETVAL, newSVuv(_color >> 8 & 0xFF)); @@ -191,8 +195,9 @@ AV* __list_rgba( SV* color ) } else if ( 0 == strcmp("SDL::Color", format) ) { - RETVAL = (AV*)sv_2mortal((SV *) newAV() ); - SDL_Color *_color = (SDL_Color*)bag2obj(color); + SDL_Color *_color; + RETVAL = (AV*)sv_2mortal((SV *) newAV() ); + _color = (SDL_Color*)bag2obj(color); av_push(RETVAL, newSVuv(_color->r)); av_push(RETVAL, newSVuv(_color->g)); av_push(RETVAL, newSVuv(_color->b)); @@ -214,10 +219,11 @@ AV* __list_rgba( SV* color ) unsigned int __map_rgb( SV* color, SDL_PixelFormat* format ) { Uint8 r, g, b; - AV* a = __list_rgb( color ); - r = SvUV(*av_fetch(a, 0, 0)); - g = SvUV(*av_fetch(a, 1, 0)); - b = SvUV(*av_fetch(a, 2, 0)); + AV* a; + a = __list_rgb( color ); + r = SvUV(*av_fetch(a, 0, 0)); + g = SvUV(*av_fetch(a, 1, 0)); + b = SvUV(*av_fetch(a, 2, 0)); return SDL_MapRGB( format, r, g, b ); } @@ -225,11 +231,12 @@ unsigned int __map_rgb( SV* color, SDL_PixelFormat* format ) unsigned int __map_rgba( SV* color, SDL_PixelFormat* format ) { int r, g, b, a; - AV* ar = __list_rgba( color ); - r = SvUV(*av_fetch(ar, 0, 0)); - g = SvUV(*av_fetch(ar, 1, 0)); - b = SvUV(*av_fetch(ar, 2, 0)); - a = SvUV(*av_fetch(ar, 3, 0)); + AV* ar; + ar = __list_rgba( color ); + r = SvUV(*av_fetch(ar, 0, 0)); + g = SvUV(*av_fetch(ar, 1, 0)); + b = SvUV(*av_fetch(ar, 2, 0)); + a = SvUV(*av_fetch(ar, 3, 0)); return SDL_MapRGBA( format, r, g, b, a ); } diff --git a/src/TTF/TTF.xs b/src/TTF/TTF.xs index 6b7231e1..7c8e9639 100644 --- a/src/TTF/TTF.xs +++ b/src/TTF/TTF.xs @@ -59,39 +59,33 @@ static Uint16 *UTF8_to_UNICODE(Uint16 *unicode, const char *utf8, int len) static Uint16 *utf16_to_UNICODE(SV *sv) { STRLEN len; - char *text = SvPV(sv, len); - len /= 2; /* 1-Byte chars to 2-Byte Uint16 */ - Uint16 *unicode = safemalloc((len + 2) * sizeof(Uint16)); /* length = BOM + characters + NULL */ int i; + Uint16 *unicode; + char *text = SvPV(sv, len); + len /= 2; /* 1-Byte chars to 2-Byte Uint16 */ + unicode = safemalloc((len + 2) * sizeof(Uint16)); /* length = BOM + characters + NULL */ /* UTF-16 Big Endian with BOM */ if((Uint8)text[0] == 0xFE && (Uint8)text[1] == 0xFF) { for( i = 0; i < len; i++ ) - { unicode[i] = ((Uint8)text[i * 2] << 8) | (Uint8)text[i * 2 + 1]; - } unicode[i] = 0; } - - else + /* UTF-16 Little Endian with BOM */ - if((Uint8)text[0] == 0xFF && (Uint8)text[1] == 0xFE) + else if((Uint8)text[0] == 0xFF && (Uint8)text[1] == 0xFE) { for( i = 0; i < len; i++ ) - { unicode[i] = ((Uint8)text[i * 2 + 1] << 8) | (Uint8)text[i * 2]; - } unicode[i] = 0; } - + else /* everything without BOM is treated as UTF-16 Big Endian */ { unicode[0] = 0xFEFF; /* we have to pass it as UTF-16 Big Endian */ for( i = 0; i <= len; i++ ) - { unicode[i + 1] = (text[i * 2] << 8) | text[i * 2 + 1]; - } unicode[i] = 0; } @@ -108,15 +102,14 @@ const SDL_version * ttf_linked_version() PREINIT: char* CLASS = "SDL::Version"; - SDL_version *version; + SDL_version *version, *version_dont_free; CODE: - version = (SDL_version *) safemalloc ( sizeof(SDL_version) ); - SDL_version* version_dont_free = (SDL_version *)TTF_Linked_Version(); - - version->major = version_dont_free->major; - version->minor = version_dont_free->minor; - version->patch = version_dont_free->patch; - RETVAL = version; + version = (SDL_version *)safemalloc( sizeof(SDL_version) ); + version_dont_free = (SDL_version *)TTF_Linked_Version(); + version->major = version_dont_free->major; + version->minor = version_dont_free->minor; + version->patch = version_dont_free->patch; + RETVAL = version; OUTPUT: RETVAL @@ -124,8 +117,9 @@ const SDL_version * ttf_compile_time_version() PREINIT: char* CLASS = "SDL::Version"; + SDL_version *compile_time_version; CODE: - SDL_version *compile_time_version = safemalloc(sizeof(SDL_version)); + compile_time_version = safemalloc(sizeof(SDL_version)); SDL_TTF_VERSION(compile_time_version); RETVAL = compile_time_version; OUTPUT: @@ -275,9 +269,9 @@ AV * ttf_glyph_metrics(font, ch) TTF_Font *font SV *ch - CODE: + PREINIT: int minx, maxx, miny, maxy, advance; - + CODE: if(TTF_GlyphMetrics(font, *(utf16_to_UNICODE(ch)+1), &minx, &maxx, &miny, &maxy, &advance) == 0) { RETVAL = newAV(); @@ -297,8 +291,9 @@ AV * ttf_size_text(font, text) TTF_Font *font const char *text - CODE: + PREINIT: int w, h; + CODE: if(0 == TTF_SizeText(font, text, &w, &h)) { RETVAL = newAV(); @@ -315,8 +310,9 @@ AV * ttf_size_utf8(font, text) TTF_Font *font const char *text - CODE: + PREINIT: int w, h; + CODE: if(0 == TTF_SizeUTF8(font, text, &w, &h)) { RETVAL = newAV(); @@ -333,8 +329,9 @@ AV * ttf_size_unicode(font, text) TTF_Font *font SV *text - CODE: + PREINIT: int w, h; + CODE: if(0 == TTF_SizeUNICODE(font, utf16_to_UNICODE(text), &w, &h)) { RETVAL = newAV(); @@ -366,16 +363,16 @@ ttf_render_utf8_solid(font, text, fg) SDL_Color *fg PREINIT: char* CLASS = "SDL::Surface"; + STRLEN len; + unsigned char *utf8_text; + Uint16 *unicode; CODE: /* this is buggy, see: http://bugzilla.libsdl.org/show_bug.cgi?id=970 */ /*RETVAL = TTF_RenderUTF8_Solid(font, text, *fg); */ - - STRLEN len; - unsigned char*utf8_text = SvPV(text, len); - Uint16 *unicode = safemalloc((sv_len_utf8(text) + 2) * sizeof(Uint16)); - *unicode = 0xFEFF; + utf8_text = SvPV(text, len); + unicode = safemalloc((sv_len_utf8(text) + 2) * sizeof(Uint16)); + *unicode = 0xFEFF; UTF8_to_UNICODE(unicode+1, utf8_text, len); - RETVAL = TTF_RenderUNICODE_Solid(font, unicode, *fg); OUTPUT: RETVAL diff --git a/src/defines.h b/src/defines.h index 69428356..0259da10 100644 --- a/src/defines.h +++ b/src/defines.h @@ -32,6 +32,19 @@ #ifndef SDL_PERL_DEFINES_H #define SDL_PERL_DEFINES_H +#ifdef _WIN32 +#include +typedef void* (*malloc_t)(int size); +malloc_t _msvcrt_malloc = NULL; +extern malloc_t _msvcrt_malloc; + +void *msvcrt_malloc(int size) { + if (!_msvcrt_malloc) + _msvcrt_malloc = (malloc_t)GetProcAddress(GetModuleHandle("msvcrt"), "malloc"); + return _msvcrt_malloc(size); +} +#endif + #ifdef USE_THREADS PerlInterpreter *parent_perl = NULL; extern PerlInterpreter *parent_perl; diff --git a/src/helper.h b/src/helper.h index 1d2ee9a5..29bc1bb3 100644 --- a/src/helper.h +++ b/src/helper.h @@ -4,6 +4,9 @@ #include #include "SDL_thread.h" +#ifndef Uint32 +#define Uint32 uint32_t +#endif PerlInterpreter * perl = NULL; @@ -22,11 +25,15 @@ void *bag2obj( SV *bag ) SV *obj2bag( int size_ptr, void *obj, char *CLASS ) { - SV * objref = newSV( size_ptr ); - void** pointers = safemalloc(3 * sizeof(void*)); + SV * objref; + void** pointers; + Uint32 *threadid; + + objref = newSV( size_ptr ); + pointers = safemalloc(3 * sizeof(void*)); pointers[0] = (void*)obj; pointers[1] = (void*)PERL_GET_CONTEXT; - Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32)); + threadid = (Uint32 *)safemalloc(sizeof(Uint32)); *threadid = SDL_ThreadID(); pointers[2] = (void*)threadid; sv_setref_pv( objref, CLASS, (void *)pointers); @@ -35,17 +42,23 @@ SV *obj2bag( int size_ptr, void *obj, char *CLASS ) SV *cpy2bag( void *object, int p_size, int s_size, char *package ) { - SV *ref = newSV( p_size ); - void *copy = safemalloc( s_size ); + void** pointers; + Uint32 *threadid; + SV* ref; + SV* a; + void *copy; + + ref = newSV( p_size ); + copy = safemalloc( s_size ); memcpy( copy, object, s_size ); - void** pointers = safemalloc(3 * sizeof(void*)); + pointers = safemalloc(3 * sizeof(void*)); pointers[0] = (void*)copy; pointers[1] = (void*)PERL_GET_CONTEXT; - Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32)); + threadid = (Uint32 *)safemalloc(sizeof(Uint32)); *threadid = SDL_ThreadID(); pointers[2] = (void*)threadid; - SV* a = sv_setref_pv(ref, package, (void *)pointers); + a = sv_setref_pv(ref, package, (void *)pointers); return a; } @@ -71,16 +84,20 @@ void objDESTROY(SV *bag, void (* callback)(void *object)) SV *_sv_ref( void *object, int p_size, int s_size, char *package ) { - SV *ref = newSV( p_size ); - void *copy = safemalloc( s_size ); - memcpy( copy, object, s_size ); + SV *ref; + void *copy; + void** pointers; + Uint32 *threadid; - void** pointers = safemalloc(3 * sizeof(void*)); - pointers[0] = (void*)copy; - pointers[1] = (void*)perl; - Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32)); - *threadid = SDL_ThreadID(); - pointers[2] = (void*)threadid; + ref = newSV( p_size ); + copy = safemalloc( s_size ); + memcpy( copy, object, s_size ); + pointers = safemalloc(3 * sizeof(void*)); + pointers[0] = (void*)copy; + pointers[1] = (void*)perl; + threadid = (Uint32 *)safemalloc(sizeof(Uint32)); + *threadid = SDL_ThreadID(); + pointers[2] = (void*)threadid; return sv_setref_pv(ref, package, (void *)pointers); } diff --git a/t/config.t b/t/config.t index d1191f7a..99ca73cb 100644 --- a/t/config.t +++ b/t/config.t @@ -1,5 +1,7 @@ # t/002_config.t - test config() functionality +use strict; +use warnings; use Test::More tests => 2; BEGIN { use_ok('SDL::Config'); } diff --git a/t/core.t b/t/core.t index 3cc7b7d6..1ccac868 100644 --- a/t/core.t +++ b/t/core.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use Config; use SDL; diff --git a/t/core_audio.t b/t/core_audio.t index 575bc43f..3ca35a4c 100644 --- a/t/core_audio.t +++ b/t/core_audio.t @@ -7,6 +7,7 @@ BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes } } use strict; +use warnings; use SDL; use SDL::Audio; use SDL::AudioSpec; diff --git a/t/core_audiospec.t b/t/core_audiospec.t index 0643b06e..aaa869c1 100644 --- a/t/core_audiospec.t +++ b/t/core_audiospec.t @@ -7,6 +7,7 @@ BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes } } use strict; +use warnings; use threads; use threads::shared; use SDL; diff --git a/t/core_cd.t b/t/core_cd.t index 4c340344..8f9b3809 100644 --- a/t/core_cd.t +++ b/t/core_cd.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; BEGIN { diff --git a/t/core_events.t b/t/core_events.t index 91240f65..1e37ade4 100644 --- a/t/core_events.t +++ b/t/core_events.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Event; use SDL::Events; diff --git a/t/core_joystick.t b/t/core_joystick.t index eaadc511..863fe613 100644 --- a/t/core_joystick.t +++ b/t/core_joystick.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use Test::More; use SDL::Joystick; diff --git a/t/core_mouse.t b/t/core_mouse.t index be817f9f..57a37b8c 100644 --- a/t/core_mouse.t +++ b/t/core_mouse.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use Test::More; use SDL::Mouse; diff --git a/t/core_multi.t b/t/core_multi.t index c36a74b7..db3ee1e2 100644 --- a/t/core_multi.t +++ b/t/core_multi.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use Test::More; diff --git a/t/core_rwops.t b/t/core_rwops.t index 634204c1..5f40a82f 100644 --- a/t/core_rwops.t +++ b/t/core_rwops.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use Test::More; use SDL::RWOps; diff --git a/t/core_surface.t b/t/core_surface.t index 328a19dd..897536b6 100644 --- a/t/core_surface.t +++ b/t/core_surface.t @@ -9,6 +9,7 @@ BEGIN { } use strict; +use warnings; use SDL; use SDL::Config; use SDL::Surface; diff --git a/t/core_timer.t b/t/core_timer.t index c341edfc..6de72342 100644 --- a/t/core_timer.t +++ b/t/core_timer.t @@ -9,6 +9,7 @@ BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes use threads; use threads::shared; use strict; +use warnings; use SDL; use Test::More; use SDL::Time; diff --git a/t/core_version.t b/t/core_version.t index 27cc8f09..5df0404c 100644 --- a/t/core_version.t +++ b/t/core_version.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Version; use Test::More tests => 8; diff --git a/t/core_video.t b/t/core_video.t index 1676d30c..caef2ced 100644 --- a/t/core_video.t +++ b/t/core_video.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Color; use SDL::Surface; diff --git a/t/core_video_convert_surface.t b/t/core_video_convert_surface.t index 1a6dbbcd..ee04a116 100644 --- a/t/core_video_convert_surface.t +++ b/t/core_video_convert_surface.t @@ -1,4 +1,5 @@ use strict; +use warnings; use SDL; use SDL::Rect; use SDL::Color; diff --git a/t/core_video_gamma.t b/t/core_video_gamma.t index 128deeca..23434a42 100644 --- a/t/core_video_gamma.t +++ b/t/core_video_gamma.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Color; use SDL::Surface; diff --git a/t/extendingrect.t b/t/extendingrect.t index 51703fef..6edb8c46 100644 --- a/t/extendingrect.t +++ b/t/extendingrect.t @@ -1,4 +1,6 @@ package MyRect; +use strict; +use warnings; use base 'SDL::Rect'; sub new { diff --git a/t/gfx_imagefilter.t b/t/gfx_imagefilter.t index d75de70a..5edcff35 100644 --- a/t/gfx_imagefilter.t +++ b/t/gfx_imagefilter.t @@ -32,6 +32,8 @@ printf( "got version: %d.%d.%d\n", $v->major, $v->minor, $v->patch ); my @done = qw/ MMX_detect + MMX_off + MMX_on /; my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE ); @@ -99,9 +101,6 @@ SDL::Video::update_rect( $display, 0, 0, 640, 480 ); #SDL::delay(1000); my @left = qw/ - MMX_detect - MMX_off - MMX_on add mean sub diff --git a/t/image.t b/t/image.t index 237da564..d1f212c5 100644 --- a/t/image.t +++ b/t/image.t @@ -1,10 +1,12 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; use SDL::Version; use SDL::Image; use SDL::RWOps; +use Alien::SDL; use Test::More; use lib 't/lib'; @@ -55,7 +57,7 @@ printf( "got version: %d.%d.%d\n", $lver->major, $lver->minor, $lver->patch ); SKIP: { - skip( 'PNG support not compiled', 14 ) unless SDL::Config->has('png'); + skip( 'PNG support not compiled', 14 ) unless Alien::SDL->config('ld_shlib_map')->{png}; isa_ok( SDL::Image::load("test/data/highlight.png"), "SDL::Surface", "[load] Gets Surface" @@ -92,7 +94,7 @@ SKIP: SKIP: { - skip( 'JPEG support not compiled', 14 ) unless SDL::Config->has('jpeg'); + skip( 'JPEG support not compiled', 14 ) unless Alien::SDL->config('ld_shlib_map')->{'jpeg'}; isa_ok( SDL::Image::load("test/data/picture.jpg"), "SDL::Surface", "[load] Gets Surface" @@ -129,7 +131,7 @@ SKIP: SKIP: { - skip( 'TIFF support not compiled', 14 ) unless SDL::Config->has('tiff'); + skip( 'TIFF support not compiled', 14 ) unless Alien::SDL->config('ld_shlib_map')->{'tiff'}; isa_ok( SDL::Image::load("test/data/picture.tif"), "SDL::Surface", "[load] Gets Surface" @@ -175,24 +177,24 @@ SKIP: skip( 'This is only for version >= 1.2.10', 2 ) if $lver < 1.2.10; SKIP: { - skip( 'JPEG support not compiled', 1 ) unless SDL::Config->has('jpeg'); - is( SDL::Image::init(IMG_INIT_JPG), IMG_INIT_JPG, + skip( 'JPEG support not compiled', 1 ) unless Alien::SDL->config('ld_shlib_map')->{'jpeg'}; + cmp_ok( SDL::Image::init(IMG_INIT_JPG), '&', IMG_INIT_JPG, '[init] Inited JPEG' ); } SKIP: { - skip( 'TIFF support not compiled', 1 ) unless SDL::Config->has('tiff'); - is( SDL::Image::init(IMG_INIT_TIF), IMG_INIT_TIF, + skip( 'TIFF support not compiled', 1 ) unless Alien::SDL->config('ld_shlib_map')->{'tiff'}; + cmp_ok( SDL::Image::init(IMG_INIT_TIF), '&', IMG_INIT_TIF, '[init] Inited TIFF' ); } SKIP: { - skip( 'PNG support not compiled', 1 ) unless SDL::Config->has('png'); - is( SDL::Image::init(IMG_INIT_PNG), IMG_INIT_PNG, '[init] Inited PNG' ); + skip( 'PNG support not compiled', 1 ) unless Alien::SDL->config('ld_shlib_map')->{'png'}; + cmp_ok( SDL::Image::init(IMG_INIT_PNG), '&', IMG_INIT_PNG, '[init] Inited PNG' ); } can_ok( diff --git a/t/image_xpm_array.t b/t/image_xpm_array.t index ad459509..adc3abaa 100644 --- a/t/image_xpm_array.t +++ b/t/image_xpm_array.t @@ -1,6 +1,8 @@ #!/usr/bin/perl -Iblib/lib -Iblib -Iblib/arch # +use strict; +use warnings; use SDL; use SDL::Config; use SDL::Rect; diff --git a/t/mixer.t b/t/mixer.t index 5a515af3..2a0b106b 100644 --- a/t/mixer.t +++ b/t/mixer.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; diff --git a/t/mixer_groups.t b/t/mixer_groups.t index 6778f382..06fe1db1 100644 --- a/t/mixer_groups.t +++ b/t/mixer_groups.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; diff --git a/t/mixer_mixmusic.t b/t/mixer_mixmusic.t index 9809c4b5..e8bee656 100644 --- a/t/mixer_mixmusic.t +++ b/t/mixer_mixmusic.t @@ -1,4 +1,5 @@ use strict; +use warnings; use SDL; use SDL::Config; diff --git a/t/mixer_music.t b/t/mixer_music.t index 8d23e558..11913192 100644 --- a/t/mixer_music.t +++ b/t/mixer_music.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; my $audiodriver; @@ -59,16 +60,18 @@ sub mix_func { return @stream; } -my $delay = 100; -my $audio_test_file = 'test/data/silence.wav'; -my $volume1 = 2; -my $volume2 = 1; +my $delay = 100; +my $wav_test_file = 'test/data/silence.wav'; +my $ogg_test_file = 'test/data/silence.ogg'; +my $volume1 = 2; +my $volume2 = 1; if ( $ENV{'SDL_RELEASE_TESTING'} ) { - $delay = 2000; - $audio_test_file = 'test/data/sample.wav'; - $volume1 = 20; - $volume2 = 10; + $delay = 2000; + $wav_test_file = 'test/data/sample.wav'; + $ogg_test_file = 'test/data/sample.ogg'; + $volume1 = 20; + $volume2 = 10; } SDL::Mixer::Music::volume_music($volume1); @@ -103,24 +106,26 @@ SKIP: is( $mix_func_called > 0, 1, "[hook_music] called $mix_func_called times" ); } -my $sample_music = SDL::Mixer::Music::load_MUS($audio_test_file); -isa_ok( $sample_music, 'SDL::Mixer::MixMusic', '[load_MUS]' ); -is( SDL::Mixer::Music::play_music( $sample_music, 0 ), - 0, "[play_music] plays $audio_test_file" -); - SKIP: { - skip( 'Version 1.2.7 needed', 2 ) if $v < 1.2.7; + skip( 'Version 1.2.7 needed', 3 ) if $v < 1.2.7; - my $rw = SDL::RWOps->new_file( $audio_test_file, "rb" ); + my $rw = SDL::RWOps->new_file( $ogg_test_file, "rb" ); + isa_ok( $rw, 'SDL::RWOps', '[SDL::RWOps->new_file]' ); my $sample_music_rw = SDL::Mixer::Music::load_MUS_RW( $rw ); isa_ok( $sample_music_rw, 'SDL::Mixer::MixMusic', '[load_MUS_RW]' ); is( SDL::Mixer::Music::play_music( $sample_music_rw, 0 ), - 0, "[play_music_rw] plays $audio_test_file" + 0, "[play_music_rw] plays $ogg_test_file" ); } +my $wav_music = SDL::Mixer::Music::load_MUS($wav_test_file); +my $ogg_music = SDL::Mixer::Music::load_MUS($ogg_test_file); +isa_ok( $wav_music, 'SDL::Mixer::MixMusic', '[load_MUS]' ); +is( SDL::Mixer::Music::play_music( $wav_music, 0 ), + 0, "[play_music] plays $wav_test_file" +); + SKIP: { skip( 'Version 1.2.9 needed', 2 ) if $v < 1.2.9; @@ -137,8 +142,8 @@ SKIP: SDL::delay($delay); is( SDL::Mixer::Music::playing_music(), 1, "[playing_music] music is playing" ); -is( SDL::Mixer::Music::get_music_type($sample_music), - MUS_WAV, "[get_music_type] $audio_test_file is MUS_WAV" +is( SDL::Mixer::Music::get_music_type($wav_music), + MUS_WAV, "[get_music_type] $wav_test_file is MUS_WAV" ); is( SDL::Mixer::Music::get_music_type(), MUS_WAV, "[get_music_type] currently playing MUS_WAV" @@ -174,7 +179,7 @@ is( SDL::Mixer::Music::set_music_cmd("mpeg123 -q"), is( SDL::Mixer::Music::set_music_cmd(), 0, '[set_music_cmd] return to the internal player' ); -is( SDL::Mixer::Music::fade_in_music( $sample_music, 0, 2000 ), +is( SDL::Mixer::Music::fade_in_music( $wav_music, 0, 2000 ), 0, "[fade_in_music] $delay ms" ); @@ -188,8 +193,8 @@ is( SDL::Mixer::Music::halt_music(), 0, '[halt_music]' ); SKIP: { skip( 'We need an MOD/OGG/MP3 for positioning', 2 ) - unless $audio_test_file =~ /\.(ogg|mod|mp3)$/; - is( SDL::Mixer::Music::fade_in_music_pos( $sample_music, 0, 2000, 2.5 ), + unless $ogg_test_file =~ /\.(ogg|mod|mp3)$/; + is( SDL::Mixer::Music::fade_in_music_pos( $ogg_music, 0, 2000, 2.5 ), 0, "[fade_in_music_pos] $delay ms, beginning at 2.5 ms" ); is( SDL::Mixer::Music::set_music_position(2.5), diff --git a/t/mixer_samples.t b/t/mixer_samples.t index ffc42c95..8b245109 100644 --- a/t/mixer_samples.t +++ b/t/mixer_samples.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; diff --git a/t/pango.t b/t/pango.t index 545eb759..f8fc6af3 100644 --- a/t/pango.t +++ b/t/pango.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; use SDL::Color; diff --git a/t/release-pod-syntax.t b/t/release-pod-syntax.t new file mode 100644 index 00000000..63bb021f --- /dev/null +++ b/t/release-pod-syntax.t @@ -0,0 +1,16 @@ +use strict; +use warnings; + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +use Test::More; + +eval "use Test::Pod 1.41"; +plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/t/sdlgamerect.t b/t/sdlgamerect.t index 22472eba..a89ba408 100644 --- a/t/sdlgamerect.t +++ b/t/sdlgamerect.t @@ -1,5 +1,6 @@ use Test::More tests => 87; use strict; +use warnings; use SDL; use_ok('SDLx::Rect'); diff --git a/t/sdlx_app.t b/t/sdlx_app.t index 56add72f..12d89296 100644 --- a/t/sdlx_app.t +++ b/t/sdlx_app.t @@ -2,6 +2,7 @@ # basic testing of SDLx::App use strict; +use warnings; use SDL; use SDL::Config; use SDL::Rect; @@ -19,18 +20,22 @@ use SDLx::App; can_ok( 'SDLx::App', qw/ new + set_video_mode + stash + init + screen_size resize title - delay - ticks + icon error - warp + warp_cursor + show_cursor fullscreen iconify grab_input sync - attribute - / + gl_attribute + / ); my $videodriver = $ENV{SDL_VIDEODRIVER}; diff --git a/t/sdlx_controller.t b/t/sdlx_controller.t index 62543be6..c2703762 100644 --- a/t/sdlx_controller.t +++ b/t/sdlx_controller.t @@ -5,19 +5,29 @@ use SDL; use SDL::Config; use SDL::Video; use SDL::Color; +use SDL::Event; +use SDL::Events; use SDLx::Controller; use Scalar::Util 'refaddr'; use lib 't/lib'; use SDL::TestTool; +# we need video for events to work +$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING}; +if ( !SDL::TestTool->init(SDL_INIT_VIDEO) or !SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE ) ) { + plan( skip_all => 'Failed to init video' ); +} + can_ok( 'SDLx::Controller', qw( - new run stop pause dt min_t current_time + new run stop stopped pause paused + dt min_t max_t delay event stop_handler default_stop_handler + time sleep add_move_handler add_event_handler add_show_handler + move_handlers event_handlers show_handlers remove_move_handler remove_event_handler remove_show_handler remove_all_move_handlers remove_all_event_handlers remove_all_show_handlers - move_handlers event_handlers show_handlers eoq exit_on_quit ) ); @@ -26,50 +36,294 @@ TODO: { can_ok( 'SDLx::Controller', qw( ) ); } +# defaults my $app = SDLx::Controller->new; isa_ok( $app, 'SDLx::Controller', 'default controller can be spawned' ); -is($app->dt, 0.1, 'default dt set to 0.1'); -is($app->min_t, 1 / 60, 'default min_t set to 1/60' ); -is($app->eoq, 0, 'no eoq by default'); -is($app->exit_on_quit, 0, 'no exit_on_quit by default'); +is($app->dt, 0.1, 'default dt set to 0.1' ); +is($app->min_t, 1/60, 'default min_t set to 1/60' ); +is($app->max_t, 0.1, 'default max_t set to 0.1' ); +is($app->delay, 0, 'default delay set to 0' ); is( scalar @{ $app->move_handlers }, 0, 'no motion handlers by default' ); is( scalar @{ $app->show_handlers }, 0, 'no show handlers by default' ); is( scalar @{ $app->event_handlers }, 0, 'no event handlers by default' ); +isa_ok($app->event, 'SDL::Event', 'SDL::Event for controller created' ); +is($app->time, 0, 'time started at 0' ); +is($app->stop_handler, \&SDLx::Controller::default_stop_handler, 'stop_handler defaults to &default_stop_handler' ); +ok( $app->stopped, 'default stopped' ); +ok( !$app->paused, 'default not paused' ); -is( $app->exit_on_quit, 0, 'exit_on_quit is not set by default' ); -is( $app->eoq, 0, 'eoq() is a method alias to exit_on_quit()' ); -$app->exit_on_quit(1); -is( scalar @{ $app->event_handlers }, 0, 'exit_on_quit does not trigger event handlers' ); -is( $app->exit_on_quit, 1, 'exit_on_quit can be set dynamically' ); -is( $app->eoq, 1, 'eoq() follows exit_on_quit()' ); +# modifying with param methods +$app->stop_handler(\&dummy_sub); +is( $app->stop_handler, \&dummy_sub, 'stop_handler changed with method' ); +is( scalar @{ $app->event_handlers }, 0, 'stop_handler does not trigger event handlers' ); $app->remove_all_event_handlers; -is( $app->exit_on_quit, 1, 'exit_on_quit is not an event handler' ); -is( $app->eoq, 1, 'eoq() still follows exit_on_quit()' ); -$app->eoq(0); -is( $app->eoq, 0, 'eoq can be set dynamically' ); -is( $app->exit_on_quit, 0, 'exit_on_quit() follows eoq()' ); +ok( $app->stop_handler, 'stop_handler is not an event handler' ); +$app->remove_all_handlers; +ok( $app->stop_handler, 'stop_handler is not removed by remove all handlers' ); +$app->stop_handler(undef); +is( $app->stop_handler, undef, 'stop_handler can be undefined' ); + +$app->dt(1337); +is( $app->dt, 1337, 'dt can be changed with method' ); +$app->min_t(123); +is( $app->min_t, 123, 'min_t can be changed with method' ); +$app->max_t(190); +is( $app->max_t, 190, 'max_t can be changed with method' ); +$app->delay(555); +is( $app->delay, 555, 'delay can be changed with method' ); +my $event = SDL::Event->new; +$app->event($event); +is( $app->event, $event, 'event can be changed with method' ); +$app->time(20.3); +is( $app->time, 20.3, 'time can be changed with method' ); + +# stop and pause +$app->stop; +ok( $app->stopped, 'stopped still true when used stop' ); +{ + my $pass_event; + my $pass_app; + my $pass_paused_within; + my $pass_not_stopped_within; + my $pass_not_paused_before; + my $pass_not_stopped_before; + my $pass_paused_in_cycle; + my $pass_stopped_in_cycle; + + my $pause_test; + $pause_test = sub { + my ($event, $caller) = @_; + $pass_event++ if $event->type == SDL_KEYUP; + $pass_app++ if $caller == $app; + $pass_paused_within++ if $app->paused == $pause_test; + $pass_not_stopped_within++ unless $app->stopped; + + $app->stop if $event->type == SDL_QUIT; + return; + }; + + $app = SDLx::Controller->new( + stop_handler => undef, + show_handlers => [ + sub { + $pass_not_paused_before++ unless $app->paused; + $pass_not_stopped_before++ unless $app->stopped; + }, + sub { + $pass_not_paused_before++ unless $app->paused; + $pass_not_stopped_before++ unless $app->stopped; + + my $event = SDL::Event->new; + $event->type(SDL_KEYUP); + my $quit_event = SDL::Event->new; + $quit_event->type(SDL_QUIT); + SDL::Events::push_event($event); + SDL::Events::push_event($event); + SDL::Events::push_event($quit_event); + + $app->pause(\&dummy_sub); + $app->pause($pause_test); + $pass_paused_in_cycle++ if $app->paused == $pause_test; + $pass_stopped_in_cycle++ if $app->stopped; + }, + sub { + $pass_paused_in_cycle++ if $app->paused == $pause_test; + $pass_stopped_in_cycle++ if $app->stopped; + }, + ], + ); + $app->run; + + ok( $app->stopped, 'stopped true after being paused' ); + ok( !$app->paused, 'paused not true after stopped' ); + is( $pass_event, 2, 'pause gets the right event' ); + is( $pass_app, 3, 'pause gets the app' ); + is( $pass_paused_within, 3, 'paused returns callback within callback' ); + is( $pass_not_stopped_within, 3, 'stopped return false within callback' ); + is( $pass_not_paused_before, 2, 'paused returns false before being paused' ); + is( $pass_not_stopped_before, 2, 'stopped returns false before being paused' ); + is( $pass_paused_in_cycle, 2, 'pause returns callback in remaining cycle' ); + is( $pass_stopped_in_cycle, 2, 'stopped returns true in remaining cycle' ); +} + +# callback returning 1 ending pause +{ + my $in_callback; + + $app = SDLx::Controller->new( + show_handlers => [sub { + $app->stop if $in_callback; + + my $event = SDL::Event->new; + my $other_event = SDL::Event->new; + $other_event->type(SDL_MOUSEBUTTONDOWN); + SDL::Events::push_event($event); + SDL::Events::push_event($event); + SDL::Events::push_event($other_event); + + $app->pause(sub { + my ($event) = @_; + $in_callback++; + return 1 if $event->type == SDL_MOUSEBUTTONDOWN; + return; + }); + }], + ); + $app->run; + + ok( $app->stopped, 'stopped true after being paused' ); + ok( !$app->paused, 'paused not true after stopped' ); + is( $in_callback, 3, 'callback called exactly three times' ); +} + +# stop overriding pause +{ + my $didnt_override; + + $app = SDLx::Controller->new( + show_handlers => [sub { + $app->stop; + + my $event = SDL::Event->new; + SDL::Events::push_event($event); + + $app->pause(sub { + $didnt_override = 1; + return 1; + }); + }], + ); + $app->run; + ok( $app->stopped, 'stopped true after run' ); + ok( !$app->paused, 'paused never happened' ); + ok( !$didnt_override, 'pause overrided by stop' ); +} +{ + my $didnt_override; + + $app = SDLx::Controller->new( + show_handlers => [sub { + my $event = SDL::Event->new; + SDL::Events::push_event($event); + + $app->pause(sub { + $didnt_override = 1; + return 1; + }); + + $app->stop; + }], + ); + $app->run; + + SDL::Events::poll_event( $app->event ); # remove unused event + ok( !$didnt_override, 'pause overrided by stop' ); +} + +# stop and event handlers +{ + my $fail_event_before_show; + my $pass_stop_handler_event; + my $pass_stop_handler_app; + my $pass_event_handler_event; + my $pass_event_handler_app; + my $pass_stopped; + my $fail_stopped; + my $in_show_handler; + + $app = SDLx::Controller->new( + stop_handler => sub { + my ($event, $caller) = @_; + $fail_event_before_show++ unless $in_show_handler; + $pass_stop_handler_event++ if $event->type == SDL_KEYDOWN; + $pass_stop_handler_app++ if $caller == $app; + $fail_stopped++ if $app->stopped; + }, + event_handlers => [ + sub { + $fail_stopped++ if $app->stopped; + }, + sub { + my ($event, $caller) = @_; + $fail_event_before_show++ unless $in_show_handler; + $pass_event_handler_event++ if $event->type == SDL_KEYDOWN; + $pass_event_handler_app++ if $caller == $app; + $app->stop if $event->type == SDL_MOUSEBUTTONUP; + }, + sub { + $pass_stopped++ if $app->stopped; + }, + ], + show_handlers => [sub { + if($app->stopped) { + $pass_stopped++; + return; + } + + $in_show_handler++; + + my $event = SDL::Event->new; + $event->type(SDL_KEYDOWN); + my $other_event = SDL::Event->new; + $other_event->type(SDL_MOUSEBUTTONUP); + SDL::Events::push_event($event); + SDL::Events::push_event($event); + SDL::Events::push_event($other_event); + }], + ); + $app->run; + + ok( $app->stopped, 'stopped true after run' ); + ok( !$fail_event_before_show, 'event handlers not called before show' ); + is( $pass_stop_handler_event, 2, 'stop handler got correct event' ); + is( $pass_stop_handler_app, 3, 'stop handler got app' ); + is( $pass_event_handler_event, 2, 'event handler got correct event' ); + is( $pass_event_handler_app, 3, 'event handler got app' ); + is( $pass_stopped, 2, 'stopped true within cycle' ); + ok( !$fail_stopped, 'stopped not true before stopped' ); + is( $in_show_handler, 1, 'got into the show handler once' ); +} + +my ($dummy_ref1, $dummy_ref2, $dummy_ref3) = ([], [sub {}, \&dummy_sub], [\&dummy_sub2, sub {}, sub {}]); + +# constructor set params $app = SDLx::Controller->new( - dt => 0.1, - min_t => 0.5, + dt => 0.1255, + min_t => 0.467, + max_t => 43, + event => $event, + event_handlers => $dummy_ref1, + move_handlers => $dummy_ref2, + show_handlers => $dummy_ref3, + delay => 0.262, + time => 99, + stop_handler => \&dummy_sub2, ); isa_ok( $app, 'SDLx::Controller' ); -is($app->dt, 0.1, 'new dt set to 0.1'); -is($app->min_t, 0.5, 'new min_t set to 0.5' ); +is($app->dt, 0.1255, 'dt set in constructor'); +is($app->min_t, 0.467, 'min_t set in constructor' ); +is($app->max_t, 43, 'max_t set in constructor' ); +is($app->event, $event, 'event set in constructor' ); +is($app->event_handlers, $dummy_ref1, 'event_handlers set in constructor' ); +is($app->move_handlers, $dummy_ref2, 'move_handlers set in constructor' ); +is($app->show_handlers, $dummy_ref3, 'show_handlers set in constructor' ); +is($app->delay, 0.262, 'delay set in constructor' ); +is($app->time, 99, 'time set in constructor' ); +is($app->stop_handler, \&dummy_sub2, 'stop_handler set in constructor' ); +# and now the app for the next part of testing +$app = SDLx::Controller->new( + dt => 0.1, + min_t => 0.5, + max_t => 1e9999, +); sub dummy_sub {1} sub dummy_sub2 {1} -my @kinds = qw(move show); - -# SDL events need a video surface to work -my $videodriver = $ENV{SDL_VIDEODRIVER}; -$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING}; -push @kinds, 'event' - if SDL::TestTool->init(SDL_INIT_VIDEO) - and SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE ); +my @kinds = qw(move show event); foreach my $kind (@kinds) { my $method = "add_${kind}_handler"; @@ -150,5 +404,10 @@ $app->run(); cmp_ok($move_inc, '>=', 30, 'called our motion handlers at least 30 times'); is($show_inc, 30, 'called our show handlers exactly 30 times'); +ok( $app->stopped, 'stopped is true after the app is stopped' ); +ok( !$app->paused, 'paused is false. none of that' ); + +# deprecated +cmp_ok( $app->ticks, '>', 0, 'ticks is deprecated but still works' ); done_testing; diff --git a/t/sdlx_controller_interface.t b/t/sdlx_controller_interface.t index 307830fc..7f91a9e8 100644 --- a/t/sdlx_controller_interface.t +++ b/t/sdlx_controller_interface.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use SDL; use SDLx::App; +use SDL::Events; use SDLx::Controller; use SDLx::Controller::State; use SDLx::Controller::Interface; @@ -79,6 +80,7 @@ my $event_called = 0; require SDL::Event; require SDL::Events; my $eve = SDL::Event->new(); + $eve->type(SDL_USEREVENT); SDL::Events::push_event($eve); my $counts = [ 0, 0, 0 ]; diff --git a/t/sdlx_fps.t b/t/sdlx_fps.t index a168b607..e9294025 100644 --- a/t/sdlx_fps.t +++ b/t/sdlx_fps.t @@ -31,7 +31,9 @@ is( $fps->get, $_fps, 'fps->get' ); is( $fps->rate, $_fps, 'fps->rate' ); cmp_ok( $fps->lastticks, '>=', $ticks_start, 'fps->lastticks' ); -cmp_ok( $fps->lastticks, '<=', $ticks_init, 'fps->lastticks' ); +# Since SDL_gfx version 2.0.24 the ticks we get are always non-zero, +# but SDL can still report 0 as $ticks_init, and then the test had failed. +cmp_ok( $fps->lastticks, '<=', ($ticks_init || 1), 'fps->lastticks' ); # rateticks is Uint32, so precision differs ok( $fps->rateticks - 1000 / $_fps < 0.000001, 'fps->rateticks' ); @@ -51,7 +53,7 @@ $fps->delay; my $ticks_post_delay = SDL::get_ticks(); cmp_ok( $fps->lastticks, '>=', $ticks_pre_delay, 'fps->lastticks after fps->delay' ); -cmp_ok( $fps->lastticks, '<=', $ticks_post_delay, 'fps->lastticks after fps->delay' ); +cmp_ok( $fps->lastticks, '<=', ($ticks_post_delay || 1), 'fps->lastticks after fps->delay' ); $fps = SDLx::FPS->new(); is( $fps->get, 30, 'fps->get default value' ); diff --git a/t/sdlx_sound.t b/t/sdlx_sound.t index a639d21f..c63f21ec 100644 --- a/t/sdlx_sound.t +++ b/t/sdlx_sound.t @@ -1,5 +1,8 @@ # basic testing of SDLx::Sound +use strict; +use warnings; + my $audiodriver; BEGIN { diff --git a/t/sdlx_surface.t b/t/sdlx_surface.t index b524c92c..943f3b03 100644 --- a/t/sdlx_surface.t +++ b/t/sdlx_surface.t @@ -241,6 +241,10 @@ is( $surf_dup->format->BitsPerPixel, 'Duplicate surf has same bpp' ); +$surf_dup->clip_rect( SDL::Rect->new ( 10, 10, 40, 50 )) ; +my $r = $surf_dup->clip_rect ; +is_deeply( [ map { $r->$_ } qw/x y w h/ ], [ 10, 10, 40 ,50 ], "set and get clip_rect work") ; + if ($videodriver) { $ENV{SDL_VIDEODRIVER} = $videodriver; } else { diff --git a/t/sdlx_text.t b/t/sdlx_text.t index 0459399d..0727b798 100644 --- a/t/sdlx_text.t +++ b/t/sdlx_text.t @@ -1,4 +1,5 @@ use strict; +use warnings; use SDL; use SDL::Config; use SDL::Color; diff --git a/t/smpeg.t b/t/smpeg.t index 65977d1a..d3de8499 100644 --- a/t/smpeg.t +++ b/t/smpeg.t @@ -6,6 +6,7 @@ BEGIN { } use strict; +use warnings; use SDL; use SDL::Config; diff --git a/t/ttf.t b/t/ttf.t index 70d54334..18bdca1c 100644 --- a/t/ttf.t +++ b/t/ttf.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; use SDL::Color; diff --git a/t/ttf_font.t b/t/ttf_font.t index 13fbd7e8..e5a05ca2 100644 --- a/t/ttf_font.t +++ b/t/ttf_font.t @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use SDL; use SDL::Config; diff --git a/test/data/sample.ogg b/test/data/sample.ogg new file mode 100644 index 00000000..3540be62 Binary files /dev/null and b/test/data/sample.ogg differ diff --git a/test/data/silence.ogg b/test/data/silence.ogg new file mode 100644 index 00000000..df793b28 Binary files /dev/null and b/test/data/silence.ogg differ diff --git a/typemap b/typemap index c3ba997a..dd11db1c 100644 --- a/typemap +++ b/typemap @@ -103,6 +103,7 @@ SDL_RWops* O_OBJECT SDL_svg_context* T_PTR int T_IV intArray T_ARRAY +void * T_PTR OUTPUT @@ -111,12 +112,14 @@ O_OBJECT_NPGC O_OBJECT if ($var) { - void** pointers = malloc(3 * sizeof(void*)); - pointers[0] = (void*)$var; - pointers[1] = (void*)PERL_GET_CONTEXT; - Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32)); - *threadid = SDL_ThreadID(); - pointers[2] = (void*)threadid; + Uint32 *threadid; + void** pointers; + pointers = malloc(3 * sizeof(void*)); + pointers[0] = (void*)$var; + pointers[1] = (void*)PERL_GET_CONTEXT; + threadid = (Uint32 *)safemalloc(sizeof(Uint32)); + *threadid = SDL_ThreadID(); + pointers[2] = (void*)threadid; sv_setref_pv( $arg, CLASS, (void*)pointers ); } else { XSRETURN_UNDEF;