BsSLPlugin.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "BsSLPrerequisites.h"
  2. #include "BsPath.h"
  3. #include "BsFileSystem.h"
  4. #include "BsDataStream.h"
  5. // DEBUG ONLY
  6. #include "BsDebug.h"
  7. #include "BsMatrix4.h"
  8. extern "C" {
  9. #include "BsMMAlloc.h"
  10. #include "BsASTFX.h"
  11. #include "BsParserFX.h"
  12. #include "BsLexerFX.h"
  13. }
  14. namespace BansheeEngine
  15. {
  16. void parseFX(ParseState* parseState, const char* source)
  17. {
  18. yyscan_t scanner;
  19. YY_BUFFER_STATE state;
  20. if (yylex_init_extra(parseState, &scanner)) {
  21. // couldn't initialize
  22. return;
  23. }
  24. state = yy_scan_string(source, scanner);
  25. if (yyparse(parseState, scanner)) {
  26. // error parsing
  27. return;
  28. }
  29. yy_delete_buffer(state, scanner);
  30. yylex_destroy(scanner);
  31. }
  32. /**
  33. * @brief Returns a name of the plugin.
  34. */
  35. extern "C" BS_SL_EXPORT const String& getPluginName()
  36. {
  37. return SystemName;
  38. }
  39. void debugPrint(ASTFXNode* node, String indent)
  40. {
  41. LOGWRN(indent + "NODE " + toString(node->type));
  42. for (int i = 0; i < node->options->count; i++)
  43. {
  44. OptionDataType odt = OPTION_LOOKUP[(int)node->options->entries[i].type].dataType;
  45. if (odt == ODT_Complex)
  46. {
  47. LOGWRN(indent + toString(i) + ". " + toString(node->options->entries[i].type));
  48. debugPrint(node->options->entries[i].value.nodePtr, indent + "\t");
  49. continue;
  50. }
  51. String value;
  52. switch (odt)
  53. {
  54. case ODT_Bool:
  55. value = toString(node->options->entries[i].value.intValue != 0);
  56. break;
  57. case ODT_Int:
  58. value = toString(node->options->entries[i].value.intValue);
  59. break;
  60. case ODT_Float:
  61. value = toString(node->options->entries[i].value.floatValue);
  62. break;
  63. case ODT_String:
  64. value = node->options->entries[i].value.strValue;
  65. break;
  66. case ODT_Matrix:
  67. {
  68. Matrix4 mat4 = *(Matrix4*)(node->options->entries[i].value.matrixValue);
  69. value = toString(mat4);
  70. }
  71. break;
  72. }
  73. LOGWRN(indent + toString(i) + ". " + toString(node->options->entries[i].type) + " = " + value);
  74. }
  75. }
  76. /**
  77. * @brief Entry point to the plugin. Called by the engine when the plugin is loaded.
  78. */
  79. extern "C" BS_SL_EXPORT void* loadPlugin()
  80. {
  81. // TODO - Register importer
  82. // DEBUG
  83. yydebug = 1;
  84. Path exampleFX = "D:\\testFX.txt";
  85. DataStreamPtr file = FileSystem::openFile(exampleFX);
  86. String contents = file->getAsString();
  87. ParseState* parseState = parseStateCreate();
  88. parseFX(parseState, contents.c_str());
  89. debugPrint(parseState->rootNode, "");
  90. int bp = 0;
  91. parseStateDelete(parseState);
  92. return nullptr;
  93. }
  94. }