]> git.lizzy.rs Git - minetest.git/blob - src/client/meshgen/collector.h
Add keybind to swap items between hands
[minetest.git] / src / client / meshgen / collector.h
1 /*
2 Minetest
3 Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21 #include <array>
22 #include <vector>
23 #include "irrlichttypes.h"
24 #include "irr_v3d.h"
25 #include <S3DVertex.h>
26 #include "client/tile.h"
27
28 struct PreMeshBuffer
29 {
30         TileLayer layer;
31         std::vector<u16> indices;
32         std::vector<video::S3DVertex> vertices;
33
34         PreMeshBuffer() = default;
35         explicit PreMeshBuffer(const TileLayer &layer) : layer(layer) {}
36 };
37
38 struct MeshCollector
39 {
40         std::array<std::vector<PreMeshBuffer>, MAX_TILE_LAYERS> prebuffers;
41         // bounding sphere radius and center
42         f32 m_bounding_radius_sq = 0.0f;
43         v3f m_center_pos;
44         v3f offset;
45
46         // center_pos: pos to use for bounding-sphere, in BS-space
47         // offset: offset added to vertices
48         MeshCollector(const v3f center_pos, v3f offset = v3f()) : m_center_pos(center_pos), offset(offset) {}
49
50         // clang-format off
51         void append(const TileSpec &material,
52                         const video::S3DVertex *vertices, u32 numVertices,
53                         const u16 *indices, u32 numIndices);
54         void append(const TileSpec &material,
55                         const video::S3DVertex *vertices, u32 numVertices,
56                         const u16 *indices, u32 numIndices,
57                         v3f pos, video::SColor c, u8 light_source);
58         // clang-format on
59
60 private:
61         // clang-format off
62         void append(const TileLayer &material,
63                         const video::S3DVertex *vertices, u32 numVertices,
64                         const u16 *indices, u32 numIndices,
65                         u8 layernum, bool use_scale = false);
66         void append(const TileLayer &material,
67                         const video::S3DVertex *vertices, u32 numVertices,
68                         const u16 *indices, u32 numIndices,
69                         v3f pos, video::SColor c, u8 light_source,
70                         u8 layernum, bool use_scale = false);
71         // clang-format on
72
73         PreMeshBuffer &findBuffer(const TileLayer &layer, u8 layernum, u32 numVertices);
74 };