Esempio n. 1
0
static void _on_exit(void) {
	s32 c = 0;
	s32 i = 0;
	static bl destroyed = FALSE;

	if(!destroyed) {
		for(i = 0; i < AHAT_COUNT; ++i) {
			if(game()->audio[i]) {
				AGE_FREE(game()->audio[i]);
				game()->audio[i] = 0;
			}
		}
		game()->destroy_score_boards();
		game()->clear_board();

		amb_save_data("data/save.bas");

		destroy_world();

		destroyed = TRUE;
	}

	c = _CrtDumpMemoryLeaks();

	if(0 != c) {
#ifdef _DEBUG
		_asm int 3
#else
		printf("Memory leak detected.\n");
		system("pause");
#endif
	}
Esempio n. 2
0
	void BufferPool::_destroy()
	{
		for (auto &e : _chunks)
		{
			AGE_FREE(e);
		}
	}
Esempio n. 3
0
static void _copy_sound_thread_info(ThreadInfo* _src, ThreadInfo* _tgt) {
	_tgt->context = _src->context;
	_tgt->thread_id = _src->thread_id;
	_tgt->thread_handle = _src->thread_handle;
	_tgt->plock = &_src->lock;
	_tgt->level = _src->level;
	_tgt->loop = _src->loop;
	if(_tgt->sequence) {
		AGE_FREE(_tgt->sequence);
		_tgt->sequence = 0;
	}
	if(_src->sequence) {
		_tgt->sequence = copy_string(_src->sequence);
		AGE_FREE(_src->sequence);
		_src->sequence = 0;
	}
	_tgt->position = _src->position;
	_tgt->time = _src->time;
}
Esempio n. 4
0
void destroy_sound_context(SoundContext* _cnt) {
	ThreadInfo* bgm = 0;
	ThreadInfo* sfx = 0;
	bgm = (ThreadInfo*)_cnt->bgm;
	sfx = (ThreadInfo*)_cnt->sfx;

	stop_sound(_cnt, ST_BGM);
	stop_sound(_cnt, ST_SFX);

	TerminateThread(bgm->thread_handle, 1);
	WaitForSingleObject(bgm->thread_handle, 10);
	CloseHandle(bgm->thread_handle);
	bgm->thread_handle = 0;
	bgm->thread_id = 0;
	TerminateThread(sfx->thread_handle, 1);
	WaitForSingleObject(sfx->thread_handle, 10);
	CloseHandle(sfx->thread_handle);
	sfx->thread_handle = 0;
	sfx->thread_id = 0;

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

	if(bgm->shadow) {
		if(bgm->shadow->sequence) {
			AGE_FREE(bgm->shadow->sequence);
		}
		AGE_FREE(bgm->shadow);
	}
	if(sfx->shadow) {
		if(sfx->shadow->sequence) {
			AGE_FREE(sfx->shadow->sequence);
		}
		AGE_FREE(sfx->shadow);
	}
	if(bgm->sequence) {
		AGE_FREE(bgm->sequence);
	}
	if(sfx->sequence) {
		AGE_FREE(sfx->sequence);
	}
	AGE_FREE(_cnt->bgm);
	AGE_FREE(_cnt->sfx);
	AGE_FREE(_cnt);
}
Esempio n. 5
0
	TextureBuffer::~TextureBuffer()
	{
		if (_textureHandle != -1)
		{
			glDeleteTextures(1, &_textureHandle);
		}
		if (_bufferHandle != -1)
		{
			glDeleteBuffers(1, &_bufferHandle);
		}
		if (_buffer)
		{
			AGE_FREE(_buffer);
		}
	}
Esempio n. 6
0
	bool BufferPool::_dealocateObject(void *addr)
	{
		auto data = (unsigned char *)(addr);
		data -= sizeof(ChunkHeader);

		auto chunk = (Chunk*)(data - (((ChunkHeader*)(data))->index * (sizeof(ChunkHeader) + _objectSize + _objectAlignement)) - _chunkAlignement) - 1;
		++(chunk->emptySlotsNumber);
		chunk->emptySlotsList.push((Link*)(addr));
		++_freeObjectNumber;

		if (chunk->emptySlotsNumber == _objectPerChunk)
		{
			_freeObjectNumber -= _objectPerChunk;
			AGE_FREE(chunk);
			_chunks.remove(chunk);
		}

		return false;
	}
Esempio n. 7
0
void stop_sound(SoundContext* _cnt, SoundType _type) {
	ThreadInfo* thread = 0;
	if(_type == ST_BGM) {
		thread = (ThreadInfo*)(_cnt->bgm);
	} else if(_type == ST_SFX) {
		thread = (ThreadInfo*)(_cnt->sfx);
	} else {
		assert(0 && "Unknown sound type");
	}
	if(thread) {
		if(thread->thread_handle) {
			EnterCriticalSection(&thread->lock); {
				thread->stop = TRUE;
				if(thread->sequence) {
					AGE_FREE(thread->sequence);
				}
				thread->level = 1;
				thread->position = 0;
			} LeaveCriticalSection(&thread->lock);
		}
	}
}
Esempio n. 8
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;
}
Esempio n. 9
0
void operator delete[](void *ptr, const std::nothrow_t&) throw()
{
	return AGE_FREE(ptr);
}
Esempio n. 10
0
void operator delete[](void* ptr) throw()
{
	return AGE_FREE(ptr);
}