示例#1
0
btBroadphaseProxy* btDbvtBroadphase::createProxy(const btVector3& aabbMin,
												 const btVector3& aabbMax,
												 int /*shapeType*/,
												 void* userPtr,
												 int collisionFilterGroup,
												 int collisionFilterMask,
												 btDispatcher* /*dispatcher*/)
{
	btDbvtProxy* proxy = new (btAlignedAlloc(sizeof(btDbvtProxy), 16)) btDbvtProxy(aabbMin, aabbMax, userPtr,
																				   collisionFilterGroup,
																				   collisionFilterMask);

	btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);

	//bproxy->aabb			=	btDbvtVolume::FromMM(aabbMin,aabbMax);
	proxy->stage = m_stageCurrent;
	proxy->m_uniqueId = ++m_gid;
	proxy->leaf = m_sets[0].insert(aabb, proxy);
	listappend(proxy, m_stageRoots[m_stageCurrent]);
	if (!m_deferedcollide)
	{
		btDbvtTreeCollider collider(this);
		collider.proxy = proxy;
		m_sets[0].collideTV(m_sets[0].m_root, aabb, collider);
		m_sets[1].collideTV(m_sets[1].m_root, aabb, collider);
	}
	return (proxy);
}
示例#2
0
文件: verbs.c 项目: zelch/LambdaMOO
static void
lister(void *data, const char *line)
{
    Var *r = (Var *) data;
    Var v;

    v.type = TYPE_STR;
    v.v.str = str_dup(line);
    *r = listappend(*r, v);
}
示例#3
0
static void 
xml_streamCharacterDataHandler(void *userData, const XML_Char *s, int len)
{
  XMLdata **data = (XMLdata**)userData;
  XMLdata *node = *data;
  Var element = node->element;
  Var v;
  v.type = TYPE_STR;
  v.v.str = str_dup(raw_bytes_to_binary(s, len));
  element.v.list[4] = listappend(element.v.list[4], v);
}
示例#4
0
static void 
finish_node(XMLdata *data)
{
  XMLdata *parent = data->parent;
  Var element = data->element;
  Var body;
  Stream *s = data->body;
  body.type = TYPE_STR;
  if(s == NULL) {
    body.v.str = str_dup("");
  } else {
    body.v.str = str_dup(reset_stream(s));
  }
  element.v.list[3] = body;
  if(parent != NULL) {
    Var pelement = parent->element;
    pelement.v.list[4] = listappend(pelement.v.list[4], var_ref(element));
  }
}
示例#5
0
static void
xml_startElement(void *userData, const char *name, const char **atts)
{
  XMLdata **data = (XMLdata**)userData;
  XMLdata *parent = *data;

  XMLdata *node = new_node(parent, name);
  const char **patts = atts;

  while(*patts != NULL) {
    Var pair = new_list(2);
    pair.v.list[1].type = TYPE_STR;
    pair.v.list[1].v.str = str_dup(patts[0]);
    pair.v.list[2].type = TYPE_STR;
    pair.v.list[2].v.str = str_dup(patts[1]); 
    patts += 2;
    node->element.v.list[2] = listappend(node->element.v.list[2], pair);
  }
  *data = node;
}
示例#6
0
void btDbvtBroadphase::setAabbForceUpdate(btBroadphaseProxy* absproxy,
										  const btVector3& aabbMin,
										  const btVector3& aabbMax,
										  btDispatcher* /*dispatcher*/)
{
	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
	ATTRIBUTE_ALIGNED16(btDbvtVolume)
	aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);
	bool docollide = false;
	if (proxy->stage == STAGECOUNT)
	{ /* fixed -> dynamic set	*/
		m_sets[1].remove(proxy->leaf);
		proxy->leaf = m_sets[0].insert(aabb, proxy);
		docollide = true;
	}
	else
	{ /* dynamic set				*/
		++m_updates_call;
		/* Teleporting			*/
		m_sets[0].update(proxy->leaf, aabb);
		++m_updates_done;
		docollide = true;
	}
	listremove(proxy, m_stageRoots[proxy->stage]);
	proxy->m_aabbMin = aabbMin;
	proxy->m_aabbMax = aabbMax;
	proxy->stage = m_stageCurrent;
	listappend(proxy, m_stageRoots[m_stageCurrent]);
	if (docollide)
	{
		m_needcleanup = true;
		if (!m_deferedcollide)
		{
			btDbvtTreeCollider collider(this);
			m_sets[1].collideTTpersistentStack(m_sets[1].m_root, proxy->leaf, collider);
			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, proxy->leaf, collider);
		}
	}
}
示例#7
0
void btDbvtBroadphase::collide(btDispatcher* dispatcher)
{
	/*printf("---------------------------------------------------------\n");
	printf("m_sets[0].m_leaves=%d\n",m_sets[0].m_leaves);
	printf("m_sets[1].m_leaves=%d\n",m_sets[1].m_leaves);
	printf("numPairs = %d\n",getOverlappingPairCache()->getNumOverlappingPairs());
	{
		int i;
		for (i=0;i<getOverlappingPairCache()->getNumOverlappingPairs();i++)
		{
			printf("pair[%d]=(%d,%d),",i,getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy0->getUid(),
				getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy1->getUid());
		}
		printf("\n");
	}
*/

	SPC(m_profiling.m_total);
	/* optimize				*/
	m_sets[0].optimizeIncremental(1 + (m_sets[0].m_leaves * m_dupdates) / 100);
	if (m_fixedleft)
	{
		const int count = 1 + (m_sets[1].m_leaves * m_fupdates) / 100;
		m_sets[1].optimizeIncremental(1 + (m_sets[1].m_leaves * m_fupdates) / 100);
		m_fixedleft = btMax<int>(0, m_fixedleft - count);
	}
	/* dynamic -> fixed set	*/
	m_stageCurrent = (m_stageCurrent + 1) % STAGECOUNT;
	btDbvtProxy* current = m_stageRoots[m_stageCurrent];
	if (current)
	{
#if DBVT_BP_ACCURATESLEEPING
		btDbvtTreeCollider collider(this);
#endif
		do
		{
			btDbvtProxy* next = current->links[1];
			listremove(current, m_stageRoots[current->stage]);
			listappend(current, m_stageRoots[STAGECOUNT]);
#if DBVT_BP_ACCURATESLEEPING
			m_paircache->removeOverlappingPairsContainingProxy(current, dispatcher);
			collider.proxy = current;
			btDbvt::collideTV(m_sets[0].m_root, current->aabb, collider);
			btDbvt::collideTV(m_sets[1].m_root, current->aabb, collider);
#endif
			m_sets[0].remove(current->leaf);
			ATTRIBUTE_ALIGNED16(btDbvtVolume)
			curAabb = btDbvtVolume::FromMM(current->m_aabbMin, current->m_aabbMax);
			current->leaf = m_sets[1].insert(curAabb, current);
			current->stage = STAGECOUNT;
			current = next;
		} while (current);
		m_fixedleft = m_sets[1].m_leaves;
		m_needcleanup = true;
	}
	/* collide dynamics		*/
	{
		btDbvtTreeCollider collider(this);
		if (m_deferedcollide)
		{
			SPC(m_profiling.m_fdcollide);
			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, m_sets[1].m_root, collider);
		}
		if (m_deferedcollide)
		{
			SPC(m_profiling.m_ddcollide);
			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, m_sets[0].m_root, collider);
		}
	}
	/* clean up				*/
	if (m_needcleanup)
	{
		SPC(m_profiling.m_cleanup);
		btBroadphasePairArray& pairs = m_paircache->getOverlappingPairArray();
		if (pairs.size() > 0)
		{
			int ni = btMin(pairs.size(), btMax<int>(m_newpairs, (pairs.size() * m_cupdates) / 100));
			for (int i = 0; i < ni; ++i)
			{
				btBroadphasePair& p = pairs[(m_cid + i) % pairs.size()];
				btDbvtProxy* pa = (btDbvtProxy*)p.m_pProxy0;
				btDbvtProxy* pb = (btDbvtProxy*)p.m_pProxy1;
				if (!Intersect(pa->leaf->volume, pb->leaf->volume))
				{
#if DBVT_BP_SORTPAIRS
					if (pa->m_uniqueId > pb->m_uniqueId)
						btSwap(pa, pb);
#endif
					m_paircache->removeOverlappingPair(pa, pb, dispatcher);
					--ni;
					--i;
				}
			}
			if (pairs.size() > 0)
				m_cid = (m_cid + ni) % pairs.size();
			else
				m_cid = 0;
		}
	}
	++m_pid;
	m_newpairs = 1;
	m_needcleanup = false;
	if (m_updates_call > 0)
	{
		m_updates_ratio = m_updates_done / (btScalar)m_updates_call;
	}
	else
	{
		m_updates_ratio = 0;
	}
	m_updates_done /= 2;
	m_updates_call /= 2;
}
示例#8
0
void btDbvtBroadphase::setAabb(btBroadphaseProxy* absproxy,
							   const btVector3& aabbMin,
							   const btVector3& aabbMax,
							   btDispatcher* /*dispatcher*/)
{
	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
	ATTRIBUTE_ALIGNED16(btDbvtVolume)
	aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);
#if DBVT_BP_PREVENTFALSEUPDATE
	if (NotEqual(aabb, proxy->leaf->volume))
#endif
	{
		bool docollide = false;
		if (proxy->stage == STAGECOUNT)
		{ /* fixed -> dynamic set	*/
			m_sets[1].remove(proxy->leaf);
			proxy->leaf = m_sets[0].insert(aabb, proxy);
			docollide = true;
		}
		else
		{ /* dynamic set				*/
			++m_updates_call;
			if (Intersect(proxy->leaf->volume, aabb))
			{ /* Moving				*/

				const btVector3 delta = aabbMin - proxy->m_aabbMin;
				btVector3 velocity(((proxy->m_aabbMax - proxy->m_aabbMin) / 2) * m_prediction);
				if (delta[0] < 0) velocity[0] = -velocity[0];
				if (delta[1] < 0) velocity[1] = -velocity[1];
				if (delta[2] < 0) velocity[2] = -velocity[2];
				if (
					m_sets[0].update(proxy->leaf, aabb, velocity, gDbvtMargin)

				)
				{
					++m_updates_done;
					docollide = true;
				}
			}
			else
			{ /* Teleporting			*/
				m_sets[0].update(proxy->leaf, aabb);
				++m_updates_done;
				docollide = true;
			}
		}
		listremove(proxy, m_stageRoots[proxy->stage]);
		proxy->m_aabbMin = aabbMin;
		proxy->m_aabbMax = aabbMax;
		proxy->stage = m_stageCurrent;
		listappend(proxy, m_stageRoots[m_stageCurrent]);
		if (docollide)
		{
			m_needcleanup = true;
			if (!m_deferedcollide)
			{
				btDbvtTreeCollider collider(this);
				m_sets[1].collideTTpersistentStack(m_sets[1].m_root, proxy->leaf, collider);
				m_sets[0].collideTTpersistentStack(m_sets[0].m_root, proxy->leaf, collider);
			}
		}
	}
}
示例#9
0
文件: ext-http.c 项目: quadagh/TauMOO
static package bf_http_request( Var arglist, Byte next, void *vdata, Objid progr)
{
  CURL *curl_handle;
  CURLcode ok;
  package result;
  if (!is_wizard(progr))
  {
    free_var(arglist);
    return make_error_pack(E_PERM);
  }
  int nargs = arglist.v.list[0].v.num;
  const char *address = arglist.v.list[1].v.str;
  const char *agent="",*postfields="",*cookies="";
  int headers = 0;
  switch(nargs)
  {
    case 5:
        cookies = arglist.v.list[5].v.str;
    case 4:
	postfields = arglist.v.list[4].v.str;
    case 3:
	agent = arglist.v.list[3].v.str;
    case 2:
	headers = arglist.v.list[2].v.num;
  }
  if(!strlen(agent))
    agent = "MOO-http/1.0";
  const char delimiters[] = "\n";
  free_var(arglist);

  struct MemoryStruct chunk;

  chunk.memory = malloc(1);
  chunk.size = 0;

  curl_global_init(CURL_GLOBAL_ALL);

  curl_handle = curl_easy_init();
  curl_easy_setopt(curl_handle, CURLOPT_URL, address);
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, agent);
  curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 5);
  curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 3);
  curl_easy_setopt(curl_handle, CURLOPT_FTP_RESPONSE_TIMEOUT, 3);
  curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 5);
  curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
  curl_easy_setopt(curl_handle, CURLOPT_MAXFILESIZE, 1048576);
  if(strlen(postfields))
    curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postfields);
  if(strlen(cookies))
    curl_easy_setopt(curl_handle, CURLOPT_COOKIE, cookies);
  if(headers)
    curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1);
  ok = curl_easy_perform(curl_handle);
  curl_easy_cleanup(curl_handle);

  if(ok == CURLE_OK && strlen(chunk.memory) != chunk.size)
    ok = CURLE_BAD_CONTENT_ENCODING;   // binary !!!

  if(ok == CURLE_OK)
  {
    char *token,*p=chunk.memory;
    Var r;
    r.type = TYPE_LIST;
    r = new_list(0);
    token = strsep(&p, delimiters);
    while( token != NULL )
    {
	Var line;
	line.type = TYPE_STR;
	if(token[strlen(token)-1] == '\r')
	    token[strlen(token)-1] = '\0';
	//run it through utf8_substr to get rid of invalid utf8
	line.v.str = (char *)utf8_substr(token,1,utf8_strlen(token));
	r = listappend(r, var_dup(line));
	token = strsep(&p, delimiters);
	free_var(line);
    }
    result = make_var_pack(r);
  }
  else
  {
    Var r;
    r.type = TYPE_INT;
    r.v.num = ok;
    result = make_raise_pack(E_INVARG,
			curl_easy_strerror(ok),
			r);
  }

  if(chunk.memory)
    free(chunk.memory);
    
  curl_global_cleanup();
  
  return result;
}
示例#10
0
文件: moosql.c 项目: quadagh/TauMOO
static package bf_mysql_query( Var arglist, Byte next, void *vdata, Objid progr)
{
  Var r;
  char error_string[MOOSQL_ERROR_LEN];
  MYSQL_CONN *wrapper;
  MYSQL_RES *res_set;
#ifdef MOOSQL_MULTIPLE_STATEMENTS
  Var tmp;
  Var end;
  int len = 0; 
  int continu = 1;
#endif
  if (!is_wizard(progr))
    {
      free_var(arglist);
      return make_error_pack(E_PERM);
    }
  Objid oid = arglist.v.list[1].v.obj;
  wrapper = resolve_mysql_connection(oid);
  if (wrapper == NULL || wrapper->conn == NULL || wrapper->active == 0)
    {
      free_var(arglist);
      return make_error_pack(E_INVARG);
    }
  const char *query = arglist.v.list[2].v.str;
  free_var(arglist);
  /* we do the query now. */
  if (mysql_query (wrapper->conn, query) != 0)   /* failed */
   {
     /* there is an error, so we will return that string. similar to below which
      * returns a string for a successful query with no result set which is handled in
      * process_mysql_query */
     snprintf(error_string,MOOSQL_ERROR_LEN,"ERR: %s",mysql_error(wrapper->conn));
     r.type = TYPE_STR;
     r.v.str = str_dup(error_string);
     return make_var_pack(r);
   }
  wrapper->last_query_time = time(0);
#ifdef MOOSQL_MULTIPLE_STATEMENTS
  r = new_list(1);
  r.v.list[1].type = TYPE_INT;
  r.v.list[1].v.num = 0;
  end = new_list(0);
  while (continu)
    {
      len++;
      res_set = process_mysql_query(wrapper,error_string);
      if (res_set == NULL) /* there was no result on this query */
	{
	  tmp.type = TYPE_STR;
	  tmp.v.str = str_dup(error_string);
	  end = listappend(end,var_dup(tmp));
	}
      else 
	{
	  tmp = process_result_set(wrapper,res_set);
	  end = listappend(end,var_dup(tmp));
	}
      if (mysql_more_results(wrapper->conn))
	{
	  mysql_next_result(wrapper->conn);
	  continu = 1;
	}
      else
	continu = 0;
    }
  if (len <= 1) /* if there is only one result return it like in previous versions, a list of rows */
    return make_var_pack(end.v.list[1]);
  r.v.list[1].v.num = len;
  /* if there are more return it in this format {X, Y} where X is the number of results and Y is a list of results */
  r = listappend(r,end); 
  return make_var_pack(r);
#else
  res_set = process_mysql_query(wrapper,error_string);

  if (res_set == NULL) /* there was either an error / no result on this query */
    {
      r.type = TYPE_STR;
      r.v.str = str_dup(error_string);
      return make_var_pack(r);
    }
  r = process_result_set(wrapper,res_set); 
  return make_var_pack(r);
#endif

}
示例#11
0
int main (int argc, char * argv [])

{
    LIST files;
    char filename [FILENAME_MAX];
    char const * paths [_LISTSIZE] =
    {
        getenv ("PWD"),
        (char const *) (0)
    };
    size_t path = 1;

#if CTAR_SEARCH

    /*
     * search argv for additional -Ipath and -I path argments, similar to
     * gcc compiler options; since we are not using getoptv() to parse the
     * command line, we scan argv[] and strip out these extra arguments;
     */

    int argn;
    int argx;
    for (argn = 1; argn < argc; argn++)
    {
        char const * sp = argv [argn];
        if (* sp++ != GETOPTV_C_OPTION)
        {
            continue;
        }
        if (* sp++ != 'I')
        {
            continue;
        }
        if (* sp == (char) (0))
        {
            for (argx = argn; argx < argc; argx++)
            {
                argv [argx] = argv [argx +  1];
            }
            sp = argv [argn];
            argc--;
        }
        paths [path++] = sp;
        for (argx = argn; argx < argc; argx++)
        {
            argv [argx] = argv [argx +  1];
        }
        argn--;
        argc--;
    }
    paths [path] = (char const *) (0);
    argv [argc] = (char *) (0);

#endif

    if (argc < 4)
    {
        printf ("%s [tar-options] archive program [-I path] [-I path] [...]\n", * argv);
        exit (1);
    }
    makepath (filename, getenv ("PWD"), argv [-- argc]);
    listcreate (& files, _LISTSIZE);
    listappend (& files, filename);
    if (ccollect (& files, paths))
    {
        error (1, 0, "%s: missing %d file(s)", files.table [0], files.error);
    }
    if ((args = (char **) (malloc ((argc +  files.count +  1) * sizeof (char *)))))
    {
        error (1, 0, "%s: out of memory", basename ((char *) (* argv)));
    }
    args [0] = PATH_TAR;
    for (argc = 1; argv [argc]; argc++)
    {
        args [argc] = argv [argc];
    }
    for (files.lower = files.start; files.lower < files.count; files.lower++)
    {
        args [argc++] = (char *) (files.table [files.lower]);
    }
    args [argc] = (char *) (0);
    execv (* args, args);
    error (1, errno, "can't execute %s", * args);
    exit (0);
}