aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_node.h
blob: b3a6c83b5cd0fd55c3298770166924c467f7d279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef S_NODE_H_
#define S_NODE_H_

#include <map>

#include "irr_v3d.h"
#include "cpp_api/s_base.h"
#include "cpp_api/s_nodemeta.h"

struct MapNode;
class ServerActiveObject;

class ScriptApiNode
		: virtual public ScriptApiBase,
		  public ScriptApiNodemeta
{
public:
	ScriptApiNode();
	virtual ~ScriptApiNode();

	bool node_on_punch(v3s16 p, MapNode node,
			ServerActiveObject *puncher, PointedThing pointed);
	bool node_on_dig(v3s16 p, MapNode node,
			ServerActiveObject *digger);
	void node_on_construct(v3s16 p, MapNode node);
	void node_on_destruct(v3s16 p, MapNode node);
	void node_after_destruct(v3s16 p, MapNode node);
	bool node_on_timer(v3s16 p, MapNode node, f32 dtime);
	void node_on_receive_fields(v3s16 p,
			const std::string &formname,
			const std::map<std::string, std::string> &fields,
			ServerActiveObject *sender);
	void node_falling_update(v3s16 p);
	void node_falling_update_single(v3s16 p);
public:
	static struct EnumString es_DrawType[];
	static struct EnumString es_ContentParamType[];
	static struct EnumString es_ContentParamType2[];
	static struct EnumString es_LiquidType[];
	static struct EnumString es_NodeBoxType[];
};



#endif /* S_NODE_H_ */
struct MinimapModeDef { bool is_radar; u16 scan_height; u16 map_size; }; struct MinimapPixel { //! The topmost node that the minimap displays. MapNode n; u16 height; u16 air_count; }; struct MinimapMapblock { void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos); MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE]; }; struct MinimapData { bool is_radar; MinimapMode mode; v3s16 pos; v3s16 old_pos; u16 scan_height; u16 map_size; MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY]; bool map_invalidated; bool minimap_shape_round; video::IImage *minimap_mask_round = nullptr; video::IImage *minimap_mask_square = nullptr; video::ITexture *texture = nullptr; video::ITexture *heightmap_texture = nullptr; video::ITexture *minimap_overlay_round = nullptr; video::ITexture *minimap_overlay_square = nullptr; video::ITexture *player_marker = nullptr; video::ITexture *object_marker_red = nullptr; }; struct QueuedMinimapUpdate { v3s16 pos; MinimapMapblock *data = nullptr; }; class MinimapUpdateThread : public UpdateThread { public: MinimapUpdateThread() : UpdateThread("Minimap") {} virtual ~MinimapUpdateThread(); void getMap(v3s16 pos, s16 size, s16 height); void enqueueBlock(v3s16 pos, MinimapMapblock *data); bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data); bool popBlockUpdate(QueuedMinimapUpdate *update); MinimapData *data = nullptr; protected: virtual void doUpdate(); private: std::mutex m_queue_mutex; std::deque<QueuedMinimapUpdate> m_update_queue; std::map<v3s16, MinimapMapblock *> m_blocks_cache; }; class Minimap { public: Minimap(Client *client); ~Minimap(); void addBlock(v3s16 pos, MinimapMapblock *data); v3f getYawVec(); void setPos(v3s16 pos); v3s16 getPos() const { return data->pos; } void setAngle(f32 angle); f32 getAngle() const { return m_angle; } void setMinimapMode(MinimapMode mode); MinimapMode getMinimapMode() const { return data->mode; } void toggleMinimapShape(); void setMinimapShape(MinimapShape shape); MinimapShape getMinimapShape(); video::ITexture *getMinimapTexture(); void blitMinimapPixelsToImageRadar(video::IImage *map_image); void blitMinimapPixelsToImageSurface(video::IImage *map_image, video::IImage *heightmap_image); scene::SMeshBuffer *getMinimapMeshBuffer(); void updateActiveMarkers(); void drawMinimap(); video::IVideoDriver *driver; Client* client; MinimapData *data; private: ITextureSource *m_tsrc; IShaderSource *m_shdrsrc; const NodeDefManager *m_ndef; MinimapUpdateThread *m_minimap_update_thread; scene::SMeshBuffer *m_meshbuffer; bool m_enable_shaders; u16 m_surface_mode_scan_height; f32 m_angle; std::mutex m_mutex; std::list<v2f> m_active_markers; };