コード例 #1
0
void RDMarkerWidget::returnPressedData()
{
  int value=SetTimeLength(mark_edit->text());
  if(!CheckLimits(value)) {
    return;
  }
  if(value!=mark_value) {
    mark_value=value;
    emit valueChanged();
  }
}
コード例 #2
0
ファイル: FlowContext.cpp プロジェクト: GerritvanNiekerk/TS
void FlowContext::SetFlowRange(int _startingFlow, int _flow_interval)
{
  assert ( _startingFlow >= 0 );
  assert ( _flow_interval > 0 );

  flow_range_set = true;
  startingFlow = ( unsigned int ) _startingFlow;
  endingFlow = startingFlow+( unsigned int ) _flow_interval;

  CheckLimits();

  fprintf ( stdout, "DEBUG: Flows to be analyzed: %d thru %d\n", startingFlow,endingFlow-1 );
}
コード例 #3
0
void RDMarkerWidget::setValue(int msecs)
{
  if(msecs<0) {
    mark_value=-1;
    mark_edit->setText("");
  }
  else {
    if(!CheckLimits(msecs)) {
      return;
    }
    mark_value=msecs;
    mark_edit->setText(GetTimeLength(mark_value));
  }
  emit valueChanged();
}
コード例 #4
0
ファイル: JDivideCpu.cpp プロジェクト: uquendo/dualsphysics
//==============================================================================
/// Configuration of the Neighbour List: Memory allocation, domain and cells.
//==============================================================================
void JDivideCpu::Config(float sizecell,float incz,unsigned np,unsigned nfixed,unsigned nmoving,unsigned nfloat,unsigned nfluid,const tfloat3 *pos,float dp){
  const char met[]="Config";
  Reset();
  string aux="**Initialising ";
  Log->Print(aux+ClassName);
  if(np<1)RunException(met,"Invalid number of particles.");
  if(sizecell<=0)RunException(met,"Invalid value for cell size.");
  Np=np; Nfixed=nfixed; Nmoving=nmoving; Nfloat=nfloat; Nfluid=nfluid;
  Nbound=Nfixed+Nmoving+Nfloat;
  if(Np!=Nbound+Nfluid)RunException(met,"Error in number of particles.");
  Npb=Nbound-Nfloat;
  SizeCell=sizecell; OvSizeCell=float(1.0/SizeCell); IncZ=incz;
  //-Allocates memory dependent on Np.
  try{
    CellPart=new unsigned[Np]; 
    Parts=new unsigned[Np];
    VSort=(byte*)new byte[max(sizeof(tfloat3)*Np,sizeof(tsymatrix3f)*(Np-Npb))];
  }
  catch(const std::bad_alloc){
    RunException(met,"Could not allocate the requested memory.");
  }
  VSortInt=(int*)VSort;
  VSortFloat=(float*)VSort;
  VSortFloat3=(tfloat3*)VSort;
  VSortFloat6=(tsymatrix3f*)VSort;
  //-Calculates limits of the domain.
  tfloat3 pmin,pmax;
  CheckLimits(0,Np,pos,pmin,pmax);
  float mod=sizecell*0.05f;  
  pmin.x-=mod; pmin.y-=mod; pmin.z-=mod;
  pmax.x+=mod; pmax.y+=mod; pmax.z+=mod;
  DifMax.x=pmax.x-pmin.x; DifMax.y=pmax.y-pmin.y; DifMax.z=pmax.z-pmin.z;
  CalcCells();
  if(ShowCellsInfo){
    char tx[128];
    sprintf(tx,"Cells of the initial domain: %d x %d x %d  (%d)",Ncells.x,Ncells.y,Ncells.z,(Ncells.x*Ncells.y*Ncells.z));
    Log->Print(tx);
  }
  pmax.z=(pmax.z-pmin.z)*(IncZ+1.f)+pmin.z;
  PosMin=pmin;
  DifMax.x=pmax.x-pmin.x; DifMax.y=pmax.y-pmin.y; DifMax.z=pmax.z-pmin.z;
  CalcCells();
  VisuLimits();
  CellInfoOk=false;
}
コード例 #5
0
ファイル: ScriptMoveType.cpp プロジェクト: Dmytry/spring
void CScriptMoveType::Update()
{
	if (useRotVel) {
		rot += rotVel;
		CalcDirections();
	}

	owner->speed = vel;
	if (extrapolate) {
		if (drag != 0.0f) {
			vel *= (1.0f - drag); // quadratic drag does not work well here
		}
		if (useRelVel) {
			const float3 rVel = (owner->frontdir *  relVel.z) +
			                    (owner->updir    *  relVel.y) +
			                    (owner->rightdir * -relVel.x); // x is left
			owner->speed += rVel;
		}
		vel.y        += mapInfo->map.gravity * gravityFactor;
		owner->speed += (wind.GetCurrentWind() * windFactor);
		owner->pos   += owner->speed;
	}

	if (trackGround) {
		const float gndMin =
			ground->GetHeight2(owner->pos.x, owner->pos.z) + groundOffset;
		if (owner->pos.y <= gndMin) {
			owner->pos.y = gndMin;
			owner->speed.y = 0.0f;
			if (gndStop) {
				owner->speed.y = 0.0f;
				vel    = ZeroVector;
				relVel = ZeroVector;
				rotVel = ZeroVector;
				scriptNotify = 1;
			}
		}
	}

	// positional clamps
	CheckLimits();

	if (trackSlope) {
		TrackSlope();
	}

	owner->UpdateMidPos();

	// don't need the rest if the pos hasn't changed
	if (oldPos == owner->pos) {
		CheckNotify();
		return;
	}

	oldPos = owner->pos;

	if (!noBlocking) {
		owner->Block();
	}

	if (groundDecals && owner->unitDef->leaveTracks && leaveTracks &&
	    (lastTrackUpdate < (gs->frameNum - 7)) &&
	    ((owner->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectatingFullView)) {
		lastTrackUpdate = gs->frameNum;
		groundDecals->UnitMoved(owner);
	}

	CheckNotify();
};
コード例 #6
0
ファイル: ScriptMoveType.cpp プロジェクト: nixtux/spring
bool CScriptMoveType::Update()
{
	if (useRotVel)
		owner->SetDirVectorsEuler(rot += rotVel);

	if (extrapolate) {
		// NOTE: only gravitational acc. is allowed to build up velocity
		// NOTE: strong wind plus low gravity can cause substantial drift
		const float3 gravVec = UpVector * (mapInfo->map.gravity * gravityFactor);
		const float3 windVec =            (wind.GetCurrentWind() * windFactor);
		const float3 unitVec = useRelVel?
			(owner->frontdir *  relVel.z) +
			(owner->updir    *  relVel.y) +
			(owner->rightdir * -relVel.x):
			ZeroVector;

		owner->Move(gravVec + velVec, true);
		owner->Move(windVec,          true);
		owner->Move(unitVec,          true);

		// quadratic drag does not work well here
		velVec += gravVec;
		velVec *= (1.0f - drag);

		owner->SetVelocityAndSpeed(velVec);
	}

	if (trackGround) {
		const float gndMin = CGround::GetHeightReal(owner->pos.x, owner->pos.z) + groundOffset;

		if (owner->pos.y <= gndMin) {
			owner->Move(UpVector * (gndMin - owner->pos.y), true);
			owner->speed.y = 0.0f;

			if (gndStop) {
				velVec = ZeroVector;
				relVel = ZeroVector;
				rotVel = ZeroVector;
				scriptNotify = 1;
			}
		}
	}

	// positional clamps
	CheckLimits();

	if (trackSlope) {
		owner->UpdateDirVectors(true);
		owner->UpdateMidAndAimPos();
	}

	// don't need the rest if the pos hasn't changed
	if (oldPos == owner->pos) {
		CheckNotify();
		return false;
	}

	oldPos = owner->pos;

	if (!noBlocking)
		owner->Block();

	CheckNotify();
	return true;
}
コード例 #7
0
ファイル: FlowContext.cpp プロジェクト: GerritvanNiekerk/TS
void FlowContext::SetFlowLimit( long flowlimit )
{
  flowLimitSet = ( unsigned int ) flowlimit;

  CheckLimits();
}
コード例 #8
0
ファイル: service.c プロジェクト: CyberGrandChallenge/samples
/*
Figure out how the pcm symbol timings correlate
to morse-like symbols
*/
void ValidateBuckets(void) {
  int dit = 0;
  int dah = 0;
  int word = 0;

  // if all three buckets are valid,
  // the largest bucket is word gap
  // second largest is inter-char gap or dah
  // third largest is intra-char gap or dit
  if (Bucket[1].valid && Bucket[2].valid && Bucket[3].valid) {
    if (Bucket[1].time > Bucket[2].time && Bucket[1].time > Bucket[3].time) {
      word = 1;
      if (Bucket[2].time > Bucket[3].time) {
        dah = 2;
        dit = 3;
      } else {
        dah = 3;
        dit = 2;
      }
    } else if (Bucket[2].time > Bucket[1].time && Bucket[2].time > Bucket[3].time) {
      word = 2;
      if (Bucket[1].time > Bucket[3].time) {
        dah = 1;
        dit = 3;
      } else {
        dah = 3;
        dit = 1;
      }
    } else if (Bucket[3].time > Bucket[1].time && Bucket[3].time > Bucket[2].time) {
      word = 3;
      if (Bucket[1].time > Bucket[2].time) {
        dah = 1;
        dit = 2;
      } else {
        dah = 2;
        dit = 1;
      }
    }

  // if only two are valid,
  // largest is the inter-char gap or dah
  // second largest is intra-char gap or dit
  } else if (Bucket[1].valid && Bucket[2].valid) {
    word = 0;
    if (Bucket[1].time > Bucket[2].time) {
      dah = 1;
      dit = 2;
    } else {
      dah = 2;
      dit = 1;
    }
  } else {
      puts("Insufficient symbol diversity\n");
      _terminate(INVALID_PCM_FMT);
  }

  Bucket[word].mark = ' ';
  Bucket[word].gap = ' ';
  Bucket[dah].mark = '-';
  Bucket[dah].gap = '|';
  Bucket[dit].mark = '.';
  Bucket[dit].gap = '\0';
  CheckLimits(dit,dah,word);
}
コード例 #9
0
// Update: draw background
update_status ModulePlayer::Update()
{
	last_position = position;

	Animation* current_animation = &idle; //Posem la animacio de quiet per defecte i despres comprovem si ha apretat alguna tecla aixi evitem fer la comprovació que havies fet al final.

	int speed = 1;

	if (!game_over_player)
	{
		if (App->input->GetKey(SDL_SCANCODE_A) == KEY_REPEAT)
		{
			current_animation = &left;
			position.x -= speed;
			direction = leftD;

		}

		if (App->input->GetKey(SDL_SCANCODE_D) == KEY_REPEAT)
		{
			current_animation = &right;
			position.x += speed;
			direction = rightD;
		}

		if (App->input->GetKey(SDL_SCANCODE_S) == KEY_REPEAT)
		{
			current_animation = &down;
			position.y += speed;
			direction = downD;

		}

		if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT)
		{
			current_animation = &up;
			position.y -= speed;
			direction = upD;

		}

		if (App->input->GetKey(SDL_SCANCODE_SPACE) == KEY_UP && current_bombs < MAX_BOMBS)
		{
			last_bomb = App->particles->AddParticle(App->particles->bomb, 24 + collider->GetPosLevel().x * TILE, 40 + collider->GetPosLevel().y* TILE, COLLIDER_BOMB, bombT);
			bomb_collision = true;
			current_bombs++;
		}
	}
	else
	{
		current_animation = &die;
	}

	
	collider->SetPos(position.x, position.y-16);

	//check collisions with bomb
	if (!bomb_collision)
	{
		last_bomb = NULL;
	}
	bomb_collision = false;
	
	CheckLimits();

	// Draw everything --------------------------------------
	SDL_Rect r;
	
	if (current_animation != &idle)				//Comprovem si esta en una animacio o parat, si esta parat li asignem el frame manualment.
		r = current_animation->GetCurrentFrame();
	else
		r = current_animation->frames[direction];
	
	
	if (game_over_player && current_animation->Finished())
		App->scene->game_over = true;
	

	App->renderer->Blit(graphics, position.x, position.y - r.h, &r);


	return UPDATE_CONTINUE;
}
コード例 #10
0
ファイル: child.c プロジェクト: xiu/child
int main(int argc, char **argv)
{
    startuptime = time(NULL);

    InitMem();

    int retval,mysql_lastconn,newfd,i,lastcheck,lastcheck2,nbfd;
    struct sockaddr_storage sa;
    socklen_t salen = sizeof(sa);
    Eclient *eclient;

    indata.nextline = indata.chunkbufentry = indata.chunkbuf;

    emerg = emerg_req = 0;

    eos = raws = verbose = vv = 0;
    int daemonize = 1;
    char op = 0;
    me.retry_attempts = me.nextretry = me.connected = 0;

    struct sigaction sig, old;
    memset(&sig,0,sizeof(sig));
    sig.sa_handler = sighandler;
    sigaction(SIGHUP,&sig,&old);
#ifdef USE_FILTER
    sigaction(SIGUSR1,&sig,&old);
#endif
    sigaction(SIGUSR2,&sig,&old);
    sigaction(SIGINT,&sig,&old);
    sigaction(SIGCHLD,&sig,&old);
    sigaction(SIGPIPE,&sig,&old);

    struct rlimit rlim;
    if ((getrlimit(RLIMIT_CORE, &rlim)) == -1) {
        perror("getrlimit");
        return -1;
    }
    rlim.rlim_cur = RLIM_INFINITY;
    if ((setrlimit(RLIMIT_CORE, &rlim)) == -1) {
        perror("setrlimit");
        return -1;
    }

    /* Setting default values */

    strcpy(me.nick,"C");
    strcpy(me.name,"services.geeknode.org");
    strcpy(me.ident,"cserve");
    strcpy(me.host,"geeknode.org");
    strcpy(me.linkpass,"f00p4ss");
    strcpy(me.mysql_host,"localhost");
    strcpy(me.mysql_db,"child");
    strcpy(me.mysql_login,"child");
    strcpy(me.mysql_passwd,"childp4ss");
    strcpy(me.logfile,"child.log");
    strcpy(me.guest_prefix,"Geek");
    strcpy(me.pl_logfile,"partyline.log");
    strcpy(me.sendmail,"/usr/sbin/sendmail -t");
    strcpy(me.sendfrom,"*****@*****.**");
    strcpy(me.usercloak,".users.geeknode.org");
    bzero(me.mysql_anope_host,32);
    bzero(me.mysql_anope_db,32);
    bzero(me.mysql_anope_login,32);
    bzero(me.mysql_anope_passwd,32);
    bzero(me.bindip,32);
    me.port = 4400;
    me.maxclones = 5;
    me.nick_expire = 45;
    me.chan_expire = 60;
    me.chanperuser = 10;
    me.level_oper = 100;
    me.level_admin = 500;
    me.level_root = 900;
    me.level_owner = 1000;
    me.limittime = 5;
    me.savedb_interval = 60;
    me.listen_port = 0;
#ifdef USE_GNUTLS
    me.ssl = 0;
#endif
    me.enable_exec = 0;
    me.anonymous_global = 0;
    me.maxmsgtime = 2;
    me.maxmsgnb = 5;
    me.ignoretime = 60;
    me.maxloginatt = 3;
    me.chlev_sadmin = 20;
    me.chlev_admin = 10;
    me.chlev_op = 5;
    me.chlev_halfop = 4;
    me.chlev_voice = 3;
    me.chlev_invite = 1;
    me.chlev_nostatus = -1;
    me.chlev_akick = -2;
    me.chlev_akb = -3;
    me.anopemd5 = 0;
#ifdef USE_FILTER
    me.filter = 0;
#endif
    me.emailreg = 0;

    /* -- */

    int ladb=0,cdb=0;

    while ((op = getopt(argc,argv,"acdhv")) != EOF) {
        switch(op) {
            case 'a':
                ladb = 1;
                break;
            case 'c':
                cdb = 1;
                break;
            case 'd':
                daemonize = 0;
                break;
            case 'v':
                if (verbose)
                    vv = 1;
                else
                    verbose = 1;
                break;
            case 'h':
            default:
                usage(argv[0]);
        }
    }

    loadconf(0);
#ifdef USE_FILTER
    if (me.filter)
        loadrulefile();
#endif

    if (ladb) {
        if (!connect_to_db()) {
            printf("Cannot connect to db\n");
            child_clean();
        }

        loadalldb();
        mysql_close(&mysql);

        if (!connect_to_anope_db()) {
            printf("Cannot connect to anope db\n");
            child_clean();
        }

        printf("Loading anope database... ");
        fflush(stdout);

        loadanopedb();
        mysql_close(&mysql2);
        printf("done.\n");
        printf("Saving databases... ");
        fflush(stdout);
        savealldb();
        printf("done.\n");
        printf("Anope database converted\n");
        child_clean();
    }

    if (cdb) {
        if (!connect_to_db()) {
            printf("Cannot connect to db\n");
            child_clean();
        }

        printf("Creating databases ... ");
        fflush(stdout);
        char tmp[512];
        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_chans` (chname varchar(50) not null, founder varchar(50) not null, entrymsg blob not null, options int not null, mlock varchar(32) not null, autolimit int not null, lastseen int not null, regtime int not null, topic blob not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_chan_access` (chname varchar(50) not null, username varchar(255) not null, level int not null, automode int not null default 1, suspended int not null, uflags int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_trusts` (hostname varchar(255) not null, clones int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_users` (username varchar(50) not null, authlevel int not null, seen int not null, vhost varchar(200) not null, md5_pass varchar(32) not null, options int not null, timeout int not null, email varchar(100) not null, regtime int not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_links` (master varchar(50) not null, slave varchar(50) not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_botserv_bots` (name varchar(50) not null, ident varchar(50) not null, host varchar(50) not null)");
        mysql_query(&mysql,tmp);

        sprintf(tmp,"CREATE TABLE IF NOT EXISTS `child_botserv_chans` (chan varchar(50) not null, bot varchar(50) not null)");
        mysql_query(&mysql,tmp);

        RunHooks(HOOK_CREATEDB,NULL,NULL,NULL,NULL);

        printf(" done.\n");
        mysql_close(&mysql);
        child_clean();
    }

    if (me.listen_port) {
        if (!Bind()) {
            fprintf(stderr,"Error while binding\n");
            child_clean();
        }
        pllog("Partyline created");
    }

    retval = ConnectToServer();
    switch(retval) {
        case -1:
            fprintf(stderr,"Failed to connect to %s:%d (connection timed out)\n",me.server,me.port);
            operlog("Failed to connect to %s:%d (connection timed out)",me.server,me.port);
            child_clean();
        case 0:
            fprintf(stderr,"Failed to connect to %s:%d",me.server,me.port);
            operlog("Failed to connect to %s:%d",me.server,me.port);
            child_clean();
    }

    if (verbose) printf("Connected to server\n");

    if (!connect_to_db()) {
        fprintf(stderr,"Cannot connect to mysql\n");
        operlog("Cannot connect to mysql db");
        child_clean();
    }

    if (verbose) printf("Connected to mysql DB\n");
    loadalldb();
    mysql_close(&mysql);
    if (verbose) printf("Logging in to server\n");
    SendInitToServer();
    me.connected = 1;
    if (verbose) printf("Logged in to server\n");

    SendRaw("EOS");

    lastcheck = lastcheck2 = mysql_lastconn = time(NULL);
    if (daemonize) daemon(1,0);
    write_pid();

    nbfd = build_poll();
    struct pollfd pfdout;
    pfdout.fd = sock;
    pfdout.events = POLLOUT;
    pfdout.revents = 0;

    while(1) {
        if (outdata.writebytes > 0) {
            retval = poll(&pfdout,1,1000);
            if (retval > 0 && (pfdout.revents & POLLOUT))
                flush_sendq();
        }
        retval = poll(ufds,nbfd,1000);
        if (retval > 0) {
            for (i=0;i<nbfd;i++) {
                if (ufds[i].revents & (POLLIN | POLLPRI)) {
                    switch(i) {
                        case 0:
                            if (!ReadChunk()) {
                                if (!me.connected || !eos) break;
                                operlog("Connection reset by peer");
                                savealldb();
                                eos = me.retry_attempts = me.connected = 0;
                                me.nextretry = time(NULL)+1;
                                cleanup_reconnect();
                                close(sock);
                                break;
                            }
                            while (GetLineFromChunk())
                                ParseLine();
                            break;
                        case 1:
                            if (!me.listen_port) break;
                            newfd = accept(esock,(struct sockaddr *)&sa,&salen);
                            if (eclient_list.size+1 >= ECL_MAXSOCK) {
                                close(newfd);
                                break;
                            }
                            fcntl(newfd,F_SETFL,O_NONBLOCK);
                            eclient = AddEclient(newfd,sa,salen);
                            sendto_all_butone(eclient,"*** Connection from %s (%s)",eclient->host,eclient->addr);
                            nbfd = build_poll(); i++;
                            break;
                        default:
                            eclient = find_eclient(ufds[i].fd);
                            if (!eclient) break;
                            int oldnbfd = nbfd;
                            int old_eclient_size = eclient_list.size;
                            if (!ReadPChunk(eclient)) {
                                if (eclient->authed == 1)
                                    sendto_all_butone(eclient,"*** User %s (%s) logged out (Connection reset by peer)",eclient->nick,eclient->host);
                                else
                                    sendto_all_butone(eclient,"*** Lost connection from %s",eclient->host);
                                close(eclient->fd);
                                DeleteEclient(eclient);
                                nbfd = build_poll();
                                i--;
                                break;
                            }
                            int tmpfd = eclient->fd;
                            while (GetLineFromPChunk(tmpfd))
                                ParseEclient(eclient);
                            if (old_eclient_size > eclient_list.size)
                                nbfd = build_poll();
                            if (nbfd < oldnbfd) i -= (oldnbfd - nbfd);
                            break;
                    }
                }
            }
        }

        int timenow = time(NULL);

        if (!me.connected && timenow - me.nextretry >= 0) {
            retval = ConnectToServer();
            if (retval == -1 || retval == 0) {
                me.retry_attempts++;
                operlog("Reconnecting attempt #%d failed (%s)",me.retry_attempts,retval ? "timeout" : "error");
                if (me.retry_attempts >= MAX_RECO_ATTEMPTS) {
                    operlog("Maximum reconnection attempts reached, exiting");
                    savealldb();
                    unloadallmod();
                    CloseAllSock();
                    child_clean();
                }
                me.nextretry = timenow + RECONNECT_DELAY;
            } else {
                SendInitToServer();
                me.connected = 1;
                me.nextretry = 0;
                SendRaw("EOS");
                operlog("Reconnected");
            }
            if (me.connected) continue;
        }

        if (timenow - mysql_lastconn >= 60*me.savedb_interval) {
            savealldb();
            mysql_lastconn = timenow;
        }

        if (timenow - lastcheck >= 1) {
            CheckGuests();
            CheckLimits();
            CheckTB();
            lastcheck = timenow;
        }

        if (timenow - lastcheck2 >= 60) {
            checkexpired();
            lastcheck2 = timenow;
        }
    }

    operlog("Program shouldn't reach this piece of code, WTF ? Saving DBs and exiting.");
    savealldb();
    unloadallmod();
    CloseAllSock();
    child_clean();

    return 0;
}