Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 12:31:59 am
Xith3D CommunityGeneral CategoryFeature Requests & Brilliant Ideas (Moderators: Marvin Fröhlich, 'n ddrylliog)Particle Implementation
Pages: 1 [2]
Print
Author Topic: Particle Implementation  (Read 5053 times)
guilhermegrg
Enjoying the stay
*
Offline Offline

Posts: 88


View Profile Email
« Reply #15 on: 07. September 2007, 08:06:17 am »

I'm having a problem with the method to load from an URL.

I've created the method to load from an InputStream and it seems to be correct.
The problem is that when loading from the URL, i get a byte count that is less than the actual file.

Th 9candles.ops is 1422 bytes long, but when i read it through a URL - by the url.openStream() - i get 1403 bytes.

If i use this in the ZipInputStream i can get the xml file name inside the zip stream - 9candles.xml - but i can't get the size of the XML file - which should be around 35 KB - nor  can i read any bytes whatsoever.



Code:
@Override
public ParticleSystem load(InputStream inputStream) throws Throwable {

BufferedInputStream bis = new BufferedInputStream(inputStream);
ZipInputStream zipInputStream = new ZipInputStream(inputStream);

ZipEntry entry = null;
entry = zipInputStream.getNextEntry();

if (entry == null)
throw new FileNotFoundException("the Zip entry is null");

if (entry.isDirectory())
throw new FileNotFoundException("the first entry is a directory");

String zeName = entry.getName();


int size = (int) entry.getSize();
// -1 means unknown size.

System.out.println("Found file name -> " + zeName + " size : " + size + " csize : " + entry.getCompressedSize());

int rb = 0;
int chunk = 0;
String file = "";
while ( (chunk = zipInputStream.read()) > 0) {
file+=chunk;
rb += chunk;
}

System.out.println("U Size : " + file.length());

if (size == -1) {
throw new RuntimeException(
"Impossible to get the size of the entry in the ZIP Stream");
}

byte[] b = new byte[(int) size];
rb = 0;
chunk = 0;
while (((int) size - rb) > 0) {
chunk = zipInputStream.read(b, rb, (int) size - rb);
if (chunk == -1) {
break;
}
rb += chunk;
}

System.out.println("Read -> " + rb + " bytes");

ByteArrayInputStream bArrayInputStream = new ByteArrayInputStream(b);

IUnmarshallingContext uctx = bfact.createUnmarshallingContext();

ParticleSystem obj = (ParticleSystem) uctx.unmarshalDocument(
bArrayInputStream, null);

ParticleSystem ps = obj;
setObjectReferences(ps);

bArrayInputStream.close();
zipInputStream.close();

return obj;
}


Code:
@Override
public ParticleSystem load(URL url) throws Throwable {
InputStream inputStream = url.openStream();
BufferedInputStream bif = new BufferedInputStream(inputStream);
InputStreamReader isr = new InputStreamReader(bif);
BufferedReader br = new BufferedReader(isr);

String file = null;
String temp = null;
while ((temp = br.readLine()) != null) {
if(file == null)
file = temp;
else
file += temp;
}


// System.out.println(file);
ByteArrayOutputStream bais = new ByteArrayOutputStream();
bais.write(file.getBytes());

System.out.println("Size : " + file.length());

System.out.println("byte output Size : " + bais.size());


ByteArrayInputStream inStream;
inStream = new ByteArrayInputStream(bais.toByteArray());

// FileOutputStream file = new FileOutputStream();

ZipInputStream zis = new ZipInputStream(inStream);
ZipEntry entry = zis.getNextEntry();
System.out.println(" entry : " + entry.getName() + " | " + entry.getSize());

File test = new File("test.ops");
test.createNewFile();
FileWriter fw = new FileWriter(test);
fw.write(file);
fw.flush();
fw.close();
System.out.println("Wrote a new file");

ParticleSystem ps = load(inStream);
inputStream.close();
return ps;
}
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #16 on: 07. September 2007, 11:21:41 am »

Oh wow, sorry about the commit.  I was trying to help, but I guess I goofed, yet again.  Ugh.  I really need to start thinking things through  Undecided.

I wonder which JARs I have to update? I'm using Eclipse Europa (the newest one, AFAIK).

It's not a matter of Eclipse. the changes you made to the joal imlpementation where matching an older joal API. Maybe you have a joal.jar in your boot-classpath. I don't quite understand the changes to the PS code. e.g. the new Transform3D(Tuple3f) does exist. I don't know, why it doesn't in your working copy.

Marvin
Logged
kukanani
Fierce Warrior
****
Offline Offline

Posts: 504


My game is coming along fairly smoothly...


View Profile WWW
« Reply #17 on: 07. September 2007, 01:43:28 pm »

Marvin, you're so right.  It was the evil joal.jar, jogl.jar, and so on, that were in my ext/lib folder.  Thanks.
Logged

xith.setCoolnessLevel(10);
jMe.setCoolnessLevel(0);
xith.rock();
guilhermegrg
Enjoying the stay
*
Offline Offline

Posts: 88


View Profile Email
« Reply #18 on: 11. September 2007, 10:08:41 am »

Sorry about the delay...I've been quite busy.
Anyways, finally found a way around the buggy ZipInputStream class. Need to use a temporary file though, but it works now.

More news soon
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #19 on: 11. September 2007, 10:19:15 am »

Btw. have you comitted the jops.jar file? Please recompile it with target=1.5 setting, since xith does not build with JDK 1.5 anymore due to class version conflicts by this jar.
Logged

guilhermegrg
Enjoying the stay
*
Offline Offline

Posts: 88


View Profile Email
« Reply #20 on: 11. September 2007, 10:28:33 am »

I've sent the updated jops.jar for target 1.6 file to Marvin as well as the changes to xith-tk in order to get the examples working.

I'll send a new one with target 1.5 as requested.

UPDATE : sent a jops.jar with targe 1.5
« Last Edit: 11. September 2007, 10:33:16 am by guilhermegrg » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #21 on: 11. September 2007, 10:32:58 am »

A remark about the input stream thing: You cuold dump the stream into a byte array instead of using a temp file. This is much cleaner.

And could you please remove that "throws Throwable" and only throw the exceptions, that are really possible?

Marvin
Logged
guilhermegrg
Enjoying the stay
*
Offline Offline

Posts: 88


View Profile Email
« Reply #22 on: 11. September 2007, 10:41:48 am »

Sent you a new jops.jar with target 1.5 with corrected exception throwing.

About the byte array : i'm already doing that.

the problem is with the ZipInputStream class itself, as i can't use it to properly load the stream. Using the ZipFile works though.
Just search Google for ZipInputStream bug...You'll find enough hits.

So I'm saving the byte array in a temp file, using ZipFile to load from it and then deleting it.

If there was a way to open a ZipFile from a byte array that would be handy...
« Last Edit: 11. September 2007, 02:48:47 pm by guilhermegrg » Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #23 on: 11. September 2007, 10:46:21 am »

@marvin:
could you please commit the jops.jar, because xith does not build anymore at all, since there seems to be a compiler-bug in 1.6 that gives an inconvertible type error for
Code:
final GLSLVertexShader vs = (GLSLVertexShader)shader;
so, the only way to compile xith at the moment is JDK 1.5.

Edit: It seems it does neither compile in 1.5 or 1.6 using sun javac, while the eclipse compiler seems to do fine. There is a workaround to first cast to Object. I will try if it helps.
« Last Edit: 11. September 2007, 10:58:40 am by Mathias 'cylab' Henze » Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #24 on: 11. September 2007, 06:38:11 pm »

I have committed the jops.jar and did the necessary changes. But the load/save methods still throw Throwable. I guess, only an IOException and some kind of "UnsupportedFileFormatException" are necessary here. Could you please change that.

Marvin
Logged
guilhermegrg
Enjoying the stay
*
Offline Offline

Posts: 88


View Profile Email
« Reply #25 on: 11. September 2007, 08:14:48 pm »

Yeah missed those methods. Changing....

Done. Sent you the new jops.jar.
Also i forgot to mention that jibx-run should also be in the classpath for the testlauncher.bat/sh . Add the following: %THIRD%\jibx\jibx-run.jar;

« Last Edit: 11. September 2007, 08:31:36 pm by guilhermegrg » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #26 on: 11. September 2007, 08:40:32 pm »

Thanks. It's all committed.

Marvin
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic