1 ###################################################
4 # authored by Eric Sebesta (esebesta@soe.sony.com
6 # Purpose: When run in a directory, it generates, and submits to
7 # perforce a basic set of object templatesbased on the files in the
8 # directory, which must be appearances.
9 # The user must pass in client and server tdf files so that we can
10 # generate object templates appropriate for the given appearances.
12 ###################################################
16 #initialize an array with all the possible extensions a valid appearance would have
17 #we use this array to check that a given file is actually an appearance
18 #@appearanceExtensions = (".lod", ".cmp", ".msh", ".sat");
20 #the template compiler must be run from the area where the tpf files should live, so make
21 #sure they are in a currently accepted location for them
22 $requiredSourceDir = "plt.shared\loc.shared\compiled\game\object";
23 $requiredSourceDirFront = "plt.shared/loc.shared/compiled/game/object";
25 #users must pass in 3 parameters, the appearance directory and the tdf file used to generate the tpfs
26 if (scalar(@ARGV) != 3)
28 die "usage: createServerOTs <clientTemplateRelative dir, i.e. \"tangible\"> <appearance dir> <TDF> \nRequire 2 parameters, received $numArgs\n";
31 #if(!cwd() =~ "sys.server")
33 # die "must be in server template directory!\n";
36 #TODO this isn't working?
37 #check the current directory against the required ones
38 if(!cwd
() =~ $requiredSourceDir)
40 if(!cwd
() =~ $requiredSourceDirFront)
42 print "not in correct dir, must be in dsrc\"\\<blah blah blah>\\game\\object\" or below\n";
47 #get the various command line parameters
48 my $clientTemplateRelativeDir = $ARGV[0];
49 print "client relative directory is $clientTemplateRelativeDir\n";
51 my $appearanceDir = $ARGV[1];
52 print "appearance directory is $appearanceDir\n";
55 print "Tdf is $TDF\n";
57 #we're all done with initial listing, delimite with a line
60 #make sure the appearance directory exists before proceeding, since we'll want to open all those files
61 #-e $appearanceDir or die "ERROR: appearance directory does not compute, I mean exist\n";
63 #read the files from the current directory
64 opendir CURRENTDIR
, $appearanceDir or die "ERROR: can't read current directory, bad: $1";
65 my @files = readdir CURRENTDIR
;
68 #process each file, building, editing, compiling, and submitting the tpf and iff file
69 foreach $file (@files)
71 print "processing $file...\n";
75 #one line seperator between files
79 ############################################################################
80 sub createOT
#11/08/01 10:58:AM
81 ############################################################################
83 #the new server template name is passed in as a parameter
86 #turn the filename into a short server template name (i.e. remove any pathing info and remove the extension)
87 $fileName =~ m/^(.*)\./;
90 my @args = ("templateCompiler", "-generate", $TDF, $base);
92 if(system(@args) != 0)
94 print "\ncouldn't run templatecompiler for template, skipping)";
102 #now get the actual iff filename
103 my $templateSourceFileName = $base . ".tpf";
104 my $compiledClientFileName = $base . ".iff";
106 #the base template has been generated, now fill in the client template name
107 my $TEMPLATE = $templateSourceFileName;
110 #build the new line we want to write (the new appearance name
111 $newLine = "clientTemplate = \"" . $clientTemplateRelativeDir . "\\" . $compiledClientFileName . "\"\n";
112 #open the new tpf file for read, so we can set the appearance name
113 open (TEMPLATE
, '<' . $templateSourceFileName) or die "failed to open original tpf file for editing\n";
114 #open a temporary file for us to write the new contents into
115 my $tempPathname = $templateSourceFileName . '.tmp';
116 open (TEMP
, '>' . $tempPathname) or die "failed to open dest filename for writing [$destPathname]\n";
118 #search the tpf the appearance line
119 while ($line = <TEMPLATE
>)
121 if($line =~ "clientTemplate =")
123 #output our new line with the client template name
128 #otherwise, write back out the original contents
132 #close all filehandles
136 # rename dest filename to source filename, clobbering the original source
137 rename $tempPathname, $templateSourceFileName;
140 @args = ("templateCompiler", "-compile", $templateSourceFileName);
142 if(system(@args) != 0)
144 print "\ncouldn't run templatecompiler -compile for template, skipping)";
152 @args = ("templateCompiler", "-submit", $templateSourceFileName);
155 #if(system(@args) != 0)
157 # print "couldn't run templatecompiler -submit for client template, skipping)";