Beispiel #1
0
void Scene::bindCameraToViewChannel( Camera* camera )
{
	ViewChannel* channel = m_view_channels[ camera->getBoundViewChannelIndex() ];

	Camera* lcamera = channel->getCamera();
	MAGICAL_ASSERT( lcamera != camera, "Invalid!" );
	if( lcamera != nullptr )
	{
		MAGICAL_ASSERT( lcamera->isActive(), "Invalid!" );
		lcamera->setActive( false );
	}

	channel->setCamera( camera );
}
Beispiel #2
0
void Log::write( Level level, const char* text )
{
	if( !text || *text == 0 ) 
		return;

#ifdef MAGICAL_DEBUG
	wstring wtext = System::utf8ToUnicode( text );
	string asnitext = System::unicodeToAnsi( wtext );

	OutputDebugStringW( wtext.c_str() );
	printf( "%s", asnitext.c_str() );
#endif

	switch( level )
	{
		case Debug:
			fprintf( _dfile, "%s", text );
			fflush( _dfile );
			break;
		case Warning:
			fprintf( _wfile, "%s", text );
			fflush( _wfile );
			break;
		case Error:
			fprintf( _efile, "%s", text );
			fflush( _efile );
			break;
		default:
			MAGICAL_ASSERT( false, "Invalid!" );
			break;
	}
}
Beispiel #3
0
void Scene::unlink( Object* child )
{
	switch( child->m_feature )
	{
	case Object::Feature:
		break;
	case Entity::Feature:
		removeEntity( (Entity*)child );
		break;
	case Camera::Feature:
		removeEntity( (Entity*)child );
		removeCamera( (Camera*)child );
		break;
	/*case Element::Light:
		break;*/
	default:
		MAGICAL_ASSERT( false, "Invalid!" );
		break;
	}

	for( auto itr : child->m_children )
	{
		unlink( itr );
	}
}
void Renderer::addCommand( RenderCommand* command )
{
	switch( command->getFeature() )
	{
	case BatchCommand::Feature:
		{
			BatchCommand* batch_command = (BatchCommand*) command;
			s_batch_command_queue.push_back( batch_command );

			Batch* batch = batch_command->getBatch();
			for( auto& arr : batch->m_vertex_arrays )
			{
				if( !arr ) continue;

				VertexArray* dst_arr = s_vertex_arrays[ arr->vertex_index ];
				if( dst_arr == nullptr )
				{
					dst_arr = new VertexArray();
					dst_arr->data = (char*) ::malloc( VertexArrayDefaultSize );
					dst_arr->cursor = 0;
					dst_arr->capacity = VertexArrayDefaultSize;
					dst_arr->sizeof_vertex = arr->sizeof_vertex;
					dst_arr->vertex_index = arr->vertex_index;

					s_vertex_arrays[ arr->vertex_index ] = dst_arr;
				}

				MAGICAL_ASSERT( arr->cursor == arr->capacity, "Invalid! not finished." );
				MAGICAL_ASSERT( arr->sizeof_vertex == dst_arr->sizeof_vertex, "Invalid! size not equals" );

				while( arr->cursor + dst_arr->cursor > dst_arr->capacity )
				{
					dst_arr->capacity *= 2;
					dst_arr->data = (char*) ::realloc( dst_arr->data, dst_arr->capacity );
					MAGICAL_ASSERT( dst_arr->data, "Invalid realloc!" );
				}

				::memcpy( dst_arr->data + dst_arr->cursor, arr->data, arr->cursor );
				dst_arr->cursor += arr->cursor;
			}
		}
		break;
	default:
		MAGICAL_ASSERT( false, "Invalid!" );
		break;
	}
}
Beispiel #5
0
void Scene::removeEntity( Entity* object )
{
	auto itr = m_entities.find( object );
	MAGICAL_ASSERT( itr != m_entities.end(), "Invalid! isn't exists in scene" );

	m_entities.erase( itr );
	object->release();
}
Beispiel #6
0
void Scene::addEntity( Entity* object )
{
	auto itr = m_entities.find( object );
	MAGICAL_ASSERT( itr == m_entities.end(), "Invalid! already in scene" );

	object->retain();
	m_entities.insert( object );
}
Beispiel #7
0
void Scene::unbindCameraFromViewChannel( Camera* camera )
{
	ViewChannel* channel = m_view_channels[ camera->getBoundViewChannelIndex() ];

	Camera* lcamera = channel->getCamera();
	MAGICAL_ASSERT( lcamera == camera, "Invalid!" );

	channel->removeCamera();
}
Beispiel #8
0
void Scene::removeCamera( Camera* camera )
{
	auto itr = m_cameras.find( camera );
	MAGICAL_ASSERT( itr != m_cameras.end(), "Invalid! isn't exists in scene" );

	m_cameras.erase( itr );
	camera->release();

	if( camera->isActive() )
	{
		unbindCameraFromViewChannel( camera );
	}
}
Beispiel #9
0
void Scene::addCamera( Camera* camera )
{
	auto itr = m_cameras.find( camera );
	MAGICAL_ASSERT( itr == m_cameras.end(), "Invalid! already in scene" );

	camera->retain();
	m_cameras.insert( camera );

	if( camera->isActive() )
	{
		bindCameraToViewChannel( camera );
	}

	if( camera->isAutoAspectRatio() )
	{
		const Size& size = Application::getWindowSize();
		camera->setAspectRatio( size.w / size.h );
	}
}
Beispiel #10
0
ViewChannel* Scene::getViewChannel( int index ) const
{
	MAGICAL_ASSERT( 0 <= index && index <= ViewChannel::Count, "Invalid Index!" );

	return m_view_channels[ index ];
}
Beispiel #11
0
Ptr<Scene> Scene::create( void )
{
	Scene* ret = new Scene();
	MAGICAL_ASSERT( ret, "new Scene() failed" );
	return Ptr<Scene>( Ptrctor<Scene>( ret ) );
}