コード例 #1
0
void FreeStrings()
{
    debugline("freeing %d strings....\n", StringList.size());
    while(!StringList.empty())
    {
        debugline("STRING: %s\n", StringList.back());
        free(StringList.back());
        StringList.pop_back();
    }
}
コード例 #2
0
CPseudoTerminal::~CPseudoTerminal()
{    
    debugline("Destructing: %d, %d, %s\n", m_iPTYFD, m_ChildPid, m_TTYName.c_str());
    
    if (m_ChildPid)
        Kill(false);

    Close();  
}
コード例 #3
0
ファイル: edgerouting.cpp プロジェクト: fugufisch/biographer
void split_route(vector<Segment> &vs,VR &nodes,int idx, int n1, int n2){
   ParamEdge e=vs[idx].edge;
   debugline(e.from(),e.to(),255,0,0,true);
   double minp=DBL_MAX;
   int minidx=-1;
   for (int j=0,n=nodes.size();j<n;j++){
      if (j==n1 || j==n2) continue;
      if (e.cross(nodes[j])){
	 if (nodes[j].contains(e.from())) continue;
	 if (nodes[j].contains(e.to())) continue;
         double p=e.cross_param_smallest(nodes[j]);
         if (p<minp){
            minp=p;
            minidx=j;
         }
      }
   }
   if (minidx<0) return ;
   Point dc=e.dist_vec(nodes[minidx].center());
   if (dc.is_null()){
      dc=to_left(e.unit(),PI/2); // minidxust choose a side 
   }
   VP pts;
   Point r=e.dist_vec(nodes[minidx].TL());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TL());
   r=e.dist_vec(nodes[minidx].TR());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TR());
   r=e.dist_vec(nodes[minidx].BL());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BL());
   r=e.dist_vec(nodes[minidx].BR());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BR());
   if (pts.size()==0) {
      printf("Ups, no points on smaller side of edge/node cut area");
      return;
   }
   if (pts.size()>2 ) throw "expected 1 or 2 points";
   vector<Segment> vsnew;
   int idxlast=idx+1;
   if (pts.size()==1){
      vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
      vsnew.push_back(Segment(ParamEdge(pts[0],e.to()),false,vs[idx].last));
   } else if (pts.size()==2) {
      if (norm(pts[0]-e.from())>norm(pts[1]-e.from())){ // do nearest point first
	swap(pts[0],pts[1]);
      }
      vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
      vsnew.push_back(Segment(ParamEdge(pts[0],pts[1]),false,false));
      vsnew.push_back(Segment(ParamEdge(pts[1],e.to()),false,vs[idx].last));
      idxlast++;
   }
   vs.erase(vs.begin()+idx);
   vs.insert(vs.begin()+idx,vsnew.begin(),vsnew.end());
   split_route(vs,nodes,idxlast,minidx,n2);
   split_route(vs,nodes,idx,n1,minidx); // new overlaps could be introduced after makeing a kink into the line
}
コード例 #4
0
char *GetTranslation(char *s)
{
    std::map<std::string, char *>::iterator p = Translations.find(s);
    if (p != Translations.end())
        return (*p).second;
    
    // No translation found
    if (!Translations.empty())
        debugline("WARNING: No translation for %s\n", s);
    return s;
}
コード例 #5
0
// Based from a example in the book "Programming in Lua"
void StackDump(const char *msg)
{
#ifndef RELEASE

    if (msg)
        debugline(msg);

    int i;
    int top = lua_gettop(LuaState);
    for (i = 1; i <= top; i++)
    {
        /* repeat for each level */
        int t = lua_type(LuaState, i);
        switch (t)
        {
        case LUA_TSTRING:  /* strings */
            debugline("`%s'\n", lua_tostring(LuaState, i));
            break;
        case LUA_TBOOLEAN:  /* booleans */
            debugline("%s\n", lua_toboolean(LuaState, i) ? "true" : "false");
            break;
        case LUA_TNUMBER:  /* numbers */
            debugline("%g\n", lua_tonumber(LuaState, i));
            break;
        default:  /* other values */
            debugline("%s\n", lua_typename(LuaState, t));
            break;
        }
    }
    debugline("---------------\n");  /* end the listing */
#endif
}
コード例 #6
0
void CPseudoTerminal::InitTerm()
{
    CreatePTY();
    GrantPT();
    UnlockPT();
    
    debugline("TTY: %s\n", m_TTYName.c_str());
    
    int flags = fcntl(m_iPTYFD, F_GETFL);
    if (flags < 0)
        throw Exceptions::CExFCntl(errno);
    
    if (!(flags & O_NONBLOCK) &&
        (fcntl(m_iPTYFD, F_SETFL, (flags | O_NONBLOCK)) < 0))
        throw Exceptions::CExFCntl(errno);
    
    m_PollData.fd = m_iPTYFD;
    m_PollData.events = POLLIN | POLLHUP;
}
コード例 #7
0
ファイル: sbj.c プロジェクト: ftnapps/pkg-sbbs
void play()
{
	char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion
		,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n"
		,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n"
		,*YourHand="\1n\1k\0015 You \1n\1m                     (%2d) %s"
		,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s"
		,*DealerHand="\1n\1hDealer                    \1n\1m(%2d) "
		,*Bust="\1n\1r\1hBust\1n\r\n"
		,*Natural="\1g\1h\1iNatural "
		,*Three7s="\1r\1h\1iThree 7's "
		,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n"
		,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n";
	int h,i,j,file;
	uint max;
	long val;
	time_t start,now;
	struct tm* tm;

sprintf(str,"MESSAGE.%d",node_num);         /* remove message if waiting */
if(fexist(str))
    remove(str);

getgamedat(0);
if(node[node_num-1]) {
	getgamedat(1);
	node[node_num-1]=0;
	putgamedat();
	getgamedat(0); }

if(total_players && misc&INPLAY) {
	bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n");
	start=now=time(NULL);
	getgamedat(0);
	while(total_players && misc&INPLAY) {
		if((i=inkey(0))!=0) {	 /* if key was hit */
			if(i==1) {		 /* if ctrl-a */
				bputs("\r\n");
				return; } }  /* return */
		mswait(100);
		getgamedat(0);
		now=time(NULL);
		if(now-start>300) { /* only wait up to 5 minutes */
			bputs("\r\ntimeout\r\n");
			return; } }
	bputs("\r\n"); }

getgamedat(1);
node[node_num-1]=user_number;
putgamedat();

if(!total_players)
    shuffle();
else
	listplayers();

sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined());
putallnodemsg(str);

while(1) {
	aborted=0;
	#if DEBUG
	debugline("top of loop");
	#endif
	if(autoplay)
		lncntr=0;
	bprintf(ShoeStatus,cur_card,total_decks*52);
	if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer())
		shuffle();
	getgamedat(1);
	misc&=~INPLAY;
	status[node_num-1]=BET;
	node[node_num-1]=user_number;
	putgamedat();

	bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n"
		,ultoac(credits/1024L,str));
	if(credits<min_bet/1024) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you have more credits.\r\n");
        break; }
	if(credits/1024L>(ulong)max_bet)
		max=max_bet;
	else
		max=credits/1024L;
	sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: "
		,ibet<credits/1024L ? ibet : credits/1024L);
	chat();
	mnemonics(str);
	if(autoplay && keyhit())
		autoplay=0;
	if(autoplay)
		i=ibet;
	else
		i=getnum(max);
	if(i==-1)	/* if user hit ^C or 'Q' */
		break;
	bputs("\r\n");
	if(i)		/* if user entered a value */
		bet[0]=i;
	else		/* if user hit enter */
		bet[0]=ibet<credits/1024L ? ibet : credits/1024L;
	if(bet[0]<min_bet) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n");
		break; }
	ibet=bet[0];
	getgamedat(0);	/* to get all new arrivals */
	sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]);
	putallnodemsg(str);

	pc[0]=2;						/* init player's 1st hand to 2 cards */
	for(i=1;i<MAX_HANDS;i++)		/* init player's other hands to 0 cards */
		pc[i]=0;
	hands=1;						/* init total player's hands to 1 */

	getgamedat(1);					/* first come first serve to be the */
	for(i=0;i<total_nodes;i++)		/* dealer in control of sync */
		if(node[i] && status[i]==SYNC_D)
			break;
	if(i==total_nodes) {
		#if DEBUG
		debugline("syncdealer");
		#endif
		syncdealer();  }			/* all players meet here */
	else {							/* first player is current after here */
		#if DEBUG
		debugline("syncplayer");
		#endif
		syncplayer(); } 			/* game is closed (INPLAY) at this point */

	#if DEBUG
	debugline("waitturn 1");
	#endif
    waitturn();
	getnodemsg();
										/* Initial deal card #1 */
	getcarddat();
	player[0][0]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
    bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[0]=card[cur_card++];
		dc=1;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 2");
	#endif
	waitturn();
	getnodemsg();

	getcarddat();					   /* Initial deal card #2 */
	player[0][1]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
	bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[1]=card[cur_card++];
		dc=2;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 3");
	#endif
	waitturn();
	getnodemsg();
	getcarddat();

	for(i=0;i<hands;i++) {
		if(autoplay)
			lncntr=0;
		done=doub=0;
		while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) {
			h=hand(player[i],pc[i]);
			str[0]=0;
			for(j=0;j<pc[i];j++) {
				strcat(str,cardstr(player[i][j]));
				strcat(str," "); }
			j=bstrlen(str);
			while(j++<19)
				strcat(str," ");
			if(h>21) {
				strcat(str,Bust);
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
				putallnodemsg(str2);
				break; }
			if(h==21) {
				if(pc[i]==2) {	/* blackjack */
					if(player[i][0].suit==player[i][1].suit)
						strcat(str,Natural);
					strcat(str,Blackjack); }
				else {
					if(player[i][0].value==7
						&& player[i][1].value==7
						&& player[i][2].value==7)
						strcat(str,Three7s);
					strcat(str,TwentyOne); }
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
                putallnodemsg(str2);
				// fdelay(500);
				break; }
			strcat(str,"\r\n");
			sprintf(str2,YourHand,h,str);
			if(!symbols)
				strip_symbols(str2);
			bputs(str2);
			sprintf(str2,UserHand,user_name,h,str);
			putallnodemsg(str2);
			if(doub)
				break;
			sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n"
				,cardstr(dealer[1]));
			if(!symbols)
				strip_symbols(str);
			bputs(str);

			if(tutor) {
				if(pc[i]==2)
					split_card=pair(player[i],pc[i]);
				else
					split_card=0;
                if(split_card==A
					|| (split_card==9 && (dealer[1].value<7
						|| (dealer[1].value>7 && dealer[1].value<10)))
                    || split_card==8
					|| (split_card==7 && dealer[1].value<9)
					|| (split_card==6 && dealer[1].value<7)
					|| (split_card==4 && dealer[1].value==5)
					|| (split_card && split_card<4 && dealer[1].value<8))
					suggestion='P';
                else if(soft(player[i],pc[i])) {
                    if(h>18)
						suggestion='S';
					else if(pc[i]==2
						&& ((h==18
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==17
							&& dealer[1].value>2 && dealer[1].value<7)
                        || (h>13
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==12
							&& dealer[1].value>4 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; }
                else { /* hard */
					if(h>16 || (h>13 && dealer[1].value<7)
						|| (h==12 && dealer[1].value>3 && dealer[1].value<7))
						suggestion='S';
					else if(pc[i]==2
						&& (h==11 || (h==10 && dealer[1].value<10)
						|| (h==9 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; } }

			if(tutor==1)
				suggest(suggestion);
			strcpy(str,"\r\n~Hit");
			strcpy(tmp,"H\r");
			if(bet[i]+ibet<=credits/1024L && pc[i]==2) {
				strcat(str,", ~Double");
				strcat(tmp,"D"); }
			if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS
				&& player[i][0].value==player[i][1].value) {
				strcat(str,", ~Split");
				strcat(tmp,"S"); }
			strcat(str,", or [Stand]: ");
			chat();
			mnemonics(str);
			if(autoplay && keyhit())
				autoplay=0;


			if(autoplay) {
				lncntr=0;
				bputs("\r\n");
				strcpy(str,stand());
				bputs(str);
				putallnodemsg(str);
				done=1; }
			else
			switch(getkeys(tmp,0)) {
				case 'H':     /* hit */
					if(tutor==2 && suggestion!='H')
						wrong(suggestion);
					strcpy(str,hit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					break;
				case 'D':   /* double down */
					if(tutor==2 && suggestion!='D')
                        wrong(suggestion);
					strcpy(str,doubit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					doub=1;
					bet[i]+=ibet;
					break;
				case 'S':   /* split */
					if(tutor==2 && suggestion!='P')
                        wrong(suggestion);
					strcpy(str,split());
					bputs(str);
					putallnodemsg(str);
					player[hands][0]=player[i][1];
					getcarddat();
					player[i][1]=card[cur_card++];
					player[hands][1]=card[cur_card++];
					putcarddat();
					pc[hands]=2;
					bet[hands]=ibet;
					hands++;
					break;
				case CR:
					if(tutor==2 && suggestion!='S')
                        wrong(suggestion);
					strcpy(str,stand());
					bputs(str);
					putallnodemsg(str);
					done=1;
					break; } } }

	if(lastplayer()) {	/* last player plays the dealer's hand */
		getcarddat();
		while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52)
			dealer[dc++]=card[cur_card++];
		putcarddat(); }

	nextplayer();
	#if DEBUG
	debugline("waitturn 4");
	#endif
	waitturn();
	getnodemsg();

	if(firstplayer()==node_num) {
		strcpy(str,"\1n\0014\1h Final \1n\r\n");
		bputs(str);
		putallnodemsg(str); }
	getcarddat();
	dh=hand(dealer,dc); 					/* display dealer's hand */
	sprintf(str,DealerHand,dh);
	for(i=0;i<dc;i++) {
		strcat(str,cardstr(dealer[i]));
		strcat(str," "); }
	i=bstrlen(str);
	while(i++<50)				/* was 50 */
		strcat(str," ");
	if(dh>21) {
		strcat(str,Bust);
		if(!symbols)
			strip_symbols(str);
		bputs(str); }
	else if(dh==21) {
		if(dc==2) { 	/* blackjack */
			if(dealer[0].suit==dealer[1].suit)
				strcat(str,Natural);
			strcat(str,Blackjack); }
		else {			/* twenty-one */
			if(dc==3 && dealer[0].value==7 && dealer[1].value==7
				&& dealer[2].value==7)
				strcat(str,Three7s);
			strcat(str,TwentyOne); }
		if(!symbols)
            strip_symbols(str);
		bputs(str); }
	else {
		if(!symbols)
            strip_symbols(str);
		bprintf("%s\r\n",str); }

	for(i=0;i<hands;i++) {						/* display player's hand(s) */
		h=hand(player[i],pc[i]);
		str[0]=0;
		for(j=0;j<pc[i];j++) {
			strcat(str,cardstr(player[i][j]));
			strcat(str," "); }
		j=bstrlen(str);
		while(j++<19)
			strcat(str," ");
		if(logit) {
			now=time(NULL);
			tm=localtime(&now);
			sprintf(log,"%02d%02d%02d.log"                  /* log winnings */
				,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100);
			if((file=nopen(log,O_RDONLY))!=-1) {
				read(file,tmp,filelength(file));
				tmp[filelength(file)]=0;
				val=atol(tmp);
				close(file); }
			else
				val=0L;
			if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
				bprintf("error opening %s\r\n",log);
				return; } }
		if(h<22 && (h>dh || dh>21	/* player won */
			|| (h==21 && pc[i]==2 && dh==21 && dh>2))) {	/* blackjack */
			j=bet[i];								  /* and dealer got 21 */
			if(h==21 && 	/* natural blackjack or three 7's */
				((player[i][0].value==7 && player[i][1].value==7
				&& player[i][2].value==7)
				|| (pc[i]==2 && player[i][0].suit==player[i][1].suit)))
				j*=2;
			else if(h==21 && pc[i]==2)	/* regular blackjack */
				j*=1.5; /* blackjack pays 1 1/2 to 1 */
			sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j);
			strcat(str,tmp);
			credits+=j*1024L;
			val-=j*1024L;
			moduserdat(); }
		else if(h<22 && h==dh)
			strcat(str,"\1n\1hPush");
		else {
			strcat(str,"\1nLost");
			credits-=bet[i]*1024L;
			val+=bet[i]*1024L;
			moduserdat(); }
		if(logit) {
			sprintf(tmp,"%ld",val);
			write(file,tmp,strlen(tmp));
			close(file); }					/* close winning log */
		strcat(str,"\1n\r\n");
		sprintf(str2,YourHand,h,str);
		if(!symbols)
			strip_symbols(str2);
		bputs(str2);
		sprintf(str2,UserHand,user_name,h,str);
		putallnodemsg(str2); }

	nextplayer();
	if(!lastplayer()) {
		#if DEBUG
		debugline("lastplayer waitturn");
		#endif
		waitturn();
		nextplayer(); }
	#if DEBUG
	debugline("end of loop");
	#endif
	getnodemsg(); }

getgamedat(1);
node[node_num-1]=0;
putgamedat();
sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left());
putallnodemsg(str);
}
コード例 #8
0
void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events)
{
    int num_frames = 0;
    int has_buttons = 0;
    TAG*tag=swf->firstTag;

    unsigned int checksum = 0;
    while(tag) {
        if(tag->id == ST_SHOWFRAME)
            num_frames++;
        if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2)
            has_buttons = 1;
	crc32_add_bytes(checksum, tag->data, tag->len);
        tag = tag->next;
    }
    int t = time(0);
    checksum = crc32_add_bytes(checksum, &t, sizeof(t));

    unsigned char h[16];
    unsigned char file_signature[33];
    sprintf((char*)file_signature, "%x", checksum);

    char scenename1[80], scenename2[80];
    sprintf(scenename1, "rfx.MainTimeline_%s", file_signature);
    sprintf(scenename2, "rfx::MainTimeline_%s", file_signature);

    abc_file_t*file = abc_file_new();
    abc_method_body_t*c = 0;
   
    abc_class_t*cls = abc_class_new2(file, scenename2, "flash.display::MovieClip");
  
    TAG*abctag = swf_InsertTagBefore(swf, swf->firstTag, ST_DOABC);
    
    tag = swf_InsertTag(abctag, ST_SYMBOLCLASS);
    swf_SetU16(tag, 1);
    swf_SetU16(tag, 0);
    swf_SetString(tag, scenename1);

    c = abc_class_getstaticconstructor(cls, 0)->body;
    c->old.max_stack = 1;
    c->old.local_count = 1;
    c->old.init_scope_depth = 9;
    c->old.max_scope_depth = 10;

    __ getlocal_0(c);
    __ pushscope(c);
    __ returnvoid(c);

    c = abc_class_getconstructor(cls, 0)->body;
    c->old.max_stack = 3;
    c->old.local_count = 1;
    c->old.init_scope_depth = 10;
    c->old.max_scope_depth = 11;
    
    debugfile(c, "constructor.as");

    __ getlocal_0(c);
    __ pushscope(c);

    __ getlocal_0(c);
    __ constructsuper(c,0);

    if(stop_each_frame || has_buttons) {
        int frame = 0;
        tag = swf->firstTag;
        abc_method_body_t*f = 0; //frame script
        while(tag && tag->id!=ST_END) {
            char framename[80];
            char needs_framescript=0;
            char buttonname[80];
            char functionname[80];
            sprintf(framename, "[packageinternal]rfx::frame%d_%s", frame, file_signature);
            
            if(!f && (tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2 || stop_each_frame)) {
                /* make the contructor add a frame script */
                __ findpropstrict(c,"[package]::addFrameScript");
                __ pushuint(c,frame);
                __ getlex(c,framename);
                __ callpropvoid(c,"[package]::addFrameScript",2);

                f = abc_class_method(cls, 0, multiname_fromstring(framename))->body;
                f->old.max_stack = 3;
                f->old.local_count = 1;
                f->old.init_scope_depth = 10;
                f->old.max_scope_depth = 11;
                __ debugfile(f, "framescript.as");
                __ debugline(f, 1);
                __ getlocal_0(f);
                __ pushscope(f);
                if(stop_each_frame) {
                    __ findpropstrict(f, "[package]::stop");
                    __ callpropvoid(f, "[package]::stop", 0);
                }
            }

            if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
                U16 id = swf_GetDefineID(tag);
                sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
                __ getlex(f,buttonname);
                __ getlex(f,"flash.events::MouseEvent");
                __ getproperty(f, "::CLICK");
                sprintf(functionname, "::clickbutton%d_%s", swf_GetDefineID(tag), file_signature);
                __ getlex(f,functionname);
                __ callpropvoid(f, "::addEventListener" ,2);

                needs_framescript = 1;

                abc_method_body_t*h =
                    abc_class_method(cls, 0, multiname_fromstring(functionname))->body;
                list_append(h->method->parameters, multiname_fromstring("flash.events::MouseEvent"));

                h->old.max_stack = 6;
                h->old.local_count = 2;
                h->old.init_scope_depth = 10;
                h->old.max_scope_depth = 11;
                __ getlocal_0(h);
                __ pushscope(h);

                ActionTAG*oldaction = swf_ButtonGetAction(tag);
                if(oldaction && oldaction->op == ACTION__GOTOFRAME) {
                    int framenr = GET16(oldaction->data);
                    if(!events) {
                        __ findpropstrict(h,"[package]::gotoAndStop");
                        __ pushuint(h,framenr+1);
                        __ callpropvoid(h,"[package]::gotoAndStop", 1);
                    } else {
                        char framename[80];
                        sprintf(framename, "frame%d_%s", framenr, file_signature);
                        __ getlocal_0(h); //this
                        __ findpropstrict(h, "[package]flash.events::TextEvent");
                        __ pushstring(h, "link");
                        __ pushtrue(h);
                        __ pushtrue(h);
                        __ pushstring(h, framename);
                        __ constructprop(h,"[package]flash.events::TextEvent", 4);
                        __ callpropvoid(h,"[package]::dispatchEvent", 1);
                    }
                } else if(oldaction && oldaction->op == ACTION__GETURL) {
                    if(!events) {
                        __ findpropstrict(h,"flash.net::navigateToURL");
                        __ findpropstrict(h,"flash.net::URLRequest");
                        // TODO: target _blank
                        __ pushstring(h,(char*)oldaction->data); //url
                        __ constructprop(h,"flash.net::URLRequest", 1);
                        __ callpropvoid(h,"flash.net::navigateToURL", 1);
                    } else {
                        __ getlocal_0(h); //this
                        __ findpropstrict(h, "[package]flash.events::TextEvent");
                        __ pushstring(h, "link");
                        __ pushtrue(h);
                        __ pushtrue(h);
                        __ pushstring(h,(char*)oldaction->data); //url
                        __ constructprop(h,"[package]flash.events::TextEvent", 4);
                        __ callpropvoid(h,"[package]::dispatchEvent", 1);
                    }
                } else if(oldaction) {
                    fprintf(stderr, "Warning: Couldn't translate button code of button %d to flash 9 abc action\n", id);
                }
                __ returnvoid(h);
                swf_ActionFree(oldaction);
            }
            if(tag->id == ST_SHOWFRAME) {
                if(f) {
                    __ returnvoid(f);
                    f = 0;
                }
                frame++;
            }
            tag = tag->next;
        }
        if(f) {
            __ returnvoid(f);
        }
    }
    __ returnvoid(c);

    tag = swf->firstTag;
    while(tag) {
        if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
            char buttonname[80];
            sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
            multiname_t*s = multiname_fromstring(buttonname);
            //abc_class_slot(cls, multiname_fromstring(buttonname), s);
            abc_class_slot(cls, multiname_fromstring(buttonname), 
                                multiname_fromstring("flash.display::SimpleButton"));
        }
        tag = tag->next;
    }


    abc_script_t*s = abc_initscript(file);
    c = s->method->body;
    c->old.max_stack = 2;
    c->old.local_count = 1;
    c->old.init_scope_depth = 1;
    c->old.max_scope_depth = 9;

    __ getlocal_0(c);
    __ pushscope(c);
    __ getscopeobject(c, 0);
    __ getlex(c,"::Object");
    __ pushscope(c);
    __ getlex(c,"flash.events::EventDispatcher");
    __ pushscope(c);
    __ getlex(c,"flash.display::DisplayObject");
    __ pushscope(c);
    __ getlex(c,"flash.display::InteractiveObject");
    __ pushscope(c);
    __ getlex(c,"flash.display::DisplayObjectContainer");
    __ pushscope(c);
    __ getlex(c,"flash.display::Sprite");
    __ pushscope(c);
    __ getlex(c,"flash.display::MovieClip");
    __ pushscope(c);
    __ getlex(c,"flash.display::MovieClip");
    __ newclass(c,cls);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ initproperty(c,scenename2);
    __ returnvoid(c);

    //abc_method_body_addClassTrait(c, "rfx:MainTimeline", 1, cls);
    multiname_t*classname = multiname_fromstring(scenename2);
    abc_initscript_addClassTrait(s, classname, cls);
    multiname_destroy(classname);

    swf_WriteABC(abctag, file);
}
コード例 #9
0
ファイル: edgerouting.cpp プロジェクト: fugufisch/biographer
void route_edges(Layouter &state,plugin& pg, double scale, int iter, double temp, int debug){
   int n=state.nw.nodes.size();
   int i,j,k;
   vector<NodeLinePair> gs;
   Rect bb=state.nw.getBB();
   bb.extend(state.avgsize/10);
   Network nv;
   vector<VI> nodemap(n);
   vector<vector<VI> > edge_crossings(n+4,vector<VI>(n+4)); // this stores for each voronoi line between node i and j the crosspoints; includes 4 virtual nodes
   printf("finding Voronoi separator lines\n");
   for (i=0;i<n;i++){
      gs.clear();
      double x=state.nw.nodes[i].x;
      double y=state.nw.nodes[i].y;
      double w=state.nw.nodes[i].width;
      double h=state.nw.nodes[i].height;
      Rect ri=state.nw.nodes[i].rect();
      //if (i==iter) debugrect(ri,0,0,255);
      gs.push_back(NodeLinePair(n,ParamEdge(Point(x,bb.ymin),bb.TL()))); // boundary lines (should point to left); adds virtual nodes n ... n+3
      gs.push_back(NodeLinePair(n+1,ParamEdge(Point(bb.xmin,y),bb.BL())));
      gs.push_back(NodeLinePair(n+2,ParamEdge(Point(x,bb.ymax),bb.BR())));
      gs.push_back(NodeLinePair(n+3,ParamEdge(Point(bb.xmax,y),bb.TR())));
      double dclosest=DBL_MAX;
      int iclosest;
      for (j=0;j<n;j++){
         if (i==j) continue;
         double x2=state.nw.nodes[j].x;
         double y2=state.nw.nodes[j].y;
         double w2=state.nw.nodes[j].width;
         double h2=state.nw.nodes[j].height;
         double dx=x2-x;
         double dy=y2-y;
         double mx=(dx>0 ? (x+w/2+x2-w2/2)/2  : (x-w/2+x2+w2/2)/2); // point thru which separation line should go (in the middle between the two nodes)
         double my=(dy>0 ? (y+h/2+y2-h2/2)/2  : (y-h/2+y2+h2/2)/2);
         if (my<min(y,y2)) my=min(y,y2); // if nodes "overlap" in one direction, these limits need to be applied
         if (mx<min(x,x2)) mx=min(x,x2);
         if (my>max(y,y2)) my=max(y,y2);
         if (mx>max(x,x2)) mx=max(x,x2);
         Point m(mx,my);
         double gx=dy; // line sould point perpendicular to distance vector; points to left
         double gy=-dx;
         //if (i==iter) debugline(m.x,m.y,m.x+gx,m.y+gy,200,100,100,true);
//         if (i==iter) debugline(x,y,x2,y2,100,100,200,true);
         
         double ord_angles[4]; 
         double &alpha=ord_angles[0];
         alpha=angle(Point(gx,gy));
         // find suitable 0, 45 and 90° lines and sort them by proximity to (gx,gy) line
         double &nearest=ord_angles[1]; // just references to iterate through candidates later on
         double &second=ord_angles[2];
         double &third=ord_angles[3];
         nearest=PI/4*round(4*alpha/PI);
         double left=PI/2*floor(2*alpha/PI);
         double right=PI/2*ceil(2*alpha/PI);

         // find second nearest
         second=PI/4*floor(4*alpha/PI);
         if (second==nearest) second=PI/4*ceil(4*alpha/PI);
         
         // find third nearest
         if (nearest==left){
            third=right;
         } else if (nearest==right){
            third=left;
         } else if (second==left){
            third=right;
         } else {
            third=left;
         }
         
/*         for (k=0;k<3;k++){
            if (i==1) debugline(m.x,m.y,m.x+100*Point(ord_angles[k]).x,m.y+100*Point(ord_angles[k]).y,100,100,200,true);
         }*/
         // check candidates in the defined order whether they collide with one of the two nodes (i or j)
         Rect rj=state.nw.nodes[j].rect();
         Point g(0,0);
         bool found=false;
         for (k=0;k<4;k++){
            g=Point(ord_angles[k]);
            if (prod(g,rj.TL()-m)>0 && prod(g,rj.TR()-m)>0 && prod(g,rj.BR()-m)>0 && prod(g,rj.BL()-m)>0 &&
               prod(g,ri.TL()-m)<0 && prod(g,ri.TR()-m)<0 && prod(g,ri.BR()-m)<0 && prod(g,ri.BL()-m)<0) { // node j completely right of g && i completely left
                found=true;
                break;
            }
         }
         if (!found) g=Point(ord_angles[0]); // ups? do nodes overlap?
            
         // generate the line and save it 
         ParamEdge ge(m,m+g); // the voronoi line separating node i from node j
         Point pclosest=ge.dist_vec(state.nw.nodes[i]); // closest point on line to node i
         ge.re_ref(state.nw.nodes[i]+pclosest); // reference point of line needs to be the closest point to node i
         gs.push_back(NodeLinePair(j,ge));
         if (norm(pclosest)<dclosest){ // find closest line to node i on the fly
            dclosest=norm(pclosest);
            iclosest=gs.size()-1;
         }
         //if (i==iter) debugline(ge.from(),ge.p(state.avgsize*4),100,100,100,true);
      }
      
      //find  set of voronoi lines which minimally surround node i
      int curidx=iclosest;
      int minidx;
      int lastidx=-1;
      bool first=true;
      int gl=gs.size();
      VI used(gl,0);
      while (first || curidx!=iclosest){
         ParamEdge &cur=gs[curidx].line;
         double minc=DBL_MAX;
         for (j=0;j<gl;j++){ // find the nearest crosspoint of one of all voronoi lines; searching to the left from last cross point
            if (j==curidx) continue;
            if (used[j]) continue;
            if (j==lastidx) continue; // finds the last voronoi line again; should not happen as this line should be in used[] already; except for iclosest
            double c=cur.cross_param(gs[j].line);
            if (c==0) { // special case, check whether new line points inwards
               Point ctr90=to_left(Point(x,y)-cur.p(c),PI);
               Point cln90=to_left(cur.unit(),PI);
               Point dirj=gs[j].line.unit();
               if (!((scalar(ctr90,dirj)<0) && (scalar(cln90,dirj)>0))){ // new line not between center line and current line
                  continue;
               }
            }
            if (c>=0 && c<minc){
               minc=c;
               minidx=j;
               //if (i==iter) debugpoint(cur.p(c),state.avgsize/10,0,0,255);
            }
         }
         used[minidx]=1;
         Point cp=cur.cross_point(gs[minidx].line);
         //if (i==iter) debugpoint(cp,state.avgsize/10,0,255,0);
         gs[minidx].line.re_ref(cp); // setting ref point of next line to the current cross point
         //if (i==iter) debugline(gs[minidx].line.from(),gs[minidx].line.p(state.avgsize),255,0,255);
         int newnode=nv.nodes.size(); 
         nv.addNode(newnode,other,"",1,1,cp.x,cp.y,0);
         edge_crossings[min(i,gs[curidx].node)][max(i,gs[curidx].node)].push_back(newnode); // add the new node to the two veronoi lines it belongs to
         edge_crossings[min(i,gs[minidx].node)][max(i,gs[minidx].node)].push_back(newnode);
         //nodemap[i].push_back(newnode);
         lastidx=curidx;
         curidx=minidx;
         first=false;
         //if (i==iter) debugline(cur.from(),cp,0,0,0);
      }
   }
   printf("finding relevant cross points on seperator lines and building network\n");
   
   // go through all voronoi lines and connect all registered cross points
   CmpCrossPoints ccp(nv);
   for (i=0;i<n+4;i++){ // includes 4 virtual nodes
      for (j=i+1;j<n+4;j++){
         if (edge_crossings[i][j].size() ==0 ) continue;
         sort(edge_crossings[i][j].begin(),edge_crossings[i][j].end(),ccp); // sort cross points on line
         for (k=0;k<(int)edge_crossings[i][j].size();k++){
            int n1=edge_crossings[i][j][k];
            if (i<n) nodemap[i].push_back(n1); // register voronoi node to be adjacent to original node i (if not virtual node)
            if (j<n) nodemap[j].push_back(n1);
            if (k==((int)edge_crossings[i][j].size())-1) break; // for the last crosspoint we do not create an edge
            int n2=edge_crossings[i][j][k+1];
            nv.addEdge(n1,n2,undirected);
            if (iter<=1) debugline(nv.nodes[n1].x,nv.nodes[n1].y,nv.nodes[n2].x,nv.nodes[n2].y,0,0,0,true);
         }
      }
   }
   printf("finding shortest path through network for each original edge\n");
   if (iter>=1){ // this is just for showing 1 step show only veronoi lines, 2nd show splines
      nv.calcEdgeLengths();
      int m=state.nw.edges.size();
      for (i=0;i<m;i++){
         printf(".");fflush(stdout);
         Edge &e=state.nw.edges[i];
         int n1=e.from;
         int n2=e.to;
         BFS bfs(nv,nodemap[n1]);
         int nn=bfs.next();
         while (nn>=0 && find(nodemap[n2].begin(),nodemap[n2].end(),nn)==nodemap[n2].end()){
            nn=bfs.next();
         }
         if (nn<0) printf("Ups, no route for edge\n");
         VI path=bfs.path();
         smooth_path(nv,path,state.avgsize/4);
         e.splinepoints.clear();
         e.splinehandles.clear();
         double beta;
         Point vec;
         double dd1=(path.size()>1 ? 
            (norm(nv.nodes[path[0]]-state.nw.nodes[n1])-max(state.nw.nodes[n1].width,state.nw.nodes[n1].height)/2)/2 :
            (norm(state.nw.nodes[n2]-state.nw.nodes[n1])-max(state.nw.nodes[n1].width,state.nw.nodes[n1].height)/2-max(state.nw.nodes[n2].width,state.nw.nodes[n2].height)/2)/2);
         dd1=min(dd1,state.avgsize/2);
         double d1=max(state.nw.nodes[n1].width,state.nw.nodes[n1].height)/2+dd1;
         double dd2=(path.size()>1 ? 
         (norm(nv.nodes[path.back()]-state.nw.nodes[n2])-max(state.nw.nodes[n2].width,state.nw.nodes[n2].height)/2)/2 :
         (norm(state.nw.nodes[n2]-state.nw.nodes[n1])-max(state.nw.nodes[n1].width,state.nw.nodes[n1].height)/2-max(state.nw.nodes[n2].width,state.nw.nodes[n2].height)/2)/2);
         dd2=min(dd2,state.avgsize/2);
         double d2=max(state.nw.nodes[n2].width,state.nw.nodes[n2].height)/2+state.avgsize/2;
         Point sp1,sp2;
         switch(e.type){
            case substrate:
               reverse(path.begin(),path.end());
               swap(n1,n2);
               swap(d1,d2);
               sp1=(path.size()>1 ? nv.nodes[path[0]] : state.nw.nodes[n2]);
               e.splinehandles.push_back(unit(sp1-state.nw.nodes[n1])*d1);
               e.splinehandles.push_back(Point(state.nw.nodes[n2].dir+PI/2)*d2);
               break;
            case product:
               e.splinehandles.push_back(Point(state.nw.nodes[n1].dir-PI/2)*d1);
               sp2=(path.size()>1 ? nv.nodes[path.back()] : state.nw.nodes[n1]);
               e.splinehandles.push_back(unit(sp2-state.nw.nodes[n2])*d2);
               break;
            case activator:
            case inhibitor:
            case catalyst:
               reverse(path.begin(),path.end());
               swap(n1,n2);
               swap(d1,d2);
               vec=state.nw.nodes[n1]-state.nw.nodes[n2]; // vector pointing from n2 (reaction) to n1 (catalyst,etc)
               beta=0;
               if (scalar(vec,Point(state.nw.nodes[n2].dir+PI))>scalar(vec,Point(state.nw.nodes[n2].dir))) beta=PI;
               sp1=(path.size()>1 ? nv.nodes[path[0]] : state.nw.nodes[n2]);
               e.splinehandles.push_back(unit(sp1-state.nw.nodes[n1])*d1);
               e.splinehandles.push_back(Point(state.nw.nodes[n2].dir+beta)*d2);
               break;
            default:
               sp1=(path.size()>1 ? nv.nodes[path[0]] : state.nw.nodes[n2]);
               e.splinehandles.push_back(unit(sp1-state.nw.nodes[n1])*d1);
               sp2=(path.size()>1 ? nv.nodes[path.back()] : state.nw.nodes[n1]);
               e.splinehandles.push_back(unit(sp2-state.nw.nodes[n2])*d2);
         }
         if (path.size()>1){
            //debugline(state.nw.nodes[n1].x,state.nw.nodes[n1].y,nv.nodes[path.front()].x,nv.nodes[path.front()].y,255,100,100);
            for (j=0;j<(int)path.size();j++){
               Point before=(j==0 ? state.nw.nodes[n1] : nv.nodes[path[j-1]]);
               Point &after=(j==((int)path.size())-1 ? state.nw.nodes[n2] : nv.nodes[path[j+1]]);
               Point &cur=nv.nodes[path[j]];
               if (after==cur) continue;
               if (before==cur) {
                  if (j-1<0) continue;
                  before=(j-1==0 ? state.nw.nodes[n1] : nv.nodes[path[j-2]]);
               }
               Point d=unit(before-cur)+unit(after-cur);
               if (d.is_null()) continue;
               d=unit(d)*min(min(norm(before-cur),norm(after-cur))/2,state.avgsize/2);
               e.splinehandles.insert(--e.splinehandles.end(),to_left(d,PI/2)*sign(scalar(to_left(d,PI/2),before-cur)));
               e.splinepoints.push_back(cur+d);
               //debugline(cur+d,cur+d+to_left(d,PI/2)*sign(scalar(to_left(d,PI/2),before-cur)),0,0,255,true);
               //if (j<path.size()-1) debugline(nv.nodes[path[j]].x,nv.nodes[path[j]].y,nv.nodes[path[j+1]].x,nv.nodes[path[j+1]].y,255,100,100);
            }
            //debugline(nv.nodes[path.back()].x,nv.nodes[path.back()].y,state.nw.nodes[n2].x,state.nw.nodes[n2].y,255,100,100);
            
         }
      }
   }
   /*   NetDisplay nd(nv);
   nd.waitKeyPress=true;
   nd.show();*/
}
コード例 #10
0
ファイル: edgerouting.cpp プロジェクト: fugufisch/biographer
void route_edges2(Layouter &state,plugin& pg, double scale, int iter, double temp, int debug){
   VR nodes;
   double d=state.avgsize/5;
   int n=state.nw.nodes.size();
   for (int i=0;i<n;i++){
      nodes.push_back(state.nw.nodes[i].rect());
      nodes.back().extend(d);
      //debugrect(nodes.back(),0,0,255);
   }
   for (int i=0,m=state.nw.edges.size();i<m;i++){
      //if (i!=iter) continue;
      Edge &e=state.nw.edges[i];
      e.splinehandles.clear();
      e.splinepoints.clear();
      int n1=e.from;
      int n2=e.to;
      Point vec,p1,p2;
      double dir;
      switch(e.type){
         case substrate:
            dir=lim(state.nw.nodes[n1].dir+PI/2);
            vec=Point(dir);
            swap(n1,n2);
            p1=state.nw.nodes[n1];
            vec=state.nw.nodes[n2].rect().border_vec(vec);
            p2=state.nw.nodes[n2]+vec;
            break;
         case product:
            dir=lim(state.nw.nodes[n1].dir-PI/2);
            vec=Point(dir);
            vec=state.nw.nodes[n1].rect().border_vec(vec);
            p1=state.nw.nodes[n1]+vec;
            p2=state.nw.nodes[n2];
            break;
         case activator:
         case inhibitor:
         case catalyst:
            swap(n1,n2);
         default:
            p1=state.nw.nodes[n1];
            p2=state.nw.nodes[n2];
      }
      vector<Segment> vs;
      vs.push_back(Segment(ParamEdge(p1,p2),true,true));
      split_route(vs,nodes,0,n1,n2);
      Point vec1=state.nw.nodes[n1].rect().border_vec(vs.front().edge.to()-vs.front().edge.from());
      Point vec2=state.nw.nodes[n2].rect().border_vec(vs.back().edge.from()-vs.back().edge.to());
      switch(e.type){
         case activator:
         case inhibitor:
         case catalyst:
            dir=lim(state.nw.nodes[n2].dir);
            if (scalar(Point(dir),vs.back().edge.from()-vs.back().edge.to())<0) dir=lim(dir+PI);
            vec=Point(dir);
            vec=state.nw.nodes[n2].rect().border_vec(vec);
            p2=state.nw.nodes[n2]+vec;
         case substrate:
            e.splinehandles.push_back(vec1+d);
            e.splinehandles.push_back(vec+d);
            break;
         case product:
            e.splinehandles.push_back(vec+d);
            e.splinehandles.push_back(vec2+d);
            break;
         default:
            e.splinehandles.push_back(vec1+d);
            e.splinehandles.push_back(vec2+d);
      }
      for (int j=1,s=vs.size();j<s;j++){
         Point before=vs[j-1].edge.from();
         Point cur=vs[j-1].edge.to();
         //if (cur!=vs[j].edge.from()) throw "ups: edge segments not continious";
         Point after=vs[j].edge.to();
         Point dv=unit(before-cur)*d+unit(after-cur)*d;
	 debugline(cur,cur+dv,0,255,0,true);
         e.splinehandles.insert(--e.splinehandles.end(),unit(to_left(dv,PI/2))*sign(scalar(to_left(dv,PI/2),before-cur))*d);
         e.splinepoints.push_back(cur+dv);
      }
   }
}