/** * Writes the template id tag definition. * * @param fp the file to write to */ void TemplateDefinitionFile::writeTemplateId(File &fp) const { fp.print("%s\n", TDF_ID_BEGIN); fp.print("\tenum\n"); fp.print("\t{\n"); fp.print("\t\t%s_tag = %s\n", getTemplateName().c_str(), getTemplateId().tagString.c_str()); fp.print("\t};\n"); fp.print("%s\n", TDF_ID_END); } // TemplateDefinitionFile::writeTemplateId
bool BaseClass::operator==(const BaseClass& c) const { if(this == &c) return true; return (getNamespaceName() == c.getNamespaceName()) && (getClassName() == c.getClassName()) && (getTemplateName() == c.getTemplateName()); }
bool BehaviorInstance::onAdd() { if(! Parent::onAdd()) return false; // Store this object's namespace mNameSpace = Namespace::global()->find( getTemplateName() ); return true; }
/** * Writes the ending of a class header file. * * @param fp the file to write to * @param sourceTemplate the template we are writing code for */ void TemplateDefinitionFile::writeClassHeaderEnd(File &fp, const TemplateData & sourceTemplate) const { UNREF(sourceTemplate); const char *name = getTemplateName().c_str(); fp.print("\n"); fp.print("private:\n"); fp.print("\tTag m_templateVersion;\t// the template version\n"); fp.print("\tbool m_versionOk;\t// flag that the template version loaded is " "the one we expect\n"); if (!m_writeForCompilerFlag) fp.print("\tstatic bool ms_allowDefaultTemplateParams;\t// flag to allow defaut params instead of fataling\n"); fp.print("\n"); fp.print("\tstatic void registerMe(void);\n"); fp.print("\tstatic ObjectTemplate * create(const std::string & filename);\n"); fp.print("\n"); fp.print("\t// no copying\n"); fp.print("\t%s(const %s &);\n", name, name); fp.print("\t%s & operator =(const %s &);\n", name, name); fp.print("};\n"); fp.print("\n"); fp.print("\n"); if (m_writeForCompilerFlag) { fp.print("inline void %s::install(void)\n", name); fp.print("{\n"); } else { fp.print("inline void %s::install(bool allowDefaultTemplateParams)\n", name); fp.print("{\n"); fp.print("\tms_allowDefaultTemplateParams = allowDefaultTemplateParams;\n"); } sourceTemplate.writeRegisterTemplate(fp, "\t"); fp.print("}\n"); fp.print("\n"); fp.print("\n"); fp.print("#endif\t// _INCLUDED_%s_H\n", name); } // TemplateDefinitionFile::writeClassHeaderEnd
ShaderDiscardCase* makeDiscardCase (Context& context, DiscardTemplate tmpl, DiscardMode mode) { StringTemplate shaderTemplate(getTemplate(tmpl)); map<string, string> params; switch (mode) { case DISCARDMODE_ALWAYS: params["DISCARD"] = "discard"; break; case DISCARDMODE_NEVER: params["DISCARD"] = "if (false) discard"; break; case DISCARDMODE_UNIFORM: params["DISCARD"] = "if (ui_one > 0) discard"; break; case DISCARDMODE_DYNAMIC: params["DISCARD"] = "if (v_coords.x+v_coords.y > 0.0) discard"; break; case DISCARDMODE_TEXTURE: params["DISCARD"] = "if (texture(ut_brick, v_coords.xy*0.25+0.5).x < 0.7) discard"; break; default: DE_ASSERT(DE_FALSE); break; } string name = string(getTemplateName(tmpl)) + "_" + getModeName(mode); string description = string(getModeDesc(mode)) + " in " + getTemplateDesc(tmpl); return new ShaderDiscardCase(context, name.c_str(), description.c_str(), shaderTemplate.specialize(params).c_str(), getEvalFunc(mode), mode == DISCARDMODE_TEXTURE); }
/** * Writes the beginning of a class source file. * * @param fp the file to write to * @param sourceTemplate the template we are writing code for */ void TemplateDefinitionFile::writeClassSourceBegin(File &fp, const TemplateData & sourceTemplate) const { const char *name = getTemplateName().c_str(); fp.print("//========================================================================\n"); fp.print("//\n"); fp.print("// %s.cpp\n", name); fp.print("//\n"); fp.print("//IMPORTANT: Any code between //@BEGIN TFD... and //@END TFD... will be\n"); fp.print("//overwritten the next time the template definition is compiled. Do not\n"); fp.print("//make changes to code inside these blocks.\n"); fp.print("//\n"); if (getFileComments().size() > 0) { writeFileComments(fp); fp.print("//\n"); } fp.print("// copyright 2001 Sony Online Entertainment\n"); fp.print("//\n"); fp.print("//========================================================================\n"); fp.print("\n"); if (m_writeForCompilerFlag) { fp.print("#include \"sharedTemplate/FirstSharedTemplate.h\"\n"); fp.print("#include \"sharedTemplateDefinition/TemplateData.h\"\n"); fp.print("#include \"sharedTemplateDefinition/TemplateGlobals.h\"\n", name); } else if (m_templateLocation == LOC_CLIENT) fp.print("#include \"%s\"\n", CLIENT_TEMPLATE_PRECOMPILED_HEADER_NAME); else if (m_templateLocation == LOC_SERVER) fp.print("#include \"%s\"\n", SERVER_TEMPLATE_PRECOMPILED_HEADER_NAME); else fp.print("#include \"%s\"\n", SHARED_TEMPLATE_PRECOMPILED_HEADER_NAME); fp.print("#include \"%s.h\"\n", name); fp.print("#include \"sharedDebug/DataLint.h\"\n"); fp.print("#include \"sharedFile/Iff.h\"\n"); if (m_writeForCompilerFlag) fp.print("#include \"sharedTemplateDefinition/ObjectTemplate.h\"\n"); else { fp.print("#include \"sharedObject/ObjectTemplate.h\"\n"); fp.print("#include \"sharedObject/ObjectTemplateList.h\"\n"); sourceTemplate.writeSourceTemplateIncludes(fp); } fp.print("#include <stdio.h>\n"); fp.print("\n"); if (!m_writeForCompilerFlag) { fp.print("const std::string DefaultString(\"\");\n"); fp.print("const StringId DefaultStringId(\"\", 0);\n"); fp.print("const Vector DefaultVector(0,0,0);\n"); fp.print("const TriggerVolumeData DefaultTriggerVolumeData;\n"); fp.print("\n"); fp.print("bool %s::ms_allowDefaultTemplateParams = true;\n", name); } fp.print("\n"); fp.print("\n"); fp.print("/**\n"); fp.print(" * Class constructor.\n"); fp.print(" */\n"); fp.print("%s::%s(const std::string & filename)\n", name, name); // if (sourceTemplate.hasList()) sourceTemplate.writeSourceLoadedFlagInit(fp); fp.print("{\n"); // fp.print("\tsetId(%s);\n", getTemplateId().tagString.c_str()); fp.print("} // %s::%s\n", name, name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Class destructor.\n"); fp.print(" */\n"); fp.print("%s::~%s()\n", name, name); fp.print("{\n"); sourceTemplate.writeSourceCleanup(fp); fp.print("} // %s::~%s\n", name, name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Static function used to register this template.\n"); fp.print(" */\n"); fp.print("void %s::registerMe(void)\n", name); fp.print("{\n"); fp.print("\tObjectTemplateList::registerTemplate(%s_tag, create);\n", name); fp.print("} // %s::registerMe\n", name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Creates a %s template.\n", name); fp.print(" *\n"); fp.print(" * @return a new instance of the template\n"); fp.print(" */\n"); fp.print("ObjectTemplate * %s::create(const std::string & filename)\n", name); fp.print("{\n"); fp.print("\treturn new %s(filename);\n", name); fp.print("} // %s::create\n", name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Returns the template id.\n"); fp.print(" *\n"); fp.print(" * @return the template id\n"); fp.print(" */\n"); fp.print("Tag %s::getId(void) const\n", name); fp.print("{\n"); fp.print("\treturn %s_tag;\n", name); fp.print("} // %s::getId\n", name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Returns this template's version.\n"); fp.print(" *\n"); fp.print(" * @return the version\n"); fp.print(" */\n"); fp.print("Tag %s::getTemplateVersion(void) const\n", name); fp.print("{\n"); fp.print("\treturn m_templateVersion;\n"); fp.print("} // %s::getTemplateVersion\n", name); fp.print("\n"); fp.print("/**\n"); fp.print(" * Returns the highest version of this template or it's base templates.\n"); fp.print(" *\n"); fp.print(" * @return the highest version\n"); fp.print(" */\n"); fp.print("Tag %s::getHighestTemplateVersion(void) const\n", name); fp.print("{\n"); fp.print("\tif (m_baseData == NULL)\n"); fp.print("\t\treturn m_templateVersion;\n"); fp.print("\tconst %s * base = dynamic_cast<const %s *>(m_baseData);\n", name, name); fp.print("\tif (base == NULL)\n"); fp.print("\t\treturn m_templateVersion;\n"); fp.print("\treturn std::max(m_templateVersion, base->getHighestTemplateVersion());\n"); fp.print("} // %s::getHighestTemplateVersion\n", name); fp.print("\n"); } // TemplateDefinitionFile::writeClassSourceBegin
/** * Writes the beginning of a class header file. * * @param fp the file to write to */ void TemplateDefinitionFile::writeClassHeaderBegin(File &fp) const { const char * name = getTemplateName().c_str(); std::string bn = getBaseName(); const char * baseName = bn.c_str(); const char * baseNamePath = ""; if (baseName[0] == '\0' && m_templateLocation != LOC_NONE) { baseNamePath = "sharedObject/"; baseName = ROOT_TEMPLATE_NAME; } else if(_stricmp(baseName, "tpfTemplate") == 0) { baseNamePath = "sharedTemplateDefinition/"; } fp.print("//========================================================================\n"); fp.print("//\n"); fp.print("// %s.h\n", name); fp.print("//\n"); fp.print("//IMPORTANT: Any code between //@BEGIN TFD... and //@END TFD... will be\n"); fp.print("//overwritten the next time the template definition is compiled. Do not\n"); fp.print("//make changes to code inside these blocks.\n"); fp.print("//\n"); if (getFileComments().size() > 0) { writeFileComments(fp); fp.print("//\n"); } fp.print("// copyright 2001 Sony Online Entertainment\n"); fp.print("//\n"); fp.print("//========================================================================\n"); fp.print("\n"); fp.print("#ifndef _INCLUDED_%s_H\n", name); fp.print("#define _INCLUDED_%s_H\n", name); fp.print("\n"); fp.print("#include \"%s%s.h\"\n", baseNamePath, baseName); fp.print("#include \"sharedFoundation/DynamicVariable.h\"\n"); if (m_writeForCompilerFlag) fp.print("#include \"sharedTemplateDefinition/TpfTemplate.h\"\n"); else fp.print("#include \"sharedUtility/TemplateParameter.h\"\n"); fp.print("\n"); fp.print("\n"); fp.print("class Vector;\n"); fp.print("typedef StructParam<ObjectTemplate> StructParamOT;\n"); if (!m_writeForCompilerFlag) { std::map<int, TemplateData *>::const_iterator iter; iter = m_templateMap.find(m_highestVersion); if (iter != m_templateMap.end()) (*iter).second->writeHeaderFwdDecls(fp); } fp.print("\n"); fp.print("\n"); fp.print("class %s : public %s\n", name, baseName); fp.print("{\n"); fp.print("public:\n"); writeTemplateId(fp); fp.print("public:\n"); fp.print("\t %s(const std::string & filename);\n", name); fp.print("\tvirtual ~%s();\n", name); fp.print("\n"); fp.print("\tvirtual Tag getId(void) const;\n"); fp.print("\tvirtual Tag getTemplateVersion(void) const;\n"); fp.print("\tvirtual Tag getHighestTemplateVersion(void) const;\n"); if (m_writeForCompilerFlag) fp.print("\tstatic void install(void);\n"); else fp.print("\tstatic void install(bool allowDefaultTemplateParams = true);\n"); fp.print("\n"); } // writeClassHeaderBegin