当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.nextPowerOfTwo方法代码示例

本文整理汇总了Java中org.andengine.util.math.MathUtils.nextPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.nextPowerOfTwo方法的具体用法?Java MathUtils.nextPowerOfTwo怎么用?Java MathUtils.nextPowerOfTwo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.andengine.util.math.MathUtils的用法示例。


在下文中一共展示了MathUtils.nextPowerOfTwo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LongMap

import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
/**
 * Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity * loadFactor items
 * before growing the backing table.
 */
public LongMap (int initialCapacity, float loadFactor) {
	if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
	if (capacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
	capacity = MathUtils.nextPowerOfTwo(initialCapacity);

	if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
	this.loadFactor = loadFactor;

	threshold = (int)(capacity * loadFactor);
	mask = capacity - 1;
	hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
	stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) + 1);
	pushIterations = Math.max(Math.min(capacity, 32), (int)Math.sqrt(capacity) / 4);

	keyTable = new long[capacity + stashCapacity];
	valueTable = (V[])new Object[keyTable.length];
}
 
开发者ID:mediamonks,项目名称:tilt-game-android,代码行数:22,代码来源:LongMap.java

示例2: writeTextureToHardware

import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
protected void writeTextureToHardware(final GLState pGLState) throws IOException {
	final IPVRTexturePixelBufferStrategyBufferManager pvrTextureLoadStrategyManager = this.mPVRTexturePixelBufferStrategy.newPVRTexturePixelBufferStrategyManager(this);

	int width = this.getWidth();
	int height = this.getHeight();

	final int dataLength = this.mPVRTextureHeader.getDataLength();

	final int bytesPerPixel = this.mPVRTextureHeader.getBitsPerPixel() / DataConstants.BITS_PER_BYTE;

	/* Adjust unpack alignment. */
	GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

	int currentLevel = 0;
	int currentPixelDataOffset = 0;
	while (currentPixelDataOffset < dataLength) {
		if (currentLevel > 0 && (width != height || MathUtils.nextPowerOfTwo(width) != width)) {
			Debug.w("Mipmap level '" + currentLevel + "' is not squared. Width: '" + width + "', height: '" + height + "'. Texture won't render correctly.");
		}

		final int currentPixelDataSize = height * width * bytesPerPixel;

		/* Load the current level. */
		this.mPVRTexturePixelBufferStrategy.loadPVRTextureData(pvrTextureLoadStrategyManager, width, height, bytesPerPixel, this.mPixelFormat, currentLevel, currentPixelDataOffset, currentPixelDataSize);

		currentPixelDataOffset += currentPixelDataSize;

		/* Prepare next mipmap level. */
		width = Math.max(width / 2, 1);
		height = Math.max(height / 2, 1);

		currentLevel++;
	}

	/* Restore default unpack alignment. */
	GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:39,代码来源:PVRTexture.java


注:本文中的org.andengine.util.math.MathUtils.nextPowerOfTwo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。