#2394 closed enhancement (fixed)
[PATCH] Add prototype functions to FixedVector return values from C++ to JS
Reported by: | sanderd17 | Owned by: | sanderd17 |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 16 |
Component: | Core engine | Keywords: | patch |
Cc: | Patch: |
Description
By addin a prototype to the return values of f.e. GetPosition() from cmpPosition, doing stuff with those return values becomes a lot easier.
The patch gives a possibility to do this (the patch is still very untested though).
Attachments (3)
Change History (13)
by , 10 years ago
Attachment: | vector_prototype.diff added |
---|
comment:1 by , 10 years ago
Keywords: | patch review added |
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Basically, these methods aren't nice: http://trac.wildfiregames.com/changeset?reponame=&new=14606%40ps%2Ftrunk%2Fbinaries%2Fdata%2Fmods%2Fpublic%2Fglobalscripts%2FMath.js&old=13515%40ps%2Ftrunk%2Fbinaries%2Fdata%2Fmods%2Fpublic%2Fglobalscripts%2FMath.js
They're not general enough (are they 2D or 3D? Isn't a cross() supposed to return a vector? ...) and making them general under the existing Math object will be a pain. Instead adding a prototype is better, but that means that the data coming from C++ should also have the prototype (else you'll have lots of useless object creations in JS just to get access to the functions).
comment:4 by , 10 years ago
A new version, with some rather ugly caching, but the method is a lot faster. While the first version doubled the time needed to query a position, this version has barely no influence.
The non-neccesary JS code isn't included in the patch below, but I did include a little profile function. When running the Huge combat demo, it gives you comparable values.
by , 10 years ago
Attachment: | vector_prototype.2.diff added |
---|
by , 10 years ago
Attachment: | vector_prototype.3.diff added |
---|
comment:5 by , 10 years ago
Yves said something about not being threadsafe, and using ScriptValRooted instead. I hope the above patch is what was meant.
Still no slowdown compared to the original code.
comment:6 by , 10 years ago
The rooting looks OK now. The input about threadsafety was loud thinking more or less. It doesn't look worse than other code now, so I think it should be OK too. As you said it's still a bit ugly that a value clearly related to vectors is stored in the ScriptInterface. But from the perspective that the conversions are implemented as part of ScriptInterface, it makes sense. A general caching mechanism for the ScriptInterface could make sense if other conversion functions can use that too.
comment:8 by , 10 years ago
Keywords: | review removed |
---|
I don't understand the description, could you explain more?