void FProvider::Tick() { bool bNotifyStateChanged = false; // remove commands that have finished executing from the queue for (int32 i = 0; i < CommandQueue.Num(); ++i) { FCommandQueueEntry CommandQueueEntry = CommandQueue[i]; auto* Command = CommandQueueEntry.Command; if (Command->HasExecuted()) { CommandQueue.RemoveAt(i); bNotifyStateChanged = Command->UpdateStates(); LogErrors(Command->ErrorMessages); Command->NotifyOperationComplete(); if (CommandQueueEntry.bAutoDelete) { delete Command; } // NotifyOperationComplete() may indirectly alter the command queue // so the loop must stop here, the queue cleanup will resume on the // next tick. break; } } if (bNotifyStateChanged) { OnSourceControlStateChanged.Broadcast(); } }
bool CScript::RunFile( WideString a_fileName ) { FILE* scriptFile = NULL; char* fileString = NULL; int fileSize = 0; bool result = true; //a_fileName = APP.useFile( wide2string(a_fileName).c_str() ).c_str(); a_fileName = wide2string( a_fileName ).c_str(); GM_ASSERT( this ); if ( APP.DebugMode ) { WideString winfo = "Loading script file "; winfo += a_fileName; CONSOLE.add( winfo ); } char* ResultChar = new char[1024]; wcstombs( ResultChar, a_fileName.c_str(), 1024 ); if ( !( scriptFile = fopen( ResultChar, "rb" ) ) ) { return false; } fseek( scriptFile, 0, SEEK_END ); fileSize = ftell( scriptFile ); fseek( scriptFile, 0, SEEK_SET ); fileString = new char[fileSize + 1]; fread( fileString, fileSize, 1, scriptFile ); fileString[fileSize] = 0; // Terminating null fclose( scriptFile ); int threadId = GM_INVALID_THREAD; errors = machine->ExecuteString( fileString, &threadId, true, ResultChar ); if ( errors ) { WideString a; a = "Script error: "; a.append( a_fileName ); LogErrors( a ); result = false; } deltaTime = 1; lastTime = getPreciseTime(); delete[] fileString; delete ResultChar; return result; }
bool CScript::Run() { if ( machine->Execute( deltaTime ) ) { // Update delta time curTime = getPreciseTime(); deltaTime = curTime - lastTime; lastTime = curTime; // Dump run time errors to output LogErrors( "Script error: runtime" ); } return true; }
ECommandResult::Type FProvider::ExecuteCommand(FCommand* Command, bool bAutoDelete) { if (GThreadPool) { GThreadPool->AddQueuedWork(Command); CommandQueue.Add({Command, bAutoDelete}); return ECommandResult::Succeeded; } else // fall back to synchronous execution { Command->DoWork(); Command->UpdateStates(); LogErrors(Command->ErrorMessages); Command->NotifyOperationComplete(); auto Result = Command->GetResult(); if (bAutoDelete) { delete Command; } return Result; } }
bool CScript::RunString( WideString a_string ) { GM_ASSERT( this ); int threadId = GM_INVALID_THREAD; char* ResultChar = new char[1024]; wcstombs( ResultChar, a_string.c_str(), 1024 ); errors = machine->ExecuteString( ResultChar, &threadId, true ); if ( errors ) { WideString a; a = "Script error: "; a.append( a_string ); LogErrors( a ); } deltaTime = 1; lastTime = getPreciseTime(); delete ResultChar; return true; }
void teShader::BuildPass(EShaderPass passType) { const c8 * passTypeString = NULL; switch(passType) { case SP_GEN_DIFFUSE: passTypeString = "#define TE_PASS_DIFFUSE\n"; break; case SP_USER_0: passTypeString = "#define TE_PASS_USER_0\n"; break; case SP_USER_1: passTypeString = "#define TE_PASS_USER_1\n"; break; case SP_USER_2: passTypeString = "#define TE_PASS_USER_2\n"; break; case SP_USER_3: passTypeString = "#define TE_PASS_USER_3\n"; break; default: TE_ASSERT_NODEBUG(0); break; } const u8 serviceStrings = 6; GLuint shaderVS = tglCreateShader(GL_VERTEX_SHADER); const c8 * sourceVSc[serviceStrings]; GLint sourceVSl[serviceStrings]; #if defined (TE_PLATFORM_IPHONE) sourceVSc[0] = "\n"; #else sourceVSc[0] = "#version 120\n"; #endif sourceVSc[1] = "#define TE_VS\n"; #if defined (TE_PLATFORM_IPHONE) sourceVSc[2] = "precision mediump int;\nprecision mediump float;\n#define TE_TEXP highp\n"; #else sourceVSc[2] = "#define TE_TEXP\n"; #endif sourceVSc[3] = passTypeString; sourceVSc[4] = source.c_str(); sourceVSc[5] = "\n"; for(u8 i = 0; i < serviceStrings; ++i) sourceVSl[i] = strlen(sourceVSc[i]); tglShaderSource(shaderVS, serviceStrings, sourceVSc, sourceVSl); tglCompileShader(shaderVS); LogErrors("compile VS", shaderVS); GLuint shaderFS = tglCreateShader(GL_FRAGMENT_SHADER); const c8 * sourceFSc[serviceStrings]; GLint sourceFSl[serviceStrings]; #if defined (TE_PLATFORM_IPHONE) sourceFSc[0] = "\n"; #else sourceFSc[0] = "#version 120\n"; #endif sourceFSc[1] = "#define TE_FS\n"; #if defined (TE_PLATFORM_IPHONE) sourceFSc[2] = "precision lowp int;\nprecision lowp float;\n#define TE_TEXP highp\n"; #else sourceFSc[2] = "#define TE_TEXP\n"; #endif sourceFSc[3] = passTypeString; sourceFSc[4] = source.c_str(); sourceFSc[5] = "\n"; for(u8 i = 0; i < serviceStrings; ++i) sourceFSl[i] = strlen(sourceFSc[i]); tglShaderSource(shaderFS, serviceStrings, sourceFSc, sourceFSl); tglCompileShader(shaderFS); LogErrors("compile FS", shaderFS); if(pass[passType].program) tglDeleteProgram(pass[passType].program); pass[passType].program = tglCreateProgram(); tglAttachShader(pass[passType].program, shaderVS); tglAttachShader(pass[passType].program, shaderFS); tglLinkProgram(pass[passType].program); tglDeleteShader(shaderVS); tglDeleteShader(shaderFS); LogErrors("link", 0, pass[passType].program); tglUseProgram(pass[passType].program); pass[passType].attributes[SLT_POSITION] = tglGetAttribLocation(pass[passType].program, "tePosition"); pass[passType].attributes[SLT_NORMAL] = tglGetAttribLocation(pass[passType].program, "teNormal"); pass[passType].attributes[SLT_UV_0] = tglGetAttribLocation(pass[passType].program, "teUV0"); pass[passType].attributes[SLT_UV_1] = tglGetAttribLocation(pass[passType].program, "teUV1"); pass[passType].attributes[SLT_UV_2] = tglGetAttribLocation(pass[passType].program, "teUV2"); pass[passType].attributes[SLT_UV_3] = tglGetAttribLocation(pass[passType].program, "teUV3"); pass[passType].attributes[SLT_COLOR] = tglGetAttribLocation(pass[passType].program, "teColor"); pass[passType].attributes[SLT_TANGENT] = tglGetAttribLocation(pass[passType].program, "teTangent"); pass[passType].attributes[SLT_BONES_IDS] = tglGetAttribLocation(pass[passType].program, "teBonesIds"); pass[passType].attributes[SLT_BONES_W] = tglGetAttribLocation(pass[passType].program, "teBonesW"); pass[passType].attributes[SLT_USER_0] = tglGetAttribLocation(pass[passType].program, "teUser0"); pass[passType].attributes[SLT_USER_1] = tglGetAttribLocation(pass[passType].program, "teUser1"); pass[passType].attributes[SLT_USER_2] = tglGetAttribLocation(pass[passType].program, "teUser2"); for(u8 i = 0; i < teMaxTextures; ++i) { c8 name[] = "teTexture "; name[9] = '0' + i; pass[passType].uniforms[UT_TEX_0 + i] = tglGetUniformLocation(pass[passType].program, name); } pass[passType].uniforms[UT_C_DIFFUSE] = tglGetUniformLocation(pass[passType].program, "teDiffuseColor"); pass[passType].uniforms[UT_MAT_V] = tglGetUniformLocation(pass[passType].program, "teVmat"); pass[passType].uniforms[UT_MAT_MV] = tglGetUniformLocation(pass[passType].program, "teMVmat"); pass[passType].uniforms[UT_MAT_MVP] = tglGetUniformLocation(pass[passType].program, "teMVPmat"); pass[passType].uniforms[UT_MAT_N] = tglGetUniformLocation(pass[passType].program, "teNmat"); pass[passType].uniforms[UT_MAT_BONES] = tglGetUniformLocation(pass[passType].program, "teBoneMatrixes"); pass[passType].uniforms[UT_TIME] = tglGetUniformLocation(pass[passType].program, "teTime"); pass[passType].uniforms[UT_USER0] = tglGetUniformLocation(pass[passType].program, "teUser0"); pass[passType].uniforms[UT_USER1] = tglGetUniformLocation(pass[passType].program, "teUser1"); pass[passType].uniforms[UT_USER2] = tglGetUniformLocation(pass[passType].program, "teUser2"); pass[passType].uniforms[UT_USER3] = tglGetUniformLocation(pass[passType].program, "teUser3"); currentPass = passType; for(u8 i = 0; i < teMaxTextures; ++i) SetUniform((EUniformType)(UT_TEX_0 + i), (s32)i); tglValidateProgram(pass[passType].program); LogErrors("validate", 0, pass[passType].program); }