light_drawer.h

main 67 lines · 1.9 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#ifndef RME_LIGHDRAWER_H
19#define RME_LIGHDRAWER_H
20
21#include "graphics.h"
22#include "position.h"
23
24class LightDrawer {
25 struct Light {
26 uint16_t map_x = 0;
27 uint16_t map_y = 0;
28 uint8_t color = 0;
29 uint8_t intensity = 0;
30 };
31
32public:
33 LightDrawer();
34 virtual ~LightDrawer();
35
36 void draw(int map_x, int map_y, int end_x, int end_y, int scroll_x, int scroll_y, bool fog);
37
38 void setGlobalLightColor(uint8_t color);
39 void addLight(int map_x, int map_y, int map_z, const SpriteLight& light);
40 void clear() noexcept;
41
42private:
43 void createGLTexture();
44 void unloadGLTexture();
45
46 inline float calculateIntensity(int map_x, int map_y, const Light& light) {
47 int dx = map_x - light.map_x;
48 int dy = map_y - light.map_y;
49 float distance = std::sqrt(dx * dx + dy * dy);
50 if (distance > MaxLightIntensity) {
51 return 0.f;
52 }
53 float intensity = (-distance + light.intensity) * 0.2f;
54 if (intensity < 0.01f) {
55 return 0.f;
56 }
57 return std::min(intensity, 1.f);
58 }
59
60 GLuint texture;
61 std::vector<Light> lights;
62 std::vector<uint8_t> buffer;
63 wxColor global_color;
64};
65
66#endif
67
Top