Exemple #1
0
    AudioSystem::AudioSystem(LinearAllocator& alloc)
        : m_device(nullptr)
        , m_context(nullptr)
        , m_sounds()
        , m_channelPool()
        , m_channels()
        , m_masterVolume(1.0f)
        , m_muted(false)
    {
        m_device = alcOpenDevice(nullptr);
        AL_CHECK;

        if (m_device == nullptr)
        {
            log::Error("Could not open audio device.");
            return;
        }

        m_context = alcCreateContext(m_device, nullptr);
        AL_CHECK;

        if (m_context == nullptr)
        {
            log::Error("Could not create audio context.");
            return;
        }

        alcMakeContextCurrent(m_context);
        AL_CHECK;

        const size_t_32 allocSize = 1024;
        m_sounds.SetMemory(alloc.Allocate(allocSize, alignof(Sound)), allocSize);
        const size_t_32 channelPoolSize = GetArraySize<Channel>(MAX_CHANNELS);
        m_channelPool.SetMemory(alloc.AllocateArray<Channel>(MAX_CHANNELS), channelPoolSize);

        for (size_t_32 i = 0; i < MAX_CHANNELS; i++)
        {
            m_channels[i] = m_channelPool.Obtain();
        }

        SetMasterVolume(m_masterVolume);
        alListener3f(AL_POSITION, 0.0f, 0.0f, -2.0f);
        AL_CHECK;
    }
Exemple #2
0
    void InitializeGeometry()
    {
        OBJResource<Vertex4> resource ("Models\\Sphere.obj");
        mMeshLibrary.LoadMesh(&mCubeMesh, mRenderer, resource);

        SampleVertex qVertices[4];
        qVertices[0].mPosition	= { -1.0f, 1.0f, 0.0f };
        qVertices[0].mUV		= { 0.0f, 0.0f};

        qVertices[1].mPosition	= { 1.0f, 1.0f, 0.0f };
        qVertices[1].mUV		= { 1.0f, 0.0f};

        qVertices[2].mPosition	= { 1.0f, -1.0f, 0.0f };
        qVertices[2].mUV		= { 1.0f, 1.0f };

        qVertices[3].mPosition	= { -1.0f, -1.0f, 0.0f };
        qVertices[3].mUV		= { 0.0f, 1.0f};

        uint16_t qIndices[6];
        qIndices[0] = 0;
        qIndices[1] = 1;
        qIndices[2] = 2;

        qIndices[3] = 2;
        qIndices[4] = 3;
        qIndices[5] = 0;

        mMeshLibrary.NewMesh(&mQuadMesh, mRenderer);
        mRenderer->VSetStaticMeshVertexBuffer(mQuadMesh, qVertices, sizeof(SampleVertex) * 4, sizeof(SampleVertex));
        mRenderer->VSetStaticMeshIndexBuffer(mQuadMesh, qIndices, 6);

        mSphereColliders = reinterpret_cast<SphereCollider*>(mAllocator.Allocate(sizeof(SphereCollider) * NODE_COUNT, alignof(SphereCollider), 0));

        for (int i = 0; i < NODE_COUNT; i++) {
            mSceneNodes[i].mTransform.SetPosition((float)(rand() % 10) - 5.0f, (float)(rand() % 10) - 5.0f, (float)(rand() % 5));
            mSceneNodes[i].mColor = { SATURATE_RANDOM, SATURATE_RANDOM, SATURATE_RANDOM, 1.0f };
            mSceneNodes[i].mMesh = mCubeMesh;
            mSceneNodes[i].mCollider = &mSphereColliders[i];
            mSceneNodes[i].mCollider->origin = mSceneNodes[i].mTransform.GetPosition();
            mSceneNodes[i].mCollider->radius = 0.5f;
        }

        mCamera.SetPosition( 0.0f, 0.0, -10.0f );
    }