//
// =======================================================================================================================
//    Map_SaveSelected Saves selected world brushes and whole entities with partial/full selections
// =======================================================================================================================
//
void Map_SaveSelected(CMemFile *pMemFile, CMemFile *pPatchFile)
{
	entity_t	*e, *next;
	int			count;
	CString		strTemp;

	// write version
	g_qeglobals.mapVersion = MAP_VERSION;
	MemFile_fprintf(pMemFile, "Version %1.2f\n", MAP_VERSION);

	// write world entity first
	world_entity->origin.Zero();
	Entity_WriteSelected(world_entity, pMemFile);

	// then write all other ents
	count = 1;

	for (e = entities.next; e != &entities; e = next) {
		MemFile_fprintf(pMemFile, "// entity %i\n", count);
		count++;
		Entity_WriteSelected(e, pMemFile);
		next = e->next;
	}

	// if (pPatchFile) Patch_WriteFile(pPatchFile);
}
//
// =======================================================================================================================
//    Entity_WriteSelected to a CMemFile
// =======================================================================================================================
//
void Entity_WriteSelected(entity_t *e, CMemFile *pMemFile)
{
    brush_t *b;
    idVec3	origin;
    char	text[128];
    int		count;

    for (b = e->brushes.onext; b != &e->brushes; b = b->onext)
    {
        if (IsBrushSelected(b))
        {
            break;	// got one
        }
    }

    if (b == &e->brushes)
    {
        return;		// nothing selected
    }

    // if fixedsize, calculate a new origin based on the current brush position
    if (e->eclass->fixedsize || EntityHasModel(e))
    {
        if (!GetVectorForKey(e, "origin", origin))
        {
            VectorSubtract(e->brushes.onext->mins, e->eclass->mins, origin);
            sprintf(text, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
            SetKeyValue(e, "origin", text);
        }
    }

    MemFile_fprintf(pMemFile, "{\n");

    count = e->epairs.GetNumKeyVals();
    for (int j = 0; j < count; j++)
    {
        MemFile_fprintf(pMemFile, "\"%s\" \"%s\"\n", e->epairs.GetKeyVal(j)->GetKey().c_str(), e->epairs.GetKeyVal(j)->GetValue().c_str());
    }

    if (!EntityHasModel(e))
    {
        count = 0;
        for (b = e->brushes.onext; b != &e->brushes; b = b->onext)
        {
            if (e->eclass->fixedsize && !b->entityModel)
            {
                continue;
            }
            if (IsBrushSelected(b))
            {
                MemFile_fprintf(pMemFile, "// brush %i\n", count);
                count++;
                Brush_Write( b, pMemFile, e->origin, ( g_PrefsDlg.m_bNewMapFormat != FALSE ) );
            }
        }
    }

    MemFile_fprintf(pMemFile, "}\n");
}
Beispiel #3
0
void Write3DMatrix (CMemFile *f, int z, int y, int x, float *m) {
	int		i;

	MemFile_fprintf (f, "(\n");
	for (i = 0 ; i < z ; i++) {
		Write2DMatrix (f, y, x, m + i*(x*y) );
	}
	MemFile_fprintf (f, ")\n");
}
Beispiel #4
0
void Write2DMatrix (CMemFile *f, int y, int x, float *m) {
	int		i;

	MemFile_fprintf (f, "( ");
	for (i = 0 ; i < y ; i++) {
		Write1DMatrix (f, x, m + i*x);
		MemFile_fprintf (f, " ");
	}
	MemFile_fprintf (f, ")\n");
}
Beispiel #5
0
void Write1DMatrix (CMemFile *f, int x, float *m) {
	int		i;

	MemFile_fprintf (f, "( ");
	for (i = 0 ; i < x ; i++) {
		if (m[i] == (int)m[i] ) {
			MemFile_fprintf (f, "%i ", (int)m[i]);
		} else {
			MemFile_fprintf (f, "%f ", m[i]);
		}
	}
	MemFile_fprintf (f, ")");
}
Beispiel #6
0
void Terrain_Write( terrainMesh_t *p, CMemFile *file ) {
	int w;
	int h;
	terrainVert_t *vert;

	MemFile_fprintf( file, " {\n  terrainDef\n  {\n" );
	MemFile_fprintf( file, "   %d %d %f %f\n", p->width, p->height, p->scale_x, p->scale_y );
	MemFile_fprintf( file, "   %f %f %f\n", p->origin[ 0 ], p->origin[ 1 ], p->origin[ 2 ] );

	vert = p->heightmap;
	for( h = 0; h < p->height; h++ ) {
		for( w = 0; w < p->width; w++, vert++ ) {
			MemFile_fprintf( file, "   %f %s\n", vert->height, ( const char * )Terrain_SurfaceString( &vert->tri ) );
		}
	}
   
	MemFile_fprintf( file, "  }\n }\n" );
}
Beispiel #7
0
//
//===========
//Map_SaveSelected
//===========
//
// Saves selected world brushes and whole entities with partial/full selections
//
void Map_SaveSelected(CMemFile* pMemFile, CMemFile* pPatchFile)
{
	entity_t	*e, *next;
	int count;
	CString strTemp;
  
	// write world entity first
	Entity_WriteSelected(world_entity, pMemFile);

	// then write all other ents
	count = 1;
	for (e=entities.next ; e != &entities ; e=next)
	{
		MemFile_fprintf(pMemFile, "// entity %i\n", count);
		count++;
 		Entity_WriteSelected(e, pMemFile);
		next = e->next;
	}

  //if (pPatchFile)
  //  Patch_WriteFile(pPatchFile);
}
Beispiel #8
0
//
//============
//Entity_WriteSelected to a CMemFile
//============
//
void Entity_WriteSelected(entity_t *e, CMemFile* pMemFile)
{
	epair_t		*ep;
	brush_t		*b;
	vec3_t		origin;
	char		text[128];
	int			count;

	for (b=e->brushes.onext ; b != &e->brushes ; b=b->onext)
		if (IsBrushSelected(b))
			break;	// got one

	if (b == &e->brushes)
		return;		// nothing selected

	// if fixedsize, calculate a new origin based on the current
	// brush position
	if (e->eclass->fixedsize)
	{
#ifdef SOF
	// I suspect these 2 will end up doing the same thing, but for now that VectorSubtract will break ours -slc
	if (strnicmp(e->eclass->name, "misc_",			5) == 0 ||
		strnicmp(e->eclass->name, "light_",			6) == 0 ||
		strnicmp(e->eclass->name, "m_",				2) == 0 ||
		strnicmp(e->eclass->name, "item_weapon_",	12)== 0 ||
		strnicmp(e->eclass->name, "item_ammo_",		10)== 0
		)
	{
		VectorCopy(e->origin, origin);
	}
#else
    if (strnicmp(e->eclass->name, "misc_model",10) == 0 && e->md3Class != NULL)
    {
		// Bugfix? I'm guessing this should have been the same as in Entity_Write, ie the copy version..... -slc
		//VectorCopy(e->origin, origin);	
		VectorSubtract (e->brushes.onext->mins, e->md3Class->mins, origin);
    }
#endif
    else
    {
		  VectorSubtract (e->brushes.onext->mins, e->eclass->mins, origin);
    }
    sprintf (text, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
		SetKeyValue (e, "origin", text);
	}

  MemFile_fprintf(pMemFile, "{\n");
	for (ep = e->epairs ; ep ; ep=ep->next)
	  MemFile_fprintf(pMemFile, "\"%s\" \"%s\"\n", ep->key, ep->value);

  if (!e->eclass->fixedsize)
  {
	  count = 0;
	  for (b=e->brushes.onext ; b != &e->brushes ; b=b->onext)
	  {
		  if (IsBrushSelected(b))
		  {
			  MemFile_fprintf(pMemFile, "// brush %i\n", count);
			  count++;
			  Brush_Write (b, pMemFile);
		  }
	  }
  }
	MemFile_fprintf(pMemFile, "}\n");
}