/Main.h

https://github.com/Andos/Flocking · C Header · 166 lines · 97 code · 37 blank · 32 comment · 1 complexity · d8dddaf0e98e86a3b56fbe832c617cdc MD5 · raw file

  1. // Object identifier "Floc"
  2. #define IDENTIFIER MAKEID(F,l,o,c)
  3. #include <vector>
  4. #include <hash_map>
  5. #include <map>
  6. class ObjectSelection;
  7. // ------------------------------
  8. // LAST CODES
  9. // ------------------------------
  10. #define CND_LAST 1
  11. #define ACT_LAST 31
  12. #define EXP_LAST 25
  13. #define ANGLE_SETTING 0
  14. #define DIR_SETTING 1
  15. #define NODIR_SETTING 2
  16. struct BoidType
  17. {
  18. float idleSpeed, minSpeed, maxSpeed, acceleration, deceleration, turnSpeed;
  19. float viewRadius, avoidanceRadius;
  20. float movementRandomization;
  21. float separationWeight, alignmentWeight, cohesionWeight;
  22. char angleDirSetting;
  23. bool avoidObstacles;
  24. bool speedDependantTurn;
  25. };
  26. struct Boid
  27. {
  28. long fixedValue;
  29. int boidType;
  30. int cellX, cellY;
  31. float x, y;
  32. float oldX, oldY;
  33. float speed, oldSpeed;
  34. float dirAngle, dirX, dirY;
  35. float sepX, sepY, cohX, cohY, aliX, aliY;
  36. float forceX, forceY;
  37. float targetX, targetY, targetDistance;
  38. int sepNeighbourCount;
  39. int aliCohNeighbourCount;
  40. };
  41. struct BoidLoop
  42. {
  43. char name[32];
  44. };
  45. struct Vec2f
  46. {
  47. float x,y;
  48. };
  49. struct Vec2i
  50. {
  51. int x,y;
  52. };
  53. typedef std::pair<int,int> Cell;
  54. struct CellHash : public stdext::hash_compare<Cell>{
  55. size_t operator()(const Cell& p) const {
  56. return p.first*239 + p.second*137;
  57. }
  58. bool operator()(const Cell& a, const Cell& b) const {
  59. return a.first < b.first && a.second < b.second;
  60. }
  61. };
  62. //typedef std::multimap<Cell,Boid> CellMap; //Slow beyond imagination in debug mode
  63. typedef stdext::hash_multimap<Cell,Boid, CellHash> CellMap;
  64. typedef std::pair<Cell,Boid> CellBoidPair;
  65. // ---------------------
  66. // OBJECT DATA STRUCTURE
  67. // ---------------------
  68. // Used at edit time and saved in the MFA/CCN/EXE files
  69. typedef struct tagEDATA_V1
  70. {
  71. // Header - required
  72. extHeader eHeader;
  73. int cellsize;
  74. BoidType defaultParameters;
  75. // Object's data
  76. // short swidth;
  77. // short sheight;
  78. } EDITDATA;
  79. typedef EDITDATA * LPEDATA;
  80. // Object versions
  81. #define KCX_CURRENT_VERSION 1
  82. // --------------------------------
  83. // RUNNING OBJECT DATA STRUCTURE
  84. // --------------------------------
  85. typedef struct tagRDATA
  86. {
  87. // Main header - required
  88. headerObject rHo; // Header
  89. //Mapping from a cell into a number of Boids in that cell.
  90. CellMap* cells;
  91. int cellsize;
  92. BoidType boidtypes[100];
  93. bool hwa;
  94. bool unicode;
  95. int numLoops;
  96. BoidLoop boidLoops[10];
  97. int perfCounter;
  98. Boid loopedBoid;
  99. Boid centerBoid;
  100. } RUNDATA;
  101. typedef RUNDATA * LPRDATA;
  102. // Size when editing the object under level editor
  103. // -----------------------------------------------
  104. #define MAX_EDITSIZE sizeof(EDITDATA)
  105. // Default flags - see documentation for more info
  106. // -------------
  107. #define OEFLAGS 0
  108. #define OEPREFS 0
  109. // If to handle message, specify the priority of the handling procedure
  110. // 0= low, 255= very high. You should use 100 as normal.
  111. // --------------------------------------------------------------------
  112. #define WINDOWPROC_PRIORITY 100
  113. long FixedValue( LPRO object );
  114. LPRO LPROFromFixed( LPRDATA rdPtr, long fixedvalue );
  115. long returnFloat(LPRDATA rdPtr, float value);
  116. /*
  117. void Debug( char * string, int value );
  118. void Debug( char * string, float value );
  119. void Debug( char * string, float valueA, float valueB );
  120. void DebugObject(Boid boid);
  121. */
  122. float RotateTowards(float angle, float targetAngle, float speed);
  123. float ToRadians(float degrees);
  124. float ToDegrees(float radians);
  125. int packFloat(float value);
  126. void LoopNeighbourBoids(LPRDATA rdPtr, char* loopname, Boid boid, int radius);
  127. Vec2i TracePosition(headerObject* rHo, int layer, Vec2i a, Vec2i b);
  128. float clamp(float val, float min, float max);
  129. float Q_rsqrt( float number );