Skip to content

Commit

Permalink
Added Box2DFlashAS3 Sample
Browse files Browse the repository at this point in the history
git-svn-id: http://hotruby.googlecode.com/svn/trunk@18 4fb8041d-b042-0410-9571-f50be27af959
  • Loading branch information
yukoba@accelart.jp committed Jan 15, 2008
1 parent 821c489 commit 7981c6b
Show file tree
Hide file tree
Showing 89 changed files with 16,227 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/ASHeader.as
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
package { package {
import flash.display.*; import flash.display.*;
public class HotRubyFlash extends Sprite { public class HotRubyFlash extends MovieClip {
public function HotRubyFlash() { public function HotRubyFlash() {
_root = this; _root = this;
new HotRuby().run(src); new HotRuby().run(src);
Expand Down
20 changes: 14 additions & 6 deletions src/RubyNative.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,20 @@
// The license of this source is "Ruby License" // The license of this source is "Ruby License"
HotRuby.prototype.classes = { HotRuby.prototype.classes = {
"<global>" : { "<global>" : {
},

"Object" : {
"==" : function(recver, args) {
return recver == args[0] ? this.trueObj : this.falseObj;
},

"to_s" : function(recver) {
if(typeof(recver) == "number")
return recver.toString();
else
return recver.__native.toString();
},

"puts" : function(recver, args, sf) { "puts" : function(recver, args, sf) {
if(args.length == 0) { if(args.length == 0) {
this.printDebug(""); this.printDebug("");
Expand Down Expand Up @@ -46,12 +60,6 @@ HotRuby.prototype.classes = {
} }
}, },


"Object" : {
"to_s" : function(recver) {
return recver.toString();
}
},

"TrueClass" : { "TrueClass" : {
"&" : function(recver, args) { "&" : function(recver, args) {
return args[0] ? true : false; return args[0] ? true : false;
Expand Down
61 changes: 40 additions & 21 deletions src/RubyVM.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ HotRuby.prototype = {
ip = opcode.label2ip[cmd[1]]; ip = opcode.label2ip[cmd[1]];
} }
break; break;
case "opt_case_dispatch":
var v = sf.stack[--sf.sp];
if(typeof(v) != "number") v = v.__native;
for(var i=0; i<cmd[1].length; i+=2) {
if(v === cmd[1][i]) {
ip = opcode.label2ip[cmd[1][i+1]];
break;
}
}
if(i == cmd[1].length) {
ip = opcode.label2ip[cmd[2]];
}
break;
case "leave" : case "leave" :
return; return;
case "putnil" : case "putnil" :
Expand Down Expand Up @@ -386,8 +399,8 @@ HotRuby.prototype = {
var args = sf.stack.slice(sf.sp - cmd[2], sf.sp); var args = sf.stack.slice(sf.sp - cmd[2], sf.sp);
sf.sp -= cmd[2]; sf.sp -= cmd[2];
var recver = sf.stack[--sf.sp]; var recver = sf.stack[--sf.sp];
if (recver == null || recver == this.nilObj) //if (recver == null || recver == this.nilObj)
recver = sf.self; // recver = sf.self;
if(cmd[3] instanceof Array) if(cmd[3] instanceof Array)
cmd[3] = this.createRubyProc(cmd[3], sf); cmd[3] = this.createRubyProc(cmd[3], sf);
if(cmd[3] != null) if(cmd[3] != null)
Expand Down Expand Up @@ -504,8 +517,10 @@ HotRuby.prototype = {
func = recver.__methods[methodName]; func = recver.__methods[methodName];
} }
if (func == null) { if (func == null) {
//trace("recverClassName = " + recverClassName);
var searchClass = this.classes[recverClassName]; var searchClass = this.classes[recverClassName];
while (true) { while (true) {
//trace("methodName = " + methodName);
// Search method in class // Search method in class
func = searchClass[methodName]; func = searchClass[methodName];
if (func != null) break; if (func != null) break;
Expand All @@ -521,11 +536,13 @@ HotRuby.prototype = {
// Search Parent class // Search Parent class
if ("__parentClass" in searchClass) { if ("__parentClass" in searchClass) {
searchClass = searchClass.__parentClass; searchClass = searchClass.__parentClass;
//trace("searchClass = " + searchClass);
if(searchClass == null) { if(searchClass == null) {
func = null; func = null;
break; break;
} }
invokeClassName = searchClass.__className; invokeClassName = searchClass.__className;
//trace("invokeClassName = " + invokeClassName);
continue; continue;
} }
break; break;
Expand Down Expand Up @@ -605,6 +622,16 @@ HotRuby.prototype = {
* Get variable from NativeEnviornment * Get variable from NativeEnviornment
*/ */
getNativeEnvVar: function(recver, varName, args, sf) { getNativeEnvVar: function(recver, varName, args, sf) {
//trace(varName);
if(this.env == "flash" && varName == "import") {
var imp = args[0].__native;
if(imp.charAt(imp.length - 1) != "*")
throw "[getNativeEnvVar] Param must ends with * : " + imp;
this.asPackages.push(imp.substr(0, imp.length - 1));
sf.stack[sf.sp++] = this.nilObj;
return;
}

if(varName in recver.__instanceVars) { if(varName in recver.__instanceVars) {
sf.stack[sf.sp++] = recver.__instanceVars[varName]; sf.stack[sf.sp++] = recver.__instanceVars[varName];
return; return;
Expand Down Expand Up @@ -723,6 +750,15 @@ HotRuby.prototype = {
* @param v native object * @param v native object
*/ */
nativeToRubyObject: function(v) { nativeToRubyObject: function(v) {
if(v === null) {
return this.nilObj;
}
if(v === true) {
return this.trueObj;
}
if(v === false) {
return this.falseObj;
}
if(typeof(v) == "number") { if(typeof(v) == "number") {
return v; return v;
} }
Expand Down Expand Up @@ -755,6 +791,7 @@ HotRuby.prototype = {
*/ */
invokeNativeNew: function(recver, methodName, args, sf) { invokeNativeNew: function(recver, methodName, args, sf) {
var obj; var obj;
var args = this.rubyObjectAryToNativeAry(args);
switch(args.length) { switch(args.length) {
case 0: obj = new recver.__native(); break; case 0: obj = new recver.__native(); break;
case 1: obj = new recver.__native(args[0]); break; case 1: obj = new recver.__native(args[0]); break;
Expand Down Expand Up @@ -1019,25 +1056,7 @@ HotRuby.prototype = {
HotRuby.debugTextField.text += str + "\n"; HotRuby.debugTextField.text += str + "\n";
} }
this.nativeClassObjCache = {}; this.nativeClassObjCache = {};
this.asPackages = [ this.asPackages = [""];
"",
"flash.display.",
"flash.text.",
"flash.system.",
"flash.geom.",
"flash.events.",
"flash.accessbility.",
"flash.errors.",
"flash.external.",
"flash.filters.",
"flash.media.",
"flash.net.",
"flash.printing.",
"flash.profiler.",
"flash.ui.",
"flash.utils.",
"flash.xml."
];
// Create _root NativeObject // Create _root NativeObject
this.globalVars.$native.__instanceVars._root = { this.globalVars.$native.__instanceVars._root = {
__className : "NativeObject", __className : "NativeObject",
Expand Down
33 changes: 33 additions & 0 deletions test/Box2DFlashAS3/Box2D/Collision/ClipVertex.as
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

package Box2D.Collision{


import Box2D.Common.Math.*
import Box2D.Collision.*


public class ClipVertex
{
public var v:b2Vec2 = new b2Vec2();
public var id:b2ContactID = new b2ContactID();
};


}
64 changes: 64 additions & 0 deletions test/Box2DFlashAS3/Box2D/Collision/Features.as
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

package Box2D.Collision{

// We use contact ids to facilitate warm starting.
public class Features
{
//
public function set referenceFace(value:int) : void{
_referenceFace = value;
_m_id._key = (_m_id._key & 0xffffff00) | (_referenceFace & 0x000000ff)
}
public function get referenceFace():int{
return _referenceFace;
}
public var _referenceFace:int;
//
public function set incidentEdge(value:int) : void{
_incidentEdge = value;
_m_id._key = (_m_id._key & 0xffff00ff) | ((_incidentEdge << 8) & 0x0000ff00)
}
public function get incidentEdge():int{
return _incidentEdge;
}
public var _incidentEdge:int;
//
public function set incidentVertex(value:int) : void{
_incidentVertex = value;
_m_id._key = (_m_id._key & 0xff00ffff) | ((_incidentVertex << 16) & 0x00ff0000)
}
public function get incidentVertex():int{
return _incidentVertex;
}
public var _incidentVertex:int;
//
public function set flip(value:int) : void{
_flip = value;
_m_id._key = (_m_id._key & 0x00ffffff) | ((_flip << 24) & 0xff000000)
}
public function get flip():int{
return _flip;
}
public var _flip:int;
public var _m_id:b2ContactID;
};


}
39 changes: 39 additions & 0 deletions test/Box2DFlashAS3/Box2D/Collision/Shapes/b2BoxDef.as
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

package Box2D.Collision.Shapes{



import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;



public class b2BoxDef extends b2ShapeDef
{
public function b2BoxDef()
{
type = b2Shape.e_boxShape;
extents = new b2Vec2(1.0, 1.0);
}

public var extents:b2Vec2;
};

}
39 changes: 39 additions & 0 deletions test/Box2DFlashAS3/Box2D/Collision/Shapes/b2CircleDef.as
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

package Box2D.Collision.Shapes{



import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;



public class b2CircleDef extends b2ShapeDef
{
public function b2CircleDef()
{
type = b2Shape.e_circleShape;
radius = 1.0;
}

public var radius:Number;
};

}
Loading

0 comments on commit 7981c6b

Please sign in to comment.