porting... starting at rev206

revision 206:
EC commented public const(s) in b2Settings.as
and EC has also added b2_fatAABBFactor for b2DynamicTree

BorrisTheBrave: it appears you have commented out maxProxies, and maxPairs. because they are not used in the growable broadphase

A Is the growable broadphase unique to the as3 port?

are these maxProxies/maxPairs variables likely to be used in EC's b2DynamicTree or Contact Manifold improvements?
i will leave them commented out for now.
im not familiar with C code.
B should i be porting the .h or the .cpp files or both in some manner?

i have so far decided to use the .h

new classes like b2DynamicTree are harder to port than isolated code changes. because i am running into a larger variety of C vs AS3 differences.

for example
Code:
class b2QueryCallback
{
public:
   ~b2QueryCallback() {}

   /// This function is called for each overlapping AABB.
   /// @return true if the query should continue.
   virtual bool Process(void* userData) = 0;
};


the "virtual bool Process(void* userData) = 0;"
i can interpret to mean
public virtual function Process(userData:*)
C but the = 0 throws me off a bit,

i did some reading on ~ as a mathematic operator and bitwise calculations last night.
D but i think "~b2QueryCallback() {}" may have something else in mind.
--edit-- i wonder if it means this class needs a kill function?

i will start digging through .h versions of files im more familiar with hoping to answer my questions.
b2DynamicTree.h

this has several classes declared in it, and i think since they are publicly accessible classes they will need to be separate .as files.


also, can't find a good reference comparrison elsewhere in the code for this bit
Quote:
virtual float32 Process(const b2RayCastInput& input, void* userData) = 0;

if have
b2internal virtual function Process(b2RayCastInput & input, userData:*)
--edit-- b2internal virtual function Process(input:b2RayCastInput, userData:*) // i have a feeling this is correct.

E not sure what to do with the & input, perhaps it just gets left off?
F template <typename T>
void Query(T* callback, const b2AABB& aabb) const;

in b2Math.h
it is used as a Number datatype...
is that true here too?
sorry for so many questions. I'm only useful if I do it correctly right? 🙂

there is a half ported version of b2DynamicTree.as here
http://www.sketchbookgames.com/b2DynamicTree.as

if you have a moment to review it for errors.

i haven't separated all the classes into different .as files yet.
I can try to help with some of these:

sketchbookgames wrote:
im not familiar with C code.
B should i be porting the .h or the .cpp files or both in some manner?

Both - the .h files specify the interface (i.e. they define the methods that will be implemented in the .cpp files, as well as the simpler implementations), and the .cpp files specify the actual code.

Quote:
the "virtual bool Process(void* userData) = 0;"
i can interpret to mean
public virtual function Process(userData:*)
C but the = 0 throws me off a bit,

Just don't worry about the "= 0", it just means that the implementation is left to a subclass.

Quote:
i did some reading on ~ as a mathematic operator and bitwise calculations last night.
D but i think "~b2QueryCallback() {}" may have something else in mind.
--edit-- i wonder if it means this class needs a kill function?

~ClassName() is a destructor for the class. In AS3 or any GC language, we don't have destructors, so you can just leave it out altogether if all it's doing is deallocating memory and stuff like that, which will happen automatically for us.

If that's not the case, and non-trivial logic happens there, it's much more difficult to port, but thus far Erin has been kind to us and refrained from such shenanigans. 🙂

sketchbookgames wrote:
this has several classes declared in it, and i think since they are publicly accessible classes they will need to be separate .as files.

Yup, there's no way around that.

Quote:
Quote:
virtual float32 Process(const b2RayCastInput& input, void* userData) = 0;

if have
b2internal virtual function Process(b2RayCastInput & input, userData:*)
--edit-- b2internal virtual function Process(input:b2RayCastInput, userData:*) // i have a feeling this is correct.

E not sure what to do with the & input, perhaps it just gets left off?

Most of the time (not quite all, unfortunately), & and * can just be deleted, and -> can turn into a dot. The & to the left of a parameter in the method signature marks the parameter as pass by reference, which for objects is (roughly speaking) how AS3 and Java pass things anyways. For primitives, this is not the case, however.

sketchbookgames wrote:
F template <typename T>
void Query(T* callback, const b2AABB& aabb) const;

Templates are tough to port if you can't use them in the target language (I don't think AS3 has templates or generics). You'll just have to look through and see how they're used and then generate the appropriate specific functions yourself; this is essentially what the C++ compiler does, you just have to do it by hand.
Ewjordan beat me to it. I wouldn't go too hard on the porting if you don't feel that confident - there are plenty of parts that don't involve creating new classes etc. It sounds like you have a good handle on things, though.

Yes, the growable broadphase is unique to the AS3 version. You'll have to check whether Erins changes cover the same area - in which case it might be easier to revert that particular change. I can fix it up for the new code later.

Templates are in general unportable. They're a hugely powerful feature in C++. However, they should be used only in specific circumstances by the API, many of which can be done. In this case, template is acting as a callback, so would properly be replaced by a Function argument in AS3, which is the equivalent technique.
Other times, templates might be best handled by multiple separate methods (as you see some overloads in C++ have been given separate names in AS3). Or sometimes you should replace what is compile time polymorphism with runtime polymorphsim (i.e. replace template arguments with an interface).
thanks for the tips.
EC says b2DynamicTree and the contact changes are not stable yet and that i should hold off on porting..

(i suppose that means once i get the go ahead i should tally up all the changed classes and look at a larger scope of Diffs)

Original thread: https://box2d.org/forum/viewtopic.php?t=3240