コード例 #1
0
ファイル: utils.c プロジェクト: DINKIN/tuo
/**
 * Convert milliseconds to a character string
 * @arg msec		number of milliseconds
 * @arg buf		destination buffer
 * @arg len		buffer length
 *
 * Converts milliseconds to a character string split up in days, hours,
 * minutes, seconds, and milliseconds and stores it in the specified
 * destination buffer.
 *
 * @return The destination buffer.
 */
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
{
	int i, split[5];
	char *units[] = {"d", "h", "m", "s", "msec"};

#define _SPLIT(idx, unit) if ((split[idx] = msec / unit) > 0) msec %= unit
	_SPLIT(0, 86400000);	/* days */
	_SPLIT(1, 3600000);	/* hours */
	_SPLIT(2, 60000);	/* minutes */
	_SPLIT(3, 1000);	/* seconds */
#undef  _SPLIT
	split[4] = msec;

	memset(buf, 0, len);

	for (i = 0; i < ARRAY_SIZE(split); i++) {
		if (split[i] > 0) {
			char t[64];
			snprintf(t, sizeof(t), "%s%d%s",
				 strlen(buf) ? " " : "", split[i], units[i]);
			strncat(buf, t, len - strlen(buf) - 1);
		}
	}

	return buf;
}
コード例 #2
0
ファイル: utils.c プロジェクト: FIT-CVUT/clondike
/**
 * Convert milliseconds to a character string
 * @arg msec		number of milliseconds
 * @arg buf		destination buffer
 * @arg len		buffer length
 *
 * Converts milliseconds to a character string split up in days, hours,
 * minutes, seconds, and milliseconds and stores it in the specified
 * destination buffer.
 *
 * @return The destination buffer.
 */
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
{
	uint64_t split[5];
	size_t i;
	static const char *units[5] = {"d", "h", "m", "s", "msec"};
	char * const buf_orig = buf;

#define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit
	_SPLIT(0, 86400000);	/* days */
	_SPLIT(1, 3600000);	/* hours */
	_SPLIT(2, 60000);	/* minutes */
	_SPLIT(3, 1000);	/* seconds */
#undef  _SPLIT
	split[4] = msec;

	if (msec == 0) {
		snprintf(buf, len, "0msec");
		return buf_orig;
	}

	for (i = 0; i < ARRAY_SIZE(split) && len; i++) {
		int l;
		if (split[i] == 0)
			continue;
		l = snprintf(buf, len, "%s%" PRIu64 "%s",
			(buf==buf_orig) ? "" : " ", split[i], units[i]);
		buf += l;
		len -= l;
	}

	return buf_orig;
}
コード例 #3
0
ファイル: geometry.cpp プロジェクト: AwsomeGameEngine/godot
static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,const Vector3& voxelsize,const Face3& p_face) {

	AABB aabb( Vector3(x,y,z),Vector3(len_x,len_y,len_z));
	aabb.pos=aabb.pos*voxelsize;
	aabb.size=aabb.size*voxelsize;

	if (!p_face.intersects_aabb(aabb))
		return;

	if (len_x==1 && len_y==1 && len_z==1) {

		p_cell_status[x][y][z]=_CELL_SOLID;
		return;
	}
	
	
 
	int div_x=len_x>1?2:1;
	int div_y=len_y>1?2:1;
	int div_z=len_z>1?2:1;

#define _SPLIT(m_i,m_div,m_v,m_len_v,m_new_v,m_new_len_v)\
	if (m_div==1) {\
		m_new_v=m_v;\
		m_new_len_v=1;	\
	} else if (m_i==0) {\
		m_new_v=m_v;\
		m_new_len_v=m_len_v/2;\
	} else {\
		m_new_v=m_v+m_len_v/2;\
		m_new_len_v=m_len_v-m_len_v/2;		\
	}

	int new_x;
	int new_len_x;
	int new_y;
	int new_len_y;
	int new_z;
	int new_len_z;

	for (int i=0;i<div_x;i++) {
		
		
		_SPLIT(i,div_x,x,len_x,new_x,new_len_x);
				
		for (int j=0;j<div_y;j++) {

			_SPLIT(j,div_y,y,len_y,new_y,new_len_y);
			
			for (int k=0;k<div_z;k++) {

				_SPLIT(k,div_z,z,len_z,new_z,new_len_z);

				_plot_face(p_cell_status,new_x,new_y,new_z,new_len_x,new_len_y,new_len_z,voxelsize,p_face);
			}
		}
	}
}