These are chat archives for voodooattack/nexusjs

29th
Apr 2016
I think I just broke the rules
:D
Even node in cluster mode couldn't beat that!
Rares Golea
@rgolea
Apr 29 2016 07:05
is nexus multithreaded?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 08:13
@rgolea yes
jtenner
@jtenner
Apr 29 2016 13:51
It looks like you're swimming upstream for sure this time :).
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:51
Haha
I just got invited to a JavaScript conference in Sweden to talk about Nexus. :)
jtenner
@jtenner
Apr 29 2016 13:53
That's amazing.
Rares Golea
@rgolea
Apr 29 2016 13:53
nice!
jtenner
@jtenner
Apr 29 2016 13:53
Make sure you keep being based.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:53
Thanks guys!
Rares Golea
@rgolea
Apr 29 2016 13:56
oh! btw… a friend asked me if you brought yet a solution for the the multithread sync and complex code generated because of multithread
I didn’t know how to answer
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:56
Tell him this: EVERYTHING is atomic.
jtenner
@jtenner
Apr 29 2016 13:57
I don't think that was even english lol
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:57
lol
jtenner
@jtenner
Apr 29 2016 13:57
Bought yet a solution... what?
Rares Golea
@rgolea
Apr 29 2016 13:57
atomic?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:57
Atomic = All threads lock objects when they access them.
Rares Golea
@rgolea
Apr 29 2016 13:57
oh!
nice!
jtenner
@jtenner
Apr 29 2016 13:57
Do they sit around waiting to modify the object?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 13:58
Hang on, let some show you something
If this string wasn't atomic it would have been corrupted by different threads accessing it
It would have been a mess
Rares Golea
@rgolea
Apr 29 2016 13:59
quite nice!
indeed
jtenner
@jtenner
Apr 29 2016 14:00
@voodooattack what happens when the a thread tries to access a locked object?
It simply waits for it to unlock, right?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:01
It will wait until the other thread is finished accessing it
jtenner
@jtenner
Apr 29 2016 14:01
That is the answer to my question :)
Thank you.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:01
You're welcome
Rares Golea
@rgolea
Apr 29 2016 14:01
2 threads might do the same thing at once? and try to modify the thing twice?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:01
Yes, but only one will be able to do so
The other will have to wait
jtenner
@jtenner
Apr 29 2016 14:01
@voodooattack now you need a webkit browser front end so I can use the canvas2d prototype only multithreaded
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:02
lol
That'd be really easy to implement, I'm already using webkit :P
jtenner
@jtenner
Apr 29 2016 14:02
Can you support the require function and node modules?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:02
A project like nw.js based on nexus would be a piece of cake
jtenner
@jtenner
Apr 29 2016 14:02
(and by design... npm?)
Rares Golea
@rgolea
Apr 29 2016 14:02
hey… can we generate a browser based on nexusjs?
jtenner
@jtenner
Apr 29 2016 14:03
(unironically bombarding @voodooattack with too many questions LOL)
Rares Golea
@rgolea
Apr 29 2016 14:03
like use the same mulit-thread etc
LOL
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:03
@jtenner I don't plan to support require(), there will be System.import though.
@t
@rgolea A browser how?
jtenner
@jtenner
Apr 29 2016 14:03
Thats exactly what I just asked
like nw.js
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:03
Ah
I'm sure someone will get to it at some point.
jtenner
@jtenner
Apr 29 2016 14:04
The reason why I would want to support require is because I can import my canvas library straight into it.
Rares Golea
@rgolea
Apr 29 2016 14:04
man… i really liked require… especially because of browserify
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:04
Hmm
Ok, I might add it
With a few extra features
Rares Golea
@rgolea
Apr 29 2016 14:04
I’m not sure chrome is multithreaded
or by that mean any of the other browsers
jtenner
@jtenner
Apr 29 2016 14:05
If I had a browser window and access to require() I could write a desktop canvas app.
Rares Golea
@rgolea
Apr 29 2016 14:05
we kind of need an app (a browser) to display a website multithread...
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:05
lol
No
That would be against everything a browser stands for
A.k.a single threaded event loop
jtenner
@jtenner
Apr 29 2016 14:06
Yeah we don't want that.
Rares Golea
@rgolea
Apr 29 2016 14:06
why not?
jtenner
@jtenner
Apr 29 2016 14:06
Because we want to be multithreaded hipsters XD.
Rares Golea
@rgolea
Apr 29 2016 14:07
faster browser for gaming and solution for big apps on the browser itself
we are already migrating everything from the server to the browser...
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:07
I'm not even sure why I'm against the idea, but I am :P
Rares Golea
@rgolea
Apr 29 2016 14:07
:)
still no access to the filesystem
as a browser shouldn’t have
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:07
Maybe a nw.js clone for nexus
With all the bells and whistles
Based on Qt.
jtenner
@jtenner
Apr 29 2016 14:08
support literally only these functions
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');
requestAnimationFrame(frame);
lol
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:08
Haha
jtenner
@jtenner
Apr 29 2016 14:09
:3
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:09
How about native OpenGL bindings? :P
jtenner
@jtenner
Apr 29 2016 14:09
Nah. I'm not good at that
But I would love to see that
var gl = canvas.getContext('open-gl')
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:10
I'm thinking: require('opengl/gl.h');
jtenner
@jtenner
Apr 29 2016 14:10
require('path/to/header')
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:10
And nexus takes care of the details
jtenner
@jtenner
Apr 29 2016 14:10
that is a great idea.
It would have to compile it at runtime... wouldn't it?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:11
Well, it would generate an API at runtime, yes.
jtenner
@jtenner
Apr 29 2016 14:11
Oh. That makes sense.
Awesome idea.
Yeah. Supporting require and relative contexts would make your platform support npm.
That alone would be super helpful.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:12
Actually, I'm thinking of something different
jtenner
@jtenner
Apr 29 2016 14:12
Reinvent server side javascript, don't reinvent package management.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:12
I'm thinking of using require('@package-name') for packages and require('file-name'); for files.
jtenner
@jtenner
Apr 29 2016 14:13
.... if you do that, it will make my library useless
require('key-code') in my library will fail.
require('./path'); or require('library/path/in/library');
Trust me when I say this, if you decide to support require, you have to be backwards compatible.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:14
you could do keyCode = (Nexus ? require('@key-code') : require('key-code'))
Rares Golea
@rgolea
Apr 29 2016 14:14
maybe have a check on a global variable
yup… just like that
jtenner
@jtenner
Apr 29 2016 14:14
Yeah but what about the thousands of packages that don't want to support nexus?
Easily I could make the change, but that requires everyone to write more code to support your platform.
Rares Golea
@rgolea
Apr 29 2016 14:15
@voodooattack maybe support both?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:15
Good point...
jtenner
@jtenner
Apr 29 2016 14:15
:)
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:15
The problem with existing libraries is that they use globals.
They assume a single threaded model.
Rares Golea
@rgolea
Apr 29 2016 14:15
so… if you do require(‘@underscore’) you can also do require(‘underscore’)
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:15
That's why I wanted to break-off from node
jtenner
@jtenner
Apr 29 2016 14:15
You can't help it when people use global variables.
You can help it when a library simply wants to use lodash.
Rares Golea
@rgolea
Apr 29 2016 14:16
yeah but changing from one to another shouldn’t be painful
jtenner
@jtenner
Apr 29 2016 14:16
lodash runs inside node without intervention from globals
Rares Golea
@rgolea
Apr 29 2016 14:16
supporting both require(‘@lodash’) and require(‘lodash’) shouldn’t be that hard
people might start changing it little by little
jtenner
@jtenner
Apr 29 2016 14:17
I'm just throwing out ideas.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:17
how about this, require() behaves differently based on package.json
jtenner
@jtenner
Apr 29 2016 14:17
Sure. What did you have in mind?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:17
If your package declares a "nexus:main", that would be used instead
And the new features would be unlocked
require('@package'), etc
jtenner
@jtenner
Apr 29 2016 14:18
Yeah that sounds great!
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:18
If not, the old require takes place.
jtenner
@jtenner
Apr 29 2016 14:18
if there is no nexus:main, require works as intented.
Perfect.
I wouldn't switch out my library for e2d. However, if I'm writing cpp....
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:19
lol
jtenner
@jtenner
Apr 29 2016 14:19
I could opt into nexus by supplying a nexus:main
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:19
Yes
jtenner
@jtenner
Apr 29 2016 14:19
As long as backward compatibility exists for systems not opting into nexus, you are golden.
I love it.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:20
I could even implement a single threaded event loop for older libraries, although I'm against it
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:21
lol
Rares Golea
@rgolea
Apr 29 2016 14:21
one quick question: for debugging… could we have the line and the file where the bug was delivered?
or the console printed out?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:22
yeah
Rares Golea
@rgolea
Apr 29 2016 14:22
It’s really frustrating to go and seek where node.js printed out the error
jtenner
@jtenner
Apr 29 2016 14:22
@rgolea can't you create a new Error and get the stack trace?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:22
Nexus prints a stack trace
Rares Golea
@rgolea
Apr 29 2016 14:22
see this?
Screen Shot 2016-04-29 at 16.22.21.png
sometimes works better, sometimes not
jtenner
@jtenner
Apr 29 2016 14:23
OUCH
Rares Golea
@rgolea
Apr 29 2016 14:23
but the first line never gets printed out the line or the file
and I have to go search for it
somewhere
jtenner
@jtenner
Apr 29 2016 14:23
Create a filestream for logging and write to it async ;-)
in nexus.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 14:24
haha
You could just pipe stderr to a file, once I implement that. :P
jtenner
@jtenner
Apr 29 2016 14:30
that would be the best.
jtenner
@jtenner
Apr 29 2016 15:35
Abdullah, I can't wait to write a multithreaded game engine for nexus...
I think it's possible to do multithreaded draw commands to a canvas too
No wait, it's possible to modify a set of view commands async.
Then every frame, draw the view commands
jtenner
@jtenner
Apr 29 2016 15:45
This message was deleted
jtenner
@jtenner
Apr 29 2016 15:51

import { Renderer, clearRect } from 'e2d'; 

class Engine extends Nexus.EventEmitter {
  constructor(config) {
    super();
    this.renderer = Renderer.create(400, 400);
    this.viewLayer = [];
    this.parts = [];
    this.config = config;
    if (config.parts) {
      this.setParts.apply(this, config.parts);
    }
  }
  setParts(...Parts) {
    Parts.forEach((Definition) => {
      this.viewLayer.push(null);
      this.parts.push(
        new Definiton(this.config)
      );
    });
  }
  onPhysics() {
    for(let i = 0; i < this.parts.length; i++) {
      let index = i;
      this.parts[i].emit('physics').then((view) => this.updatePart(view, index));
    }
  }
  updatePart(view, i) {
    this.view[i] = view;
  }
  onRender() {
    this.renderer.render(
      clearRect(400, 400),
      this.view
    );
  }
}
Physics ends up behind the view by a few MS
idk why the game needs to be an event emitter
I'm just throwing out ideas
jtenner
@jtenner
Apr 29 2016 15:56
Since I'm working cross threads, but passing objects to the main thread happens so quickly, there's no problem with the physics event returning e2d view commands!
The problem is that I don't know if the physics will be done in time for drawing.
So I gotta wait a frame to draw the prior state of the game.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:03
@jtenner that's it. I'm adding task groups.
jtenner
@jtenner
Apr 29 2016 16:03
hahahaha
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:04
If you enqueue tasks together they will be guaranteed to execute serially
How does that sound?
jtenner
@jtenner
Apr 29 2016 16:04
Will it lock the main thread until you are garunteed physics is done?
for instance.
Also, what would that look like?
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:05
No, but it will make sure that any tasks execute serially
jtenner
@jtenner
Apr 29 2016 16:05
Ah.
So I still need to wait a frame for physics to execute.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:05
So you could pass the physics task and the render task together
jtenner
@jtenner
Apr 29 2016 16:06
Yeah that's what I currently do with sidekick-worker. It works well, but physics ends up behind a frame.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:06
Hmmm
jtenner
@jtenner
Apr 29 2016 16:07
WebWorker streams a set of deltas back to the browser using postMessage()
it works very well.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:07
I'll have to think of something
jtenner
@jtenner
Apr 29 2016 16:08
A synchronous parallel task would be ideal.
Idk.
I'm not enough of an expert.
Abdullah A. Hassan
@voodooattack
Apr 29 2016 16:10
I'll think on it
jtenner
@jtenner
Apr 29 2016 18:01
The idea of having a multithreaded browser-like really makes me giddy though.
Rares Golea
@rgolea
Apr 29 2016 18:11
Why is that??
it's supposed to be the same thing but it should process faster
jtenner
@jtenner
Apr 29 2016 18:11
If I can pack more cpu power into a browser environment then I can do more stuff.
Rares Golea
@rgolea
Apr 29 2016 18:12
And since with angular/react/every other js framework + games leave the entire logic of the app on the browser
I think it's quite reasonable to have a multi threaded browser
At least from my point of view
jtenner
@jtenner
Apr 29 2016 18:13
I like the Worker object already. I think it has a great implementation but I want to be able to pass objects across a thread with the same speed.
worker.postMessage({ type: 'type', data: data}, [data.buffer]); //transferables are fast
This is fast enough for regular browser stuff, but I would rather be emitting events to another thread.
Rares Golea
@rgolea
Apr 29 2016 18:15
And correct me if I'm wrong... But the whole idea of single threaded browser was placed in because in the browsers in the 90s you only had to display some text and some info
jtenner
@jtenner
Apr 29 2016 18:16
nod
Rares Golea
@rgolea
Apr 29 2016 18:16
our apps keep getting bigger and our cpu is limited...
jtenner
@jtenner
Apr 29 2016 18:17
Yeah. From my standpoint, I have maybe 60% of the browser's attention when making a game. Garbage collection and render/layout really hamper my efforts.
Leaving garbage collection to happen more often and in short bursts because it happens on another thread is so lucrative.
Rares Golea
@rgolea
Apr 29 2016 18:18
for example, the current app I'm working on, consumes 700mb of ram... Haven't checked the cpu... But I know developers I work with really struggle with opening the app because they have low systems
personally I think the last time they updated was about 10 yrs ago
jtenner
@jtenner
Apr 29 2016 18:18
Trade off memory usage for cpu usage a bit then.
Rares Golea
@rgolea
Apr 29 2016 18:18
:smile:
I should... But I had this template made in angular-material and it has like 1000 watchers per page
and I don't think I can
jtenner
@jtenner
Apr 29 2016 18:20
wow
Angular makes it really easy to do stuff like that, in my experience.
Rares Golea
@rgolea
Apr 29 2016 18:21
Yeah... But I'm talking about a 20000 lines of code app
that's what I could count 4 months ago
anyways
I don't want to spend more time on that app
that can't be good :(
Rares Golea
@rgolea
Apr 29 2016 18:22
but since I stumbled across this project... I thought I would give an idea
Well... I'm not the lead architect of the app
and I can't really do what I want
jtenner
@jtenner
Apr 29 2016 18:23
I wasn't defending that point?
Just saying it stunk lol
Rares Golea
@rgolea
Apr 29 2016 18:24
yup
it does
anyways... That's why I think a multithreaded browser or maybe something like atom electron should be quite nice to have
jtenner
@jtenner
Apr 29 2016 18:25
For the love of everything, make it accessible unlike electron.
I have such a hard time developing in atom :(
Rares Golea
@rgolea
Apr 29 2016 18:25
maybe not the full browser if it's not possible... But if it is possible... Go for it
Im currently trying to get some people I know to collaborate on this project
@voodooattack I'll tell you if I find anyone
jtenner
@jtenner
Apr 29 2016 18:29
@voodooattack List of necessary features Nexus must have from a developer standpoint:
  1. Must Support node_modules and require syntax so that libraries can be made compatible with Nexus (with an optional opt into a cooler syntax is fine)
  2. Must be installable via *.msi or via ./configure && make && sudo make install or via binary
  3. Support ES2015 syntax right out of the box with no compilation (babel can't target Nexus... yet...?)
Also, @voodooattack can you mentor me and teach me how to use cpp like this?
Rares Golea
@rgolea
Apr 29 2016 18:34
We should start making docs :smile:
jtenner
@jtenner
Apr 29 2016 18:34
If @voodooattack will show me some examples, I can help write tutorial examples.
Rares Golea
@rgolea
Apr 29 2016 18:35
I think it would be nice if we'd get to compile docs from the code itself and make links that point directly to that code
jtenner
@jtenner
Apr 29 2016 18:35
Lack of sockets implementation also make me want to wait on making docs. A simple hello world example would set Nexus on the path to becoming popular.
Rares Golea
@rgolea
Apr 29 2016 18:37
Hahaha we're so excited for this project and we're not even participating yet
poor @voodooattack has to listen to us and develop everything by himself for now :smile:
jtenner
@jtenner
Apr 29 2016 18:38
I'm going to sit down and learn how to code CPP and learn Nexus so I can be as helpful as I can.
Rares Golea
@rgolea
Apr 29 2016 18:39
that's a possible solution
Abdullah A. Hassan
@voodooattack
Apr 29 2016 20:29
You guys are awesome.
But I gotta run, we'll talk more when I get back. :D
jtenner
@jtenner
Apr 29 2016 20:30
You come back and school me on how this thing works ;-).
jtenner
@jtenner
Apr 29 2016 20:36
@voodooattack this is going to be super important: https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md
you may have to implement the Standard Javascript Modules with import and export syntax.