*** Merged Code from Multiplayer Branch Revision 2960 ***

- Virtual File System (VFS) by birdflu. This is needed for Multiplayer and is also used for Single Player. Very neat system :-)
- Multiplayer Version 1.1 + some additional features and bugfixes
* INFO: If you compile a new EXE and want to test, be sure to also use the latest SVN GameDir files in your JA2 install directory *




git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2961 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2009-06-04 21:01:45 +00:00
parent 17f44f63e8
commit 47db604b50
301 changed files with 76701 additions and 1843 deletions
+40
View File
@@ -0,0 +1,40 @@
#include "HPTimer.h"
CHPTimer::CHPTimer()
{
#ifdef WIN32
QueryPerformanceFrequency(&ticksPerSecond);
#endif
}
CHPTimer::~CHPTimer()
{
}
void CHPTimer::StartTimer()
{
#ifdef WIN32
QueryPerformanceCounter(&tick);
#elif LINUX
gettimeofday(&t1,0);
#endif
}
void CHPTimer::StopTimer()
{
#ifdef WIN32
QueryPerformanceCounter(&tick2);
#elif LINUX
gettimeofday(&t2,0);
#endif
}
double CHPTimer::GetElapsedTimeInSeconds()
{
#ifdef WIN32
return (double)(tick2.QuadPart - tick.QuadPart)/(double)ticksPerSecond.QuadPart;
#elif LINUX
return (double)(t2.tv_usec - t1.tv_usec)/1000000.0;
#endif
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef _HPTIMER_
#define _HPTIMER_
#ifdef WIN32
#include <Windows.h>
#elif LINUX
#include <sys/time.h>
#endif
class CHPTimer
{
public:
CHPTimer();
~CHPTimer();
void StartTimer();
void StopTimer();
double GetElapsedTimeInSeconds();
protected:
#ifdef WIN32
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER tick,tick2;
#elif LINUX
timeval t1,t2;
#endif
};
#endif // _HPTIMER_
+148
View File
@@ -0,0 +1,148 @@
#define NOMINMAX
#include "Prof.h"
#include "../vfs_types.h"
#include "../File/vfs_file.h"
#include <sstream>
CProf* g_Profiler = NULL;
class CProfileStarter
{
public:
CProfileStarter()
{
CProf::GetProf();
}
};
static CProfileStarter starter;
CProf* CProf::GetProf()
{
if(!g_Profiler)
{
g_Profiler = new CProf();
}
return g_Profiler;
}
CProf::CProf()
{
m_vMarker.resize(1024);
_nextMarker = 0;
}
void CProf::Clear()
{
for(unsigned int i = 0; i < _nextMarker; ++i)
{
m_vMarker[i].markername = "";
m_vMarker[i].time = 0;
m_vMarker[i].call_count = 0;
m_vMarker[i].success_count = 0;
m_vMarker[i].fail_count = 0;
}
_nextMarker = 0;
}
CProf::tMarkerID CProf::RegisterMarker(const char *marker)
{
m_vMarker[_nextMarker].markername = marker;
return _nextMarker++;
}
void CProf::StartMarker(tMarkerID id)
{
m_vMarker[id].timer.StartTimer();
}
void CProf::StopMarker(tMarkerID id, bool success)
{
m_vMarker[id].timer.StopTimer();
m_vMarker[id].time += m_vMarker[id].timer.GetElapsedTimeInSeconds();
m_vMarker[id].call_count++;
if(success) m_vMarker[id].success_count++;
else m_vMarker[id].fail_count++;
}
inline std::string MultChar(std::string::value_type c, unsigned int multiplicity)
{
std::string s;
s.resize(multiplicity);
for(unsigned int i=0; i<multiplicity; ++i)
{
s[i] = c;
}
return s;
}
inline long double perCent(unsigned long value, unsigned long ref)
{
return 100.0 * ((double)(value)/double(ref));
}
inline long double oneDigit(long double number)
{
unsigned long temp = (unsigned long)(number * 10);
return (temp / 10.0);
}
bool CProf::PrintProfilerState(vfs::Path const& file)
{
vfs::CFile oFile(file);
if(!oFile.OpenWrite(true,true))
{
return false;
}
// get largest value
long double max_time = 0;
unsigned int max_prefix = 0;
for(unsigned int i=0; i<m_vMarker.size(); ++i)
{
if(m_vMarker[i].time > max_time)
{
max_time = m_vMarker[i].time;
}
std::string::size_type prefix_length = m_vMarker[i].markername.length();
if(prefix_length > max_prefix)
{
max_prefix = prefix_length;
}
}
const unsigned int WIDTH = 40;
std::stringstream line;
long double ld_success, ld_failure;
for(unsigned int i=0; i<m_vMarker.size(); ++i)
{
if(m_vMarker[i].markername.empty())
{
break;
}
if(m_vMarker[i].markername.length() < WIDTH)
{
unsigned int space = WIDTH - m_vMarker[i].markername.length();
line << m_vMarker[i].markername << MultChar(' ',space) << " | ";
}
else
{
line << m_vMarker[i].markername.substr(0,WIDTH) << " | ";
}
if(max_time != 0)
{
unsigned int num_stars = (unsigned int)(WIDTH * (m_vMarker[i].time / max_time));
ld_success = perCent(m_vMarker[i].success_count,m_vMarker[i].call_count);
ld_failure = perCent(m_vMarker[i].fail_count,m_vMarker[i].call_count);
line << "[" << oneDigit(ld_success) << "|" << oneDigit(ld_failure) << "] "
<< MultChar('*', num_stars) << MultChar(' ', WIDTH - num_stars) << " | ";
}
line << "C: " << m_vMarker[i].call_count << ", T: " << m_vMarker[i].time << std::endl;
//line << std::endl;
}
vfs::UInt32 written;
std::string useless_copy = line.str();
oFile.Write(useless_copy.c_str(), useless_copy.length()*sizeof(std::string::value_type),written);
oFile.Close();
return true;
}
+58
View File
@@ -0,0 +1,58 @@
#ifndef _PROF_H_
#define _PROF_H_
#include "HPTimer.h"
#include "../vfs_types.h"
#include <string>
#include <vector>
#define DO_PROFILE 1
#if DO_PROFILE
#define REGISTERMARKER(id,name) static CProf::tMarkerID id = g_Profiler->RegisterMarker(name)
#define STARTMARKER(id) (g_Profiler->StartMarker(id))
#define STOPMARKER(id,success) (g_Profiler->StopMarker(id,success))
#define DUMPPROFILERSTATSTOFILE(file) if(g_Profiler){g_Profiler->PrintProfilerState(file);}
#else
#define REGISTERMARKER(id,name)
#define STARTMARKER(id)
#define STOPMARKER(id,success)
#define DUMPPROFILERSTATSTOFILE(file)
#endif
class CProf
{
public:
typedef unsigned int tMarkerID;
static CProf* GetProf();
void Clear();
tMarkerID RegisterMarker(const char *marker);
void StartMarker(tMarkerID id);
void StopMarker(tMarkerID id, bool success);
bool PrintProfilerState(vfs::Path const& file);
private:
CProf();
struct MARKER
{
MARKER() : call_count(0), success_count(0), fail_count(0), time(0.0) {};
std::string markername;
long double time;
unsigned long call_count;
unsigned long success_count;
unsigned long fail_count;
CHPTimer timer;
};
std::vector<MARKER> m_vMarker;
unsigned int _nextMarker;
};
extern CProf* g_Profiler;
#endif // _PROF_H_