Ejemplo n.º 1
0
/*
==================
WriteMiptex
==================
*/
void WriteMiptex (void)
{
  int		i, len;
  byte	*data;
  dmiptexlump_t	*l;
  char	*path;

  path = ValueForKey (&entities[0], "_wad");
  if (!path || !path[0])
    {
      path = ValueForKey (&entities[0], "wad");
      if (!path || !path[0])
	{
	  printf ("WARNING: no wadfile specified\n");
	  texdatasize = 0;
	  return;
	}
    }

  TEX_InitFromWad (path);

  AddAnimatingTextures ();

  l = (dmiptexlump_t *)dtexdata;
  data = (byte *)&l->dataofs[nummiptex];
  l->nummiptex = nummiptex;
  for (i=0 ; i < nummiptex ; i++)
    {
      printf("miptex used:  %s\n", miptex[i]);
      l->dataofs[i] = data - (byte *)l;
      len = LoadLump (miptex[i], data);
      if (data + len - dtexdata >= MAX_MAP_MIPTEX)
	Error ("Textures exceeded MAX_MAP_MIPTEX");
      if (!len)
	l->dataofs[i] = -1;	// didn't find the texture
      data += len;
    }

  texdatasize = data - dtexdata;
}
Ejemplo n.º 2
0
/*
==================
WriteMiptex
==================
*/
void WriteMiptex (void)
{
	int		i, len;
	int j;
	byte	*data;
	unsigned int *ldata;
	dmiptexlump_t	*l;
	char	*path;
	char	fullpath[1024];

#if 0
	path = ValueForKey (&entities[0], "_wad");
	if (!path || !path[0])
	{
		path = ValueForKey (&entities[0], "wad");
		if (!path || !path[0])
		{
			printf ("WARNING: no wadfile specified\n");
			texdatasize = 0;
			return;
		}
	}
	
	sprintf (fullpath, "%s/%s", gamedir, path);

	TEX_InitFromWad (fullpath);
#endif

	AddAnimatingTextures ();

	l = (dmiptexlump_t *)dtexdata;
	data = (byte *)&l->dataofs[nummiptex];
	l->nummiptex = nummiptex;
	for (i=0 ; i<nummiptex ; i++)
	{
		l->dataofs[i] = data - (byte *)l;
		len = LoadLump (miptex[i], data);
		if (!len)
		{
#if 0
			l->dataofs[i] = -1;	// didn't find the texture
#else
			l->dataofs[i] = (data - (byte *)l) | (1<<31);
			strncpy((char *)data, miptex[i], 16);
			data[15] = 0;
			for(j=0;data[j];j++)
			{
				data[j] = tolower(data[j]);
			}

			for(j=0;idtextures[j].name;j++)
			{
				if (strcmp((char *)data, idtextures[j].name) == 0)
					break;
			}

			if (!idtextures[j].name)
			{
				Error("Couldn't get dimensions for texture \"%s\"", data);
			}

			ldata = (unsigned int *)(data + 16);
			ldata[0] = LittleLong(idtextures[j].width);
			ldata[1] = LittleLong(idtextures[j].height);

			len = 24;
#endif
		}

		if (data + len - dtexdata >= MAX_MAP_MIPTEX)
			Error ("Textures exceeded MAX_MAP_MIPTEX");

		data += len;
	}

	texdatasize = data - dtexdata;
}
Ejemplo n.º 3
0
void WriteMiptex (void)
{
	int i, success;
	byte *miptex_data;
	dmiptexlump_t *miptex_lumps;
	char *path, *currentpath;
	miptexfile_t *m;

	path = ValueForKey (&entities[0], "_wad");
	if (!path || !path[0])
	{
		path = ValueForKey (&entities[0], "wad");
		if (!path || !path[0])
		{
			printf ("WriteMiptex: no wads specified in \"wad\" key in worldspawn\n");
			texdatasize = 0;
			return;
		}
	}

	nummiptexfiles = 0;

	currentpath = path;
	while (*currentpath)
	{
		getwadname(wadname, &currentpath);
		if (wadname[0])
		{
			success = false;
			// try prepending each -wadpath on the commandline to the wad name
			for (i = 1;i < myargc;i++)
			{
				if (!Q_strcasecmp("-wadpath", myargv[i]))
				{
					i++;
					if (i < myargc)
					{
						sprintf(wadfilename, "%s%s", myargv[i], wadname);
						if ((success = loadwad(wadfilename) >= 0))
							break;
					}
				}
			}
			if (!success)
			{
				// if the map name has a path, we can try loading the wad from there
				ExtractFilePath(bspfilename, wadfilename);
				if (wadfilename[0])
				{
					strcat(wadfilename, wadname);
					if (!(success = loadwad(wadfilename) >= 0))
					{
						// try the parent directory
						ExtractFilePath(bspfilename, wadfilename);
						strcat(wadfilename, "../");
						strcat(wadfilename, wadname);
						success = loadwad(wadfilename) >= 0;
					}
				}
			}
			if (!success)
			{
				// try the wadname itself
				success = loadwad(wadname) >= 0;
			}
			if (!success)
				printf("Could not find wad \"%s\" using -wadpath options or in the same directory as the map or it's parent directory, so there!\n", wadname);
		}
	}

	for (i = 0;i < nummiptex;i++)
		CleanupName(miptex[i], miptex[i]);

	AddAnimatingTextures();

	miptex_lumps = (dmiptexlump_t *)dtexdata;
	miptex_data = (byte *)&miptex_lumps->dataofs[nummiptex];
	miptex_lumps->nummiptex = nummiptex;
	for (i=0 ; i < nummiptex ; i++)
	{
		printf("miptex used: %s", miptex[i]);
		m = FindMipTexFile(miptex[i]);
		if (m)
		{
			if (miptex_data + m->size - dtexdata >= MAX_MAP_MIPTEX)
			{
				miptex_lumps->dataofs[i] = -1;
				printf(" (MAX_MAP_MIPTEX exceeded)\n");
			}
			else if (ReadMipTexFile(m, miptex_data))
			{
				miptex_lumps->dataofs[i] = -1;
				printf(" (READ ERROR)\n");
			}
			else
			{
				miptex_lumps->dataofs[i] = miptex_data - (byte *)miptex_lumps;
				printf("\n");
				miptex_data += m->size;
			}
		}
		else
		{
			miptex_lumps->dataofs[i] = -1;
			printf(" (NOT FOUND)\n");
		}
	}

	texdatasize = miptex_data - dtexdata;
}
Ejemplo n.º 4
0
// =====================================================================================
//  WriteMiptex
// =====================================================================================
void            WriteMiptex()
{
    int             len, texsize, totaltexsize = 0;
    byte*           data;
    dmiptexlump_t*  l;
    double          start, end;

    g_texdatasize = 0;

    start = I_FloatTime();
    {
        if (!TEX_InitFromWad())
            return;

        AddAnimatingTextures();
    }
    end = I_FloatTime();
    Verbose("TEX_InitFromWad & AddAnimatingTextures elapsed time = %ldms\n", (long)(end - start));

    start = I_FloatTime();
    {
        int             i;

        for (i = 0; i < nummiptex; i++)
        {
            lumpinfo_t*     found;

            found = FindTexture(miptex + i);
            if (found)
            {
                miptex[i] = *found;
            }
            else
            {
                miptex[i].iTexFile = miptex[i].filepos = miptex[i].disksize = 0;
            }
        }
    }
    end = I_FloatTime();
    Verbose("FindTextures elapsed time = %ldms\n", (long)(end - start));

    start = I_FloatTime();
    {
        int             i;
        texinfo_t*      tx = g_texinfo;

        // Sort them FIRST by wadfile and THEN by name for most efficient loading in the engine.
        qsort((void*)miptex, (size_t) nummiptex, sizeof(miptex[0]), lump_sorter_by_wad_and_name);

        // Sleazy Hack 104 Pt 2 - After sorting the miptex array, reset the texinfos to point to the right miptexs
        for (i = 0; i < g_numtexinfo; i++, tx++)
        {
            char*          miptex_name = texmap64_retrieve(tx->miptex);

            tx->miptex = FindMiptex(miptex_name);

            // Free up the originally strdup()'ed miptex_name
            free(miptex_name);
        }
    }
    end = I_FloatTime();
    Verbose("qsort(miptex) elapsed time = %ldms\n", (long)(end - start));

    start = I_FloatTime();
    {
        int             i;

        // Now setup to get the miptex data (or just the headers if using -wadtextures) from the wadfile
        l = (dmiptexlump_t*)g_dtexdata;
        data = (byte*) & l->dataofs[nummiptex];
        l->nummiptex = nummiptex;
        for (i = 0; i < nummiptex; i++)
        {
            l->dataofs[i] = data - (byte*) l;
            len = LoadLump(miptex + i, data, &texsize);

            if (!len)
            {
                l->dataofs[i] = -1;                        // didn't find the texture
            }
            else
            {
                totaltexsize += texsize;

                hlassume(totaltexsize < g_max_map_miptex, assume_MAX_MAP_MIPTEX);
            }
            data += len;
        }
        g_texdatasize = data - g_dtexdata;
    }
    end = I_FloatTime();
    Log("Texture usage is at %1.2f mb (of %1.2f mb MAX)\n", (float)totaltexsize / (1024 * 1024),
        (float)g_max_map_miptex / (1024 * 1024));
    Verbose("LoadLump() elapsed time = %ldms\n", (long)(end - start));
}