Example #1
0
Array<ZT> MakeArray(const ZT& x, const ZT& y)
{
    Array<ZT> a;
    a.PushBack(x);
    a.PushBack(y);
    return a;
}
Example #2
0
Array<String> MakeStrA(const String& x, const String& y)
{
    Array<String> a;
    a.PushBack(x);
    a.PushBack(y);
    return a;
}
//==============================
// VRMenuEventHandler::Opened
void VRMenuEventHandler::Opened( Array< VRMenuEvent > & events )
{
	LOG( "Opened" );
	// broadcast the opened event
	VRMenuEvent event( VRMENU_EVENT_OPENED, EVENT_DISPATCH_BROADCAST, menuHandle_t(), Vector3f( 0.0f ), HitTestResult() );
	events.PushBack( event );
}
Example #4
0
//==================================
// VRMenuMgrLocal::CondenseList
// keeps the free list from growing too large when items are removed
void VRMenuMgrLocal::CondenseList()
{
	// we can only condense the array if we have a significant number of items at the end of the array buffer
	// that are empty (because we cannot move an existing object around without changing its handle, too, which
	// would invalidate any existing references to it).  
	// This is the difference between the current size and the array capacity.
	int const MIN_FREE = 64;	// very arbitray number
	if ( ObjectList.GetCapacityI() - ObjectList.GetSizeI() < MIN_FREE )
	{
		return;
	}

	// shrink to current size
	ObjectList.Resize( ObjectList.GetSizeI() );	

	// create a new free list of just indices < the new size
	Array< int > newFreeList;
	for ( int i = 0; i < FreeList.GetSizeI(); ++i ) 
	{
		if ( FreeList[i] <= ObjectList.GetSizeI() )
		{
			newFreeList.PushBack( FreeList[i] );
		}
	}
	FreeList = newFreeList;
}
//==============================
// VRMenuEventHandler::Closing
void VRMenuEventHandler::Closing( Array< VRMenuEvent > & events )
{
	LOG( "Closing" );
	// broadcast the closing event
	VRMenuEvent event( VRMENU_EVENT_CLOSING, EVENT_DISPATCH_BROADCAST, menuHandle_t(), Vector3f( 0.0f ), HitTestResult() );
	events.PushBack( event );
}
Example #6
0
static void FilterTaggedData(JSON* data, const char* tag_name, const char* qtag, Array<JSON*>& items)
{
    if (data == NULL || !(data->Name == "TaggedData") || data->Type != JSON_Array)
        return;

    JSON* tagged_item = data->GetFirstItem();
    while (tagged_item)
    {
        JSON* tags = tagged_item->GetItemByName("tags");
        if (tags->Type == JSON_Array)
        {   // Check for a tag match on the requested tag
            
            JSON* tag = tags->GetFirstItem();
            while (tag)
            {
                JSON* tagval = tag->GetFirstItem();
                if (tagval && tagval->Name == tag_name)
                {
                    if (tagval->Value == qtag)
                    {   // Add this item to the output list
                        items.PushBack(tagged_item);
                    }
                    break;
                }
                tag = tags->GetNextItem(tag);
            }
        }

        tagged_item = data->GetNextItem(tagged_item);
    }
}
Example #7
0
Matrix4f OvrSceneView::DrawEyeView( const int eye, const float fovDegreesX, const float fovDegreesY ) const
{
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
	glFrontFace( GL_CCW );

	const Matrix4f centerEyeViewMatrix = GetCenterEyeViewMatrix();
	const Matrix4f viewMatrix = GetEyeViewMatrix( eye );
	const Matrix4f projectionMatrix = GetEyeProjectionMatrix( eye, fovDegreesX, fovDegreesY );

	// Cull the model surfaces using a view and projection matrix that contain both eyes
	// and add the surfaces to the sorted surface list.
	if ( eye == 0 )
	{
		Matrix4f symmetricEyeProjectionMatrix = projectionMatrix;
		symmetricEyeProjectionMatrix.M[0][0] = projectionMatrix.M[0][0] / ( fabs( projectionMatrix.M[0][2] ) + 1.0f );
		symmetricEyeProjectionMatrix.M[0][2] = 0.0f;
 
		const float moveBackDistance = 0.5f * HeadModelParms.InterpupillaryDistance * symmetricEyeProjectionMatrix.M[0][0];
		Matrix4f centerEyeCullViewMatrix = Matrix4f::Translation( 0, 0, -moveBackDistance ) * centerEyeViewMatrix;

		Array< ModelState * > emitModels;
		for ( int i = 0; i < Models.GetSizeI(); i++ )
		{
			emitModels.PushBack( &Models[i]->State );
		}

		BuildModelSurfaceList( DrawSurfaceList, SupressModelsWithClientId, emitModels, EmitSurfaces, centerEyeCullViewMatrix, symmetricEyeProjectionMatrix );
	}

	RenderSurfaceList( DrawSurfaceList, viewMatrix, projectionMatrix );

	return ( projectionMatrix * viewMatrix );
}
Example #8
0
Directx::TGeometry::TGeometry(const ArrayBridge<uint8>&& Data,const ArrayBridge<size_t>&& _Indexes,const SoyGraphics::TGeometryVertex& Vertex,TContext& ContextDx) :
	mVertexDescription	( Vertex ),
	mIndexCount			( 0 )
{
	Array<uint32> Indexes;
	for ( int i=0;	i<_Indexes.GetSize();	i++ )
		Indexes.PushBack( size_cast<uint32>( _Indexes[i] ) );


	// Set up the description of the static vertex buffer.
	D3D11_BUFFER_DESC vertexBufferDesc;
	vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	vertexBufferDesc.ByteWidth = Data.GetDataSize();//Vertex.GetDataSize();
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = Vertex.GetStride(0);	//	should be 0

	// Give the subresource structure a pointer to the vertex data.
	D3D11_SUBRESOURCE_DATA vertexData;
	vertexData.pSysMem = Data.GetArray();
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	// Set up the description of the static index buffer.
	D3D11_BUFFER_DESC indexBufferDesc;

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = Indexes.GetDataSize();
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;
	indexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the index data.
	D3D11_SUBRESOURCE_DATA indexData;
	indexData.pSysMem = Indexes.GetArray();
	indexData.SysMemPitch = 0;
	indexData.SysMemSlicePitch = 0;


	auto& Device = ContextDx.LockGetDevice();
	try
	{
		auto Result = Device.CreateBuffer(&vertexBufferDesc, &vertexData, &mVertexBuffer.mObject );
		Directx::IsOkay( Result, "Create vertex buffer");

		Result = Device.CreateBuffer(&indexBufferDesc, &indexData, &mIndexBuffer.mObject );
		Directx::IsOkay( Result, "Create index buffer");
		mIndexCount = Indexes.GetSize();
		mIndexFormat = DXGI_FORMAT_R32_UINT;
	}
	catch( std::exception& e)
	{
		ContextDx.Unlock();
		throw;
	}
}
//==============================
// FindTargetPath
static void FindTargetPath( OvrGuiSys & guiSys, menuHandle_t const rootHandle, 
        menuHandle_t const curHandle, Array< menuHandle_t > & targetPath ) 
{
	FindTargetPath( guiSys, curHandle, targetPath );
	if ( targetPath.GetSizeI() == 0 )
	{
		targetPath.PushBack( rootHandle );   // ensure at least root is in the path
	}
}
Example #10
0
static void TestDataAlignmentT()
{
    Array<TYPE> v;
    v.PushBack( TYPE() );

    UT_ASSERT(v.GetSize() == 1);
    UT_ASSERT(((long)v.GetData()) % AligmentSize == 0);

}
Example #11
0
NitsEndTest

NitsTestWithSetup(TestInlineCOW, TestArraySetup)
{
    Array< int > v;

    v.PushBack(0);

    Array< int > v2 = v;

    v2[0] = 1;
    v.PushBack(1);

    UT_ASSERT(0 == v[0]);
    UT_ASSERT(1 == v[1]);
    UT_ASSERT(1 == v2[0]);
    UT_ASSERT(v.GetSize() == 2);
    UT_ASSERT(v2.GetSize() == 1);
}
//==============================
// FindTargetPath
static void FindTargetPath( OvrGuiSys & guiSys, 
        menuHandle_t const curHandle, Array< menuHandle_t > & targetPath ) 
{
	VRMenuObject * obj = guiSys.GetVRMenuMgr().ToObject( curHandle );
	if ( obj != NULL )
	{
		FindTargetPath( guiSys, obj->GetParentHandle(), targetPath );
		targetPath.PushBack( curHandle );
	}
}
//==============================
// FindTargetPath
static void FindTargetPath( OvrVRMenuMgr const & menuMgr,
                            menuHandle_t const curHandle, Array< menuHandle_t > & targetPath )
{
    VRMenuObject * obj = menuMgr.ToObject( curHandle );
    if ( obj != NULL )
    {
        FindTargetPath( menuMgr, obj->GetParentHandle(), targetPath );
        targetPath.PushBack( curHandle );
    }
}
Example #14
0
Array<float>  AttrWidgetVectorFloat::GetValue()
{
    Array<float> result;
    for (unsigned int i = 0; i < m_floatSlots.Size(); ++i)
    {
        float f = m_floatSlots[i]->GetValue();
        result.PushBack(f);
    }
    return result;
}
Example #15
0
Array<ZT> MakeArray(const ZT& x, Uint32 n)
{
    Array<ZT> a;
    for (Uint32 i = 0; i < n; i++)
    {
        a.PushBack(x);
    }

    return a;
}
Example #16
0
//==================================
// VRMenuMgrLocal::CreateObject
// creates a new menu object
menuHandle_t VRMenuMgrLocal::CreateObject( VRMenuObjectParms const & parms )
{
	if ( !Initialized )
	{
		LOG( "VRMenuMgrLocal::CreateObject - manager has not been initialized!" );
		return menuHandle_t();
	}

	// validate parameters
	if ( parms.Type >= VRMENU_MAX )
	{
		LOG( "VRMenuMgrLocal::CreateObject - Invalid menu object type: %i", parms.Type );
		return menuHandle_t();
	}

	// create the handle first so we can enforce setting it be requiring it to be passed to the constructor
	int index = -1;
	if ( FreeList.GetSizeI() > 0 )
	{
		index = FreeList.Back();
		FreeList.PopBack();
	}
	else
	{
		index = ObjectList.GetSizeI();
	}

	UInt32 id = ++CurrentId;
	menuHandle_t handle = ComposeHandle( index, id );
	//LOG( "VRMenuMgrLocal::CreateObject - handle is %llu", handle.Get() );

	VRMenuObject * obj = new VRMenuObjectLocal( parms, handle );
	if ( obj == NULL )
	{
		LOG( "VRMenuMgrLocal::CreateObject - failed to allocate menu object!" );
		OVR_ASSERT( obj != NULL );	// this would be bad -- but we're likely just going to explode elsewhere
		return menuHandle_t();
	}
	
	obj->Init( parms );

	if ( index == ObjectList.GetSizeI() )
	{
		// we have to grow the array
		ObjectList.PushBack( obj );
	}
	else
	{
		// insert in existing slot
		OVR_ASSERT( ObjectList[index] == NULL );
		ObjectList[index ] = obj;
	}

	return handle;
}
Example #17
0
void AddStatus( const SimpleString& Status, uint8 Color )
{
	SStatus NewStatus;
	NewStatus.m_Status = Status;
	NewStatus.m_Color = Color;

	g_Statuses.PushBack( NewStatus );
	g_StatusOffset = g_Statuses.Size() > g_NumStatusLines ? g_Statuses.Size() - g_NumStatusLines : 0;

	PRINTF( SimpleString::PrintF( "Status: %s\n", Status.CStr() ).CStr() );
}
Example #18
0
void Crypto::Decrypt( const Array< char >& Ciphertext, const Array< SimpleString >& Keys, SimpleString& OutPlaintext )
{
	Array< char > KeyArray;
	Array< char > PlaintextArray;

	ConstructKeyFromStrings( Keys, KeyArray );

	Decrypt( Ciphertext, KeyArray, PlaintextArray );

	PlaintextArray.PushBack( '\0' );
	OutPlaintext = PlaintextArray;
}
Example #19
0
void OvrSoundManager::LoadSoundAssets()
{
	Array<String> searchPaths;
	searchPaths.PushBack( "/storage/extSdCard/" );
	searchPaths.PushBack( "/sdcard/" );

	// First look for sound definition using SearchPaths for dev
	String foundPath;
	if ( GetFullPath( searchPaths, DEV_SOUNDS_RELATIVE, foundPath ) )
	{
		JSON * dataFile = JSON::Load( foundPath.ToCStr() );
		if ( dataFile == NULL )
		{
			FAIL( "OvrSoundManager::LoadSoundAssets failed to load JSON meta file: %s", foundPath.ToCStr( ) );
		}
		foundPath.StripTrailing( "sound_assets.json" );
		LoadSoundAssetsFromJsonObject( foundPath, dataFile );
	}
	else // if that fails, we are in release - load sounds from vrlib/res/raw and the assets folder
	{
		if ( ovr_PackageFileExists( VRLIB_SOUNDS ) )
		{
			LoadSoundAssetsFromPackage( "res/raw/", VRLIB_SOUNDS );
		}
		if ( ovr_PackageFileExists( APP_SOUNDS ) )
		{
			LoadSoundAssetsFromPackage( "", APP_SOUNDS );
		}
	}

	if ( SoundMap.IsEmpty() )
	{
#if defined( OVR_BUILD_DEBUG )
		FAIL( "SoundManger - failed to load any sound definition files!" );
#else
		WARN( "SoundManger - failed to load any sound definition files!" );
#endif
	}
}
// From http://stackoverflow.com/questions/9524309/enumdisplaydevices-function-not-working-for-me
void GetGraphicsCardList( Array< String > &gpus)
{
    gpus.Clear();
    DISPLAY_DEVICEW dd;
    dd.cb = sizeof(dd);

    DWORD deviceNum = 0;
    while( EnumDisplayDevicesW(NULL, deviceNum, &dd, 0) )
    {
        if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
            gpus.PushBack(String(dd.DeviceString));
        deviceNum++;
    }
}
Example #21
0
		int Add(int _x, int _y, const Vec3 & pos)
		{
			for (int i = 0; i < vertArray.Size(); ++i)
			{
				if (vertArray[i]._x == _x && vertArray[i]._y == _y)
					return i;
			}

			Vertex v = { _x, _y, pos };

			vertArray.PushBack(v);

			return vertArray.Size() - 1;
		}
Example #22
0
static void create_index(Stream* archive, const String& path, Array<String>& files, Array<String>& folders)
{
	DIR* dirp = opendir(path);
	if( !dirp )
		PRCORE_EXCEPTION("Unable to open directory.");

	dirent* dp;
	while ( (dp = readdir(dirp)) )
	{
		String name(dp->d_name);

		static String s1(".");
		static String s2("..");

		if ( !StringCompare(name,s1) && !StringCompare(name,s2) )
		{
			// check if we are dealing with a folder or file
			String testname = path + name;

			DIR* tempdir = opendir(testname);
			if ( tempdir )
			{
				closedir(tempdir);

				name << '/';
				folders.PushBack(name);
			}
			else
			{
				files.PushBack(name);
			}
		}
	}   

	closedir(dirp);
}
Example #23
0
	void GrassManager::_getActiveBlocks(Array<GrassBlock *> & arr)
	{
		const FixedArray<WorldSection *, 9> & ws = World::Instance()->GetActiveSections();
		for (int i = 0; i < ws.Size(); ++i)
		{
			GrassSection * section = ws[i]->GetDataT<GrassSection>();
			if (section != NULL)
			{
				int count = section->_getBlockCount().x * section->_getBlockCount().y;
				for (int k = 0; k < count; ++k)
				{
					arr.PushBack(section->_getBlock(k));
				}
			}
		}
	}
const TemperatureReport& median(const Array<TemperatureReport>& temperatureReportsBin, int coord)
{
    Array<double> values;
    values.Reserve(temperatureReportsBin.GetSize());
    for (unsigned i = 0; i < temperatureReportsBin.GetSize(); i++)
        if (temperatureReportsBin[i].ActualTemperature != 0)
            values.PushBack(temperatureReportsBin[i].Offset[coord]);
    if (values.GetSize() > 0)
    {
        double med = Median(values);
        // this is kind of a hack
        for (unsigned i = 0; i < temperatureReportsBin.GetSize(); i++)
            if (temperatureReportsBin[i].Offset[coord] == med)
                return temperatureReportsBin[i];
        // if we haven't found the median in the original array, something is wrong
        OVR_DEBUG_BREAK;
    }
    return temperatureReportsBin[0];
}
Example #25
0
void WBScene::GetEntitiesByComponent( Array<WBEntity*>& OutEntities, const HashedString& ComponentName ) const
{
	BEGIN_ITERATING_ENTITIES;
	FOR_EACH_MAP( EntityIter, m_Entities, uint, SEntityRef )
	{
		const SEntityRef& EntityRef = EntityIter.GetValue();
		WBEntity* const pEntity = EntityRef.m_Entity;
		DEVASSERT( pEntity );

		if( EntityRef.m_Removed || pEntity->IsDestroyed() )
		{
			continue;
		}

		if( pEntity->GetComponent( ComponentName ) )
		{
			OutEntities.PushBack( pEntity );
		}
	}
	END_ITERATING_ENTITIES;
}
Example #26
0
	void GrassManager::_getAllBlocks(Array<GrassBlock *> & arr)
	{
		const World::Info * wi = World::Instance()->GetInfo();

		for (int j = 0; j < wi->SectionCount.y; ++j)
		{
			for (int i = 0; i < wi->SectionCount.x; ++i)
			{
				WorldSection * ws = World::Instance()->GetSection(i, j);
				GrassSection * section = ws->GetDataT<GrassSection>();
				if (section != NULL)
				{
					int count = section->_getBlockCount().x * section->_getBlockCount().y;
					for (int k = 0; k < count; ++k)
					{
						arr.PushBack(section->_getBlock(k));
					}
				}
			}
		}
	}
Example #27
0
void Patcher_HandleReceipt_ManifestFile()
{
	g_FilesInManifest.Clear();
	g_NextPatchFileIndex = 0;

	char* MessageContent = strstr( g_HTTPResultBuffer.GetData(), CRLF CRLF );
	if( !MessageContent )
	{
		AddStatus( "Error receiving manifest file.", g_StatusWarningColor );
		++g_NumWarnings;
		return;
	}

	MessageContent += 4;

	uint Offset = ( uint )( MessageContent - g_HTTPResultBuffer.GetData() );
	uint ContentSize = g_HTTPSocket->AsyncGetBytesReceived() - Offset;

	Array<SimpleString>	Lines;
	SplitIntoLines( MessageContent, ContentSize, Lines );

	for( uint LinesIndex = 0; LinesIndex + 2 < Lines.Size(); LinesIndex += 3 )
	{
		SManifestFile ManifestFile;
		ManifestFile.m_Filename = Lines[ LinesIndex ];
		ManifestFile.m_Length = Lines[ LinesIndex + 1 ];
		ManifestFile.m_Checksum = Lines[ LinesIndex + 2 ];
		ManifestFile.m_Validated = false;

		g_FilesInManifest.PushBack( ManifestFile );
	}

	AddStatus( "Manifest file received.", g_StatusColor );

	if( g_NextPatchFileIndex < g_FilesInManifest.Size() )
	{
		Patcher_GetNextPatchFile();
	}
}
Example #28
0
//==================================
// VRMenuMgrLocal::FreeObject
// Frees a menu object.  If the object is a child of a parent object, this will
// also remove the child from the parent.
void VRMenuMgrLocal::FreeObject( menuHandle_t const handle )
{
	int index;
	UInt32 id;
	DecomposeHandle( handle, index, id );
	if ( !HandleComponentsAreValid( index, id ) )
	{
		return;
	}
	if ( ObjectList[index] == NULL )
	{
		// already freed
		return;
	}

	VRMenuObject * obj = ObjectList[index];
	// remove this object from its parent's child list
	if ( obj->GetParentHandle().IsValid() )
	{
		VRMenuObject * parentObj = ToObject( obj->GetParentHandle() );
		if ( parentObj != NULL )
		{
			parentObj->RemoveChild( *this, handle );
		}
	}

    // free all of this object's children
    obj->FreeChildren( *this );

	delete obj;

	// empty the slot
	ObjectList[index] = NULL;
	// add the index to the free list
	FreeList.PushBack( index );
	
	CondenseList();
}
void MoviePlayerView::CreateMenu( App * app, OvrVRMenuMgr & menuMgr, BitmapFont const & font )
{
	Menu = VRMenu::Create( "MoviePlayerMenu" );

    Array< VRMenuObjectParms const * > parms;

	Posef moveScreenPose( Quatf( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ),
			Vector3f(  0.0f, 0.0f,  -1.8f ) );

	VRMenuFontParms moveScreenFontParms( true, true, false, false, false, 0.5f );

	VRMenuSurfaceParms moveScreenSurfParms( "",
			NULL, SURFACE_TEXTURE_MAX,
			NULL, SURFACE_TEXTURE_MAX,
			NULL, SURFACE_TEXTURE_MAX );

	VRMenuObjectParms moveScreenParms( VRMENU_BUTTON, Array< VRMenuComponent* >(), moveScreenSurfParms,
			Strings::MoviePlayer_Reorient, moveScreenPose, Vector3f( 1.0f ), moveScreenFontParms, ID_MOVE_SCREEN,
			VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );

	parms.PushBack( &moveScreenParms );

	Menu->InitWithItems(menuMgr, font, 0.0f, VRMenuFlags_t( VRMENU_FLAG_TRACK_GAZE ) | VRMENU_FLAG_BACK_KEY_DOESNT_EXIT, parms);
	parms.Clear();

	MoveScreenHandle = Menu->HandleForId( menuMgr, ID_MOVE_SCREEN );
	MoveScreenObj = menuMgr.ToObject( MoveScreenHandle );

    MoveScreenObj->AddFlags( VRMENUOBJECT_DONT_RENDER );
	Vector3f moveScreenTextPosition = Vector3f( 0.0f, -24 * VRMenuObject::DEFAULT_TEXEL_SCALE, 0.0f );
    MoveScreenObj->SetTextLocalPosition( moveScreenTextPosition );

    // ==============================================================================
    //
    // finalize
    //
    Cinema.app->GetGuiSys().AddMenu( Menu );
}
    FakeMemoryInternal* Open(const char *name, int bytes, bool openOnly)
    {
        Lock::Locker locker(&FakeLock);

        const int count = FakeArray.GetSizeI();
        for (int ii = 0; ii < count; ++ii)
        {
            if (FakeArray[ii]->IsNamed(name))
            {
                FakeArray[ii]->IncrementReferences();
                return new FakeMemoryInternal(FakeArray[ii]);
            }
        }

        if (openOnly)
        {
            return NULL;
        }

        Ptr<FakeMemoryBlock> data = *new FakeMemoryBlock(name, bytes);
        FakeArray.PushBack(data);
        return new FakeMemoryInternal(data);
    }