Example #1
0
void State::floor(const _3Vec& X) {
	(*this)[d_index] = max((*this)[d_index], rho_floor);
#ifndef POLYTROPIC
	const Real ei0 = et() - ek(X);
	if (ei0 > 0.1 * et()) {
		(*this)[tau_index] = pow(max(ei0, ei_floor), 1.0 / gamma);
	}
#endif
}
Example #2
0
Real State::ei(const _3Vec& X) const {
#ifdef POLYTROPIC
	Real ei0;
#else POLYTROPIC
	Real ei0 = et() - ek(X);
	if (ei0 <= 0.001 * et()) {
#endif
		ei0 = pow((*this)[tau_index], gamma);
#ifndef POLYTROPIC
	}
#endif
	return max(ei0, ei_floor);
}
Example #3
0
void Navigation::_navmesh_unlink(int p_id) {

	ERR_FAIL_COND(!navmesh_map.has(p_id));
	NavMesh &nm=navmesh_map[p_id];
	ERR_FAIL_COND(!nm.linked);

	print_line("UNLINK");

	for (List<Polygon>::Element *E=nm.polygons.front();E;E=E->next()) {


		Polygon &p=E->get();

		int ec = p.edges.size();
		Polygon::Edge *edges=p.edges.ptr();

		for(int i=0;i<ec;i++) {
			int next = (i+1)%ec;

			EdgeKey ek(edges[i].point,edges[next].point);
			Map<EdgeKey,Connection>::Element *C=connections.find(ek);
			ERR_CONTINUE(!C);
			if (C->get().B) {
				//disconnect

				C->get().B->edges[C->get().B_edge].C=NULL;
				C->get().B->edges[C->get().B_edge].C_edge=-1;
				C->get().A->edges[C->get().A_edge].C=NULL;
				C->get().A->edges[C->get().A_edge].C_edge=-1;

				if (C->get().A==&E->get()) {

					C->get().A=C->get().B;
					C->get().A_edge=C->get().B_edge;
				}
				C->get().B=NULL;
				C->get().B_edge=-1;

			} else {
				connections.erase(C);
				//erase
			}
		}
	}

	nm.polygons.clear();

	nm.linked=false;


}
int main()
{
    int res,i,u,v,w;
    s=1;
//    freopen("D:\\in.txt","r",stdin);
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        chu();
        
        for(i=0;i<m;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            cap[u][v] += w;
        }
        res=ek();
        printf("%d\n",res);
    }
    return 0;
}
int main()
{
    int i,f,num,res,u,v,w,m;
//    freopen("D:\\in.txt","r",stdin);
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {    
        scanf("%d%d",&n,&m);
            
        chu();

        for(f=0;f<m;f++)
        {
            scanf("%d%d%d",&u,&v,&w);
            cap[u][v]+=w;
        }

        res=ek();
        printf("Case %d: %d\n",i+1,res);
    }
    return 0;
}
Example #6
0
void Navigation2D::_navpoly_link(int p_id) {

	ERR_FAIL_COND(!navpoly_map.has(p_id));
	NavMesh &nm = navpoly_map[p_id];
	ERR_FAIL_COND(nm.linked);

	PoolVector<Vector2> vertices = nm.navpoly->get_vertices();
	int len = vertices.size();
	if (len == 0)
		return;

	PoolVector<Vector2>::Read r = vertices.read();

	for (int i = 0; i < nm.navpoly->get_polygon_count(); i++) {

		//build

		List<Polygon>::Element *P = nm.polygons.push_back(Polygon());
		Polygon &p = P->get();
		p.owner = &nm;

		Vector<int> poly = nm.navpoly->get_polygon(i);
		int plen = poly.size();
		const int *indices = poly.ptr();
		bool valid = true;
		p.edges.resize(plen);

		Vector2 center;
		float sum = 0;

		for (int j = 0; j < plen; j++) {

			int idx = indices[j];
			if (idx < 0 || idx >= len) {
				valid = false;
				break;
			}

			Polygon::Edge e;
			Vector2 ep = nm.xform.xform(r[idx]);
			center += ep;
			e.point = _get_point(ep);
			p.edges.write[j] = e;

			int idxn = indices[(j + 1) % plen];
			if (idxn < 0 || idxn >= len) {
				valid = false;
				break;
			}

			Vector2 epn = nm.xform.xform(r[idxn]);

			sum += (epn.x - ep.x) * (epn.y + ep.y);
		}

		p.clockwise = sum > 0;

		if (!valid) {
			nm.polygons.pop_back();
			ERR_CONTINUE(!valid);
			continue;
		}

		p.center = center / plen;

		//connect

		for (int j = 0; j < plen; j++) {

			int next = (j + 1) % plen;
			EdgeKey ek(p.edges[j].point, p.edges[next].point);

			Map<EdgeKey, Connection>::Element *C = connections.find(ek);
			if (!C) {

				Connection c;
				c.A = &p;
				c.A_edge = j;
				c.B = NULL;
				c.B_edge = -1;
				connections[ek] = c;
			} else {

				if (C->get().B != NULL) {
					ConnectionPending pending;
					pending.polygon = &p;
					pending.edge = j;
					p.edges.write[j].P = C->get().pending.push_back(pending);
					continue;
				}

				C->get().B = &p;
				C->get().B_edge = j;
				C->get().A->edges.write[C->get().A_edge].C = &p;
				C->get().A->edges.write[C->get().A_edge].C_edge = j;
				p.edges.write[j].C = C->get().A;
				p.edges.write[j].C_edge = C->get().A_edge;
				//connection successful.
			}
		}
	}

	nm.linked = true;
}
Example #7
0
void Navigation2D::_navpoly_unlink(int p_id) {

	ERR_FAIL_COND(!navpoly_map.has(p_id));
	NavMesh &nm = navpoly_map[p_id];
	ERR_FAIL_COND(!nm.linked);

	for (List<Polygon>::Element *E = nm.polygons.front(); E; E = E->next()) {

		Polygon &p = E->get();

		int ec = p.edges.size();
		Polygon::Edge *edges = p.edges.ptrw();

		for (int i = 0; i < ec; i++) {
			int next = (i + 1) % ec;

			EdgeKey ek(edges[i].point, edges[next].point);
			Map<EdgeKey, Connection>::Element *C = connections.find(ek);
			ERR_CONTINUE(!C);

			if (edges[i].P) {
				C->get().pending.erase(edges[i].P);
				edges[i].P = NULL;

			} else if (C->get().B) {
				//disconnect

				C->get().B->edges.write[C->get().B_edge].C = NULL;
				C->get().B->edges.write[C->get().B_edge].C_edge = -1;
				C->get().A->edges.write[C->get().A_edge].C = NULL;
				C->get().A->edges.write[C->get().A_edge].C_edge = -1;

				if (C->get().A == &E->get()) {

					C->get().A = C->get().B;
					C->get().A_edge = C->get().B_edge;
				}
				C->get().B = NULL;
				C->get().B_edge = -1;

				if (C->get().pending.size()) {
					//reconnect if something is pending
					ConnectionPending cp = C->get().pending.front()->get();
					C->get().pending.pop_front();

					C->get().B = cp.polygon;
					C->get().B_edge = cp.edge;
					C->get().A->edges.write[C->get().A_edge].C = cp.polygon;
					C->get().A->edges.write[C->get().A_edge].C_edge = cp.edge;
					cp.polygon->edges.write[cp.edge].C = C->get().A;
					cp.polygon->edges.write[cp.edge].C_edge = C->get().A_edge;
					cp.polygon->edges.write[cp.edge].P = NULL;
				}

			} else {
				connections.erase(C);
				//erase
			}
		}
	}

	nm.polygons.clear();

	nm.linked = false;
}
Example #8
0
void Navigation::_navmesh_link(int p_id) {

	ERR_FAIL_COND(!navmesh_map.has(p_id));
	NavMesh &nm=navmesh_map[p_id];
	ERR_FAIL_COND(nm.linked);

	print_line("LINK");

	DVector<Vector3> vertices=nm.navmesh->get_vertices();
	int len = vertices.size();
	if (len==0)
		return;

	DVector<Vector3>::Read r=vertices.read();

	for(int i=0;i<nm.navmesh->get_polygon_count();i++) {

		//build

		List<Polygon>::Element *P=nm.polygons.push_back(Polygon());
		Polygon &p=P->get();
		p.owner=&nm;

		Vector<int> poly = nm.navmesh->get_polygon(i);
		int plen=poly.size();
		const int *indices=poly.ptr();
		bool valid=true;
		p.edges.resize(plen);

		Vector3 center;
		float sum=0;

		for(int j=0;j<plen;j++) {

			int idx = indices[j];
			if (idx<0 || idx>=len) {
				valid=false;
				break;
			}

			Polygon::Edge e;
			Vector3 ep=nm.xform.xform(r[idx]);
			center+=ep;
			e.point=_get_point(ep);
			p.edges[j]=e;

			if (j>=2) {
				Vector3 epa = nm.xform.xform(r[indices[j-2]]);
				Vector3 epb = nm.xform.xform(r[indices[j-1]]);

				sum+=up.dot((epb-epa).cross(ep-epa));

			}

		}

		p.clockwise=sum>0;

		if (!valid) {
			nm.polygons.pop_back();
			ERR_CONTINUE(!valid);
			continue;
		}

		p.center=center/plen;

		//connect

		for(int j=0;j<plen;j++) {

			int next = (j+1)%plen;
			EdgeKey ek(p.edges[j].point,p.edges[next].point);

			Map<EdgeKey,Connection>::Element *C=connections.find(ek);
			if (!C) {

				Connection c;
				c.A=&p;
				c.A_edge=j;
				c.B=NULL;
				c.B_edge=-1;
				connections[ek]=c;
			} else {

				if (C->get().B!=NULL) {
					ConnectionPending pending;
					pending.polygon=&p;
					pending.edge=j;
					p.edges[j].P=C->get().pending.push_back(pending);
					continue;
					//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
				}
				//ERR_CONTINUE(C->get().B!=NULL); //wut

				C->get().B=&p;
				C->get().B_edge=j;
				C->get().A->edges[C->get().A_edge].C=&p;
				C->get().A->edges[C->get().A_edge].C_edge=j;;
				p.edges[j].C=C->get().A;
				p.edges[j].C_edge=C->get().A_edge;
				//connection successful.
			}
		}
	}

	nm.linked=true;

}
Example #9
0
void XWindow::OnKeyPress(WindowEventKey *e)
{
    // ********************************************************************
    // Calculate keySym and keyText
    XkbStateRec s;
    Status st = XkbGetState(e->Handle()->display, XkbUseCoreKbd, &s);
    if (st != XkbOD_Success)
        throw new XException("Error getting xkb keyboard state", __FILE__, __LINE__, __func__);

    int shift = (s.mods & ShiftMask) != 0 ? 1 : 0;
    if (shift == 0) shift =  (s.mods & Mod5Mask) != 0 ? 2 : 0;
    //int lock = (s.mods & LockMask) != 0 ? 1 : 0;
    //int ctrl = (s.mods & ControlMask) != 0 ? 1 : 0;
    //int mod1 = (s.mods & Mod1Mask) != 0 ? 1 : 0;
    //int mod2 = (s.mods & Mod2Mask) != 0 ? 1 : 0;
    //int mod3 = (s.mods & Mod3Mask) != 0 ? 1 : 0;
    //int mod4 = (s.mods & Mod4Mask) != 0 ? 1 : 0;
    //int mod5 = (s.mods & Mod5Mask) != 0 ? 1 : 0;
    KeySym keySym = XkbKeycodeToKeysym(e->Handle()->display, e->Handle()->keycode, 0, shift);

    char cadena[10];
    int overflow = 0;
    int nbytes = XkbTranslateKeySym(e->Handle()->display, &keySym, s.mods, cadena, 10, &overflow);
    Text keyText = nbytes > 0 ? cadena : "";


    // ********************************************************************
    // Manage KeyPreview and KeyPress events
    ControlEventKey ek(*e, KeyCompositionSymbol(keySym, keyText));

    // Key preview to every control
    for (int i=0; i<controls->Count(); i++)
        (*controls)[i]->OnKeyPreview(&ek);

    // OnKeyPress until the focused control catches it
    bool redirected = false;
    for (int i=0; i<controls->Count() && !redirected; i++)
        redirected = (*controls)[i]->OnKeyPress(&ek);

    // Noone catched the event?
    if (!redirected) {
        if (keySym == KeySymbols::Tab) {
            // Window focus rotate
            if (!e->PressedShift()) ControlFocusNext();
            else ControlFocusPrevious();
        } else if (keySym == KeySymbols::Return) {
            // Return: Window Accept
        } else if (keySym == KeySymbols::Escape) {
            // Escape: Window Cancel
        } else if (keySym == KeySymbols::Space) {
            // Return: Window Accept
        }
    }

    DelegationOnKeyPress().Execute(e);


    // ********************************************************************
    // Manage KeySymbol event
    bool continueComposing = false;
    Text t = KeyCompositionManager::Default().GetComposedKeySym(*composeKeySymBuffer + keyText, continueComposing);
    *composeKeySymBuffer = continueComposing ? *composeKeySymBuffer + keyText : "";

    // Send Key Symbol Event
    if (!continueComposing) {
        KeyCompositionSymbol symbol(t == keyText ? keySym : 0, t);
        WindowEventKeySymbol weks(symbol);
        OnKeySymbol(&weks);
    }
}
Example #10
0
void State::to_con(const _3Vec& X) {
	(*this)[sx_index] *= rho();
	(*this)[sy_index] *= rho();
	(*this)[sz_index] *= rho();
	(*this)[et_index] += ek(X);
}
Example #11
0
void State::to_prim(const _3Vec& X) {
	(*this)[et_index] -= ek(X);
	(*this)[sx_index] /= rho();
	(*this)[sy_index] /= rho();
	(*this)[sz_index] /= rho();
}