Ejemplo n.º 1
0
static int tolua_lua_cocos2dx_userext_EntityComponent_registerHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"EntityComponent",0,&tolua_err) ||
     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
     (tolua_isvaluenil(tolua_S,3,&tolua_err) || !toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err)) ||
     !tolua_isnoobj(tolua_S,4,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  EntityComponent* self = (EntityComponent*)  tolua_tousertype(tolua_S,1,0);
  const char* event_name = ((const char*)  tolua_tostring(tolua_S,2,0));
  LUA_FUNCTION handler = (  toluafix_ref_function(tolua_S,3,0));
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'registerHandler'", NULL);
#endif
  {
   self->registerHandler(event_name,handler);
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'registerHandler'.",&tolua_err);
 return 0;
#endif
}
Ejemplo n.º 2
0
static int tolua_lua_cocos2dx_userext_EntityComponent_unregisterAllHandlers00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"EntityComponent",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  EntityComponent* self = (EntityComponent*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'unregisterAllHandlers'", NULL);
#endif
  {
   self->unregisterAllHandlers();
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'unregisterAllHandlers'.",&tolua_err);
 return 0;
#endif
}
Ejemplo n.º 3
0
void EntityComponent_SetVisible(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope handle_scope;

    EntityComponent* ptr = GetPtr(info.This());
    assert(ptr);

    ptr->setVisible(value->ToBoolean()->Value());
}
Ejemplo n.º 4
0
v8::Handle<Value> EntityComponent_IsVisible(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

    EntityComponent* ptr = GetPtr(info.This());
    assert(ptr);

    return handle_scope.Close(v8::Boolean::New(ptr->isVisible()));
}
Ejemplo n.º 5
0
v8::Handle<v8::Value> EntityComponent_FlipVisibility(const Arguments& args)
{
    HandleScope handle_scope;

    EntityComponent* ptr = GetPtr(args.This());
    assert(ptr);

    ptr->flipVisibility();

    return v8::Handle<v8::Value>();
}
Ejemplo n.º 6
0
//-------------------------------------------------------------------------------------
PyObject* EntityComponent::__py_reduce_ex__(PyObject* self, PyObject* protocol)
{
	EntityComponent* pEntityComponent = static_cast<EntityComponent*>(self);
	
	PyObject* args = PyTuple_New(2);
	PyObject* unpickleMethod = script::Pickler::getUnpickleFunc("EntityComponent");
	PyTuple_SET_ITEM(args, 0, unpickleMethod);
	
	PyObject* args1 = PyTuple_New(3);
	PyTuple_SET_ITEM(args1, 0, PyLong_FromLong(pEntityComponent->ownerID()));
	PyTuple_SET_ITEM(args1, 1, PyLong_FromLong(pEntityComponent->pComponentDescrs()->getUType()));
	PyTuple_SET_ITEM(args1, 2, PyLong_FromLong(pEntityComponent->componentType()));

	PyTuple_SET_ITEM(args, 1, args1);

	if(unpickleMethod == NULL){
		Py_DECREF(args);
		return NULL;
	}
	return args;
}
Ejemplo n.º 7
0
void InterpolateComponent::OnVarNameChanged(Variant *pDataObject)
{
	if (m_pComponentName->length())
	{
		EntityComponent * pComp = GetParent()->GetComponentByName(*m_pComponentName);
		if (!pComp)
		{
			LogError("InterpolateComponent %s is unable to find component %s to set its var %s",
				GetName().c_str(), m_pComponentName->c_str(), pDataObject->GetString().c_str());
			assert(!"Check out your log!");
			return;
		}

		m_pVar = pComp->GetVar(pDataObject->GetString());

		// If the target component gets deleted we mustn't access its variants anymore
		pComp->GetFunction("OnDelete")->sig_function.connect(1, boost::bind(&InterpolateComponent::NullifyVarPointer, this, _1));
	} else
	{
		m_pVar = GetParent()->GetVar(pDataObject->GetString());
	}
}
void ScrollBarRenderComponent::OnAdd(Entity *pEnt)
{
	EntityComponent::OnAdd(pEnt);
	//shared with the rest of the entity
	m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
	m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
	m_pScale2d = &GetParent()->GetVarWithDefault("scale2d", Variant(1.0f, 1.0f))->GetVector2();
	m_pAlpha = &GetParent()->GetVarWithDefault("alpha", Variant(0.3f))->GetFloat();
	m_pColor = &GetParent()->GetVarWithDefault("color", Variant(MAKE_RGBA(224,188,130,255)))->GetUINT32();
	m_pColorMod = &GetParent()->GetVarWithDefault("colorMod", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
	
	m_pFileName = &GetVar("fileName")->GetString(); //local to us
	
	GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnUpdate, this, _1));
	GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnRender, this, _1));
	GetParent()->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnTargetOverStart, this, _1));
	GetParent()->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnTargetOverEnd, this, _1));
	//if "fileName" is set, we'll know about it here
	GetVar("fileName")->GetSigOnChanged()->connect(boost::bind(&ScrollBarRenderComponent::OnFileNameChanged, this, _1));

	GetVar("fileName")->Set("interface/scroll_bar_caps.rttex"); //default

	EntityComponent *pScrollComp = GetParent()->GetComponentByName("Scroll");
	if (!pScrollComp)
	{
		//assume our stuff will get set from the outside
		m_pBoundsRect = &GetParent()->GetVar("boundsRect")->GetRect();
		m_pProgress2d = &GetParent()->GetVar("progress2d")->GetVector2();

	} else
	{
		m_bUsingScrollComponent = true; //I keep track of this becuse it looks like the bounds is calculated a little
		//differently with scroll components.. ??
		m_pBoundsRect = &pScrollComp->GetVar("boundsRect")->GetRect();
		m_pProgress2d = &pScrollComp->GetVar("progress2d")->GetVector2();
	}
}
Ejemplo n.º 9
0
void MessageManager::Deliver(Message *m)
{
	if (m->GetClass() == MESSAGE_CLASS_ENTITY)
	{
		if (m->GetTargetComponent())
		{
			switch (m->GetType())
			{
				case MESSAGE_TYPE_SET_ENTITY_VARIANT:
					m->GetTargetComponent()->GetVar(m->GetVarName())->Set(m->Get());
					break;

				case MESSAGE_TYPE_CALL_ENTITY_FUNCTION:
					m->GetTargetComponent()->GetShared()->CallFunctionIfExists(m->GetVarName(), &m->GetVariantList());
					break;

				case MESSAGE_TYPE_REMOVE_COMPONENT:
					//actually, we're targeting an entity but adding this component...
					m->GetTargetEntity()->AddComponent(m->GetTargetComponent());
					m->ClearComponent();
					break;

				default:
					LogError("Message delivery error");
					assert(0);
					break;
			}
	
		} 
		else if (m->GetTargetEntity())
		{
			switch (m->GetType())
			{
		
				case MESSAGE_TYPE_CALL_COMPONENT_FUNCTION_BY_NAME:
					{

						EntityComponent *pComp = m->GetTargetEntity()->GetComponentByName(m->GetStringParm());
						if (pComp)
						{
							pComp->GetFunction(m->GetVarName())->m_sig_function(&m->GetVariantList());
						} else
						{
							LogMsg("Warning: Entity %s doesn't have a component named %s to call %s on", m->GetTargetEntity()->GetName().c_str(),
								m->GetStringParm().c_str(), m->GetVarName().c_str());
						}
					}
					break;

				
				case MESSAGE_TYPE_SET_ENTITY_VARIANT:
					m->GetTargetEntity()->GetVar(m->GetVarName())->Set(m->Get());
					break;

				case MESSAGE_TYPE_CALL_ENTITY_FUNCTION:
					m->GetTargetEntity()->GetFunction(m->GetVarName())->m_sig_function(&m->GetVariantList());
					break;

				case MESSAGE_TYPE_CALL_ENTITY_FUNCTION_RECURSIVELY:

					if (m->GetType() == MESSAGE_TYPE_GUI_CLICK_START)
					{
						//this function is sort of a hack to fake a mouse click, used with automation stuff for stress tests

						//fake out our touch tracker, will override the 11th finger touch..
						BaseApp::GetBaseApp()->GetTouch(C_MAX_TOUCHES_AT_ONCE-1)->SetWasHandled(false);
						BaseApp::GetBaseApp()->GetTouch(C_MAX_TOUCHES_AT_ONCE-1)->SetWasPreHandled(false);
						BaseApp::GetBaseApp()->GetTouch(C_MAX_TOUCHES_AT_ONCE-1)->SetIsDown(true);
						BaseApp::GetBaseApp()->GetTouch(C_MAX_TOUCHES_AT_ONCE-1)->SetPos(m->GetVariantList().Get(1).GetVector2());
					}

					m->GetTargetEntity()->CallFunctionRecursively(m->GetVarName(), &m->GetVariantList());

					break;

				case MESSAGE_TYPE_REMOVE_COMPONENT:
					m->GetTargetEntity()->RemoveComponentByName(m->GetVarName());
					break;
				
				default:
					LogError("Message delivery error");
					assert(0);
					break;
			}	//entity's shared space
		} 
		else
		{
			switch (m->GetType())
			{
				case MESSAGE_TYPE_CALL_STATIC_FUNCTION:
					(m->GetFunctionPointer())(&m->GetVariantList());
					break;
			
				default:
					//LogError("Message delivery error");
					break;
					//Not actually an error, if an entity is killed while a message is in transit, it will set the entity
					//to null and some messages may end up here as they are undeliverable
			}
		}
	} 
	else //MESSAGE_CLASS_MOUSE, MESSAGE_CLASS_GAME
	{
		BaseApp::GetBaseApp()->OnMessage(*m);
	}
}
Ejemplo n.º 10
0
void App::Update()
{
	
	//game can think here.  The baseApp::Update() will run Update() on all entities, if any are added.  The only one
	//we use in this example is one that is watching for the Back (android) or Escape key to quit that we setup earlier.

	BaseApp::Update();

	if (!m_bDidPostInit)
	{
		//stuff I want loaded during the first "Update"
		m_bDidPostInit = true;
		
		//for android, so the back key (or escape on windows) will quit out of the game
		Entity *pEnt = GetEntityRoot()->AddEntity(new Entity);
		EntityComponent *pComp = pEnt->AddComponent(new CustomInputComponent);
		//tell the component which key has to be hit for it to be activated
		pComp->GetVar("keycode")->Set(uint32(VIRTUAL_KEY_BACK));
		//attach our function so it is called when the back key is hit
		pComp->GetFunction("OnActivated")->sig_function.connect(1, boost::bind(&App::OnExitApp, this, _1));

		//nothing will happen unless we give it input focus
		pEnt->AddComponent(new FocusInputComponent);

		//ACCELTEST:  To test the accelerometer uncomment below: (will print values to the debug output)
		//SetAccelerometerUpdateHz(25); //default is 0, disabled
		//GetBaseApp()->m_sig_accel.connect(1, boost::bind(&App::OnAccel, this, _1));

		//TRACKBALL/ARCADETEST: Uncomment below to see log messages on trackball/key movement input
		pComp = pEnt->AddComponent(new ArcadeInputComponent);
		GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&App::OnArcadeInput, this, _1));
	
		//these arrow keys will be triggered by the keyboard, if applicable
		AddKeyBinding(pComp, "Left", VIRTUAL_KEY_DIR_LEFT, VIRTUAL_KEY_DIR_LEFT);
		AddKeyBinding(pComp, "Right", VIRTUAL_KEY_DIR_RIGHT, VIRTUAL_KEY_DIR_RIGHT);
		AddKeyBinding(pComp, "Up", VIRTUAL_KEY_DIR_UP, VIRTUAL_KEY_DIR_UP);
		AddKeyBinding(pComp, "Down", VIRTUAL_KEY_DIR_DOWN, VIRTUAL_KEY_DIR_DOWN);
		AddKeyBinding(pComp, "Shift", VIRTUAL_KEY_CONTROL, VIRTUAL_KEY_CONTROL);
		AddKeyBinding(pComp, "Fire", VIRTUAL_KEY_CONTROL, VIRTUAL_KEY_GAME_FIRE);

		//INPUT TEST - wire up input to some functions to manually handle.  AppInput will use LogMsg to
		//send them to the log.  (Each device has a way to view a debug log in real-time)
		GetBaseApp()->m_sig_input.connect(&AppInput);

		/*
		//file handling test, if TextScanner.h is included at the top..

		TextScanner t;
		t.m_lines.push_back("Testing 123");
		t.m_lines.push_back("F**k ya'll!");
		t.m_lines.push_back("Whoopsopsop!");

		LogMsg("Saving file...");
		t.SaveFile("temp.txt");


		TextScanner b;
		b.LoadFile("temp.txt");
		b.DumpToLog();
		*/
	}

	//game is thinking.  
	if (g_game->game_state_ == 1) //we update the objects
	{
		g_game->update();
	}
}
Ejemplo n.º 11
0
EntityView* EntityFactory::createEntity(ulong entityType, ulong resType, Stream* stream, size_t len)
{
	if (entityType >= typeMaxCount)
	{
		Error("Unknow entity type: "<<entityType<<endl);
		return NULL;
	}

	if (resType < 0 || resType >= ResourceTypeMaxCount)
	{
		Error("ResourceType("<<resType<<") is Error!"<<endl);
		return NULL;
	}

	EntityView* view = NULL;

	switch (entityType)
	{
	case typeStatic:
	case typeWaypoint:
	case typeSpile:
		{
			EntityViewImpl* ev = new EntityViewImpl();
			ev->setEntityType(entityType);
			ev->setResType(resType);
			view = ev;

			EntityComponent* ec = new VisualComponentMPW();
			ec->setOwner(ev);
			ec->create();
			ev->setComponent(ComponentIDVisual, ec);
		}
		break;

	
	 //case typeCreature: //下面3个取代typeCreature
	case typePerson:
	case typePet:
	case typeMonster:
	case typeCage:
		{
			EntityViewImpl* ev = new EntityViewImpl();
			ev->setEntityType(entityType);
			ev->setResType(resType);
            //  生物(包括主角和怪物)设置为不占位;
            ev->setOccupantValue(0);
			view = ev;

			EntityComponent* ec = new VisualComponentMZ();
			ec->setOwner(ev);
			ec->create();
			ev->setComponent(ComponentIDVisual, ec);

			MoveComponentMZ* mc = new MoveComponentMZ();
			mc->setOwner(ev);
			mc->create();
			ev->setComponent(ComponentIDMove, mc);
		}
		break;
	case typeBox:
	case typeBubble: //add by zjp
		{
			EntityViewImpl* ev = new EntityViewImpl();
			ev->setEntityType(entityType);
			ev->setResType(resType);
			view = ev;

			ev->setOccupantValue(0);
			EntityComponent* ec = new VisualComponentBOX();
			ec->setOwner(ev);
			ec->create();
			ev->setComponent(ComponentIDVisual, ec);
		}
		break;

	case typeEffect:
		{
			MagicView* ev = new MagicView();
			ev->setEntityType(entityType);
			ev->setResType(resType);
			view = ev;
		}
		break;

	default:
		Error("No implement new object or memory error, entity type: "<<entityType<<endl);
		return NULL;
	}

	if (!view)
		return NULL;

	size_t actual = view->onLoad(stream, len);
	if (actual == 0 || actual > len)
	{
		Error("onLoad(), length error, entity type: "<<entityType<<endl);
		view->release();
		return NULL;
	}

	return view;
}