Added: #1440 Project value macros

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 13 years ago
parent 5345ca742d
commit 252989fc69

@ -34,8 +34,12 @@
// NeL includes // NeL includes
// #include <nel/misc/debug.h> // #include <nel/misc/debug.h>
#include <nel/georges/u_form_elm.h> #include <nel/georges/u_form_elm.h>
#include <nel/net/service.h>
#include <nel/misc/config_file.h>
#include <nel/misc/path.h>
// Project includes // Project includes
#include "pipeline_service.h"
using namespace std; using namespace std;
// using namespace NLMISC; // using namespace NLMISC;
@ -112,31 +116,165 @@ bool CPipelineProject::getValueNb(uint &result, const std::string &name)
return true; return true;
} }
bool CPipelineProject::getMacro(std::string &result, const std::string &name)
{
// TODO: Maybe preload the macros into a map.
NLGEORGES::UFormElm *elm;
if (!m_Form->getRootNode().getNodeByName(&elm, "Macros"))
{
nlwarning("Node 'Macros' not found in '%s'", m_Form->getFilename().c_str());
return false;
}
uint size;
if (!elm->getArraySize(size))
{
nlwarning("Array size of node 'Macros' not found in '%s'", name.c_str(), m_Form->getFilename().c_str());
return false;
}
for (uint i = 0; i < size; ++i)
{
NLGEORGES::UFormElm *macro;
if (!elm->getArrayNode(&macro, i))
{
nlwarning("Array node of node 'Macros' at '%i' not found in '%s'", i, m_Form->getFilename().c_str());
return false;
}
std::string macroName;
if (!macro->getValueByName(macroName, "Name"))
{
nlwarning("Macro does not contain value 'Name' at '%i' in '%s'", i, m_Form->getFilename().c_str());
return false;
}
if (macroName == name)
{
std::string macroValue;
if (!macro->getValueByName(macroValue, "Value"))
{
nlwarning("Macro does not contain value 'Value' at '%i' in '%s'", i, m_Form->getFilename().c_str());
return false;
}
parseValue(result, macroValue);
return true;
}
}
nlwarning("Macro '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str());
result = std::string("[&") + name + std::string("]");
return false;
}
std::string CPipelineProject::getName()
{
return NLMISC::CFile::getFilenameWithoutExtension(m_Form->getFilename());
}
std::string CPipelineProject::getOutputDirectory()
{
return g_PipelineDirectory + getName() + "/";
}
std::string CPipelineProject::getTempDirectory()
{
if (m_TempDirectory.empty())
{
std::stringstream ss;
ss << g_PipelineDirectory;
ss << getName();
ss << ".";
ss << NLMISC::CTime::getSecondsSince1970();
ss << ".";
ss << rand();
ss << PIPELINE_DIRECTORY_TEMP_SUFFIX;
m_TempDirectory = ss.str();
}
return m_TempDirectory;
}
void CPipelineProject::parseValue(std::string &result, const std::string &value) void CPipelineProject::parseValue(std::string &result, const std::string &value)
{ {
std::stringstream ss; std::stringstream ss;
std::string::const_iterator lastEnd = value.begin(); std::string::const_iterator lastEndPP = value.begin();
std::string::const_iterator findOpen = find(lastEnd, value.end(), '['); std::string::const_iterator findOpen = find(lastEndPP, value.end(), '[');
ss << std::string(lastEnd, findOpen); ss << std::string(lastEndPP, findOpen);
while (findOpen != value.end()) while (findOpen != value.end())
{ {
++findOpen; ++findOpen;
switch (*findOpen) switch (*findOpen)
{ {
case '$': case '$': // SERVICE CONFIGURATION VALUE
// TODO {
++findOpen;
lastEndPP = find(findOpen, value.end(), ']');
std::string tagName = std::string(findOpen, lastEndPP);
if (NLNET::IService::getInstance()->ConfigFile.exists(tagName))
{
std::string cfgValue = NLNET::IService::getInstance()->ConfigFile.getVar(tagName).asString();
ss << cfgValue;
}
else
{
nlwarning("Unknown service configuration value '%s' in '%s'", tagName.c_str(), m_Form->getFilename().c_str());
ss << "[$";
ss << tagName;
ss << "]";
}
++lastEndPP;
}
break; break;
case '@': case '!': // SPECIAL PROJECT VALUE
// TODO {
++findOpen;
lastEndPP = find(findOpen, value.end(), ']');
std::string tagName = std::string(findOpen, lastEndPP);
if (tagName == "OutputDirectory")
{
ss << getOutputDirectory();
}
else if (tagName == "TempDirectory")
{
ss << getTempDirectory();
}
else
{
nlwarning("Unknown special project value '%s' in '%s'", tagName.c_str(), m_Form->getFilename().c_str());
ss << "[!";
ss << tagName;
ss << "]";
}
++lastEndPP;
}
break; break;
case '#': case '&': // PROJECT MACRO VALUE
// TODO {
++findOpen;
lastEndPP = find(findOpen, value.end(), ']');
std::string tagName = std::string(findOpen, lastEndPP);
std::string macroValue;
getMacro(macroValue, tagName);
ss << macroValue;
++lastEndPP;
}
break; break;
default: case '@': // WORKSPACE PROJECT VALUE
// TODO
// break;
case '#': // LEVELDESIGN SHEET VALUE
// TODO // TODO
// break;
default:
lastEndPP = find(findOpen, value.end(), ']');
--findOpen;
++lastEndPP;
std::string unknownTag = std::string(findOpen, lastEndPP);
ss << unknownTag;
nlwarning("Unknown tag '%s'", unknownTag.c_str());
break; break;
} }
findOpen = find(lastEndPP, value.end(), '[');
ss << std::string(lastEndPP, findOpen);
} }
result = ss.str(); result = ss.str();

@ -51,6 +51,7 @@ class CPipelineProject
protected: protected:
CPipelineWorkspace *m_Workspace; CPipelineWorkspace *m_Workspace;
NLMISC::CRefPtr<NLGEORGES::UForm> m_Form; NLMISC::CRefPtr<NLGEORGES::UForm> m_Form;
std::string m_TempDirectory;
public: public:
CPipelineProject(CPipelineWorkspace *workspace, NLGEORGES::UForm *form); CPipelineProject(CPipelineWorkspace *workspace, NLGEORGES::UForm *form);
@ -60,6 +61,17 @@ public:
bool getValues(std::vector<std::string> &resultAppend, const std::string &name); bool getValues(std::vector<std::string> &resultAppend, const std::string &name);
bool getValueNb(uint &result, const std::string &name); bool getValueNb(uint &result, const std::string &name);
bool getMacro(std::string &result, const std::string &name);
/// Gets the project name.
std::string getName();
/// Gets the output directory for the project.
std::string getOutputDirectory();
/// Gets a temporary directory for the current process. Should be created/deleted by process when (no longer) needed. Temp directories MUST NOT be shared between seperate processes, as these may run in different systems.
std::string getTempDirectory();
private: private:
// Strip all macros and turn all macro paths into real paths. // Strip all macros and turn all macro paths into real paths.
void parseValue(std::string &result, const std::string &value); void parseValue(std::string &result, const std::string &value);

@ -49,6 +49,7 @@
// Project includes // Project includes
#include "pipeline_workspace.h" #include "pipeline_workspace.h"
#include "pipeline_project.h"
#include "database_status.h" #include "database_status.h"
#include "pipeline_interface_impl.h" #include "pipeline_interface_impl.h"
#include "pipeline_process_impl.h" #include "pipeline_process_impl.h"
@ -301,8 +302,10 @@ public:
{ {
g_DatabaseDirectory = CPath::standardizePath(ConfigFile.getVar("DatabaseDirectory").asString(), true); g_DatabaseDirectory = CPath::standardizePath(ConfigFile.getVar("DatabaseDirectory").asString(), true);
if (!CFile::isDirectory(g_DatabaseDirectory)) nlwarning("'DatabaseDirectory' does not exist! (%s)", g_DatabaseDirectory.c_str()); if (!CFile::isDirectory(g_DatabaseDirectory)) nlwarning("'DatabaseDirectory' does not exist! (%s)", g_DatabaseDirectory.c_str());
ConfigFile.getVar("DatabaseDirectory").setAsString(g_DatabaseDirectory);
g_PipelineDirectory = CPath::standardizePath(ConfigFile.getVar("PipelineDirectory").asString(), true); g_PipelineDirectory = CPath::standardizePath(ConfigFile.getVar("PipelineDirectory").asString(), true);
if (!CFile::isDirectory(g_PipelineDirectory)) nlwarning("'PipelineDirectory' does not exist! (%s)", g_PipelineDirectory.c_str()); if (!CFile::isDirectory(g_PipelineDirectory)) nlwarning("'PipelineDirectory' does not exist! (%s)", g_PipelineDirectory.c_str());
ConfigFile.getVar("PipelineDirectory").setAsString(g_PipelineDirectory);
s_TaskManager = new CTaskManager(); s_TaskManager = new CTaskManager();
@ -480,6 +483,43 @@ NLMISC_COMMAND(listProcessPlugins, "List process plugins.", "<processName>")
} }
log.displayNL("LISTPP '%s': '%s' (%s), '%s' (%s)", args[0].c_str(), it->Handler.c_str(), statusHandler.c_str(), it->Info.c_str(), statusInfo.c_str()); log.displayNL("LISTPP '%s': '%s' (%s), '%s' (%s)", args[0].c_str(), it->Handler.c_str(), statusHandler.c_str(), it->Info.c_str(), statusInfo.c_str());
} }
return true;
}
NLMISC_COMMAND(showProjectMacro, "Show project macro.", "<projectName> <macroName>")
{
if(args.size() != 2) return false;
PIPELINE::CPipelineProject *project = PIPELINE::g_PipelineWorkspace->getProject(args[0]);
if (project)
{
std::string result;
project->getMacro(result, args[1]);
log.displayNL("MACRO: '%s', '%s': '%s'", args[0].c_str(), args[1].c_str(), result.c_str());
return true;
}
else
{
log.displayNL("MACRO: Project '%s' does not exist", args[0].c_str());
return false;
}
}
NLMISC_COMMAND(showProjectValue, "Show project value.", "<projectName> <valueName>")
{
if(args.size() != 2) return false;
PIPELINE::CPipelineProject *project = PIPELINE::g_PipelineWorkspace->getProject(args[0]);
if (project)
{
std::string result;
project->getValue(result, args[1]);
log.displayNL("VALUE: '%s', '%s': '%s'", args[0].c_str(), args[1].c_str(), result.c_str());
return true;
}
else
{
log.displayNL("VALUE: Project '%s' does not exist", args[0].c_str());
return false;
}
} }
NLNET_SERVICE_MAIN(PIPELINE::CPipelineService, PIPELINE_SHORT_SERVICE_NAME, PIPELINE_LONG_SERVICE_NAME, 0, PIPELINE::s_ShardCallbacks, PIPELINE_SERVICE_DIRECTORY, PIPELINE_SERVICE_DIRECTORY) NLNET_SERVICE_MAIN(PIPELINE::CPipelineService, PIPELINE_SHORT_SERVICE_NAME, PIPELINE_LONG_SERVICE_NAME, 0, PIPELINE::s_ShardCallbacks, PIPELINE_SERVICE_DIRECTORY, PIPELINE_SERVICE_DIRECTORY)

@ -170,6 +170,17 @@ void CPipelineWorkspace::getProcessPlugins(std::vector<CProcessPluginInfo> &resu
} }
} }
CPipelineProject *CPipelineWorkspace::getProject(const std::string &project)
{
std::map<std::string, CPipelineProject *>::const_iterator it = m_Projects.find(project);
if (it == m_Projects.end())
{
nlwarning("Project '%s' does not exist", project.c_str());
return NULL;
}
return it->second;
}
} /* namespace PIPELINE */ } /* namespace PIPELINE */
/* end of file */ /* end of file */

@ -77,7 +77,7 @@ public:
virtual ~CPipelineWorkspace(); virtual ~CPipelineWorkspace();
void getProcessPlugins(std::vector<CProcessPluginInfo> &result, const std::string &process); void getProcessPlugins(std::vector<CProcessPluginInfo> &result, const std::string &process);
CPipelineProject *getProject(const std::string &project) { return m_Projects[project]; } CPipelineProject *getProject(const std::string &project);
}; /* class CPipelineWorkspace */ }; /* class CPipelineWorkspace */

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<DFN Revision="$Revision$" State="modified">
<ELEMENT Name="Name" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Value" Type="Type" Filename="string.typ"/>
<LOG>Sat Mar 03 13:31:21 2012 (Kaetemi) Dfn Structure = </LOG>
</DFN>

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<DFN Revision="$Revision$" State="modified"> <DFN Revision="$Revision$" State="modified">
<ELEMENT Name="Description" Type="Type" Filename="string.typ"/> <ELEMENT Name="Description" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Macros" Type="Type" Filename="string.typ" Array="true"/> <ELEMENT Name="Macros" Type="Dfn" Filename="pipeline_macro.dfn" Array="true"/>
<ELEMENT Name="DependentProjects" Type="Type" Filename="filename.typ" Array="true"/> <ELEMENT Name="DependentProjects" Type="Type" Filename="filename.typ" Array="true"/>
<ELEMENT Name="Processes" Type="Type" Filename="string.typ" Array="true"/> <ELEMENT Name="Processes" Type="Type" Filename="string.typ" Array="true"/>
<ELEMENT Name="Interface" Type="Dfn" Filename="pipeline_process_interface.dfn"/> <ELEMENT Name="Interface" Type="Dfn" Filename="pipeline_process_interface.dfn"/>
@ -9,5 +9,6 @@
Sat Feb 18 13:36:45 2012 (Kaetemi) Dfn Structure = Sat Feb 18 13:36:45 2012 (Kaetemi) Dfn Structure =
Sat Feb 18 13:44:45 2012 (Kaetemi) Dfn Structure = Sat Feb 18 13:44:45 2012 (Kaetemi) Dfn Structure =
Sat Feb 18 15:28:54 2012 (Kaetemi) Dfn Structure = Sat Feb 18 15:28:54 2012 (Kaetemi) Dfn Structure =
Fri Mar 02 21:21:25 2012 (Kaetemi) Dfn Structure = </LOG> Fri Mar 02 21:21:25 2012 (Kaetemi) Dfn Structure =
Sat Mar 03 13:31:41 2012 (Kaetemi) Dfn Structure = </LOG>
</DFN> </DFN>

@ -2,6 +2,16 @@
<FORM Revision="$Revision$" State="modified"> <FORM Revision="$Revision$" State="modified">
<STRUCT> <STRUCT>
<ATOM Name="Description" Value="Common Interface"/> <ATOM Name="Description" Value="Common Interface"/>
<ARRAY Name="Macros">
<STRUCT>
<ATOM Name="Name" Value="DstInterfaceAtlas"/>
<ATOM Name="Value" Value="[!OutputDirectory]/interface_atlas/"/>
</STRUCT>
<STRUCT>
<ATOM Name="Name" Value="DstInterfaceAtlasDxtc"/>
<ATOM Name="Value" Value="[!OutputDirectory]/interface_atlas_dxtc/"/>
</STRUCT>
</ARRAY>
<ARRAY Name="Processes"> <ARRAY Name="Processes">
<ATOM Value="CProcessInterface"/> <ATOM Value="CProcessInterface"/>
</ARRAY> </ARRAY>
@ -12,19 +22,19 @@
<ATOM Value="[$DatabaseDirectory]/interfaces/v3"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3"/>
<ATOM Value="[$DatabaseDirectory]/interfaces/r2_interface"/> <ATOM Value="[$DatabaseDirectory]/interfaces/r2_interface"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputFile" Value="[$OutputDirectory]/interface_atlas/texture_interfaces_v3.tga"/> <ATOM Name="OutputFile" Value="[&amp;DstInterfaceAtlas]/texture_interfaces_v3.tga"/>
</STRUCT> </STRUCT>
<STRUCT> <STRUCT>
<ARRAY Name="InputDirectories"> <ARRAY Name="InputDirectories">
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_login"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_login"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputFile" Value="[$OutputDirectory]/interface_atlas/texture_interfaces_v3_login.tga"/> <ATOM Name="OutputFile" Value="[&amp;DstInterfaceAtlas]/texture_interfaces_v3_login.tga"/>
</STRUCT> </STRUCT>
<STRUCT> <STRUCT>
<ARRAY Name="InputDirectories"> <ARRAY Name="InputDirectories">
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_outgame/ui"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_outgame/ui"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputFile" Value="[$OutputDirectory]/interface_atlas/texture_interfaces_v3_outgame_ui.tga"/> <ATOM Name="OutputFile" Value="[&amp;DstInterfaceAtlas]/texture_interfaces_v3_outgame_ui.tga"/>
</STRUCT> </STRUCT>
</ARRAY> </ARRAY>
<ARRAY Name="AtlasDxtc"> <ARRAY Name="AtlasDxtc">
@ -34,7 +44,7 @@
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_items"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_items"/>
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_dxtc_misc"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_dxtc_misc"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputFile" Value="[$OutputDirectory]/interface_atlas_dxtc/texture_interfaces_dxtc.tga"/> <ATOM Name="OutputFile" Value="[&amp;DstInterfaceAtlasDxtc]/texture_interfaces_dxtc.tga"/>
</STRUCT> </STRUCT>
</ARRAY> </ARRAY>
<STRUCT Name="Fullscreen"> <STRUCT Name="Fullscreen">
@ -53,7 +63,7 @@
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_quick_help/graph"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_quick_help/graph"/>
<ATOM Value="[$DatabaseDirectory]/interfaces/r2_decals"/> <ATOM Value="[$DatabaseDirectory]/interfaces/r2_decals"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputDirectory" Value="[$OutputDirectory]/interface_fullscreen"/> <ATOM Name="OutputDirectory" Value="[!OutputDirectory]/interface_fullscreen"/>
</STRUCT> </STRUCT>
<STRUCT Name="3D"> <STRUCT Name="3D">
<ARRAY Name="InputDirectories"> <ARRAY Name="InputDirectories">
@ -63,7 +73,7 @@
<ATOM Value="[$DatabaseDirectory]/interfaces/v3_quick_help"/> <ATOM Value="[$DatabaseDirectory]/interfaces/v3_quick_help"/>
<ATOM Value="[$DatabaseDirectory]/interfaces/r2_3d"/> <ATOM Value="[$DatabaseDirectory]/interfaces/r2_3d"/>
</ARRAY> </ARRAY>
<ATOM Name="OutputDirectory" Value="[$OutputDirectory]/interface_3d"/> <ATOM Name="OutputDirectory" Value="[!OutputDirectory]/interface_3d"/>
</STRUCT> </STRUCT>
</STRUCT> </STRUCT>
</STRUCT> </STRUCT>
@ -71,5 +81,16 @@
<STRUCT/> <STRUCT/>
<STRUCT/> <STRUCT/>
<STRUCT/> <STRUCT/>
<LOG>Sat Mar 03 12:10:45 2012 (Kaetemi) .Description = Common Interface</LOG> <LOG>Sat Mar 03 12:10:45 2012 (Kaetemi) .Description = Common Interface
Sat Mar 03 13:33:24 2012 (Kaetemi) .Interface.Atlas[0].OutputFile = [&amp;DstInterfaceAtlas]/texture_interfaces_v3.tga
Sat Mar 03 13:33:24 2012 (Kaetemi) .Macros[0].Name = DstInterfaceAtlas
Sat Mar 03 13:33:24 2012 (Kaetemi) .Macros[0].Value = [!OutputDirectory]/interface_atlas/
Sat Mar 03 13:33:24 2012 (Kaetemi) formName Resized = 1
Sat Mar 03 13:33:28 2012 (Kaetemi) .Interface.Atlas[1].OutputFile = [&amp;DstInterfaceAtlas]/texture_interfaces_v3_login.tga
Sat Mar 03 13:34:02 2012 (Kaetemi) .Interface.Atlas[1].OutputFile = [&amp;DstInterfaceAtlas]/texture_interfaces_v3_login.tga
Sat Mar 03 13:34:02 2012 (Kaetemi) .Interface.Atlas[2].OutputFile = [&amp;DstInterfaceAtlas]/texture_interfaces_v3_outgame_ui.tga
Sat Mar 03 13:34:02 2012 (Kaetemi) .Macros[1].Name = DstInterfaceAtlasDxtc
Sat Mar 03 13:34:02 2012 (Kaetemi) .Macros[1].Value = [!OutputDirectory]/interface_atlas_dxtc/
Sat Mar 03 13:34:02 2012 (Kaetemi) formName Resized = 2
Sat Mar 03 13:34:32 2012 (Kaetemi) .Interface.AtlasDxtc[0].OutputFile = [&amp;DstInterfaceAtlasDxtc]/texture_interfaces_dxtc.tga</LOG>
</FORM> </FORM>

Loading…
Cancel
Save