Пример #1
0
	bool BufferPool::_allocateChunk()
	{
		auto chunkSize = _getChunkSize();
		auto newChunk = (Chunk*)AGE_MALLOC(chunkSize);
		if (!newChunk)
			return false;
		newChunk->emptySlotsNumber = _objectPerChunk;
		newChunk->emptySlotsList.init();
		_chunks.push_front(newChunk);
		_freeObjectNumber += _objectPerChunk;

		auto data = (unsigned char*)(newChunk + 1);
		data += _chunkAlignement;

		for (std::size_t i = 0; i < _objectPerChunk; ++i)
		{
			((ChunkHeader*)(data))->index = i;

			data += sizeof(ChunkHeader);

			newChunk->emptySlotsList.push((Link*)(data));
			data += _objectSize + _objectAlignement;
		}
		return true;
	}
Пример #2
0
SoundContext* create_sound_context(void) {
	SoundContext* result = AGE_MALLOC(SoundContext);
	ThreadInfo* bgm = 0;
	ThreadInfo* sfx = 0;
	bgm = result->bgm = AGE_MALLOC(ThreadInfo);
	sfx = result->sfx = AGE_MALLOC(ThreadInfo);
	bgm->context = result;
	sfx->context = result;
	bgm->level = 1;
	sfx->level = 1;

	InitializeCriticalSection(&bgm->lock);
	InitializeCriticalSection(&sfx->lock);

	bgm->thread_handle = CreateThread(0, 0, sound_proc, bgm, 0, &bgm->thread_id);
	sfx->thread_handle = CreateThread(0, 0, sound_proc, sfx, 0, &sfx->thread_id);
	SetThreadPriority(bgm->thread_handle, THREAD_PRIORITY_HIGHEST);
	SetThreadPriority(sfx->thread_handle, THREAD_PRIORITY_HIGHEST);
	age_sleep(1);

	return result;
}
Пример #3
0
	bool TextureBuffer::init(GLsizeiptr count, GLenum internal_format /*GL_R32F */, GLsizeiptr size, GLenum usage /* GL_STATIC_DRAW ...*/)
	{
		SCOPE_profile_cpu_function("TextureBuffer");
		AGE_ASSERT(_bufferHandle == -1 && _textureHandle == -1 && _count == 0 && _size == 0 && _buffer == nullptr);
		_count = count;
		_size = size;

		glGenBuffers(1, &_bufferHandle);
		bindBuffer();
		glBufferData(GL_TEXTURE_BUFFER, size * count, nullptr, usage);
		glGenTextures(1, &_textureHandle);
		bind();
		glTexBuffer(GL_TEXTURE_BUFFER, internal_format, _bufferHandle);
		_buffer = (char*)AGE_MALLOC(size * count);
		return true;
	}
Пример #4
0
static s32 WINAPI sound_proc(Ptr param) {
	DWORD result = 0;
	ThreadInfo* _info = (ThreadInfo*)param;
	ThreadInfo* info = 0;
	s32 len = 0;
	s8 last = '\0';
	s8 ch = '\0';
	s8 note = '\0';

	EnterCriticalSection(&_info->lock); {
		info = AGE_MALLOC(ThreadInfo);
		_info->shadow = info;
		_copy_sound_thread_info(_info, info);
		len = info->sequence ? strlen(info->sequence) : 0;
	} LeaveCriticalSection(&_info->lock);

_again:
	EnterCriticalSection(info->plock); {
		if(_info->sequence) {
			_copy_sound_thread_info(_info, info);
			len = info->sequence ? strlen(info->sequence) : 0;
		}
		if(_info->stop) {
			_info->stop = FALSE;
			AGE_FREE(info->sequence);
			info->sequence = 0;
			len = 0;
		}
	} LeaveCriticalSection(info->plock);
	if(info->sequence) {
		while(info->position < len) {
			ch = info->sequence[info->position++];
			if(ch == '>') {
				__PLAY_ONE_NOTE('\0');
				if(info->level < 2) {
					++info->level;
				}
			} else if(ch == '<') {
				__PLAY_ONE_NOTE('\0');
				if(info->level > 0) {
					--info->level;
				}
			} else if(_is_note(ch) || ch == '\0') {
				__PLAY_ONE_NOTE(ch);
			}
			last = ch;
			age_sleep(80);
		}
		if(info->loop) {
			info->position = 0;
			goto _again;
		} else {
			AGE_FREE(info->sequence);
			info->position = 0;
			goto _again;
		}
	} else {
		age_sleep(100);
		goto _again;
	}

	return result;
}
Пример #5
0
void* operator new[](size_t count, const std::nothrow_t&) throw()
{
	return AGE_MALLOC(count);
}
Пример #6
0
void* operator new[](size_t count) throw(std::bad_alloc)
{
	return AGE_MALLOC(count);
}