コード例 #1
0
	void loadProgram(Program &p, const std::string& name) {

		//Initializes a Program object
		p.create();

		//Gets the path to the vertex shader (ending in ".vsh")
		string sv = rh.pathToResource(name, "vsh");
		// cout << "path of vertex shader is: " << sv << endl;

		//Compiles the vertex shader and attaches it to our Program object
		p.attach(rh.contentsOfFile(sv), GL_VERTEX_SHADER);

		//Binds attribute variables to a particular ID
		glBindAttribLocation(p.id(), posLoc, "vertexPosition");
		glBindAttribLocation(p.id(), colLoc, "vertexColor");


		//Gets the path to the fragment shader (ending in ".fsh")
		string sp = rh.pathToResource(name, "fsh");
		// cout << "path of vertex shader is: " << sp << endl;

		//Compiles the fragment shader and attaches it to our Program object
		p.attach(rh.contentsOfFile(sp), GL_FRAGMENT_SHADER);

		//Links the Program object to the GPU so that it can be activated when needed
		p.link();
	}
コード例 #2
0
ファイル: spritemodel.cpp プロジェクト: Tarjei400/TibiaEditor
QVariant SpriteModel::data( const QModelIndex& index, int role ) const
{
    if ( !index.isValid() )
        return QVariant();

    if( role == Qt::DecorationRole || role == Qt::DisplayRole || role == Qt::UserRole ) {
        SharedResource resource = m_resourceList.value( index.row() );
        if( role == Qt::DecorationRole ) {
            TibiaSprite sprite = g_resourceHandler.getSpriteByResource( resource );
            if( sprite.image.height() > 128 || sprite.image.width() > 128 )
                return QVariant( sprite.image.scaled( 128, 128, Qt::KeepAspectRatio ) );

            return QVariant( sprite.image );
        } else if( role == Qt::DisplayRole ) {
            if( resource ) {
                quint32 realId = g_resourceHandler.getDisplayIdentifier( resource );
                if( realId == 0xFFFF ) {
                    if( ResourceFile *resourceFile = dynamic_cast<ResourceFile *>( resource->getFile() ) )
                        return QVariant( resourceFile->getSource() );
                }
                return QVariant( realId );
            }
        } else if( role == Qt::UserRole ) {
            return QVariant::fromValue( resource );
        }
    }

    return QVariant();
}
コード例 #3
0
void President::initializeImages(std::string &path)
{
	ResourceHandler* handler = ResourceHandler::getInstance();
	mTexture = &handler->getTexture(path);
	mPortrait.setTexture(*mTexture);
	mClickedPortraitTexture = &handler->getTexture("PickedLeaders/president-" + mName + "-picked");
}
コード例 #4
0
ファイル: Task.cpp プロジェクト: alex-games/a1
	void* Task::operator new( size_t size )
	{
		ResourceHandler* pRH = ResourceHandler::GetInst();
		void* p = pRH->AllocMemory();
		//std::cout << "( Alloc ) Rest blocks : " << pRH->m_Alloc.GetNumRestBlocks() << " Address : " << p;
		//std::cout << " Size : " << size << std::endl;
		return p;
	}
コード例 #5
0
ファイル: component.cpp プロジェクト: S-A-L-S-A/salsa
void Component::declareResourceAsNull(QString name)
{
	ConfigurationManagerLocker locker(m_confManager);

	ResourceHandler* h = getResourceHandlerForOurResource(name);

	// Now setting the resource to nullptr. If this throws an exception we could have simply created a non-existing
	// resource above that doesn't modify the external behaviour of this and other classes (so we can say
	// that this function is strongly exception-safe)
	h->declareAsNull();
}
コード例 #6
0
ファイル: Button.cpp プロジェクト: Arqu3/Spelprojekt-1
Button::Button(ResourceHandler &handler, sf::RectangleShape &rect, std::string textureName, std::string hoverName):
mTextureName(textureName),
mRect(rect),
mHoverRect(rect),
mMoveToPosition(rect.getPosition().x, rect.getPosition().y),
mDirection(0, 0),
mIsOnPosition(true),
mSpeed(100),
mMode(RectangleShape)
{
	mRect.setTexture(handler.getTexture(textureName));
	mHoverRect.setTexture(handler.getTexture(hoverName));
}
コード例 #7
0
ファイル: Resource.cpp プロジェクト: ByeDream/pixellight
/**
*  @brief
*    Adds a resource handler
*/
bool Resource::AddHandler(ResourceHandler &cHandler)
{
	// Is this handler already registered?
	if (!m_lstHandlers.IsElement(&cHandler)) {
		if (m_lstHandlers.Add(&cHandler)) {
			if (cHandler.GetResource() != this)
				cHandler.SetResource(this);
		} else {
			// Error!
			return false;
		}
	}

	// Done
	return true;
}
コード例 #8
0
ファイル: component.cpp プロジェクト: S-A-L-S-A/salsa
void Component::addNotifiedResource(QString name, Component* owner)
{
	ConfigurationManagerLocker locker(m_confManager);

	// If in configuration phase, we only record the request
	if (inConfigurationPhase()) {
		recordRequestOfResourceChangeNotification(name, owner);

		return;
	}

	// Getting the resource handler. It will be created if doesn't exists
	ResourceHandler* h = owner->getResourceHandlerForOurResource(name);

	h->addNotifee(this);
}
コード例 #9
0
  void onCreate() {

    loadProgram(program, "resources/billboard");
    rh.loadTexture(texture, "resources/eye.png");

    camera = Camera(glm::radians(60.0), (float)width/(float)height, 0.01, 100.0).translate(vec3(0.0,0.0,-2.0));


    Utils::randomSeed();
    MeshData points;

    for (int i = 0; i < 1; i++) {
      MeshUtils::addPoint(points, Utils::randomVec3(-1.0,1.0), Utils::randomVec3(0.0,1.0));

    }

    mb1.init(points, posLoc, -1, texCoordLoc, -1);

    proj = glm::perspective(glm::radians(45.0), 1.0, 0.1, 100.0);
    view = glm::lookAt(vec3(0,0,-2), vec3(0,0,0), vec3(0,1,0) );
    model = glm::mat4();

    glDisable(GL_DEPTH_TEST);


    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glViewport(0, 0, width, height);
    glClearColor(0.3,0.3,0.3,1.0);
  }
コード例 #10
0
bool PictureFile::createNew( void )
{
    if( !m_loaded ) {
        m_count = 1;
        TibiaSprite picture;
        picture.id = 1;
        picture.setDummy( false );
        SharedResource newResource = g_resourceHandler.createLocalResource( RESOURCE_TYPE_PICTURE, 0, picture );
        ResourceList resources;
        resources.push_back( newResource );
        g_resourceHandler.addLocalResources( RESOURCE_TYPE_PICTURE, 0, resources );
        m_loaded = true;
        return true;
    }

    return false;
}
コード例 #11
0
ファイル: component.cpp プロジェクト: S-A-L-S-A/salsa
void Component::removeNotifiedResource(QString name, Component* owner)
{
	ConfigurationManagerLocker locker(m_confManager);

	// If in configuration phase, we remove the recorded notification if it exists
	if (inConfigurationPhase()) {
		removeRequestOfResourceChangeNotification(name, owner);

		return;
	}

	// Getting the resource handler. It will be created if doesn't exists
	ResourceHandler* h = getResourceHandlerWithOwner(name, owner);

	if (h != nullptr) {
		h->removeNotifee(this);
	}
}
コード例 #12
0
ファイル: Button.cpp プロジェクト: Arqu3/Spelprojekt-1
//Creates a sprite representing a button
Button::Button(ResourceHandler &handler, sf::Vector2f &pos, string textureName):
mTextureName(textureName),
mMoveToPosition(pos),
mDirection(0, 0),
mIsOnPosition(true),
mSpeed(100),
mMode(Texture)
{
	mSprite.setTexture(*handler.getTexture(textureName));
	mSprite.setPosition(pos);
}
コード例 #13
0
ファイル: Button.cpp プロジェクト: Arqu3/Spelprojekt-1
//Creates a sprite representing a button
Button::Button(ResourceHandler &handler, float x, float y, string textureName):
mTextureName(textureName),
mMoveToPosition(x, y),
mDirection(0, 0),
mIsOnPosition(true),
mSpeed(100),
mMode(Texture)
{
	mSprite.setTexture(*handler.getTexture(textureName));
	mSprite.setPosition(x, y);
}
コード例 #14
0
ファイル: Loading.cpp プロジェクト: alex-games/a1
	int Loading::ThreadFunc()
	{
		while( m_LoadingState != LOADING_STATE_TERM ){
			if(	m_LoadingState == LOADING_STATE_STOP ||
				m_LoadingState == LOADING_STATE_COMP ||
				m_LoadingState == LOADING_STATE_IDLE ){
				Sleep( 1 );
			}
			else if( m_LoadingState == LOADING_STATE_LOAD ){
				ResourceHandler* p = ResourceHandler::GetInst();
				//p->m_pCompiler->Compile( m_Scene );
				p->m_pCompiler->Load( p->m_Archiver, m_Scene );
				p->SetupHandle();
				*m_ppScriptCmd = p->m_pCompiler->GetStageScript();
				m_pStageVCPU->Init( *m_ppScriptCmd, m_pStageInfo );
				m_LoadingState = LOADING_STATE_COMP;
			}
		}

		return 0;
	}
コード例 #15
0
ファイル: RiddleSpider.cpp プロジェクト: Arqu3/Spelprojekt-1
RiddleSpider::RiddleSpider(ResourceHandler &handler, sf::Vector2f position) :
mPosition(position),
mState(INACTIVE),
mMoveTimer(0),
mActiveTimer(0),
mTextCounter(-1),
mTexts()
{
	mSprite.setTexture(*handler.getTexture("RiddleSpider.png"));
	mSprite.setPosition(position);
	mFont.loadFromFile("Resources/Fonts/Lora-Regular.ttf");
}
コード例 #16
0
ファイル: Resource.cpp プロジェクト: ByeDream/pixellight
/**
*  @brief
*    Removes a resource handler
*/
bool Resource::RemoveHandler(ResourceHandler &cHandler)
{
	if (m_lstHandlers.Remove(&cHandler)) {
		cHandler.SetResource();

		// Done
		return true;
	} else {
		// Error!
		return false;
	}
}
コード例 #17
0
  void loadProgram(Program &p, const std::string& name) {

    //can't link shaders unless a vao is bound...
    //bindDefaultVAO();

    p.create();

    string sv = rh.pathToResource(name, "vsh");

    p.attach(rh.contentsOfFile(sv), GL_VERTEX_SHADER);

    glBindAttribLocation(p.id(), posLoc, "vertexPosition");
    glBindAttribLocation(p.id(), texCoordLoc, "vertexTexCoord");


    string sg = rh.pathToResource(name, "gsh");
    cout << "path of vertex shader is: " << sg << endl;

    p.attach(rh.contentsOfFile(sg), GL_GEOMETRY_SHADER);

    string sp = rh.pathToResource(name, "fsh");

    p.attach(rh.contentsOfFile(sp), GL_FRAGMENT_SHADER);

    p.link();
  }
コード例 #18
0
  void onCreate() {
    
    rh.loadTexture(texture, "resources/hubble.jpg");
    texture.minFilter(GL_NEAREST);
    texture.maxFilter(GL_NEAREST);
    
    rh.loadProgram(textureProgram, "resources/texture", posLoc, -1, texCoordLoc, -1);
    rh.loadProgram(phongProgram, "resources/phong", posLoc, normalLoc, texCoordLoc, -1);
    rh.loadProgram(programColor, "resources/color", posLoc, normalLoc, -1, colorLoc);
    
    MeshData md1;
    addCube(md1, true, 0.95);
    
    MeshData md2;
    addCube(md2, true, 0.5);
    
    MeshData md3;
    addCube(md3, 0.33); //this version makes normals, texcoords, and colors each side with a different default color
    
    cubeMeshBuffer1.init(md1, posLoc, normalLoc, texCoordLoc, -1);
    cubeMeshBuffer2.init(md2, posLoc, normalLoc, texCoordLoc, -1);
    
    cubeMeshBuffer3.init(md3, posLoc, normalLoc, -1, colorLoc);
    
    
    fbo.create(32, 32);

millisToNano(1000);
    
    rotateBehavior = Behavior(now()).delay(1000).length(5000).range(vec3(3.14, 3.14, 3.14)).reversing(true).repeats(-1).sine();
    
    
    proj = glm::perspective(45.0, 1.0, 0.1, 100.0);
    view = glm::lookAt(vec3(0.0,0.0,5), vec3(0,0,0), vec3(0,1,0) );
    model = glm::mat4();
    
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, width, height);
  }
コード例 #19
0
  virtual void onCreate() {

    rh.loadProgram(planetProgram, "week5c_ImageDistortation/planet", 0, -1, -1, -1);

    mb.init(MeshUtils::makeClipRectangle(), 0, -1, -1, -1);

    rh.loadCubeMapTexture(cubemap[0], 2048, 2048,
                          "week5c_ImageDistortation/f_negz.jpg",
                          "week5c_ImageDistortation/f_posz.jpg",
                          "week5c_ImageDistortation/f_posy.jpg",
                          "week5c_ImageDistortation/f_negy.jpg",
                          "week5c_ImageDistortation/f_negx.jpg",
                          "week5c_ImageDistortation/f_posx.jpg");

    rh.loadCubeMapTexture(cubemap[1], 2048, 2048,
                          "week5c_ImageDistortation/b_negz.jpg",
                          "week5c_ImageDistortation/b_posz.jpg",
                          "week5c_ImageDistortation/b_posy.jpg",
                          "week5c_ImageDistortation/b_negy.jpg",
                          "week5c_ImageDistortation/b_negx.jpg",
                          "week5c_ImageDistortation/b_posx.jpg");
  }
コード例 #20
0
/// Search for the resource handler for the specified type.
///
/// @param[in] pType  Resource type.
///
/// @return  Resource handler for the given type if found, null if no resource handler was found.
ResourceHandler* ResourceHandler::FindResourceHandlerForType( const GameObjectType* pType )
{
    HELIUM_ASSERT( pType );

    const GameObjectType* pResourceHandlerType = GetStaticType();
    HELIUM_ASSERT( pResourceHandlerType );

    GameObjectType::ConstIterator typeEnd = GameObjectType::GetTypeEnd();
    for( GameObjectType::ConstIterator typeIterator = GameObjectType::GetTypeBegin(); typeIterator != typeEnd; ++typeIterator )
    {
        const GameObjectType& rType = *typeIterator;
        if( &rType != pResourceHandlerType && rType.GetClass()->IsType( pResourceHandlerType->GetClass() ) )
        {
            ResourceHandler* pHandler = Reflect::AssertCast< ResourceHandler >( rType.GetTemplate() );
            HELIUM_ASSERT( pHandler );
            if( pHandler->GetResourceType() == pType )
            {
                return pHandler;
            }
        }
    }

    return NULL;
}
コード例 #21
0
bool ExternalFile::readItem( QDataStream& in, ItemData& itemData, DatFormat *datFormat, TibiaModule *tibiaModule, qint32 index, quint32& address, QString& error )
{
    QIODevice *device = in.device();
    if( !device )
        return false;

    quint8 type = 0;
    in >> type;

    if( type != ITEM_TYPE_ITEM && type != ITEM_TYPE_OUTFIT && type != ITEM_TYPE_EFFECT && type != ITEM_TYPE_PROJECTILE ) {
        error = QObject::tr( "Unknown Item type" );
        return false;
    }

    ItemData d_itemData;
    if( datFormat ) {
        if( !ItemFile::loadItem( datFormat, in, d_itemData, error ) )
            return false;
    }

    d_itemData.parent = ITEM_PARENT_EXTERNAL;
    d_itemData.type = type;

    address = 0;

    if( !device->atEnd() ) {
        quint32 spriteCount = 0, now = 0, offset = 0;
        in >> spriteCount;
        address = device->pos();
        now = device->pos();
        for( quint32 i = 0; i < spriteCount; i++ ) {
            device->seek( now );
            in >> offset;
            if ( offset == 0x00000000 || offset > device->size() ) { // Direct to an image that doesnt exist or out of boundaries
                now += sizeof( quint32 );
                continue;
            }

            QMutex mutex;
            mutex.lock();
            SharedResource *resource = &g_resourceHandler.addResource(RESOURCE_TYPE_SPRITE, index, i, tibiaModule);
            d_itemData.setSpriteResource(i, *resource);
            mutex.unlock();
            now += sizeof( quint32 );
        }
    }
コード例 #22
0
  virtual void onCreate() {

    rh.loadProgram(program, "week5a_NoiseDisplacement/noise", posLoc, normalLoc, -1, -1);

    int res = 250;
    addSphere(mesh, 1.0, res, res);

    mb.init(mesh, posLoc, normalLoc, -1, -1);

    proj = glm::perspective(glm::radians(60.0), 1.0, 0.1, 1000.0);
    view = glm::lookAt(vec3(0.0,0.0, -4.0), vec3(0,0,0), vec3(0,1,0) );
    model = glm::mat4();

    glEnable(GL_DEPTH_TEST);
    glClearColor(1.0,1.0,1.0,1.0);

    rotateBehavior = Behavior(now()).delay(0).length(10000).range(M_PI * 2.0).looping(true).repeats(-1);
  }
コード例 #23
0
ファイル: Cursor.cpp プロジェクト: Arqu3/Spelprojekt-1
Cursor::Cursor(ResourceHandler &handler) :
mode(NORMAL)
{
	mNormalMouse = *handler.getTexture("mousecursor.png");
	mEyeMouse = *handler.getTexture("eyecursor.png");
	mOpenHandMouse = *handler.getTexture("openhand.png");
	mClosedHandMouse = *handler.getTexture("closedhand.png");
	mSpeechMouse = *handler.getTexture("speechbubble.png");
	mSceneChangeMouse = *handler.getTexture("scenechangecursor.png");

	mMouseCursor.setTexture(mNormalMouse);
	mMouseCursor.setScale(sf::Vector2f(0.2f, 0.2f));
}
コード例 #24
0
ファイル: LoosePackageLoader.cpp プロジェクト: James-Z/Helium
/// Update during the package preload process.
void LoosePackageLoader::TickPreload()
{
	HELIUM_ASSERT( m_startPreloadCounter != 0 );
	HELIUM_ASSERT( m_preloadedCounter == 0 );

	AsyncLoader& rAsyncLoader = AsyncLoader::GetStaticInstance();

	bool bAllFileRequestsDone = true;

	// Walk through every load request
	for (size_t i = 0; i < m_fileReadRequests.GetSize();)
	{
		FileReadRequest &rRequest = m_fileReadRequests[i];
		HELIUM_ASSERT(rRequest.asyncLoadId);
		HELIUM_ASSERT(rRequest.pLoadBuffer);

		size_t bytes_read = 0;
		if (!rAsyncLoader.TrySyncRequest(rRequest.asyncLoadId, bytes_read))
		{
			// Havn't finished reading yet, move on to next entry
			bAllFileRequestsDone = false;
			++i;
			continue;
		}

		HELIUM_ASSERT(bytes_read == rRequest.expectedSize);
		if( IsInvalid( bytes_read ) )
		{
			HELIUM_TRACE(
				TraceLevels::Error,
				TXT( "LoosePackageLoader: Failed to read the contents of async load request \"%d\".\n" ),
				rRequest.asyncLoadId );
		}
		else if( bytes_read != rRequest.expectedSize)
		{
			HELIUM_TRACE(
				TraceLevels::Warning,
				( TXT( "LoosePackageLoader: Attempted to read %" ) PRIuSZ TXT( " bytes from package file \"%s\", " )
				TXT( "but only %" ) PRIuSZ TXT( " bytes were read.\n" ) ),
				rRequest.expectedSize,
				bytes_read );
		}
		else
		{
			HELIUM_ASSERT( rRequest.expectedSize < ~static_cast<size_t>( 0 ) );

			// the name is deduced from the file name (bad idea to store it in the file)
			Name name ( m_fileReadRequests[i].filePath.Basename().c_str() );

			// read some preliminary data from the json
			struct PreliminaryObjectHandler : rapidjson::BaseReaderHandler<>
			{
				Helium::Name typeName;
				Helium::String templatePath;
				bool templateIsNext;

				PreliminaryObjectHandler()
					: typeName( ENullName () )
					, templatePath( "" )
				{
					templateIsNext = false;
				}

				void String(const Ch* chars, rapidjson::SizeType length, bool copy)
				{
					if ( typeName.IsEmpty() )
					{
						typeName.Set( Helium::String ( chars, length ) );
						return;
					}

					if ( templatePath.IsEmpty() )
					{
						Helium::String str ( chars, length ); 

						if ( templateIsNext )
						{
							templatePath = str;
							templateIsNext = false;
							return;
						}
						else
						{
							if ( str == "m_spTemplate" )
							{
								templateIsNext = true;
								return;
							}
						}
					}
				}

				void StartObject() { Default(); }
				void EndObject( rapidjson::SizeType ) { Default(); }

			} handler;

			// non destructive in-place stream helper
			rapidjson::StringStream stream ( static_cast< char* >( rRequest.pLoadBuffer ) );

			// the main reader object
			rapidjson::Reader reader;
			if ( reader.Parse< rapidjson::kParseDefaultFlags >( stream, handler ) )
			{
				SerializedObjectData* pObjectData = m_objects.New();
				HELIUM_ASSERT( pObjectData );
				HELIUM_VERIFY( pObjectData->objectPath.Set( name, false, m_packagePath ) );
				pObjectData->templatePath.Set( handler.templatePath );
				pObjectData->typeName = handler.typeName;
				pObjectData->filePath = rRequest.filePath;
				pObjectData->fileTimeStamp = rRequest.fileTimestamp;
				pObjectData->bMetadataGood = true;

				HELIUM_TRACE(
					TraceLevels::Debug,
					TXT( "LoosePackageLoader: Success reading preliminary data for object '%s' from file '%s'.\n" ),
					*name,
					rRequest.filePath.c_str() );
			}
			else
			{
				HELIUM_TRACE(
					TraceLevels::Error,
					TXT( "LoosePackageLoader: Failure reading preliminary data for object '%s' from file '%s': %s\n" ),
					*name,
					rRequest.filePath.c_str(),
					reader.GetParseError() );
			}
		}

		// We're finished with this load, so deallocate memory and get rid of the request
		DefaultAllocator().Free( rRequest.pLoadBuffer );
		rRequest.pLoadBuffer = NULL;
		SetInvalid(rRequest.asyncLoadId);
		m_fileReadRequests.RemoveSwap(i);
	}

	// Wait for the parent package to finish loading.
	AssetPtr spParentPackage;
	if( IsValid( m_parentPackageLoadId ) )
	{
		AssetLoader* pAssetLoader = AssetLoader::GetStaticInstance();
		HELIUM_ASSERT( pAssetLoader );
		if( !pAssetLoader->TryFinishLoad( m_parentPackageLoadId, spParentPackage ) )
		{
			return;
		}

		SetInvalid( m_parentPackageLoadId );

		// Package loading should not fail.  If it does, this is a sign of a potentially serious issue.
		HELIUM_ASSERT( spParentPackage );
	}

	// Everything beyond this point "finalizes" the package preload, so stop here if we aren't ready to go
	if (!bAllFileRequestsDone)
	{
		return;
	}

	// Create the package object if it does not yet exist.
	Package* pPackage = m_spPackage;
	if( !pPackage )
	{
		HELIUM_ASSERT( spParentPackage ? !m_packagePath.GetParent().IsEmpty() : m_packagePath.GetParent().IsEmpty() );
		HELIUM_VERIFY( Asset::Create< Package >( m_spPackage, m_packagePath.GetName(), spParentPackage ) );
		pPackage = m_spPackage;
		HELIUM_ASSERT( pPackage );
		pPackage->SetLoader( this );
	}

	HELIUM_ASSERT( pPackage->GetLoader() == this );

	FilePath packageDirectoryPath;

	if ( !FileLocations::GetDataDirectory( packageDirectoryPath ) )
	{
		HELIUM_TRACE( TraceLevels::Error, TXT( "LoosePackageLoader::TickPreload(): Could not get data directory.\n" ) );
		return;
	}

	packageDirectoryPath += m_packagePath.ToFilePathString().GetData();
	packageDirectoryPath += TXT("/");

	DirectoryIterator packageDirectory( packageDirectoryPath );
	for( ; !packageDirectory.IsDone(); packageDirectory.Next() )
	{
		const DirectoryIteratorItem& item = packageDirectory.GetItem();

		if ( !item.m_Path.IsFile() )
		{
			continue;
		}

		Name objectName( item.m_Path.Filename().c_str() );
		String objectNameString( item.m_Path.Filename().c_str() );

		size_t objectIndex = FindObjectByName( objectName );

		if( objectIndex != Invalid< size_t >() )
		{
			m_objects[ objectIndex ].fileTimeStamp = Helium::Max( 
				m_objects[ objectIndex ].fileTimeStamp, 
				static_cast< int64_t >( packageDirectory.GetItem().m_ModTime ) );

			continue;
		}

		// Check the extension to see if the file is supported by one of the resource handlers.
		ResourceHandler* pBestHandler = ResourceHandler::GetBestResourceHandlerForFile( objectNameString );

		if( pBestHandler )
		{
			// File extension matches a supported source asset type, so add it to the object list.
			const AssetType* pResourceType = pBestHandler->GetResourceType();
			HELIUM_ASSERT( pResourceType );

			HELIUM_TRACE(
				TraceLevels::Debug,
				( TXT( "LoosePackageLoader: Registered source asset file \"%s\" as as instance of resource " )
				TXT( "type \"%s\" in package \"%s\".\n" ) ),
				*objectNameString,
				*pResourceType->GetName(),
				*m_packagePath.ToString() );

			SerializedObjectData* pObjectData = m_objects.New();
			HELIUM_ASSERT( pObjectData );
			HELIUM_VERIFY( pObjectData->objectPath.Set( objectName, false, m_packagePath ) );
			pObjectData->typeName = pResourceType->GetName();
			pObjectData->templatePath.Clear();
			pObjectData->filePath.Clear();
			pObjectData->fileTimeStamp = packageDirectory.GetItem().m_ModTime;
			pObjectData->bMetadataGood = true;
		}
		else
		{
			HELIUM_TRACE(
				TraceLevels::Debug,
				( TXT( "LoosePackageLoader: Did not recognize \"%s\" as as instance of resource " )
				TXT( "in package \"%s\".\n" ) ),
				*objectNameString,
				*m_packagePath.ToString() );
			
			for ( AssetType::ConstIterator iter = AssetType::GetTypeBegin();
				iter != AssetType::GetTypeEnd(); ++iter)
			{
				HELIUM_TRACE(
					TraceLevels::Info,
					TXT( " - %s\n" ),
					*iter->GetName() );
			}
		}
	}

	// Package preloading is now complete.
	pPackage->SetFlags( Asset::FLAG_PRELOADED | Asset::FLAG_LINKED );
	pPackage->ConditionalFinalizeLoad();

	AtomicExchangeRelease( m_preloadedCounter, 1 );

	LooseAssetLoader::OnPackagePreloaded( this );
}
コード例 #25
0
ファイル: RHandle.cpp プロジェクト: Ryxali/SpaceSumo
void res::loadResource(std::string ref)
{
	handler.load(ref);
}
コード例 #26
0
ファイル: RHandle.cpp プロジェクト: Ryxali/SpaceSumo
const STexture &res::getTexture(std::string ref)
{
	return handler.getTexStore().get(ref);
}
コード例 #27
0
ファイル: RHandle.cpp プロジェクト: Ryxali/SpaceSumo
const SSoundBuffer &res::getSoundBuffer(std::string ref)
{
	return handler.getSBufStore().get(ref);
}
コード例 #28
0
ファイル: Level2.cpp プロジェクト: Arqu3/Spelprojekt-1
void Level2::toggleActive(ResourceHandler &handler, sf::RenderWindow &window, UI *ui)
{
	if (!mIsActive)
	{
		handler.loadLevel2(window);

		//Default bool values
		mItemInteraction = false;
		mLevelComplete = false;
		mMouseReleased = false;
		mAutoDialogueTriggered = false;
		mTalkedToArnold = false;
		mSteamMachineWorking = false;

		mActiveScene = 0;

		//Room Textures
		//Background texture
		background.setSize(sf::Vector2f(1520, 576));
		background.setTexture(handler.getTexture("Workshop.png"));

		//Playground texture
		/*playground.setSize(sf::Vector2f(1024, 576));
		playground.setTexture(handler.getTexture("thomaspg.png"));*/

		//Foreground texture
		/*foreground.setSize(sf::Vector2f(1024, 576));
		foreground.setTexture(handler.getTexture("thomasfg.png"));*/

		// Zoom Textures
		//Background Zoom texture
		/*backgroundZoom.setSize(sf::Vector2f(1024, 576));
		backgroundZoom.setTexture(handler.getTexture("thomaszoombg.png"));*/

		//Playground Zoom texture
		/*playgroundZoom.setSize(sf::Vector2f(1024, 576));
		playgroundZoom.setTexture(handler.getTexture("thomaszoompg.png"));*/

		//Foreground Zoom texture
		/*foregroundZoom.setSize(sf::Vector2f(1024, 576));
		foregroundZoom.setTexture(handler.getTexture("thomaszoomfg.png"));*/

		//Help rectangles
		rectangleSteamMachine.setPosition(sf::Vector2f(683, 189));
		rectangleSteamMachine.setSize(sf::Vector2f(90, 50));
		rectangleVise.setPosition(sf::Vector2f(963, 203));
		rectangleVise.setSize(sf::Vector2f(60, 40));
		rectangleDrawer.setPosition(sf::Vector2f(1270, 330));
		rectangleDrawer.setSize(sf::Vector2f(100, 100));
		rectangleBicycle.setPosition(sf::Vector2f(150, 219));
		rectangleBicycle.setSize(sf::Vector2f(200, 100));
		rectangleComputer.setPosition(sf::Vector2f(1440, 275));
		rectangleComputer.setSize(sf::Vector2f(100, 100));
		rectanglePosters.setPosition(sf::Vector2f(1400, 95));
		rectanglePosters.setSize(sf::Vector2f(110, 140));
		rectangleToolwall.setPosition(sf::Vector2f(813, 47));
		rectangleToolwall.setSize(sf::Vector2f(200, 130));

		//Sound/music
		/*music.openFromFile(handler.getMusic("Level1Music.ogg"));
		music.setLoop(true);
		music.setVolume(10);
		music.play();*/

		/*mAmbientSound.setBuffer(*handler.getSound("Level1_Ambience.ogg"));
		mAmbientSound.setLoop(true);
		mAmbientSound.setVolume(10);
		mAmbientSound.play();*/

		mCriticalItemSound.setBuffer(*handler.getSound("Critical_Item.ogg"));
		mCriticalItemSound.setVolume(70);

		mRegularItemSound.setBuffer(*handler.getSound("Regular_Item_Pickup.ogg"));
		mMenuMainUISound.setBuffer(*handler.getSound("Menu_MainUI.ogg"));
		mMenuHatSound.setBuffer(*handler.getSound("Menu_Hat.ogg"));
		mMenuInventorySound.setBuffer(*handler.getSound("Menu_Inventory.ogg"));

		music.openFromFile(handler.getMusic("Level2Music.ogg"));
		music.setLoop(true);
		music.setVolume(50);
		music.play();

		//View
		mView.setCenter(512, 288);
		mView.setSize(1024, 576);

		//Player
		mPlayer = new Player(handler, sf::Vector2f(414, 342));

		//Inventory
		mInventory = new Inventory(handler);
		mInventory->setCraftableItems(handler, 1);

		//DialogueSystem
		mDialogueSystem = new DialogueSystem(handler, 1);

		//Mouse Cursor
		mCursor = new Cursor(handler);

		//Menu
		mUI = ui; //TODO - Test mUI** and &ui if not working

		//Clues
		mClues = new Clue(handler, "ClueBackground1.png");
		/*mClues->add(handler, "Clue1First.png", sf::Vector2f(58, 31));
		mClues->getClue(0)->setStrings("Jag måste hitta en stjärna, en \nastronaut, och en skruvmakapär.", "");
		mClues->getClue(0)->setState1();

		mClues->add(handler, "thomasstar.png", sf::Vector2f(210, 185));
		mClues->getClue(1)->setStrings("Först måste jag hitta stjärnan.", "Jag hittade stjärnan på golvet!");
		mClues->getClue(1)->setState1();

		mClues->add(handler, "thomasastronaut.png", sf::Vector2f(405, 80));
		mClues->getClue(2)->setStrings("Nu måste jag hitta astronauten.", "Astronauten är i akvariumet \nmen jag måste fiska upp den!");

		mClues->add(handler, "Clue1Aqua.png", sf::Vector2f(610, 70));
		mClues->getClue(3)->setStrings("Jag måste hitta något att fiska \nupp astronauten med.", "Med magnetfiskaren kan jag få \ntag i astronauten!");

		mClues->add(handler, "FishingRodMagnet.png", sf::Vector2f(710, 260));
		mClues->getClue(4)->setStrings("Nu måste jag bara fiska upp \nastronauten också.", "Astronauten har blivit hittad!");

		mClues->add(handler, "ScrewDeviceINV.png", sf::Vector2f(800, 400));
		mClues->getClue(5)->setStrings("Var kan nu skruvmakapären \nvara?", "Äntligen! Skruvmakapären är \nhittad!");

		mClues->add(handler, "InfoIcon.png", sf::Vector2f(280, 450));
		mClues->getClue(6)->setStrings("Detta är ledtrådskartan. \nHär kan du läsa vad du har gjort \nhittills och vad du bör göra \nhärnäst. Bara håll musen över \nen ledtråd för att läsa den. \nPilarna låter dig se ledtrådar \nför banor du tidigare klarat.", "");
		mClues->getClue(6)->setState1();*/

		//Create Items
		mCable = new Item(handler, sf::Vector2f(595, 165), "Cable");
		mAirbag = new Item(handler, sf::Vector2f(74, 321), "Airbag");
		mFilledBalloon = new Item(handler, sf::Vector2f(74, 321), "FilledBalloon"); //Invisible/Not Active, get from Steam Machine
		mJuice = new Item(handler, sf::Vector2f(74, 321), "Juice"); //Invisible/Not Active, get from Arnold
		mGlove = new Item(handler, sf::Vector2f(895, 226), "Glove");
		mKey = new Item(handler, sf::Vector2f(1170, 45), "Key"); //Invisible, get from Birdnest
		mWorkshopStick = new Item(handler, sf::Vector2f(1058, 120), "WorkshopStick");
		mCloth = new Item(handler, sf::Vector2f(805, 225), "Cloth");
		mCan = new Item(handler, sf::Vector2f(1330, 112), "Can"); //Invisible/Not Active, get from Putte
		mPutte = new Item(handler, sf::Vector2f(1330, 112), "Putte");
		mArnold = new Item(handler, sf::Vector2f(480, 165), "Arnold");
		mSteamMachine = new Item(handler, sf::Vector2f(683, 189), "SteamMachine");
		mVise = new Item(handler, sf::Vector2f(963, 203), "Vise");
		mDrawer = new Item(handler, sf::Vector2f(1270, 330), "Drawer");

		//Item Glow
		/*mAstronautGlow.setTexture(*handler.getTexture("AstronautGlow.png"));
		mAstronautGlow.setPosition(477, 287);
		mAstronautGlow.setScale(0.7f, 0.7f);*/

		//Playground rectangles
		mPlayRects.push_back(createRect(295, 334, 940, 224));
		mPlayRects.push_back(createRect(1255, 430, 135, 127));

		//Add Rects here
		////Steam machine
		//mRects.push_back(createRect(683, 189, 90, 50));
		////Vise
		//mRects.push_back(createRect(963, 203, 60, 40));
		////Drawer
		//mRects.push_back(createRect(1270, 330, 100, 100));
		//Bicycle
		mRects.push_back(createRect(150, 219, 200, 100));
		//Computer
		mRects.push_back(createRect(1440, 275, 100, 100));
		//Posters
		mRects.push_back(createRect(1400, 95, 110, 140));
		//Toolwall
		mRects.push_back(createRect(813, 47, 200, 130));
		//Scenechange
		//mRects.push_back(createRect(963, 203, 60, 40));

		//Items - Set as Active, Pickupable, Interactable
		mCable->toggleActive();
		mCable->togglePickupable();

		mAirbag->toggleActive();
		mAirbag->togglePickupable();

		mGlove->toggleActive();
		mGlove->togglePickupable();

		mKey->toggleActive();
		mKey->togglePickupable();

		mWorkshopStick->toggleActive();
		mWorkshopStick->togglePickupable();

		mCloth->toggleActive();
		mCloth->togglePickupable();

		mPutte->toggleActive();

		mArnold->toggleActive(); //TODO - Toggle later instead?

		mSteamMachine->toggleActive();

		mVise->toggleActive();

		mDrawer->toggleActive();
		mDrawer->toggleInteractable();

		//Add to ItemVector
		addItem(mCable);
		addItem(mAirbag);
		addItem(mGlove);
		addItem(mKey);
		addItem(mWorkshopStick);
		addItem(mCloth);
		addItem(mPutte);
		addItem(mArnold);
		addItem(mSteamMachine);
		addItem(mVise);
		addItem(mDrawer);
	}
	else
	{
		delete mPlayer;
		delete mInventory;
		delete mDialogueSystem;
		delete mClues;
		mItems.clear();
		mRects.clear();
		mPlayRects.clear();
		mUI->setActiveAnimation("None");
		//TODO - Add Volume Fadeout?
		music.stop();
		mAmbientSound.stop();
	}
	mIsActive = !mIsActive;
}
コード例 #29
0
ファイル: RHandle.cpp プロジェクト: Ryxali/SpaceSumo
void res::addResource(std::string ref) 
{
	handler.add(ref);
}
コード例 #30
0
ファイル: SkyBox.cpp プロジェクト: CreativeCodingLab/aluminum
  virtual void onCreate() {

    rh.loadProgram(skyboxProgram, "week5b_CubeMapping/skybox", posLoc, -1, -1, -1);
    rh.loadProgram(environmentMappingProgram, "week5b_CubeMapping/envMap", posLoc, normalLoc, -1, -1);

    MeshData cube;
    addCube(cube, 8.0);
    cubeMeshBuffer.init(cube, posLoc, normalLoc, -1, -1);
    cubeModel = mat4();
    cubeModel = glm::translate(cubeModel, vec3(0.0,0.0,40));


    obj::Model m = obj::loadModelFromFile(rh.pathToResource("week5b_CubeMapping/dragon.obj"));

    MeshData dragonMesh;

    for(std::map<std::string, std::vector<unsigned short> >::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g) {

      for (int i = 0 ; i < g->second.size() ; i++) {

        dragonMesh.index(g->second[i]);
      }
    }


    for (int i = 0; i < m.vertex.size(); i+=3) {
      vec3 pos = vec3(m.vertex[i], m.vertex[i+1], m.vertex[i+2]);
      pos *= 30;
      dragonMesh.vertex(pos);
    }

    for (int i = 0; i < m.normal.size(); i+=3) {
      dragonMesh.normal(m.normal[i], m.normal[i+1], m.normal[i+2]);
    }

    dragonMeshBuffer.init(dragonMesh, posLoc, normalLoc, -1, -1);
    dragonModel = glm::mat4();
    dragonModel = glm::translate(dragonModel, vec3(0.0, -1.2, 30.0));

    MeshData skybox;
    addCube(skybox, 100.0);
    skyboxMeshBuffer.init(skybox, posLoc, -1, -1, -1);


    //create the cube map texture
    rh.loadCubeMapTexture(cmt, 2048, 2048,
                          "week5b_CubeMapping/negz.jpg",
                          "week5b_CubeMapping/posz.jpg",
                          "week5b_CubeMapping/posy.jpg",
                          "week5b_CubeMapping/negy.jpg",
                          "week5b_CubeMapping/negx.jpg",
                          "week5b_CubeMapping/posx.jpg");


    rotateBehavior = Behavior(now()).delay(1000).length(10000).range(vec3(glm::radians(360.0))).looping(true).repeats(-1);

    camera = Camera(glm::radians(60.0), (float)width/(float)height, 0.01, 1000.0);

    glEnable(GL_DEPTH_TEST);

  }