aboutsummaryrefslogtreecommitdiff
path: root/src/dungeongen.h
blob: 4be3df4aa8f05455401cb247b54d3bf1366e948d (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Minetest
Copyright (C) 2010-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 DUNGEONGEN_HEADER
#define DUNGEONGEN_HEADER

#include "voxel.h"
#include "noise.h"

#define VMANIP_FLAG_DUNGEON_INSIDE VOXELFLAG_CHECKED1
#define VMANIP_FLAG_DUNGEON_PRESERVE VOXELFLAG_CHECKED2
#define VMANIP_FLAG_DUNGEON_UNTOUCHABLE (\
		VMANIP_FLAG_DUNGEON_INSIDE|VMANIP_FLAG_DUNGEON_PRESERVE)

class ManualMapVoxelManipulator;
class INodeDefManager;

v3s16 rand_ortho_dir(PseudoRandom &random);
v3s16 turn_xz(v3s16 olddir, int t);
v3s16 random_turn(PseudoRandom &random, v3s16 olddir);
int dir_to_facedir(v3s16 d);

class DungeonGen {
public:
	u32 blockseed;
	u64 mapseed;
	ManualMapVoxelManipulator *vmanip;
	INodeDefManager *ndef;
	PseudoRandom random;
	v3s16 csize;
	s16 water_level;
	
	NoiseParams *np_rarity;
	NoiseParams *np_wetness;
	NoiseParams *np_density;
	
	content_t cid_water_source;
	content_t cid_cobble;
	content_t cid_mossycobble;
	content_t cid_torch;
	content_t cid_cobblestair;
	
	//RoomWalker
	v3s16 m_pos;
	v3s16 m_dir;

	DungeonGen(INodeDefManager *ndef, u64 seed, s16 waterlevel);
	void generate(ManualMapVoxelManipulator *vm, u32 bseed,
				  v3s16 full_node_min, v3s16 full_node_max);
	//void generate(v3s16 full_node_min, v3s16 full_node_max, u32 bseed);
	
	void makeDungeon(v3s16 start_padding);
	void makeRoom(v3s16 roomsize, v3s16 roomplace);
	void makeCorridor(v3s16 doorplace, v3s16 doordir,
					  v3s16 &result_place, v3s16 &result_dir);
	void makeDoor(v3s16 doorplace, v3s16 doordir);
	void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags);
	void makeHole(v3s16 place);

	bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir);
	bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
			v3s16 &result_doordir, v3s16 &result_roomplace);
			
	void randomizeDir()
	{
		m_dir = rand_ortho_dir(random);
	}
};

class RoomWalker
{
public:

	RoomWalker(VoxelManipulator &vmanip_, v3s16 pos, PseudoRandom &random,
			INodeDefManager *ndef):
			vmanip(vmanip_),
			m_pos(pos),
			m_random(random),
			m_ndef(ndef)
	{
		randomizeDir();
	}

	void randomizeDir()
	{
		m_dir = rand_ortho_dir(m_random);
	}

	void setPos(v3s16 pos)
	{
		m_pos = pos;
	}

	void setDir(v3s16 dir)
	{
		m_dir = dir;
	}

	//bool findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir);
	//bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
	//		v3s16 &result_doordir, v3s16 &result_roomplace);

private:
	VoxelManipulator &vmanip;
	v3s16 m_pos;
	v3s16 m_dir;
	PseudoRandom &m_random;
	INodeDefManager *m_ndef;
};


#endif
. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. The original version of this class can be located at: http://irrlicht.suckerfreegames.com/ John Norman john@suckerfreegames.com */ #ifndef __C_GUI_TTFONT_H_INCLUDED__ #define __C_GUI_TTFONT_H_INCLUDED__ #include <irrlicht.h> #include <ft2build.h> #include FT_FREETYPE_H namespace irr { namespace gui { struct SGUITTFace; class CGUITTFont; //! Class to assist in deleting glyphs. class CGUITTAssistDelete { public: template <class T, typename TAlloc> static void Delete(core::array<T, TAlloc>& a) { TAlloc allocator; allocator.deallocate(a.pointer()); } }; //! Structure representing a single TrueType glyph. struct SGUITTGlyph { //! Constructor. SGUITTGlyph() : isLoaded(false), glyph_page(0), surface(0), parent(0) {} //! Destructor. ~SGUITTGlyph() { unload(); } //! Preload the glyph. //! The preload process occurs when the program tries to cache the glyph from FT_Library. //! However, it simply defines the SGUITTGlyph's properties and will only create the page //! textures if necessary. The actual creation of the textures should only occur right //! before the batch draw call. void preload(u32 char_index, FT_Face face, video::IVideoDriver* driver, u32 font_size, const FT_Int32 loadFlags); //! Unloads the glyph. void unload(); //! Creates the IImage object from the FT_Bitmap. video::IImage* createGlyphImage(const FT_Bitmap& bits, video::IVideoDriver* driver) const; //! If true, the glyph has been loaded. bool isLoaded; //! The page the glyph is on. u32 glyph_page; //! The source rectangle for the glyph. core::recti source_rect; //! The offset of glyph when drawn. core::vector2di offset; //! Glyph advance information. FT_Vector advance; //! This is just the temporary image holder. After this glyph is paged, //! it will be dropped. mutable video::IImage* surface; //! The pointer pointing to the parent (CGUITTFont) CGUITTFont* parent; }; //! Holds a sheet of glyphs. class CGUITTGlyphPage { public: CGUITTGlyphPage(video::IVideoDriver* Driver, const io::path& texture_name) :texture(0), available_slots(0), used_slots(0), dirty(false), driver(Driver), name(texture_name) {} ~CGUITTGlyphPage() { if (texture) { if (driver) driver->removeTexture(texture); else texture->drop(); } } //! Create the actual page texture, bool createPageTexture(const u8& pixel_mode, const core::dimension2du& texture_size) { if( texture ) return false; bool flgmip = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); // Set the texture color format. switch (pixel_mode) { case FT_PIXEL_MODE_MONO: texture = driver->addTexture(texture_size, name, video::ECF_A1R5G5B5); break; case FT_PIXEL_MODE_GRAY: default: texture = driver->addTexture(texture_size, name, video::ECF_A8R8G8B8); break; } // Restore our texture creation flags. driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flgmip); return texture ? true : false; } //! Add the glyph to a list of glyphs to be paged. //! This collection will be cleared after updateTexture is called. void pushGlyphToBePaged(const SGUITTGlyph* glyph) { glyph_to_be_paged.push_back(glyph); } //! Updates the texture atlas with new glyphs. void updateTexture() { if (!dirty) return; void* ptr = texture->lock(); video::ECOLOR_FORMAT format = texture->getColorFormat(); core::dimension2du size = texture->getOriginalSize(); video::IImage* pageholder = driver->createImageFromData(format, size, ptr, true, false); for (u32 i = 0; i < glyph_to_be_paged.size(); ++i) { const SGUITTGlyph* glyph = glyph_to_be_paged[i]; if (glyph && glyph->isLoaded) { if (glyph->surface) { glyph->surface->copyTo(pageholder, glyph->source_rect.UpperLeftCorner); glyph->surface->drop(); glyph->surface = 0; } else { ; // TODO: add error message? //currently, if we failed to create the image, just ignore this operation. } } } pageholder->drop(); texture->unlock(); glyph_to_be_paged.clear(); dirty = false; } video::ITexture* texture; u32 available_slots; u32 used_slots; bool dirty; core::array<core::vector2di> render_positions; core::array<core::recti> render_source_rects; private: core::array<const SGUITTGlyph*> glyph_to_be_paged; video::IVideoDriver* driver; io::path name; }; //! Class representing a TrueType font. class CGUITTFont : public IGUIFont { public: //! Creates a new TrueType font and returns a pointer to it. The pointer must be drop()'ed when finished. //! \param env The IGUIEnvironment the font loads out of. //! \param filename The filename of the font. //! \param size The size of the font glyphs in pixels. Since this is the size of the individual glyphs, the true height of the font may change depending on the characters used. //! \param antialias set the use_monochrome (opposite to antialias) flag //! \param transparency set the use_transparency flag //! \return Returns a pointer to a CGUITTFont. Will return 0 if the font failed to load. static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true, const u32 shadow = 0, const u32 shadow_alpha = 255); static CGUITTFont* createTTFont(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true); static CGUITTFont* create(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true); static CGUITTFont* create(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true); //! Destructor