Beispiel #1
0
	// Adds child at <code>index<code/>, or does nothing if <code>index<code/> greater than <code>numChildren</code>.
	void DisplayObject::addChildAt(DisplayObject * displayObject, unsigned int index)
	{
		if (index <= numChildren()) {
			std::vector<DisplayObject*>::iterator it;
			
			// Get iterator for index.
			it = _children.begin();
			it += index;
			
			// Insert child
			_children.insert(it, displayObject);
			displayObject->setParent(this);
			
			// hold on to it so it doesn't get freed.
			retain(displayObject);
		}
	}
Beispiel #2
0
void NetworkSprite::loadTexture() {
	if (_asset && _asset->isReadAvailable()) {
		auto cache = TextureCache::getInstance();

		Asset * asset = _asset;

		retain();
		cache->addTexture(_asset, [this, asset] (cocos2d::Texture2D *tex) {
			if (asset == _asset && tex) {
				setTexture(tex, Rect(0, 0, tex->getContentSize().width, tex->getContentSize().height));
			}
			release();
		}, _texture != nullptr);
	} else {
		setTexture(nullptr, Rect::ZERO);
	}
}
Beispiel #3
0
//--------------------------------------------------------------
void ofVbo::setVertexData(const float * vert0x, int numCoords, int total, int usage, int stride) {

#ifdef TARGET_OPENGLES
	if(!vaoChecked){
		if(ofGetGLProgrammableRenderer()){
			glGenVertexArrays = (glGenVertexArraysType)dlsym(RTLD_DEFAULT, "glGenVertexArrays");
			glDeleteVertexArrays =  (glDeleteVertexArraysType)dlsym(RTLD_DEFAULT, "glDeleteVertexArrays");
			glBindVertexArray =  (glBindVertexArrayType)dlsym(RTLD_DEFAULT, "glBindVertexArrayArrays");
		}else{
			glGenVertexArrays = (glGenVertexArraysType)dlsym(RTLD_DEFAULT, "glGenVertexArraysOES");
			glDeleteVertexArrays =  (glDeleteVertexArraysType)dlsym(RTLD_DEFAULT, "glDeleteVertexArraysOES");
			glBindVertexArray =  (glBindVertexArrayType)dlsym(RTLD_DEFAULT, "glBindVertexArrayArraysOES");
		}
		vaoChecked = true;
		supportVAOs = glGenVertexArrays && glDeleteVertexArrays && glBindVertexArray;
	}
#else
	if(!vaoChecked){
		supportVAOs = ofGetGLProgrammableRenderer() || glewIsSupported("GL_ARB_vertex_array_object");
		vaoChecked = true;
	}
#endif


	if(vertId==0) {
		bAllocated  = true;
		bUsingVerts = true;
		vaoChanged=true;
		glGenBuffers(1, &(vertId));
		retain(vertId);
		#if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS)
			registerVbo(this);
		#endif
	}

	vertUsage = usage;
	vertSize = numCoords;
	vertStride = stride==0?3*sizeof(float):stride;
	totalVerts = total;
	
	glBindBuffer(GL_ARRAY_BUFFER, vertId);
	glBufferData(GL_ARRAY_BUFFER, total * stride, vert0x, usage);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

}
Beispiel #4
0
int Application::run()
{
    initGLContextAttrs();
    // Initialize instance and cocos2d.
    if (! applicationDidFinishLaunching())
    {
        return 0;
    }

    long lastTime = 0L;
    long curTime = 0L;

    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();

    // Retain glview to avoid glview being released in the while loop
    glview->retain();

    while (!glview->windowShouldClose())
    {
        lastTime = getCurrentMillSecond();

        director->mainLoop();
        glview->pollEvents();

        curTime = getCurrentMillSecond();
        if (curTime - lastTime < _animationInterval)
        {
            usleep((_animationInterval - curTime + lastTime)*1000);
        }
    }
    /* Only work on Desktop
    *  Director::mainLoop is really one frame logic
    *  when we want to close the window, we should call Director::end();
    *  then call Director::mainLoop to do release of internal resources
    */
    if (glview->isOpenGLReady())
    {
        director->end();
        director->mainLoop();
        director = nullptr;
    }
    glview->release();
    return -1;
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Starcraft");
        director->setOpenGLView(glview);
    }
    
    glview->setDesignResolutionSize(DISPLAY_WIDTH, DISPLAY_HEIGHT, ResolutionPolicy::SHOW_ALL);

    // turn on display FPS
    director->setDisplayStats(true);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    register_all_packages();
    
    ///////////////////////////로그인 서버로 접속

    if(PLAY_ALONE) {
        glview->setDesignResolutionSize(1280, 720, ResolutionPolicy::SHOW_ALL);
        auto scene = GameWorld::createScene();
        
        // run
        director->runWithScene(scene);
    }else{
        GameClient::GetInstance().Initialize();
        
        auto networkBGLayer = NetworkLayer::create();
        networkBGLayer->retain();
        
        GameClient::GetInstance().currentScene = NO_SCENE_NOW;
        
        Scene* scene = HelloWorld::createScene();
        
        scene->addChild(networkBGLayer, 0, TAG_NETWORK_LAYER);
        Director::getInstance()->runWithScene(scene);
        
        networkBGLayer->handler->frontSendFirstConnectReq();
    }

    return true;
}
Beispiel #6
0
ofVbo & ofVbo::operator=(const ofVbo& mom){
	if(&mom==this) return *this;
	clear();
	bUsingVerts = mom.bUsingVerts;
	bUsingTexCoords = mom.bUsingTexCoords;
	bUsingColors = mom.bUsingColors;
	bUsingNormals = mom.bUsingNormals;
	bUsingIndices = mom.bUsingIndices;

	vertSize		= mom.vertSize;
	vertStride      = mom.vertStride;
	colorStride		= mom.colorStride;
	normalStride    = mom.normalStride;
	texCoordStride  = mom.texCoordStride;

	vertUsage		= mom.vertUsage;
	colorUsage		= mom.colorUsage;
	normUsage		= mom.normUsage;
	texUsage		= mom.texUsage;

	vertId     = mom.vertId;
	retain(vertId);
	normalId   = mom.normalId;
	retain(normalId);
	colorId    = mom.colorId;
	retain(colorId);
	texCoordId = mom.texCoordId;
	retain(texCoordId);
	indexId    = mom.indexId;
	retain(indexId);
	if(supportVAOs){
		vaoID	   = mom.vaoID;
		retainVAO(vaoID);
		vaoChanged = mom.vaoChanged;
	}

	attributeIds = mom.attributeIds;
	for (map<int, GLuint>::iterator it = attributeIds.begin(); it != attributeIds.end(); it++){
		retain(it->second);
	}
	
	attributeNumCoords = mom.attributeNumCoords;
	attributeStrides = mom.attributeStrides;
	attributeSize = mom.attributeSize;
	
	totalVerts = mom.totalVerts;
	totalIndices = mom.totalIndices;

	bAllocated		= mom.bAllocated;
	bBound   = mom.bBound;
	return *this;
}
Beispiel #7
0
unsigned long Channel::push(Variant *var)
{
	if (!var)
		return 0;

	Lock l(mutex);
	var->retain();

	// Keep a reference to ourselves
	// if we're non-empty and named.
	if (named && queue.empty())
		retain();

	queue.push(var);
	cond->broadcast();

	return ++sent;
}
Beispiel #8
0
void HelloWorld::initScene()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    auto vp = Camera::getDefaultViewport();
    auto node = CSLoader::createNode("res/Scene3DNoParticle.csb");
    node->setCameraMask((unsigned short)CameraFlag::USER1, true);
    addChild(node);
    _headNode = node->getChildByTag(57);
    {
        _camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height * 0.5,0.1f,800);
        _camera->setCameraFlag(CameraFlag::USER1);
        //
        //        _camera->setPosition3D(Vec3(-0.01,0,0));
        _camera->setFrameBufferObject(Director::getInstance()->getDefaultFBO());
        _camera->setViewport(experimental::Viewport(vp._left,vp._bottom, vp._width/2, vp._height));
        _headNode->addChild(_camera);
        
        _camera2 = Camera::createPerspective(60,visibleSize.width/visibleSize.height * 0.5,0.1f,800);
        _camera2->setCameraFlag(CameraFlag::USER1);
        //
        //        _camera->setPosition3D(Vec3(-0.01,0,0));
        _camera2->setFrameBufferObject(Director::getInstance()->getDefaultFBO());
        _camera2->setViewport(experimental::Viewport(vp._left + vp._width/2,vp._bottom, vp._width/2, vp._height));
        _headNode->addChild(_camera2);
    }
    
    //add skybox
    {
        auto textureCube = TextureCube::create("skybox/left.jpg", "skybox/right.jpg",
                                           "skybox/top.jpg", "skybox/bottom.jpg",
                                           "skybox/front.jpg", "skybox/back.jpg");
        auto skyBox = Skybox::create();
        skyBox->retain();
        
        skyBox->setTexture(textureCube);
        addChild(skyBox);
        skyBox->setCameraMask((unsigned short)CameraFlag::USER1);
    }
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    CCASSERT(_headNode, "");
}
Beispiel #9
0
/**
 * @brief Reads a Boole from `reader`.
 * @param reader The JSONReader.
 * @return The Boole.
 */
static _Bool *readBoole(JSONReader *reader) {

	Boole *boolean = NULL;

	switch (*reader->b) {
		case 't':
			consumeBytes(reader, "true");
			boolean = $$(Boole, True);
			break;
		case 'f':
			consumeBytes(reader, "false");
			boolean = $$(Boole, False);
			break;
		default:
			assert(false);
	}

	return retain(boolean);
}
Beispiel #10
0
/**
 * @fn Array *Array::initWithArray(Array *self, const Array *array)
 *
 * @memberof Array
 */
static Array *initWithArray(Array *self, const Array *array) {

	self = (Array *) super(Object, self, init);
	if (self) {

		self->count = array->count;
		if (self->count) {

			self->elements = calloc(self->count, sizeof(ident));
			assert(self->elements);

			for (size_t i = 0; i < self->count; i++) {
				self->elements[i] = retain(array->elements[i]);
			}
		}
	}

	return self;
}
Beispiel #11
0
void CAAlertView::showMessage(std::string title, std::string alertMsg, std::vector<std::string>& vBtnText)
{
	setTitleImage(CAImage::create("source_material/alert_title.png"));
	setContentBackGroundImage(CAImage::create("source_material/alert_content.png"));
	setTitle(title.c_str(), CAColor_white);
	setAlertMessage(alertMsg.c_str());
	
	initAllButton(vBtnText);
	setAllBtnBackGroundImage(CAControlStateNormal, CAImage::create("source_material/alert_btn.png"));
	setAllBtnBackGroundImage(CAControlStateHighlighted, CAImage::create("source_material/alert_btn_sel.png"));
	setAllBtnTextColor();

	calcuCtrlsSize();

	CAApplication* pApplication = CAApplication::getApplication();
	CCAssert(pApplication != NULL, "");
	pApplication->getRootWindow()->insertSubview(this, CAWindowZoderCenter);
	retain();
}
Beispiel #12
0
//----------------------------------------
void ofLight::enable() {
	if(glIndex==-1){
		// search for the first free block
		for(int i=0; i<OF_MAX_LIGHTS; i++) {
			if(getActiveLights()[i] == false) {
				glIndex = i;
				retain(glIndex);
				enable();
				return;
			}
		}
	}
	if(glIndex!=-1) {
		ofEnableLighting();
		glEnable(GL_LIGHT0 + glIndex);
	}else{
		ofLog(OF_LOG_ERROR, "Trying to create too many lights: " + ofToString(glIndex));
	}
}
Beispiel #13
0
Goal::Goal():clampPos(nullptr){
	Sprite::init();
	_isDead = false;

	PhysicsBody* pb = PhysicsBody::createCircle(25);
	pb->setMass(1000.0f);
	pb->setDynamic(true);
	pb->setContactTestBitmask(true);
	setPhysicsBody(pb);
	setName("Goal");
	
	/*-------
	 当たり判定
	 --------*/
	auto c = CollisionDelegate<Goal>::create(this, &Goal::onContact);
	CollisionFuncManager::getInstance()->addFunc(this->getName(), c);

	retain();
}
bool IOFWSyncer::init(bool twoRetains)
{
    if (!OSObject::init())
        return false;

    if (!(guardLock = IOSimpleLockAlloc()) )
        return false;
	
    IOSimpleLockInit(guardLock);

    if(twoRetains)
	retain();

    fResult = kIOReturnSuccess;

    reinit();

    return true;
}
Beispiel #15
0
ARC<TextureProtocol>
SDLRenderer::textureFromImage(const std::string& image) {
    
    if(_textureCache.find(image) != _textureCache.end()) {
        return alloc<SDLTexture>(_textureCache[image]);
    }
    
    // TODO: Replace with cache call for SDL_Texture
    SDL_Texture* _sdl = IMG_LoadTexture(_renderer, image.c_str());
    if(_sdl == nullptr) {
        throw std::runtime_error(std::string("Error creating texture: ")+IMG_GetError());
    }
    SDL_SetTextureBlendMode(_sdl, SDL_BLENDMODE_BLEND);
    
    auto texture = alloc<SDLTextureRef>(_sdl);
    _textureCache[image] = texture;
    texture->retain();
    
    return alloc<SDLTexture>(texture);
}
Beispiel #16
0
obj udef_op0(obj ope, obj v){
	assert(type(ope)==tSymbol);
	obj lamb = find_var(ope);
	if(!lamb) return nil;
	assert(type(lamb)==tClosure);
	list ll = seek_lamb(ul(lamb), v);
	if(! ll) {
		return nil;
	}
	if(type(first(ll))==tInternalFn) error("user-defined operator not defined for the type.");
	obj vars = Assoc();
	bind_vars(&vars, first(ll), v);
	push(env);
	env = op(vars, retain(third(ll)));
	release(lamb);	//execÇÃǻǩÇ≈lambÇ™çÌèúÇ≥ÇÍÇÈâ¬î\ê´Ç†ÇË
	obj rr = exec(second(ll));
	release(env);
	env = pop(&is);
	return strip_return(rr);
}
Beispiel #17
0
 bp::Object * invoke(const std::string & functionName,
                     unsigned int id,
                     std::vector<const bp::Object *> args)
 {
     if (!functionName.compare("stop")) {
         m_rl->stop();            
     } else if (!functionName.compare("setTimeout")) {
         // extract arguments
         CPPUNIT_ASSERT( args.size() == 2 ); 
         unsigned int msec = (unsigned int) ((long long) *args[1]);
         CPPUNIT_ASSERT_EQUAL( args[0]->type(), BPTCallBack ); 
         m_tid = id;
         m_cb = bp::CallBack(*(args[0]));
         retain(id);
         m_t.setMsec(msec);
     } else {
         BP_THROW_FATAL("no such function");
     }
     return NULL;
 }
Beispiel #18
0
//----------------------------------------
void ofLight::enable() {
	if(glIndex==-1){
		bool bLightFound = false;
		// search for the first free block
		for(int i=0; i<OF_MAX_LIGHTS; i++) {
			if(getActiveLights()[i] == false) {
				glIndex = i;
				retain(glIndex);
				bLightFound = true;
				break;
			}
		}
		if( !bLightFound ){
			ofLog(OF_LOG_ERROR, "ofLight : Trying to create too many lights: " + ofToString(glIndex));
		}
	}
	
	ofEnableLighting();
	glEnable(GL_LIGHT0 + glIndex);
}
void DungeonLayer::reset() {
  _monsterRoomDatas.clear();
  this->removeAllChildren();
  
  auto initialRoom = Game::getInstance()->getDungeon()->getInitialRoom();
  auto initialCoordinate = INITIAL_COORDINATE;
  
  auto initialSprite = DungeonRoomSprite::createWithRoom(initialRoom);
  initialSprite->setCoordinate(initialCoordinate);
  
  this->addChild(initialSprite, DUNGEON_ROOM_WITH_CHAR_Z_ORDER);
  
  auto character = Game::getInstance()->getPlayer()->getCharacter();
  
  auto characterSprite = character->getSprite();
  characterSprite->retain();
  characterSprite->removeFromParent();
  characterSprite->setPosition(PositionUtil::centerOfNode(initialSprite));
  initialSprite->addChild(characterSprite);
  characterSprite->release();
}
//--------------------------------------------------------------
void ofVboByteColor::setVertexData(const float * vert0x, int numCoords, int total, int usage, int stride) {
	if(vert0x == NULL) {
		ofLog(OF_LOG_WARNING,"ofVboByteColor: bad vertex data!\n");
		return;	
	}
	if(vertId==0) {
		bAllocated  = true;
		bUsingVerts = true;
		glGenBuffers(1, &(vertId));
		retain(vertId);
	}

	vertUsage = usage;
	vertSize = numCoords;
	vertStride = stride;
	totalVerts = total;
	
	glBindBuffer(GL_ARRAY_BUFFER, vertId);
	glBufferData(GL_ARRAY_BUFFER, total * stride, vert0x, usage);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Beispiel #21
0
bool DynamicSprite::init(const std::string &file, const Rect &rect, float density) {
	if (!init(nullptr, rect, density)) {
		return false;
	}

	_textureTime = Time::now();
	auto time = _textureTime;
	retain();
	TextureCache::getInstance()->addTexture(file, [this, time] (cocos2d::Texture2D *tex) {
		if (time == _textureTime) {
			if (_textureRect.equals(Rect::ZERO)) {
				setTexture(tex);
			} else {
				setTexture(tex, _textureRect);
			}
		}
		release();
	});

	return true;
}
Beispiel #22
0
Animation* AnimationManager::getImageAnimationWithPlist(char *plist, char *format, USIZE nStart, USIZE nEnd, char *imagePath)
{
    auto cache = SpriteFrameCache::getInstance();
    
	if (imagePath)
		cache->addSpriteFramesWithFile(plist, imagePath);
    else
        cache->addSpriteFramesWithFile(plist);
    
    auto animation = Animation::create();
    animation->retain();
    
    for (USIZE i = nStart; i <= nEnd; ++i)
    {
        auto path = String::createWithFormat(format, i)->getCString();
        auto frame = cache->getSpriteFrameByName(path);
        animation->addSpriteFrame(frame);
    }
    
    return animation;
}
Beispiel #23
0
unsigned int array_insert(void * _self, void * element, unsigned int _index) {
  struct Array * self = _self;
  const int index = _index;
  assert(index <= self -> _count);

  if(self -> _count >= self -> _size) {
    array_reallocateMemory(_self);
  }
  int i = self -> _count - 1;
  while (i >= index) {
    self -> _objects[i + 1] = self -> _objects[i];
    i--;
  }
#ifdef REFERENCE_COUNTING
  self -> _objects[index] = retain(element);
#else
  self -> _objects[index] = element;
#endif
  self -> _count ++;
  return index;
}
// IOFireWireIRMAllocation::handleBusReset
//
//
void IOFireWireIRMAllocation::handleBusReset(UInt32 generation)
{
	// Take the lock
	IORecursiveLockLock(fLock);

	if (!isAllocated)
	{
		IORecursiveLockUnlock(fLock);
		return;
	}
	
	if (fAllocationGeneration == generation)
	{
		IORecursiveLockUnlock(fLock);
		return;
	}
	
	// Spawn a thread to do the reallocation
	IRMAllocationThreadInfo * threadInfo = (IRMAllocationThreadInfo *)IOMalloc( sizeof(IRMAllocationThreadInfo) );
	if( threadInfo ) 
	{
		threadInfo->fGeneration = generation;
		threadInfo->fIRMAllocation = this;
		threadInfo->fControl = fControl;
		threadInfo->fLock = fLock;
		threadInfo->fIsochChannel = fIsochChannel; 
		threadInfo->fBandwidthUnits = fBandwidthUnits;

		retain();	// retain ourself for the thread to use

		thread_t		thread;
		if( kernel_thread_start((thread_continue_t)threadFunc, threadInfo, &thread ) == KERN_SUCCESS )
		{
			thread_deallocate(thread);
		}
	}
	
	// Unlock the lock
	IORecursiveLockUnlock(fLock);
}
Beispiel #25
0
		void Http::get(std::string strUrl,std::string strRequestData /*= ""*/,RequestCompleteCallBack completeCallBack /*= nullptr*/,RequestErrorCallBack errorCallBack)
		{
			HttpRequest* request = new HttpRequest();
			request->setRequestData(strRequestData.c_str(),strRequestData.length());
			request->setRequestType(HttpRequest::Type::GET);
			request->setUrl((strUrl + "?" + strRequestData).c_str());

			auto target = completeCallBack.target<Ref>();
			if (target)
			{
				target->retain();
			}
			request->setResponseCallback([=](network::HttpClient* client, network::HttpResponse* respons){
				if (target)
				{
					target->release();
				}
				CCLOG("requestUrl:%s requestData:%s",strUrl.c_str(),strRequestData.c_str());
				if ((HttpResponseCode)respons->getResponseCode() == HttpResponseCode::OK)
				{
					auto buffer = respons->getResponseData(); 
					buffer->push_back((char)0);
					char const* szBuffer = &(*buffer->begin());
					CCLOG("Http::get:%s",szBuffer);
					if (completeCallBack)
					{
						completeCallBack(szBuffer);
					}
				}else
				{
					if (errorCallBack)
					{
						errorCallBack((HttpResponseCode)respons->getResponseCode(),respons->getResponseDataString());
					}
					CCLOG("request error code:%d",respons->getResponseCode());
				}
			});
			network::HttpClient::getInstance()->sendImmediate(request);
			request->release();
		}
void ofxTexture3d::allocate(int w, int h, int d, int internalGlDataType)
{
    texData.tex_w = w;
    texData.tex_h = h;
    texData.tex_d = d;
    texData.tex_t = w;
    texData.tex_u = h;
    texData.tex_v = d;
    texData.textureTarget = GL_TEXTURE_3D;

    texData.glTypeInternal = internalGlDataType;
    // get the glType (format) and pixelType (type) corresponding to the glTypeInteral (internalFormat)
    texData.glType = ofGetGLFormatFromInternal(texData.glTypeInternal);
    texData.pixelType = ofGetGlTypeFromInternal(texData.glTypeInternal);
    // attempt to free the previous bound texture, if we can:
    clear();

    glGenTextures(1, (GLuint *)&texData.textureID);
    retain(texData.textureID);
    glEnable(texData.textureTarget);
    glBindTexture(texData.textureTarget, (GLuint)texData.textureID);

    glTexImage3D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, (GLint)texData.tex_d, 0, texData.glType, texData.pixelType, 0);

    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);

    //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glDisable(texData.textureTarget);

    texData.width = w;
    texData.height = h;
    texData.depth = d;
    texData.bFlipTexture = false;
    texData.bAllocated = true;
}
bool ScrollText::initClipper( cocos2d::Sprite* &pMask,cocos2d::Node* &pMoveChild)
{
	auto clipper = ClippingNode::create();
	IF_RETURN_FALSE(!clipper);
	IF_RETURN_FALSE(!pMask);
	setContentSize(pMask->getContentSize());
	IF_RETURN_FALSE(!pMask->getTexture());
	auto _clipperStencil = Sprite::createWithTexture(pMask->getTexture());
	//_clipperStencil->setAnchorPoint((0.5,0.5));
	IF_RETURN_FALSE(!_clipperStencil);
	_clipperStencil->retain();
	clipper->setAlphaThreshold(0.1f);
	clipper->setStencil(_clipperStencil);
	clipper->addChild(pMoveChild,1);
	addChild(clipper);
	for (auto child:_mNodes)
	{
		IF_RETURN_FALSE(!child);
		clipper->addChild(child);
	}
	return true;
}
void ShieldDiceDragHandler::dragStarted(ActionDiceDragData* data,
                                        GameplayLayer* layer,
                                        DockableContainer* dockableContainer) {
  Vector<Node*> targetNodes;
  for (auto node : layer->getChildren()) {
    if (IS(node, ActionDiceSprite)) {
      auto diceSprite = (ActionDiceSprite*) node;
      auto dice = diceSprite->getDice();
      
      if (DiceUtil::isSwordDice(dice)) {
        targetNodes.pushBack(node);
      }
    }
  }
  
  auto game = Game::getInstance();
  if (game->getDamageTaken() > 0) {
    auto scene = (GameplayScene*) layer->getScene();
    auto dungeonLayer = scene->getDungeonLayer();
    
    auto character = game->getPlayer()->getCharacter();
    auto characterSprite = character->getSprite();
    
    auto position = characterSprite->getPosition() -
        Vec2(TILE_DIMENSION / 2, TILE_DIMENSION / 2) +
        characterSprite->getParent()->getPosition() +
        dungeonLayer->getParent()->getPosition();
    characterSprite->setPosition(position);
    
    characterSprite->retain();
    characterSprite->removeFromParent();
    layer->addChild(characterSprite);
    characterSprite->release();
    
    targetNodes.pushBack(characterSprite);
  }
  
  OverlayUtil::addOverlay(targetNodes, layer);
}
void MFCAppDelegate::CreateWnd(HWND hwnd)
{
	if (!m_hwnd)
	{
		m_hwnd = hwnd;

		initGLContextAttrs();
		// Initialize instance and cocos2d.
		if (!applicationDidFinishLaunching())
		{
			return;
		}

		auto director = Director::getInstance();
		auto glview = director->getOpenGLView();
		if (glview)
		{
			// Retain glview to avoid glview being released in the while loop
			glview->retain();
		}
	}
}
Beispiel #30
0
static obj func_def(obj name, obj params, obj expr) {
	assert(type(name)==tSymbol);
	obj* func = lfind_var(name);
	if(! *func) {
		obj (*fn)(obj) = searchFunc(name, infnbind);
		if(fn) let(func, tag(fn));
	}
	list lam = list3(retain(params), retain(expr), retain(env));
    if(*func){
        if(type(*func)==tClosure){			// free if complete overload, in the future
            lam = merge(lam, retain(ul(*func)));
        } else if(type(*func)==tInternalFn){
            lam = merge(lam, list3(retain(*func), nil, nil));
        }
    }
	return retain(*let(func, render(tClosure, lam)));
}