// SetModelCollisionBox( index ); static cell AMX_NATIVE_CALL SetModelCollisionBox(AMX *amx, cell *params) { int entityIndex = params[1]; CHECK_ENTITY(entityIndex); edict_t *pentModel = INDEXENT2(entityIndex); if (!FNullEnt(pentModel)) { studiohdr_t *pStudiohdr = static_cast<studiohdr_t*>(GET_MODEL_PTR(pentModel)); if (!pStudiohdr) { MF_LogError(amx, AMX_ERR_NATIVE, "Could not find the model pointer for the entity."); return 0; } SET_SIZE(pentModel, pStudiohdr->bbmin, pStudiohdr->bbmax); return 1; } return 0; };
/** allocate small block */ static void* mem_small_allocate(struct s_arena* arena, size_t size_in_words, unsigned int nptrs){ void* ptr; struct single_bdescr* single_block = find_current_single_block(arena); const int block_offset_words = WORDS_OF_TYPE(struct single_bdescr); if((single_block->cur_words + size_in_words +1)*sizeof(void*) > BLOCK_SIZE){ /* no space to alloc */ /* clear trailing area */ debug("%s : 1 single_bloc %08x cur_words %08x target %08x\n",__FUNCTION__,single_block,single_block->cur_words,(unsigned int)(((void**) single_block)+single_block->cur_words)); *(((void**) single_block)+single_block->cur_words) = NULL; prepend_new_single_block(arena); single_block = find_current_single_block(arena); } /* allocated ptr is now fixed. */ ptr = (void*)((void**)single_block + ((single_block->cur_words) +1)); single_block->cur_words += size_in_words + 1; debug("%s : 2 single_bloc %08x cur_words %08x target %08x\n",__FUNCTION__,single_block,single_block->cur_words,(((void**) single_block)+single_block->cur_words)); *(((void**) single_block)+single_block->cur_words) = NULL; if((single_block->cur_words + 1)*sizeof(void*) < BLOCK_SIZE){ *(((void**) single_block)+(single_block->cur_words +1)) = NULL; } if((single_block->cur_words + size_in_words +1)*sizeof(void*) > BLOCK_SIZE){ debug("%s : 3 single_bloc %08x cur_words %08x target %08x\n",__FUNCTION__,single_block,single_block->cur_words,(((void**) single_block)+single_block->cur_words)); /* no space to alloc */ /* clear trailing area */ *(((void**) single_block)+single_block->cur_words) = NULL; prepend_new_single_block(arena); single_block = find_current_single_block(arena); } SET_SIZE(ptr,size_in_words); SET_NPTR(ptr,nptrs); debug("%s small_block size : %d size_in_words : %d\n",__FUNCTION__,size_in_words*4,size_in_words); return ptr; }
/* * coalesce * Boundary tag coalescing. Return ptr to coalesced block * delete or insert entry of free list. */ static void *coalesce(void *bp) { size_t prev_alloc = IS_PREV_ALLOC(HDRP(bp)); size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); size_t size = GET_SIZE(HDRP(bp)); if (prev_alloc && next_alloc) { /* Case 1 */ /* nop */ } else if (prev_alloc && !next_alloc) { /* Case 2 */ if (heap_tailp == NEXT_BLKP(bp)) { heap_tailp = bp; } delete_node(get_level(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(NEXT_BLKP(bp))); PUT(HDRP(bp), PACK3(size, 2, 0)); PUT(FTRP(bp), PACK3(size, 2, 0)); } else if (!prev_alloc && next_alloc) { /* Case 3 */ int t = (bp == heap_tailp); delete_node(get_level(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))); SET_SIZE(FTRP(bp), size); SET_SIZE(HDRP(PREV_BLKP(bp)), size); bp = PREV_BLKP(bp); if (t) { heap_tailp = bp; } } else { /* Case 4 */ int t = (NEXT_BLKP(bp) == heap_tailp); delete_node(get_level(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); delete_node(get_level(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp))); SET_SIZE(HDRP(PREV_BLKP(bp)), size); SET_SIZE(FTRP(NEXT_BLKP(bp)), size); bp = PREV_BLKP(bp); if (t) { heap_tailp = bp; } } UNFLAG(HDRP(NEXT_BLKP(bp))); insert_node(get_level(GET_SIZE(HDRP(bp))), bp); return bp; }
void *malloc(ssize_t size_) { void *at = mem_ptr; uint32_t size = (uint32_t)ROUNDUP(size_, BYTES_PER_LONG) + BYTES_PER_LONG; int looped = 0; uint32_t expand_size; void *expanded; /* Scan the current heap for an opening. */ while (!looped || at < mem_ptr) { uint32_t at_size = BLOCK_SIZE(at); if (!IS_USED(at) && at_size >= size && at_size - size != BYTES_PER_LONG) { /* We can use this block. */ void *leftover = at + size; SET_SIZE(at, size); SET_USED(at); SET_SIZE(leftover, at_size - size); SET_UNUSED(leftover); mem_ptr = leftover; return PTR(at); } at += at_size; if (at >= curr_brk) { at = orig_brk; looped = 1; } } /* Expand the heap. */ expand_size = size + BUFFER_SIZE; expanded = mbrk(curr_brk + expand_size); if (expanded != at + expand_size) return NULL; at = curr_brk; curr_brk = expanded; SET_SIZE(at, size); SET_USED(at); SET_SIZE(at + size, expand_size - size); SET_UNUSED(at + size); return PTR(at); }
int __init_malloc(void) { curr_brk = mem_ptr = orig_brk = (void*)ROUNDUP(UL(mbrk(0)), BYTES_PER_LONG); if (orig_brk + INITIAL_SIZE != mbrk(orig_brk + INITIAL_SIZE)) return -1; SET_SIZE(mem_ptr, INITIAL_SIZE); SET_UNUSED(mem_ptr); curr_brk = orig_brk + INITIAL_SIZE; return 0; }
Array new_Array_raw(uns_int c) { if (c == 0) { return empty_Array; } Array result = NEW_ARRAYED(struct Array_t, Optr[c]); HEADER(result) = Array_Class; SET_SIZE(result, c); return result; }
// SetModelBoudingBox( index, sequence = Model_DefaultSize ); static cell AMX_NATIVE_CALL SetModelBoundingBox(AMX *amx, cell *params) { int entityIndex = params[1]; CHECK_ENTITY(entityIndex); edict_t *pentModel = INDEXENT2(entityIndex); if (!FNullEnt(pentModel)) { studiohdr_t *pStudiohdr = static_cast<studiohdr_t*>(GET_MODEL_PTR(pentModel)); if (!pStudiohdr) { MF_LogError(amx, AMX_ERR_NATIVE, "Could not find the model pointer for the entity."); return 0; } int sequence = params[2]; if (sequence <= Model_DefaultSize) { SET_SIZE(pentModel, pStudiohdr->min, pStudiohdr->max); } else { if (sequence <= Model_CurrentSequence || sequence >= pStudiohdr->numseq) sequence = pentModel->v.sequence; mstudioseqdesc_t *pSeqdesc; pSeqdesc = (mstudioseqdesc_t*)((byte*)pStudiohdr + pStudiohdr->seqindex); SET_SIZE(pentModel, pSeqdesc[sequence].bbmin, pSeqdesc[sequence].bbmax); return 1; } } return 0; }
/* * coalesce - Implements boundary-tag coalescing to merge the input block * with any adjacent free blocks in constant time. */ static void *coalesce(void *bp) { size_t prev_alloc = GET_PREV_ALLOC(HDRP(bp)); size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); size_t size = GET_SIZE(HDRP(bp)); if (prev_alloc && next_alloc) { /* Case 1 */ UNSET_TAG(HDRP(NEXT_BLKP(bp))); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); return bp; } else if (prev_alloc && !next_alloc) { /* Case 2 */ remove_from_list(find_list(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(NEXT_BLKP(bp))); PUT(HDRP(bp), PACK(size, 0)); PUT(FTRP(bp), PACK(size,0)); SET_TAG(HDRP(bp)); SET_TAG(FTRP(bp)); } else if (!prev_alloc && next_alloc) { /* Case 3 */ remove_from_list(find_list(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))); SET_SIZE(FTRP(bp), size); SET_SIZE(HDRP(PREV_BLKP(bp)), size); bp = PREV_BLKP(bp); } else { /* Case 4 */ remove_from_list(find_list(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); remove_from_list(find_list(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp))); SET_SIZE(HDRP(PREV_BLKP(bp)), size); SET_SIZE(FTRP(NEXT_BLKP(bp)), size); bp = PREV_BLKP(bp); } UNSET_TAG(HDRP(NEXT_BLKP(bp))); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); return bp; }
/* place - * Places the requested block at the beginning of the freeblock, and splitting * only if the size of the remainder block would equal or exceed the minimum * block size */ static void place(void *bp, size_t asize) { size_t csize = GET_SIZE(HDRP(bp)); size_t remainder = csize - asize; if (remainder >= (MINSIZE * WSIZE)) { remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp); SET_SIZE(HDRP(bp), asize); SET_ALLOC(HDRP(bp)); bp = NEXT_BLKP(bp); SET_SIZE(HDRP(bp), remainder); SET_SIZE(FTRP(bp), remainder); UNSET_ALLOC(HDRP(bp)); UNSET_ALLOC(FTRP(bp)); SET_TAG(HDRP(bp)); SET_TAG(FTRP(bp)); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); }else { remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp); SET_ALLOC(HDRP(bp)); SET_TAG(HDRP(NEXT_BLKP(bp))); } }
static cell AMX_NATIVE_CALL entity_set_origin(AMX *amx, cell *params) { int iEnt = params[1]; CHECK_ENTITY_SIMPLE(iEnt); edict_t *pEnt = INDEXENT2(iEnt); cell *vVector = MF_GetAmxAddr(amx, params[2]); REAL fX = amx_ctof(vVector[0]); REAL fY = amx_ctof(vVector[1]); REAL fZ = amx_ctof(vVector[2]); Vector vOrigin = Vector(fX, fY, fZ); SET_SIZE(pEnt, pEnt->v.mins, pEnt->v.maxs); SET_ORIGIN(pEnt, vOrigin); return 1; }
static cell AMX_NATIVE_CALL set_user_origin(AMX *amx, cell *params) // set_user_origin(index, origin[3]); = 2 arguments { // Sets user origin. // params[1] = index // params[2] = origin // Check index CHECK_PLAYER(params[1]); // Fetch player pointer edict_t *pPlayer = MF_GetPlayerEdict(params[1]); cell *newVectorCell = MF_GetAmxAddr(amx, params[2]); SET_SIZE(pPlayer, pPlayer->v.mins, pPlayer->v.maxs); SET_ORIGIN(pPlayer, Vector((float)newVectorCell[0], (float)newVectorCell[1], (float)newVectorCell[2])); return 1; }
/* * place - Place block of asize bytes at start of free block bp * and split if remainder would be at least minimum block size */ static void place(void *bp, size_t asize){ size_t csize = GET_SIZE(HDRP(bp)); if (IS_VALID(csize - asize)) { /* we want to make sure the new free block satisfy the minimum requirement */ int t = (bp == heap_tailp); delete_node(get_level(GET_SIZE(HDRP(bp))), bp); /* remove the record in the free block list */ SET_SIZE(HDRP(bp), asize); MARK_ALLOC(HDRP(bp)); bp = NEXT_BLKP(bp); PUT(HDRP(bp), PACK3(csize-asize, 2, 0)); PUT(FTRP(bp), PACK3(csize-asize, 2, 0)); insert_node(get_level(GET_SIZE(HDRP(bp))), bp); if (t) { heap_tailp = bp; } }else { delete_node(get_level(GET_SIZE(HDRP(bp))), bp); MARK_ALLOC(HDRP(bp)); FLAG(HDRP(NEXT_BLKP(bp))); } }
void AddNodeEntity(const Vector &origin, int effects) { edict_t *pNode = CREATE_ENTITY(); if (g_fIsMetamod) { CALL_GAME_ENTITY(PLID, "info_node", VARS(pNode)); } else { info_node(VARS(pNode)); } pNode->v.classname = MAKE_STRING("info_node"); SET_ORIGIN(pNode, origin); pNode->v.rendercolor.x = 255; pNode->v.rendercolor.y = 255; pNode->v.rendercolor.z = 0; pNode->v.rendermode = kRenderTransAdd; pNode->v.movetype = MOVETYPE_NONE; pNode->v.solid = SOLID_TRIGGER; SET_SIZE(ENT(&pNode->v), Vector(-8, -8, -8), Vector(8, 8, 8)); pNode->v.renderfx = kRenderFxNoDissipation; pNode->v.renderamt = 255; pNode->v.scale = 0.2; SET_MODEL(ENT(pNode), "sprites/glow02.spr"); pNode->v.effects = effects; }
void NPC::Spawn(Vector origin) { pev->solid = SOLID_BBOX; pev->takedamage = DAMAGE_AIM; pev->deadflag = DEAD_NO; pev->health = pev->max_health; pev->fixangle = true; SET_SIZE(GetEntity(), g_npcSize[0], g_npcSize[1]); SET_ORIGIN(GetEntity(), origin); m_pmodel = null; DROP_TO_FLOOR(GetEntity()); pev->animtime = gpGlobals->time; pev->nextthink = m_nextThinkTime = gpGlobals->time + 0.2f; m_frameInterval = gpGlobals->time; m_iDamage = false; SetEntityAction(GetIndex(), m_npcTeam, 1); m_workNPC = true; }
// SetView, this sets the view of a player. This is done by // Creating a camera entity, which follows the player. //(vexd) static cell AMX_NATIVE_CALL set_view(AMX *amx, cell *params) { int iIndex = params[1]; int iCameraType = params[2]; if (iIndex > gpGlobals->maxClients || !MF_IsPlayerIngame(iIndex)) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", iIndex); return 0; } edict_t *pPlayer = INDEXENT2(iIndex); edict_t *pNewCamera; switch(iCameraType) { case CAMERA_NONE: SET_VIEW(pPlayer, pPlayer); if(plinfo[ENTINDEX(pPlayer)].pViewEnt) { REMOVE_ENTITY(plinfo[ENTINDEX(pPlayer)].pViewEnt); } if (plinfo[ENTINDEX(pPlayer)].iViewType != CAMERA_NONE) // Verify that they were originally in a modified view { g_CameraCount--; if (g_CameraCount < 0) g_CameraCount=0; if (g_CameraCount==0) // Reset the AddToFullPack pointer if there's no more cameras in use... g_pFunctionTable->pfnAddToFullPack=NULL; } plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_NONE; plinfo[ENTINDEX(pPlayer)].pViewEnt = NULL; return 1; break; case CAMERA_3RDPERSON: if(plinfo[ENTINDEX(pPlayer)].iViewType != CAMERA_NONE) { plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_3RDPERSON; return 1; } g_CameraCount++; g_pFunctionTable_Post->pfnAddToFullPack=AddToFullPack_Post; g_pFunctionTable_Post->pfnPlayerPostThink=PlayerPostThink_Post; plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_3RDPERSON; pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera->v.classname = MAKE_STRING("VexdCam"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_SIZE(pNewCamera, Vector(0, 0, 0), Vector(0, 0, 0)); pNewCamera->v.movetype = MOVETYPE_NOCLIP; pNewCamera->v.solid = SOLID_NOT; pNewCamera->v.takedamage = DAMAGE_NO; pNewCamera->v.gravity = 0; pNewCamera->v.owner = pPlayer; pNewCamera->v.rendermode = kRenderTransColor; pNewCamera->v.renderamt = 0; pNewCamera->v.renderfx = kRenderFxNone; SET_VIEW(pPlayer, pNewCamera); plinfo[ENTINDEX(pPlayer)].pViewEnt = pNewCamera; break; case CAMERA_UPLEFT: if(plinfo[ENTINDEX(pPlayer)].iViewType != CAMERA_NONE) { plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_UPLEFT; return 1; } g_CameraCount++; g_pFunctionTable_Post->pfnAddToFullPack=AddToFullPack_Post; g_pFunctionTable_Post->pfnPlayerPostThink=PlayerPostThink_Post; plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_UPLEFT; pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera->v.classname = MAKE_STRING("VexdCam"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_SIZE(pNewCamera, Vector(0, 0, 0), Vector(0, 0, 0)); pNewCamera->v.movetype = MOVETYPE_NOCLIP; pNewCamera->v.solid = SOLID_NOT; pNewCamera->v.takedamage = DAMAGE_NO; pNewCamera->v.gravity = 0; pNewCamera->v.owner = pPlayer; pNewCamera->v.rendermode = kRenderTransColor; pNewCamera->v.renderamt = 0; pNewCamera->v.renderfx = kRenderFxNone; SET_VIEW(pPlayer, pNewCamera); plinfo[ENTINDEX(pPlayer)].pViewEnt = pNewCamera; break; case CAMERA_TOPDOWN: if(plinfo[ENTINDEX(pPlayer)].iViewType != CAMERA_NONE) { plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_TOPDOWN; return 1; } g_CameraCount++; g_pFunctionTable_Post->pfnAddToFullPack=AddToFullPack_Post; g_pFunctionTable_Post->pfnPlayerPostThink=PlayerPostThink_Post; plinfo[ENTINDEX(pPlayer)].iViewType = CAMERA_TOPDOWN; pNewCamera = CREATE_NAMED_ENTITY(MAKE_STRING("info_target")); pNewCamera->v.classname = MAKE_STRING("VexdCam"); SET_MODEL(pNewCamera, "models/rpgrocket.mdl"); SET_SIZE(pNewCamera, Vector(0, 0, 0), Vector(0, 0, 0)); pNewCamera->v.movetype = MOVETYPE_NOCLIP; pNewCamera->v.solid = SOLID_NOT; pNewCamera->v.takedamage = DAMAGE_NO; pNewCamera->v.gravity = 0; pNewCamera->v.owner = pPlayer; pNewCamera->v.rendermode = kRenderTransColor; pNewCamera->v.renderamt = 0; pNewCamera->v.renderfx = kRenderFxNone; SET_VIEW(pPlayer, pNewCamera); plinfo[ENTINDEX(pPlayer)].pViewEnt = pNewCamera; break; default: break; } return 1; }
void UTIL_SetSize( entvars_t *pev, const Vector &vecMin, const Vector &vecMax ) { SET_SIZE( ENT(pev), vecMin, vecMax ); }
int difference_direntrylist() { int ndiffs; /* Number of differences found */ struct direntry* entry_prev; /* Pointer to iterate through previous direntrylist */ struct direntry* entry_cur; /* Pointer to iterate through current direntry list */ ndiffs = 0; // Populate the curdir list with entries in directory right now exploredir(curdir, (const char*)full_path); /* Global variable: full_path */ // No differences if there is no entries in the directory if (curdir->count == 0 && prevdir->count == 0) { return 0; } entry_prev = prevdir->head; while (entry_prev != NULL) { if ((entry_cur = find_direntry(curdir, entry_prev)) != NULL && !IS_CHECKED(entry_prev->mask)) { // Permissions if (entry_prev->attrs.st_mode != entry_cur->attrs.st_mode) { SET_MODIFIED(entry_prev->mask); SET_PERM(entry_prev->mask); ndiffs++; } // UID if (entry_prev->attrs.st_uid != entry_cur->attrs.st_uid) { SET_MODIFIED(entry_prev->mask); SET_UID(entry_prev->mask); ndiffs++; } // GID if (entry_prev->attrs.st_gid != entry_cur->attrs.st_gid) { SET_MODIFIED(entry_prev->mask); SET_GID(entry_prev->mask); ndiffs++; } // Size if (entry_prev->attrs.st_size != entry_cur->attrs.st_size) { SET_MODIFIED(entry_prev->mask); SET_SIZE(entry_prev->mask); ndiffs++; } // Access time if (entry_prev->attrs.st_atime != entry_cur->attrs.st_atime) { SET_MODIFIED(entry_prev->mask); SET_LAT(entry_prev->mask); ndiffs++; } // Modified time if (entry_prev->attrs.st_mtime != entry_cur->attrs.st_mtime) { SET_MODIFIED(entry_prev->mask); SET_LMT(entry_prev->mask); ndiffs++; } // File status time if (entry_prev->attrs.st_ctime != entry_cur->attrs.st_ctime) { SET_MODIFIED(entry_prev->mask); SET_LFST(entry_prev->mask); ndiffs++; } // Show that the entries have been checked for differences // and not to check them again SET_CHECKED(entry_prev->mask); SET_CHECKED(entry_cur->mask); } else { // If a previous entry cannot be found in the current directory, // it was removed SET_REMOVED(entry_prev->mask); ndiffs++; } entry_prev = entry_prev->next; } // Now check for any entries that have been added to the monitored // directory entry_cur = curdir->head; while (entry_cur != NULL) { if (!IS_CHECKED(entry_cur->mask)) { SET_ADDED(entry_cur->mask); ndiffs++; } entry_cur = entry_cur->next; } return ndiffs; }