bool point_in_rectangle(const point &p, const point &v, double w, double h) {
  static const bool EDGE_IS_INSIDE = true;
  if (w < 0) {
    return point_in_rectangle(p, point(v.x + w, v.y), -w, h);
  }
  if (h < 0) {
    return point_in_rectangle(p, point(v.x, v.y + h), w, -h);
  }
  return EDGE_IS_INSIDE
      ? (GE(p.x, v.x) && LE(p.x, v.x + w) && GE(p.y, v.y) && LE(p.y, v.y + h))
      : (GT(p.x, v.x) && LT(p.x, v.x + w) && GT(p.y, v.y) && LT(p.y, v.y + h));
}
void SW_SWC_adjust_snow( RealD temp_min, RealD temp_max, RealD ppt, RealD *rain, RealD *snow, RealD *snowmelt, RealD *snowloss ) {
/*---------------------
	10/04/2010	(drs) added snowMAUS snow accumulation, sublimation and melt algorithm: Trnka, M., Kocmánková, E., Balek, J., Eitzinger, J., Ruget, F., Formayer, H., Hlavinka, P., Schaumberger, A., Horáková, V., Mozny, M. & Zalud, Z. (2010) Simple snow cover model for agrometeorological applications. Agricultural and Forest Meteorology, 150, 1115-1127.
					replaced SW_SWC_snow_accumulation, SW_SWC_snow_sublimation, and SW_SWC_snow_melt with SW_SWC_adjust_snow
	10/19/2010	(drs) replaced snowMAUS simulation with SWAT2K routines: Neitsch S, Arnold J, Kiniry J, Williams J. 2005. Soil and water assessment tool (SWAT) theoretical documentation. version 2005. Blackland Research Center, Texas Agricultural Experiment Station: Temple, TX.
	Inputs:	temp_min: daily minimum temperature (C)
			temp_max: daily maximum temperature (C)
			ppt: daily precipitation (cm)
			snowpack[Yesterday]: yesterday's snowpack (water-equivalent cm)
	Outputs:	snowpack[Today], partitioning of ppt into rain and snow, snowmelt and snowloss
---------------------*/


RealD	*snowpack = &SW_Soilwat.snowpack[Today],
		doy = SW_Model.doy,
		temp_ave, Rmelt, snow_cov = 1., cov_soil = 0.5,
		SnowAccu = 0., SnowMelt = 0., SnowLoss = 0.;
		
static RealD temp_snow = 0.;

temp_ave = (temp_min+temp_max)/2.;
/* snow accumulation */
if ( LE(temp_ave, SW_Site.TminAccu2) ) {SnowAccu = ppt;} else {SnowAccu = 0.;}
*rain = fmax(0., ppt - SnowAccu);
*snow = fmax(0., SnowAccu);
*snowpack += SnowAccu;

/* snow melt */
Rmelt = (SW_Site.RmeltMax+SW_Site.RmeltMin)/2. + sin((doy-81.)/58.09) * (SW_Site.RmeltMax-SW_Site.RmeltMin)/2.;
temp_snow = temp_snow*(1-SW_Site.lambdasnow) + temp_ave * SW_Site.lambdasnow;
if ( GT(temp_snow, SW_Site.TmaxCrit) ) {SnowMelt = fmin( *snowpack, Rmelt * snow_cov * ((temp_snow + temp_max)/2. - SW_Site.TmaxCrit) );} else {SnowMelt = 0.;}
if ( GT(*snowpack, 0.) ) {
	*snowmelt = fmax(0., SnowMelt);
	*snowpack = fmax(0., *snowpack - *snowmelt );
} else {
	*snowmelt = 0.;
}

/* snow loss through sublimation and other processes */
SnowLoss = fmin( *snowpack, cov_soil * SW_Soilwat.pet );
if ( GT(*snowpack, 0.) ) {
	*snowloss = fmax(0., SnowLoss);
	*snowpack = fmax(0., *snowpack - *snowloss );
} else {
	*snowloss = 0.;
}

}
Пример #3
0
Glib::ustring FileManager::get_first_file()
	{
	if( !initialised )
		return GT( "No file to load." );
	file_iterator = filenames.begin();
	return *file_iterator;
	}
Пример #4
0
// saving is only supported for png, jpeg and bmp, let's see whether we are allowed
// to save whatever the user is trying to save
Glib::ustring FileManager::filter_save_filename(Glib::ustring filename)
	{
	if( magic_file( cookie, filename.c_str() ) != NULL )
		{
		result = magic_file(cookie, filename.c_str() );
#ifdef DEBUG
		std::cout << result << std::endl;
#endif // DEBUG
		}
	else
		{
		std::cerr << GT( "FILTER_SAVE_FILENAME: The file type could not be determined: " ) << filename << std::endl;
		return "unsupported";
		}

	if( result.find("JPEG") != Glib::ustring::npos )
		return "jpeg";

	else if( result.find("PNG") != Glib::ustring::npos )
		return "png";

	else if( result.find("PC bitmap") != Glib::ustring::npos )
		return "bmp";

	else
		return  "unsupported";
	
	}
Пример #5
0
void decrease_key (int delta, item* i, heap* h) {

  node* n = i->n;
  
  i->key = i->key - delta;
  n->key = i->key;
  
  if (n->parent != NULL) {

    // first clean up one level up
    if (n->right_sibling == n) { // only one in the list
      n->parent->child = NULL;
      n->parent->rank = 0;
    } else {
      n->parent->child = n->right_sibling; //make sure the parents child does not point to us
      n->parent->rank = n->parent->rank - 1;
      remove_node_in_list(n);
    }

    update_marked(n->parent, h);

    n->parent = NULL;

    // move the node up to the root
    concat_list(h->min_node, n);    
  }
      
  if (GT(h->min_node->key, n->key)) {
    h->min_node = n;
  }
}
Пример #6
0
int ShowEscortHelp (char *goal_str, char *tstr)
{

	int				nItems;
	newmenu_item	m [12];
	char szGoal		[40], szMsgs [40];

	static char *szEscortHelp [12] = {
		"0.  Next Goal: %s",
		"1.  Find Energy Powerup",
		"2.  Find Energy Center",
		"3.  Find Shield Powerup",
		"4.  Find Any Powerup",
		"5.  Find a Robot",
		"6.  Find a Hostage",
		"7.  Stay Away From Me",
		"8.  Find My Powerups",
		"9.  Find the exit",
		"",
		"T.  %s Messages"
		};

sprintf (szGoal, TXT_GOAL_NEXT, goal_str);
sprintf (szMsgs, TXT_GOAL_MESSAGES, tstr);
memset (m, 0, sizeof (m));
for (nItems = 1; nItems < 10; nItems++) {
	m [nItems].text = GT (343 + nItems);
	m [nItems].type = *m [nItems].text ? NM_TYPE_MENU : NM_TYPE_TEXT;
	m [nItems].key = -1;
	}
m [0].text = szGoal;
m [10].text = szMsgs;
m [10].key = KEY_T;
return ExecMenutiny2 (NULL, "Guide-Bot Commands", 11, m, NULL);
}
DefaultAllocator::~DefaultAllocator()
{
	if (m_allocatedCount != 0 || m_allocatedSize != 0)
	{
		WRITE_LOG(WARNING, GT("Memory leak detected!"));
	}
}
Пример #8
0
int KickPlayer (int bBan)
{
	int i, name_index = 5 - bBan;
	const char *pszKick = GT (589 + bBan);

if (strlen (gameData.multigame.msg.szMsg) > 5)
	while (gameData.multigame.msg.szMsg [name_index] == ' ')
		name_index++;

if (!NetworkIAmMaster ()) {
	HUDInitMessage (TXT_KICK_RIGHTS, gameData.multiplayer.players [NetworkWhoIsMaster ()].callsign, pszKick);
	MultiSendMsgQuit ();
	return 1;
	}
if (strlen (gameData.multigame.msg.szMsg) <= (size_t) name_index) {
	HUDInitMessage (TXT_KICK_NAME, pszKick);
	MultiSendMsgQuit ();
	return 1;
	}

if (gameData.multigame.msg.szMsg [name_index] == '#' && ::isdigit (gameData.multigame.msg.szMsg [name_index+1])) {
	int players [MAX_PLAYERS];
	int listpos = gameData.multigame.msg.szMsg [name_index+1] - '0';

	if (gameData.multigame.kills.bShowList == 1 || gameData.multigame.kills.bShowList == 2) {
		if (listpos == 0 || listpos  >= gameData.multiplayer.nPlayers) {
			HUDInitMessage (TXT_KICK_PLR, pszKick);
			MultiSendMsgQuit ();
			return 1;
			}
		MultiGetKillList (players);
		i = players [listpos];
		if ((i != gameData.multiplayer.nLocalPlayer) && (gameData.multiplayer.players [i].connected))
			goto kick_player;
		}
	else 
		HUDInitMessage (TXT_KICK_NUMBER, pszKick);
	MultiSendMsgQuit ();
	return 1;
	}

for (i = 0; i < gameData.multiplayer.nPlayers; i++)
	if ((!strnicmp (gameData.multiplayer.players [i].callsign, &gameData.multigame.msg.szMsg [name_index], strlen (gameData.multigame.msg.szMsg)-name_index)) && (i != gameData.multiplayer.nLocalPlayer) && (gameData.multiplayer.players [i].connected)) {
kick_player:;
		if (gameStates.multi.nGameType  >= IPX_GAME)
			NetworkDumpPlayer (
				netPlayers.m_info.players [i].network.ipx.server, 
				netPlayers.m_info.players [i].network.ipx.node, 
				7);

		HUDInitMessage (TXT_DUMPING, gameData.multiplayer.players [i].callsign);
		if (bBan)
			banList.Add (gameData.multiplayer.players [i].callsign);
		MultiSendMsgQuit ();
		return 1;
		}
return 0;
}
Пример #9
0
// save the configuration file
void AppWindow::save_config(void)
	{
	#ifdef DEBUG
	std::cout << GT( "SAVE_CONFIG: Saving config file to $HOME/.gimmagerc\n" );
	#endif
	
	FILE * config;

	Glib::ustring home;
	Glib::ustring configfile;

	if( (home = Glib::get_home_dir() ) == "" )
		std::cerr << GT( "SAVE_CONFIG: Failed to find home directory" ) << std::endl;
	else
		configfile = home + (Glib::ustring) "/.gimmagerc";
	
	if( (config = fopen(configfile.c_str(),"w")) == NULL )
		{
		std::cerr << GT( "SAVE_CONFIG: Failed to write config file." ) << std::endl;
		}
	else
		{
		// alow the filechooser to hide before saving the sizes
		FileChooser.hide();
		while(Gtk::Main::events_pending()) Gtk::Main::iteration();
		
		w_width = get_width();
		w_height = get_height();
		v_width = (int)h_scroller->get_page_size();
		v_height = (int)v_scroller->get_page_size();

		if( v_height == 0 )
			v_height = 420;
		if( v_width == 0 )
			v_width = 420;
		if( w_height == 0 )
			w_height = 480;
		if( w_width == 0)
			w_width = 640;
		
		fprintf(config,"w_width=%d\nw_height=%d\nv_width=%d\nv_height=%d\n",
						w_width, w_height, v_width, v_height);
		fclose(config);
		}
	}
void PartResource::importXmlNode(slim::XmlNode* node, void* param0, void* param1)
{
	assert(node != NULL);

	m_userProperty.pairs.reserve(node->getChildCount(GT("property")));
	m_materialResources.reserve(node->getChildCount(GT("material")));

	//for compatibility
	readMesh(node, param0, param1, GT("mesh"));

	slim::NodeIterator nodeIter;
	for (slim::XmlNode* child = node->getFirstChild(nodeIter);
		child != NULL;
		child = node->getNextChild(nodeIter))
	{
		if (Strcmp(child->getName(), GT("mesh")) == 0)
		{
			if (m_meshResource == NULL)
			{
				readMesh(child, param0, param1, GT("filename"));
			}
		}
		else if (Strcmp(child->getName(), GT("material")) == 0)
		{
			readMaterial(child, param0, param1);
		}
		else if (Strcmp(child->getName(), GT("property")) == 0)
		{
			readPropertyFromNode(child, m_userProperty.pairs);
		}
	}
}
Пример #11
0
/* TreeSearch: search for target starting at node root.
Pre:   The tree to which root points has been created.
Post: The function returns a pointer to a tree node that matches targetor
NULL if the target is not in the tree. */
   arv_bin * TreeSearch(arv_bin *root, char * target)
   {
      if (root)
         if (LT(target, root->info))
            root = TreeSearch(root->left, target);
         
         else if (GT(target, root->info))
            root = TreeSearch(root->right, target);
   
      return root;
   }
Пример #12
0
/**
* @brief B tree internal search.
*
* @param x subtree root.
* @param k the element to search.
*
* @return return the search result, if not find the element, it will return 
* SEARCH_NIL, which the node pointer is NIL.
*/
PRIVATE SEARCH_RET _btree_search(NODE* x, ELEMENT k) {
	int i = 0;
	while (i < x->n && GT(k, x->key[i])) { i ++; }
	if (i < x->n && EQ(k, x->key[i])) {
		return (SEARCH_RET){x, i};
	} else if (x->leaf) {
		return SEARCH_NIL;
	} else {
		_btree_disk_read(x->c[i]);
		return _btree_search(x->c[i], k);
	}
}
Пример #13
0
FileManager::FileManager(int argc, char **argv)
	{
	// we have not initialised yet
	initialised = false;
	// no operations carried out yet
	last_op_next = false;
	last_op_previous = false;


	// initialise magic database
	if( (cookie = magic_open(MAGIC_SYMLINK) ) == NULL)
		std::cout << GT( "FILEMANAGER: ERROR during magic open" ) << std::endl;
	if( magic_load(cookie,NULL) != 0 )
		std::cout << GT( "FILEMANAGER: ERROR during magic load" ) << std::endl;

	numfiles=0;
	cwd_checked=0;
	/* let's call OpenFiles() to scan through the directories and set the initialised variable
	   to tell everyone we're up and running */
	if( OpenFiles(argc,argv) )
		initialised = true;
	}
void PartResource::readMesh(slim::XmlNode* node, void* param0, void* param1, const slim::Char* meshAttrName)
{
	assert(node != NULL);

	slim::XmlAttribute* filenameAttr = node->findAttribute(meshAttrName);
	if (filenameAttr == NULL)
	{
		return;
	}
	ResourceType resType;
	slim::XmlAttribute* typeAttr = node->findAttribute(GT("type"));
	if (typeAttr != NULL && Strcmp(typeAttr->getValue<const Char*>(), GT("skinned")) == 0)
	{
		resType = RES_TYPE_SKINNED_MESH;
	}
	else
	{
		resType = RES_TYPE_RIGID_MESH;
	}
	IResource* resource = grabChildResource(resType, filenameAttr->getValue<const Char*>(), param0, param1);
	m_meshResource = static_cast<Resource*>(resource);
}
RealD SW_SnowDepth( RealD SWE, RealD snowdensity) {
/*---------------------
	08/22/2011	(drs)	calculates depth of snowpack
	Input:	SWE: snow water equivalents (cm = 10kg/m2)
			snowdensity (kg/m3)
	Output: snow depth (cm)
---------------------*/
	if( GT(snowdensity, 0.) ){
		return SWE / snowdensity * 10. * 100.;
	} else {
		return 0.;
	}
}
void 
_BSort::ranksort(int lo, int hi, int depth)
{
  int i,j;
  for (i=lo+1; i<=hi; i++)
    {
      int tmp = posn[i];
      for(j=i-1; j>=lo && GT(posn[j], tmp, depth); j--)
        posn[j+1] = posn[j];
      posn[j+1] = tmp;
    }
  for(i=lo;i<=hi;i++) 
    rank[posn[i]]=i;
}
bool PartResource::importXml(const void* buffer, size_t size, void* param0, void* param1)
{
	slim::XmlDocument xmlFile;
	if (!xmlFile.loadFromMemory((const char*)buffer, size))
	{
		return false;
	}
	slim::XmlNode* node = xmlFile.findChild(GT("part"));
	if (node == NULL)
	{
		return false;
	}
	importXmlNode(node, param0, param1);
	return true;
}
Пример #18
0
/*
 |  void  siftdown (array, lower, upper)
 |  KEY_T  array[];
 |  int    lower, upper;
 |
 |  Abstract:
 |	Assume array[] is a heap except array[lower] is not in order.
 |	Sift array[lower] down the heap as long as it is bigger than
 |	its two children nodes. Preserving the heap condition.
 |
 |	Optimization: rather than swapping array[i] with the greater
 |	of its children within the loop, we save array[lower]
 |	before the loop, shift the inner values within the loop, and
 |	finally plug the saved value into its final location.
 */
void  siftdown (KEY_T array[], int lower, int upper)
{
    register int	i = lower, c = lower;
    register int	lastindex = upper/2;
    register KEY_T	temp;

    temp = array[i];
    while (c <= lastindex) {
	c = 2 * i;		/* c = 2i is the left-child of i */
	if (c + 1 <= upper  &&  GT(array[c + 1], array[c]))
	    c++;		/* c is the greatest child of i */
	if (GE(temp, array[c])) break;
	array[i] = array[c];
	i = c;
    }
    array[i] = temp;
}
Пример #19
0
void  insort_long (long *array, int len)
{
	int	i, j;
	long	temp;

	for (i = 1; i < len; i++) {
		/* invariant:  array[0..i-1] is sorted */
		j = i;
		/* customization bug: SWAP is not used here */
		temp = array[j];
		while (j > 0 && GT(array[j-1], temp)) {
			array[j] = array[j-1];
			j--;
		}
		array[j] = temp;
	}
}
Пример #20
0
Glib::ustring FileManager::get_previous_file()
	{
	if( !initialised )
		return GT( "No file to load." );

	std::list<Glib::ustring>::iterator end = filenames.end();
	std::list<Glib::ustring>::iterator begin = filenames.begin();
		
	// no next/prev operations carried out yet, load the last image
	if( !last_op_previous && !last_op_next && file_iterator == begin )
		{
		last_op_previous = true;
		last_op_next = false;
		file_iterator = end; // don't forget, end() points to a position after the last image
		file_iterator--;
		return *file_iterator;
		}

	// we're going through the pictures backwards and hit the first one
	// we'll jump to the last one in the list
	// OR
	// we've hit the first picture going forwards and now want to go backwards
	// we display the last picture
	if( last_op_previous && file_iterator == begin || last_op_next && file_iterator == begin )
		{
		last_op_previous = true;
		last_op_next = false;
		file_iterator = end;
		file_iterator--;
		return *file_iterator;
		}
	// valid for all pictures except the first one ->
	// we decrement the iterator and display the picture
	else if( file_iterator != begin )
		{
		last_op_previous = true;
		last_op_next = false;
		file_iterator--;
		return *file_iterator;
		}

	}
Пример #21
0
heap* meld (heap* h1, heap* h2) {

  if (h1->min_node == NULL) { *h1 = *h2; return h1; }
  if (h2->min_node == NULL) {return h1; }

  node* h1_min_node = h1->min_node;
  node* h2_min_node = h2->min_node;

  concat_list(h1_min_node, h2_min_node);

  if (GT(h1_min_node->key, h2_min_node->key)) {
    h1->min_node = h2->min_node;
  }

  h1->rank = h1->rank + h2->rank;
  
  free(h2);

  return h1;
}
Пример #22
0
static	void	rmfree(RMHEAD_PTR h, MAX_SIZ_TYP n)
{
	RMHEAD_PTR	f;
#ifdef	_MSC_VER
	RMHEAD_PTR	t;
#endif

	n = RMCHUNK(n);
	RMnfree	 += n;
	h->s.size = n;
	if (!RMfree)  {
		RMfree = h;
		h->s.next = NULL;
		return;
	}
	if (GT(RMfree, h))  {
		if (EQ(h + n / sizeof(RMHEAD), RMfree))	 {
			h->s.size += RMfree->s.size;
			h->s.next =  RMfree->s.next;
			RMfree = h;
			return;
		}
		h->s.next = RMfree;
		RMfree = h;
		return;
	}
	for (f=RMfree ;	f->s.next ; f=f->s.next)
		if (LT(f, h)  &&  LT(h, f->s.next))
			break;
	if (EQ(f + f->s.size / (long) sizeof(RMHEAD), h))
		f->s.size += h->s.size;
	else  {
		h->s.next = f->s.next;
		f->s.next = h;
		f = h;
	}
	if (f->s.next  &&  EQ(f	+ f->s.size / (long) sizeof(RMHEAD), f->s.next))  {
		f->s.size += f->s.next->s.size;
		f->s.next =  f->s.next->s.next;
	}
}
void SW_SWC_adjust_swc( TimeInt doy) {
/* =================================================== */
/* 01/07/02 (cwb) added final loop to guarantee swc > swc_min
*/

SW_SOILWAT *v = &SW_Soilwat;
RealD lower, upper;
LyrIndex lyr;
TimeInt dy = doy -1;

switch (SW_Soilwat.hist.method) {
case SW_Adjust_Avg:
ForEachSoilLayer(lyr) {
v->swc[Today][lyr] += v->hist.swc[dy][lyr];
v->swc[Today][lyr] /= 2.;
}
break;

case SW_Adjust_StdErr:
ForEachSoilLayer(lyr) {
upper = v->hist.swc[dy][lyr] + v->hist.std_err[dy][lyr];
lower = v->hist.swc[dy][lyr] - v->hist.std_err[dy][lyr];
if ( GT(v->swc[Today][lyr], upper) )
v->swc[Today][lyr] = upper;
else if ( LT(v->swc[Today][lyr], lower) )
v->swc[Today][lyr] = lower;
}
break;

default:
LogError(logfp, LOGFATAL, "%s : Invalid SWC adjustment method.",
SW_F_name(eSoilwat));
}


/* this will guarantee that any method will not lower swc */
/* below the minimum defined for the soil layers          */
ForEachSoilLayer(lyr)
	v->swc[Today][lyr] = fmax(v->swc[Today][lyr], SW_Site.lyr[lyr]->swc_min);

}
Пример #24
0
/**
* @brief B tree internal insert element into non-full node method.
*
* @param x the subtree root.
* @param k the element to insert.
*/
PRIVATE void _btree_insert_nonfull(NODE* x, ELEMENT k) {
	int i = x->n-1;
	if (x->leaf) {
		while (i >= 0 && LT(k, x->key[i])) {
			ELEMENT_COPY(x->key[i+1], x->key[i]);
			i --;
		}
		ELEMENT_COPY(x->key[i+1], k);
		x->n ++;
		_btree_disk_write(x);
	} else {
		while (i >= 0 && LT(k, x->key[i])) { i --; }
		i ++;
		_btree_disk_read(x->c[i]);
		if (FULL_KEY_COUNT == x->c[i]->n) {
			_btree_split_child(x, i);
			if (GT(k, x->key[i])) { i ++; }
		}
		_btree_insert_nonfull(x->c[i], k);
	}
}
Пример #25
0
/**************************************************************************************************************************************
 PURPOSE: To get the index of the lower(x1) and upper bound(x2) at the depth, for use in soil_temperature function.  written in it's own separate function to reduce code duplication.  located here so it doesn't take up space in SW_Flow_lib.c

 *NOTE* Works with positive values.  Hasn't been tested with negative values, might not work correctly

 HISTORY:
 05/31/2012 (DLM) initial coding

 INPUTS:
 size - the size of the array bounds[]
 depth - the depth of the index you are looking for, should be less than the highest bound (ie. bounds[size - i]) or the function won't work properly
 bounds[] - the depths of the bounds (needs to be in order from lowest to highest)

 OUTPUTS:
 x1 - the index of the lower bound (-1 means below the lowest depth of bounds[] (aka UINT_MAX), in this case x2 will be 0)
 x2 - the index of the upper bound (-1 means above the highest depth of bounds[] (aka UINT_MAX), in this case x1 will be size - 1)
 equal - is this equals 1, then the depth is equal to the depth at bounds[x1]
 **************************************************************************************************************************************/
void st_getBounds(unsigned int *x1, unsigned int *x2, unsigned int *equal, unsigned int size, double depth, double bounds[]) {
	unsigned int i;
	*equal = 0;
	*x1 = -1; 			// -1 means below the lowest bound
	*x2 = size - 1; 	// size - 1 is the upmost bound...

	// makes sure the depth is within the bounds before starting the for loop... to save time if it's not in between the bounds
	if (LT(depth, bounds[0])) {
		*x2 = 0;
		return;
	} else if (GT(depth, bounds[size - 1])) {
		*x1 = size - 1;
		*x2 = -1;
		return;
	}

	for (i = 0; i < size; i++) {

		if (i < size - 1) { // to avoid going out of the bounds of the array and subsequently blowing up the program
			if (LE(bounds[i], depth) && (!(LE(bounds[i + 1], depth)))) {
				*x1 = i;
				if (EQ(bounds[i], depth)) {
					*equal = 1;
					*x2 = i;
					return; // return since they're equal & no more calculation is necessary
				}
			}
		}
		if (i > 0) {  // to avoid going out of the bounds of the array
			if (GE(bounds[i], depth) && (!(GE(bounds[i - 1], depth)))) {
				*x2 = i;
				if (EQ(bounds[i], depth)) {
					*equal = 1;
					*x1 = i;
				}
				return; // if it's found the upperbound, then the lowerbound has already been calculated, so return
			}
		}
	}
}
Пример #26
0
void MultiThreadingOptionsMenu (void)
{
	CMenu	m (10);
	int	h, i, bSound = gameData.app.bUseMultiThreading [rtSound], choice = 0;

	static int	menuToTask [rtTaskCount] = {0, 1, 1, 2, 2, 3, 4, 5};	//map menu entries to tasks
	static int	taskToMenu [6] = {0, 1, 3, 5, 6, 7};	//map tasks to menu entries

h = gameStates.app.bMultiThreaded ? 6 : 1;
for (i = 0; i < h; i++)
	m.AddCheck (GT (1060 + i), gameData.app.bUseMultiThreading [taskToMenu [i]], -1, HT (359 + i));
i = m.Menu (NULL, TXT_MT_MENU_TITLE, NULL, &choice);
h = gameStates.app.bMultiThreaded ? rtTaskCount : rtSound + 1;
for (i = rtSound; i < h; i++)
	gameData.app.bUseMultiThreading [i] = (m [menuToTask [i]].m_value != 0);
if (gameStates.app.bGameRunning) {
	ControlRenderThreads ();
	ControlSoundThread ();
	ControlTranspRenderThread ();
	ControlEffectsThread ();
	}
}
void PartResource::readMaterial(slim::XmlNode* node, void* param0, void* param1)
{
	assert(node != NULL);

	IResource* resource = NULL;
	slim::XmlAttribute* filenameAttr = node->findAttribute(GT("filename"));
	if (filenameAttr == NULL)
	{
		//embedded material data, create resource from factory
		assert(g_resourceFactory != NULL);
		resource = g_resourceFactory->createResource(getResourceUrl(), RES_TYPE_MATERIAL, param0, param1, false);
		MaterialResource* materialResource = static_cast<MaterialResource*>(resource);
		materialResource->importXmlNode(node);
		materialResource->setResourceState(RES_STATE_COMPLETE);
		materialResource->grab();
	}
	else
	{
		resource = grabChildResource(RES_TYPE_MATERIAL, filenameAttr->getValue<const Char*>(), param0, param1);
	}
	m_materialResources.push_back(static_cast<MaterialResource*>(resource));
}
Пример #28
0
int main(int argc, char *argv[]) {
	E_RT_init(argc, argv);
JMP(main);
main: MOVI(0, R999);
JMP(ML1);
RL3: MOVI(2, R901);
MOVI(10000, R777);
MOVS("NAVDEEP", R777);
PRTS(R777);
PRTS("a:b\n");
JMP(L4);
RL5: MOVI(2, R904);
MOVI(10000, R777);
MOVS("NAVDEEP", R777);
PRTS(R777);
PRTS("a OR b:c\n");
JMP(L6);
ML1: R900=MUL(128,0);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(1, R001);
R001=ADD(R900,98);
STI(-1, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
R900=MUL(128,1);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(-1, R001);
R001=ADD(R900,98);
STI(2, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
R900=MUL(128,2);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(-1, R001);
R001=ADD(R900,98);
STI(-1, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
MOVI(2, R902);
MOVI(0, R901);
R903=MUL(128,0);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(1, R001);
R001=ADD(R903,98);
STI(1, R001);
R001=ADD(R903,99);
STI(-1, R001);
R001=ADD(R903,100);
STI(-1, R001);
R903=MUL(128,1);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(-1, R001);
R001=ADD(R903,98);
STI(-1, R001);
R001=ADD(R903,99);
STI(2, R001);
R001=ADD(R903,100);
STI(-1, R001);
R903=MUL(128,2);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(-1, R001);
R001=ADD(R903,98);
STI(-1, R001);
R001=ADD(R903,99);
STI(-1, R001);
R001=ADD(R903,100);
STI(-1, R001);
MOVI(2, R905);
MOVI(0, R904);
L2: IN(R000);
JMPC(GT(0, R000), L0);
JMPC(GT(0, R901), L4);
R001=MUL(128,R901);
R001=ADD(10999,R001);
R001=ADD(R000,R001);
LDI(R001, R002);
JMPC(EQ(R002, R902), RL3);
MOVI(R002, R901);
L4: JMPC(GT(0, R904), L6);
R001=MUL(128,R904);
R001=ADD(11383,R001);
R001=ADD(R000,R001);
LDI(R001, R002);
JMPC(EQ(R002, R905), RL5);
MOVI(R002, R904);
L6: JMP(L2);
L0: MOVI(31000, R000);
MOVS("The End", R000);
PRTS(R000);

	E_RT_exit(); return 0;
}
Пример #29
0
int Proutespline (Pedge_t *edges, int edgen, Ppolyline_t input,
        Ppoint_t *evs, Ppolyline_t *output) {
#if 0
    Ppoint_t p0, p1, p2, p3;
    Ppoint_t *pp;
    Pvector_t v1, v2, v12, v23;
    int ipi, opi;
    int ei, p2ei;
    Pedge_t *e0p, *e1p;
#endif
	Ppoint_t	*inps;
	int			inpn;

	/* unpack into previous format rather than modify legacy code */
	inps = input.ps;
	inpn = input.pn;

#if 0
    if (!(p2es = (p2e_t *) malloc (sizeof (p2e_t) * (p2en = edgen * 2)))) {
        prerror ("cannot malloc p2es");
        abort ();
    }
    for (ei = 0, p2ei = 0; ei < edgen; ei++) {
        if (edges[ei].a.x == edges[ei].b.x && edges[ei].a.y == edges[ei].b.y)
            continue;
        p2es[p2ei].pp = &edges[ei].a;
        p2es[p2ei++].ep = &edges[ei];
        p2es[p2ei].pp = &edges[ei].b;
        p2es[p2ei++].ep = &edges[ei];
    }
    p2en = p2ei;
    qsort (p2es, p2en, sizeof (p2e_t), cmpp2efunc);
    elist = NULL;
    for (p2ei = 0; p2ei < p2en; p2ei += 2) {
        pp = p2es[p2ei].pp;
#if DEBUG >= 1
fprintf (stderr, "point: %d %lf %lf\n", p2ei, pp->x, pp->y);
#endif
        e0p = p2es[p2ei].ep;
        e1p = p2es[p2ei + 1].ep;
        p0 = (&e0p->a == p2es[p2ei].pp) ? e0p->b : e0p->a;
        p1 = (&e0p->a == p2es[p2ei + 1].pp) ? e1p->b : e1p->a;
        if (LT (p0, pp) && LT (p1, pp)) {
            listdelete (e0p), listdelete (e1p);
        } else if (GT (p0, pp) && GT (p1, pp)) {
            listinsert (e0p, *pp), listinsert (e1p, *pp);
        } else {
            if (LT (p0, pp))
                listreplace (e0p, e1p);
            else
                listreplace (e1p, e0p);
        }
    }
#endif
    /* generate the splines */
    evs[0] = normv (evs[0]);
    evs[1] = normv (evs[1]);
    opl = 0;
    growops (4);
    ops[opl++] = inps[0];
    if (reallyroutespline (edges, edgen, inps, inpn, evs[0], evs[1]) == -1)
        return -1;
	output->pn = opl;
	output->ps = ops;

#if 0
    fprintf (stderr, "edge\na\nb\n");
    fprintf (stderr, "points\n%d\n", inpn);
    for (ipi = 0; ipi < inpn; ipi++)
        fprintf (stderr, "%f %f\n", inps[ipi].x, inps[ipi].y);
    fprintf (stderr, "splpoints\n%d\n", opl);
    for (opi = 0; opi < opl; opi++)
        fprintf (stderr, "%f %f\n", ops[opi].x, ops[opi].y);
#endif

    return 0;
}
Пример #30
0
/* really __gl_pqSortInit */
int pqInit( PriorityQ *pq )
{
  PQkey **p, **r, **i, **j, *piv;
  struct { PQkey **p, **r; } Stack[50], *top = Stack;
  unsigned long seed = 2016473283;

  /* Create an array of indirect pointers to the keys, so that we
   * the handles we have returned are still valid.
   */
/*
  pq->order = (PQHeapKey **)memAlloc( (size_t)
                                  (pq->size * sizeof(pq->order[0])) );
*/
  pq->order = (PQHeapKey **)memAlloc( (size_t)
                                  ((pq->size+1) * sizeof(pq->order[0])) );
/* the previous line is a patch to compensate for the fact that IBM */
/* machines return a null on a malloc of zero bytes (unlike SGI),   */
/* so we have to put in this defense to guard against a memory      */
/* fault four lines down. from [email protected].               */
  if (pq->order == NULL) return 0;

  p = pq->order;
  r = p + pq->size - 1;
  for( piv = pq->keys, i = p; i <= r; ++piv, ++i ) {
    *i = piv;
  }

  /* Sort the indirect pointers in descending order,
   * using randomized Quicksort
   */
  top->p = p; top->r = r; ++top;
  while( --top >= Stack ) {
    p = top->p;
    r = top->r;
    while( r > p + 10 ) {
      seed = seed * 1539415821 + 1;
      i = p + seed % (r - p + 1);
      piv = *i;
      *i = *p;
      *p = piv;
      i = p - 1;
      j = r + 1;
      do {
	do { ++i; } while( GT( **i, *piv ));
	do { --j; } while( LT( **j, *piv ));
	Swap( i, j );
      } while( i < j );
      Swap( i, j );	/* Undo last swap */
      if( i - p < r - j ) {
	top->p = j+1; top->r = r; ++top;
	r = i-1;
      } else {
	top->p = p; top->r = i-1; ++top;
	p = j+1;
      }
    }
    /* Insertion sort small lists */
    for( i = p+1; i <= r; ++i ) {
      piv = *i;
      for( j = i; j > p && LT( **(j-1), *piv ); --j ) {
	*j = *(j-1);
      }
      *j = piv;
    }
  }
  pq->max = pq->size;
  pq->initialized = TRUE;
  __gl_pqHeapInit( pq->heap );	/* always succeeds */

#ifndef NDEBUG
  p = pq->order;
  r = p + pq->size - 1;
  for( i = p; i < r; ++i ) {
    assert( LEQ( **(i+1), **i ));
  }
#endif

  return 1;
}