AFFECT_DATA *new_affect(void) { static AFFECT_DATA af_zero; AFFECT_DATA *af; if (affect_free == NULL) af = alloc_perm(sizeof(*af)); else { af = affect_free; affect_free = affect_free->next; } *af = af_zero; VALIDATE(af); return af; }
static int onlp_psu_cpr_4011_fan_percentage_set(onlp_oid_t id, int p) { int i = ONLP_OID_ID_GET(id) - 2; unsigned char mux_ch[] = {0x2, 0x4}; unsigned char cfg_addr[] = {I2C_PSU1_SLAVE_ADDR_CFG, I2C_PSU2_SLAVE_ADDR_CFG}; unsigned char speed[2] = {(unsigned char)p, 0}; VALIDATE(id); if (as5610_52x_i2c0_pca9548_channel_set(mux_ch[i]) != 0) { return ONLP_STATUS_E_INTERNAL; } if (i2c_nWrite(I2C_PSU_BUS_ID, cfg_addr[i], I2C_PSU_FAN_SPEED_CTL_REG, sizeof(speed), speed) != 0) { return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; }
const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) { VALIDATE(); uint32_t id = SkGlyph::MakeID(glyphID); unsigned index = ID2HashIndex(id); SkGlyph* glyph = fGlyphHash[index]; if (NULL == glyph || glyph->fID != id) { RecordHashCollisionIf(glyph != NULL); glyph = this->lookupMetrics(glyphID, kFull_MetricsType); fGlyphHash[index] = glyph; } else { RecordHashSuccess(); if (glyph->isJustAdvance()) { fScalerContext->getMetrics(glyph); } } SkASSERT(glyph->isFullMetrics()); return *glyph; }
MBR_DATA * new_mbr (void) { static MBR_DATA mbr_zero; MBR_DATA *mbr; if (mbr_free == NULL) mbr = alloc_perm (sizeof (*mbr)); else { mbr = mbr_free; mbr_free = mbr_free->next; } *mbr = mbr_zero; VALIDATE (mbr); mbr->name = &str_empty[0]; return mbr; }
BAN_DATA * new_ban (void) { static BAN_DATA ban_zero; BAN_DATA *ban; if (ban_free == NULL) ban = alloc_perm (sizeof (*ban)); else { ban = ban_free; ban_free = ban_free->next; } *ban = ban_zero; VALIDATE (ban); ban->name = &str_empty[0]; return ban; }
WIZ_DATA * new_wiz (void) { static WIZ_DATA wiz_zero; WIZ_DATA *wiz; if (wiz_free == NULL) wiz = alloc_perm (sizeof (*wiz)); else { wiz = wiz_free; wiz_free = wiz_free->next; } *wiz = wiz_zero; VALIDATE (wiz); wiz->name = &str_empty[0]; return wiz; }
CLN_DATA * new_cln (void) { static CLN_DATA cln_zero; CLN_DATA *cln; if (cln_free == NULL) cln = alloc_perm (sizeof (*cln)); else { cln = cln_free; cln_free = cln_free->next; } *cln = cln_zero; VALIDATE (cln); cln->name = &str_empty[0]; return cln; }
void Lin_Init( const Lin_ConfigType* Config ) { (void)Config; uint8 i; VALIDATE( (LinDriverStatus == LIN_UNINIT), LIN_INIT_SERVICE_ID, LIN_E_STATE_TRANSITION ); /* VALIDATE( (Config!=0), LIN_INIT_SERVICE_ID, LIN_E_INVALID_POINTER ); */ for (i=0;i<LIN_CONTROLLER_CNT;i++) { /* LIN171: On entering the state LIN_INIT, the Lin module shall set each channel into * state LIN_CH_UNINIT. */ LinChannelStatus[i] = LIN_CH_UNINIT; } /* LIN146: LIN_UNINIT -> LIN_INIT: The Lin module shall transition from LIN_UNINIT * to LIN_INIT when the function Lin_Init is called. */ LinDriverStatus = LIN_INIT; }
GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrBufferType intendedType, GrAccessPattern accessPattern, bool cpuBacked, const void* data) : INHERITED(gpu, size, intendedType, accessPattern, cpuBacked), fCPUData(nullptr), fIntendedType(intendedType), fBufferID(0), fSizeInBytes(size), fUsage(gr_to_gl_access_pattern(intendedType, accessPattern)), fGLSizeInBytes(0), fHasAttachedToTexture(false) { if (this->isCPUBacked()) { // Core profile uses vertex array objects, which disallow client side arrays. SkASSERT(!gpu->glCaps().isCoreProfile()); if (gpu->caps()->mustClearUploadedBufferData()) { fCPUData = sk_calloc_throw(fSizeInBytes); } else { fCPUData = sk_malloc_flags(fSizeInBytes, SK_MALLOC_THROW); } if (data) { memcpy(fCPUData, data, fSizeInBytes); } } else { GL_CALL(GenBuffers(1, &fBufferID)); if (fBufferID) { GrGLenum target = gpu->bindBuffer(fIntendedType, this); CLEAR_ERROR_BEFORE_ALLOC(gpu->glInterface()); // make sure driver can allocate memory for this buffer GL_ALLOC_CALL(gpu->glInterface(), BufferData(target, (GrGLsizeiptr) fSizeInBytes, data, fUsage)); if (CHECK_ALLOC_ERROR(gpu->glInterface()) != GR_GL_NO_ERROR) { GL_CALL(DeleteBuffers(1, &fBufferID)); fBufferID = 0; } else { fGLSizeInBytes = fSizeInBytes; } } } VALIDATE(); this->registerWithCache(SkBudgeted::kYes); }
void tscrollbar_::set_item_position(const unsigned item_position) { // Set the value always execute since we update a part of the state. item_position_ = item_position > item_count_ - visible_items_ ? item_count_ - visible_items_ : item_position; item_position_ = (item_position_ + step_size_ - 1) / step_size_; if(all_items_visible()) { item_position_ = 0; } // Determine the pixel offset of the item position. positioner_offset_ = static_cast<unsigned>(item_position_ * pixels_per_step_); update_canvas(); VALIDATE(item_position_ <= item_count_ - visible_items_, null_str); }
static int cpg_virt_hostlist(hostlist_callback callback, void *arg, void *priv) { struct cpg_info *info = (struct cpg_info *) priv; int i; VALIDATE(priv); printf("[cpg-virt] HOSTLIST operation\n"); pthread_mutex_lock(&local_vm_list_lock); update_local_vms(info); for (i = 0 ; i < local_vm_list->vm_count ; i++) { callback(local_vm_list->vm_states[i].v_name, local_vm_list->vm_states[i].v_uuid, local_vm_list->vm_states[i].v_state.s_state, arg); } pthread_mutex_unlock(&local_vm_list_lock); return 1; }
bool DX10_Obj_LitTex::Initialise(DX10_Renderer* _pRenderer, DX10_Mesh* _pMesh, DX10_Shader_LitTex* _pShader, std::string _texName) { if (_pRenderer == 0 || _pMesh == 0 || _pShader == 0) { // If any pointers are NULL, Object cannot be initialized return false; } // Assign Member Variables m_pRenderer = _pRenderer; m_pMesh = _pMesh; m_pShader = _pShader; m_pTextures = new std::vector<ID3D10ShaderResourceView*>; ID3D10ShaderResourceView* pTempTex = 0; VALIDATE(m_pRenderer->CreateTexture(_texName, pTempTex)); m_pTextures->push_back(pTempTex); return true; }
std::pair<T*, config::attribute_value> mp_options_helper::add_node_and_get_widget( tree_view_node& option_node, const std::string& id, data_map& data, const config& cfg) { tree_view_node& node = option_node.add_child(id + "_node", data); T* widget = dynamic_cast<T*>(node.find(id, true)); VALIDATE(widget, missing_widget(id)); const std::string widget_id = cfg["id"]; auto& option_config = options_data_[visible_options_.back().id]; if(!option_config.has_attribute(widget_id) || option_config[widget_id].empty()) { option_config[widget_id] = cfg["default"]; } widget->set_id(widget_id); widget->set_tooltip(cfg["description"]); return {widget, option_config[widget_id]}; }
PROG_LIST *new_rprog(void) { static PROG_LIST rp_zero; PROG_LIST *rp; if (rprog_free == NULL) rp = alloc_perm(sizeof(*rp)); else { rp = rprog_free; rprog_free=rprog_free->next; } *rp = rp_zero; rp->vnum = 0; rp->trig_type = 0; rp->code = str_dup(""); VALIDATE(rp); return rp; }
static int onlp_thermal_info_get_locked__(onlp_oid_t oid, onlp_thermal_info_t* info) { int rv; VALIDATE(oid); rv = onlp_thermali_info_get(oid, info); if(rv >= 0) { #if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1 int id = ONLP_OID_ID_GET(oid); cJSON* entry = NULL; cjson_util_lookup(onlp_json_get(0), &entry, "overrides.thermal.%d", id); onlp_thermali_info_from_json__(entry, info, 0); #endif } return rv; }
PROG_LIST *new_oprog(void) { static PROG_LIST op_zero; PROG_LIST *op; if (oprog_free == NULL) op = alloc_perm(sizeof(*op)); else { op = oprog_free; oprog_free=oprog_free->next; } *op = op_zero; op->vnum = 0; op->trig_type = 0; op->code = str_dup(""); VALIDATE(op); return op; }
int AutoTableOutFormattingI(TABLE *tabPO, int val, int row) { char valS[DEF_BS], val2S[DEF_BS], rowS[DEF_BS]; VALIDATE(tabPO,TABLE_ID); INIT_S(valS); INIT_S(val2S); INIT_S(rowS); if(val) { /* xxx */ NumlistAutoFormatStringI(tabPO->vals, NULL, NULL, valS); } if(row) { WordlistAutoFormatStringI(tabPO->rlabs, NULL, rowS); } SetTablePrintformI(tabPO, valS, val2S, NULL, rowS, NULL); return(TRUE); }
void tslider::set_maximum_value(const int maximum_value) { if(maximum_value == get_maximum_value()) { return; } /** @todo maybe make it a VALIDATE. */ VALIDATE(minimum_value_ < maximum_value, null_str); const int value = get_value(); // The number of items needs to include the begin and end so distance + 1. set_item_count(distance(minimum_value_, maximum_value) + 1); if(value > maximum_value) { set_item_position(get_maximum_value()); } else { set_item_position(minimum_value_ + value); } }
MEM_DATA *new_mem_data(void) { MEM_DATA *memory; if (mem_data_free == NULL) memory = alloc_mem(sizeof(*memory)); else { memory = mem_data_free; mem_data_free = mem_data_free->next; } memory->next = NULL; memory->id = 0; memory->reaction = 0; memory->when = 0; VALIDATE(memory); return memory; }
MPROG_LIST *new_mprog(void) { static MPROG_LIST mp_zero; MPROG_LIST *mp; if (mprog_free == NULL) mp = alloc_perm(sizeof(*mp)); else { mp = mprog_free; mprog_free=mprog_free->next; } *mp = mp_zero; mp->vnum = 0; mp->trig_type = 0; mp->code = str_dup(""); VALIDATE(mp); return mp; }
CHAR_DATA *new_char (void) { static CHAR_DATA ch_zero; CHAR_DATA *ch; int i; if (char_free == NULL) ch = alloc_perm(sizeof(*ch)); else { ch = char_free; char_free = char_free->next; } *ch = ch_zero; VALIDATE(ch); ch->name = &str_empty[0]; ch->short_descr = &str_empty[0]; ch->long_descr = &str_empty[0]; ch->description = &str_empty[0]; ch->prompt = &str_empty[0]; ch->prefix = &str_empty[0]; ch->logon = current_time; ch->lines = PAGELEN; for (i = 0; i < 4; i++) ch->armor[i] = 100; ch->position = POS_STANDING; ch->hit = 20; ch->max_hit = 20; ch->mana = 100; ch->max_mana = 100; ch->move = 100; ch->max_move = 100; for (i = 0; i < MAX_STATS; i ++) { ch->perm_stat[i] = 13; ch->mod_stat[i] = 0; } return ch; }
void GrVkBuffer::internalUnmap(GrVkGpu* gpu, size_t size) { VALIDATE(); SkASSERT(this->vkIsMapped()); if (fDesc.fDynamic) { const GrVkAlloc& alloc = this->alloc(); SkASSERT(alloc.fSize > 0); SkASSERT(alloc.fSize >= size); // We currently don't use fOffset SkASSERT(0 == fOffset); GrVkMemory::FlushMappedAlloc(gpu, alloc, 0, size); GrVkMemory::UnmapAlloc(gpu, alloc); fMapPtr = nullptr; } else { // vkCmdUpdateBuffer requires size < 64k and 4-byte alignment. // https://bugs.chromium.org/p/skia/issues/detail?id=7488 if (size <= 65536 && 0 == (size & 0x3)) { gpu->updateBuffer(this, fMapPtr, this->offset(), size); } else { GrVkTransferBuffer* transferBuffer = GrVkTransferBuffer::Create(gpu, size, GrVkBuffer::kCopyRead_Type); if (!transferBuffer) { return; } char* buffer = (char*) transferBuffer->map(); memcpy (buffer, fMapPtr, size); transferBuffer->unmap(); gpu->copyBuffer(transferBuffer, this, 0, this->offset(), size); transferBuffer->unref(); } this->addMemoryBarrier(gpu, VK_ACCESS_TRANSFER_WRITE_BIT, buffer_type_to_access_flags(fDesc.fType), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, false); } }
void GrGLBufferImpl::unmap(GrGpuGL* gpu) { VALIDATE(); SkASSERT(this->isMapped()); if (0 != fDesc.fID) { switch (gpu->glCaps().mapBufferType()) { case GrGLCaps::kNone_MapBufferType: SkDEBUGFAIL("Shouldn't get here."); return; case GrGLCaps::kMapBuffer_MapBufferType: // fall through case GrGLCaps::kMapBufferRange_MapBufferType: this->bind(gpu); GL_CALL(gpu, UnmapBuffer(fBufferType)); break; case GrGLCaps::kChromium_MapBufferType: this->bind(gpu); GR_GL_CALL(gpu->glInterface(), UnmapBufferSubData(fMapPtr)); break; } } fMapPtr = NULL; }
int GetTablePrintformI(TABLE *tabPO, char *valS, char *val2S, char *sepS, char *rowS, char *preS) { VALIDATE(tabPO,TABLE_ID); if(valS) { strcpy(valS,tabPO->pvform); } if(val2S) { strcpy(val2S,tabPO->pvform2); } if(sepS) { strcpy(sepS,tabPO->pvsep); } if(rowS) { strcpy(rowS,tabPO->prlform); } if(preS) { strcpy(preS,tabPO->prefix); } return(TRUE); }
/************************************************************************** * Set the print format strings for when table is dumped * valS = Format string to dump (number) values (e.g. "%5.2f") * sepS = Separator between items (e.g. "\t") * rowS = Format string to dump (string) row lables (e.g. "%-12s") * preS = Prefix string for lines (e.g. "# ") */ int SetTablePrintformI(TABLE *tabPO, char *valS, char *val2S, char *sepS, char *rowS, char *preS) { VALIDATE(tabPO,TABLE_ID); if(valS && (!NO_S(valS))) { strcpy(tabPO->pvform,valS); } if(val2S && (!NO_S(val2S))) { strcpy(tabPO->pvform2,val2S); } if(sepS && (!NO_S(sepS))) { strcpy(tabPO->pvsep,sepS); } if(rowS && (!NO_S(rowS))) { strcpy(tabPO->prlform,rowS); } if(preS && (!NO_S(preS))) { strcpy(tabPO->prefix,preS); } return(TRUE); }
SLEEP_DATA *new_sleep_data(void) { SLEEP_DATA *sd; if (sd_free == NULL) sd = alloc_perm(sizeof(*sd)); else { sd = sd_free; sd_free=sd_free->next; } sd->vnum = 0; sd->timer = 0; sd->line = 0; sd->prog = NULL; sd->mob = NULL; sd->ch = NULL; sd->next = NULL; sd->prev = NULL; VALIDATE(sd); return sd; }
const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode) { VALIDATE(); uint32_t id = SkGlyph::MakeID(charCode); CharGlyphRec* rec = &fCharToGlyphHash[ID2HashIndex(id)]; if (rec->fID != id) { RecordHashCollisionIf(rec->fGlyph != NULL); // this ID is based on the UniChar rec->fID = id; // this ID is based on the glyph index id = SkGlyph::MakeID(fScalerContext->charToGlyphID(charCode)); rec->fGlyph = this->lookupMetrics(id, kFull_MetricsType); } else { RecordHashSuccess(); if (rec->fGlyph->isJustAdvance()) { fScalerContext->getMetrics(rec->fGlyph); } } SkASSERT(rec->fGlyph->isFullMetrics()); return *rec->fGlyph; }
bool base_map::erase2(base_unit* u, bool delete_unit) { VALIDATE(u->map_index_ != UNIT_NO_INDEX, "unit must be in map_!"); map_vsize_ --; for (int i = u->map_index_; i < map_vsize_; i ++) { map_[i] = map_[i + 1]; map_[i]->map_index_ = i; } map_[map_vsize_] = NULL; bool base = u->base(); std::set<map_location> invalid_locs; const std::set<map_location>& touch_locs = u->get_touch_locations(); for (std::set<map_location>::const_iterator itor = touch_locs.begin(); itor != touch_locs.end(); ++ itor) { const map_location& loc = *itor; if (base) { coor_map_[index(loc.x, loc.y)].base = NULL; } else { coor_map_[index(loc.x, loc.y)].overlay = NULL; } invalid_locs.insert(loc); } display* disp = display::get_singleton(); if (disp) { disp->invalidate(u->get_draw_locations()); } if (delete_unit) { delete u; } else { u->map_index_ = UNIT_NO_INDEX; } verify_map_index(); return true; }
// extract/place pair only use in overlay layer. base_unit* base_map::extract(const map_location &loc) { if (!loc.valid()) { return NULL; } base_unit* u = coor_map_[index(loc.x, loc.y)].overlay; if (!u) { return NULL; } const std::set<map_location>& touch_locs = u->get_touch_locations(); for (std::set<map_location>::const_iterator itor = touch_locs.begin(); itor != touch_locs.end(); ++ itor) { coor_map_[index(itor->x, itor->y)].overlay = NULL; } if (!place_unsort_) { VALIDATE(u->get_map_index() != UNIT_NO_INDEX, null_str); } return u; }
void tline::draw(surface& canvas , const game_logic::map_formula_callable& variables) { /** * @todo formulas are now recalculated every draw cycle which is a bit silly * unless there has been a resize. So to optimize we should use an extra * flag or do the calculation in a separate routine. */ const unsigned x1 = x1_(variables); const unsigned y1 = y1_(variables); const unsigned x2 = x2_(variables); const unsigned y2 = y2_(variables); DBG_GUI_D << "Line: draw from " << x1 << ',' << y1 << " to " << x2 << ',' << y2 << " canvas size " << canvas->w << ',' << canvas->h << ".\n"; VALIDATE( static_cast<int>(x1) < canvas->w && static_cast<int>(x2) < canvas->w && static_cast<int>(y1) < canvas->h && static_cast<int>(y2) < canvas->h , _("Line doesn't fit on canvas.")); // @todo FIXME respect the thickness. // now draw the line we use Bresenham's algorithm, which doesn't // support antialiasing. The advantage is that it's easy for testing. // lock the surface surface_lock locker(canvas); if(x1 > x2) { // invert points draw_line(canvas, color_, x2, y2, x1, y1); } else { draw_line(canvas, color_, x1, y1, x2, y2); } }