Comments (5)
Hi,
While I think your code is nice, I'm not sure if it is necessary to have it in p2.js. It is already possible to subscribe the same handler to different event types. It is also already possible to control the order of the handlers (if there are more than one). What else will it add other than the .one()
mechanism and a nicer API? I'm trying to keep the code base size as small as possible.
I think I found your 30% slowdown btw... Here you create a new Object()
for each emit. If you have 10^6 emitted events per frame in 60Hz, you will allocate 24_10^6_60 bytes/s = 1440 megabytes per second (!?). It would probably be nicer if you could reuse this 24 byte event object for each emit.
(btw, I'm not 100% sure that the plain javascript object weighs 24 bytes, it might be some other number)
from p2.js.
actually the slowdown is caused by something else. i tried a copy/paste of your emit method and it had no difference. I think it's a combination of things.
But i think you're right, it would be better to reuse the same object :)
I can understand your wanting to keep the codebase small.
The major benefits are...
// event data having the "handler" and "type" reference so that one can do things like this:
ps.on( 'type', function( e ){
// since i'm using a reverse while() loop, removing a listener won't interfere with the rest of the callbacks
if ( something ) ps.off( e.type, e.handler );
});
// multiple events in one shot (works with .off() too)
ps.on({
'type1': function( e ) {
// handle
},
'type2': function( e ) {
// ...
}
// ...
});
// bind to different "this"
ps.on( 'type', function( e ){
this === scope; // true
}, scope);
// remove all events bound to "type"
ps.off( 'type', true );
// remove all events
ps.off( true );
// priority management
ps.on( 'type', function( e ){
// runs last
}, 1 );
ps.on( 'type', function( e ){
// runs first, no matter where/when this .on() is called
}, 100);
from p2.js.
I have thought some about this and I think that it's not necessary for a library focusing on lightweight and physics. I searched for other physics engines implementing these patterns and found nothing. If you know a physics engine other than PhysicsJS implementing this, please point me to that...
Anyway, all these mechanisms can be implemented in the (game) application layer if they are needed. Better keep the physics library as small and maintainable as possible.
from p2.js.
sounds good
from p2.js.
Yeah, sorry, but that's what I think right now. Thanks for the offer though!
from p2.js.
Related Issues (20)
- npm finds 119 vulnerabilities on install HOT 5
- how to get constant speed of body?
- Unmount usage in React
- Particle Demo
- removeSpring event is not fired
- Shape position changed when added to a body
- p2.js Multiplayer Game issue HOT 3
- RotationalSpring damping is ignored
- CCD doesn't work with collisionGroups ? HOT 1
- Why is localAxis passed into projectOntoLocalAxis only to be overwritten by tmpVec1?
- How many pixels is a meter in p2.js? HOT 3
- How do I destroy an entity that has a body?
- Is there water or liquid simulation possibilities? HOT 3
- Is it possible to use the GPU for better performance?
- Collisions not working at all HOT 1
- Cannot read property 'overlaps' of undefined
- Help with resizing P2 Box?
- p2
- fatal: unable to access 'http://ikt.pm2.io/ikt.git/': Could not resolve host: ikt.pm2.io HOT 1
- Collision between circle and box can be missed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p2.js.