llmaterialtable.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * @file llmaterialtable.cpp
  3. * @brief Table of material names and IDs for viewer
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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 "llmaterialtable.h"
  34. #include "llstl.h"
  35. #include "imageids.h"
  36. #include "sound_ids.h"
  37. constexpr F32 DEFAULT_FRICTION = 0.5f;
  38. constexpr F32 DEFAULT_RESTITUTION = 0.4f;
  39. LLMaterialTable gMaterialTable;
  40. LLMaterialTable::LLMaterialTable()
  41. {
  42. // Concrete
  43. mMaterialInfoList.emplace_back(LL_MCODE_STONE, "Stone", 0.8f, 0.4f);
  44. // Steel
  45. mMaterialInfoList.emplace_back(LL_MCODE_METAL, "Metal", 0.3f, 0.4f);
  46. // Borosilicate glass
  47. mMaterialInfoList.emplace_back(LL_MCODE_GLASS, "Glass", 0.2f, 0.7f);
  48. // Southern pine
  49. mMaterialInfoList.emplace_back(LL_MCODE_WOOD, "Wood", 0.6f, 0.5f);
  50. // Saltwater
  51. mMaterialInfoList.emplace_back(LL_MCODE_FLESH, "Flesh", 0.9f, 0.3f);
  52. // HDPE
  53. mMaterialInfoList.emplace_back(LL_MCODE_PLASTIC, "Plastic", 0.4f, 0.7f);
  54. mMaterialInfoList.emplace_back(LL_MCODE_RUBBER, "Rubber", 0.9f, 0.9f);
  55. mMaterialInfoList.emplace_back(LL_MCODE_LIGHT, "Light", 0.2f, 0.7f);
  56. // Collision sounds
  57. mCollisionsSounds.reserve(28);
  58. mCollisionsSounds.emplace(SND_FLESH_FLESH);
  59. mCollisionsSounds.emplace(SND_FLESH_PLASTIC);
  60. mCollisionsSounds.emplace(SND_FLESH_RUBBER);
  61. mCollisionsSounds.emplace(SND_GLASS_FLESH);
  62. mCollisionsSounds.emplace(SND_GLASS_GLASS);
  63. mCollisionsSounds.emplace(SND_GLASS_PLASTIC);
  64. mCollisionsSounds.emplace(SND_GLASS_RUBBER);
  65. mCollisionsSounds.emplace(SND_GLASS_WOOD);
  66. mCollisionsSounds.emplace(SND_METAL_FLESH);
  67. mCollisionsSounds.emplace(SND_METAL_GLASS);
  68. mCollisionsSounds.emplace(SND_METAL_METAL);
  69. mCollisionsSounds.emplace(SND_METAL_PLASTIC);
  70. mCollisionsSounds.emplace(SND_METAL_RUBBER);
  71. mCollisionsSounds.emplace(SND_METAL_WOOD);
  72. mCollisionsSounds.emplace(SND_PLASTIC_PLASTIC);
  73. mCollisionsSounds.emplace(SND_RUBBER_PLASTIC);
  74. mCollisionsSounds.emplace(SND_RUBBER_RUBBER);
  75. mCollisionsSounds.emplace(SND_STONE_FLESH);
  76. mCollisionsSounds.emplace(SND_STONE_GLASS);
  77. mCollisionsSounds.emplace(SND_STONE_METAL);
  78. mCollisionsSounds.emplace(SND_STONE_PLASTIC);
  79. mCollisionsSounds.emplace(SND_STONE_RUBBER);
  80. mCollisionsSounds.emplace(SND_STONE_STONE);
  81. mCollisionsSounds.emplace(SND_STONE_WOOD);
  82. mCollisionsSounds.emplace(SND_WOOD_FLESH);
  83. mCollisionsSounds.emplace(SND_WOOD_PLASTIC);
  84. mCollisionsSounds.emplace(SND_WOOD_RUBBER);
  85. mCollisionsSounds.emplace(SND_WOOD_WOOD);
  86. mCollisionsSounds.emplace(SND_OPENSIM_COLLISION);
  87. // Ground collision sounds, with SL sim servers recently seen spamming them
  88. // to the viewer, so let's add them here to allow muting it with the rest
  89. // of the collision sounds. HB
  90. mCollisionsSounds.emplace(SND_STONE_DIRT_01);
  91. mCollisionsSounds.emplace(SND_STONE_DIRT_02);
  92. mCollisionsSounds.emplace(SND_STONE_DIRT_03);
  93. mCollisionsSounds.emplace(SND_STONE_DIRT_04);
  94. mCollisionsSounds.emplace(SND_STONE_STONE_02);
  95. mCollisionsSounds.emplace(SND_STONE_STONE_04);
  96. }
  97. void LLMaterialTable::initTableTransNames(name_map_t namemap)
  98. {
  99. for (info_list_t::iterator iter = mMaterialInfoList.begin();
  100. iter != mMaterialInfoList.end(); ++iter)
  101. {
  102. LLMaterialInfo& info = *iter;
  103. info.mName = namemap[info.mName];
  104. }
  105. }
  106. U8 LLMaterialTable::getMCode(const std::string& name) const
  107. {
  108. for (info_list_t::const_iterator iter = mMaterialInfoList.begin(),
  109. end = mMaterialInfoList.end();
  110. iter != end; ++iter)
  111. {
  112. const LLMaterialInfo& info = *iter;
  113. if (name == info.mName)
  114. {
  115. return info.mMCode;
  116. }
  117. }
  118. return 0;
  119. }
  120. const std::string& LLMaterialTable::getName(U8 mcode) const
  121. {
  122. mcode &= LL_MCODE_MASK;
  123. for (info_list_t::const_iterator iter = mMaterialInfoList.begin(),
  124. end = mMaterialInfoList.end();
  125. iter != end; ++iter)
  126. {
  127. const LLMaterialInfo& info = *iter;
  128. if (mcode == info.mMCode)
  129. {
  130. return info.mName;
  131. }
  132. }
  133. return LLStringUtil::null;
  134. }
  135. F32 LLMaterialTable::getRestitution(U8 mcode) const
  136. {
  137. for (info_list_t::const_iterator iter = mMaterialInfoList.begin(),
  138. end = mMaterialInfoList.end();
  139. iter != end; ++iter)
  140. {
  141. const LLMaterialInfo& info = *iter;
  142. if (mcode == info.mMCode)
  143. {
  144. return info.mRestitution;
  145. }
  146. }
  147. return DEFAULT_RESTITUTION;
  148. }
  149. F32 LLMaterialTable::getFriction(U8 mcode) const
  150. {
  151. for (info_list_t::const_iterator iter = mMaterialInfoList.begin(),
  152. end = mMaterialInfoList.end();
  153. iter != end; ++iter)
  154. {
  155. const LLMaterialInfo& info = *iter;
  156. if (mcode == info.mMCode)
  157. {
  158. return info.mFriction;
  159. }
  160. }
  161. return DEFAULT_FRICTION;
  162. }