void QueuedWork::Run(Type what, int maxcount) { switch (what) { case Polling: Instance().poll.get(); for (std::vector<Queued *>::iterator it = Instance().Polls.begin(); it != Instance().Polls.end(); ++it) { (*it)->run(); } Instance().poll.put(); break; case Blocking: for (;;) { Instance().semaphore.get(); Instance().lock.get(); Queued *q = Instance().MayBlock.front(); Instance().MayBlock.pop_front(); Instance().lock.put(); q->run(); } break; case OpenGL: Instance().lock.get(); for (int i = 0; i < maxcount && Instance().OpenGLContext.size(); i++) { Queued *q = Instance().OpenGLContext.front(); Instance().OpenGLContext.pop_front(); Instance().lock.put(); q->run(); Instance().lock.get(); } Instance().lock.put(); break; } }
void HUD::SetHighscore(int score) { Instance().strScore = Tools::ToString(score); Instance().DisplayHighscore(); }
HRESULT AnimaApplication::CreateInstance( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { assert( AnimaApplication::mInstance == 0 ); HWND hWnd; WNDCLASSEX winClass; memset( &winClass, 0x0, sizeof(WNDCLASSEX) ); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WindowProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON); winClass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.lpszMenuName = NULL; winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; if( !RegisterClassEx(&winClass) ) return E_FAIL; hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", "DX9 Skinning Sample", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, NULL, NULL, hInstance, NULL ); if( hWnd == NULL ) return E_FAIL; // register raw input device RAWINPUTDEVICE Rid[2]; Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hWnd; // Keyboard Rid[1].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[1].usUsage = 6; Rid[1].dwFlags = 0; Rid[1].hwndTarget=hWnd; RegisterRawInputDevices( Rid, 2, sizeof(Rid[0]) ); ShowWindow( hWnd, nCmdShow ); UpdateWindow( hWnd ); LPWSTR *szArglist; int nArgs; szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); TestEnvironment* testEnvironment = new TestEnvironment( nArgs, szArglist ); Math::Random::Init( testEnvironment->GetRandomSeed() ); AnimaApplication::mInstance = new AnimaApplication( winClass, hWnd ); char szCurrentDir[2048]; GetCurrentDirectory( sizeof(szCurrentDir), szCurrentDir ); strcat_s(szCurrentDir, "/../Shaders"); Instance()->mShadersWatcher = FindFirstChangeNotification( szCurrentDir, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE); if (Instance()->mShadersWatcher == INVALID_HANDLE_VALUE) DXTRACE_ERR("Unable to monitor shaders directory. Live shaders editing will not work", E_FAIL ); Instance()->mTestEnvironment = testEnvironment; Instance()->mRenderContext = new RenderContext( hWnd, DISPLAY_WIDTH, DISPLAY_HEIGHT ); Instance()->mFramerateCounter = new FramerateCounter; Instance()->mUserInterface = new UserInterface( mInstance->mRenderContext, mInstance->mFramerateCounter ); Instance()->mUserInterface->AcquireResources( Instance()->mRenderContext ); Instance()->mInput = new Input(); Instance()->mCamera = new Camera( *Instance()->mInput, *Instance()->mRenderContext ); // set up renderer Instance()->mModel = new SkeletalModel( "..\\Models\\frank.dae" ); Instance()->mModel->Load( Instance()->mRenderContext ); Instance()->mModel->SetNext( Instance()->mUserInterface ); Instance()->mModel->PlayAnimation( 0, 0.25f ); Instance()->mModelRotationAngle = 0.f; Instance()->mRotateModel = true; Instance()->mFrameCounter = 0; return S_OK; }
void HUD::SetLives(int amount, bool who) { if(who) { //Removes previous list from the higscore score. As to not diplay the score along with the previous score. while(!Instance().playerLivesSymbols.empty()) { Instance().playerLivesSymbols.pop_front(); } Instance().nextPos = sf::Vector2f(16*4, 0); for (int i=0; i < amount; i++) { Instance().playerLivesSymbols.push_back( Instance().BlasterFont.GetGlyph((char)Instance().strScore.at(0), Instance().nextPos) ); Instance().nextPos.x += 16; } } else { //Removes previous list from the higscore score. As to not diplay the score along with the previous score. while(!Instance().playerLivesSymbols.empty()) { Instance().playerLivesSymbols.pop_front(); } Instance().nextPos = sf::Vector2f(16*24, 0); for (int i=0; i < amount; i++) { Instance().playerLivesSymbols.push_back( Instance().BlasterFont.GetGlyph((char)Instance().strScore.at(0), Instance().nextPos) ); Instance().nextPos.x -= 16; } } }
void HUD::UpdateTheHighscoreFile(int score, std::string name) { Instance().UpdateHighscoreFile(score, name); }
static void Disable() { Instance().enable_ = false; }
template <typename T> static T* DelCnt(T* p) { return Instance().dl(p); }
const CNcbiArguments& GetArguments(void) { return *(CNcbiArguments*)Instance(); }
// Set the position of the next character (and the x-coordinate of the first // character of all following new lines ) void Typewriter::SetStartPosition( const Point3D& ac_roPosition ) { Instance().m_oStartPosition = ac_roPosition; Instance().SetPosition( ac_roPosition ); }
// static command target void PatchInspector::toggle(const cmd::ArgumentList& args) { Instance().ToggleVisibility(); }
CNcbiEnvironment& SetEnvironment(void) { return *(CNcbiEnvironment*)Instance(); }
bool handleRunInstances( AttributeValueMap & avm, std::string & reply, unsigned requestNumber ) { // fprintf( stdout, "handleRunInstances()\n" ); bool found = false; std::string userID; User & user = validateAndAcquireUser( avm, userID, reply, found ); if( ! found ) { return false; } // Validate the ImageId, MinCount, and MaxCount parameters, as well // as the optional parameters KeyName, InstanceType, SecurityGroup*, // and UserData. // We presently assume all imageIDs are valid. std::string imageID = getObject< std::string >( avm, "ImageId", found ); if( (! found) || imageID.empty() ) { fprintf( stderr, "Failed to find imageID in query.\n" ); reply = "Required parameter ImageId missing or empty.\n"; return false; } std::string minCount = getObject< std::string >( avm, "MinCount", found ); if( (! found) || minCount.empty() ) { fprintf( stderr, "Failed to find minCount in query.\n" ); reply = "Required parameter MinCount missing or empty.\n"; return false; } std::string maxCount = getObject< std::string >( avm, "MaxCount", found ); if( (! found) || maxCount.empty() ) { fprintf( stderr, "Failed to find maxCount in query.\n" ); reply = "Required parameter MaxCount missing or empty.\n"; return false; } if( minCount != "1" || maxCount != "1" ) { fprintf( stderr, "The simulator presently only supports starting one instance at a time.\n" ); reply = "Counts must be '1' at present.\n"; return false; } std::string keyName = getObject< std::string >( avm, "KeyName", found ); if( ! keyName.empty() ) { Keypair kp = getObject< Keypair >( user.keypairs, keyName, found ); if( ! found ) { std::ostringstream error; error << "The requested keypair, '" << keyName << "', does not exist." << std::endl; reply = error.str(); fprintf( stderr, "%s", reply.c_str() ); return false; } } // We presently assume all instanceTypes are valid. std::string instanceType = getObject< std::string >( avm, "InstanceType", found ); if( instanceType.empty() ) { instanceType = "m1.small"; } std::string userData = getObject< std::string >( avm, "UserData", found ); if( ! userData.empty() ) { // We should validate that the user data is properly Base64-encoded. } std::vector< std::string > groupNames; for( int i = 1; ; ++i ) { std::ostringstream sgParameterName; sgParameterName << "SecurityGroup." << i; std::string sgName = getObject< std::string >( avm, sgParameterName.str(), found ); if( ! found ) { break; } if( sgName.empty() ) { std::ostringstream error; error << "Optional parameter " << sgName << " must not be empty." << std::endl; reply = error.str(); fprintf( stderr, "%s", reply.c_str() ); return false; } NameToGroupMap::const_iterator ci = user.groups.find( sgName ); if( ci != user.groups.end() ) { groupNames.push_back( sgName ); } else { std::ostringstream error; error << "Group '" << sgName << "' does not exist.\n"; reply = error.str(); fprintf( stderr, "%s", reply.c_str() ); return false; } } if( groupNames.empty() ) { groupNames.push_back( "default" ); } // Create the (unique) corresponding Instance. char edh[] = "12345678"; snprintf( edh, sizeof( edh ), "%.8x", (unsigned)user.instances.size() ); std::string instanceID = "i-"; instanceID += edh; std::string privateDNSName = "private.dns."; privateDNSName += edh; std::string publicDNSName = "public.dns."; publicDNSName += edh; std::string instanceState = "pending"; user.instances[ instanceID ] = Instance( instanceID, imageID, privateDNSName, publicDNSName, instanceType, instanceState, keyName, groupNames ); std::string reservationID = "r-"; reservationID += edh; // Construct the XML reply. std::ostringstream xml; xml << "<RunInstancesResponse xmlns=\"http://ec2.amazonaws.com/doc/2010-11-15/\">" << std::endl; char rID[] = "1234"; snprintf( rID, sizeof( rID ), "%.4x", requestNumber ); std::string requestID = rID; xml << "<requestId>" << requestID << "</requestId>" << std::endl; xml << "<reservationId>" << reservationID << "</reservationId>" << std::endl; xml << "<ownerId>" << userID << "</ownerId>" << std::endl; xml << "<groupSet>" << std::endl; for( unsigned i = 0; i < groupNames.size(); ++i ) { xml << xmlTag( "item", xmlTag( "groupId", groupNames[i] ) ) << std::endl; } xml << "</groupSet>" << std::endl; xml << "<instancesSet>" << std::endl; xml << user.instances[instanceID]; xml << "</instancesSet>" << std::endl; xml << "</RunInstancesResponse>" << std::endl; reply = xml.str(); return true; }
void CALLBACK SceneSync::ITimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { Instance().Update(); }
int main( int args, char *argv[]) { //Platform init code GLFWwindow* window; if (!glfwInit()) return 0; glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); if (!window) { glfwTerminate(); return 0; } glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { glfwTerminate(); return 0; } //End of platform init code const GLchar FragmentSource[] = { "#version 330 core \n" "out vec4 fcolor; \n" "void main(){ \n" " fcolor = vec4( 1,0,0,0); \n" "} \n" }; const GLchar VertexSource[] = { "#version 330 core \n" "layout(location = 0) in vec2 in_position; \n" "layout(location = 1) in vec2 in_size; \n" " \n" "uniform sce_camera{ \n" " vec2 camera; \n" " float zoom; \n" "}; \n" " \n" "void main(){ \n" " gl_Position = vec4( in_position + camera, 0, 1 ); \n" "} \n" }; Engine::CShader VertexShader( Engine::VertexShader ); if( !VertexShader.Compile( VertexSource ) ){ std::cout << VertexShader.Log() << std::endl; } Engine::CShader FragmentShader( Engine::FragmentShader ); if( !FragmentShader.Compile( FragmentSource ) ){ std::cout << FragmentShader.Log() << std::endl; } Engine::CProgram SpriteProgram; SpriteProgram.Attach( &VertexShader ); SpriteProgram.Attach( &FragmentShader ); if( !SpriteProgram.Link()) { std::cout << SpriteProgram.Log() << std::endl; } Engine::CSCECamera Camera; Engine::CSCEInstance Instance( &Camera ); const size_t sprite_count = 128; SSprite *SpritesOfGods = new SSprite[sprite_count]; for( size_t i = 0; i < sprite_count; i++ ) SpritesOfGods[i].position = glm::vec2( 0,0 ); GPUSpriteStorage* SpriteStorage = new GPUSpriteStorage(); GPUSpriteInstance* SpriteInstance = new GPUSpriteInstance(); GPUSpriteRenderer* SpriteRenderer = new GPUSpriteRenderer(); SpriteRenderer->Program().Attach( &VertexShader ); SpriteRenderer->Program().Attach( &FragmentShader ); if( !SpriteRenderer->Program().Link()) { std::cout << SpriteRenderer->Program().Log() << std::endl; } Instance.Initialize( SpriteRenderer ); Instance.Camera()->Position() = glm::vec2( 0.25, 0.25 ); Instance.Camera()->UpdateGpuBuffer(); //Upload sprites.... SpriteStorage->Upload( SpritesOfGods, sprite_count ); //Enable the sprites in an instance SpriteInstance->Enable( SpriteStorage ); glPointSize( 10.0f ); while (!glfwWindowShouldClose(window)) { int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); SpriteRenderer->Enable( ); SpriteRenderer->Render( SpriteInstance, Engine::Points, SpriteStorage->Size() ); SpriteRenderer->Disable( ); glfwSwapBuffers(window); glfwPollEvents(); } //PLATFORM glfwDestroyWindow(window); glfwTerminate(); return 0; }
static void Clear() { Instance().count_.clear(); }
void Logger::setPriority(Logger::Priority priority) { Logger* logger = Instance(); logger->mPriority = priority; }
static void Enable() { Instance().enable_ = true; }
void DESC_MANAGER::NotifyClientPackageFileChanged( const std::string& dirName, eFileUpdatedOptions eUpdateOption ) { Instance().LoadClientPackageCryptInfo(dirName.c_str()); }
template <typename T> static T* NewCnt(T* p) { return Instance().nw(p); }
void DrawerCommandQueue::Begin() { auto queue = Instance(); queue->Finish(); queue->threaded_render++; }
bool HUD::IsInstanceOfGlyph(int i, int j) { return Instance().CheckIfAtGlyph(i, j); }
void DrawerCommandQueue::WaitForWorkers() { Instance()->Finish(); }
void HUD::SetUpHighscoresAttractorMode() { Instance().DisplayHighscoresAttractorMode(); }
void DrawerCommandQueue::Finish() { auto queue = Instance(); if (queue->commands.empty()) return; // Give worker threads something to do: std::unique_lock<std::mutex> start_lock(queue->start_mutex); queue->active_commands.swap(queue->commands); queue->run_id++; start_lock.unlock(); queue->StartThreads(); queue->start_condition.notify_all(); // Do one thread ourselves: DrawerThread thread; thread.core = 0; thread.num_cores = (int)(queue->threads.size() + 1); struct TryCatchData { DrawerCommandQueue *queue; DrawerThread *thread; size_t command_index; } data; data.queue = queue; data.thread = &thread; data.command_index = 0; VectoredTryCatch(&data, [](void *data) { TryCatchData *d = (TryCatchData*)data; for (int pass = 0; pass < d->queue->num_passes; pass++) { d->thread->pass_start_y = pass * d->queue->rows_in_pass; d->thread->pass_end_y = (pass + 1) * d->queue->rows_in_pass; if (pass + 1 == d->queue->num_passes) d->thread->pass_end_y = MAX(d->thread->pass_end_y, MAXHEIGHT); size_t size = d->queue->active_commands.size(); for (d->command_index = 0; d->command_index < size; d->command_index++) { auto &command = d->queue->active_commands[d->command_index]; command->Execute(d->thread); } } }, [](void *data, const char *reason, bool fatal) { TryCatchData *d = (TryCatchData*)data; ReportDrawerError(d->queue->active_commands[d->command_index], true, reason, fatal); }); // Wait for everyone to finish: std::unique_lock<std::mutex> end_lock(queue->end_mutex); queue->end_condition.wait(end_lock, [&]() { return queue->finished_threads == queue->threads.size(); }); if (!queue->thread_error.IsEmpty()) { static bool first = true; if (queue->thread_error_fatal) I_FatalError("%s", queue->thread_error.GetChars()); else if (first) Printf("%s\n", queue->thread_error.GetChars()); first = false; } // Clean up batch: for (auto &command : queue->active_commands) command->~DrawerCommand(); queue->active_commands.clear(); queue->memorypool_pos = 0; queue->finished_threads = 0; }
void HUD::SetScore(int score, bool who) { Instance().strScore = Tools::ToString(score); Instance().DisplayScore(who); }
void RecyclingPlayerExplosionFactory::RecyclePlayerExplosion(GameObject* explosion) { //adds EnemyExplosion to recycle stack Instance().recycledItems.push( (PlayerExplosion*) explosion); }
"uint64_t hash(var self);", "Get the hash value for the object `self`." }, { "hash_data", "uint64_t hash_data(void* data, size_t num);", "Hash `num` bytes pointed to by `data` using " "[Murmurhash](http://en.wikipedia.org/wiki/MurmurHash)." }, {NULL, NULL, NULL} }; return methods; } var Hash = Cello(Hash, Instance(Doc, Hash_Name, Hash_Brief, Hash_Description, Hash_Definition, Hash_Examples, Hash_Methods)); uint64_t hash_data(const void* data, size_t size) { const uint64_t m = 0xc6a4a7935bd1e995; const int r = 47; const uint64_t * d = (const uint64_t*)data; const uint64_t * end = d + (size/8); uint64_t h = 0xCe110 ^ (size * m); while (d != end) { uint64_t k = *d++; k *= m; k ^= k >> r;
void FProfilerModule::StatsMemoryDumpCommand( const TCHAR* Filename ) { TUniquePtr<FRawStatsMemoryProfiler> Instance( FCreateStatsReader<FRawStatsMemoryProfiler>::ForRawStats( Filename ) ); if (Instance) { Instance->ReadAndProcessSynchronously(); while (Instance->IsBusy()) { FPlatformProcess::Sleep( 1.0f ); UE_LOG( LogStats, Log, TEXT( "Async: Stage: %s / %3i%%" ), *Instance->GetProcessingStageAsString(), Instance->GetStageProgress() ); } //Instance->RequestStop(); if (Instance->HasValidData()) { // Dump scoped allocations between the first and the last snapshot. const FName FirstSnapshotName = Instance->GetSnapshotNames()[0]; const FName LastSnapshotName = Instance->GetSnapshotNames()[Instance->GetSnapshotNames().Num()-1]; TMap<FString, FCombinedAllocationInfo> FrameBegin_End; Instance->CompareSnapshotsHumanReadable( FirstSnapshotName, LastSnapshotName, FrameBegin_End ); Instance->DumpScopedAllocations( TEXT( "Begin_End" ), FrameBegin_End ); Instance->ProcessAndDumpUObjectAllocations( TEXT( "Frame-240" ) ); #if 1/*UE_BUILD_DEBUG*/ // Dump debug scoped allocation generated when debug.EnableLeakTest=1 TMap<FString, FCombinedAllocationInfo> Frame060_120; Instance->CompareSnapshotsHumanReadable( TEXT( "Frame-060" ), TEXT( "Frame-120" ), Frame060_120 ); Instance->DumpScopedAllocations( TEXT( "Frame060_120" ), Frame060_120 ); TMap<FString, FCombinedAllocationInfo> Frame060_240; Instance->CompareSnapshotsHumanReadable( TEXT( "Frame-060" ), TEXT( "Frame-240" ), Frame060_240 ); Instance->DumpScopedAllocations( TEXT( "Frame060_240" ), Frame060_240 ); // Generate scoped tree view. { // 1. Compare snapshots. TMap<FName, FCombinedAllocationInfo> FrameBegin_End_FName; Instance->CompareSnapshots( FirstSnapshotName, LastSnapshotName, FrameBegin_End_FName ); // 2. Generate tree of allocations. FNodeAllocationInfo Root; Root.EncodedCallstack = TEXT( "ThreadRoot" ); Root.HumanReadableCallstack = TEXT( "ThreadRoot" ); Instance->GenerateScopedTreeAllocations( FrameBegin_End_FName, Root ); // 3. Display. } { TMap<FName, FCombinedAllocationInfo> Frame060_240_FName; Instance->CompareSnapshots( TEXT( "Frame-060" ), TEXT( "Frame-240" ), Frame060_240_FName ); FNodeAllocationInfo Root; Root.EncodedCallstack = TEXT( "ThreadRoot" ); Root.HumanReadableCallstack = TEXT( "ThreadRoot" ); Instance->GenerateScopedTreeAllocations( Frame060_240_FName, Root ); } #endif // UE_BUILD_DEBUG } } }
int CButtonTarget::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) { Use(Instance(pevAttacker), this, USE_TOGGLE, 0); return 1; }
SingletonMockB::~SingletonMockB() { QVERIFY(Instance().test()); // Check if CuteHMI-2.workaround is working. test_Singleton::InstancesCtr--; }