]> git.lizzy.rs Git - minetest.git/blob - src/tile.cpp
Added a more flexible path system (and fixed some minor stuff)
[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 // 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_with_grass.png",
41         "cloud.png",
42         "coalstone.png",
43         "wood.png",
44 };
45
46 std::string g_tile_texture_path_strings[TILES_COUNT];
47 const char * g_tile_texture_paths[TILES_COUNT] = {0};
48
49 void init_tile_texture_paths()
50 {
51         for(s32 i=0; i<TILES_COUNT; i++)
52         {
53                 const char *filename = g_tile_texture_filenames[i];
54
55                 if(filename != NULL)
56                 {
57                         g_tile_texture_path_strings[i] =
58                                         porting::getDataPath(filename);
59                         g_tile_texture_paths[i] =
60                                         g_tile_texture_path_strings[i].c_str();
61                 }
62         }
63 }
64
65 const char * tile_texture_path_get(u32 i)
66 {
67         assert(i < TILES_COUNT);
68
69         return g_tile_texture_paths[i];
70 }
71
72 // A mapping from tiles to materials
73 // Initialized at run-time.
74 video::SMaterial g_tile_materials[TILES_COUNT];
75
76 void tile_materials_preload(IrrlichtWrapper *irrlicht)
77 {
78         for(s32 i=0; i<TILES_COUNT; i++)
79         {
80                 const char *path = tile_texture_path_get(i);
81
82                 video::ITexture *t = NULL;
83
84                 if(path != NULL)
85                 {
86                         t = irrlicht->getTexture(path);
87                         assert(t != NULL);
88                 }
89
90                 g_tile_materials[i].Lighting = false;
91                 g_tile_materials[i].BackfaceCulling = false;
92                 g_tile_materials[i].setFlag(video::EMF_BILINEAR_FILTER, false);
93                 g_tile_materials[i].setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
94                 //if(i != TILE_WATER)
95                 g_tile_materials[i].setFlag(video::EMF_FOG_ENABLE, true);
96                 
97                 //g_tile_materials[i].setFlag(video::EMF_TEXTURE_WRAP, video::ETC_REPEAT);
98                 //g_tile_materials[i].setFlag(video::EMF_ANISOTROPIC_FILTER, false);
99
100                 g_tile_materials[i].setTexture(0, t);
101         }
102         
103         g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
104         //g_tile_materials[TILE_WATER].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
105 }
106
107 video::SMaterial & tile_material_get(u32 i)
108 {
109         assert(i < TILES_COUNT);
110
111         return g_tile_materials[i];
112 }
113