New type of ResourceBundle - NetworkResourceBundle - This bundle grabs its resources over HTTP from a root URL rather than from a local jar file. To make use of this, we need a way to put all the contents of the bundle into an appropriate directory instead of a jar, including its metadata, so some new Bundler Tasks were created to do this. Finally, allow tile set trimming to be done to a non-raw image format through passing an optional imgFormat parameter. If no parameter is passed, it'll default ot the old behavior of using raw/FastIO. Note that to use network bundles, you can set the set_type in the resource manager.properties file. (e.g. "resource.set_type.tilesets = network") If no set_type is set for a resource set, it defaults to a normal FileResourceBundle

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@343 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2007-11-13 01:12:18 +00:00
parent 785eb10234
commit ee73dd43de
13 changed files with 713 additions and 73 deletions
@@ -33,6 +33,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -166,9 +167,7 @@ public class ComponentBundlerTask extends Task
try {
// make sure we can create our bundle file
FileOutputStream fout = new FileOutputStream(_target);
JarOutputStream jout = new JarOutputStream(fout);
jout.setLevel(Deflater.BEST_COMPRESSION);
OutputStream fout = createOutputStream(_target);
// we'll fill this with component id to tuple mappings
HashIntMap mapping = new HashIntMap();
@@ -206,7 +205,7 @@ public class ComponentBundlerTask extends Task
mapping.put(cid, new Tuple(info[0], info[1]));
// process and store the main component image
processComponent(info, aset, cfile, jout);
processComponent(info, aset, cfile, fout);
// pick up any auxiliary images as well like the shadow or
// crop files
@@ -217,20 +216,20 @@ public class ComponentBundlerTask extends Task
FileUtil.resuffix(cfile, ext, AUX_EXTS[aa] + ext));
if (afile.exists()) {
info[2] = action + AUX_EXTS[aa];
processComponent(info, aset, afile, jout);
processComponent(info, aset, afile, fout);
}
}
}
}
// write our mapping table to the jar file as well
jout.putNextEntry(new JarEntry(BundleUtil.COMPONENTS_PATH));
ObjectOutputStream oout = new ObjectOutputStream(jout);
fout = nextEntry(fout, BundleUtil.COMPONENTS_PATH);
ObjectOutputStream oout = new ObjectOutputStream(fout);
oout.writeObject(mapping);
oout.flush();
// seal up our jar file
jout.close();
fout.close();
} catch (IOException ioe) {
String errmsg = "Unable to create component bundle.";
@@ -246,13 +245,13 @@ public class ComponentBundlerTask extends Task
}
protected void processComponent (
String[] info, TileSet aset, File cfile, JarOutputStream jout)
String[] info, TileSet aset, File cfile, OutputStream fout)
throws IOException, BuildException
{
// construct the path that'll go in the jar file
String ipath = composePath(
info, BundleUtil.IMAGE_EXTENSION);
jout.putNextEntry(new JarEntry(ipath));
fout = nextEntry(fout, ipath);
// create a trimmed tileset based on the source action tileset and
// stuff the new trimmed image into the jar file at the same time
@@ -260,7 +259,7 @@ public class ComponentBundlerTask extends Task
TrimmedTileSet tset = null;
try {
tset = TrimmedTileSet.trimTileSet(aset, jout);
tset = trim(aset, fout);
tset.setImagePath(ipath);
} catch (Throwable t) {
System.err.println(
@@ -278,8 +277,9 @@ public class ComponentBundlerTask extends Task
if (tset != null) {
String tpath = composePath(
info, BundleUtil.TILESET_EXTENSION);
jout.putNextEntry(new JarEntry(tpath));
ObjectOutputStream oout = new ObjectOutputStream(jout);
fout = nextEntry(fout, tpath);
ObjectOutputStream oout = new ObjectOutputStream(fout);
oout.writeObject(tset);
oout.flush();
}
@@ -417,7 +417,7 @@ public class ComponentBundlerTask extends Task
digester.addSetProperties("actions" + ActionRuleSet.ACTION_PATH);
addTileSetRuleSet(digester, new SwissArmyTileSetRuleSet());
addTileSetRuleSet(digester, new UniformTileSetRuleSet("/uniformTileset"));
HashMap actsets = new ActionMap();
digester.push(actsets);
@@ -439,6 +439,37 @@ public class ComponentBundlerTask extends Task
return actsets;
}
/**
* Creates the base output stream to which to write our bundle's files.
*/
protected OutputStream createOutputStream (File target)
throws IOException
{
JarOutputStream jout = new JarOutputStream(new FileOutputStream(target));
jout.setLevel(Deflater.BEST_COMPRESSION);
return jout;
}
/**
* Advances to the next named entry in the bundle and returns the stream to which to write
* that entry.
*/
protected OutputStream nextEntry (OutputStream lastEntry, String path)
throws IOException
{
((JarOutputStream)lastEntry).putNextEntry(new JarEntry(path));
return lastEntry;
}
/**
* Converts the tileset to a trimmed tile set and saves it at the specified location.
*/
protected TrimmedTileSet trim (TileSet aset, OutputStream fout)
throws IOException
{
return TrimmedTileSet.trimTileSet(aset, fout);
}
/** Used when parsing action tilesets. */
public static class ActionMap extends HashMap
{
@@ -0,0 +1,65 @@
//
// $Id: ComponentBundlerTask.java 281 2007-08-02 23:18:16Z charlie $
//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.cast.bundle.tools;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TrimmedTileSet;
/**
* Creates all the information for a component bundle but places it into a specified directory
* rather than a bundle jar file.
*/
public class DirectoryComponentBundlerTask extends ComponentBundlerTask
{
@Override // documentation inherited.
protected OutputStream createOutputStream (File target)
throws IOException
{
// Since we recreate our output stream on every entry, we don't need one to start with.
return null;
}
@Override // documentation inherited
protected OutputStream nextEntry (OutputStream lastEntry, String path)
throws IOException
{
File file = new File(_target, path);
file.getParentFile().mkdirs();
return new FileOutputStream(file);
}
@Override // documentation inherited
protected TrimmedTileSet trim (TileSet aset, OutputStream fout)
throws IOException
{
return TrimmedTileSet.trimTileSet(aset, fout, "png");
}
}
@@ -0,0 +1,51 @@
//
// $Id: ComponentBundlerTask.java 281 2007-08-02 23:18:16Z charlie $
//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.cast.bundle.tools;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* Creates all the information that would be in a metadata bundle and place it in a directory.
*/
public class DirectoryMetadataBundlerTask extends MetadataBundlerTask
{
@Override // documentation inherited.
protected OutputStream createOutputStream (File target)
throws IOException
{
// Since we recreate our output stream on every entry, we don't need one to start with.
return null;
}
@Override // documentation inherited
protected OutputStream nextEntry (OutputStream lastEntry, String path)
throws IOException
{
File file = new File(_target, path);
file.getParentFile().mkdirs();
return new FileOutputStream(file);
}
}
@@ -28,6 +28,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.jar.JarEntry;
@@ -92,9 +93,8 @@ public class MetadataBundlerTask extends Task
"file via the 'target' attribute.");
// make sure we can write to the target bundle file
FileOutputStream fout = null;
OutputStream fout = null;
try {
fout = new FileOutputStream(_target);
// parse our metadata
Tuple tuple = parseActions();
@@ -102,33 +102,28 @@ public class MetadataBundlerTask extends Task
HashMap actionSets = (HashMap)tuple.right;
HashMap classes = parseClasses();
// and create the bundle file
JarOutputStream jout = new JarOutputStream(fout);
jout.setLevel(Deflater.BEST_COMPRESSION);
fout = createOutputStream(_target);
// throw the serialized actions table in there
JarEntry aentry = new JarEntry(BundleUtil.ACTIONS_PATH);
jout.putNextEntry(aentry);
ObjectOutputStream oout = new ObjectOutputStream(jout);
fout = nextEntry(fout, BundleUtil.ACTIONS_PATH);
ObjectOutputStream oout = new ObjectOutputStream(fout);
oout.writeObject(actions);
oout.flush();
// throw the serialized action tilesets table in there
JarEntry sentry = new JarEntry(BundleUtil.ACTION_SETS_PATH);
jout.putNextEntry(sentry);
oout = new ObjectOutputStream(jout);
fout = nextEntry(fout, BundleUtil.ACTION_SETS_PATH);
oout = new ObjectOutputStream(fout);
oout.writeObject(actionSets);
oout.flush();
// throw the serialized classes table in there
JarEntry centry = new JarEntry(BundleUtil.CLASSES_PATH);
jout.putNextEntry(centry);
oout = new ObjectOutputStream(jout);
fout = nextEntry(fout, BundleUtil.CLASSES_PATH);
oout = new ObjectOutputStream(fout);
oout.writeObject(classes);
oout.flush();
// close it up and we're done
jout.close();
fout.close();
} catch (IOException ioe) {
String errmsg = "Unable to output to target bundle " +
@@ -146,6 +141,28 @@ public class MetadataBundlerTask extends Task
}
}
/**
* Creates the base output stream to which to write our bundle's files.
*/
protected OutputStream createOutputStream (File target)
throws IOException
{
JarOutputStream jout = new JarOutputStream(new FileOutputStream(target));
jout.setLevel(Deflater.BEST_COMPRESSION);
return jout;
}
/**
* Advances to the next named entry in the bundle and returns the stream to which to write
* that entry.
*/
protected OutputStream nextEntry (OutputStream lastEntry, String path)
throws IOException
{
((JarOutputStream)lastEntry).putNextEntry(new JarEntry(path));
return lastEntry;
}
/**
* Configures <code>ruleSet</code> and hooks it into <code>digester</code>.
*/