]> git.lizzy.rs Git - minetest.git/blob - src/tile.cpp
18a2f155ab77d8090ee7ce1401905f6ed793deac
[minetest.git] / src / tile.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 #include "tile.h"
21 #include "porting.h"
22 // For IrrlichtWrapper
23 #include "main.h"
24 #include <string>
25
26 /*
27         These can either be real paths or generated names of preloaded
28         textures (like "mud.png_sidegrass")
29 */
30 std::string g_tile_texture_paths[TILES_COUNT];
31
32 const char * tile_texture_path_get(u32 i)
33 {
34         assert(i < TILES_COUNT);
35
36         //return g_tile_texture_paths[i];
37         return g_tile_texture_paths[i].c_str();
38 }
39
40 // A mapping from tiles to materials
41 // Initialized at run-time.
42 video::SMaterial g_tile_materials[TILES_COUNT];
43
44 enum TileTextureModID
45 {
46         TTMID_NONE,
47         TTMID_SIDEGRASS,
48 };
49
50 struct TileTextureSpec
51 {
52         const char *filename;
53         enum TileTextureModID mod;
54 };
55
56 /*
57         Initializes g_tile_texture_paths with paths of textures,
58         generates generated textures and creates the tile material array.
59 */
60 void init_tile_textures()
61 {
62         TileTextureSpec tile_texture_specs[TILES_COUNT] =
63         {
64                 {NULL, TTMID_NONE},
65                 {"stone.png", TTMID_NONE},
66                 {"water.png", TTMID_NONE},
67                 {"grass.png", TTMID_NONE},
68                 {"tree.png", TTMID_NONE},
69                 {"leaves.png", TTMID_NONE},
70                 {"grass_footsteps.png", TTMID_NONE},
71                 {"mese.png", TTMID_NONE},
72                 {"mud.png", TTMID_NONE},
73                 {"tree_top.png", TTMID_NONE},
74                 {"mud.png", TTMID_SIDEGRASS},
75                 {"cloud.png", TTMID_NONE},
76                 {"coalstone.png", TTMID_NONE},
77                 {"wood.png", TTMID_NONE},
78         };
79         
80         for(s32 i=0; i<TILES_COUNT; i++)
81         {
82                 const char *filename = tile_texture_specs[i].filename;
83                 enum TileTextureModID mod_id = tile_texture_specs[i].mod;
84
85                 if(filename != NULL && std::string("") != filename)
86                 {
87                         std::string path = porting::getDataPath(filename);
88                         std::string mod_postfix = "";
89                         if(mod_id == TTMID_SIDEGRASS)
90                         {
91                                 mod_postfix = "_sidegrass";
92                                 // Generate texture
93                                 TextureMod *mod = new SideGrassTextureMod();
94                                 g_irrlicht->getTexture(TextureSpec(path + mod_postfix,
95                                                 path, mod));
96                         }
97                         g_tile_texture_paths[i] = path + mod_postfix;
98                 }
99         }
100
101         for(s32 i=0; i<TILES_COUNT; i++)
102         {
103                 const char *path = tile_texture_path_get(i);
104
105                 video::ITexture *t = NULL;
106
107                 if(path != NULL && std::string("") != path)
108                 {
109                         t = g_irrlicht->getTexture(path);
110                         assert(t != NULL);
111                 }
112
113                 g_tile_materials[i].Lighting = false;
114                 g_tile_materials[i].BackfaceCulling = false;
115                 g_tile_materials[i].setFlag(video::EMF_BILINEAR_FILTER, false);
116                 g_tile_materials[i].setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
117                 //if(i != TILE_WATER)
118                 g_tile_materials[i].setFlag(video::EMF_FOG_ENABLE, true);
119                 
120                 //g_tile_materials[i].setFlag(video::EMF_TEXTURE_WRAP, video::ETC_REPEAT);
121                 //g_tile_materials[i].setFlag(video::EMF_ANISOTROPIC_FILTER, false);
122
123                 g_tile_materials[i].setTexture(0, t);
124         }
125
126         g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
127         //g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
128 }
129
130 video::SMaterial & tile_material_get(u32 i)
131 {
132         assert(i < TILES_COUNT);
133
134         return g_tile_materials[i];
135 }
136