Skip to main content

News

Recent Posts

21
Sphere General / Re: Sphere v2 API discussion
Last post by Fat Cerberus -
I've just learnt how the history feature works on github. :P

Version control is awesome isn't it? :D  I like using Git because I'm not tempted to keep dead/commented-out code around forever, I can prune things as aggressively as I want and if it turns out I need the code back later I can just get it back from the history.  Sometimes it's difficult to find things, but I've found YAGNI holds true most of the time and I indeed never need the deleted code again.
22
Just skimming real quick, I came across this bit of ugly Sphere v1 code:

Code: (javascript) [Select]
var file = OpenRawFile("output.txt",true);
var avgs = [0,0,0,0];
for(var i = 0; i < m_render_times.length; ++i)
{
avgs[0] += (m_render_times[i] / m_render_times.length);
avgs[1] += (s_render_times[i] / s_render_times.length);
avgs[2] += (m_update_times[i] / m_update_times.length);
avgs[3] += (s_update_times[i] / s_update_times.length);
}
file.write(CreateByteArrayFromString("average m_r = " + avgs[0] + "\n average s_r = " + avgs[1] + "\n average m_u = " + avgs[2] + "\n average s_u = " + avgs[3]));
file.close();

You could change that to (Sphere v2):
Code: (javascript) [Select]
// [snip: calculate averages]
FS.writeFile("~/output.txt", "average m_r = " + avgs[0] + "\n average s_r = " + avgs[1] + "\n average m_u = " + avgs[2] + "\n average s_u = " + avgs[3]);

I haven't actually tried it out yet, just skimming over the code for now.
23
Engine Development / Re: miniSphere 4.8.3
Last post by Flying Jester -
A couple of notes on my points above:
V8 documentation: a lot of content on their wiki has been written this year, so it may have been a lot worse before.

It was non-existent before. A big part of when I switched to SM for TurboSphere was that V8 was largely undocumented, and what was there was unusable. The API changed wildly every couple months (compared with SM's, which is quite stable in comparison), and there was no documentation at all, except three pages of outdated descriptions of APIs that no longer existed, and two examples that were not updated since before I began the project.

Regarding API stability, unless things have drastically changed in the last couple months since I updated some Turbo code to SM 52, SM is still way, way more stable than V8.

I also caution against using V8 for anything relating to graphics or files, since its GC is very unreliable. SM's was much more stable, always releasing memory in a timely manner. This made V8 basically unusable for Galileo or any FS work.
24
Engine Development / Re: miniSphere 4.8.3
Last post by Fat Cerberus -
Maybe the module functions are experimental/not released yet?  I'll check into that later.
25
Sphere General / Re: Sphere v2 API discussion
Last post by Rhuan -
Thanks for the heads up, I'll fix the bug in 4.8.4.

As for the branches and backrefs, I removed them because they were difficult to document adequately.  So I just tried to make it work similarly to a C struct because that's easy to understand and explain.  If there's enough demand I could bring the feature back, though. ;)

I admit I was nice being able to load an entire .rmp file with one call...
I've just learnt how the history feature works on github. :P

I'm going to add the branches/backrefs code to my own script for now, it's too good not to use.
26
Sphere General / Re: Sphere v2 API discussion
Last post by Fat Cerberus -
Thanks for the heads up, I'll fix the bug in 4.8.4.

As for the branches and backrefs, I removed them because they were difficult to document adequately.  So I just tried to make it work similarly to a C struct because that's easy to understand and explain.  If there's enough demand I could bring the feature back, though. ;)

I admit I was nice being able to load an entire .rmp file with one call...
27
Engine Development / Re: miniSphere 4.8.3
Last post by Rhuan -
So far I've written a bunch of functions to abstract around the JS engine and fit in with the style of the rest of the codebase:
https://github.com/fatcerberus/minisphere/blob/chakra-js/src/shared/ecmunch.c

I've done some testing with it and I can successfully set object properties, create functions, eval code and get the result back, etc.  I haven't figured out how to get it to load a module yet, though.
Hmm I said the documentation was good... But it's not all in place, for some reason setting up modules is documented in ChakraCore.h but not in the wiki.
For executing a module looks like you need:
JsInitializeModuleRecord
JsParseModuleSource
and
JsModuleEvaluation

As far as I can tell these are all ES6 style, not commonJS though I haven't gone into the detail to check that.

I assume commonJS may need to be added similar to other engines.

Something interesting about CC is that any JsValueRefs stored as local variables on the stack are apparently protected from garbage collection without needing to explicitly root them nor call JsRelease().  I'm not really sure how that works: Does the GC actually examine the native C/C++stack frames looking for refs?

Although I guess you'd need to have a system like that if you're doing GC off-thread.  Otherwise the object might get collected before you had a chance to root it.

A quick look gave me the following:
Quote
A Chakra runtime will automatically track JsRef references as long as they are stored in local variables or in parameters (i.e. on the stack). Storing a JsRef somewhere other than on the stack requires calling JsAddRef and JsRelease to manage the lifetime of the object, otherwise the garbage collector may free the object while it is still in use.
28
Sphere General / Re: Sphere v2 API discussion
Last post by Rhuan -
A few questions on dataReader.js (I thought I'd use it for loading .rmp files rather than re-inventing the wheel again)

1. I think it's meant to have:
const from = require('from');
at the top, the latest version doesn't have this but it uses from in the _checkStructDescriptor function.

2. Did you remove the ability to have multi-tier objects/arrays? I was looking back around page 74 of the miniSphere development topic and you'd been using a somewhat complex object with branches and self references in it to read an .rmp file, I assumed that this was with an early version of dataReader.js but I can't see any facility for processing of self references or branches in the latest version, am I missing something? If the facility is gone/not returning that's fine I'll write my own just don't want to do it if it's already there somewhere.

29
Engine Development / Re: miniSphere 4.8.3
Last post by Fat Cerberus -
Something interesting about CC is that any JsValueRefs stored as local variables on the stack are apparently protected from garbage collection without needing to explicitly root them nor call JsRelease().  I'm not really sure how that works: Does the GC actually examine the native C/C++stack frames looking for refs?

Although I guess you'd need to have a system like that if you're doing GC off-thread.  Otherwise the object might get collected before you had a chance to root it.
30
Engine Development / Re: miniSphere 4.8.3
Last post by Fat Cerberus -
So far I've written a bunch of functions to abstract around the JS engine and fit in with the style of the rest of the codebase:
https://github.com/fatcerberus/minisphere/blob/chakra-js/src/shared/ecmunch.c

I've done some testing with it and I can successfully set object properties, create functions, eval code and get the result back, etc.  I haven't figured out how to get it to load a module yet, though.