//----------------------------------------------------------------------------------------------- __declspec( noreturn ) void FatalError( const char* filePath, const char* functionName, int lineNum, const std::string& reasonForError, const char* conditionText ) { std::string errorMessage = reasonForError; if( reasonForError.empty() ) { if( conditionText ) errorMessage = Stringf( "ERROR: \"%s\" is false!", conditionText ); else errorMessage = "Unspecified fatal error"; } const char* fileName = FindStartOfFileNameWithinFilePath( filePath ); // std::string appName = theApplication ? theApplication->GetApplicationName() : "Unnamed Application"; std::string appName = "Unnamed Application"; std::string fullMessageTitle = appName + " :: Error"; std::string fullMessageText = errorMessage; fullMessageText += "\n\nThe application will now close.\n"; bool isDebuggerPresent = (IsDebuggerPresent() == TRUE); if( isDebuggerPresent ) { fullMessageText += "\nDEBUGGER DETECTED!\nWould you like to break and debug?\n (Yes=debug, No=quit)\n"; } fullMessageText += "\n---------- Debugging Details Follow ----------\n"; if( conditionText ) { fullMessageText += Stringf( "\nThis error was triggered by a run-time condition check:\n %s\n from %s(), line %i in %s\n", conditionText, functionName, lineNum, fileName ); } else { fullMessageText += Stringf( "\nThis was an unconditional error triggered by reaching\n line %i of %s, in %s()\n", lineNum, fileName, functionName ); } DebuggerPrintf( "\n==============================================================================\n" ); DebuggerPrintf( "RUN-TIME FATAL ERROR on line %i of %s, in %s()\n", lineNum, fileName, functionName ); DebuggerPrintf( "%s(%d): %s\n", filePath, lineNum, errorMessage.c_str() ); // Use this specific format so Visual Studio users can double-click to jump to file-and-line of error DebuggerPrintf( "==============================================================================\n\n" ); if( isDebuggerPresent ) { bool isAnswerYes = SystemDialogue_YesNo( fullMessageTitle, fullMessageText, SEVERITY_FATAL ); ShowCursor( TRUE ); if( isAnswerYes ) { __debugbreak(); } } else { SystemDialogue_Okay( fullMessageTitle, fullMessageText, SEVERITY_FATAL ); ShowCursor( TRUE ); } exit( 0 ); }
//----------------------------------------------------------------------------------- void TheGame::RenderCoolStuff() const { Matrix4x4 view = Renderer::instance->GetView(); Matrix4x4 proj = Renderer::instance->GetProjection(); Matrix4x4 translation; Matrix4x4 rotation; Matrix4x4 model; m_currentMaterial->m_shaderProgram->SetVec3Uniform("gCameraPosition", m_camera->m_position); Matrix4x4::MatrixMakeTranslation(&translation, Vector3(0.0f, sin((float)GetCurrentTimeSeconds()) * spinFactor, 3.0f)); Matrix4x4::MatrixMakeRotationAroundY(&rotation, (float)GetCurrentTimeSeconds() * spinFactor); Matrix4x4::MatrixMultiply(&model, &rotation, &translation); if ((g_loadedMotion || g_loadedMotions) && g_loadedSkeleton) { int NUM_BONES = 200; for (unsigned int i = 0; i < g_loadedSkeleton->m_jointArray.size(); ++i) { Matrix4x4 world = g_loadedSkeleton->GetWorldBoneToModelOutOfLocal(i); //g_loadedSkeleton->m_jointArray.at(i).m_boneToModelSpace; Matrix4x4 inverseWorld = g_loadedSkeleton->m_jointArray.at(i).m_modelToBoneSpace; //g_loadedSkeleton->GetWorldModelToBoneOutOfLocal(i); Matrix4x4 mat = Matrix4x4::IDENTITY; Matrix4x4::MatrixMultiply(&mat, &inverseWorld, &world); m_testMaterial->SetMatrix4x4Uniform(Stringf("gBoneMatrices[%i]", i).c_str(), mat, NUM_BONES); } } m_currentMaterial->SetMatrices(model, view, proj); GL_CHECK_ERROR(); loadedMesh->m_material = m_currentMaterial; loadedMesh->Render(); }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteBlockBegin( const char* optionalLabel ) { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) return; // absent in compact binary format if( !m_justWroteBlockBegin ) { if( m_consecutiveNewLineCount == 0 ) { WriteNewLine(); // end the previous line (if we were in the middle of one) } if( m_consecutiveNewLineCount <= 1 ) { WriteNewLine(); // make sure there's a blank line before each block } } if( optionalLabel ) { WriteStringIndentedIfNeeded( Stringf( ENDLINE_LABEL_FORMAT_STRING, optionalLabel ) ); WriteNewLine(); } WriteStringIndentedIfNeeded( "{" ); m_currentIndentationDepth ++; WriteNewLine(); m_justWroteBlockBegin = true; }
///----------------------------------------------------------------------- /// ///----------------------------------------------------------------------- void ReportXMLDocumentUsage( XMLNode& xmlDocumentToReport, const ResourceStream& resourceStream, bool reportUsed ) { UNUSED( reportUsed ); std::vector< XMLNode > unusedElements ; GetUnusedElements( xmlDocumentToReport, unusedElements ); if ( !unusedElements.empty() ) { std::string warningMessage = Stringf( "Unused elements in file: %s\n", resourceStream.GetJazzPath().c_str() ); for ( std::vector< XMLNode >::iterator xmlNodeIter = unusedElements.begin(); xmlNodeIter != unusedElements.end(); ++xmlNodeIter ) { XMLNode& unusedNode = (*xmlNodeIter); int stringSize = 0 ; char* nodeString = unusedNode.createXMLString( 1, &stringSize ); if ( nodeString ) { if ( stringSize > 2048 ) { nodeString[ 2040 ] = '.' ; nodeString[ 2041 ] = '.' ; nodeString[ 2042 ] = '.' ; nodeString[ 2043 ] = 0 ; } delete nodeString ; } } NamedProperties warningProperties ; warningProperties.Set( "Warning", warningMessage ); // FireEvent( "SystemWarningEvent", warningProperties ); } }
///---------------------------------------------------------- /// ///---------------------------------------------------------- std::string GetXMLErrorDescForErrorCode( XMLError xmlErrorCode ) { switch( xmlErrorCode ) { case eXMLErrorNone: case eXMLErrorMissingEndTag: return "MissingEndTag"; case eXMLErrorNoXMLTagFound: return "NoXMLTagFound"; case eXMLErrorEmpty: return "Empty"; case eXMLErrorMissingTagName: return "MissingTagName"; case eXMLErrorMissingEndTagName: return "MissingEndTagName"; case eXMLErrorUnmatchedEndTag: return "UnmatchedEndTag"; case eXMLErrorUnmatchedEndClearTag: return "UnmatchedEndClearTag"; case eXMLErrorUnexpectedToken: return "UnexpectedToken"; case eXMLErrorNoElements: return "NoElements"; case eXMLErrorFileNotFound: return "FileNotFound"; case eXMLErrorFirstTagNotFound: return "FirstTagNotFound"; case eXMLErrorUnknownCharacterEntity: return "UnknownCharacterEntity"; case eXMLErrorCharConversionError: return "CharConversionError"; case eXMLErrorCannotOpenWriteFile: return "CannotOpenWriteFile"; case eXMLErrorCannotWriteFile: return "CannotWriteFile"; case eXMLErrorBase64DataSizeIsNotMultipleOf4: return "Base64DataSizeIsNotMultipleOf4"; case eXMLErrorBase64DecodeIllegalCharacter: return "Base64DecodeIllegalCharacter"; case eXMLErrorBase64DecodeTruncatedData: return "Base64DecodeTruncatedData"; case eXMLErrorBase64DecodeBufferTooSmall: return "Base64DecodeBufferTooSmall"; default: return Stringf( "Unknown XML error code #%d", xmlErrorCode ); }; }
//----------------------------------------------------------------------------------------------- std::string ResourceStream::GetReadPositionContextIfInTextMode() { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) return std::string( "(Context unavailable; resource stream was in binary format)" ); int numCharsToReadBackward = 320; int numCharsToReadForward = 80; std::string currentLocationMarker( "[CURRENT READ LOCATION]" ); if( numCharsToReadBackward > m_currentReadOffset ) numCharsToReadBackward = m_currentReadOffset; if( numCharsToReadForward > DataBytesRemaining() ) numCharsToReadForward = DataBytesRemaining(); int startOffsetForReadBackward = m_currentReadOffset - numCharsToReadBackward; int startOffsetForReadForward = m_currentReadOffset; char* startOfCharacters = (char*) m_startOfData; std::string readBackward( &startOfCharacters[ startOffsetForReadBackward ], numCharsToReadBackward ); std::string readForward( &startOfCharacters[ startOffsetForReadForward ], numCharsToReadForward ); std::string fileName = m_jazzPath; std::string printFileName = fileName.length() == 0 ? "(unknown filename)" : fileName; std::string returnValue = Stringf( "Near line #%d of %s:\n\n%s%s%s\n", m_consecutiveNewLineCount, printFileName.c_str(), readBackward.c_str(), currentLocationMarker.c_str(), readForward.c_str() ); return returnValue; }
void Renderer::GLCheckError(const char* file, size_t line) { #ifdef CHECK_GL_ERRORS GLenum error = glGetError(); if (error != 0) { const char* errorText; switch (error) { case GL_INVALID_OPERATION: errorText = "INVALID_OPERATION"; break; case GL_INVALID_ENUM: errorText = "INVALID_ENUM"; break; case GL_INVALID_VALUE: errorText = "INVALID_VALUE"; break; case GL_INVALID_FRAMEBUFFER_OPERATION: errorText = "INVALID_FRAMEBUFFER_OPERATION"; break; case GL_OUT_OF_MEMORY: errorText = "OUT_OF_MEMORY"; break; default: errorText = "Invalid Enum Value, please debug."; break; } ERROR_RECOVERABLE(Stringf("OpenGL Error: %s\n File Name: %s at %i : \n", errorText, file, line)); } #endif }
//----------------------------------------------------------------------------------- SceneImport* FbxLoadSceneFromFile(const char* fbxFilename, const Matrix4x4& engineBasis, bool isEngineBasisRightHanded, const Matrix4x4& transform) { FbxScene* scene = nullptr; FbxManager* fbxManager = FbxManager::Create(); if (nullptr == fbxManager) { Console::instance->PrintLine("Could not create fbx manager."); DebuggerPrintf("Could not create fbx manager."); return nullptr; } FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager, IOSROOT); //Name of object is blank, we don't care fbxManager->SetIOSettings(ioSettings); //Create an importer FbxImporter* importer = FbxImporter::Create(fbxManager, ""); bool loadSuccessful = importer->Initialize(fbxFilename, -1, fbxManager->GetIOSettings()); if (loadSuccessful) { //We have imported the FBX scene = FbxScene::Create(fbxManager, ""); bool importSuccessful = importer->Import(scene); ASSERT_OR_DIE(importSuccessful, "Scene import failed!"); } else { Console::instance->PrintLine(Stringf("Could not import scene: %s", fbxFilename)); DebuggerPrintf("Could not import scene: %s", fbxFilename); } SceneImport* import = new SceneImport(); MatrixStack4x4 matrixStack; matrixStack.Push(transform); //Set up our initial transforms Matrix4x4 sceneBasis = GetSceneBasis(scene); Matrix4x4::MatrixTranspose(&sceneBasis); if (!isEngineBasisRightHanded) { Vector3 forward = Matrix4x4::MatrixGetForward(&sceneBasis); Matrix4x4::MatrixSetForward(&sceneBasis, -forward); //3rd row or column } matrixStack.Push(sceneBasis); ImportScene(import, scene, matrixStack); FBX_SAFE_DESTROY(importer); FBX_SAFE_DESTROY(ioSettings); FBX_SAFE_DESTROY(scene); FBX_SAFE_DESTROY(fbxManager); return import; }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteLineEndIfVerbose( const char* optionalLabel ) { if( m_internalFormat != RESOURCE_STREAM_FORMAT_TEXT_VERBOSE ) return; if( optionalLabel ) { WriteStringDirectly( Stringf( ENDLINE_LABEL_FORMAT_STRING, optionalLabel ) ); } WriteNewLine(); }
//----------------------------------------------------------------------------------- static void PrintNode(FbxNode* node, int depth) { Console::instance->PrintLine(Stringf("%*sNode [%s]\n", depth, " ", node->GetName())); DebuggerPrintf("%*sNode [%s]\n", depth, " ", node->GetName()); for (int i = 0; i < node->GetNodeAttributeCount(); ++i) { PrintAttribute(node->GetNodeAttributeByIndex(i), depth); } for (int i = 0; i < node->GetChildCount(); ++i) { PrintNode(node->GetChild(i), depth + 1); } }
//----------------------------------------------------------------------------------- void MemoryAnalyticsShutdown() { //Walk the list of callstacks, print them all out. This is what you haven't freed //Can bucketize the callstacks into unique callstack hash lists, then print the # of reports you got if (g_memoryAnalytics.m_numberOfAllocations > g_memoryAnalytics.m_startupNumberOfAllocations) { ERROR_RECOVERABLE(Stringf("Leaked a total of %i bytes, from %i individual leaks. %i of these were from before startup.\n[Press enter to continue]", g_memoryAnalytics.m_numberOfBytes, g_memoryAnalytics.m_numberOfAllocations, g_memoryAnalytics.m_startupNumberOfAllocations)); MemoryMetadata::PrintAllMetadataInList(); } if (g_memoryAnalytics.m_numberOfShaderAllocations != 0) { ERROR_RECOVERABLE(Stringf("Leaked a total of %i shaders.\n[Press enter to continue]", g_memoryAnalytics.m_numberOfShaderAllocations)); } if (g_memoryAnalytics.m_numberOfVAOAllocations != 0) { ERROR_RECOVERABLE(Stringf("Leaked a total of %i VAOs.\n[Press enter to continue]", g_memoryAnalytics.m_numberOfVAOAllocations)); } if (g_memoryAnalytics.m_numberOfRenderBufferAllocations != 0) { ERROR_RECOVERABLE(Stringf("Leaked a total of %i Render Buffers.\n[Press enter to continue]", g_memoryAnalytics.m_numberOfRenderBufferAllocations)); } g_memoryAnalytics.Shutdown(); }
//----------------------------------------------------------------------------------- static void PrintAttribute(FbxNodeAttribute* attribute, int depth) { if (attribute == nullptr) { return; } FbxNodeAttribute::EType type = attribute->GetAttributeType(); const char* typeName = GetAttributeTypeName(type); const char* attribName = attribute->GetName(); Console::instance->PrintLine(Stringf("%*s- type='%s', name='%s'\n", depth, " ", typeName, attribName)); DebuggerPrintf("%*s- type='%s', name='%s'\n", depth, " ", typeName, attribName); }
//----------------------------------------------------------------------------------------------- void ResourceStream::WriteNewLine( const char* optionalLabel ) { if( m_internalFormat == RESOURCE_STREAM_FORMAT_BINARY ) return; // absent in compact binary format if( optionalLabel && m_internalFormat == RESOURCE_STREAM_FORMAT_TEXT_TERSE ) // if( optionalLabel ) { WriteStringIndentedIfNeeded( Stringf( ENDLINE_LABEL_FORMAT_STRING, optionalLabel ) ); } WriteStringDirectly( "\r\n" ); m_consecutiveNewLineCount ++; }
///---------------------------------------------------------- /// ///---------------------------------------------------------- void ReportXMLError( const ResourceStream& resourceStream, XMLNode xmlDocumentRootNode, XMLResults errorResult ) { if( errorResult.error == eXMLErrorNone ) return; const std::string shortFileName = resourceStream.GetJazzPath(); const std::string longFileName = resourceStream.GetJazzPath(); std::string errorTitle = "XML Data File Error"; std::string errorText = Stringf( "Error in XML data file \"%s\":\n", longFileName.c_str() ); bool locateErrorInText = true; const std::string errorName = GetXMLErrorDescForErrorCode( errorResult.error ); std::string errorDescription = Stringf( "\n *** %s ***\n", errorName.c_str() ); // if( errorResult == eXMLErrorUnexpectedToken ) // { // Set "errorDescription" here to be as specific as you need to be, for each particular error // } errorText += errorDescription; if( locateErrorInText ) { errorText += Stringf( "\nError location: line %d (column %d) of %s\n", errorResult.nLine, errorResult.nColumn, shortFileName.c_str() ); const std::string errorLine = resourceStream.FetchLine( errorResult.nLine ); std::string errorLinePartial( errorLine, 0, errorResult.nColumn-1 ); errorText += Stringf( "\nLine %d is probably:\n%s\n", errorResult.nLine, errorLine.c_str() ); if( errorLinePartial.length() < errorLine.length() ) { errorText += Stringf( "\n...and the error occurred somewhere in this initial section:\n%s <== ERROR HERE\n", errorLinePartial.c_str() ); } } //{ int q = 5; } //JAZZ_ERROR( errorTitle, errorText ); }
//----------------------------------------------------------------------------------- GenerationProcessData::GenerationProcessData(const XMLNode& node) { m_generatorName = XMLUtils::GetAttribute(node, "generator"); std::string stepString = XMLUtils::GetAttribute(node, "steps"); std::vector<std::string>* numbers = SplitString(stepString, "~"); if (numbers->size() == 1) { int numberOfSteps = stoi(numbers->at(0)); m_rangeSteps = Vector2Int(numberOfSteps, numberOfSteps); } else if (numbers->size() == 2) { m_rangeSteps = Vector2Int(stoi(numbers->at(0)), stoi(numbers->at(1))); } else { ERROR_AND_DIE(Stringf("Range data was invalid for generator %s", m_generatorName.c_str())); } }
//----------------------------------------------------------------------------------- void TheGame::RenderMapSelection() { Vector2 offset = Vector2(0.0f, 750.0f); Renderer::instance->DrawText2D(offset, "Available Quests:", 3.0f, RGBA::VAPORWAVE, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); char indexCharacter = 'A'; for (auto iterator = EnvironmentBlueprint::s_envirnomentBlueprints.begin(); iterator != EnvironmentBlueprint::s_envirnomentBlueprints.end(); ++iterator) { offset += Vector2(0, -120); std::string str = iterator->first; Renderer::instance->DrawText2D(offset, Stringf("%c) %s", indexCharacter++, str.c_str()), 3.0f, RGBA::VAPORWAVE, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); } if (m_autoGenerate) { Renderer::instance->DrawText2D(Vector2(1000, 0.0f), "Auto Generate", 3.0f, RGBA::SEA_GREEN, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); } else { Renderer::instance->DrawText2D(Vector2(1000, 0.0f), "Manual Generate", 3.0f, RGBA::RED, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); } }
//----------------------------------------------------------------------------------- void FbxListScene(const char* filename) { FbxManager* fbxManager = FbxManager::Create(); if (nullptr == fbxManager) { Console::instance->PrintLine("Could not create fbx manager."); DebuggerPrintf("Could not create fbx manager."); return; } FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager, IOSROOT); //Name of object is blank, we don't care fbxManager->SetIOSettings(ioSettings); //Create an importer FbxImporter* importer = FbxImporter::Create(fbxManager, ""); bool loadSuccessful = importer->Initialize(filename, -1, fbxManager->GetIOSettings()); if (loadSuccessful) { //We have imported the FBX FbxScene* scene = FbxScene::Create(fbxManager, ""); bool importSuccessful = importer->Import(scene); if (importSuccessful) { FbxNode* root = scene->GetRootNode(); PrintNode(root, 0); } FBX_SAFE_DESTROY(scene); } else { Console::instance->PrintLine(Stringf("Could not import scene: %s", filename)); DebuggerPrintf("Could not import scene: %s", filename); } FBX_SAFE_DESTROY(importer); FBX_SAFE_DESTROY(ioSettings); FBX_SAFE_DESTROY(fbxManager); }
//----------------------------------------------------------------------------------- void TheGame::Update(float deltaTime) { DebugRenderer::instance->Update(deltaTime); if (InputSystem::instance->WasKeyJustPressed(InputSystem::ExtraKeys::TILDE)) { Console::instance->ActivateConsole(); } if (Console::instance->IsActive()) { return; //Don't do anything involving input updates. } UpdateCamera(deltaTime); for (int i = 0; i < 16; i++) { m_lightPositions[i] = Vector3(sinf(static_cast<float>(GetCurrentTimeSeconds() + i)) * 5.0f, cosf(static_cast<float>(GetCurrentTimeSeconds() + i) / 2.0f) * 3.0f, 0.5f); m_lights[i].SetPosition(m_lightPositions[i]); m_currentMaterial->m_shaderProgram->SetVec3Uniform(Stringf("gLightPosition[%i]", i).c_str(), m_lightPositions[i], 16); } if (InputSystem::instance->WasKeyJustPressed('O')) { m_renderAxisLines = !m_renderAxisLines; } if (InputSystem::instance->WasKeyJustPressed('1')) { MeshBuilder builder; MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP); builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50, [](const void* userData, float x, float y) { MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData; Vector3 position = plane->initialPosition + (plane->right * x) + (plane->up * y); return position; } , data); builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO); spinFactor = 0.0f; } if (InputSystem::instance->WasKeyJustPressed('2')) { MeshBuilder builder; MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP); builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50, [](const void* userData, float x, float y) { MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData; Vector3 position = plane->initialPosition + (plane->right * x) + (plane->up * y); position.z = sin(x + y); return position; } , data); builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO); spinFactor = 0.0f; } if (InputSystem::instance->WasKeyJustPressed('3')) { MeshBuilder builder; MeshBuilder::PlaneData* data = new MeshBuilder::PlaneData(Vector3::ZERO, Vector3::RIGHT, Vector3::UP); builder.BuildPatch(-5.0f, 5.0f, 50, -5.0f, 5.0f, 50, [](const void* userData, float x, float y) { MeshBuilder::PlaneData const *plane = (MeshBuilder::PlaneData const*)userData; Vector3 position = plane->initialPosition + (plane->right * x) + (plane->up * y); position.z = .05f * -cos(((float)GetCurrentTimeSeconds() * 4.0f) + (Vector2(x, y).CalculateMagnitude() * 100.0f)); return position; } , data); builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO); spinFactor = 0.0f; } if (InputSystem::instance->WasKeyJustPressed('4')) { FbxListScene("Data/FBX/SampleBox.fbx"); } if (InputSystem::instance->WasKeyJustPressed('5')) { Console::instance->RunCommand("fbxLoad Data/FBX/unitychan.fbx"); } if (InputSystem::instance->WasKeyJustPressed('6')) { Console::instance->RunCommand("fbxLoad Data/FBX/samplebox.fbx"); } if (InputSystem::instance->WasKeyJustPressed('7')) { Console::instance->RunCommand("saveMesh saveFile.picomesh"); } if (InputSystem::instance->WasKeyJustPressed('8')) { Console::instance->RunCommand("loadMesh saveFile.picomesh"); } if (g_loadedMesh != nullptr) { loadedMesh->m_mesh = g_loadedMesh; } if (InputSystem::instance->WasKeyJustPressed('B')) { m_currentMaterial = m_testMaterial; } else if (InputSystem::instance->WasKeyJustPressed('N')) { m_currentMaterial = m_normalDebugMaterial; } else if (InputSystem::instance->WasKeyJustPressed('U')) { m_currentMaterial = m_uvDebugMaterial; } if(InputSystem::instance->WasKeyJustPressed('K')) { m_showSkeleton = !m_showSkeleton; } if (InputSystem::instance->WasKeyJustPressed('I') && g_loadedMotion != nullptr) { g_loadedMotion->m_playbackMode = AnimationMotion::CLAMP; } else if (InputSystem::instance->WasKeyJustPressed('L') && g_loadedMotion != nullptr) { g_loadedMotion->m_playbackMode = AnimationMotion::LOOP; } else if (InputSystem::instance->WasKeyJustPressed('P') && g_loadedMotion != nullptr) { g_loadedMotion->m_playbackMode = AnimationMotion::PING_PONG; } else if (InputSystem::instance->WasKeyJustPressed('O') && g_loadedMotion != nullptr) { g_loadedMotion->m_playbackMode = AnimationMotion::PAUSED; } quadForFBO->m_material->SetFloatUniform("gTime", (float)GetCurrentTimeSeconds()); }
//----------------------------------------------------------------------------------------------- bool ResourceStream::CheckExpectedToken( char tokenCharacter ) { return CheckExpectedToken( Stringf( "%c", tokenCharacter ) ); }
std::string Dice::ToString() { return Stringf("%id%i%c%i", m_numDice, m_numSides, m_bonusModifier < 0 ? '-' : '+', (int)abs(m_bonusModifier)); }
//----------------------------------------------------------------------------------------------- void RecoverableWarning( const char* filePath, const char* functionName, int lineNum, const std::string& reasonForWarning, const char* conditionText ) { std::string errorMessage = reasonForWarning; if( reasonForWarning.empty() ) { if( conditionText ) errorMessage = Stringf( "WARNING: \"%s\" is false!", conditionText ); else errorMessage = "Unspecified warning"; } const char* fileName = FindStartOfFileNameWithinFilePath( filePath ); // std::string appName = theApplication ? theApplication->GetApplicationName() : "Unnamed Application"; std::string appName = "Unnamed Application"; std::string fullMessageTitle = appName + " :: Warning"; std::string fullMessageText = errorMessage; bool isDebuggerPresent = (IsDebuggerPresent() == TRUE); if( isDebuggerPresent ) { fullMessageText += "\n\nDEBUGGER DETECTED!\nWould you like to continue running?\n (Yes=continue, No=quit, Cancel=debug)\n"; } else { fullMessageText += "\n\nWould you like to continue running?\n (Yes=continue, No=quit)\n"; } fullMessageText += "\n---------- Debugging Details Follow ----------\n"; if( conditionText ) { fullMessageText += Stringf( "\nThis warning was triggered by a run-time condition check:\n %s\n from %s(), line %i in %s\n", conditionText, functionName, lineNum, fileName ); } else { fullMessageText += Stringf( "\nThis was an unconditional warning triggered by reaching\n line %i of %s, in %s()\n", lineNum, fileName, functionName ); } DebuggerPrintf( "\n------------------------------------------------------------------------------\n" ); DebuggerPrintf( "RUN-TIME RECOVERABLE WARNING on line %i of %s, in %s()\n", lineNum, fileName, functionName ); DebuggerPrintf( "%s(%d): %s\n", filePath, lineNum, errorMessage.c_str() ); // Use this specific format so Visual Studio users can double-click to jump to file-and-line of error DebuggerPrintf( "------------------------------------------------------------------------------\n\n" ); if( isDebuggerPresent ) { int answerCode = SystemDialogue_YesNoCancel( fullMessageTitle, fullMessageText, SEVERITY_WARNING ); ShowCursor( TRUE ); if( answerCode == 0 ) // "NO" { exit( 0 ); } else if( answerCode == -1 ) // "CANCEL" { __debugbreak(); } } else { bool isAnswerYes = SystemDialogue_YesNo( fullMessageTitle, fullMessageText, SEVERITY_WARNING ); ShowCursor( TRUE ); if( !isAnswerYes ) { exit( 0 ); } } }
//----------------------------------------------------------------------------------- void TheGame::SetUpShader() { m_testMaterial = new Material( new ShaderProgram("Data/Shaders/SkinDebug.vert", "Data/Shaders/SkinDebug.frag"), //fixedVertexFormat timeBased basicLight multiLight RenderState(RenderState::DepthTestingMode::ON, RenderState::FaceCullingMode::CULL_BACK_FACES, RenderState::BlendMode::ALPHA_BLEND) ); m_uvDebugMaterial = new Material( new ShaderProgram("Data/Shaders/basicLight.vert", "Data/Shaders/uvDebug.frag"), RenderState(RenderState::DepthTestingMode::ON, RenderState::FaceCullingMode::CULL_BACK_FACES, RenderState::BlendMode::ALPHA_BLEND) ); m_normalDebugMaterial = new Material( new ShaderProgram("Data/Shaders/basicLight.vert", "Data/Shaders/normalDebug.frag"), RenderState(RenderState::DepthTestingMode::ON, RenderState::FaceCullingMode::CULL_BACK_FACES, RenderState::BlendMode::ALPHA_BLEND) ); m_testMaterial->SetDiffuseTexture("Data/Images/stone_diffuse.png"); m_testMaterial->SetNormalTexture("Data/Images/stone_normal.png"); m_testMaterial->SetEmissiveTexture("Data/Images/pattern_81/maymay.tga"); m_testMaterial->SetNoiseTexture("Data/Images/perlinNoise.png"); m_testMaterial->SetVec4Uniform("gDissolveColor", Vector4(0.0f, 1.0f, 0.3f, 1.0f)); m_testMaterial->SetVec4Uniform("gColor", Vector4(1.0f, 1.0f, 1.0f, 1.0f)); m_testMaterial->SetVec4Uniform("gAmbientLight", Vector4(1.0f, 1.0f, 1.0f, 0.0f)); m_testMaterial->SetFloatUniform("gSpecularPower", 16.0f); m_testMaterial->SetFloatUniform("gSpecularIntensity", 0.5f); //0 to 1 m_testMaterial->SetVec4Uniform("gFogColor", Vector4(0.7f, 0.7f, 0.7f, 1.0f)); m_testMaterial->SetFloatUniform("gMinFogDistance", 10.0f); m_testMaterial->SetFloatUniform("gMaxFogDistance", 20.0f); m_testMaterial->SetIntUniform("gLightCount", NUM_LIGHTS); lightMaterial = new Material( new ShaderProgram("Data/Shaders/fixedVertexFormat.vert", "Data/Shaders/fixedVertexFormat.frag"), //fixedVertexFormat timeBased basicLight RenderState(RenderState::DepthTestingMode::ON, RenderState::FaceCullingMode::CULL_BACK_FACES, RenderState::BlendMode::ALPHA_BLEND) ); lightMaterial->SetDiffuseTexture(Renderer::instance->m_defaultTexture); //Set all attributes of the arrays to default values for (int i = 0; i < 16; i++) { m_lightPositions[i] = Vector3::ZERO; m_lightDirections[i] = Vector3::FORWARD; m_lightDirectionFactor[i] = 0.0f; m_nearPower[i] = 1.0f; m_farPower[i] = 1.0f; m_nearDistance[i] = 2.0f; m_farDistance[i] = 6.0f; m_innerPower[i] = 1.0f; m_outerPower[i] = 1.0f; m_innerAngle[i] = 1.0f; m_outerAngle[i] = -1.0f; m_lightColors[i] = RGBA::BLACK.ToVec4(); //i % 2 == 0 ? RGBA::RED.ToVec4() : RGBA::BLUE.ToVec4();// } //Initialize the lights for the demo // m_lights[0] = Light(Vector3::ZERO, RGBA(RGBA::RED), lightMaterial); // m_lights[0].ConvertToLocalPointLight(2.0f, 6.0f, 1.0f, 0.0f); // m_lights[1] = Light(Vector3::ZERO, RGBA(RGBA::GREEN), lightMaterial); // m_lights[1].ConvertToGlobalDirectLight(Vector3::FORWARD, 2.0f, 6.0f); //Initialize the arrays with our values for (int i = 0; i < NUM_LIGHTS; i++) { m_lightColors[i] = m_lights[i].GetColor(); m_lightDirections[i] = m_lights[i].GetDirection(); m_lightDirectionFactor[i] = m_lights[i].IsDirectional() ? 1.0f : 0.0f; m_nearPower[i] = m_lights[i].GetNearPower(); m_farPower[i] = m_lights[i].GetFarPower(); m_nearDistance[i] = m_lights[i].GetNearDistance(); m_farDistance[i] = m_lights[i].GetFarDistance(); m_innerPower[i] = m_lights[i].GetInnerPower(); m_outerPower[i] = m_lights[i].GetOuterPower(); m_innerAngle[i] = m_lights[i].GetInnerAngle(); m_outerAngle[i] = m_lights[i].GetOuterAngle(); } for (int i = 0; i < NUM_LIGHTS; i++) { m_testMaterial->SetVec4Uniform(Stringf("gLightColor[%i]", i).c_str(), m_lightColors[i], 16); m_testMaterial->SetVec3Uniform(Stringf("gLightDirection[%i]", i).c_str(), m_lightDirections[i], 16); m_testMaterial->SetFloatUniform(Stringf("gLightDirectionFactor[%i]", i).c_str(), m_lightDirectionFactor[i], 16); m_testMaterial->SetFloatUniform(Stringf("gNearPower[%i]", i).c_str(), m_nearPower[i], 16); m_testMaterial->SetFloatUniform(Stringf("gFarPower[%i]", i).c_str(), m_farPower[i], 16); m_testMaterial->SetFloatUniform(Stringf("gNearDistance[%i]", i).c_str(), m_nearDistance[i], 16); m_testMaterial->SetFloatUniform(Stringf("gFarDistance[%i]", i).c_str(), m_farDistance[i], 16); m_testMaterial->SetFloatUniform(Stringf("gInnerPower[%i]", i).c_str(), m_innerPower[i], 16); m_testMaterial->SetFloatUniform(Stringf("gOuterPower[%i]", i).c_str(), m_outerPower[i], 16); m_testMaterial->SetFloatUniform(Stringf("gInnerAngle[%i]", i).c_str(), m_innerAngle[i], 16); m_testMaterial->SetFloatUniform(Stringf("gOuterAngle[%i]", i).c_str(), m_outerAngle[i], 16); } m_currentMaterial = m_testMaterial; MeshBuilder builder; builder.AddCube(2.0f); //Lol more blatant memory leaks fml loadedMesh = new MeshRenderer(new Mesh(), m_currentMaterial); builder.CopyToMesh(loadedMesh->m_mesh, &Vertex_SkinnedPCTN::Copy, sizeof(Vertex_SkinnedPCTN), &Vertex_SkinnedPCTN::BindMeshToVAO); m_uvDebugMaterial->SetDiffuseTexture(Renderer::instance->m_defaultTexture); m_uvDebugMaterial->SetNormalTexture(Renderer::instance->m_defaultTexture); m_uvDebugMaterial->SetEmissiveTexture("Data/Images/pattern_81/maymay.tga"); m_uvDebugMaterial->SetNoiseTexture("Data/Images/perlinNoise.png"); m_uvDebugMaterial->SetVec4Uniform("gDissolveColor", Vector4(0.0f, 1.0f, 0.3f, 1.0f)); m_uvDebugMaterial->SetVec4Uniform("gColor", Vector4(1.0f, 1.0f, 1.0f, 1.0f)); m_uvDebugMaterial->SetVec4Uniform("gAmbientLight", Vector4(1.0f, 1.0f, 1.0f, 0.0f)); m_uvDebugMaterial->SetFloatUniform("gSpecularPower", 16.0f); m_uvDebugMaterial->SetFloatUniform("gSpecularIntensity", 0.5f); //0 to 1 m_uvDebugMaterial->SetVec4Uniform("gFogColor", Vector4(0.7f, 0.7f, 0.7f, 1.0f)); m_uvDebugMaterial->SetFloatUniform("gMinFogDistance", 10.0f); m_uvDebugMaterial->SetFloatUniform("gMaxFogDistance", 20.0f); m_uvDebugMaterial->SetIntUniform("gLightCount", NUM_LIGHTS); for (int i = 0; i < NUM_LIGHTS; i++) { m_uvDebugMaterial->SetVec4Uniform(Stringf("gLightColor[%i]", i).c_str(), m_lightColors[i], 16); m_uvDebugMaterial->SetVec3Uniform(Stringf("gLightDirection[%i]", i).c_str(), m_lightDirections[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gLightDirectionFactor[%i]", i).c_str(), m_lightDirectionFactor[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gNearPower[%i]", i).c_str(), m_nearPower[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gFarPower[%i]", i).c_str(), m_farPower[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gNearDistance[%i]", i).c_str(), m_nearDistance[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gFarDistance[%i]", i).c_str(), m_farDistance[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gInnerPower[%i]", i).c_str(), m_innerPower[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gOuterPower[%i]", i).c_str(), m_outerPower[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gInnerAngle[%i]", i).c_str(), m_innerAngle[i], 16); m_uvDebugMaterial->SetFloatUniform(Stringf("gOuterAngle[%i]", i).c_str(), m_outerAngle[i], 16); } m_normalDebugMaterial->SetDiffuseTexture("Data/Images/stone_diffuse.png"); m_normalDebugMaterial->SetNormalTexture("Data/Images/stone_normal.png"); m_normalDebugMaterial->SetEmissiveTexture("Data/Images/pattern_81/maymay.tga"); m_normalDebugMaterial->SetNoiseTexture("Data/Images/perlinNoise.png"); m_normalDebugMaterial->SetVec4Uniform("gDissolveColor", Vector4(0.0f, 1.0f, 0.3f, 1.0f)); m_normalDebugMaterial->SetVec4Uniform("gColor", Vector4(1.0f, 1.0f, 1.0f, 1.0f)); m_normalDebugMaterial->SetVec4Uniform("gAmbientLight", Vector4(1.0f, 1.0f, 1.0f, 0.0f)); m_normalDebugMaterial->SetFloatUniform("gSpecularPower", 16.0f); m_normalDebugMaterial->SetFloatUniform("gSpecularIntensity", 0.5f); //0 to 1 m_normalDebugMaterial->SetVec4Uniform("gFogColor", Vector4(0.7f, 0.7f, 0.7f, 1.0f)); m_normalDebugMaterial->SetFloatUniform("gMinFogDistance", 10.0f); m_normalDebugMaterial->SetFloatUniform("gMaxFogDistance", 20.0f); m_normalDebugMaterial->SetIntUniform("gLightCount", NUM_LIGHTS); for (int i = 0; i < NUM_LIGHTS; i++) { m_normalDebugMaterial->SetVec4Uniform(Stringf("gLightColor[%i]", i).c_str(), m_lightColors[i], 16); m_normalDebugMaterial->SetVec3Uniform(Stringf("gLightDirection[%i]", i).c_str(), m_lightDirections[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gLightDirectionFactor[%i]", i).c_str(), m_lightDirectionFactor[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gNearPower[%i]", i).c_str(), m_nearPower[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gFarPower[%i]", i).c_str(), m_farPower[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gNearDistance[%i]", i).c_str(), m_nearDistance[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gFarDistance[%i]", i).c_str(), m_farDistance[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gInnerPower[%i]", i).c_str(), m_innerPower[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gOuterPower[%i]", i).c_str(), m_outerPower[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gInnerAngle[%i]", i).c_str(), m_innerAngle[i], 16); m_normalDebugMaterial->SetFloatUniform(Stringf("gOuterAngle[%i]", i).c_str(), m_outerAngle[i], 16); } int NUM_BONES = 200; Matrix4x4 mat = Matrix4x4::IDENTITY; for (int i = 0; i < NUM_BONES; ++i) { m_testMaterial->SetMatrix4x4Uniform(Stringf("gBoneMatrices[%i]", i).c_str(), mat, NUM_BONES); } }