Permalink
Browse files

Stubbed Function::apply

  • Loading branch information...
alexp-sssup committed Feb 22, 2010
1 parent 40068ab commit 7dd7136c89f762bceab37f6444ce93039cafbea7
Showing with 126 additions and 60 deletions.
  1. +1 −1 abc.cpp
  2. +0 −6 abc_opcodes.cpp
  3. +26 −3 asobjects.cpp
  4. +2 −11 asobjects.h
  5. +87 −35 flashdisplay.cpp
  6. +4 −3 flashdisplay.h
  7. +6 −1 swftypes.cpp
View
@@ -807,7 +807,7 @@ multiname* ABCContext::getMultiname(unsigned int n, call_context* th)
switch(m->kind)
{
case 0x1d:
- cout << "PUPPA" << endl;
+ abort();
case 0x07:
case 0x09:
{
View
@@ -489,12 +489,6 @@ bool ABCVm::ifNLT(ASObject* obj2, ASObject* obj1)
{
//Real comparision demanded to object
bool ret=!(obj1->isLess(obj2));
- if(obj1->getObjectType()==T_INTEGER ||
- obj1->getObjectType()==T_UINTEGER)
- cout << obj1->toInt() << endl;
- if(obj2->getObjectType()==T_INTEGER ||
- obj2->getObjectType()==T_UINTEGER)
- cout << obj2->toInt() << endl;
LOG(LOG_CALLS,"ifNLT (" << ((ret)?"taken)":"not taken)"));
obj2->decRef();
View
@@ -159,7 +159,6 @@ ASFUNCTIONBODY(Array,_concat)
//this array could die too
for(int i=0;i<ret->data.size();i++)
{
-
if(ret->data[i].type==STACK_OBJECT)
ret->data[i].data->incRef();
}
@@ -195,7 +194,7 @@ ASFUNCTIONBODY(Array,unshift)
}
th->data.insert(th->data.begin(),args->at(0));
args->at(0)->incRef();
- return new Integer(th->size());
+ return abstract_i(th->size());
}
ASFUNCTIONBODY(Array,_push)
@@ -208,7 +207,7 @@ ASFUNCTIONBODY(Array,_push)
}
th->push(args->at(0));
args->at(0)->incRef();
- return new Integer(th->size());
+ return abstract_i(th->size());
}
ASMovieClipLoader::ASMovieClipLoader()
@@ -972,6 +971,30 @@ IFunction* Function::toFunction()
return this;
}
+IFunction::IFunction():bound(false),closure_this(NULL),closure_level(-1),overriden_by(NULL)
+{
+ type=T_FUNCTION;
+}
+
+ASFUNCTIONBODY(IFunction,apply)
+{
+ IFunction* th=static_cast<IFunction*>(obj);
+ assert(args->size()==2);
+
+ //Validate parameters
+ assert(args->at(1)->getObjectType()==T_ARRAY);
+ Array* array=Class<Array>::cast(args->at(1)->implementation);
+
+ int len=array->size();
+ ASObject** new_args=new ASObject*[len];
+ for(int i=0;i<len;i++)
+ new_args[i]=array->at(i);
+
+ ASObject* ret=th->fast_call(args->at(0),new_args,len,0);
+ delete[] new_args;
+ return ret;
+}
+
SyntheticFunction::SyntheticFunction(method_info* m):mi(m),hit_count(0),val(NULL)
{
// class_index=-2;
View
@@ -198,7 +198,8 @@ class Class_function: public Class_base
class IFunction: public ASObject
{
public:
- IFunction():bound(false),closure_this(NULL),closure_level(-1),overriden_by(NULL){type=T_FUNCTION;}
+ ASFUNCTION(apply);
+ IFunction();
typedef ASObject* (*as_function)(ASObject*, arguments*);
virtual ASObject* call(ASObject* obj, arguments* args, int level)=0;
virtual ASObject* fast_call(ASObject* obj, ASObject** args,int num_args, int level)=0;
@@ -208,16 +209,6 @@ class IFunction: public ASObject
{
//If binding with null we are not a class method
IFunction* ret;
- /*if(c!=NULL)
- {
- c->incRef();
- ret=clone();
- }
- else
- {
- incRef();
- ret=this;
- }*/
incRef();
ret=this;
ret->bound=true;
View
@@ -291,6 +291,8 @@ void Sprite::getBounds(number_t& xmin, number_t& xmax, number_t& ymin, number_t&
void Sprite::Render()
{
+ assert(obj && obj->prototype);
+
glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glDisable(GL_BLEND);
glClearColor(1,1,1,0);
@@ -443,24 +445,6 @@ ASFUNCTIONBODY(MovieClip,createEmptyMovieClip)
return ret;*/
}
-ASFUNCTIONBODY(MovieClip,moveTo)
-{
- LOG(LOG_NOT_IMPLEMENTED,"Called moveTo");
- return NULL;
-}
-
-ASFUNCTIONBODY(MovieClip,lineTo)
-{
- LOG(LOG_NOT_IMPLEMENTED,"Called lineTo");
- return NULL;
-}
-
-ASFUNCTIONBODY(MovieClip,lineStyle)
-{
- LOG(LOG_NOT_IMPLEMENTED,"Called lineStyle");
- return NULL;
-}
-
ASFUNCTIONBODY(MovieClip,swapDepths)
{
LOG(LOG_NOT_IMPLEMENTED,"Called swapDepths");
@@ -677,6 +661,7 @@ ASFUNCTIONBODY(DisplayObject,_setY)
DisplayObject* th=static_cast<DisplayObject*>(obj->implementation);
assert(args && args->size()==1);
th->Matrix.TranslateY=args->at(0)->toInt();
+ cout << th->Matrix.TranslateY << endl;
return NULL;
}
@@ -814,14 +799,20 @@ ASFUNCTIONBODY(DisplayObject,_getWidth)
number_t x1,x2,y1,y2;
th->getBounds(x1,x2,y1,y2);
- th->width=x2-x1;
- return abstract_i(th->width);
+ return abstract_i(x2-x1);
}
ASFUNCTIONBODY(DisplayObject,_getHeight)
{
DisplayObject* th=static_cast<DisplayObject*>(obj->implementation);
- return abstract_i(th->height);
+ //If the height has been explicity set, return that
+ if(th->height!=0)
+ return abstract_b(th->height);
+
+ number_t x1,x2,y1,y2;
+ th->getBounds(x1,x2,y1,y2);
+
+ return abstract_i(y2-y1);
}
void DisplayObjectContainer::sinit(Class_base* c)
@@ -838,6 +829,7 @@ void DisplayObjectContainer::buildTraits(ASObject* o)
o->setVariableByQName("getChildIndex","",new Function(getChildIndex));
o->setVariableByQName("getChildAt","",new Function(getChildAt));
o->setVariableByQName("addChild","",new Function(addChild));
+ o->setVariableByQName("removeChild","",new Function(removeChild));
o->setVariableByQName("addChildAt","",new Function(addChildAt));
o->setVariableByQName("contains","",new Function(contains));
o->setSetterByQName("mouseChildren","",new Function(undefinedFunction));
@@ -855,7 +847,8 @@ ASFUNCTIONBODY(DisplayObjectContainer,_constructor)
ASFUNCTIONBODY(DisplayObjectContainer,_getNumChildren)
{
- return new Integer(0);;
+ DisplayObjectContainer* th=static_cast<DisplayObjectContainer*>(obj->implementation);
+ return abstract_i(th->dynamicDisplayList.size());
}
void DisplayObjectContainer::_addChildAt(DisplayObject* child, int index)
@@ -877,8 +870,16 @@ void DisplayObjectContainer::_addChildAt(DisplayObject* child, int index)
child->parent=this;
//We insert the object in the back of the list
- //TODO: support the 'at index' version of the call
- dynamicDisplayList.push_back(child);
+ if(index==-1)
+ dynamicDisplayList.push_back(child);
+ else
+ {
+ assert(index<=dynamicDisplayList.size());
+ list<IDisplayListElem*>::iterator it=dynamicDisplayList.begin();
+ for(int i=0;i<index;i++)
+ it++;
+ dynamicDisplayList.insert(it,child);
+ }
}
void DisplayObjectContainer::_removeChild(IDisplayListElem* child)
@@ -889,6 +890,7 @@ void DisplayObjectContainer::_removeChild(IDisplayListElem* child)
list<IDisplayListElem*>::iterator it=find(dynamicDisplayList.begin(),dynamicDisplayList.end(),child);
assert(it!=dynamicDisplayList.end());
dynamicDisplayList.erase(it);
+ child->parent=NULL;
}
bool DisplayObjectContainer::_contains(DisplayObject* d)
@@ -930,9 +932,11 @@ ASFUNCTIONBODY(DisplayObjectContainer,addChildAt)
assert(args->at(0)->prototype->isSubClass(Class<DisplayObject>::getClass()));
args->at(0)->incRef();
+ int index=args->at(1)->toInt();
+
//Cast to object
DisplayObject* d=Class<DisplayObject>::cast(args->at(0)->implementation);
- th->_addChildAt(d,0);
+ th->_addChildAt(d,index);
//Notify the object
d->obj->incRef();
@@ -941,6 +945,21 @@ ASFUNCTIONBODY(DisplayObjectContainer,addChildAt)
return d->obj;
}
+ASFUNCTIONBODY(DisplayObjectContainer,removeChild)
+{
+ DisplayObjectContainer* th=static_cast<DisplayObjectContainer*>(obj->implementation);
+ assert(args->size()==1);
+ //Validate object type
+ assert(args->at(0)->prototype->isSubClass(Class<DisplayObject>::getClass()));
+ //Cast to object
+ DisplayObject* d=Class<DisplayObject>::cast(args->at(0)->implementation);
+
+ th->_removeChild(d);
+
+ //As we return the child we don't decRef it
+ return d->obj;
+}
+
ASFUNCTIONBODY(DisplayObjectContainer,addChild)
{
DisplayObjectContainer* th=static_cast<DisplayObjectContainer*>(obj->implementation);
@@ -951,7 +970,7 @@ ASFUNCTIONBODY(DisplayObjectContainer,addChild)
//Cast to object
DisplayObject* d=Class<DisplayObject>::cast(args->at(0)->implementation);
- th->_addChildAt(d,0);
+ th->_addChildAt(d,-1);
//Notify the object
d->obj->incRef();
@@ -1117,6 +1136,7 @@ void Graphics::buildTraits(ASObject* o)
o->setVariableByQName("clear","",new Function(clear));
o->setVariableByQName("drawRect","",new Function(drawRect));
o->setVariableByQName("moveTo","",new Function(moveTo));
+ o->setVariableByQName("lineTo","",new Function(lineTo));
o->setVariableByQName("beginFill","",new Function(beginFill));
}
@@ -1172,11 +1192,42 @@ ASFUNCTIONBODY(Graphics,moveTo)
Graphics* th=static_cast<Graphics*>(obj->implementation);
assert(args->size()==2);
+ //As we are moving, first of all flush the shape
+ th->flushShape();
+
th->curX=args->at(0)->toInt();
th->curY=args->at(1)->toInt();
return NULL;
}
+ASFUNCTIONBODY(Graphics,lineTo)
+{
+ Graphics* th=static_cast<Graphics*>(obj->implementation);
+ assert(args->size()==2);
+
+ int x=args->at(0)->toInt();
+ int y=args->at(1)->toInt();
+
+ //If this is the first line, add also the starting point
+ if(th->tmpShape.outline.size()==0)
+ th->tmpShape.outline.push_back(Vector2(th->curX,th->curY));
+
+ th->tmpShape.outline.push_back(Vector2(x,y));
+
+ return NULL;
+}
+
+void Graphics::flushShape()
+{
+ if(!tmpShape.outline.empty())
+ {
+ sem_wait(&geometry_mutex);
+ geometry.push_back(tmpShape);
+ sem_post(&geometry_mutex);
+ tmpShape=GeomShape();
+ }
+}
+
ASFUNCTIONBODY(Graphics,drawRect)
{
Graphics* th=static_cast<Graphics*>(obj->implementation);
@@ -1187,17 +1238,17 @@ ASFUNCTIONBODY(Graphics,drawRect)
int width=args->at(2)->toInt();
int height=args->at(3)->toInt();
+ th->flushShape();
+
//Build a shape and add it to the geometry vector
- GeomShape tmpShape;
- tmpShape.outline.push_back(Vector2(x,y));
- tmpShape.outline.push_back(Vector2(x+width,y));
- tmpShape.outline.push_back(Vector2(x+width,y+height));
- tmpShape.outline.push_back(Vector2(x,y+height));
- tmpShape.outline.push_back(Vector2(x,y));
+ th->tmpShape.outline.push_back(Vector2(x,y));
+ th->tmpShape.outline.push_back(Vector2(x+width,y));
+ th->tmpShape.outline.push_back(Vector2(x+width,y+height));
+ th->tmpShape.outline.push_back(Vector2(x,y+height));
+ th->tmpShape.outline.push_back(Vector2(x,y));
+
+ th->flushShape();
- sem_wait(&th->geometry_mutex);
- th->geometry.push_back(tmpShape);
- sem_post(&th->geometry_mutex);
return NULL;
}
@@ -1213,6 +1264,7 @@ ASFUNCTIONBODY(Graphics,beginFill)
void Graphics::Render()
{
+ //Should probably flush the shape
sem_wait(&geometry_mutex);
for(int i=0;i<geometry.size();i++)
View
@@ -119,6 +119,7 @@ class DisplayObjectContainer: public DisplayObject
ASFUNCTION(_constructor);
ASFUNCTION(_getNumChildren);
ASFUNCTION(addChild);
+ ASFUNCTION(removeChild);
ASFUNCTION(addChildAt);
ASFUNCTION(getChildIndex);
ASFUNCTION(getChildAt);
@@ -131,7 +132,9 @@ class Graphics: public IInterface
//As geometry is used by RenderThread but modified by ABCVm we have to mutex a bit
sem_t geometry_mutex;
std::vector<GeomShape> geometry;
+ GeomShape tmpShape;
int curX, curY;
+ void flushShape();
public:
Graphics():curX(0),curY(0)
{
@@ -143,6 +146,7 @@ class Graphics: public IInterface
ASFUNCTION(beginFill);
ASFUNCTION(drawRect);
ASFUNCTION(moveTo);
+ ASFUNCTION(lineTo);
ASFUNCTION(clear);
void Render();
void getBounds(number_t& xmin, number_t& xmax, number_t& ymin, number_t& ymax);
@@ -264,9 +268,6 @@ friend class ParseThread;
static void sinit(Class_base* c);
static void buildTraits(ASObject* o);
ASFUNCTION(_constructor);
- ASFUNCTION(moveTo);
- ASFUNCTION(lineStyle);
- ASFUNCTION(lineTo);
ASFUNCTION(swapDepths);
ASFUNCTION(createEmptyMovieClip);
ASFUNCTION(addFrameScript);
Oops, something went wrong.

0 comments on commit 7dd7136

Please sign in to comment.