]> git.lizzy.rs Git - dragonfireclient.git/blob - src/tile.cpp
Faster lighting at map generation time
[dragonfireclient.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 // A mapping from tiles to paths of textures
27
28 /*const char * g_tile_texture_filenames[TILES_COUNT] =
29 {
30         NULL,
31         "stone.png",
32         "water.png",
33         "grass.png",
34         "tree.png",
35         "leaves.png",
36         "grass_footsteps.png",
37         "mese.png",
38         "mud.png",
39         "tree_top.png",
40         "mud.png_sidegrass",
41         "cloud.png",
42         "coalstone.png",
43         "wood.png",
44 };*/
45
46 /*
47         These can either be real paths or generated names of preloaded
48         textures (like "mud.png_sidegrass")
49 */
50 std::string g_tile_texture_paths[TILES_COUNT];
51
52 /*std::string g_tile_texture_path_strings[TILES_COUNT];
53 const char * g_tile_texture_paths[TILES_COUNT] = {0};
54
55 void init_tile_texture_paths()
56 {
57         for(s32 i=0; i<TILES_COUNT; i++)
58         {
59                 const char *filename = g_tile_texture_filenames[i];
60
61                 if(filename != NULL)
62                 {
63                         g_tile_texture_path_strings[i] =
64                                         porting::getDataPath(filename);
65                         g_tile_texture_paths[i] =
66                                         g_tile_texture_path_strings[i].c_str();
67                 }
68         }
69 }*/
70
71 const char * tile_texture_path_get(u32 i)
72 {
73         assert(i < TILES_COUNT);
74
75         //return g_tile_texture_paths[i];
76         return g_tile_texture_paths[i].c_str();
77 }
78
79 // A mapping from tiles to materials
80 // Initialized at run-time.
81 video::SMaterial g_tile_materials[TILES_COUNT];
82
83 enum TileTextureModID
84 {
85         TTMID_NONE,
86         TTMID_SIDEGRASS,
87 };
88
89 struct TileTextureSpec
90 {
91         const char *filename;
92         enum TileTextureModID mod;
93 };
94
95 /*
96         Initializes g_tile_texture_paths with paths of textures,
97         generates generated textures and creates the tile material array.
98 */
99 void init_tile_textures()
100 {
101         TileTextureSpec tile_texture_specs[TILES_COUNT] =
102         {
103                 {NULL, TTMID_NONE},
104                 {"stone.png", TTMID_NONE},
105                 {"water.png", TTMID_NONE},
106                 {"grass.png", TTMID_NONE},
107                 {"tree.png", TTMID_NONE},
108                 {"leaves.png", TTMID_NONE},
109                 {"grass_footsteps.png", TTMID_NONE},
110                 {"mese.png", TTMID_NONE},
111                 {"mud.png", TTMID_NONE},
112                 {"tree_top.png", TTMID_NONE},
113                 {"mud.png", TTMID_SIDEGRASS},
114                 {"cloud.png", TTMID_NONE},
115                 {"coalstone.png", TTMID_NONE},
116                 {"wood.png", TTMID_NONE},
117         };
118         
119         for(s32 i=0; i<TILES_COUNT; i++)
120         {
121                 const char *filename = tile_texture_specs[i].filename;
122                 enum TileTextureModID mod_id = tile_texture_specs[i].mod;
123
124                 if(filename != NULL && std::string("") != filename)
125                 {
126                         std::string path = porting::getDataPath(filename);
127                         std::string mod_postfix = "";
128                         if(mod_id == TTMID_SIDEGRASS)
129                         {
130                                 mod_postfix = "_sidegrass";
131                                 // Generate texture
132                                 TextureMod *mod = new SideGrassTextureMod();
133                                 g_irrlicht->getTexture(TextureSpec(path + mod_postfix,
134                                                 path, mod));
135                         }
136                         g_tile_texture_paths[i] = path + mod_postfix;
137                 }
138         }
139
140         for(s32 i=0; i<TILES_COUNT; i++)
141         {
142                 const char *path = tile_texture_path_get(i);
143
144                 video::ITexture *t = NULL;
145
146                 if(path != NULL && std::string("") != path)
147                 {
148                         t = g_irrlicht->getTexture(path);
149                         assert(t != NULL);
150                 }
151
152                 g_tile_materials[i].Lighting = false;
153                 g_tile_materials[i].BackfaceCulling = false;
154                 g_tile_materials[i].setFlag(video::EMF_BILINEAR_FILTER, false);
155                 g_tile_materials[i].setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
156                 //if(i != TILE_WATER)
157                 g_tile_materials[i].setFlag(video::EMF_FOG_ENABLE, true);
158                 
159                 //g_tile_materials[i].setFlag(video::EMF_TEXTURE_WRAP, video::ETC_REPEAT);
160                 //g_tile_materials[i].setFlag(video::EMF_ANISOTROPIC_FILTER, false);
161
162                 g_tile_materials[i].setTexture(0, t);
163         }
164
165         g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
166         //g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
167 }
168
169 video::SMaterial & tile_material_get(u32 i)
170 {
171         assert(i < TILES_COUNT);
172
173         return g_tile_materials[i];
174 }
175