Ejemplo n.º 1
0
void ModelPhysics::insert(ModelInstance & modelInst,
                          f32 mass,
                          f32 friction,
                          vec3 linearFactor,
                          vec3 angularFactor,
                          u32 group,
                          const ivec4 & mask03,
                          const ivec4 & mask47)
{
    if (mBodies.find(modelInst.model().uid()) == mBodies.end())
    {
        ASSERT(modelInst.mHasBody == false);

        vec3 halfExtents = modelInst.model().gmdl().halfExtents();
        auto colShapeIt = mCollisionShapes.find(halfExtents);
        btVector3 btExtents(halfExtents.x, halfExtents.y, halfExtents.z);

        btCollisionShape * pCollisionShape = nullptr;
        if (colShapeIt != mCollisionShapes.end())
            pCollisionShape = colShapeIt->second.get();
        else
        {
            auto empRes = mCollisionShapes.emplace(std::piecewise_construct,
                                                   std::forward_as_tuple(halfExtents),
                                                   std::forward_as_tuple(GNEW(kMEM_Physics, btBoxShape, btExtents)));
            pCollisionShape = empRes.first->second.get();
        }

        ModelMotionState * pMotionState = GNEW(kMEM_Physics, ModelMotionState, modelInst);
        btRigidBody::btRigidBodyConstructionInfo constrInfo(mass, pMotionState, pCollisionShape);
        constrInfo.m_friction = friction;

//        constrInfo.m_angularDamping = 0.1;
//        constrInfo.m_localInertia = btExtents;

        ModelBody * pBody = GNEW(kMEM_Physics, ModelBody, pMotionState, group, constrInfo);
        mBodies.emplace(modelInst.model().uid(), pBody);

        pBody->setLinearFactor(btVector3(linearFactor.x, linearFactor.y, linearFactor.z));
        pBody->setAngularFactor(btVector3(angularFactor.x, angularFactor.y, angularFactor.z));

        if (group == 0)
        {
            mpDynamicsWorld->addRigidBody(pBody);
        }
        else
        {
            u16 groupMask = maskFromHash(group);
            u16 mask = buildMask(mask03, mask47);
            mpDynamicsWorld->addRigidBody(pBody, maskFromHash(group), buildMask(mask03, mask47));
        }
        pBody->setGravity(btVector3(0,0,0));
    }
    else
    {
        LOG_ERROR("ModelBody for %u already created", modelInst.model().uid());
    }
}
Ejemplo n.º 2
0
i32 sprite_create(AssetHandleP pAssetHandle, i32 stageHash, i32 passHash, const mat43 & transform, Entity * pCaller)
{
    ASSERT(pAssetHandle->typeHash() == HASH::asset);
    const Asset * pAsset = pAssetHandle->data<Asset>();

    Sprite * pSprite = GNEW(kMEM_Engine, Sprite, pCaller->task().id(), pAsset);
    SpriteInstance * pSpriteInst = GNEW(kMEM_Engine, SpriteInstance, pSprite, stageHash, pass_from_hash(passHash), transform);

    SpriteInstance::sprite_insert(pCaller->task().id(), kSpriteMgrTaskId, pSpriteInst);

    return pSprite->uid();
}
Ejemplo n.º 3
0
VOID Editor::Open(const GData* data)
{
	if(mMapPtr) mMapPtr.Release();
	mMapPtr = GNEW(EMap); CHECK(mMapPtr);
	mMapPtr->Load(data);

	// set the brush
	mBrushPtr = GNEW(BrushLozenge(mMapPtr.Ptr()));
	CHECK(mBrushPtr);
	mBrushPtr->Name("map/brick.tga");
	mBrushPtr->Radius(1.0f);
	mBrushPtr->Strength(0.5f);
	mBrushPtr->Softness(1.0f);
}
Ejemplo n.º 4
0
GAudio::GAudio() : mDevice(NULL), mContext(NULL), mChannels(NULL)
{
  // open the device
  mDevice = alcOpenDevice(NULL);
  if(mDevice==NULL) GAssert("GAudio: could not open the al device!.");

  // create a context
  ALCint caps[] = 
  { 
    ALC_FREQUENCY, 44100,
    ALC_STEREO_SOURCES, 4, 
    0, 0
  };
  mContext = alcCreateContext(mDevice, caps);
  if(mContext==NULL) GAssert("GAudio: could not create a al context.");
  CHECK(alcMakeContextCurrent(mContext));

  // initialize channels.
  mChannels = GNEW(GAudioSource[MAX_AUDIO_CHANNELS]);
  CHECK(mChannels);
  for(U32 i = 0; i < MAX_AUDIO_CHANNELS; i++)
  {
    mFrees.push_back(&mChannels[i]);
  }

  // use our own distance model.
  alDistanceModel(AL_NONE);
}
Ejemplo n.º 5
0
	Constant::Constant(I32 n)
	{
		mType = CT_INT;		
		mData = GNEW(U8[sizeof(I32)]); CHECK(mData);
		mCount = 1;
		*((I32*)mData) = n;
	}
Ejemplo n.º 6
0
static edgelistitem *mkItem(Dt_t * d, edgelistitem * obj, Dtdisc_t * disc)
{
    edgelistitem *ap = GNEW(edgelistitem);

    ap->edge = obj->edge;
    return ap;
}
Ejemplo n.º 7
0
/* 
 * John M. suggests:
 * You might want to add four more:
 *
 * _ohdraw_ (optional head-end arrow for edges)
 * _ohldraw_ (optional head-end label for edges)
 * _otdraw_ (optional tail-end arrow for edges)
 * _otldraw_ (optional tail-end label for edges)
 * 
 * that would be generated when an additional option is supplied to 
 * dot, etc. and 
 * these would be the arrow/label positions to use if a user want to flip the 
 * direction of an edge (as sometimes is there want).
 * 
 * N.B. John M. asks:
 *   By the way, I don't know if you ever plan to add other letters for 
 * the xdot spec, but could you reserve "a" and also "A" (for  attribute), 
 * "n" and also "N" (for numeric), "w" (for sWitch),  "s" (for string) 
 * and "t" (for tooltip) and "x" (for position). We use  those letters in 
 * our drawing spec (and also "<" and ">"), so if you  start generating 
 * output with them, it could break what we have. 
 */
static void
xdot_begin_graph (graph_t *g, int s_arrows, int e_arrows, format_type id)
{
    int i, us;
    char* s;

    xd = GNEW(xdot_state_t);

    if (id == FORMAT_XDOT14) {
	xd->version = 14;
	xd->version_s = "1.4";
    }
    else if (id == FORMAT_XDOT12) {
	xd->version = 12;
	xd->version_s = "1.2";
    }
    else if ((s = agget(g, "xdotversion")) && s[0] && ((us = versionStr2Version(s)) > 10)) {
	xd->version = us;
	xd->version_s = s;
    }
    else {
	xd->version = versionStr2Version(XDOTVERSION);
	xd->version_s = XDOTVERSION;
    }

    if (GD_n_cluster(g))
#ifndef WITH_CGRAPH
	xd->g_draw = safe_dcl(g, g, "_draw_", "", agraphattr);
#else
	xd->g_draw = safe_dcl(g, AGRAPH, "_draw_", "");
#endif
    else
Ejemplo n.º 8
0
/* list is alpha sorted by type, the quality sorted within the type,
   then, if qualities are the same, last install wins */
bool gvplugin_install(GVC_t * gvc, api_t api,
		 char *typestr, int quality, char *packagename, char *path,
		 gvplugin_installed_t * typeptr)
{
    gvplugin_available_t *plugin, **pnext;


    if (api < 0)
	return FALSE;

    /* point to the beginning of the linked list of plugins for this api */
    pnext = &(gvc->apis[api]);

    /* keep alpha-sorted and insert new duplicates ahead of old */
    while (*pnext && strcmp(typestr, (*pnext)->typestr) > 0)
	pnext = &((*pnext)->next);

    /* keep quality sorted within type and inster new duplicates ahead of old */
    while (*pnext && strcmp(typestr, (*pnext)->typestr) == 0 && quality < (*pnext)->quality)
	pnext = &((*pnext)->next);

    plugin = GNEW(gvplugin_available_t);
    plugin->next = *pnext;
    *pnext = plugin;
    plugin->typestr = typestr;
    plugin->quality = quality;
    plugin->packagename = packagename;	/* packagename,  all packages */
    plugin->path = path;	/* filepath for .so, or NULL for builtins */
    plugin->typeptr = typeptr;	/* null if not loaded */

    return TRUE;
}
Ejemplo n.º 9
0
	Constant::Constant(F32 f)
	{
		mType = CT_FLOAT;
		mData = GNEW(U8[sizeof(F32)]); CHECK(mData);
		mCount = 1;
		*((F32*)mData) = f;
	}
Ejemplo n.º 10
0
	Constant::Constant(const Vector4& vec)
	{
		mType = CT_VECTOR;
		mData = GNEW(U8[sizeof(Vector4)]); CHECK(mData);
		mCount = 1;
		*((Vector4*)mData) = vec;
	}
Ejemplo n.º 11
0
static nsitem_t *mkItem(Dt_t * d, nsitem_t * obj, Dtdisc_t * disc)
{
    nsitem_t *ap = GNEW(nsitem_t);

    ap->np = obj->np;
    return ap;
}
Ejemplo n.º 12
0
	/*
	====================
	Load
	====================
	*/
	VOID Map2D::Load(const GData* data)
	{
		GUARD(Map2D::Load);

		CHECK(data);
		U8*data_ptr = (U8*)data->Ptr();

		// check the map header
		CHECK(*(U32*)data_ptr == (MAKEFOURCC('G','M','A','P')));
		data_ptr += sizeof(U32);

		// get the stride of the map
		mWidth = *(U32*)data_ptr;
		data_ptr += sizeof(U32);
		mHeight = *(U32*)data_ptr;
		data_ptr += sizeof(U32);

		// load all of the chunks
		for(U32 j = 0; j < mHeight; j++)
		{
			for(U32 i = 0; i < mWidth; i++)
			{
				Chunk2DPtr chunk = GNEW(Chunk2D); CHECK(chunk);
				chunk->Load(data_ptr);
				mChunks.push_back(chunk);
			}
		}

		UNGUARD;
	}
Ejemplo n.º 13
0
	Constant::Constant(const Matrix& mat)
	{
		mType = CT_MATRIX;
		mData = GNEW(U8[sizeof(Matrix)]); CHECK(mData);
		mCount = 1;
		*((Matrix*)mData) = mat;
	}
Ejemplo n.º 14
0
CMajEnv *initConstrainedMajorization(float *packedMat, int n,
				     int *ordering, int *levels,
				     int num_levels)
{
    int i, level = -1, start_of_level_above = 0;
    CMajEnv *e = GNEW(CMajEnv);
    e->A = NULL;
    e->n = n;
    e->ordering = ordering;
    e->levels = levels;
    e->num_levels = num_levels;
    e->A = unpackMatrix(packedMat, n);
    e->lev = N_GNEW(n, int);
    for (i = 0; i < e->n; i++) {
	if (i >= start_of_level_above) {
	    level++;
	    start_of_level_above =
		(level == num_levels) ? e->n : levels[level];
	}
	e->lev[ordering[i]] = level;
    }
    e->fArray1 = N_GNEW(n, float);
    e->fArray2 = N_GNEW(n, float);
    e->fArray3 = N_GNEW(n, float);
    e->fArray4 = N_GNEW(n, float);
    e->iArray1 = N_GNEW(n, int);
    e->iArray2 = N_GNEW(n, int);
    e->iArray3 = N_GNEW(n, int);
    e->iArray4 = N_GNEW(n, int);
    return e;
}
Ejemplo n.º 15
0
static degitem *mkItem(Dt_t * d, degitem * obj, Dtdisc_t * disc)
{
    degitem *ap = GNEW(degitem);

    ap->np = NULL;
    ap->deg = obj->deg;
    return ap;
}
Ejemplo n.º 16
0
	Constant::Constant(const I32* pn, U32 count)
	{
		CHECK(pn);
		mType = CT_INT_ARRAY;
		mData = GNEW(U8[count*sizeof(I32)]); CHECK(mData);
		mCount = count;
		::memcpy(mData,pn,count*sizeof(I32));
	}
Ejemplo n.º 17
0
	Constant::Constant(const Matrix* pmat, U32 count)
	{
		CHECK(pmat);
		mType = CT_MATRIX_ARRAY;
		mData = GNEW(U8[count*sizeof(Matrix)]); CHECK(mData);
		mCount = count;
		::memcpy(mData,pmat,count*sizeof(Matrix));
	}
Ejemplo n.º 18
0
	Constant::Constant(const Vector4* pvec, U32 count)
	{
		CHECK(pvec);
		mType = CT_VECTOR_ARRAY;
		mData = GNEW(U8[count*sizeof(Vector4)]); CHECK(mData);
		mCount = count;
		::memcpy(mData,pvec,count*sizeof(Vector4));
	}
Ejemplo n.º 19
0
	Constant::Constant(const F32* pf, U32 count)
	{
		CHECK(pf);
		mType = CT_FLOAT_ARRAY;
		mData = GNEW(U8[count*sizeof(F32)]); CHECK(mData);
		mCount = count;
		::memcpy(mData,pf,count*sizeof(F32));
	}
Ejemplo n.º 20
0
/*
====================
Update
====================
*/
VOID EChunk::Update()
{
	GUARD(EChunk::Update);

	// erase the layer that is invalid
	std::vector<Layer>::iterator it = mLayers.begin();
	while(it != mLayers.end())
	{
		Layer& layer = (*it);
		if(layer.total==0)
		{
			it = mLayers.erase(it);
		}
		else
		{
			++it;
		}
	}

	// update the alpha texture
	U32 width = U2P(ALPHA_STRIDE);
	U32 height = U2P(ALPHA_STRIDE);
	for(I32 k = 0; k < mLayers.size(); k++)
	{
		Layer& layer = mLayers[k];
		Image* image = GNEW(Image); CHECK(image);
		image->Width(width);
		image->Height(height);
		image->PixelFormat(PF_ALPHA);
		image->DataType(DT_UNSIGNED_BYTE);
		image->MipmapCount(1);
		if(k==0)
		{
			image->Mipmap(0,NULL,width*height*sizeof(U8));
			U8* data = (U8*)image->Mipmap(0);
			for(U32 j = 0; j < height; j++)
			{
				for( U32 i = 0; i < width; i++)
				{
					U8& alpha = layer.alpha[i+j*width];
					U8& mask = mMask[i+j*width];
					if(mask == 0) data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f);
					else data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f)+128;
				}
			}
			layer.texture->Load(image);
			layer.primitive->SetShader(dynamic_cast<Shader*>(mShaderKey->Ptr()), "base");
		}
		else
		{
			image->Mipmap(0,&layer.alpha[0],width*height*sizeof(U8));
			layer.texture->Load(image);
			layer.primitive->SetShader(dynamic_cast<Shader*>(mShaderKey->Ptr()), "layer");
		}
	}

	UNGUARD;
}
Ejemplo n.º 21
0
PointMap *newPM(void)
{
    MPairDisc *dp = GNEW(MPairDisc);

    dp->disc = intMPairDisc;
    dp->flist = 0;

    return (dtopen(&(dp->disc), Dtoset));
}
Ejemplo n.º 22
0
ModelPhysics::ModelPhysics()
{
    mTimePrev = mTimeCurr = now();

    mpBroadphase = GNEW(kMEM_Physics, btDbvtBroadphase);
    mpCollisionConfiguration = GNEW(kMEM_Physics, btDefaultCollisionConfiguration);

    mpDispatcher = GNEW(kMEM_Physics, btCollisionDispatcher, mpCollisionConfiguration);
    mpDispatcher->setNearCallback(near_callback);

    mpSolver = GNEW(kMEM_Physics, btSequentialImpulseConstraintSolver);
    mpDynamicsWorld = GNEW(kMEM_Physics,
                           btDiscreteDynamicsWorld,
                           mpDispatcher,
                           mpBroadphase,
                           mpSolver,
                           mpCollisionConfiguration);
}
Ejemplo n.º 23
0
/* mkTriGraph:
 * Generate graph with triangles as nodes and an edge iff two triangles
 * share an edge.
 */
static tgraph *mkTriGraph(surface_t * sf, int maxv, pointf * pts)
{
    tgraph *g;
    tnode *np;
    int j, i, ne = 0;
    int *edgei;
    int *jp;

    /* ne is twice no. of edges */
    for (i = 0; i < 3 * sf->nfaces; i++)
	if (sf->neigh[i] != -1)
	    ne++;

    g = GNEW(tgraph);

    /* plus 2 for nodes added as endpoints of an edge */
    g->nodes = N_GNEW(sf->nfaces + 2, tnode);

    /* allow 1 possible extra edge per triangle, plus 
     * obstacles can have at most maxv triangles touching 
     */
    edgei = N_GNEW(sf->nfaces + ne + 2 * maxv, int);
    g->edges = N_GNEW(ne/2 + 2 * maxv, tedge);
    g->nedges = 0;

    for (i = 0; i < sf->nfaces; i++) {
	np = g->nodes + i;
	np->ne = 0;
	np->edges = edgei;
	np->ctr = triCenter(pts, sf->faces + 3 * i);
	edgei += degT(sf->neigh + 3 * i) + 1;
    }
    /* initialize variable nodes */
    np = g->nodes + i;
    np->ne = 0;
    np->edges = edgei;
    np++;
    np->ne = 0;
    np->edges = edgei + maxv;

    for (i = 0; i < sf->nfaces; i++) {
	np = g->nodes + i;
	jp = sf->neigh + 3 * i;
        ne = 0;
	while ((ne < 3) && ((j = *jp++) != -1)) {
	    if (i < j) {
		double dist = DIST(np->ctr, (g->nodes + j)->ctr);
		ipair seg =
		    sharedEdge(sf->faces + 3 * i, sf->faces + 3 * j);
		addTriEdge(g, i, j, dist, seg);
	    }
	    ne++;
	}
    }

    return g;
}
Ejemplo n.º 24
0
/*
====================
bind
====================
*/
VOID Game::bind(U32 fbo)
{
    GUARD(Game::bind);

    // build the fbo
    mNullRTPtr = GNEW(Target(fbo));
    CHECK(mNullRTPtr);

    UNGUARD;
}
Ejemplo n.º 25
0
static cluster_data* cluster_map(graph_t *mastergraph, graph_t *g)
{
    /* search meta-graph to find clusters */
    graph_t *mg, *subg;
    node_t *mm, *mn;
    node_t *n;
    edge_t *me;
     /* array of arrays of node indices in each cluster */
    int **cs,*cn;
    int i,j,nclusters=0;
    bool* assigned = N_NEW(agnnodes(g), bool);
    cluster_data *cdata = GNEW(cluster_data);

    cdata->ntoplevel = agnnodes(g);
    mm = mastergraph->meta_node;
    mg = mm->graph;
    for (me = agfstout(mg, mm); me; me = agnxtout(mg, me)) {
        mn = me->head;
        subg = agusergraph(mn);
        if (!strncmp(subg->name, "cluster", 7)) {
            nclusters++;
        }
    }
    cdata->nvars=0;
    cdata->nclusters = nclusters;
    cs = cdata->clusters = N_GNEW(nclusters,int*);
    cn = cdata->clustersizes = N_GNEW(nclusters,int);
    /* fprintf(stderr,"search %d clusters...\n",nclusters); */
    for (me = agfstout(mg, mm); me; me = agnxtout(mg, me)) {
        mn = me->head;
        subg = agusergraph(mn);
        /* clusters are processed by separate calls to ordered_edges */
        if (!strncmp(subg->name, "cluster", 7)) {
            int *c;

            *cn = agnnodes(subg);
            cdata->nvars += *cn;
            c = *cs++ = N_GNEW(*cn++,int);
            /* fprintf(stderr,"Cluster with %d nodes...\n",agnnodes(subg)); */
            for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) {
                node_t *gn;
                int ind = 0;
                for (gn = agfstnode(g); gn; gn = agnxtnode(g, gn)) {
                    if(gn->id==n->id) break;
                    ind++;
                }
                /* fprintf(stderr,"  node=%s, id=%d, ind=%d\n",n->name,n->id,ind); */
                *c++=ind;
                assigned[ind]=true;
                cdata->ntoplevel--;
            }
        }
    }
Ejemplo n.º 26
0
	/*
	====================
	SetVector
	====================
	*/
	VOID Constant::SetVector(const Vector4& vec)
	{
		if(mType == CT_NONE) mType = CT_VECTOR;
		CHECK(mType == CT_VECTOR);
		if(mCount != 1)
		{
			if(mData){ GDELETE([]mData), mData = NULL; }
			mData = GNEW(U8[sizeof(Vector4)]); CHECK(mData);
			mCount = 1;
		}
		*((Vector4*)mData) = vec;
	}
Ejemplo n.º 27
0
	/*
	====================
	SetMatrix
	====================
	*/
	VOID Constant::SetMatrix(const Matrix& mat)
	{
		if(mType == CT_NONE) mType = CT_MATRIX;
		CHECK(mType == CT_MATRIX);
		if(mCount != 1)
		{
			if(mData){ GDELETE([]mData), mData = NULL; }
			mData = GNEW(U8[sizeof(Matrix)]); CHECK(mData);
			mCount = 1;
		}
		*((Matrix*)mData) = mat;
	}
Ejemplo n.º 28
0
/* mkGrid:
 * Create grid data structure.
 * cellHint provides rough idea of how many cells
 * may be needed.
 */
Grid *mkGrid(int cellHint)
{
    Grid *g;

    g = GNEW(Grid);
    _grid = g;			/* see comment above */
    g->data = dtopen(&gridDisc, Dtoset);
    g->listMem = 0;
    g->listSize = 0;
    g->cellMem = newBlock(cellHint);
    return g;
}
Ejemplo n.º 29
0
/* newBlock:
 * Create new block of size cells
 */
static block_t *newBlock(int size)
{
    block_t *newb;

    newb = GNEW(block_t);
    newb->next = 0;
    newb->mem = N_GNEW(size, cell);
    newb->endp = newb->mem + size;
    newb->cur = newb->mem;

    return newb;
}
Ejemplo n.º 30
0
/*
====================
GLoad
====================
*/
const GData* GLoad(const CHAR* path)
{
  GFile file;
  file.Open(path);
  U32 pos = file.Seek(0,FS_CUR);
  U32 size = file.Seek(0,FS_END);	
  file.Seek(pos,FS_SET);
  GData* data = GNEW(GData(size+1,0)); CHECK(data);
  CHECK(file.Read(data->Ptr(),data->Size())==size);
  file.Close();
  return data;
}