示例#1
0
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
	(void)ev;
	en.each<Position, Direction>([dt](entityx::Entity entity, Position &position, Direction &direction) {
		position.x += direction.x * dt;
		position.y += direction.y * dt;

		if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
			auto animate = entity.component<Animate>();
			entity.component<Sprite>()->sprite = 
				(direction.x != 0) ? animate->nextFrame() : animate->firstFrame();
		}
		if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
			direction.x = 0;
		} else {
			if (entity.has_component<Sprite>()) {
				auto& fl = entity.component<Sprite>()->faceLeft;
				if (direction.x != 0)
					fl = (direction.x < 0);
			}

			if (entity.has_component<Wander>()) {
				auto& countdown = entity.component<Wander>()->countdown;

				if (countdown > 0) {
					countdown--;
				} else {
					countdown = 5000 + randGet() % 10 * 100;
					direction.x = (randGet() % 3 - 1) * 0.02f;
				}
			}
		}
	});
}
示例#2
0
void myDump(char *url){
    int num=getPoolSize(finishPool);
    int i;
    FILE *fptr;
    char name[1024];
    sprintf(name,"./log/urlList_%s",url);
    fptr=fopen(name,"w");
    if(fptr!=NULL){
	fprintf(fptr,"good URL list:\n");
	for(i=0;i<num;i++){
	    fprintf(fptr,"%s\n",randGet(finishPool));
	}
	fprintf(fptr,"bad URL list:\n");
	for(i=0;i<getPoolSize(failedPool);i++){
	    fprintf(fptr,"%s\n",randGet(failedPool));
	}
	fclose(fptr);
    }

}
示例#3
0
int main(int argc,char *argv[]){
    if(argc<2)
	usage(0);
    char *sourceURL=argv[1];
    clock_t begin, end;
    int i=0;
    char *handleURL;
    int pos;
    UPU *tmp;
    URL_FILE *buf;
    char prefix[10],host[1024],path[4096],filename[4096];


    for(i=0;i<HashSize;i++){
	URLPool[i]=NULL;
	finishPool[i]=NULL;
	failedPool[i]=NULL;
    }
    memset(prefix,0,10);
    memset(host,0,1024);
    memset(path,0,4096);
    memset(filename,0,4096);
    sepURL(sourceURL,prefix,host,path,filename);
    //check/create Folder    
    folderInit(host);
    readRec(sourceURL);
    //init
    if(!logInit(host)){
	printf("log file error\n");
	exit(1);
    }
    pos=hashfn(sourceURL);
    myAdd(&URLPool[pos],sourceURL,strlen(sourceURL));
    //start loop
    begin=clock();
    i=0;
    while(getPoolSize(URLPool)!=0){
	//random get one URL Structure Pointer from URLPool
	handleURL=randGet(URLPool);
	pos=hashfn(handleURL);
	printf("run [%d] %s\n",pos,handleURL);
	memset(prefix,0,10);
	memset(host,0,1024);
	memset(path,0,4096);
	memset(filename,0,4096);
	sepURL(handleURL,prefix,host,path,filename);
	//put the url in finishPool
	tmp=finishPool[pos];
	if(tmp==NULL){
	    myAdd(&finishPool[pos],handleURL,strlen(handleURL));
	}else{
	    while(tmp->next!=NULL){
		tmp=tmp->next;
	    }
	    myAdd(&(tmp->next),handleURL,strlen(handleURL));
	}
	//start run the CURL
	if((buf=runCURL(handleURL))!=NULL){	    
	    //write to File
	    myWrite(host,filename,buf->buffer,buf->buffer_len,i++);
	    getURL(buf->buffer,buf->buffer_len,handleURL,prefix,host,path,filename);
	    printf("%d\n",getPoolSize(URLPool));
	    memset(buf->buffer,0,buf->buffer_len);
	    free(buf->buffer);
	    fflush(logfp);
	}
	else{
	    printf("no content\n");
	}
	free(buf);
    }
    logClose();
    end=clock();
    printf("finally finish: %d 's URL, cost %lf sec\n",getPoolSize(finishPool),(double)( end - begin ) / CLOCKS_PER_SEC);
    myDump(host);
    return 0;
}