Exemplo n.º 1
0
void BingoStorage::add (OracleEnv &env, const Array<char> &data, int &blockno, int &offset)
{
    if (_blocks.size() < 1 || _blocks.top().size + data.size() > _MAX_BLOCK_SIZE)
        _insertLOB(env, _blocks.size() + 1);

    _Block &top = _blocks.top();

    blockno = _blocks.size() - 1;
    offset = top.size;

    _top_lob_pending_data.concat(data);

    _Addr addr;

    addr.blockno = _blocks.size() - 1;
    addr.length = data.size();
    addr.offset = top.size;
    top.size += data.size();

    _index_lob_pending_data.concat((char *)&addr, sizeof(_Addr));

    _n_added++;

    _State *state = _getState(true);

    if (state != 0)
        state->age++;
}
Exemplo n.º 2
0
void BZSpriteStarHolder::onUpdate()
{
	BZSpriteCommon::onUpdate();

	switch (_getState())
	{
	case ESHS_Blank:
		break;
	case ESHS_Filling:
		{
			int n = 0;
			CASprite* psprsRemoved[256];
			CAObject* pobj;
			CCARRAY_FOREACH(_pieces, pobj)
			{
				CASprite* pspr = (CASprite*)pobj;
				float p0 = pspr->getAnimationPercent(this->layer()->getTimeNow());
				float p = p0 + 0.1f;
				if (p > 1.0f) p = 1.0f;

				CCPoint pos;
				CCPoint posBegin = pspr->getPos();
				CCPoint posTo = getPos();
				pos.x = posBegin.x + (posTo.x - posBegin.x) * p;
				pos.y = posBegin.y + (posTo.y - posBegin.y) * p;

				_Info("star (%.2f) (%.2f,%.2f) (%.2f,%.2f) (%.2f,%.2f)", p0, pos.x, pos.y, posBegin.x, posBegin.y, posTo.x, posTo.y);

				pspr->setPos(pos);
				if (pspr->isAnimationDone())
				{
					pspr->setPos(posTo);
					pspr->killMyself();
					psprsRemoved[n++] = pspr;

					this->setState("on");
					_setState(ESHS_Filled);
				}
			}
			while (n > 0)
			{
				CASprite* pspr = psprsRemoved[n - 1];
				_pieces->removeObject(pspr);
				n--;
			}
		}
		break;
	case ESHS_Filled:
		break;
	}
Exemplo n.º 3
0
void BingoStorage::markRemoved (OracleEnv &env, int blockno, int offset)
{
    OracleStatement statement(env);
    OracleLOB lob(env);

    statement.append("SELECT bindata FROM %s WHERE id = :id FOR UPDATE", _table_name.ptr());
    statement.prepare();
    statement.bindIntByName(":id", &blockno);
    statement.defineBlobByPos(1, lob);
    statement.execute();

    byte mark = 1;

    lob.write(offset, (char *)&mark, 1);

    _State *state = _getState(true);

    if (state != 0)
        state->age++;
}
Exemplo n.º 4
0
void BingoStorage::validate (OracleEnv &env)
{
    env.dbgPrintfTS("validating storage... ");

    if (_shmem_state != 0 && strcmp(_shmem_state->getID(), _shmem_id.ptr()) != 0)
    {
        delete _shmem_state;
        _shmem_state = 0;
        _age_loaded = -1;
    }

    _State *state = _getState(true);

    // TODO: implement a semaphore
    while (state->state == _STATE_LOADING)
    {
        delete _shmem_state;
        _shmem_state = 0;
        _age_loaded = -1;

        state = _getState(true);

        if (state == 0)
            throw Error("can't get shared info");

        env.dbgPrintf(".");
    }

    if (state->state == _STATE_READY)
    {
        if (state->age_loaded == state->age)
        {
            if (_age_loaded == state->age)
            {
                env.dbgPrintf("up to date\n");
                return;
            }
            else
                env.dbgPrintf("loaded by the other process\n");
        }
        else
        {
            env.dbgPrintf("has changed, reloading\n");
            state->state = _STATE_LOADING;
        }
    }
    else
    {
        state->state = _STATE_LOADING;
        env.dbgPrintf("loading ... \n");
    }

    _shmem_array.clear();
    _blocks.clear();

    OracleStatement statement(env);

    int id, length;
    OracleLOB lob(env);
    QS_DEF(Array<char>, block_name);

    statement.append("SELECT id, length(bindata), bindata FROM %s ORDER BY id",
                     _table_name.ptr());

    statement.prepare();
    statement.defineIntByPos(1, &id);
    statement.defineIntByPos(2, &length);
    statement.defineBlobByPos(3, lob);
    statement.execute();

    do
    {
        ArrayOutput output(block_name);
        output.printf("%s_%d_%d", _shmem_id.ptr(), id, state->age);
        output.writeByte(0);

        if (length < 1)
        {
            if (id == 0)
            {
                _index.clear();
                break;
            }
            throw Error("cannot validate block #%d: length=%d", id, length);
        }

        _shmem_array.add(new SharedMemory(block_name.ptr(), length, state->state == _STATE_READY));

        void *ptr = _shmem_array.top()->ptr();

        if (ptr == 0)
        {
            if (state->state == _STATE_READY)
            {
                // That's rare case, but possible.
                // Reload the storage.
                env.dbgPrintf("shared memory is gone, resetting... \n");
                state->state = _STATE_EMPTY;
                validate(env);
                return;
            }
            else
                throw Error("can't map block #%d", id);
        }

        if (state->state != _STATE_READY)
            lob.read(0, (char *)ptr, length);

        if (id == 0)
        {
            if ((length % sizeof(_Addr)) != 0)
                throw Error("LOB size %d (expected a multiple of %d)", length, sizeof(_Addr));
            if (length > 0)
                _index.copy((_Addr *)_shmem_array[0]->ptr(), length / sizeof(_Addr));
        }

        _Block &block = _blocks.push();

        block.size = length;
    } while (statement.fetch());

    state->state = _STATE_READY;
    state->age_loaded = state->age;
    _age_loaded = state->age;
}
Exemplo n.º 5
0
	void UIButton::comp(){
		state = _getState(mousePosition, mouseState);
		if(state == UIState::UP && callbackPtr != NULL){
			return (void)callbackPtr(callbackParam);
		}
	}