Skip to main content

News

Topic: neoSphere 5.9.2 (Read 522595 times) previous topic - next topic

0 Members and 20 Guests are viewing this topic.
  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #600
I just added ByteArray inflate/deflate support:
https://github.com/fatcerberus/minisphere/commit/40063460804b7834b18b0e71099fab44184f7310

Used like:
var little = bytearray.deflate([level]);
var big = bytearray.inflate();

Honestly though, I'm not sure how useful this is in a game engine - I only added it because 1) Sphere 1.6 has it and 2) I already had a zlib dependency thanks to libmng, so may as well use it.
  • Last Edit: June 11, 2015, 12:53:03 pm by Lord English
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

Re: minisphere 1.2.4
Reply #601
It would be useful saving data or sending data across a network.

zlib is so fast and so common that there's not really a good reason not to use it when sending or saving more than a few kilobytes of data.

You also pulled in zlib once you supported png.
  • Last Edit: June 11, 2015, 04:56:04 pm by Flying Jester

  • FBnil
  • [*][*]
Re: minisphere 1.2.4
Reply #602
Works perfectly:
Code: [Select]
function game(){
var originaltext = "Hello Sphere Worlds!";
var source = CreateByteArrayFromString( originaltext );

var compressed = DeflateByteArray( source , 9); // Sphere Syntax
//var compressed = source.deflate(9); // MiniSphere Syntax

if( compressed !== null ){
var inflated = InflateByteArray(compressed, 1024*16); // Sphere Syntax
//var inflated = compressed.inflate(); // MiniSphere Syntax
if(inflated !== null){
var copy = CreateStringFromByteArray(inflated);
if(copy === originaltext)
  Abort( "SUCCES:" + CreateStringFromByteArray(inflated) );
else
  Abort("ByteArray to string failed");
 
}else{
Abort( "Decompression failed." );
}
}else{
Abort("Compression failed.")
}
}

// MiniSphere to Sphere syntax

function DeflateByteArray(BA_obj,ratio){
  return BA_obj.deflate(ratio);
}

function InflateByteArray(BA_obj,size){
  return BA_obj.inflate(size); // need size or we can make a inflate bomb?
}


edit: A deflate bomb is possible:  http://security.stackexchange.com/questions/51071/zlib-deflate-decompression-bomb
  • Last Edit: June 11, 2015, 05:12:31 pm by FBnil

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #603

You also pulled in zlib once you supported png.


In theory, yes.  In practice no because Allegro uses GDIplus to load images on Windows.  Nonetheless, I did pull it in with libmng, so your point stands. :)
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #604

Works perfectly:
Code: [Select]
function game(){
var originaltext = "Hello Sphere Worlds!";
var source = CreateByteArrayFromString( originaltext );

var compressed = DeflateByteArray( source , 9); // Sphere Syntax
//var compressed = source.deflate(9); // MiniSphere Syntax

if( compressed !== null ){
var inflated = InflateByteArray(compressed, 1024*16); // Sphere Syntax
//var inflated = compressed.inflate(); // MiniSphere Syntax
if(inflated !== null){
var copy = CreateStringFromByteArray(inflated);
if(copy === originaltext)
  Abort( "SUCCES:" + CreateStringFromByteArray(inflated) );
else
  Abort("ByteArray to string failed");
 
}else{
Abort( "Decompression failed." );
}
}else{
Abort("Compression failed.")
}
}

// MiniSphere to Sphere syntax

function DeflateByteArray(BA_obj,ratio){
  return BA_obj.deflate(ratio);
}

function InflateByteArray(BA_obj,size){
  return BA_obj.inflate(size); // need size or we can make a inflate bomb?
}



You don't even need the shims with the latest commit, I added the Sphere compatible functions.  :)

Could you also test the ColorMatrix support?
  • Last Edit: June 11, 2015, 05:07:02 pm by Lord English
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • FBnil
  • [*][*]
Re: minisphere 1.2.4
Reply #605
sure thing, will work on it over the weekend.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #606
One potential pitfall: minisphere will throw if an inflate/deflate fails, apparently Sphere returns null instead?

Good point on the potential for inflate bombs though, I'll add an optional size parameter when I get a chance.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: minisphere 1.2.4
Reply #607
Didn't original Sphere never throw exceptions because implementing exceptions was a difficult mess, or am I wrong on that? Even if it did though, it'd be pretty inconsistent with everything else. I've never seen try..catch in Sphere...

Re: minisphere 1.2.4
Reply #608

Didn't original Sphere never throw exceptions because implementing exceptions was a difficult mess, or am I wrong on that? Even if it did though, it'd be pretty inconsistent with everything else. I've never seen try..catch in Sphere...


I thought it did? For instance, you could try...catch a LoadImage in case the image didn't exist?

Canonical Sphere scripts certainly don't use exceptions much at all, either way.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #609
Yeah, LoadImage et al will throw on error.  sphere APIs that return null on failure are in the minority I think.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: minisphere 1.2.4
Reply #610
Huh. Well, how about that. I was certain there was a whole issue around this, but guess not.

...And here I have this whole script/function dedicated to loading resources and doing its best determining whether a resource exists or not and providing placeholders for years... Time to update that script to make use of it, I suppose.

Re: minisphere 1.2.4
Reply #611
I'm 99% certain that anytime you get the black screen + white text that blames a SS_* function, you could have used a try...catch on it :)

Just for some reason, none of us ever did that...

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #612
On that note, the minisphere error screen is so much nicer looking than the Sphere 1.5 one.  Just have to toot my own horn a little... ;)
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

Re: minisphere 1.2.4
Reply #613

On that note, the minisphere error screen is so much nicer looking than the Sphere 1.5 one.  Just have to toot my own horn a little... ;)


But can you select the text on the error screen?

You can select the text in TurboSphere's error screen :)

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: minisphere 1.2.4
Reply #614
I wanted to do something like that, but as Allegro has no clipboard routines...
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub