3da2f48d56766f947c218827ab417b3a7d0ebc97
[oweals/minetest.git] / src / utility.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 /*
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
22 */
23
24 #include "utility.h"
25 #include "irrlichtwrapper.h"
26
27 TimeTaker::TimeTaker(const char *name, IrrlichtWrapper *irrlicht, u32 *result)
28 {
29         m_name = name;
30         m_irrlicht = irrlicht;
31         m_result = result;
32         m_running = true;
33         if(irrlicht == NULL)
34         {
35                 m_time1 = 0;
36                 return;
37         }
38         m_time1 = m_irrlicht->getTime();
39 }
40
41 u32 TimeTaker::stop(bool quiet)
42 {
43         if(m_running)
44         {
45                 if(m_irrlicht == NULL)
46                 {
47                         /*if(quiet == false)
48                                 std::cout<<"Couldn't measure time for "<<m_name
49                                                 <<": irrlicht==NULL"<<std::endl;*/
50                         return 0;
51                 }
52                 u32 time2 = m_irrlicht->getTime();
53                 u32 dtime = time2 - m_time1;
54                 if(m_result != NULL)
55                 {
56                         (*m_result) += dtime;
57                 }
58                 else
59                 {
60                         if(quiet == false)
61                                 std::cout<<m_name<<" took "<<dtime<<"ms"<<std::endl;
62                 }
63                 m_running = false;
64                 return dtime;
65         }
66         return 0;
67 }
68
69 const v3s16 g_26dirs[26] =
70 {
71         // +right, +top, +back
72         v3s16( 0, 0, 1), // back
73         v3s16( 0, 1, 0), // top
74         v3s16( 1, 0, 0), // right
75         v3s16( 0, 0,-1), // front
76         v3s16( 0,-1, 0), // bottom
77         v3s16(-1, 0, 0), // left
78         // 6
79         v3s16(-1, 1, 0), // top left
80         v3s16( 1, 1, 0), // top right
81         v3s16( 0, 1, 1), // top back
82         v3s16( 0, 1,-1), // top front
83         v3s16(-1, 0, 1), // back left
84         v3s16( 1, 0, 1), // back right
85         v3s16(-1, 0,-1), // front left
86         v3s16( 1, 0,-1), // front right
87         v3s16(-1,-1, 0), // bottom left
88         v3s16( 1,-1, 0), // bottom right
89         v3s16( 0,-1, 1), // bottom back
90         v3s16( 0,-1,-1), // bottom front
91         // 18
92         v3s16(-1, 1, 1), // top back-left
93         v3s16( 1, 1, 1), // top back-right
94         v3s16(-1, 1,-1), // top front-left
95         v3s16( 1, 1,-1), // top front-right
96         v3s16(-1,-1, 1), // bottom back-left
97         v3s16( 1,-1, 1), // bottom back-right
98         v3s16(-1,-1,-1), // bottom front-left
99         v3s16( 1,-1,-1), // bottom front-right
100         // 26
101 };
102
103