Beispiel #1
0
void Game::mousePressEvent(QMouseEvent *pe){
	if(pe->buttons() == 1){
		int x = pe->x()/50;
		int y = (500-pe->y())/50;
		if(arrayofpoints[x][y] != NULL){
			if(activepoint != NULL) activepoint->active = 0;
			activepoint=arrayofpoints[x][y];
			activepoint->active = 1;
		} else {
			if(activepoint != NULL){
			/////////////////////////////////////////	
				if(movepoint(activepoint->x/50,activepoint->y/50,x,y)){
					if(!checkarray()){
						emit scoreChanged();
						addpoint(); addpoint(); addpoint();
					}
					checkarray();
					emit scoreChanged();
				}
			/////////////////////////////////////////
			}
		}

	}

	if(pe->buttons() == 2){
		if(activepoint){
			activepoint->active = 0;
			activepoint = NULL;
		}
	}
}
Beispiel #2
0
static unsigned int *getindex(lua_State *L, unsigned int *mask) {
    NumArray *a = checkarray(L);
    int index = luaL_checkint(L, 2) - 1;
    luaL_argcheck(L, 0 <= index && index < a->size, 2, "index out of range");
    *mask = I_BIT(index);
    return &a->values[I_WORD(index)];
}
Beispiel #3
0
static double *getelem(lua_State *L) {
	NumArray *a = checkarray(L);
	int index = luaL_checkint(L, 2);
	luaL_argcheck(L, 1 <= index && index <= a->size, 2,
		"index out of range");
	/* return element address */
	return &a->values[index - 1];
}
Beispiel #4
0
static int
checkfill(Symbol* tsym, Datasrc* src)
{
    int i,iscmpd,result;
    Constant* con;
    Symbol* original = tsym;

    result = 1;
    switch (tsym->subclass) {
    case NC_ENUM: case NC_OPAQUE: case NC_PRIM:
	con = srcnext(src);
	if(src == NULL) {
	    semerror(srcline(src),"%s: malformed _FillValue",original->name);
	    result = 0;
	} else if(con->nctype != tsym->typ.typecode) result = 0; /* wrong type*/
	break;

    case NC_COMPOUND:
        if(!issublist(src)) {/* fail on no compound*/
           semerror(srcline(src),"Compound constants must be enclosed in {..}");
        }
	srcpush(src);
        for(i=0;i<listlength(tsym->subnodes);i++) {
	    Symbol* field = (Symbol*)listget(tsym->subnodes,i);
	    result = checkfill(field,src,original);
	    if(!result) break;
        }	  
	srcpop(src);
	break;

    case NC_VLEN:
	if(!issublist(src)) {
	    semerror(srcline(src),"%s: vlen instances in _FillValue must be enclosed in {...}",original->name);
	    result = 0;
	} else {
	    srcpush(src);
            while(srcmore(src)) {
		result = checkfill(tsym->typ.basetype,src,original);
		if(!result) break;
	    }
	    srcpop(src);
	}
	break;

    case NC_FIELD:
	/* Braces are optional */
	if((iscmpd=issublist(src))) srcpush(src);
	if(tsym->typ.dimset.ndims > 0) {
            result = checkarray(tsym->typ.basetype,&tsym->typ.dimset,0,src,original,!TOPLEVEL);
	} else
	    result = checkfill(tsym->typ.basetype,src,original);
	if(iscmpd) srcpop(src);
	break;

    default: PANIC1("checkfillvalue: unexpected subclass %d",tsym->subclass);
    }
    return result;
}
Beispiel #5
0
static int getsize(lua_State *L)
{
	printf("call %s\n",__func__);
	NumArray *a = checkarray(L);
	//luaL_argcheck(L, a != NULL, 1, "'array' expected");

	lua_pushinteger(L, a->size);
	return 1;
}
static int
checkarray(Symbol* basetype, Dimset* dimset, int index, Datasrc* src, Symbol* original, int toplevel)
{
    int i,result;
    Symbol* dim = dimset->dimsyms[index];
    unsigned int size = dim->dim.declsize;
    int lastdim = (index == (dimset->ndims - 1));
    int isunlimited = (size == 0);

    result = 1;
    if(isunlimited) {
	if(!toplevel) {
	    if(!issublist(src)) {
		semerror(srcline(src),"UNLIMITED dimension constants (other than top level) must be enclosed in {...}");
		result = 0;
		goto done;
	    } else
		srcpush(src);
	}
        if(lastdim) {
	    while(srcmore(src) && result) {
		result = checkfill(basetype,src,original);
	    }
	} else { /*!lastdim*/
	    while(srcmore(src) && result) {
	        result = checkarray(basetype,dimset,index+1,src,original,toplevel);
	    }
	}
    } else { /* bounded*/
        if(lastdim) {
	    for(i=0;i<size && result;i++) {
		result = checkfill(basetype,src,original);
	    }
	} else { /* !lastdim*/
	    for(i=0;i<size && result;i++) {
	        result = checkarray(basetype,dimset,index+1,src,original,toplevel);
	    }
	}
    }
done:
    return result;
}
int
checkfillvalue(Symbol* tvsym, Datalist* filler)
{
    Datasrc* src = datalist2src(filler);
    int result;
    ASSERT(tvsym->objectclass == NC_VAR || tvsym->objectclass == NC_TYPE);
    if(tvsym->objectclass == NC_VAR) {
	if(tvsym->typ.dimset.ndims > 0) {
            result = checkarray(tvsym->typ.basetype,&tvsym->typ.dimset,0,src,tvsym,TOPLEVEL);
	} else
	    result = checkfill(tvsym->typ.basetype,src,tvsym);
    } else /* NC_TYPE*/
	result = checkfill(tvsym,src,tvsym);
    freedatasrc(src);
    return result;
}
Beispiel #8
0
void vertex_tabread :: render(GemState *state)
{
  int      length=0;
  int      size=0;
  GLfloat*dummy=NULL;

  state->VertexArray   = NULL; state->VertexArraySize   = 0;
  state->ColorArray    = NULL; state->HaveColorArray    = 0;
  state->NormalArray   = NULL; state->HaveNormalArray   = 0;
  state->TexCoordArray = NULL; state->HaveTexCoordArray = 0;

  if(m_Vtable){
    dummy=checkarray(m_Vtable, length);
    size=length;
    if(dummy && length>0){
      state->VertexArray = dummy;
      state->VertexArraySize = length >> 2;

      state->VertexArrayStride = 3;
    }
  }
Beispiel #9
0
static int getsize(lua_State *L)
{
	NumArray *a = checkarray(L);
	lua_pushinteger(L, a->size);
	return 1;
}
task main()
{
    int count=0;
    int direction=1;
    int end=0;
    int doubleline=0;
    int pause=0;

    //open the file to write
    fileHandle=fileOpenWrite(filename);
    //turn right go forward until hit double line go back half a square then turn left You are at bottom left sq now
    RightTurn();
    while(pause==0)
  	{
      motor(motorB)=SPEED;
  		motor(motorC)=SPEED;
  		wait1Msec(1);

  		if(SensorValue(S3)<45&&doubleline!=1)
  		{
  			if(time1[T1]<200)
  			{
  				pause=1;
  			}
  			doubleline=1;
  	}
  		if(SensorValue(S3)>45&&doubleline==1)
  		{
  			doubleline=0;
  			clearTimer(T1);
  		}
	}
	motor[motorB]=-20;
	motor[motorC]=-20;
	wait1Msec(700);
	LeftTurn();

    //start traversing grid
    while(end!=7)
    {
        //traverse right and count lines
        if(direction==1)
        {
            end++;
            while(count<8)
            {
                if(SensorValue(S3)<45)
                {
                    blacksq++;
                    //store position to array
                    grid[pos1][pos2]='1';
                }
                //increment counters
                count++;
                total++;
                displayBigTextLine(2,"Black:%d",blacksq);
                displayBigTextLine(5,"Count:%d ",count);
                displayBigTextLine(8,"Total:%d",total);
                //move forward one square
                Forward();
                pos2++;
            }

            //Switches to next line
            if(end!=7)
            {
                direction=NextLineLeft(direction);
                //Resets count
                count=ResetCount(count);
                pos1++;
            }
        }
        if(direction==2)
        {
            end++;
            while(count<8)
            {
                if(SensorValue(S3)<45)
                {
                    blacksq++;
                    //store position to array
                    grid[pos1][pos2]='1';
                }
                //increment counters
                count++;
                total++;
                displayBigTextLine(2,"Black:%d",blacksq);
                displayBigTextLine(5,"Count:%d ",count);
                displayBigTextLine(8,"Total:%d",total);
                //move forward one square
                Forward();
                pos2--;
            }
            //Switches to next line
            if(end!=7)
            {
                //Switches to next line
                direction=NextLineRight(direction);
                //Resets count
                count=ResetCount(count);
                pos1++;
            }
        }//end if()
    }//end while()
		checkarray();
    //Goes back to the start function
    GoStart();

    //THIS IS THE SECOND PART OF THE PROGRAM TO MAP THE LOCATION OF THE OBJECT
    while(1==1)
    {
    	if(getTouchValue(S2)==1)
    	{
            //reset all values
            pos1=0;
            pos2=0;
            count=0;
            direction=1;
            end=0;
            while(end!=7)
            {
                //traverse right and count lines
                if(direction==1)
                {
                    end++;
                    while(count<8)
                    {
                        //check to see if there is an object 140mm away
                        if(getUSDistance(S1)<14)
                        {
                            grid[pos1][pos2]='J';
                             	motor[motorB]=0;
															motor[motorC]=0;
                            wait1Msec(1000000);
                        }
                        //increment counters
                        count++;
                        Forward();
                        pos2++;
                    }

                    //Switches to next line
                    if(end!=7)
                    {
                        direction=NextLineLeft(direction);
                        //Resets count
                        count=ResetCount(count);
                        pos1++;
                    }
                }
                if(direction==2)
                {
                    //check to see if there is an object 140mm away
                    end++;
                    while(count<8)
                    {
                        if(getUSDistance(S1)<14)
                        {
                            grid[pos1][pos2]='J';
                            	motor[motorB]=0;
															motor[motorC]=0;
                            wait1Msec(1000000);
                        }
                        //increment counters
                        count++;
                        //move forward one square
                        Forward();
                        pos2--;
                    }
                    //Switches to next line
                    if(end!=7)
                    {
                        //Switches to next line
                        direction=NextLineRight(direction);
                        //Resets count
                        count=ResetCount(count);
                        pos1++;
                    }
                }//end if()
            }//end while()

      }  }//end if()
}//end main()
Beispiel #11
0
static int array2string(lua_State *L)
{
	NumArray *a = checkarray(L);
	lua_pushfstring(L,"array(%d)",a->size);
	return 1;
}