1 /* 2 Copyright (c) 2005-2020 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef UNIVERSE_H_ 18 #define UNIVERSE_H_ 19 20 #ifndef UNIVERSE_WIDTH 21 #define UNIVERSE_WIDTH 1024 22 #endif 23 #ifndef UNIVERSE_HEIGHT 24 #define UNIVERSE_HEIGHT 512 25 #endif 26 27 #include "../../common/gui/video.h" 28 #include "tbb/partitioner.h" 29 30 class Universe { 31 public: 32 enum { 33 UniverseWidth = UNIVERSE_WIDTH, 34 UniverseHeight = UNIVERSE_HEIGHT 35 }; 36 private: 37 //in order to avoid performance degradation due to cache aliasing issue 38 //some padding is needed after each row in array, and between array themselves. 39 //the padding is achieved by adjusting number of rows and columns. 40 //as the compiler is forced to place class members of the same clause in order of the 41 //declaration this seems to be the right way of padding. 42 43 //magic constants added below are chosen experimentally for 1024x512. 44 enum { 45 MaxWidth = UniverseWidth+1, 46 MaxHeight = UniverseHeight+3 47 }; 48 49 typedef float ValueType; 50 51 //! Horizontal stress 52 ValueType S[MaxHeight][MaxWidth]; 53 54 //! Velocity at each grid point 55 ValueType V[MaxHeight][MaxWidth]; 56 57 //! Vertical stress 58 ValueType T[MaxHeight][MaxWidth]; 59 60 //! Coefficient related to modulus 61 ValueType M[MaxHeight][MaxWidth]; 62 63 //! Damping coefficients 64 ValueType D[MaxHeight][MaxWidth]; 65 66 //! Coefficient related to lightness 67 ValueType L[MaxHeight][MaxWidth]; 68 69 enum { ColorMapSize = 1024}; 70 color_t ColorMap[4][ColorMapSize]; 71 72 enum MaterialType { 73 WATER=0, 74 SANDSTONE=1, 75 SHALE=2 76 }; 77 78 //! Values are MaterialType, cast to an unsigned char to save space. 79 unsigned char material[MaxHeight][MaxWidth]; 80 81 private: 82 enum { DamperSize = 32}; 83 84 int pulseTime; 85 int pulseCounter; 86 int pulseX; 87 int pulseY; 88 89 drawing_memory drawingMemory; 90 91 public: 92 void InitializeUniverse(video const& colorizer); 93 94 void SerialUpdateUniverse(); 95 void ParallelUpdateUniverse(); 96 bool TryPutNewPulseSource(int x, int y); 97 void SetDrawingMemory(const drawing_memory &dmem); 98 private: 99 struct Rectangle; 100 void UpdatePulse(); 101 void UpdateStress(Rectangle const& r ); 102 103 void SerialUpdateStress() ; 104 friend struct UpdateStressBody; 105 friend struct UpdateVelocityBody; 106 void ParallelUpdateStress(tbb::affinity_partitioner &affinity); 107 108 void UpdateVelocity(Rectangle const& r); 109 110 void SerialUpdateVelocity() ; 111 void ParallelUpdateVelocity(tbb::affinity_partitioner &affinity); 112 }; 113 114 #endif /* UNIVERSE_H_ */ 115