llassettype.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:7k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llassettype.cpp
  3.  * @brief Implementatino of LLAssetType functionality.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "linden_common.h"
  33. #include "llassettype.h"
  34. #include "lldictionary.h"
  35. #include "llmemory.h"
  36. #include "llsingleton.h"
  37. ///----------------------------------------------------------------------------
  38. /// Class LLAssetType
  39. ///----------------------------------------------------------------------------
  40. struct AssetEntry : public LLDictionaryEntry
  41. {
  42. AssetEntry(const char *desc_name,
  43.    const char *type_name,  // 8 character limit!
  44.    const char *human_name,  // for decoding to human readable form; put any and as many printable characters you want in each one
  45.    bool can_link)  // can you create a link to this type?
  46. :
  47. LLDictionaryEntry(desc_name),
  48. mTypeName(type_name),
  49. mHumanName(human_name),
  50. mCanLink(can_link)
  51. {
  52. llassert(strlen(mTypeName) <= 8);
  53. }
  54. const char *mTypeName;
  55. const char *mHumanName;
  56. bool mCanLink;
  57. };
  58. class LLAssetDictionary : public LLSingleton<LLAssetDictionary>,
  59.   public LLDictionary<LLAssetType::EType, AssetEntry>
  60. {
  61. public:
  62. LLAssetDictionary();
  63. };
  64. LLAssetDictionary::LLAssetDictionary()
  65. {
  66. //           DESCRIPTION TYPE NAME HUMAN NAME CAN LINK?
  67. //         |--------------------|-----------|-------------------|-----------|
  68. addEntry(LLAssetType::AT_TEXTURE,  new AssetEntry("TEXTURE", "texture", "texture", FALSE));
  69. addEntry(LLAssetType::AT_SOUND,  new AssetEntry("SOUND", "sound", "sound", FALSE));
  70. addEntry(LLAssetType::AT_CALLINGCARD,  new AssetEntry("CALLINGCARD", "callcard", "calling card", FALSE));
  71. addEntry(LLAssetType::AT_LANDMARK,  new AssetEntry("LANDMARK", "landmark", "landmark", FALSE));
  72. addEntry(LLAssetType::AT_SCRIPT,  new AssetEntry("SCRIPT", "script", "legacy script", FALSE));
  73. addEntry(LLAssetType::AT_CLOTHING,  new AssetEntry("CLOTHING", "clothing", "clothing", TRUE));
  74. addEntry(LLAssetType::AT_OBJECT,  new AssetEntry("OBJECT", "object", "object", TRUE));
  75. addEntry(LLAssetType::AT_NOTECARD,  new AssetEntry("NOTECARD", "notecard", "note card", FALSE));
  76. addEntry(LLAssetType::AT_CATEGORY,  new AssetEntry("CATEGORY", "category", "folder", TRUE));
  77. addEntry(LLAssetType::AT_LSL_TEXT,  new AssetEntry("LSL_TEXT", "lsltext", "lsl2 script", FALSE));
  78. addEntry(LLAssetType::AT_LSL_BYTECODE,  new AssetEntry("LSL_BYTECODE", "lslbyte", "lsl bytecode", FALSE));
  79. addEntry(LLAssetType::AT_TEXTURE_TGA,  new AssetEntry("TEXTURE_TGA", "txtr_tga", "tga texture", FALSE));
  80. addEntry(LLAssetType::AT_BODYPART,  new AssetEntry("BODYPART", "bodypart", "body part", TRUE));
  81. addEntry(LLAssetType::AT_SOUND_WAV,  new AssetEntry("SOUND_WAV", "snd_wav", "sound", FALSE));
  82. addEntry(LLAssetType::AT_IMAGE_TGA,  new AssetEntry("IMAGE_TGA", "img_tga", "targa image", FALSE));
  83. addEntry(LLAssetType::AT_IMAGE_JPEG,  new AssetEntry("IMAGE_JPEG", "jpeg", "jpeg image", FALSE));
  84. addEntry(LLAssetType::AT_ANIMATION,  new AssetEntry("ANIMATION", "animatn", "animation", FALSE));
  85. addEntry(LLAssetType::AT_GESTURE,  new AssetEntry("GESTURE", "gesture", "gesture", TRUE));
  86. addEntry(LLAssetType::AT_SIMSTATE,  new AssetEntry("SIMSTATE", "simstate", "simstate", FALSE));
  87. addEntry(LLAssetType::AT_LINK,  new AssetEntry("LINK", "link", "symbolic link", FALSE));
  88. addEntry(LLAssetType::AT_LINK_FOLDER,  new AssetEntry("FOLDER_LINK", "link_f",  "symbolic folder link", FALSE));
  89. addEntry(LLAssetType::AT_NONE,  new AssetEntry("NONE", "-1", NULL,    FALSE));
  90. };
  91. // static
  92. LLAssetType::EType LLAssetType::getType(const std::string& desc_name)
  93. {
  94. std::string s = desc_name;
  95. LLStringUtil::toUpper(s);
  96. return LLAssetDictionary::getInstance()->lookup(s);
  97. }
  98. // static
  99. const std::string &LLAssetType::getDesc(LLAssetType::EType asset_type)
  100. {
  101. const AssetEntry *entry = LLAssetDictionary::getInstance()->lookup(asset_type);
  102. if (entry)
  103. {
  104. return entry->mName;
  105. }
  106. else
  107. {
  108. return badLookup();
  109. }
  110. }
  111. // static
  112. const char *LLAssetType::lookup(LLAssetType::EType asset_type)
  113. {
  114. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  115. const AssetEntry *entry = dict->lookup(asset_type);
  116. if (entry)
  117. {
  118. return entry->mTypeName;
  119. }
  120. else
  121. {
  122. return badLookup().c_str();
  123. }
  124. }
  125. // static
  126. LLAssetType::EType LLAssetType::lookup(const char* name)
  127. {
  128. return lookup(ll_safe_string(name));
  129. }
  130. // static
  131. LLAssetType::EType LLAssetType::lookup(const std::string& type_name)
  132. {
  133. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  134. for (LLAssetDictionary::const_iterator iter = dict->begin();
  135.  iter != dict->end();
  136.  iter++)
  137. {
  138. const AssetEntry *entry = iter->second;
  139. if (type_name == entry->mTypeName)
  140. {
  141. return iter->first;
  142. }
  143. }
  144. return AT_NONE;
  145. }
  146. // static
  147. const char *LLAssetType::lookupHumanReadable(LLAssetType::EType asset_type)
  148. {
  149. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  150. const AssetEntry *entry = dict->lookup(asset_type);
  151. if (entry)
  152. {
  153. return entry->mHumanName;
  154. }
  155. else
  156. {
  157. return badLookup().c_str();
  158. }
  159. }
  160. // static
  161. LLAssetType::EType LLAssetType::lookupHumanReadable(const char* name)
  162. {
  163. return lookupHumanReadable(ll_safe_string(name));
  164. }
  165. // static
  166. LLAssetType::EType LLAssetType::lookupHumanReadable(const std::string& readable_name)
  167. {
  168. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  169. for (LLAssetDictionary::const_iterator iter = dict->begin();
  170.  iter != dict->end();
  171.  iter++)
  172. {
  173. const AssetEntry *entry = iter->second;
  174. if (entry->mHumanName && (readable_name == entry->mHumanName))
  175. {
  176. return iter->first;
  177. }
  178. }
  179. return AT_NONE;
  180. }
  181. // static
  182. bool LLAssetType::lookupCanLink(EType asset_type)
  183. {
  184. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  185. const AssetEntry *entry = dict->lookup(asset_type);
  186. if (entry)
  187. {
  188. return entry->mCanLink;
  189. }
  190. return false;
  191. }
  192. // static
  193. // Not adding this to dictionary since we probably will only have these two types
  194. bool LLAssetType::lookupIsLinkType(EType asset_type)
  195. {
  196. if (asset_type == AT_LINK || asset_type == AT_LINK_FOLDER)
  197. {
  198. return true;
  199. }
  200. return false;
  201. }
  202. // static
  203. const std::string &LLAssetType::badLookup()
  204. {
  205. static const std::string sBadLookup = "llassettype_bad_lookup";
  206. return sBadLookup;
  207. }