Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 5:27 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Nov 15, 2008 8:06 pm 
Offline

Joined: Fri Mar 07, 2008 8:41 pm
Posts: 21
The thing is that we need a slightly extended ParticleSystem class, but we still want to use Pedigree etc., so what it bogs down to is that ParticleIO.loadConfiguredSystem should not necessarily call new ParticleSystem.

I figured I could do such a simple change myself, so here is a patch (proposal) for org.newdawn.slick.particles.ParticleIO (against latest svn revision). Basically I just added a third parameter ParticleSystem to said method which would be used if != null. Existing code is not broken.

Code:
Index: ParticleIO.java
===================================================================
--- ParticleIO.java   (revision 1095)
+++ ParticleIO.java   (working copy)
@@ -49,7 +49,7 @@
   public static ParticleSystem loadConfiguredSystem(String ref)
         throws IOException {
      return loadConfiguredSystem(ResourceLoader.getResourceAsStream(ref),
-            null);
+            null, null);
   }

   /**
@@ -63,7 +63,7 @@
    */
   public static ParticleSystem loadConfiguredSystem(File ref)
         throws IOException {
-      return loadConfiguredSystem(new FileInputStream(ref), null);
+      return loadConfiguredSystem(new FileInputStream(ref), null, null);
   }

   /**
@@ -77,7 +77,7 @@
    */
   public static ParticleSystem loadConfiguredSystem(InputStream ref)
         throws IOException {
-      return loadConfiguredSystem(ref, null);
+      return loadConfiguredSystem(ref, null, null);
   }

   /**
@@ -95,7 +95,7 @@
   public static ParticleSystem loadConfiguredSystem(String ref,
         ConfigurableEmitterFactory factory) throws IOException {
      return loadConfiguredSystem(ResourceLoader.getResourceAsStream(ref),
-            factory);
+            factory, null);
   }

   /**
@@ -112,7 +112,7 @@
    */
   public static ParticleSystem loadConfiguredSystem(File ref,
         ConfigurableEmitterFactory factory) throws IOException {
-      return loadConfiguredSystem(new FileInputStream(ref), factory);
+      return loadConfiguredSystem(new FileInputStream(ref), factory, null);
   }

   /**
@@ -129,6 +129,24 @@
    */
   public static ParticleSystem loadConfiguredSystem(InputStream ref,
         ConfigurableEmitterFactory factory) throws IOException {
+            return loadConfiguredSystem(ref, factory, null);
+         }
+
+   /**
+    * Load a set of configured emitters into a single system
+    *
+    * @param ref
+    *            The stream to read the XML from
+    * @param factory
+    *            The factory used to create the emitter than will be poulated
+    *            with loaded data.
+    * @param existingSystem TODO
+    * @return A configured particle system
+    * @throws IOException
+    *             Indicates a failure to find, read or parse the XML file
+    */
+   public static ParticleSystem loadConfiguredSystem(InputStream ref,
+         ConfigurableEmitterFactory factory, ParticleSystem system) throws IOException {
      if (factory == null) {
         factory = new ConfigurableEmitterFactory() {
            public ConfigurableEmitter createEmitter(String name) {
@@ -146,8 +164,10 @@
            throw new IOException("Not a particle system file");
         }
         
-         ParticleSystem system = new ParticleSystem("org/newdawn/slick/data/particle.tga",
+         if (system == null) {
+         system = new ParticleSystem("org/newdawn/slick/data/particle.tga",
               2000);
+         }
         boolean additive = "true".equals(element.getAttribute("additive"));
         if (additive) {
            system.setBlendingMode(ParticleSystem.BLEND_ADDITIVE);


edit: Fixed patch (removed code formatter changes)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2008 7:25 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Applied to SVN. Thanks for the update.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group