From: Tobias Leich Date: Sun, 15 Nov 2009 14:34:30 +0000 (+0100) Subject: added tuts X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3ef54ec01be4b60fc106acc290e3b95c644de00;p=sdlgit%2FSDL-Site.git added tuts --- diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..1915102 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on + +RewriteRule ^(.*)\.html$ index.php?$1 [L] +RewriteRule ^assets/(.*)$ htdocs/assets/$1 [L] diff --git a/cgi-bin/sdl.cgi b/cgi-bin/sdl.cgi old mode 100755 new mode 100644 diff --git a/index.php b/index.php new file mode 100644 index 0000000..6b7ba98 --- /dev/null +++ b/index.php @@ -0,0 +1,16 @@ +' => '
' . file_get_contents("pages/{$_SERVER{'QUERY_STRING'}}.html-inc") . '
')); +} +else +{ + echo strtr($layout, array('
' => '
' . file_get_contents("pages/index.html-inc") . '
')); +} + +?> \ No newline at end of file diff --git a/pages/SDL-Tutorial-Animation.html-inc b/pages/SDL-Tutorial-Animation.html-inc new file mode 100644 index 0000000..51fcdcf --- /dev/null +++ b/pages/SDL-Tutorial-Animation.html-inc @@ -0,0 +1,180 @@ +
+ +

Index

+ +
+ + +

NAME

Top

+
+

SDL::Tutorial::Animation

+ +
+

SYNOPSIS

Top

+
+
	# to read this tutorial
+	$ perldoc SDL::Tutorial::Animation
+
+	# to create a demo animation program based on this tutorial
+	$ perl -MSDL::Tutorial::Animation=sdl_anim.pl -e 1
+
+
+ +
+

ANIMATING A RECTANGLE

Top

+
+

Now that you can display a rectangle on the screen, the next step is to animate +that rectangle. As with movies, there's no actual motion. Computer animations are just very very fast slideshows. The hard work is creating nearly identical images in every slide (or frame, in graphics terms).

+

Okay, it's not that difficult.

+

There is one small difficulty to address, however. Once you blit one surface +onto another, the destination is changed permanently. There's no concept of +layers here unless you write it yourself. If you fail to take this into +account (and just about everyone does at first), you'll end up with blurry +graphics moving around on the screen.

+

There are two approaches to solve this problem, redrawing the screen on every +frame and saving and restoring the background for every object drawn.

+ +
+

Redrawing the Screen

+
+

Since you have to draw the screen in the right order once to start with it's +pretty easy to make this into a loop and redraw things in the right order for +every frame. Given a SDL::App object $app, a SDL::Rect $rect, and +a SDL::Color $color, you only have to create a new SDL::Rect $bg, +representing the whole of the background surface and a new SDL::Color +$bg_color, representing the background color. You can write a +draw_frame() function as follows:

+

 

+
	sub draw_frame
+	{
+		my ($app, %args) = @_;
+
+		$app->fill( $args{ bg }, $args{ bg_color } );
+		$app->fill( $args{rect}, $args{rect_color} );
+		$app->update( $args{bg} );
+	}
+
+
+

 

+

Since you can change the x and y coordinates of a rect with the x() +and y() methods, you can move a rectangle across the screen with a loop like +this:

+

 

+
	for my $x (0 .. 640)
+	{
+		$rect->x( $x );
+		draw_frame( $app,
+			bg   => $bg,   bg_color   => $bg_color,
+			rect => $rect, rect_color => $color,
+		);
+	}
+
+
+

 

+

If $rect's starting y position is 190 and its height and width are 100, the +rectangle (er, square) will move across the middle of the screen.

+

Provided you can keep track of the proper order in which to redraw rectangles +and provided you don't need the optimal speed necessary (since blitting every +object takes more work than just blitting the portions you need), this works +quite well.

+ +
+

Undrawing the Updated Rectangle

+
+

If you need more speed or want to make a different complexity tradeoff, you can +take a snapshot of the destination rectangle before you blit onto it. That +way, when you need to redraw, you can blit the old snapshot back before +blitting to the new position.

+

Note: I have no idea how this will work in the face of alpha blending, +which, admittedly, I haven't even mentioned yet. If you don't know what this +means, forget it. If you do know what this means and know why I'm waving my +hands here, feel free to explain what should and what does happen and why. :)

+

With this technique, the frame-drawing subroutine has to be a little more +complicated. Instead of the background rect, it needs a rect for the previous +position. It also needs to do two updates (or must perform some scary math to +figure out the rectangle of the correct size to update(). No thanks!).

+

 

+
	sub undraw_redraw_rect
+	{
+		my ($app, %args) = @_;
+
+		$app->fill(   $args{old_rect}, $args{bg_color}   );
+		$app->fill(   $args{rect],     $args{rect_color} );
+		$app->update( $args{old_rect}, $args{rect}       );
+	}
+
+
+

 

+

We'll need to create a new SDL::Rect, $old_rect, that is a duplicate of +$rect, at the same position at first. You should already know how to do +this.

+

As before, the loop to call undraw_redraw_rect() would look something like:

+

 

+
	for my $x (0 .. 640)
+	{
+		$rect->x( $x );
+
+		undraw_redraw_rect( $app,
+			rect       => $rect,  old_rect => $old_rect,
+			rect_color => $color, bg_color => $bgcolor,
+		);
+
+		$old_rect->x( $x );
+	}
+
+
+

 

+

If you run this code, you'll probably notice that it's tremendously faster than +the previous version. It may be too fast, where the alternate technique was +just fast enough. There are a couple of good ways to set a fixed animation +speed regardless of the speed of the processor and graphics hardware (provided +they're good enough, which is increasingly often the case), and we'll get to +them soon.

+ +
+

SEE ALSO

Top

+
+
+
SDL::Tutorial::Drawing
+
+

basic drawing with SDL Perl

+
+
SDL::Tutorial::Images
+
+

animating images

+
+
+ +
+

AUTHOR

Top

+
+

chromatic, <chromatic@wgz.org>

+

Written for and maintained by the Perl SDL project, http://sdl.perl.org/.

+ +
+

BUGS

Top

+
+

No known bugs.

+ +
+

COPYRIGHT

Top

+ +
\ No newline at end of file diff --git a/pages/SDL-Tutorial-Images.html-inc b/pages/SDL-Tutorial-Images.html-inc new file mode 100644 index 0000000..6c9aa01 --- /dev/null +++ b/pages/SDL-Tutorial-Images.html-inc @@ -0,0 +1,224 @@ +
+ +

Index

+ +
+ + +

NAME

Top

+
+

SDL::Tutorial::Images

+ +
+

SYNOPSIS

Top

+
+
	# to read this tutorial
+	$ perldoc SDL::Tutorial::Images
+
+	# to create a demo animation program based on this tutorial
+	$ perl -MSDL::Tutorial::Images=sdl_images.pl -e 1
+
+
+ +
+

ANIMATING IMAGES

Top

+
+

Since you're already familiar with the concepts behind animation, it's time to +learn how to work with images. As usual, the important point is that computer animation is just simulating motion by painting several slightly different frames to the screen every second.

+

There are two ways to vary an image on screen. One is to change its +coordinates so it's at a slightly different position. This is very easy to do; +it's just like animating a rectangle. The other way is to change the image +itself so it's slightly different. This is a little more difficult, as you'll +need to draw the alternate image beforehand somehow.

+ +
+

Loading Images

+
+

As usual, start with an SDL::App object representing the image window. Then +preload the image file. This is easy; just pass the name parameter to the +SDL::Surface constructor:

+

 

+
	use SDL::Surface;
+
+	my $frame = SDL::Surface->new( -name => 'frame1.png' );
+
+
+

 

+

Note: you'll need to have compiled SDL Perl (and probably SDL) to support +JPEG and PNG files for this to work.

+

That's it; now you have an SDL::Surface object containing the image. You can +use the height(), width(), and bpp() methods to retrieve its height, +width, and bits per pixel, if you need them.

+ +
+

Displaying Images

+
+

Drawing an image onto the screen requires blitting it from one surface to +another. (Remember, "blitting" means copying bits in memory.) The blit() +method of SDL::Surface objects comes in handy. Its arguments are a little odd, +though. Assuming $app is the SDL::App object, as usual:

+

 

+
	use SDL::Rect;
+
+	my $frame_rect = SDL::Rect->new(
+		-height => $frame->height(),
+		-width  => $frame->width(),
+		-x      => 0,
+		-y      => 0,
+	);
+
+	my $dest_rect  = SDL::Rect->new(
+		-height => $frame->height(),
+		-width  => $frame->width(),
+		-x      => 0,
+		-y      => 0,
+	);
+
+	$frame->blit( $frame_rect, $app, $dest_rect );
+	$app->update( $dest_rect );
+
+
+

 

+

Here we have two SDL::Rect objects which represent rectangular regions of a +Surface. $frame_rect represents the entire area of $frame, while +$dest_rect represents the area of the main window in which to blit the +frame. This may be clearer with more descriptive variable names:

+

 

+
	$source_surface->blit(
+		$area_of_source_to_blit,
+		$destination_surface,
+		$destination_area
+	);
+
+
+

 

+

As usual, call update() on $app to see the change.

+

Requiring the source and destination Rect objects may seem tedious in this +simple example, but it's highly useful for copying only part of surface to part +of another. For example, animating this image is a matter of changing the x +and y coordinates of $dest_rect:

+

 

+
	for my $x ( 1 .. 100 )
+	{
+		$dest_rect->x( $x );
+		$frame->blit( $frame_rect, $app, $dest_rect );
+		$app->update( $dest_rect );
+	}
+
+
+

 

+

Of course, you'll have to redraw all or part of the screen to avoid artifacts, +as discussed in the previous tutorial.

+ +
+

Multi-Image Animation

+
+

That covers moving a single image around the screen. What if you want +something more? For example, what if you want to animate a stick figure +walking?

+

You'll need several frames, just as in a flip-book. Each frame should be slightly different than the one before it. It's probably handy to encapsulate all of this in a Walker class:

+

 

+
	package Walker;
+
+	use SDL::Surface;
+
+	sub new
+	{
+		my ($class, @images) = @_;
+		my $self = [ map { SDL::Surface->new( -name => $_ ) } @images ];
+
+		bless $self, $class;
+	}
+
+	sub next_frame
+	{
+		my $self  = shift;
+		my $frame = shift @$self;
+
+		push @$self, $frame;
+		return $frame;
+	}
+
+
+

 

+

To use this class, instantiate an object:

+

 

+
	my $walker = Walker->new( 'frame1.png', 'frame2.png', 'frame3.png' );
+
+
+

 

+

Then call next_frame() within the loop:

+

 

+
	for my $x ( 1 .. 100 )
+	{
+		my $frame = $walker->next_frame();
+
+		$dest_rect->x( $x );
+		$frame->blit( $frame_rect, $app, $dest_rect );
+		$app->update( $dest_rect );
+	}
+
+
+

 

+

Again, the rest of the frame drawing is missing from this example so as not to +distract from this technique. You'll probably want to abstract the undrawing +and redrawing into a separate subroutine so you don't have to worry about it +every time.

+

It'd be easy to make next_frame() much smarter, selecting an image +appropriate to the direction of travel, using a bored animation when the +character is no longer moving, or adding other characteristics to the +character. As you can see, the hard part of this technique is generating the +images beforehand. That can add up to a tremendous amount of art and that's +one reason for the popularity of 3D models... but that's another tutorial much +further down the road.

+

More importantly, it's time to discuss how to make these animations run more +smoothly. More on that next time.

+ +
+

SEE ALSO

Top

+
+
+
SDL::Tutorial
+
+

basic SDL tutorial

+
+
SDL::Tutorial::Animation
+
+

non-image animation

+
+
+ +
+

AUTHOR

Top

+
+

chromatic, <chromatic@wgz.org>

+

Written for and maintained by the Perl SDL project, http://sdl.perl.org/.

+ +
+

BUGS

Top

+
+

No known bugs.

+ +
+

COPYRIGHT

Top

+ +
\ No newline at end of file diff --git a/pages/SDL-Tutorial-LunarLander.html-inc b/pages/SDL-Tutorial-LunarLander.html-inc new file mode 100644 index 0000000..2efac82 --- /dev/null +++ b/pages/SDL-Tutorial-LunarLander.html-inc @@ -0,0 +1,302 @@ +
+ +

Index

+ +
+ + +

NAME

Top

+
+

Lunar Lander - a small tutorial on Perl SDL

+ +
+

INTRODUCTION

Top

+
+

This is a quick introduction to Games, Perl, and SDL (Simple +DirectMedia Layer, a cross-platform multimedia programming +library). We'll write a small game -- Lunar Lander -- in 100 +lines of code, or less.

+ +
+

CREATING A DEMO

+
+

You can see the final version of the demo code by doing:

+

 

+
   perl -MSDL::Tutorial::LunarLander=lander.pl -e1
+
+
+

 

+

this will create all three files used in the tutorial:

+ + + + + +
+

FIRST VERSION

+
+

We'll start with a text version of the game.

+

"What?", you may ask. "I thought it was a SDL tutorial".

+

Yes, it is -- thank you for reminding me. But we'll leave the SDL part for +later. We must build the game logic first!

+

One of the traps of game programming is focusing too much on the interface. +If we start with a simpler simulation, we can worry with the presentation +later.

+

So, here's the initial code:

+

 

+
    #!/usr/bin/perl
+
+    use strict;
+    use warnings;
+
+    my $height   = 1000; # m
+    my $velocity = 0;    # m/s
+    my $gravity  = 1;    # m/s^2
+
+    my $t = 0;
+
+    while ( $height > 0 ) {
+        print "at $t s height = $height m, velocity = $velocity m/s\n";
+
+        $height   = $height - $velocity;
+        $velocity = $velocity + $gravity;
+        $t        = $t + 1;
+    }
+
+    if ( $velocity > 10 ) {
+        print "CRASH!!!\n";
+    } else {
+        print "You landed on the surface safely! :-D\n";
+    }
+
+
+

 

+

Run the code and you'll see something like this:

+

 

+
    at 0 s height = 1000 m, velocity = 0 m/s
+    at 1 s height = 1000 m, velocity = 1 m/s
+    at 2 s height = 999 m, velocity = 2 m/s
+    at 3 s height = 997 m, velocity = 3 m/s
+    at 4 s height = 994 m, velocity = 4 m/s
+    at 5 s height = 990 m, velocity = 5 m/s
+    ...
+    at 43 s height = 97 m, velocity = 43 m/s
+    at 44 s height = 54 m, velocity = 44 m/s
+    at 45 s height = 10 m, velocity = 45 m/s
+
+    CRASH!!!
+
+
+

 

+

"What happened? How do I control the ship???"

+ +
+

CONTROLLING THE SHIP

+
+

The problem with our first spaceship is that it had no controls!

+

So, let's fix this problem, making the spaceship scriptable. (We +could write some code to handle keyboard and joysticks now, but +an scriptable spaceship will be easier to start. Remember, focus +on the game logic!)

+

So, create add this simple script to the end of your file:

+

 

+
    __DATA__
+    at 41s, accelerate 10 m/s^2 up
+    at 43s, 10 m/s^2
+    at 45s, 10
+    at 47s, 10
+    at 49s, 10
+
+
+

 

+

The script is straightforward: it simply states a time when we +will push the spaceship up with a given acceleration. It accepts +free text: any two numbers you type will work.

+

We can parse the script using this regular expression:

+

 

+
    my $script_re = qr/(\d+) \D+ (\d+)/x;
+
+
+

 

+

And we can build a hash of ( time => acceleration ) with:

+

 

+
    my %up = map { $_ =~ $script_re } <DATA>;
+
+
+

 

+

So the middle section of the program will become:

+

 

+
    my $script_re = qr/(\d+) \D+ (\d+)/x;
+    my %up = map { $_ =~ $script_re } <DATA>;
+
+    while ( $height > 0 ) {
+        print "at $t s height = $height m, velocity = $velocity m/s\n";
+
+        if ( $up{$t} ) {
+            my $a = $up{$t};
+            print "(accellerating $a m/s^2)\n";
+            $velocity = $velocity - $a;
+        }
+
+        $height   = $height - $velocity;
+        $velocity = $velocity + $gravity;
+        $t        = $t + 1;
+    }
+
+
+

 

+

That's it!

+

Try to run the program, and the ship should land safely:

+

 

+
    ./lunar.pl autopilot.txt 
+    at 0 s height = 1000 m, velocity = 0 m/s
+    at 1 s height = 1000 m, velocity = 1 m/s
+    at 2 s height = 999 m, velocity = 2 m/s
+    at 3 s height = 997 m, velocity = 3 m/s
+    at 4 s height = 994 m, velocity = 4 m/s
+    at 5 s height = 990 m, velocity = 5 m/s
+    ...
+    at 54 s height = 19 m, velocity = 4 m/s
+    at 55 s height = 15 m, velocity = 5 m/s
+    at 56 s height = 10 m, velocity = 6 m/s
+    at 57 s height = 4 m, velocity = 7 m/s
+
+    You landed on the surface safely! :-D
+
+
+

 

+

Cool, but...

+ +
+

HOW ABOUT THE GRAPHICS?

+
+

Okay, okay... now that we have a working prototype, we can work on +the graphics. But, first of all, we'll need...

+ +
+

THE GRAPHICS

+
+

Yes, the graphics.

+

We won't use anything fancy here, just two images: a large one, for +the background, and a smaller one for the spaceship.

+

Create the images using the Gimp, or use the images provided by +this tutorial; Save these images in a subdirectory called "images": +("images/background.jpg" and "images/ship.png").

+ +
+

USING SDL

+
+

First step: use the required libraries:

+

 

+
    use SDL; #needed to get all constants
+    use SDL::App;
+    use SDL::Surface;
+    use SDL::Rect;
+
+
+

 

+

Second step: initialize SDL::App:

+

 

+
    my $app = SDL::App->new(
+        -title  => "Lunar Lander",
+        -width  => 800,
+        -height => 600,
+        -depth  => 32,
+    );
+
+
+

 

+

Third step: load the images and create the necessary "rectangles":

+

 

+
    my $background = SDL::Surface->new( -name => 'images/background.jpg', );
+    my $ship       = SDL::Surface->new( -name => 'images/ship.png', );
+
+    my $background_rect = SDL::Rect->new(
+        -height => $background->height(),
+        -width  => $background->width(),
+    );
+
+    my $ship_rect = SDL::Rect->new(
+        -height => $ship->height(),
+        -width  => $ship->width(),
+    );
+
+
+

 

+

Fourth step: create a sub to draw the spaceship and background:

+

 

+
    sub draw {
+        my ( $x, $y ) = @_; # spaceship position
+
+        # fix $y for screen resolution
+        $y = 450 * ( 1000 - $y ) / 1000;
+
+        # background
+        $background->blit( $background_rect, $app, $background_rect );
+
+        # ship
+        my $ship_dest_rect = SDL::Rect->new(
+            -height => $ship->height(),
+            -width  => $ship->width(),
+            -x      => $x,
+            -y      => $y,
+        );
+
+        $ship->blit( $ship_rect, $app, $ship_dest_rect );
+
+        $app->update($background_rect);
+    }
+
+
+

 

+

Note that this sub first combines all the bitmaps, using a blit +("Block Image Transfer") operation -- which is quite fast, but does +not update the display.

+

The combined image is displayed in the last line. This process of +combining first, and displaying later, avoids that annoying fading +between cycles ("flickering").

+

Finally, add the following lines to the end of the main loop, so that +we call the draw() function with the correct spaceship +coordinates:

+

 

+
    while ( $height > 0 ) {
+
+        # ...
+
+        draw( 100, $height );
+        $app->delay(10);
+    }
+
+
+

 

+

That's it!

+

Run the program and watch the spaceship landing safely on the surface +of the moon.

+ +
+

COPYRIGHT & LICENSE

Top

+ +
\ No newline at end of file diff --git a/pages/SDL-Tutorial-Pong.html-inc b/pages/SDL-Tutorial-Pong.html-inc new file mode 100644 index 0000000..a0e0d9a --- /dev/null +++ b/pages/SDL-Tutorial-Pong.html-inc @@ -0,0 +1,166 @@ +
+ +

Index

+ +
+ + +

PONG TUTORIAL

Top

+
+

This tutorial is intended to help you build your very own version of the Pong game and/or variations of it, using SDL Perl.

+

Just in case you live under a rock, Pong is one of the earliest arcade games, a true classic by Atari Inc. The game has two simple rectangles scrolling up and down trying to hit a (square) ball that bounces around, and could be thought of as a table tennis simulation.

+ +
+

Part 1: We start with a Rect

+
+

In Pong, the player controls a rectangle that moves up and down, so creating the rectangle looks like a good place to start:

+

 

+
   my $player = SDL::Game::Rect->new({
+                       -top    => 10,
+                       -left   => 20,
+                       -width  => 6,
+                       -height => 32,
+                });
+
+
+

 

+

That creates a new SDL::Game::Rect object, a rectangle, with the given width/height dimensions and in the given top/left position of the screen.

+

Wait. Did I say... <screen>?

+ +
+

Part 0: "The Screen"

+
+

In SDL Perl, creating a window screen is very easy and straightforward:

+

 

+
  use SDL;
+  use SDL::App;
+
+  my $app = SDL::App->new(
+                 -title  => 'Pong',  # set window title
+                 -width  => 640,     # window width
+                 -height => 480,     # window height
+          );
+
+
+

 

+

That's it. If you run this code, you'll see a window appear and disappear almost instantly. Why doesn't it stay up? Well, the code is processed linearly, like usual programs are, and with no hidden magic. So, you basically said "create a window" and then the program ended - destroying the window. In order to keep it up and running, listening for events, you need an event loop.

+ +
+

Creating an (empty) event loop

+
+

An event loop is a simple infinite loop that captures events (like a key pressed or released from the keyboard, mouse movement, etc) and either does something about it or dispatches it to any object that might.

+

For this simple game we don't need a very sofisticated event loop, so let's create a simple one.

+

 

+
  event_loop() while 1;
+
+
+

 

+

Yay, an infinite loop! Now we are free to define our very own event loop any way we want. Let's make it an empty sub for starters:

+

 

+
  sub event_loop {
+  }
+
+
+

 

+

Ok. If you run it, you'll see your $app window displayed until you force to shutdown the program by typing Ctrl-C or something. Other than that, our event loop doesn't do anything,

+ +
+

Part 1 (cont.) - Drawing our Rect on the screen

+
+

# TODO

+ +
+

Part 2 - Our first event: tracking user movement

+
+

# TODO

+

Now let's query some events!

+

First, we need to use the SDL::Event module. Add this to the beginning of our code:

+

 

+
  use SDL::Event;
+  my $event = SDL::Event->new;
+
+
+

 

+ + + + +

Now let's rewrite the event_loop subroutine to take advantage of our event object. The new subroutine should look like this:

+

 

+
  sub event_loop {
+      # first we poll if an event occurred...
+      while ($event->poll) {
+
+          # if there is an event, we check its type
+          my $type = $event->type
+
+          # handle window closing
+          exit if $type == SDL_QUIT;
+      }
+  }
+
+
+

 

+

#TODO

+ +
+

Hey, don't move away from the court! Our first collision detection.

+
+ +
+

Part 3 - Enter "the Ball"

+
+

#TODO

+ +
+

Some vetorial background

+
+

#TODO

+ +
+

Part 4 - Collision Detection

+
+

#TODO

+ +
+

Part 5 - Our hero's nemesis appears

+
+

#TODO

+ +
+

(really) basic IA

+
+

#TODO

+ +
+

Part 6 - Counting (and showing) the score

+
+

#TODO +

+ +
+
\ No newline at end of file diff --git a/pages/SDL-Tutorial-Tetris.html-inc b/pages/SDL-Tutorial-Tetris.html-inc new file mode 100644 index 0000000..c4d9f6a --- /dev/null +++ b/pages/SDL-Tutorial-Tetris.html-inc @@ -0,0 +1,65 @@ +
+ +

Index

+ +
+ + +

NAME

Top

+
+

Let's Make Tetris

+ +
+

The Overall view

+
+

All games are a while loop. So we will have something like this.

+ +
+

The Game Loop

+
+
 package Tetris;
+
+ sub run_game_fun_times
+ {
+  while(1)
+  {
+   #game logic here
+  }
+ }	
+
+
+

You need more code you say? Ok well, a game does two things more.

+ +
+

The Game Logic

+
+
+
Input Events
+
+

A game essentially move objects (boxes, monsters so on) in time.

+

+

+
Time
+
+

In SDL time is measured in ticks.

+
+
User Input
+
+

+
+
Draw Everything
+
+

--Kartik +

+ +
+
\ No newline at end of file diff --git a/pages/documentation.html-inc b/pages/documentation.html-inc index d16d709..26532a2 100644 --- a/pages/documentation.html-inc +++ b/pages/documentation.html-inc @@ -1,2 +1,2 @@ +

Documentation (latest development branch)

SDL
SDL::App
SDL::Cdrom
SDL::Color
SDL::Cookbook
SDL::Cookbook::PDL
SDL::Cursor
SDL::Event
SDL::Events
SDL::Font
SDL::Game::Palette
SDL::MPEG
SDL::Mixer
SDL::MultiThread
SDL::Music
SDL::OpenGL
SDL::Overlay
SDL::Palette
SDL::PixelFormat
SDL::Rect
SDL::SFont
SDL::SMPEG
SDL::Sound
SDL::Surface
SDL::TTFont
SDL::Timer
SDL::Tool::Font
SDL::Tool::Graphic
SDL::Tutorial
SDL::Tutorial::Animation
SDL::Tutorial::Images
SDL::Tutorial::LunarLander
SDL::Tutorial::Pong
SDL::Tutorial::Tetris
SDL::Video
SDL::VideoInfo
diff --git a/tools/PM-Pod2html-snippet.pl b/tools/PM-Pod2html-snippet.pl new file mode 100644 index 0000000..816558f --- /dev/null +++ b/tools/PM-Pod2html-snippet.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use File::Spec; +use Pod::Xhtml; + +#system('git pull'); + +my $input_path = 'C:/SDL_perl/lib/pods'; +my $output_path = 'F:/htdocs/SDL-Site/pages'; +my $parser = Pod::Xhtml->new(FragmentOnly => 1); +my %module_names = (); +my $fh; + +read_file($input_path); + +# creating index file +open($fh, '>', File::Spec->catfile($output_path, 'documentation.html-inc')); +binmode($fh, ":utf8"); +print($fh "
\n

Documentation (latest development branch)

"); +for my $module_name (sort keys %module_names) +{ + print($fh '', + $module_name, + '
' + ); +} +print($fh "
\n"); +close($fh); + +sub read_file +{ + my $path = shift; + my @files = <$path/*>; + + foreach(@files) + { + read_file($_) if(-d $_); + + if($_ =~ /\.pod$/i) + { + my $file_name = $_; + $file_name =~ s/^$input_path\/*//; + my $module_name = $file_name; + $module_name =~ s/\//::/g; + $module_name =~ s/(\.pm|\.pod)$//i; + $file_name =~ s/\//-/g; + $file_name =~ s/(\.pm|\.pod)$/.html-inc/i; + my $file_path = $file_name; + $file_path =~ s/\-inc$//; + $module_names{$module_name} = $file_path; + $file_name = File::Spec->catfile($output_path, $file_name); + + $parser->parse_from_file($_, $file_name); + } + } +} diff --git a/tools/RSS2html-snippet.pl b/tools/RSS2html-snippet.pl new file mode 100644 index 0000000..5a5b59e --- /dev/null +++ b/tools/RSS2html-snippet.pl @@ -0,0 +1,139 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use File::Spec::Functions qw(rel2abs splitpath splitdir catpath catdir catfile canonpath); +use XML::Feed; + +my $feed = XML::Feed->parse(URI->new('http://yapgh.blogspot.com/feeds/posts/default?alt=rss')) + or die XML::Feed->errstr; + +my ($volume, $dirs) = splitpath(rel2abs(__FILE__)); + +my @directories = splitdir(canonpath($dirs)); +pop(@directories); +my $parent_dir = catpath($volume, catdir(@directories)); +my $output_path = catdir($parent_dir, 'pages'); + +die("Error: Output path '$output_path' not found.") unless(-d $output_path); + +my $fh; +my %available_tags = (); # tags to filenames +my %tag_overview = (); # tags to short content + +printf("path for placing files is: %s\n", $output_path); + +my $i = 1; +for my $entry ($feed->entries) +{ + my $output_file = sprintf("blog-%04d.html-inc", $i); + my @tags = $entry->tags; + + foreach my $tag (sort @tags) + { + @{$available_tags{$tag}} = () unless defined ($available_tags{$tag}); + push(@{$available_tags{$tag}}, $output_file); + } + + open($fh, '>', catfile($output_path, $output_file)); + binmode($fh, ":utf8"); + print($fh "
\n

\n", + $entry->title, + "\n

\n
\n", + $entry->content->body, + "
", + "
" + ); + close($fh); + + printf("created file: %s\n", $output_file); + + $i++; +} + +open($fh, '>', catfile($output_path, 'blog-0000.html-inc')); +binmode($fh, ":utf8"); +print($fh "

Articles

\n"); +$i = 1; +for my $entry ($feed->entries) +{ + my $tag_links = ''; + my @tags = $entry->tags; + foreach my $tag (sort @tags) + { + my $_tag = $tag; + $_tag =~ s/\W/-/g; + $tag_links .= sprintf(' [%s]', $_tag, $tag); + } + + my $text = $entry->content->body; + $text = $1 if $text =~ /^(.+)$/; + $text =~ s//\n/g; + $text =~ s/<[@#%\w\s"\/?&=:\-\.;']+>/ /g; + $text =~ s/^\n*//g; + $text =~ s/\n*$//g; + $text =~ s/\n+/\n/g; + $text =~ s/\n/
/g; + $text = $1 if $text =~ /^([^<>]+
[^<>]+
[^<>]+
).*$/; + $text =~ s/(
)+$//g; + + # overview of all blog entries + printf($fh '
' + . '%s
' + . '%s
' + . 'Tags:%s
' + . '%s
[more]

' + . '
' + . '
', + $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i + ); + + # preparing the %tag_overview hash for tag-overview-pages + @tags = $entry->tags; + foreach my $tag (sort @tags) + { + @{$tag_overview{$tag}} = () unless defined ($tag_overview{$tag}); + push(@{$tag_overview{$tag}}, + sprintf('
' + . '%s
' + . '%s
' + . 'Tags: %s
' + . '%s
[more]

' + . '
', + $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i + )); + } + + $i++; +} +print($fh "
\n"); +close($fh); +printf("created file: %s\n", 'blog-0000.html-inc'); + + +# csv: "tagname: file1,file2\n" +open($fh, '>', catfile($output_path, 'tags-index')); +binmode($fh, ":utf8"); +foreach my $tag (sort keys %available_tags) +{ + printf($fh "%s: %s\n", $tag, join(',', @{$available_tags{$tag}})); +} +close($fh); +printf("created file: %s\n", 'tags-index'); + +# overview pages for tags +foreach my $tag (sort keys %tag_overview) +{ + my $_tag = $tag; + $_tag =~ s/\W/-/g; + open($fh, '>', catfile($output_path, 'tags-' . $_tag . '.html-inc')); + binmode($fh, ":utf8"); + print($fh '

Results for tag: ' . $tag . '

' + . join('
', @{$tag_overview{$tag}}) + . '
'); + close($fh); + printf("created file: %s\n", 'tags-' . $_tag . '.html-inc'); +} +