1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 /* 14 * WeatherRenderer: 15 * Encapsulates rendering of weather stuff (rain and clouds) 16 * 17 */ 18 19 #ifndef BZF_WEATHER_RENDERER_H 20 #define BZF_WEATHER_RENDERER_H 21 22 #include "common.h" 23 24 /* system headers */ 25 #include <string> 26 #include <vector> 27 #include <map> 28 29 /* common interface headers */ 30 #include "bzfgl.h" 31 #include "OpenGLGState.h" 32 #include "SceneRenderer.h" 33 34 class WeatherRenderer 35 { 36 public: 37 WeatherRenderer(); 38 ~WeatherRenderer(); 39 40 // called once to setup the rain state, load lists and materials and stuff 41 void init(void); 42 43 // called each time the rain state needs to change, i.e. when the bzdb stuff changes 44 void set(void); 45 46 // called to update the rain simulation state. 47 void update(void); 48 49 // called to draw the rain for the current frame 50 void draw(const SceneRenderer& sr); 51 52 // called when the GL lists need to be deleted 53 void freeContext(void); 54 55 // called when the GL lists need to be remade 56 void rebuildContext(void); 57 58 protected: 59 OpenGLGState rainGState; 60 OpenGLGState texturedRainState; 61 OpenGLGState puddleState; 62 std::string rainSkin; 63 std::vector<std::string> rainTextures; 64 float rainColor[2][4]; 65 float rainSize[2]; 66 int rainDensity; 67 float rainSpeed; 68 float rainSpeedMod; 69 float rainSpread; 70 bool doPuddles; 71 bool doLineRain; 72 bool doBillBoards; 73 bool spinRain; 74 bool cullRoofTops; 75 bool roofPuddles; 76 float rainStartZ; 77 float rainEndZ; 78 float maxPuddleTime; 79 float puddleSpeed; 80 float puddleColor[4]; 81 GLuint dropList; 82 GLuint puddleList; 83 84 public: 85 typedef struct 86 { 87 float pos[3]; 88 float speed; 89 float roofTop; 90 int texture; 91 } rain; 92 93 protected: 94 std::vector<rain> raindrops; 95 96 typedef struct 97 { 98 float pos[3]; 99 float time; 100 int texture; 101 } puddle; 102 std::vector<puddle> puddles; 103 104 float lastRainTime; 105 106 void buildDropList(bool draw = false); 107 void buildPuddleList(bool draw = false); 108 109 bool updateDrop(std::vector<rain>::iterator &drop, float frameTime, std::vector<rain> &toAdd); 110 bool updatePuddle(std::vector<puddle>::iterator &splash, float frameTime); 111 112 void drawDrop(rain &drop, const SceneRenderer& sr); 113 void drawPuddle(puddle &splash); 114 115 // some kinda culling 116 void addDrop(rain &drop); 117 118 int keyFromPos(float x, float y) const; 119 120 float gridSize; 121 float keyFactor; 122 123 public: 124 typedef struct 125 { 126 float mins[3]; 127 float maxs[3]; 128 } copyExtents; 129 130 protected: 131 typedef struct 132 { 133 std::vector<rain> drops; 134 copyExtents bbox; 135 } visibleChunk; 136 137 std::map<int, visibleChunk> chunkMap; 138 139 void setChunkFromDrop(visibleChunk &chunk, rain &drop); 140 141 bool dbItemSet(const char* name); 142 143 int rainCount; 144 int cellCount; 145 }; 146 147 #endif // BZF_WEATHER_RENDERER_H 148 149 // Local Variables: *** 150 // mode: C++ *** 151 // tab-width: 4 *** 152 // c-basic-offset: 4 *** 153 // indent-tabs-mode: nil *** 154 // End: *** 155 // ex: shiftwidth=4 tabstop=4 156