Esempio n. 1
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
bool VertexBuffer::createBufferAndLayoutElements(const DeviceManager& deviceManager, size_t bufferSize, void* data, bool dynamic, const VertexDecalartionDesctriptor& vertexDeclartion, const ID3DBlob* vertexShaderCodeBlob)
{
    D3D11_BUFFER_DESC bufferDescriptor;
    ZeroMemory(&bufferDescriptor, sizeof(D3D11_BUFFER_DESC));
    bufferDescriptor.Usage = D3D11_USAGE_IMMUTABLE;
    bufferDescriptor.ByteWidth = (unsigned int)bufferSize;
    bufferDescriptor.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    bufferDescriptor.CPUAccessFlags = 0;
    bufferDescriptor.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA initData;
    ZeroMemory(&initData, sizeof(D3D11_SUBRESOURCE_DATA));
    initData.pSysMem = data;
    initData.SysMemPitch = 0;
    initData.SysMemSlicePitch = 0;

    HRESULT hr = deviceManager.getDevice()->CreateBuffer( &bufferDescriptor, &initData, &m_buffer );
    if (FAILED(hr))
    {
        MSG_TRACE_CHANNEL("VERTEXBUFFER", "Failed to create a D3D11 Buffer object with code: 0x%x", hr );
        return false;
    }

    if (!createVertexInputLayout(deviceManager, const_cast<ID3DBlob*>(vertexShaderCodeBlob), vertexDeclartion.createInputElementLayout(m_vertexStride)))
    {
        MSG_TRACE_CHANNEL("VERTEXBUFFER", "Failed to create Vertex Input Layout" );
        return false;
    }
    
    m_vertexCount = bufferSize / m_vertexStride;
    dynamic = false;

    return true;
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void InputState::printState() const
{
    MSG_TRACE_CHANNEL("Input State", "/**********************INPUT STATE DATA*********************************/");
    for (auto inputAction : m_inputState)
    {
        MSG_TRACE_CHANNEL( "Input State", "Input state for action %s is value %f ", InputSystem::m_actionNames[inputAction.getAction()], inputAction.getValue());
    }
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void InputSystem::initialise( const std::string& inputMapFileName, HWND hwnd )
{
    tinyxml2::XMLDocument actionsDoc;
    std::string availableActionsFileName = extractPathFromFileName(inputMapFileName) + "AvailableActions.xml";
    if (actionsDoc.LoadFile(availableActionsFileName.c_str()) != tinyxml2::XML_NO_ERROR)
    {
        MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", availableActionsFileName.c_str());
    }

    const tinyxml2::XMLElement* element1 = actionsDoc.FirstChildElement();
    element1 = element1->FirstChildElement();//Skip the <xml> node

    for (; element1; element1 = element1->NextSiblingElement())
    {
        const tinyxml2::XMLAttribute* actionNameAttribute = element1->FindAttribute("name");
        const tinyxml2::XMLAttribute* actionLngNameAttribute = element1->FindAttribute("lng");
        if (actionLngNameAttribute != nullptr)
        {
            MSG_TRACE_CHANNEL("Input SYSTEM", "adding actions for: %s with hash %u", actionNameAttribute->Value(), hashString(actionNameAttribute->Value()));
            m_availableActions.emplace_back(InputActions::ActionType(actionNameAttribute->Value(), actionLngNameAttribute != nullptr ? actionLngNameAttribute->Value() : ""));
#ifdef DEBUG
			m_actionNames.insert(std::make_pair(m_availableActions[m_availableActions.size() - 1],actionNameAttribute->Value()));
#endif
        }
    }

    tinyxml2::XMLDocument doc;
    if (doc.LoadFile(inputMapFileName.c_str()) != tinyxml2::XML_NO_ERROR)
    {
        MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", inputMapFileName.c_str());
    }

    const tinyxml2::XMLElement* element = doc.FirstChildElement();
    element = element->FirstChildElement();//Skip the <xml> node

    for (; element; element = element->NextSiblingElement())
    {
        IInputDevice* controller = createController(stringToControllerType(element->Name()));
        MSG_TRACE_CHANNEL("INPUT SYSTEM", "controller name: %s", element->Name());
        const tinyxml2::XMLAttribute* attribute = element->FindAttribute("input_map");
        if (controller != nullptr && attribute != nullptr )
        {
            tinyxml2::XMLDocument inputDoc;
            std::string buttonMapFileName = std::string(extractPathFromFileName(inputMapFileName) + attribute->Value());
            if (inputDoc.LoadFile(buttonMapFileName.c_str()) != tinyxml2::XML_NO_ERROR)
            {
                MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", buttonMapFileName.c_str());
                return;
            }

            tinyxml2::XMLElement* inputElement = inputDoc.FirstChildElement();
            inputElement = inputElement->FirstChildElement();//Skip the <xml> node
            controller->deserialise(inputElement, *this);
            controller->initialise(hwnd);
        }
    }
}
Esempio n. 4
0
///-------------------------------------------------------------------------
// @brief 
///-------------------------------------------------------------------------
const ShaderInstance ForceField::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
        m_nameHash = hashString(m_name);
    }

    for (element = element->FirstChildElement(); element != 0; element = element->NextSiblingElement())
    {
        unsigned int typeHash = hashString(element->Value());
        if (Material::m_hash == typeHash)
        {
            MSG_TRACE_CHANNEL("REFACTOR", "SEND create material message to render system");
            //shaderInstance.getMaterial().deserialise(m_resource, getResource().getDeviceManager(), getResource().getTextureManager(), getResource().getLightManager(), element);
            //shaderInstance.getMaterial().setBlendState(true);
            m_materialParameters = Material::GetMaterialParameters(element);
        }
        else if (Vector3::m_hash == typeHash)
        {
            m_position.deserialise(element);
            translate(m_world, m_position.x(), m_position.y(), m_position.z());
        }
    }

    return shaderInstance;
}
Esempio n. 5
0
void GunTurret::createScorchMark(const Vector3 &pos, const Vector3 &normal)
{
    //cout <<"Create scorch mark at: " << pos << "\nThis plane has the normal: " << normal << endl;
    //cout << "Number of lasers: " << m_lasers.size();
    MSG_TRACE_CHANNEL("ERROR", "Size of ScorchMark: %d", sizeof(ScorchMark) )
    m_scorchmarks.push_back(new ScorchMark(m_resource, pos, normal, 5.0f));
}
Esempio n. 6
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void ShaderCache::DumpLoadedShaderNames()
{
    for (VertexShaders::const_iterator it = m_vertexShaders.begin(); it != m_vertexShaders.end(); ++it)
    {
        MSG_TRACE_CHANNEL("ShaderCache", "Vertex Shader: %s", it->second.getFileName().c_str());
    }
}
Esempio n. 7
0
///-----------------------------------------------------------------------------
///! @brief   TODO enter a description
///! @remark
///-----------------------------------------------------------------------------
void MouseController::initialise(HWND hwnd)
{
    RAWINPUTDEVICE rawInputDevice;

    rawInputDevice.usUsagePage = 0x01;
    rawInputDevice.usUsage = 0x02;
    rawInputDevice.dwFlags = RIDEV_NOLEGACY;   // adds HID mouse and also ignores legacy mouse messages
    rawInputDevice.hwndTarget = hwnd;

    m_connected = true;
    //InputSystem.addRawInputDevice(rawInputDevice);

    if (RegisterRawInputDevices(&rawInputDevice, 1, sizeof(RAWINPUTDEVICE)) == FALSE)
    {
        m_connected = false;
        unsigned int error = GetLastError();
        MSG_TRACE_CHANNEL("MOUSE CONTROLLER ERROR:", "Failed to register the mouse device with error: %d, %s", error, getLastErrorMessage(error));
    }

    HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
    MONITORINFO info;
    info.cbSize = sizeof(MONITORINFO);
    GetMonitorInfo(monitor, &info);
    m_monitorWidth = info.rcMonitor.right - info.rcMonitor.left;
    m_monitorHeight = info.rcMonitor.bottom - info.rcMonitor.top;
}
Esempio n. 8
0
void TextureManager::addLoad(const DeviceManager& deviceManager, const std::string& filename)
{
	assert (!filename.empty());

    //Extract filename if file name contains a path as well, this is not always true need to deal with relative paths here too
    std::string texureName = getTextureNameFromFileName(filename);

	if (find(texureName))
	{
		//MSG_TRACE_CHANNEL("", "Texture: " << filename << " was already loaded. Skipping the loading of the second instance of this texture" << std::endl;
        return;
	}

	MSG_TRACE_CHANNEL("TEXTUREMANAGER", "Attempting to read in texture: %s", filename.c_str());
	Texture tex;
    if (!tex.loadTextureFromFile(deviceManager, filename))
	{
        MSG_TRACE_CHANNEL("ERROR", "Texture cannot be loaded: %s", filename.c_str());
    }

    unsigned int textureFileNameHash = hashString(texureName);
	m_textures.insert(std::make_pair(textureFileNameHash, tex));
}
///-----------------------------------------------------------------------------
///! @brief   TODO enter a description
///! @remark
///-----------------------------------------------------------------------------
void convertToUTF16String(const std::string& str, std::wstring& out)
{
    wchar_t buffer[4096];
    int numberOfWideChars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.c_str(), (int)str.size(), buffer, 0);
    if (numberOfWideChars > 0)
    {
        out.reserve(numberOfWideChars);
        MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.c_str(), (int)str.size(), buffer, numberOfWideChars);
        buffer[numberOfWideChars] = 0;
        out = buffer;
    }
    else
    {
        DWORD error = GetLastError();
        HRESULT hr = HRESULT_FROM_WIN32(error);
        MSG_TRACE_CHANNEL("String Conversion Error", "Failed to convert from UTF8 to MB with Hresult: 0x%08x, %s", hr, getLastErrorMessage(error));
    }
}
Esempio n. 10
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void InputState::mergeInputState(const InputState& input)
{
#ifdef _DEBUG
    static bool test = false;
    if (test)
    {
        printState();
    }
#endif
    for (auto standardInputAction : input.m_inputState)
    {
        //Does this action exist in the current input state?
        InputStateMap::iterator it = std::find_if(m_inputState.begin(), m_inputState.end(), [standardInputAction](const StandardInputAction& inputAction) { return inputAction.getAction().getType() == standardInputAction.getAction().getType(); });
        if (it != m_inputState.end())
        {
            float currentValue = it->getValue();
            float inputValue = standardInputAction.getValue();
            //Different signs, take the difference, need to figure out which one is bigger or negative
            currentValue = currentValue + inputValue;
            currentValue = math::clamp(currentValue, 0.0f, 1.0f);
#ifdef _DEBUG
            if (test)
            {
                MSG_TRACE_CHANNEL("Input State", "During merging %s value will change to %f", InputSystem::m_actionNames[standardInputAction.getAction()], currentValue);
            }
#endif

            it->setValue(currentValue);
        }
        else
        {
            //Value is not found in the current input set so we should add it to it.
            m_inputState.push_back(standardInputAction);
        }
    }

#ifdef _DEBUG
    if (test)
    {
        printState();
        input.printState();
    }
#endif
}
///-----------------------------------------------------------------------------
///! @brief   TODO enter a description
///! @remark
///-----------------------------------------------------------------------------
void convertToCString(const std::wstring& str, std::string& out)
{
    char buffer[4096];
    // BOOL usedDefaultChar = FALSE;
    int numberOfCChars = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str.c_str(), (int)str.size(), buffer, 0, 0, 0);
    if (numberOfCChars > 0)
    {
        out.reserve(numberOfCChars);
        WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str.c_str(), (int)str.size(), buffer, numberOfCChars, 0, 0);
        buffer[numberOfCChars] = 0;
        out = buffer;
    }
    else
    {
        DWORD error = GetLastError();
        HRESULT hr = HRESULT_FROM_WIN32(error);
        MSG_TRACE_CHANNEL("String Conversion Error", "Failed to convert from MB to UTF8 with Hresult: 0x%08x, %s", hr, getLastErrorMessage(error));
    }
}
Esempio n. 12
0
///-------------------------------------------------------------------------
// @brief 
///-------------------------------------------------------------------------
const ShaderInstance RotatingBlades::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;

    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    for (element = element->FirstChildElement(); element != 0; element = element->NextSiblingElement())
    {
        unsigned int typeHash = hashString(element->Value());
        if (Material::m_hash == typeHash)
        {
            //This all needs to be a message to the renderer to create a render object
            MSG_TRACE_CHANNEL("REFACTOR", "CREATE RENDER RESOURCE HERE THROUGH A MESSAGE");
            //shaderInstance.getMaterial().deserialise(m_resource, getResource().getDeviceManager(), getResource().getTextureManager(), getResource().getLightManager(), element);
            //shaderInstance.getMaterial().setBlendState(true);
            m_materialParameters = Material::GetMaterialParameters(element);
        }
        else if (Vector3::m_hash == typeHash)
        {
            //m_position.deserialise(element);
            //translate(m_world, m_position.x(), m_position.y(), m_position.z());
            //Matrix44 transform;
            //translate(transform, 0.0f, 0.0f, -25.0f);
            //Matrix44 world = m_world;
            //shaderInstance.setWorld(m_world * transform);
            //Matrix44 transform2;
            //rotate(transform2, Vector3::yAxis(), 90);
            //Matrix44 translateX;
            //translate(translateX, 25.0f, 0.0f, 0.0f);
            //Matrix44 temp = transform2 * translateX * m_world;
            //m_rotatingblades2.setWorld(temp);
        }
    }

    return shaderInstance;
}
Esempio n. 13
0
void IndexBuffer::createBuffer( const DeviceManager& deviceManager, unsigned int bufferSize, void* data, bool dynamic, unsigned int bindFlag )
{
    D3D11_BUFFER_DESC bufferDescriptor;
    ZeroMemory(&bufferDescriptor, sizeof(D3D11_BUFFER_DESC));
    bufferDescriptor.Usage = D3D11_USAGE_IMMUTABLE;
    bufferDescriptor.ByteWidth = bufferSize;
    bufferDescriptor.BindFlags = bindFlag;
    bufferDescriptor.CPUAccessFlags = 0;
    bufferDescriptor.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA initData;
    ZeroMemory(&initData, sizeof(D3D11_SUBRESOURCE_DATA));
    initData.pSysMem = data;
    initData.SysMemPitch = 0;
    initData.SysMemSlicePitch = 0;

    HRESULT hr = deviceManager.getDevice()->CreateBuffer( &bufferDescriptor, &initData, &m_buffer );
    if (FAILED(hr))
    {
        MSG_TRACE_CHANNEL("INDEXBUFFER", "Failed to create a D3D11 Buffer object with code: 0x%x", hr );
    }

    dynamic = false;
}
Esempio n. 14
0
//-----------------------------------------------------------------------------
//! @brief   Initialise the application
//! @remark
//-----------------------------------------------------------------------------
bool Application::initialise()
{
    m_gameResource = new GameResource(&m_entityManager, &m_cameraSystem, &m_renderSystem.getDeviceMananger(), &m_settingsManager, &m_renderSystem.getTextureManager(), &m_gameObjectManager, &m_renderSystem.getModelManger(),
                                      &m_pfxManager, &m_lightManager, &m_laserManager, &m_shaderCache, &m_effectCache, &m_paths, &m_uiManager, nullptr, &m_logger, &m_physicsManger);


    m_logger.addLogger(new OutputDebugLog());
    FileLogger* file_logger = new FileLogger(m_paths.getLogPath());
    if (file_logger->is_open())
    {
        m_logger.addLogger(file_logger);
    }
    else
    {
        delete file_logger;
    }
    //m_logger.addLogger(new HttpDebugLog());
    
    //cache = new Text::TextBlockCache(1000, m_gameResource);
    
    bool returnValue = true;

    int windowWidth = 1280;
    int windowHeight = 720;
    const ISetting<int>* widthSetting = m_settingsManager.getSetting<int>("WindowWidth");
    if (widthSetting)
    {
        windowWidth = widthSetting->getData();     
    }
    const ISetting<int>* heightSetting = m_settingsManager.getSetting<int>("WindowHeight");
    if (heightSetting)
    {
        windowHeight = heightSetting->getData();     
    }
    m_projection = math::createLeftHandedFOVPerspectiveMatrix(math::gmPI / 4.0f, (float)windowWidth / (float)windowHeight, 0.1f, 10000.0f);

    SettingsParser settings(&m_settingsManager);
    if (!settings.loadFile(m_paths.getSettingsPath() + "settings.cfg"))
    {
        MSG_TRACE_CHANNEL("BASEAPPLICATION", "Failed to load the settings file" )
        //terminate application if we fail to find the settings file
        returnValue &= false;
    }

    //m_uiManager.initialise();
    m_renderSystem.initialise(m_gameResource);
    //m_inputSystem.createController(Gamepad);
    m_inputSystem.initialise(m_paths.getSettingsPath() + "Input Maps\\input_mapping.xml", m_renderSystem.getWindowHandle());
    m_inputDispatch = &InputSystem::SetRawInput;
    ShaderPack shaderPack(m_gameResource);
    shaderPack.loadShaderPack("shader_pack.xml");
    m_laserManager.initialise(m_gameResource);
	returnValue &= m_cameraSystem.createCamera(*m_gameResource, "global", Vector3(0.0f, 0.0f, 200.0f), Vector3(0.0f, 0.0f, 0.0f), Vector3::yAxis());
	returnValue &= m_cameraSystem.createCamera(*m_gameResource, "text_block_camera", Vector3(0.0f, 0.0f, 200.0f), Vector3(0.0f, 0.0f, 0.0f), Vector3::yAxis());
    returnValue &= m_cameraSystem.createCamera(*m_gameResource, "player_camera", Vector3(0.0f, 0.0f, 200.0f), Vector3(0.0f, 0.0f, 0.0f), Vector3::yAxis());
    Player* player = new Player(m_gameResource);
    player->initialize(m_cameraSystem);
    m_gameObjectManager.addGameObject(player);


    //Test Code
	m_cameraSystem.update(m_elapsedTime, m_time);
	const Camera* cam = m_cameraSystem.getCamera("global");
	m_view = cam->getCamera();

    //Text::BitmapFont bitmapFont;
    //bitmapFont.openFont("D:/SDK/Demo/SpaceSim/bin/FE/franklin.fnt.conv.fnt", m_gameResource);
    //cache->addFont("D:/SDK/Demo/SpaceSim/bin/FE/franklin.fnt.conv.fnt");
    //cache->addText("Hello World From Bitmap Font!", Vector4(0.f,0.f, 100.f, 500.f), Text::Align::left, bitmapFont.getFontInfo().m_fontNameHash, 48.0f, true);

    const ISetting<std::string>* mapFileName = m_settingsManager.getSetting<std::string>("SpaceStationMap");
    if (mapFileName)
    {
        returnValue &= m_map.loadMap(m_gameResource, mapFileName->getData());
    }

    MSG_TRACE_CHANNEL("BASEAPPLICATION", "Number of verts:  %d", Face::m_totalNumberOfVerts);
    MSG_TRACE_CHANNEL("BASEAPPLICATION", "Number of polies: %d", Face::m_totalNumberOfPolygons);

    return returnValue;
}