// // ResourceObj::GiveResource // // Give resource // U32 ResourceObj::GiveResource(U32 amount) { // How much space is left ASSERT(resource <= ResourceType()->GetResourceMax()) U32 left = ResourceType()->GetResourceMax() - resource; if (amount > left) { amount = left; } // Is this object in a cluster if (currentCluster) { currentCluster->ai.AddResource(amount); } // Add to the resource resource += amount; AdjustResource(); // Return the amount actually added return (amount); }
// // ResourceObj::ResourceObj // // Constructor // ResourceObj::ResourceObj(ResourceObjType *objType, U32 id) : MapObj(objType, id), teamsCanSee(0), teamsHaveSeen(0), resource(ResourceType()->GetResourceMax()) { }
// // Adjust resource display // void ResourceObj::AdjustResource() { if (Mesh().curCycle) { Mesh().SetFrame((Mesh().curCycle->maxFrame - 1) * (1.0f - (F32(resource) * ResourceType()->GetResourceMaxInv()))); } }
/** * Constructor with initialization values. * @param label is the name of the resource. It should be uniqe for every resource of defined type. * @param path is the path to resource's file. */ Texture::Texture(string label, string path) { resourceType = ResourceType(TEXTURE); name = label; filepath = string(""); filepath.assign(path); }
// // ResourceObj::TakeResource // // Take some resource // U32 ResourceObj::TakeResource(U32 want) { if (want > resource) { want = resource; // If this resource doesn't regenerate then mark it for deletion if (!ResourceType()->resourceRate) { GameObjCtrl::MarkForDeletion(this); } } // Is this object in a cluster if (currentCluster) { currentCluster->ai.RemoveResource(want); } // Remove from the resource resource -= want; AdjustResource(); // Return the amount that was available return (want); }
// // ResourceObj::LoadState // // Load a state configuration scope // void ResourceObj::LoadState(FScope *fScope) { // Call parent scope first MapObj::LoadState(fScope); if ((fScope = fScope->GetFunction(SCOPE_CONFIG, FALSE)) != NULL) { FScope *sScope; while ((sScope = fScope->NextFunction()) != NULL) { switch (sScope->NameCrc()) { case 0x5457F5AB: // "TeamHaveSeen" teamsHaveSeen = Game::TeamBitfield(StdLoad::TypeU32(sScope)); break; case 0x7C8A86BB: // "ResourcePercent" resource = StdLoad::TypePercentage(sScope, ResourceType()->GetResourceMax()); AdjustResource(); break; } } } }
GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu, const GrTextureParams* params, const GrSurfaceDesc& desc, const GrCacheID& cacheID) { GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc); return GrResourceKey(cacheID, ResourceType(), flags); }
/** * Copy constructor. * @param texture is the object which will be copied. */ Texture::Texture(Texture& texture) { resourceType = ResourceType(TEXTURE); name = texture.name; filepath = string(""); filepath.assign(texture.filepath); this->texture = texture.texture; }
// Prepare a sound effect SoundEffect::SoundEffect(SimpleFMOD *fmod, const char *filename, FMOD::ChannelGroup *cg, FMOD_MODE mode) : SimpleFMODResource(fmod) { FMOD::Sound *s; ErrorCheck(engine->FMOD()->createSound(filename, mode, 0, &s)); resource = ResourceType(s); // Remember channel group channelGroup = cg; }
// // ResourceObj::Equip // // Equip the object // void ResourceObj::Equip() { // Default the amount of resource to the maximum resource = ResourceType()->GetResourceMax(); AdjustResource(); // Call parent scope first MapObj::Equip(); }
PRESLINK AllocResLink( PRES pRes) { PRESLINK prl; PRES pResNew; PRES2 pRes2; LPTSTR pszName; INT cbName; LPTSTR pszType; if (!(prl = (PRESLINK)MyAlloc(sizeof(RESLINK)))) return NULL; prl->prlNext = NULL; prl->cbRes = ResourceSize(pRes); if (!(prl->hRes = GlobalAlloc(GMEM_MOVEABLE, prl->cbRes))) { MyFree(prl); Message(MSG_OUTOFMEMORY); return NULL; } pResNew = (PRES)GlobalLock(prl->hRes); memcpy(pResNew, pRes, prl->cbRes); GlobalUnlock(prl->hRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == ORDID_RT_DIALOG) { prl->fDlgResource = TRUE; pszName = ResourceName(pRes); cbName = NameOrdLen(pszName); if (!(prl->pszName = MyAlloc(cbName))) { GlobalFree(prl->hRes); MyFree(prl); return NULL; } NameOrdCpy(prl->pszName, pszName); pRes2 = ResourcePart2(pRes); prl->wLanguage = pRes2->LanguageId; } else { prl->fDlgResource = FALSE; prl->pszName = NULL; prl->wLanguage = 0; } return prl; }
/** * \brief Returns a resource type given its Lua name. * \param resource_type_name Lua name of a resource type. It must be valid. * \return The corresponding resource_type. */ ResourceType QuestResources::get_resource_type_by_name( const std::string& resource_type_name ) { int i = 0; for (const auto& kvp: resource_type_names) { if (kvp.second == resource_type_name) { return kvp.first; } ++i; } Debug::die(std::string("Unknown resource type: ") + resource_type_name); return ResourceType(); }
Song::Song(SimpleFMOD *fmod, const char *filename, FMOD::ChannelGroup *cg, FMOD_MODE mode) : SimpleFMODResource(fmod) { // Set stream size higher than the default (16384) to try to help reduce stuttering engine->FMOD()->setStreamBufferSize(65536, FMOD_TIMEUNIT_RAWBYTES); // Open the stream FMOD::Sound *s; ErrorCheck(engine->FMOD()->createStream(filename, mode, 0, &s)); resource = ResourceType(s); // Remember channel group channelGroup = cg; fade = false; }
void SQLiteStore::get(const std::string &path, GetCallback callback, void *ptr) { assert(uv_thread_self() == thread_id); if (!db || !*db) { if (callback) { callback(nullptr, ptr); } return; } GetBaton *get_baton = new GetBaton; get_baton->db = db; get_baton->path = path; get_baton->ptr = ptr; get_baton->callback = callback; uv_worker_send(worker, get_baton, [](void *data) { GetBaton *baton = (GetBaton *)data; const std::string url = unifyMapboxURLs(baton->path); // 0 1 2 Statement stmt = baton->db->prepare("SELECT `code`, `type`, `modified`, " // 3 4 5 6 "`etag`, `expires`, `data`, `compressed` FROM `http_cache` WHERE `url` = ?"); stmt.bind(1, url.c_str()); if (stmt.run()) { // There is data. baton->response = std::unique_ptr<Response>(new Response); baton->response->code = stmt.get<int>(0); baton->type = ResourceType(stmt.get<int>(1)); baton->response->modified = stmt.get<int64_t>(2); baton->response->etag = stmt.get<std::string>(3); baton->response->expires = stmt.get<int64_t>(4); baton->response->data = stmt.get<std::string>(5); if (stmt.get<int>(6)) { // == compressed baton->response->data = util::decompress(baton->response->data); } } else { // There is no data. // This is a noop. } }, [](void *data) { std::unique_ptr<GetBaton> baton { (GetBaton *)data }; if (baton->callback) { baton->callback(std::move(baton->response), baton->ptr); } }); }
// // ResourceObj::SaveState // // Save a state configuration scope // void ResourceObj::SaveState(FScope *fScope, MeshEnt * theMesh) // = NULL) { // Call parent scope first MapObj::SaveState(fScope); if (SaveGame::SaveActive()) { // Create our specific config scope fScope = fScope->AddFunction(SCOPE_CONFIG); // Save the sight bitfield StdSave::TypeU32(fScope, "TeamHaveSeen", teamsHaveSeen); // Save the amount of resource StdSave::TypePercentage(fScope, "ResourcePercent", ResourceType()->GetResourceMax(), resource); } }
// // ResourceObj::SetResource // // Set resource // void ResourceObj::SetResource(F32 percentage) { // Is this object in a cluster if (currentCluster) { currentCluster->ai.RemoveResource(resource); } resource = U32(percentage * F32(ResourceType()->GetResourceMax())); AdjustResource(); // Is this object in a cluster if (currentCluster) { currentCluster->ai.AddResource(resource); } }
GrResourceKey GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc) { GrCacheID::Key idKey; // Instead of a client-provided key of the texture contents we create a key from the // descriptor. GR_STATIC_ASSERT(sizeof(idKey) >= 16); SkASSERT(desc.fHeight < (1 << 16)); SkASSERT(desc.fWidth < (1 << 16)); idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; idKey.fData32[2] = desc.fFlags; idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually static const int kPadSize = sizeof(idKey) - 16; GR_STATIC_ASSERT(kPadSize >= 0); memset(idKey.fData8 + 16, 0, kPadSize); GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey); return GrResourceKey(cacheID, ResourceType(), 0); }
void BaseResource::PublishResourceAd( ClassAd *resource_ad ) { std::string buff; formatstr( buff, "%s %s", ResourceType(), resourceName ); resource_ad->Assign( ATTR_NAME, buff.c_str() ); resource_ad->Assign( "HashName", GetHashName() ); resource_ad->Assign( ATTR_SCHEDD_NAME, ScheddName ); resource_ad->Assign( ATTR_SCHEDD_IP_ADDR, ScheddObj->addr() ); resource_ad->Assign( ATTR_OWNER, myUserName ); if ( SelectionValue ) { resource_ad->Assign( ATTR_GRIDMANAGER_SELECTION_VALUE, SelectionValue ); } resource_ad->Assign( "NumJobs", registeredJobs.Number() ); resource_ad->Assign( "JobLimit", jobLimit ); resource_ad->Assign( "SubmitsAllowed", submitsAllowed.Number() ); resource_ad->Assign( "SubmitsWanted", submitsWanted.Number() ); if ( resourceDown ) { resource_ad->Assign( ATTR_GRID_RESOURCE_UNAVAILABLE_TIME, (int)lastStatusChange ); } int num_idle = 0; int num_running = 0; BaseJob *job; registeredJobs.Rewind(); while ( registeredJobs.Next( job ) ) { switch ( job->condorState ) { case IDLE: num_idle++; break; case RUNNING: num_running++; break; default: break; } } resource_ad->Assign( ATTR_RUNNING_JOBS, num_running ); resource_ad->Assign( ATTR_IDLE_JOBS, num_idle ); }
SoundEffect::SoundEffect(SimpleFMOD *fmod, int resourceId, LPCTSTR resourceType, FMOD::ChannelGroup *cg, FMOD_MODE mode) : SimpleFMODResource(fmod) { HRSRC rsrc = FindResource(NULL, MAKEINTRESOURCE(resourceId), resourceType); HGLOBAL handle = LoadResource(NULL, rsrc); DWORD audioSize = SizeofResource(NULL, rsrc); LPVOID audioData = LockResource(handle); FMOD_CREATESOUNDEXINFO audioInfo; memset(&audioInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); audioInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); audioInfo.length = static_cast<unsigned int>(audioSize); FMOD::Sound *s; ErrorCheck(engine->FMOD()->createSound(static_cast<const char *>(audioData), FMOD_OPENMEMORY | mode, &audioInfo, &s)); resource = ResourceType(s); // Remember channel group channelGroup = cg; }
void BaseResource::Reconfig() { int tmp_int; char *param_value; std::string param_name; tmp_int = param_integer( "GRIDMANAGER_RESOURCE_PROBE_INTERVAL", 5 * 60 ); setProbeInterval( tmp_int ); jobLimit = -1; formatstr( param_name, "GRIDMANAGER_MAX_SUBMITTED_JOBS_PER_RESOURCE_%s", ResourceType() ); param_value = param( param_name.c_str() ); if ( param_value == NULL ) { param_value = param( "GRIDMANAGER_MAX_SUBMITTED_JOBS_PER_RESOURCE" ); } if ( param_value != NULL ) { char *tmp1; char *tmp2; StringList limits( param_value ); limits.rewind(); if ( limits.number() > 0 ) { jobLimit = atoi( limits.next() ); while ( (tmp1 = limits.next()) && (tmp2 = limits.next()) ) { if ( strstr( resourceName, tmp1 ) != 0 ) { jobLimit = atoi( tmp2 ); } } } free( param_value ); } if ( jobLimit <= 0 ) { jobLimit = DEFAULT_MAX_SUBMITTED_JOBS_PER_RESOURCE; } // If the jobLimit was widened, move jobs from Wanted to Allowed and // signal them while ( submitsAllowed.Length() < jobLimit && submitsWanted.Length() > 0 ) { BaseJob *wanted_job = submitsWanted.Head(); submitsWanted.Delete( wanted_job ); submitsAllowed.Append( wanted_job ); wanted_job->SetEvaluateState(); } formatstr( param_name, "GRIDMANAGER_JOB_PROBE_RATE_%s", ResourceType() ); m_paramJobPollRate = param_integer( param_name.c_str(), -1 ); if ( m_paramJobPollRate <= 0 ) { m_paramJobPollRate = param_integer( "GRIDMANAGER_JOB_PROBE_RATE", DEFAULT_JOB_POLL_RATE ); } if ( m_paramJobPollRate <= 0 ) { m_paramJobPollRate = DEFAULT_JOB_POLL_RATE; } const char *legacy_job_poll_param = NULL; const char *type = ResourceType(); if ( strcmp( type, "condor" ) == 0 ) { legacy_job_poll_param = "CONDOR_JOB_POLL_INTERVAL"; } else if ( strcmp( type, "batch" ) == 0 || strcmp( type, "pbs" ) == 0 || strcmp( type, "lsf" ) == 0 || strcmp( type, "nqs" ) == 0 || strcmp( type, "sge" ) == 0 || strcmp( type, "naregi" ) == 0 ) { legacy_job_poll_param = "INFN_JOB_POLL_INTERVAL"; } formatstr( param_name, "GRIDMANAGER_JOB_PROBE_INTERVAL_%s", ResourceType() ); m_paramJobPollInterval = param_integer( param_name.c_str(), -1 ); if ( m_paramJobPollInterval <= 0 ) { m_paramJobPollInterval = param_integer( "GRIDMANAGER_JOB_PROBE_INTERVAL", -1 ); } if ( m_paramJobPollInterval <= 0 && legacy_job_poll_param ) { m_paramJobPollInterval = param_integer( legacy_job_poll_param, -1 ); } if ( m_paramJobPollInterval <= 0 ) { m_paramJobPollInterval = DEFAULT_JOB_POLL_INTERVAL; } SetJobPollInterval(); _collectorUpdateInterval = param_integer ( "GRIDMANAGER_COLLECTOR_UPDATE_INTERVAL", 5*60 ); }
static HWND SearchResource(LPCSTR lpName, int type, DLGPROC pDialogProc, LPARAM param, char *lpFileBase, int TotalFileSize, HWND parentWnd) { char *pResAll = lpFileBase + TotalFileSize; PRES pRes = (PRES)lpFileBase; char pszSearchedName[256]; char *pszType = ResourceType(pRes); char *pszName; int size = ResourceSize(pRes); char Name[512],*bb; PDIALOGBOXHEADER pdbh; HWND result; UINT_PTR ul; ul = (UINT_PTR)lpName; if (HIWORD(ul) == 0) { sprintf(pszSearchedName,"%d",LOWORD(ul)); } else if (IsOrd((char *)lpName)) { sprintf(pszSearchedName,"%d",OrdID(lpName)); } else if (lpName[1] == 0 && lpName[3] == 0) { ConvertWideString((char *)lpName,(char *)pszSearchedName); } else { strcpy(pszSearchedName,lpName); } do { if (pRes->HeaderSize+pRes->DataSize == 0) break; if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) { /* Ignore include files */ ; } else if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_RESOURCE32) { /* * This is the dummy resource that identifies a * 32 bit resource file. This resource should be * skipped also. */ } else { /* This is some other kind of a resource. See if it matches */ if (pRes->DataSize) { int size = ResourceSize(pRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == type) { pszName = ResourceName(pRes); if (!IsOrd(pszName)) { if (pszName[1] == 0 && pszName[3] == 0) ConvertWideString(pszName,Name); else strcpy(Name,pszName); } else { sprintf(Name,"%d",OrdID(pszName)); } if (!strcmp(Name,pszSearchedName)) { /* found it.*/ if (type == 5) { /* Build a dialog box */ pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes); bb = malloc(size); memcpy(bb,pdbh,size); result = CreateDialogIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)bb, parentWnd, pDialogProc,param); free(bb); return result; } else if (type == 4) { /* Build a menu */ return (HWND) ReadMenu((char *)SkipResHeader(pRes)); } else if (type == 3) { /* Build an Icon */ HICON hicon; hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, TRUE, 0x30000); return (HWND)hicon; } else if (type == 1) { /* Build a cursor */ return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, FALSE, 0x30000); } else if (type == 2 || type == 14) { /* Build bitmap */ char *start = SkipResHeader(pRes); bb = malloc(size); memcpy(bb,start,size); return (HWND) bb; } } } } } /* Move to the next resource. */ pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize); DWordAlign((PBYTE *)&pRes); } while (pRes < (PRES) ((char *) pResAll + size)); return (HWND) 0; }