afxEA_ConsoleMessage.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include <typeinfo>
  25. #include "afx/arcaneFX.h"
  26. #include "afx/afxEffectDefs.h"
  27. #include "afx/afxEffectWrapper.h"
  28. #include "afx/afxChoreographer.h"
  29. #include "afx/ce/afxConsoleMessage.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxEA_ConsoleMessage
  32. class afxEA_ConsoleMessage : public afxEffectWrapper
  33. {
  34. typedef afxEffectWrapper Parent;
  35. afxConsoleMessageData* message_data;
  36. bool displayed;
  37. void do_runtime_substitutions();
  38. public:
  39. /*C*/ afxEA_ConsoleMessage();
  40. virtual bool isDone() { return displayed; }
  41. virtual void ea_set_datablock(SimDataBlock*);
  42. virtual bool ea_start();
  43. virtual bool ea_update(F32 dt);
  44. };
  45. //~~~~~~~~~~~~~~~~~~~~//
  46. afxEA_ConsoleMessage::afxEA_ConsoleMessage()
  47. {
  48. message_data = 0;
  49. displayed = false;
  50. }
  51. void afxEA_ConsoleMessage::ea_set_datablock(SimDataBlock* db)
  52. {
  53. message_data = dynamic_cast<afxConsoleMessageData*>(db);
  54. }
  55. bool afxEA_ConsoleMessage::ea_start()
  56. {
  57. if (!message_data)
  58. {
  59. Con::errorf("afxEA_ConsoleMessage::ea_start() -- missing or incompatible datablock.");
  60. return false;
  61. }
  62. do_runtime_substitutions();
  63. return true;
  64. }
  65. bool afxEA_ConsoleMessage::ea_update(F32 dt)
  66. {
  67. if (!displayed)
  68. {
  69. if (message_data->message_str != ST_NULLSTRING)
  70. Con::printf("ConsoleMessage: \"%s\"", message_data->message_str);
  71. displayed = true;
  72. }
  73. return true;
  74. }
  75. void afxEA_ConsoleMessage::do_runtime_substitutions()
  76. {
  77. // only clone the datablock if there are substitutions
  78. if (message_data->getSubstitutionCount() > 0)
  79. {
  80. // clone the datablock and perform substitutions
  81. afxConsoleMessageData* orig_db = message_data;
  82. message_data = new afxConsoleMessageData(*orig_db, true);
  83. orig_db->performSubstitutions(message_data, mChoreographer, mGroup_index);
  84. }
  85. }
  86. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  87. class afxEA_ConsoleMessageDesc : public afxEffectAdapterDesc, public afxEffectDefs
  88. {
  89. static afxEA_ConsoleMessageDesc desc;
  90. public:
  91. virtual bool testEffectType(const SimDataBlock*) const;
  92. virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const { return false; }
  93. virtual bool runsOnServer(const afxEffectWrapperData*) const { return true; }
  94. virtual bool runsOnClient(const afxEffectWrapperData*) const { return true; }
  95. virtual bool isPositional(const afxEffectWrapperData*) const { return false; }
  96. virtual afxEffectWrapper* create() const { return new afxEA_ConsoleMessage; }
  97. };
  98. afxEA_ConsoleMessageDesc afxEA_ConsoleMessageDesc::desc;
  99. bool afxEA_ConsoleMessageDesc::testEffectType(const SimDataBlock* db) const
  100. {
  101. return (typeid(afxConsoleMessageData) == typeid(*db));
  102. }
  103. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//