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">&lt;<a href="mailto:fongog@gmail.com">fongog@gmail.com</a>&gt;</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&#39;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 &lt;<a href="mailto:davidstuartbruce@gmail.com">davidstuartbruce@gmail.com</a>&gt;:<br><div class="im">&gt; Hi,<br>&gt;<br>&gt; On Wed, Jun 30, 2010 at 11:40 AM, Jesus Mager &lt;<a href="mailto:fongog@gmail.com">fongog@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Hi all!<br>&gt;&gt;<br>&gt;&gt; I&#39;m trying to find a good way to compress and inflate the campaing<br>&gt;&gt; files that should contain things like XML files, and in the future LUA<br>&gt;&gt; and other text files. I was thinking zlib is a good option<br>
&gt;<br>&gt; I take it you want to save space on the user&#39;s HD?  Obviously, our<br>&gt; tarballs and installer files are already compressed.<br>&gt;<br>&gt; Anyway, zlib is definitely cross-platform and is already part of our<br>
&gt; dependencies (IIRC, SDL_image depends on zlib).  Thus, if it does what<br>&gt; needs to be done, you can use it without worrying about having to drag<br>&gt; in additional libs.  If that is what you do, we should add a test in<br>
&gt; <a href="http://configure.ac" target="_blank">configure.ac</a> to directly test for it, just so we still know that it is<br>&gt; available even if a future version of SDL_image no longer uses it.<br>&gt;<br>&gt; Cheers,<br>
&gt;<br>&gt; David<br>&gt;<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&#39;t it work if I make two objects similarly instead of one, that&#39;s what they </div><div>seem to have done with zziplib. </div><div><br></div><div><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; font-size: medium; "><pre>
#include &quot;SDL.h&quot;
#include &lt;stdio.h&gt;
#include &lt;zlib.h&gt;

int main(void) {
  SDL_Surface *screen;
  SDL_Surface *one;
  SDL_Rect rect;

  /* This is the RWops structure we&#39;ll be using */
  SDL_RWops *rw;

  /* gzFile is the Zlib equivalent of FILE from stdio */
  gzFile file;

  /* We&#39;ll be needing space to store our graphic into.  The penguin
     graphic is about 12k, so we&#39;ll fake it for now.  You&#39;d want to
     figure out how much space you need for other graphics in a real
     application, though. */
  Uint8 buffer[13000];

  /* We&#39;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(&quot;penguin.gz&quot;, &quot;r&quot;);
<br></pre><pre>  /*Your 2nd compressed file here*/</pre><pre><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; white-space: normal; "><pre>  file2 = gzopen(&quot;number2.gz&quot;, &quot;r&quot;);</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: &#39;Times New Roman&#39;; 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: &#39;Times New Roman&#39;; white-space: normal; "><pre>  rw2 = SDL_RWFromMem(buffer, filesize2);</pre></span>
  /* The function that does the loading doesn&#39;t change at all */
  one = SDL_LoadBMP_RW(rw, 0);</pre><pre><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; 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 -&gt; w;
  rect.y = one -&gt; h;
  SDL_BlitSurface(one, NULL, screen, &amp;rect);</pre><pre><br></pre><pre><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; white-space: normal; "><pre>  rect.x += rect.w + 10;
  rect.w = two -&gt; w;
  rect.h = two -&gt; h;
  SDL_BlitSurface(two, NULL, screen, &amp;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>