Beispiel #1
0
void Tribe::AddResource(csString resource, int amount, csString nick)
{
    for(size_t i=0; i < resources.GetSize(); i++)
    {
        if(resources[i].name == resource)
        {
            resources[i].amount += amount;
            resources[i].nick = nick;
            SaveResource(&resources[i],false); // Update resource

            if(resource == GetNeededResource() && amount > 0)
            {
                UpdateResourceRate(amount);
            }

            return;
        }
    }
    Resource newRes;
    newRes.name  = resource;
    newRes.amount = amount;
    SaveResource(&newRes,true); // New resource
    resources.Push(newRes);

    if(resource == GetNeededResource() && amount > 0)
    {
        UpdateResourceRate(amount);
    }
}
int PASCAL WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR  lpCmdLine, int nCmdShow)
{
	FILE *ifp;
	char buffer[220];

	if(!ParseCommandLine (lpCmdLine))
	{
		printf("Sound Resource - Version 1.0 - by Peter Ward\n\n");
		printf("Usage: SOUNDRSC [path]<soundrc.irc> [path]<output>\n");
		printf("    Sorry... ALL input MUST .WAV files (PCM or IMA ADPCM)\n");
		printf("    Only includes [LOADSOUND] Tokens\n");
		return(0);
	}

	ifp=fopen(FileList,"r");
	if(!ifp)
	{
		printf("Can't open soundrc.irc file (%s)\n",FileList);
		return(0);
	}

	TheTime=GetCurrentTime();

 	SoundTable=new C_Hash;
 	SoundTable->Setup(512);
 	SoundTable->SetFlags(HSH_REMOVE);

 	while(fgets(buffer,200,ifp) > 0)
 		ProcessSoundLine(buffer);
 	fclose(ifp);

 	SaveResource(OutputFile);
 	printf("Input (%1ld)... Output (%1ld)  %%%1ld\n",InputSize,OutputSize,OutputSize*100/InputSize);
	return(0);
}
void ProcessPathList(char buffer[])
{
	FILE *pfp;
	char pathbuf[202];

	ImageTable=new C_Hash;
	ImageTable->Setup(512);
	ImageTable->SetFlags(HSH_REMOVE);

	ProcessImageLine(buffer);

	pfp=fopen(PathFile,"r");
	if(!pfp)
	{
		printf("Can't open path file (%s)\n",PathFile);
		return;
	}

	while(fgets(pathbuf,200,pfp) > 0)
		ProcessImageLine(pathbuf);

	fclose(pfp);

	SaveResource(OutputFile);
	if(ImageTable)
	{
		ImageTable->Cleanup();
		delete ImageTable;
		ImageTable=NULL;
	}
	if(OriginalImage)
	{
		delete OriginalImage;
		OriginalImage=NULL;
	}
	if(InputSize)
		printf("Input (%1ld)... Output (%1ld)  %%%1ld\n",InputSize,OutputSize,OutputSize*100/InputSize);
	InputSize=0;
	OutputSize=0;
	HeaderSize=0;
	DataSize=0;
}
Beispiel #4
0
//-*****************************************************************************
void ProcessSubD( ISubD &subd, ProcArgs &args, const std::string & facesetName )
{
    ISubDSchema &ss = subd.getSchema();

    TimeSamplingPtr ts = ss.getTimeSampling();

    SampleTimeSet sampleTimes;
    GetRelevantSampleTimes( args, ts, ss.getNumSamples(), sampleTimes );

    bool multiSample = sampleTimes.size() > 1;

    //include this code path for future expansion
    bool isHierarchicalSubD = false;
    bool hasLocalResources = false;
    
    
    
    std::vector<IFaceSet> faceSets;
    std::vector<std::string> faceSetResourceNames;
    if ( facesetName.empty() )
    {
        std::vector <std::string> childFaceSetNames;
        ss.getFaceSetNames(childFaceSetNames);
        
        faceSets.reserve(childFaceSetNames.size());
        faceSetResourceNames.reserve(childFaceSetNames.size());
        
        for (size_t i = 0; i < childFaceSetNames.size(); ++i)
        {
            faceSets.push_back(ss.getFaceSet(childFaceSetNames[i]));
            
            IFaceSet & faceSet = faceSets.back();
            
            std::string resourceName = args.getResource(
                    faceSet.getFullName() );
            
            if ( resourceName.empty() )
            {
                resourceName = args.getResource( faceSet.getName() );
            }
            
#ifdef PRMAN_USE_ABCMATERIAL
                
                Mat::MaterialFlatten mafla(faceSet);
                
                if (!mafla.empty())
                {
                    if (!hasLocalResources)
                    {
                        RiResourceBegin();
                        hasLocalResources = true;
                    }
                    
                    RiAttributeBegin();
                    
                    if ( !resourceName.empty() )
                    {
                        //restore existing resource state here
                        RestoreResource( resourceName );
                    }
                    
                    
                    WriteMaterial( mafla, args );
                    
                    resourceName = faceSet.getFullName();
                    SaveResource( resourceName );
                    
                    RiAttributeEnd();
                }
#endif
            faceSetResourceNames.push_back(resourceName);
            
        }
    }
#ifdef PRMAN_USE_ABCMATERIAL    
    else
    {
        //handle single faceset material directly
        if ( ss.hasFaceSet( facesetName ) )
        {
            IFaceSet faceSet = ss.getFaceSet( facesetName );
            ApplyObjectMaterial(faceSet, args);
            
        }
    }
#endif
    
    
    
    
    

    if ( multiSample ) { WriteMotionBegin( args, sampleTimes ); }

    for ( SampleTimeSet::iterator iter = sampleTimes.begin();
          iter != sampleTimes.end(); ++iter )
    {
        
        ISampleSelector sampleSelector( *iter );

        ISubDSchema::Sample sample = ss.getValue( sampleSelector );

        RtInt npolys = (RtInt) sample.getFaceCounts()->size();

        ParamListBuilder paramListBuilder;

        paramListBuilder.add( "P", (RtPointer)sample.getPositions()->get() );

        IV2fGeomParam uvParam = ss.getUVsParam();
        if ( uvParam.valid() )
        {
            ICompoundProperty parent = uvParam.getParent();
            
            if ( !args.flipv )
            {
                AddGeomParamToParamListBuilder<IV2fGeomParam>(
                    parent,
                    uvParam.getHeader(),
                    sampleSelector,
                    "float",
                    paramListBuilder,
                    2,
                    "st");
            }
            else if ( std::vector<float> * values =
                    AddGeomParamToParamListBuilderAsFloat<IV2fGeomParam, float>(
                        parent,
                        uvParam.getHeader(),
                        sampleSelector,
                        "float",
                        paramListBuilder,
                        "st") )
            {
                for ( size_t i = 1, e = values->size(); i < e; i += 2 )
                {
                    (*values)[i] = 1.0 - (*values)[i];
                }
            }
            
        }

        ICompoundProperty arbGeomParams = ss.getArbGeomParams();
        AddArbitraryGeomParams( arbGeomParams,
                    sampleSelector, paramListBuilder );

        std::string subdScheme = sample.getSubdivisionScheme();

        SubDTagBuilder tags;

        ProcessFacevaryingInterpolateBoundry( tags, sample );
        ProcessInterpolateBoundry( tags, sample );
        ProcessFacevaryingPropagateCorners( tags, sample );
        ProcessHoles( tags, sample );
        ProcessCreases( tags, sample );
        ProcessCorners( tags, sample );
        
        if ( !facesetName.empty() )
        {
            if ( ss.hasFaceSet( facesetName ) )
            {
                IFaceSet faceSet = ss.getFaceSet( facesetName );
                
                ApplyResources( faceSet, args );
                
                // TODO, move the hold test outside of MotionBegin
                // as it's not meaningful to change per sample
                
                IFaceSetSchema::Sample faceSetSample = 
                        faceSet.getSchema().getValue( sampleSelector );
                
                std::set<int> facesToKeep;
                
                facesToKeep.insert( faceSetSample.getFaces()->get(),
                        faceSetSample.getFaces()->get() +
                                faceSetSample.getFaces()->size() );
                
                for ( int i = 0; i < npolys; ++i )
                {
                    if ( facesToKeep.find( i ) == facesToKeep.end() )
                    {
                        tags.add( "hole" );
                        tags.addIntArg( i );
                    }
                }
            }
        }
        else
        {
            //loop through the facesets and determine whether there are any
            //resources assigned to each
            
            for (size_t i = 0; i < faceSetResourceNames.size(); ++i)
            {
                const std::string & resourceName = faceSetResourceNames[i];
                
                //TODO, visibility?
                
                if ( !resourceName.empty() )
                {
                    IFaceSet & faceSet = faceSets[i];
                    
                    isHierarchicalSubD = true;
                    
                    tags.add("faceedit");
                    
                    Int32ArraySamplePtr faces = faceSet.getSchema().getValue(
                            sampleSelector ).getFaces();
                    
                    for (size_t j = 0, e = faces->size(); j < e; ++j)
                    {
                        tags.addIntArg(1); //yep, every face gets a 1 in front of it too
                        tags.addIntArg( (int) faces->get()[j]);
                    }
                    
                    tags.addStringArg( "attributes" );
                    tags.addStringArg( resourceName );
                    tags.addStringArg( "shading" );
                }
            }
        }


        if ( isHierarchicalSubD )
        {
            RiHierarchicalSubdivisionMeshV(
                const_cast<RtToken>( subdScheme.c_str() ),
                npolys,
                (RtInt*) sample.getFaceCounts()->get(),
                (RtInt*) sample.getFaceIndices()->get(),
                tags.nt(),
                tags.tags(),
                tags.nargs( true ),
                tags.intargs(),
                tags.floatargs(),
                tags.stringargs(),
                paramListBuilder.n(),
                paramListBuilder.nms(),
                paramListBuilder.vals()
                                          );
        }
        else
        {
            RiSubdivisionMeshV(
                const_cast<RtToken>(subdScheme.c_str() ),
                npolys,
                (RtInt*) sample.getFaceCounts()->get(),
                (RtInt*) sample.getFaceIndices()->get(),
                tags.nt(),
                tags.tags(),
                tags.nargs( false ),
                tags.intargs(),
                tags.floatargs(),
                paramListBuilder.n(),
                paramListBuilder.nms(),
                paramListBuilder.vals()
                              );
        }
    }

    if ( multiSample ) { RiMotionEnd(); }
    
    if ( hasLocalResources ) { RiResourceEnd(); }
}
int PASCAL WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR  lpCmdLine, int nCmdShow)
{
	FILE *ifp;
	char buffer[220];

	if(!ParseCommandLine (lpCmdLine))
	{
		printf("Make Resource - Version 1.0 - by Peter Ward\n\n");
		printf("Usage: MAKERSC [path]<imagerc.irc> [path]<output>\n");
		printf("    Sorry... ALL input MUST be in 16bit targa format\n");
		return(0);
	}

	ifp=fopen(FileList,"r");
	if(!ifp)
	{
		printf("Can't open imagerc.irc file (%s)\n",FileList);
		return(0);
	}

	TheTime=GetCurrentTime();

	if(!UsePathList)
	{
		ImageTable=new C_Hash;
		ImageTable->Setup(512);
		ImageTable->SetFlags(HSH_REMOVE);

		while(fgets(buffer,200,ifp) > 0)
			ProcessImageLine(buffer);
		fclose(ifp);

		SaveResource(OutputFile);
		if(ImageTable)
		{
			ImageTable->Cleanup();
			delete ImageTable;
		}
		if(OriginalImage)
			delete OriginalImage;

		if(InputSize)
			printf("Input (%1ld)... Output (%1ld)  %%%1ld\n",InputSize,OutputSize,OutputSize*100/InputSize);
	}
	else
	{
		while(fgets(buffer,200,ifp) > 0)
			ProcessPathList(buffer);
		fclose(ifp);
	}

	if(ColorOrder)
	{
		ColorOrder->Cleanup();
		delete ColorOrder;
	}
	if(IDOrder)
	{
		IDOrder->Cleanup();
		delete IDOrder;
	}
	return(0);
}