Example #1
0
// This removes the pShape from its current collide space, but leaves everything intact.
void CShape::RemoveFromSpace()
{
	n_assert(ODESpaceID);
	n_assert(ODEGeomID);
	dSpaceRemove(ODESpaceID, ODEGeomID);
	ODESpaceID = NULL;
}
Example #2
0
bool CDataServer::CopyFile(const nString& SrcPath, const nString& DestPath)
{
	//???mangle here for perf reasons?

	if (IsFileReadOnly(DestPath))
		SetFileReadOnly(DestPath, false);

	CFileStream Src, Dest;
	if (!Src.Open(SrcPath, SAM_READ, SAP_SEQUENTIAL)) FAIL;
	if (!Dest.Open(DestPath, SAM_WRITE, SAP_SEQUENTIAL))
	{
		Src.Close();
		FAIL;
	}

	int Size = Src.GetSize();
	char* pBuffer = (char*)n_malloc(Size);
	int RealSize = Src.Read(pBuffer, Size);
	n_assert(RealSize == Size);
	Src.Close();

	RealSize = Dest.Write(pBuffer, Size);
	n_assert(RealSize == Size);
	Dest.Close();
	n_free(pBuffer);

	OK;
}
Example #3
0
static
char *mkdbcache_path(char *path, size_t size, const char *cachedir,
                     const char *dbfull_path)
{
    int len;
    char tmp[PATH_MAX], *p;
    
    n_assert(cachedir);
    if (*dbfull_path == '/')
        dbfull_path++;

    len = n_snprintf(tmp, sizeof(tmp), "%s", dbfull_path);
    if (tmp[len - 1] == '/') {
        tmp[len - 1] = '\0';
        len--;
    }
    n_assert(len);
    p = tmp;

    while (*p) {
        if (*p == '/')
            *p = '.';
        p++;
    }

    n_snprintf(path, size, "%s/packages.%s.%s.gz", cachedir,
               RPMDBCACHE_PDIRTYPE, tmp);
    return path;
}
Example #4
0
int iset_remove(struct iset *iset, struct pkg *pkg)
{
    int i;
    
    if (!iset_ismarkedf(iset, pkg, PKGMARK_ISET)) /* not here */
        return 0;
    
    n_hash_clean(iset->capcache); /* flush all, TODO: remove pkg caps only */
    pkg_clr_mf(iset->pms, pkg, PKGMARK_ISET);

    i = n_array_bsearch_idx(iset->pkgs, pkg);
    if (i >= 0) {
        struct pkg *p = n_array_nth(iset->pkgs, i);
        
        n_assert(pkg_cmp_name_evr(p, pkg) == 0);
        
        if (poldek_conf_MULTILIB)
            n_assert(pkg_cmp_arch(p, pkg) == 0);

        n_array_remove_nth(iset->pkgs, i);
    
        /* recreate pkgs_by_recno (cheaper than manually find item to remove) */
        n_array_free(iset->pkgs_by_recno);
        iset->pkgs_by_recno = n_array_dup(iset->pkgs, (tn_fn_dup)pkg_link);
        n_array_ctl_set_cmpfn(iset->pkgs_by_recno, (tn_fn_cmp)pkg_cmp_recno);
    }
    
    n_assert(!iset_has_pkg(iset, pkg));
    return 1;
}
Example #5
0
tn_array *n_array_remove_nth(tn_array *arr, int i)
{
    register unsigned int pos = arr->start_index + i;
    register void *ptr;

    trurl_die__if_frozen(arr);
    
    n_assert(i >= 0);
    n_assert(arr->allocated > 0);
    n_assert(arr->items > 0);

    if ((size_t) i >= arr->items || i < 0) {
        trurl_die("n_array_remove_nth: index(%d) out of bounds(0 - %d)\n", i,
                  arr->items);
        return NULL;
    }
    
    ptr = arr->data[pos];

    /* if slot is not empty, free node data */
    if (arr->data[pos] != NULL && arr->free_fn != NULL)
        arr->free_fn(arr->data[pos]);

    if (pos == arr->items) 
        arr->data[pos] = NULL;
    else 
        memmove(&arr->data[pos], &arr->data[pos + 1],
                (arr->allocated - 1 - pos) * sizeof(*arr->data));

    arr->data[arr->allocated - 1] = NULL;
    arr->items--;
    return arr;
}
Example #6
0
void CValueTable::Realloc(int NewPitch, int NewAllocRows)
{
	n_assert(NewAllocRows >= NumRows);
	n_assert(NewPitch >= RowPitch);

	AllocatedRows = NewAllocRows;
	int NewValueBufferSize = NewPitch * NewAllocRows;
	ValueBuffer = n_realloc(ValueBuffer, NewValueBufferSize);

	if (NewPitch != RowPitch)
	{
		int RowIdx = NumRows - 1;
		int PitchDiff = NewPitch - RowPitch;
		char* FromPtr = (char*)ValueBuffer + RowIdx * RowPitch;
		char* ToPtr = (char*)ValueBuffer + RowIdx * NewPitch;
		while (FromPtr > (char*)ValueBuffer)
		{
			memcpy(ToPtr, FromPtr, RowPitch);
			memset(ToPtr - PitchDiff, 0, PitchDiff);
			FromPtr -= RowPitch;
			ToPtr -= NewPitch;
		}
	}

	int LastRowDataEndOffset = NewPitch * (NumRows - 1) + RowPitch;
	memset((char*)ValueBuffer + LastRowDataEndOffset, 0, NewValueBufferSize - LastRowDataEndOffset);

	RowPitch = NewPitch;

	//???pad to 4 bytes (see buffer-wide operations & DWORD usage)?
	RowStateBuffer = (uchar*)n_realloc(RowStateBuffer, NewAllocRows);
	memset(RowStateBuffer + NumRows, 0, NewAllocRows - NumRows);
}
Example #7
0
bool CMeshShape::LoadFromFile(nMeshLoader& MeshLoader)
{
	n_assert(FileName.IsValid());
	n_assert(pVBuffer);
	n_assert(pIBuffer);

	// open file and read header data
	MeshLoader.SetFilename(FileName.Get());
	MeshLoader.SetIndexType(nMeshLoader::Index32);
	if (!MeshLoader.Open())
	{
		n_error("CMeshShape: Failed to open file '%Sphere'!", FileName.Get());
		FAIL;
	}

	// transfer mesh attributes
	VertexCount = MeshLoader.GetNumVertices();
	IndexCount  = MeshLoader.GetNumIndices();
	VertexWidth = MeshLoader.GetVertexWidth();

	// allocate vertex and index buffer
	int VBSize = MeshLoader.GetNumVertices() * MeshLoader.GetVertexWidth() * sizeof(float);
	int IBSize = MeshLoader.GetNumIndices() * sizeof(uint);
	pVBuffer = (float*)n_malloc(VBSize);
	pIBuffer = (int*)n_malloc(IBSize);

	// read vertices and indices
	MeshLoader.ReadVertices(pVBuffer, VBSize);
	MeshLoader.ReadIndices(pIBuffer, IBSize);

	// close mesh loader
	MeshLoader.Close();

	OK;
}
Example #8
0
void CCharEntity::SetOverlayAnimationMix(const nArray<nString>& AnimNames, const nArray<float>& Weights,
										 nTime FadeIn, nTime OverrideDuration)
{
	n_assert(AnimNames.Size() >= 1);
	n_assert(Weights.Size() >= 1);
	n_assert(pNCharacter);
	n_assert(pCharacterSet);
	n_assert(pNCharacter->GetSkinAnimator());

	const nString& MappedName = GfxSrv->GetAnimationName(AnimMapping, AnimNames[0]).Name;
	int Idx = pNCharacter->GetSkinAnimator()->GetClipIndexByName(MappedName);
	if (Idx != INVALID_INDEX)
	{
		OverlayAnimNames = AnimNames;
		OverlayAnimWeights = Weights;
		OverlayAnimStarted = GetEntityTime();
		if (OverrideDuration > 0.0) OverlayAnimDuration = OverrideDuration;
		else if (TimeFactor > 0.0f)
		{
			OverlayAnimDuration = (pNCharacter->GetSkinAnimator()->GetClipDuration(Idx) - FadeIn) / TimeFactor;
			if (OverlayAnimDuration < 0.0) BaseAnimDuration = 0.0;
		}
		else OverlayAnimDuration = 0.0;

		RestartOverlayAnim = 1;
		OverlayEndFadeIn = FadeIn;

		ActivateAnimations(OverlayAnimNames, OverlayAnimWeights, FadeIn);
	}
}
Example #9
0
static
int pattern_match(struct pattern *pt, const char *s, int len) 
{
    int match = 0;

    if (len == 0)
        len = strlen(s);

    switch (pt->type) {
        case PATTERN_FMASK:
            n_assert(s[len] == '\0');
            match = (fnmatch(pt->regexp, s, pt->fnmatch_flags) == 0);
            break;
            
        case PATTERN_PCRE:
            if (pcre_exec(pt->pcre, pt->pcre_extra, s, len, 0, 0, NULL, 0) == 0)
                match = 1;
            break;

        default:
            n_assert(0);
            break;
    }
    
    return match;
}
Example #10
0
// Called by Physics::Server when the Level is removed from the server.
void CLevel::Deactivate()
{
	n_assert(ODEWorldID);
	n_assert(ODEDynamicSpaceID);
	n_assert(ODEStaticSpaceID);
	n_assert(ODECommonSpaceID);

	for (int i = 0; i < Shapes.Size(); i++) Shapes[i]->Detach();
	Shapes.Clear();

	for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnRemovedFromLevel();
	Entities.Clear();

	// delete the Contact group for joints
	dJointGroupDestroy(ContactJointGroup);

	// shutdown ode
	dSpaceDestroy(ODEDynamicSpaceID);
	dSpaceDestroy(ODEStaticSpaceID);
	dSpaceDestroy(ODECommonSpaceID);
	dWorldDestroy(ODEWorldID);
	dCloseODE();
	ODECommonSpaceID = NULL;
	ODEDynamicSpaceID = NULL;
	ODEStaticSpaceID = NULL;
	ODEWorldID = NULL;
}
Example #11
0
// Universal method for all specific ODE geom types, which add the
// geom to the collide space, using an ODE proxy geom to offset the
// geom by the provided transformation matrix. The geom will also
// be attached to the rigid body, if any is set.
void CShape::AttachGeom(dGeomID GeomId, dSpaceID SpaceID)
{
	n_assert(GeomId);
	n_assert(!IsAttached());

	// set the geom's local Transform
	const vector3& Pos = Transform.pos_component();
	dGeomSetPosition(GeomId, Pos.x, Pos.y, Pos.z);
	dMatrix3 ODERotation;
	CPhysicsServer::Matrix44ToOde(Transform, ODERotation);
	dGeomSetRotation(GeomId, ODERotation);

	// if attached to rigid body, create a geom Transform "proxy" object && attach it to the rigid body
	// else directly set Transform and rotation
	if (pRigidBody)
	{
		ODEGeomID = dCreateGeomTransform(0);
		dGeomTransformSetCleanup(ODEGeomID, 1);
		dGeomTransformSetGeom(ODEGeomID, GeomId);
		dGeomSetBody(ODEGeomID, pRigidBody->GetODEBodyID());
	}
	else ODEGeomID = GeomId;

	dGeomSetCategoryBits(ODEGeomID, CatBits);
	dGeomSetCollideBits(ODEGeomID, CollBits);
	dGeomSetData(ODEGeomID, this);
	AttachToSpace(SpaceID);
}
int source_cmp(const struct source *s1, const struct source *s2)
{
    n_assert(s1->path);
    n_assert(s2->path);
    
    return strcmp(s1->path, s2->path);
}
Example #13
0
// This attaches the pShape to a new collide space. This method is more
// lightweight then Attach() (in fact, it's called by Attach(). This method
// together with RemoveFromSpace() can be used to move the pShape
// quickly between collide spaces.
void CShape::AttachToSpace(dSpaceID SpaceID)
{
	n_assert(!ODESpaceID);
	n_assert(ODEGeomID);
	ODESpaceID = SpaceID;
	dSpaceAdd(SpaceID, ODEGeomID);
}
Example #14
0
// Remove a static collide shape to the Level
void CLevel::RemoveShape(CShape* pShape)
{
	n_assert(pShape);
	nArray<PShape>::iterator ShapeIt = Shapes.Find(pShape);
	n_assert(ShapeIt);
	pShape->Detach();
	Shapes.Erase(ShapeIt);
}
Example #15
0
void CShape::Detach()
{
	n_assert(IsAttached());
	n_assert(ODEGeomID);
	dGeomDestroy(ODEGeomID);
	ODEGeomID = NULL;
	ODESpaceID = NULL;
}
Example #16
0
tn_array *iset_packages_in_install_order(struct iset *iset)
{
    tn_array *pkgs = NULL;
    
    packages_order(iset->pkgs, &pkgs, PKGORDER_INSTALL);
    n_assert(pkgs);
    n_assert(n_array_size(pkgs) == n_array_size(iset->pkgs));
    return pkgs;
}
struct source *source_new(const char *name, const char *type,
                          const char *path, const char *pkg_prefix)
{
    struct source   *src;
    struct stat     st;
    char            clpath[PATH_MAX], clprefix[PATH_MAX];
    int             n;

    n_assert(name || path);
    
    if (path) {
        if ((n = vf_cleanpath(clpath, sizeof(clpath), path)) == 0 ||
            n == sizeof(clpath))
            return NULL;
    
        if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
            if (clpath[n - 1] != '/')
                clpath[n++] = '/';
    
        } else {
            int l = strlen(path);
            if (clpath[n - 1] != '/' && path[l - 1] == '/')
                clpath[n++] = '/';
        }
        clpath[n] = '\0';
        
    }

    if (pkg_prefix) {
        n_assert(path);
        if ((n = vf_cleanpath(clprefix, sizeof(clprefix), pkg_prefix)) == 0 ||
            n == sizeof(clprefix))
            return NULL;
    }
    
    src = source_malloc();
    if (name) {
        src->flags |= PKGSOURCE_NAMED;
        src->name = n_strdup(name);
    }
    
    if (type) {
        src->type = n_strdup(type);
        src->flags |= PKGSOURCE_TYPE;
        
    } else {
        src->type = n_strdup(poldek_conf_PKGDIR_DEFAULT_TYPE);
    }
    
    if (path)
        src->path = n_strdup(clpath);
    
    if (pkg_prefix)
        src->pkg_prefix = n_strdup(clprefix);
    
    return src;
}
Example #18
0
void CLevel::RemoveEntity(CEntity* pEnt)
{
	n_assert(pEnt);
	n_assert(pEnt->GetLevel() == this);
	n_assert(pEnt->GetRefCount() > 0); //???can happen?
	nArray<PEntity>::iterator EntityIt = Entities.Find(pEnt);
	n_assert(EntityIt);
	Entities.Erase(EntityIt);
	pEnt->Deactivate();
	pEnt->OnRemovedFromLevel();
}
Example #19
0
tn_buf *capreq_arr_store(tn_array *arr, tn_buf *nbuf, int n)
{
    int32_t size;
    int16_t arr_size;
    int i, off;

    n_assert(n_array_size(arr) < INT16_MAX);
    
    arr_size = n;
    if (n == 0) {
        for (i=0; i < n_array_size(arr); i++) {
            struct capreq *cr = n_array_nth(arr, i);
            if (!capreq_is_bastard(cr))
                arr_size++;
        }
    }
    n_assert(arr_size);
    if (arr_size == 0)
        return NULL;
    
    n_array_isort_ex(arr, (tn_fn_cmp)capreq_strcmp_name_evr);

    if (nbuf == NULL)
        nbuf = n_buf_new(16 * arr_size);
    
    off = n_buf_tell(nbuf);
    n_buf_add_int16(nbuf, 0);   /* fake size */
    n_buf_add_int16(nbuf, arr_size);
    
    for (i=0; i < n_array_size(arr); i++) {
        struct capreq *cr = n_array_nth(arr, i);
        if (!capreq_is_bastard(cr)) {
            capreq_store(cr, nbuf);
            //printf("STORE %s %d -> %d\n", capreq_snprintf_s(cr),
            //     strlen(capreq_snprintf_s(cr)), capreq_sizeof(cr));
        }
    }

    n_buf_puts(nbuf, "\n");
    //printf("tells %d\n", n_buf_tell(nbuf));
    
    size = n_buf_tell(nbuf) - off - sizeof(uint16_t);
    n_assert(size < UINT16_MAX);
    
    n_buf_seek(nbuf, off, SEEK_SET);
    n_buf_add_int16(nbuf, size);
    n_buf_seek(nbuf, 0, SEEK_END);

    DBGF("capreq_arr_store %d (at %d), arr_size = %d\n",
         size, off, arr_size);

    return nbuf;
}
Example #20
0
float CBTFile::GetHeight(DWORD X, DWORD Z) const
{
	n_assert(Header);
	n_assert(X < Header->Width);
	n_assert(Z < Header->Height);
	if (IsFloatData()) return GetHeightF(X, Z);
	else
	{
		short Height = GetHeightS(X, Z);
		return (Height == NoDataS) ? NoDataF : Height * GetVerticalScale();
	}
}
Example #21
0
void CLevel::AttachEntity(CEntity* pEnt)
{
	n_assert(pEnt);
	n_assert(pEnt->GetLevel() == 0);
	n_assert(!Entities.Find(pEnt));

	//!!!revisit!
	pEnt->OnAttachedToLevel(this);
	pEnt->Activate();
	
	Entities.Append(pEnt);
}
Example #22
0
// Create the optional ragdoll composite for the character entity.
void CCharEntity::CreateRagdollComposite()
{
	if (CompositeName.IsValid())
	{
		n_assert(CompositeName.IsValid());
		RagdollComposite = (Physics::CRagdoll*)PhysicsSrv->LoadCompositeFromPRM(CompositeName);
		n_assert(RagdollComposite->IsA(CRagdoll::RTTI));
		RagdollComposite->SetTransform(Transform);
		RagdollComposite->SetCharacter(pNCharacter);
		RagdollComposite->Bind();
	}
}
Example #23
0
// OutFloats must be preallocated
// BT stores south-to-north column-major, but we return N-to-S row-major here
void CBTFile::GetHeights(float* OutFloats, DWORD X, DWORD Z, DWORD W, DWORD H)
{
	n_assert(Header);
	n_assert(OutFloats);
	n_assert(X < Header->Width);
	n_assert(Z < Header->Height);
	if (W == 0) W = Header->Width - X;
	else n_assert(X + W < Header->Width);
	if (H == 0) H = Header->Height - Z;
	else n_assert(Z + H < Header->Height);

	float* Dest = OutFloats;
	
	if (IsFloatData())
	{
		n_assert(Header->DataSize == sizeof(float));
		for (DWORD Row = Z; Row < Z + H; Row++)
		    for (DWORD Col = X; Col < X + W; Col++)
                Dest[Row * Header->Width + Col] =
                    HeightsF[Col * Header->Height + Header->Height - 1 - Row];
	}
	else
	{
		n_assert(Header->DataSize == sizeof(short));
		float VScale = GetVerticalScale();
		for (DWORD Row = Z; Row < Z + H; Row++)
		    for (DWORD Col = X; Col < X + W; Col++)
            {
                short Src = HeightsS[Col * Header->Height + Header->Height - 1 - Row];
                Dest[Row * Header->Width + Col] = (Src == NoDataS) ? NoDataF : Src * VScale;
            }
    }
}
Example #24
0
void CMeshShape::Detach()
{
	n_assert(IsAttached());
	n_assert(pVBuffer);
	n_assert(pIBuffer);

	dGeomTriMeshDataDestroy(ODETriMeshDataID);

	n_free(pVBuffer);
	n_free(pIBuffer);
	pVBuffer = NULL;
	pIBuffer = NULL;

	CShape::Detach();
};
// "Travel" command handler
bool CPropTransitionZone::OnTravel(const Events::CEventBase& Event)
{
	Data::PParams P = ((const Events::CEvent&)Event).Params;
	Game::CEntity* pActorEnt = EntityMgr->GetEntityByID(P->Get<CStrID>(CStrID("Actor")));
	n_assert(pActorEnt);

	const nString& LevelID = GetEntity()->Get<nString>(Attr::TargetLevelID);
	const nString& DestPt = GetEntity()->Get<nString>(Attr::DestPoint);

	//???set pause?

	if (DestPt.IsValid())
	{
		matrix44 Tfm;
		if (EntityFct->GetEntityAttribute<matrix44>(DestPt, Attr::Transform, Tfm))
			pActorEnt->Set<matrix44>(Attr::Transform, Rotate180 * Tfm); //???or fire SetTransform?
		else n_printf("Travel, Warning: destination point '%s' not found\n", DestPt.Get());
	}

	pActorEnt->Set<nString>(Attr::LevelID, LevelID);
	
	LoaderSrv->CommitChangesToDB();

	P = n_new(Data::CParams(1));
	P->Set(CStrID("LevelID"), LevelID);
	EventMgr->FireEvent(CStrID("RequestLevel"), P);

	OK;
}
Example #26
0
__inline__
static int add_reqpkg(struct pkg *pkg, struct capreq *req, struct pkg *dpkg)
{
    struct reqpkg *rpkg;
    struct reqpkg tmp_rpkg = { NULL, NULL, 0 };

    tmp_rpkg.pkg = dpkg;
    rpkg = n_array_bsearch(pkg->reqpkgs, &tmp_rpkg);

    if (rpkg == NULL) {
        rpkg = reqpkg_new(dpkg, req, 0, 0);
        
        n_array_push(pkg->reqpkgs, rpkg);
        n_array_isort(pkg->reqpkgs);
        if (dpkg->revreqpkgs == NULL)
            dpkg->revreqpkgs = n_array_new(2, NULL, (tn_fn_cmp)pkg_cmp_id);
        n_array_push(dpkg->revreqpkgs, pkg);
    }
    
    n_assert(rpkg);
    
    if (capreq_is_prereq(req)) 
        rpkg->flags |= REQPKG_PREREQ;
    
    if (capreq_is_prereq_un(req)) 
        rpkg->flags |= REQPKG_PREREQ_UN;
    
    return 1;
}
Example #27
0
static
int do_load(struct pkgdir *pkgdir, unsigned ldflags)
{
    int i;
    struct pm_ctx *pmctx = pkgdir->mod_data;

    ldflags = ldflags;          /* unused */

    n_assert(pmctx);
    if (pkgdir->pkgroups == NULL)
        pkgdir->pkgroups = pkgroup_idx_new();

    pkgdir->ts = pm_dbmtime(pmctx, pkgdir->idxpath);

    DBGF("prev_dir %p\n", pkgdir->prev_pkgdir);
    
    if (!load_db_packages(pkgdir->mod_data, pkgdir, "/"))
        return 0;
    
    for (i=0; i < n_array_size(pkgdir->pkgs); i++) {
        struct pkg *pkg = n_array_nth(pkgdir->pkgs, i);
        pkg->pkgdir = pkgdir;
    }

    return n_array_size(pkgdir->pkgs);
}
Example #28
0
// Attach a static collide shape to the Level.
void CLevel::AttachShape(Physics::CShape* pShape)
{
	n_assert(pShape);
	Shapes.Append(pShape);
	if (!pShape->Attach(ODEStaticSpaceID))
		n_error("CLevel::AttachShape(): Failed attaching a shape!");
}
Example #29
0
static
void poclidek_destroy(struct poclidek_ctx *cctx) 
{
    if (cctx->htcnf) {
        n_hash_free(cctx->htcnf);
        cctx->htcnf = NULL;
    }

    if (cctx->pkgs_available) {
	n_array_free(cctx->pkgs_available);
	cctx->pkgs_available = NULL;
    }
    
    cctx->pkgs_installed = NULL;

    if (cctx->rootdir)
        pkg_dent_free(cctx->rootdir);

    if (cctx->dbpkgdir) {
        poclidek_save_installedcache(cctx, cctx->dbpkgdir);
        pkgdir_free(cctx->dbpkgdir);
    }

    n_alloc_free(cctx->_dent_na);
    n_array_free(cctx->commands);

    n_assert(cctx->ctx);
    poldek_free(cctx->ctx);
    memset(cctx, 0, sizeof(*cctx));
}
Example #30
0
bool CFilterSet::CheckShape(CShape* pShape) const
{
	n_assert(pShape);
	return CheckMaterialType(pShape->GetMaterialType()) ||
		(pShape->GetEntity() && CheckEntityID(pShape->GetEntity()->GetUniqueID())) ||
		(pShape->GetRigidBody() && CheckRigidBodyID(pShape->GetRigidBody()->GetUniqueID()));
}