backing up some stuff

This commit is contained in:
Perttu Ahola 2011-01-26 17:13:19 +02:00
parent adb7f248da
commit bd100c5483
6 changed files with 172 additions and 43 deletions

@ -32,6 +32,8 @@ void debugstreams_init(bool disable_stderr, const char *filename)
{ {
if(disable_stderr) if(disable_stderr)
g_debugstreams[0] = NULL; g_debugstreams[0] = NULL;
else
g_debugstreams[0] = stderr;
if(filename) if(filename)
g_debugstreams[1] = fopen(filename, "a"); g_debugstreams[1] = fopen(filename, "a");
@ -42,6 +44,9 @@ void debugstreams_init(bool disable_stderr, const char *filename)
fprintf(g_debugstreams[1], " Separator \n"); fprintf(g_debugstreams[1], " Separator \n");
fprintf(g_debugstreams[1], "-------------\n\n"); fprintf(g_debugstreams[1], "-------------\n\n");
} }
DEBUGPRINT("Debug streams initialized, disable_stderr=%d\n",
disable_stderr);
} }
void debugstreams_deinit() void debugstreams_deinit()

@ -104,12 +104,8 @@ SUGG: Meshes of blocks could be split into 6 meshes facing into
Gaming ideas: Gaming ideas:
------------- -------------
- How would some GTA-style ideas work? - Aim for something like controlling a single dwarf in Dwarf Fortress.
- Cars? Stealing? Unlawful stuff and cops? Lots of guns?
- RPG style?
- Space racer style?
Documentation: Documentation:
-------------- --------------
@ -286,9 +282,16 @@ TODO: Remove duplicate lighting implementation from Map (leave
VoxelManipulator, which is faster) VoxelManipulator, which is faster)
FIXME: The new texture stuff is slow on wine FIXME: The new texture stuff is slow on wine
- Actually it is not too slow; updating excess amount of meshes - A basic grassy ground block takes 20-40ms
when making footprints is too slow. It has to be fixed. - A bit more complicated block can take 270ms
- On linux, a similar one doesn't take long at all (14ms)
- Is it a bad std::string implementation of MSVC?
- Can take up to 200ms? Is it when loading textures or always?
- Updating excess amount of meshes when making footprints is too
slow. It has to be fixed.
-> implement Map::updateNodeMeshes() -> implement Map::updateNodeMeshes()
TODO: Optimize TileSpec to only contain a reference number that
is fast to compare, which refers to a cached string
Doing now: Doing now:
---------- ----------
@ -1266,41 +1269,106 @@ struct ChatLine
std::wstring text; std::wstring text;
}; };
int main(int argc, char *argv[]) // These are defined global so that they're not optimized too much.
// Can't change them to volatile.
s16 temp16;
f32 tempf;
v3f tempv3f1;
v3f tempv3f2;
std::string tempstring;
std::string tempstring2;
void SpeedTests()
{ {
/* {
Low-level initialization dstream<<"The following test should take around 20ms."<<std::endl;
*/ TimeTaker timer("Testing std::string speed");
const u32 jj = 10000;
for(u32 j=0; j<jj; j++)
{
tempstring = "";
tempstring2 = "";
const u32 ii = 10;
for(u32 i=0; i<ii; i++){
tempstring2 += "asd";
}
for(u32 i=0; i<ii+1; i++){
tempstring += "asd";
if(tempstring == tempstring2)
break;
}
}
}
bool disable_stderr = false; dstream<<"All of the following tests should take around 100ms each."
#ifdef _WIN32
disable_stderr = true;
#endif
// Initialize debug streams
debugstreams_init(disable_stderr, DEBUGFILE);
// Initialize debug stacks
debug_stacks_init();
DSTACK(__FUNCTION_NAME);
porting::initializePaths();
// Create user data directory
fs::CreateDir(porting::path_userdata);
// C-style stuff initialization
initializeMaterialProperties();
init_mapnode();
// Debug handler
BEGIN_DEBUG_EXCEPTION_HANDLER
// Print startup message
dstream<<DTIME<<"minetest-c55"
" with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
<<", "<<BUILD_INFO
<<std::endl; <<std::endl;
{
TimeTaker timer("Testing floating-point conversion speed");
tempf = 0.001;
for(u32 i=0; i<4000000; i++){
temp16 += tempf;
tempf += 0.001;
}
}
{
TimeTaker timer("Testing floating-point vector speed");
tempv3f1 = v3f(1,2,3);
tempv3f2 = v3f(4,5,6);
for(u32 i=0; i<10000000; i++){
tempf += tempv3f1.dotProduct(tempv3f2);
tempv3f2 += v3f(7,8,9);
}
}
{
TimeTaker timer("Testing core::map speed");
core::map<v2s16, f32> map1;
tempf = -324;
const s16 ii=300;
for(s16 y=0; y<ii; y++){
for(s16 x=0; x<ii; x++){
map1.insert(v2s16(x,y), tempf);
tempf += 1;
}
}
for(s16 y=ii-1; y>=0; y--){
for(s16 x=0; x<ii; x++){
tempf = map1[v2s16(x,y)];
}
}
}
{
dstream<<"Around 5000/ms should do well here."<<std::endl;
TimeTaker timer("Testing mutex speed");
JMutex m;
m.Init();
u32 n = 0;
u32 i = 0;
do{
n += 10000;
for(; i<n; i++){
m.Lock();
m.Unlock();
}
}
// Do at least 10ms
while(timer.getTime() < 10);
u32 dtime = timer.stop();
u32 per_ms = n / dtime;
std::cout<<"Done. "<<dtime<<"ms, "
<<per_ms<<"/ms"<<std::endl;
}
}
int main(int argc, char *argv[])
{
/* /*
Parse command line Parse command line
*/ */
@ -1318,6 +1386,10 @@ int main(int argc, char *argv[])
allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG)); allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG)); allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING)); allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
#ifdef _WIN32
allowed_options.insert("dstream-on-stderr", ValueSpec(VALUETYPE_FLAG));
#endif
allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG));
Settings cmd_args; Settings cmd_args;
@ -1350,6 +1422,39 @@ int main(int argc, char *argv[])
return cmd_args.getFlag("help") ? 0 : 1; return cmd_args.getFlag("help") ? 0 : 1;
} }
/*
Low-level initialization
*/
bool disable_stderr = false;
#ifdef _WIN32
if(cmd_args.getFlag("dstream-on-stderr") == false)
disable_stderr = true;
#endif
// Initialize debug streams
debugstreams_init(disable_stderr, DEBUGFILE);
// Initialize debug stacks
debug_stacks_init();
DSTACK(__FUNCTION_NAME);
porting::initializePaths();
// Create user data directory
fs::CreateDir(porting::path_userdata);
// C-style stuff initialization
initializeMaterialProperties();
init_mapnode();
// Debug handler
BEGIN_DEBUG_EXCEPTION_HANDLER
// Print startup message
dstream<<DTIME<<"minetest-c55"
" with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
<<", "<<BUILD_INFO
<<std::endl;
/* /*
Basic initialization Basic initialization
@ -1519,7 +1624,15 @@ int main(int argc, char *argv[])
g_device = device; g_device = device;
g_irrlicht = new IrrlichtWrapper(device); g_irrlicht = new IrrlichtWrapper(device);
//g_device = device; /*
Speed tests (done after irrlicht is loaded to get timer)
*/
if(cmd_args.getFlag("speedtests"))
{
dstream<<"Running speed tests"<<std::endl;
SpeedTests();
return 0;
}
device->setResizable(true); device->setResizable(true);

@ -601,7 +601,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
*/ */
{ {
//TimeTaker timer2("updateMesh() collect"); TimeTaker timer2("updateMesh() collect");
// Lock this, as m_temp_mods will be used directly // Lock this, as m_temp_mods will be used directly
JMutexAutoLock lock(m_temp_mods_mutex); JMutexAutoLock lock(m_temp_mods_mutex);

@ -160,7 +160,9 @@ TileSpec MapNode::getTile(v3s16 dir)
s32 dir_i = -1; s32 dir_i = -1;
if(dir == v3s16(0,1,0)) if(dir == v3s16(0,0,0))
dir_i = -1;
else if(dir == v3s16(0,1,0))
dir_i = 0; dir_i = 0;
else if(dir == v3s16(0,-1,0)) else if(dir == v3s16(0,-1,0))
dir_i = 1; dir_i = 1;

@ -54,6 +54,13 @@ u32 TimeTaker::stop(bool quiet)
return 0; return 0;
} }
u32 TimeTaker::getTime()
{
u32 time2 = getTimeMs();
u32 dtime = time2 - m_time1;
return dtime;
}
const v3s16 g_26dirs[26] = const v3s16 g_26dirs[26] =
{ {
// +right, +top, +back // +right, +top, +back

@ -409,6 +409,8 @@ public:
u32 stop(bool quiet=false); u32 stop(bool quiet=false);
u32 getTime();
private: private:
const char *m_name; const char *m_name;
u32 m_time1; u32 m_time1;