コード例 #1
0
ファイル: termcap.c プロジェクト: Distrotech/screen
/*
 * Compile the terminal capabilities for a display.
 * Input: tgetent(, D_termname) extra_incap, extra_outcap.
 * Effect: display initialisation.
 */
int InitTermcap(int width, int height)
{
	char *s;
	int i;
	char tbuf[TERMCAP_BUFSIZE], *tp;
	int t, xue, xse, xme;

	memset(tbuf, 0, sizeof(tbuf));
	if (*D_termname == 0 || e_tgetent(tbuf, D_termname) != 1) {
		Msg(0, "Cannot find terminfo entry for '%s'.", D_termname);
		return -1;
	}

	if ((D_tentry = malloc(TERMCAP_BUFSIZE + (extra_incap ? strlen(extra_incap) + 1 : 0))) == 0) {
		Msg(0, "%s", strnomem);
		return -1;
	}

	/*
	 * loop through all needed capabilities, record their values in the display
	 */
	tp = D_tentry;
	for (i = 0; i < T_N; i++) {
		switch (term[i].type) {
		case T_FLG:
			D_tcs[i].flg = e_tgetflag(term[i].tcname);
			break;
		case T_NUM:
			D_tcs[i].num = e_tgetnum(term[i].tcname);
			break;
		case T_STR:
			D_tcs[i].str = e_tgetstr(term[i].tcname, &tp);
			/* no empty strings, please */
			if (D_tcs[i].str && *D_tcs[i].str == 0)
				D_tcs[i].str = 0;
			break;
		default:
			Panic(0, "Illegal tc type in entry #%d", i);
		 /*NOTREACHED*/}
	}

	/*
	 * Now a good deal of sanity checks on the retrieved capabilities.
	 */
	if (D_HC) {
		Msg(0, "You can't run screen on a hardcopy terminal.");
		return -1;
	}
	if (D_OS) {
		Msg(0, "You can't run screen on a terminal that overstrikes.");
		return -1;
	}
	if (!D_CL) {
		Msg(0, "Clear screen capability required.");
		return -1;
	}
	if (!D_CM) {
		Msg(0, "Addressable cursor capability required.");
		return -1;
	}
	if ((s = getenv("COLUMNS")) && (i = atoi(s)) > 0)
		D_CO = i;
	if ((s = getenv("LINES")) && (i = atoi(s)) > 0)
		D_LI = i;
	if (width)
		D_CO = width;
	if (height)
		D_LI = height;
	if (D_CO <= 0)
		D_CO = 80;
	if (D_LI <= 0)
		D_LI = 24;

	if (D_CTF) {
		/* standard fixes for xterms etc */
		/* assume color for everything that looks ansi-compatible */
		if (!D_CAF && D_ME && (InStr(D_ME, "\033[m") || InStr(D_ME, "\033[0m"))) {
			D_CAF = "\033[3%p1%dm";
			D_CAB = "\033[4%p1%dm";
		}
		if (D_OP && InStr(D_OP, "\033[39;49m"))
			D_CAX = 1;
		if (D_OP && (InStr(D_OP, "\033[m") || InStr(D_OP, "\033[0m")))
			D_OP = 0;
		/* ISO2022 */
		if ((D_EA && InStr(D_EA, "\033(B")) || (D_AS && InStr(D_AS, "\033(0")))
			D_CG0 = 1;
		if (InStr(D_termname, "xterm") || InStr(D_termname, "rxvt") || (D_CKM && InStr(D_CKM, "\033[M")))
			D_CXT = 1;
		/* "be" seems to be standard for xterms... */
		if (D_CXT)
			D_BE = 1;
	}
	if (nwin_options.flowflag == nwin_undef.flowflag)
		nwin_default.flowflag = D_CNF ? FLOW_OFF : D_NX ? FLOW_ON : FLOW_AUTOFLAG;
	D_CLP |= (!D_AM || D_XV || D_XN);
	if (!D_BL)
		D_BL = "\007";
	if (!D_BC) {
		if (D_BS)
			D_BC = "\b";
		else
			D_BC = D_LE;
	}
	if (!D_CR)
		D_CR = "\r";
	if (!D_NL)
		D_NL = "\n";

	/*
	 *  Set up attribute handling.
	 *  This is rather complicated because termcap has different
	 *  attribute groups.
	 */

	if (D_UG > 0)
		D_US = D_UE = 0;
	if (D_SG > 0)
		D_SO = D_SE = 0;
	/* Unfortunately there is no 'mg' capability.
	 * For now we think that mg > 0 if sg and ug > 0.
	 */
	if (D_UG > 0 && D_SG > 0)
		D_MH = D_MD = D_MR = D_MB = D_ME = 0;

	xue = ATYP_U;
	xse = ATYP_S;
	xme = ATYP_M;

	if (D_SO && D_SE == 0) {
		Msg(0, "Warning: 'so' but no 'se' capability.");
		if (D_ME)
			xse = xme;
		else
			D_SO = 0;
	}
	if (D_US && D_UE == 0) {
		Msg(0, "Warning: 'us' but no 'ue' capability.");
		if (D_ME)
			xue = xme;
		else
			D_US = 0;
	}
	if ((D_MH || D_MD || D_MR || D_MB) && D_ME == 0) {
		Msg(0, "Warning: 'm?' but no 'me' capability.");
		D_MH = D_MD = D_MR = D_MB = 0;
	}
	/*
	 * Does ME also reverse the effect of SO and/or US?  This is not
	 * clearly specified by the termcap manual. Anyway, we should at
	 * least look whether ME and SE/UE are equal:
	 */
	if (D_UE && D_SE && strcmp(D_SE, D_UE) == 0)
		xse = xue;
	if (D_SE && D_ME && strcmp(D_ME, D_SE) == 0)
		xse = xme;
	if (D_UE && D_ME && strcmp(D_ME, D_UE) == 0)
		xue = xme;

	for (i = 0; i < NATTR; i++) {
		D_attrtab[i] = D_tcs[T_ATTR + i].str;
		D_attrtyp[i] = i == ATTR_SO ? xse : (i == ATTR_US ? xue : xme);
	}

	/* Set up missing entries (attributes are priority ordered) */
	s = 0;
	t = 0;
	for (i = 0; i < NATTR; i++)
		if ((s = D_attrtab[i])) {
			t = D_attrtyp[i];
			break;
		}
	for (i = 0; i < NATTR; i++) {
		if (D_attrtab[i] == 0) {
			D_attrtab[i] = s;
			D_attrtyp[i] = t;
		} else {
			s = D_attrtab[i];
			t = D_attrtyp[i];
		}
	}
	if (D_CAF || D_CAB || D_CSF || D_CSB)
		D_hascolor = 1;
	if (D_UT)
		D_BE = 1;	/* screen erased with background color */

	if (!D_DO)
		D_DO = D_NL;
	if (!D_SF)
		D_SF = D_NL;
	if (D_IN)
		D_IC = D_IM = 0;
	if (D_EI == 0)
		D_IM = 0;
	/* some strange termcap entries have IC == IM */
	if (D_IC && D_IM && strcmp(D_IC, D_IM) == 0)
		D_IC = 0;
	if (D_KE == 0)
		D_KS = 0;
	if (D_CVN == 0)
		D_CVR = 0;
	if (D_VE == 0)
		D_VI = D_VS = 0;
	if (D_CCE == 0)
		D_CCS = 0;

	if (D_CG0) {
		if (D_CS0 == 0)
			D_CS0 = "\033(%p1%c";
		if (D_CE0 == 0)
			D_CE0 = "\033(B";
		D_AC = 0;
		D_EA = 0;
	} else if (D_AC || (D_AS && D_AE)) {	/* some kind of graphics */
		D_CS0 = (D_AS && D_AE) ? D_AS : "";
		D_CE0 = (D_AS && D_AE) ? D_AE : "";
		D_CC0 = D_AC;
	} else {
		D_CS0 = D_CE0 = "";
		D_CC0 = 0;
		D_AC = "";	/* enable default string */
	}

	for (i = 0; i < 256; i++)
		D_c0_tab[i] = i;
	if (D_AC) {
		/* init with default string first */
		s = "l+m+k+j+u+t+v+w+q-x|n+o~s_p\"r#`+a:f'g#~o.v-^+<,>h#I#0#y<z>";
		for (i = (strlen(s) - 2) & ~1; i >= 0; i -= 2)
			D_c0_tab[(int)(unsigned char)s[i]] = s[i + 1];
	}
	if (D_CC0)
		for (i = (strlen(D_CC0) - 2) & ~1; i >= 0; i -= 2)
			D_c0_tab[(int)(unsigned char)D_CC0[i]] = D_CC0[i + 1];
	if (D_PF == 0)
		D_PO = 0;

	if (D_CXC)
		if (CreateTransTable(D_CXC))
			return -1;

	/* Termcap fields Z0 & Z1 contain width-changing sequences. */
	if (D_CZ1 == 0)
		D_CZ0 = 0;

	CheckScreenSize(0);

	if (D_TS == 0 || D_FS == 0 || D_DS == 0)
		D_HS = 0;
	if (D_HS) {
		if (D_WS < 0)
			D_WS = 0;
	}
	D_has_hstatus = hardstatusemu & ~HSTATUS_ALWAYS;
	if (D_HS && !(hardstatusemu & HSTATUS_ALWAYS))
		D_has_hstatus = HSTATUS_HS;

	if (D_CKJ) {
		int enc = FindEncoding(D_CKJ);
		if (enc != -1)
			D_encoding = enc;
	}
	if (!D_tcs[T_NAVIGATE].str && D_tcs[T_NAVIGATE + 1].str)
		D_tcs[T_NAVIGATE].str = D_tcs[T_NAVIGATE + 1].str;	/* kh = @1 */
	if (!D_tcs[T_NAVIGATE + 2].str && D_tcs[T_NAVIGATE + 3].str)
		D_tcs[T_NAVIGATE + 2].str = D_tcs[T_NAVIGATE + 3].str;	/* kH = @7 */

	D_UPcost = CalcCost(D_UP);
	D_DOcost = CalcCost(D_DO);
	D_NLcost = CalcCost(D_NL);
	D_LEcost = CalcCost(D_BC);
	D_NDcost = CalcCost(D_ND);
	D_CRcost = CalcCost(D_CR);
	D_IMcost = CalcCost(D_IM);
	D_EIcost = CalcCost(D_EI);

	if (D_CAN) {
		D_auto_nuke = true;
	}
	if (D_COL > 0) {
		D_obufmax = D_COL;
		D_obuflenmax = D_obuflen - D_obufmax;
	}

	/* Some xterm entries set F0 and F10 to the same string. Nuke F0. */
	if (D_tcs[T_CAPS].str && D_tcs[T_CAPS + 10].str && !strcmp(D_tcs[T_CAPS].str, D_tcs[T_CAPS + 10].str))
		D_tcs[T_CAPS].str = 0;
	/* Some xterm entries set kD to ^?. Nuke it. */
	if (D_tcs[T_NAVIGATE_DELETE].str && !strcmp(D_tcs[T_NAVIGATE_DELETE].str, "\0177"))
		D_tcs[T_NAVIGATE_DELETE].str = 0;
	/* wyse52 entries have kcub1 == kb == ^H. Nuke... */
	if (D_tcs[T_CURSOR + 3].str && !strcmp(D_tcs[T_CURSOR + 3].str, "\008"))
		D_tcs[T_CURSOR + 3].str = 0;

	D_nseqs = 0;
	for (i = 0; i < T_OCAPS - T_CAPS; i++)
		remap(i, 1);
	for (i = 0; i < kmap_extn; i++)
		remap(i + (KMAP_KEYS + KMAP_AKEYS), 1);
	D_seqp = D_kmaps + 3;
	D_seql = 0;
	D_seqh = 0;

	D_tcinited = 1;
	MakeTermcap(0);
	CheckEscape();
	return 0;
}
コード例 #2
0
ファイル: Corpse.cpp プロジェクト: 2mac/openspades
		void Corpse::LineCollision(NodeType a, NodeType b, float dt){
			if(!r_corpseLineCollision)
				return;
			Node& n1 = nodes[a];
			Node& n2 = nodes[b];
			
			IntVector3 hitBlock;
			
			if(map->CastRay(n1.lastPos, n2.lastPos, 16.f, hitBlock)) {
				GameMap::RayCastResult res1 = map->CastRay2(n1.lastPos, n2.lastPos - n1.lastPos, 8);
				GameMap::RayCastResult res2 = map->CastRay2(n2.lastPos, n1.lastPos - n2.lastPos, 8);
				
				if(!res1.hit) return;
				if(!res2.hit) return;
				if(res1.startSolid || res2.startSolid){
					return;
				}
				
				// really hit?
				if(Vector3::Dot(res1.hitPos - n1.lastPos, n2.lastPos - n1.lastPos)
				   > (n2.pos-n1.pos).GetPoweredLength()){
					return;
				}
				if(Vector3::Dot(res1.hitPos - n1.lastPos, n2.lastPos - n1.lastPos)
				  < 0.f){
					return;
				}
				if(Vector3::Dot(res2.hitPos - n2.lastPos, n1.lastPos - n2.lastPos)
				   > (n2.pos-n1.pos).GetPoweredLength()){
					return;
				}
				if(Vector3::Dot(res2.hitPos - n2.lastPos, n1.lastPos - n2.lastPos)
				   < 0.f){
					return;
				}
				
				Vector3 blockPos;
				blockPos.x = hitBlock.x + .5f;
				blockPos.y = hitBlock.y + .5f;
				blockPos.z = hitBlock.z + .5f;
				
				float inlen = (res1.hitPos - res2.hitPos).GetLength();
				
				IntVector3 ivec = {0, 0, 0};
				
				ivec.x += res1.normal.x;
				ivec.y += res1.normal.y;
				ivec.z += res1.normal.z;
				ivec.x += res2.normal.x;
				ivec.y += res2.normal.y;
				ivec.z += res2.normal.z;
				
				Vector3 dir = {0.f, 0.f, 0.f};
				if(ivec.x == 0 && ivec.y == 0 && ivec.z == 0) {
					// hanging. which direction to escape?
					float bestDist = 1000.f;
					IntVector3 bestDir;
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(1, 0, 0),
								bestDist, bestDir);
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(-1, 0, 0),
								bestDist, bestDir);
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(0, 1, 0),
								bestDist, bestDir);
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(0, -1, 0),
								bestDist, bestDir);
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(0, 0, 1),
								bestDist, bestDir);
					CheckEscape(map, hitBlock,
								n1.pos.Floor(),
								n2.pos.Floor(),
								IntVector3::Make(0, 0, -1),
								bestDist, bestDir);
					if(bestDist > 10.f){
						// failed to find appropriate direction.
						return;
					}
					ivec = bestDir;
					inlen = bestDist + .1f;
				}
				dir.x = ivec.x;
				dir.y = ivec.y;
				dir.z = ivec.z;
				
				Vector3 normDir = dir; // |D|
				
				n1.vel -= normDir * std::min(Vector3::Dot(normDir, n1.vel), 0.f);
				n2.vel -= normDir * std::min(Vector3::Dot(normDir, n2.vel), 0.f);
				
				dir *= dt * inlen * 5.f;
				
				n1.vel += dir;
				n2.vel += dir;
				
				// friction
				n1.vel -= (n1.vel - normDir * Vector3::Dot(normDir, n1.vel)) * .2f;
				n2.vel -= (n2.vel - normDir * Vector3::Dot(normDir, n2.vel)) * .2f;
				
			}
			
		}