Hi Jesus, <div><br></div><div><br></div><div><div class="gmail_quote">On Sat, Jul 3, 2010 at 3:59 AM, Jesus Mager <span dir="ltr"><<a href="mailto:fongog@gmail.com">fongog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
Hi david (and all)!<br><br>Thank you. I want to write code that can read a campaign file for<br>tuxhistory. This file should be a compressed file that contains map<br>files, lua scripts, etc... Mainly I need a transparent access to this<br>
files (I don't need inflate the files in a directory) to load the<br>content in to memory. I was searching, but cant find any good resource<br>to do that with zlib. I found a very good article [1], but it only<br>shows a transparent access for one compressed file using zlib. The<br>
same text illustrates a good way to access multiple files using<br>zzip[2]. Even though the library seems to be written in ANSI-C some<br>comments specifics multiplaform/cross compiling problems. Any idea to<br>deal this issue?<br>
<br>[1] <a href="http://www.kekkai.org/roger/sdl/rwops/rwops.html" target="_blank">http://www.kekkai.org/roger/sdl/rwops/rwops.html</a><br>[2] <a href="http://zziplib.sourceforge.net/" target="_blank">http://zziplib.sourceforge.net/</a><br>
<br>2010/6/30 David Bruce <<a href="mailto:davidstuartbruce@gmail.com">davidstuartbruce@gmail.com</a>>:<br><div class="im">> Hi,<br>><br>> On Wed, Jun 30, 2010 at 11:40 AM, Jesus Mager <<a href="mailto:fongog@gmail.com">fongog@gmail.com</a>> wrote:<br>
>> Hi all!<br>>><br>>> I'm trying to find a good way to compress and inflate the campaing<br>>> files that should contain things like XML files, and in the future LUA<br>>> and other text files. I was thinking zlib is a good option<br>
><br>> I take it you want to save space on the user's HD? Obviously, our<br>> tarballs and installer files are already compressed.<br>><br>> Anyway, zlib is definitely cross-platform and is already part of our<br>
> dependencies (IIRC, SDL_image depends on zlib). Thus, if it does what<br>> needs to be done, you can use it without worrying about having to drag<br>> in additional libs. If that is what you do, we should add a test in<br>
> <a href="http://configure.ac" target="_blank">configure.ac</a> to directly test for it, just so we still know that it is<br>> available even if a future version of SDL_image no longer uses it.<br>><br>> Cheers,<br>
><br>> David<br>><br><br><br><br>--<br></div><div class="im">Jesus Mager<br>[<a href="http://www.h1n1-al.blogspot.com" target="_blank">www.h1n1-al.blogspot.com</a>]<br><br></div>_______________________________________________<br>
Tux4kids-tuxtype-dev mailing list<br><a href="mailto:Tux4kids-tuxtype-dev@lists.alioth.debian.org">Tux4kids-tuxtype-dev@lists.alioth.debian.org</a><br><a href="http://lists.alioth.debian.org/mailman/listinfo/tux4kids-tuxtype-dev" target="_blank">http://lists.alioth.debian.org/mailman/listinfo/tux4kids-tuxtype-dev</a><br>
</blockquote></div><br></div><div><br></div><div>Won't it work if I make two objects similarly instead of one, that's what they </div><div>seem to have done with zziplib. </div><div><br></div><div><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "><pre>
#include "SDL.h"
#include <stdio.h>
#include <zlib.h>
int main(void) {
SDL_Surface *screen;
SDL_Surface *one;
SDL_Rect rect;
/* This is the RWops structure we'll be using */
SDL_RWops *rw;
/* gzFile is the Zlib equivalent of FILE from stdio */
gzFile file;
/* We'll be needing space to store our graphic into. The penguin
graphic is about 12k, so we'll fake it for now. You'd want to
figure out how much space you need for other graphics in a real
application, though. */
Uint8 buffer[13000];
/* We'll need to store the actual size of the file when it comes in
*/
int filesize;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);
/* Opens up the file with Zlib */
file = gzopen("penguin.gz", "r");
<br></pre><pre> /*Your 2nd compressed file here*/</pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre> file2 = gzopen("number2.gz", "r");</pre>
</span></pre><pre> /* Decompresses the file into memory (the buffer we set aside),
13000 bytes max. gzread returns the number of (decompressed)
bytes it actually read, and we need that information for
later. */
filesize = gzread(file, buffer, 13000);</pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre> filesize2 = gzread(file2, buffer, 13000);</pre></span>
/* Gives us an RWops from memory - SDL_RWFromMem needs to know where
the data is, and how big it is (thus why we saved the filesize)
*/
rw = SDL_RWFromMem(buffer, filesize);
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre> rw2 = SDL_RWFromMem(buffer, filesize2);</pre></span>
/* The function that does the loading doesn't change at all */
one = SDL_LoadBMP_RW(rw, 0);</pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre> two = SDL_LoadBMP_RW(rw2, 0);</pre></span>
/* And clean up */
SDL_FreeRW(rw);
gzclose(file);
/* Haphazard way of getting stuff to the screen */
rect.x = rect.y = 20;
rect.w = one -> w;
rect.y = one -> h;
SDL_BlitSurface(one, NULL, screen, &rect);</pre><pre><br></pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre> rect.x += rect.w + 10;
rect.w = two -> w;
rect.h = two -> h;
SDL_BlitSurface(two, NULL, screen, &rect);
</pre><div><br></div></span>
SDL_Flip(screen);
SDL_Delay(3000);
}</pre></span><br><div class="gmail_quote"><br></div><br>-- <br>Best Regards<br>Akash Gangil<br><br>
</div>