aboutsummaryrefslogtreecommitdiff
path: root/advtrains
Commit message (Collapse)AuthorAge
* Unite all save data (except the track database) into a single save fileorwell962017-01-12
|
* Prevent non-initialized wagons from accidentally polluting the worldorwell962017-01-10
| | | | | sometimes wagons get created/loaded but are not initialized. These stand around and can't be removed. Now if a wagon does not get initialized after 20 steps, something went wrong and the wagon is removed.
* Fix restoring the detector.on_node table when paths get cleaned uporwell962017-01-10
|
* Clean up debug message codeorwell962017-01-08
|
* Add fancy passenger wagonorwell962017-01-06
|
* also print ATC reverse command warningorwell962017-01-04
| | | | and move atc_command.txt at a better place
* Purge all debug messages and change 'print' function name to 'atprint'orwell962017-01-04
| | | | Ready for 2.0 release.
* update makefile to new circumstancesorwell962017-01-04
|
* Fix bug in track databaseorwell962017-01-04
| | | | the entire database was broken due to a not removed indexing
* Restructure mod directoryorwell962017-01-04
|
* Add Automatic Train Control systemorwell962017-01-04
|
* add API documentationorwell962017-01-03
|
* make detector code clear entries of trains that do not existorwell962017-01-02
|
* unify update_trainpart_properties and check_trainpartloadorwell962017-01-02
|
* fix discouple not disappearing and a logical mistake with ownersorwell962017-01-02
|
* Do not duplicate definitions of 'print' in every fileorwell962017-01-02
|
* spawn couple on train collisionorwell962016-12-31
| | | | also fix empty trains hanging around for too long
* remove train type concept and calculate train's capabilities based on used ↵orwell962016-12-22
| | | | wagons
* Turning mod into a modpack and separating the trains from the core modorwell962016-12-20
t;util/numeric.h" // paging() #include "debug.h" // assert() #define MAX_PROFILER_TEXT_ROWS 20 // Global profiler class Profiler; extern Profiler *g_profiler; /* Time profiler */ class Profiler { public: Profiler() { } void add(const std::string &name, float value) { MutexAutoLock lock(m_mutex); { /* No average shall have been used; mark add used as -2 */ std::map<std::string, int>::iterator n = m_avgcounts.find(name); if(n == m_avgcounts.end()) m_avgcounts[name] = -2; else{ if(n->second == -1) n->second = -2; assert(n->second == -2); } } { std::map<std::string, float>::iterator n = m_data.find(name); if(n == m_data.end()) m_data[name] = value; else n->second += value; } } void avg(const std::string &name, float value) { MutexAutoLock lock(m_mutex); int &count = m_avgcounts[name]; assert(count != -2); count = MYMAX(count, 0) + 1; m_data[name] += value; } void clear() { MutexAutoLock lock(m_mutex); for(std::map<std::string, float>::iterator i = m_data.begin(); i != m_data.end(); ++i) { i->second = 0; } m_avgcounts.clear(); } void print(std::ostream &o) { printPage(o, 1, 1); } float getValue(const std::string &name) const { std::map<std::string, float>::const_iterator numerator = m_data.find(name); if (numerator == m_data.end()) return 0.f; std::map<std::string, int>::const_iterator denominator = m_avgcounts.find(name); if (denominator != m_avgcounts.end()){ if (denominator->second >= 1) return numerator->second / denominator->second; } return numerator->second; } void printPage(std::ostream &o, u32 page, u32 pagecount) { MutexAutoLock lock(m_mutex); u32 minindex, maxindex; paging(m_data.size(), page, pagecount, minindex, maxindex); for(std::map<std::string, float>::iterator i = m_data.begin(); i != m_data.end(); ++i) { if(maxindex == 0) break; maxindex--; if(minindex != 0) { minindex--; continue; } std::string name = i->first; int avgcount = 1; std::map<std::string, int>::iterator n = m_avgcounts.find(name); if(n != m_avgcounts.end()){ if(n->second >= 1) avgcount = n->second; } o<<" "<<name<<": "; s32 clampsize = 40; s32 space = clampsize - name.size(); for(s32 j=0; j<space; j++) { if(j%2 == 0 && j < space - 1) o<<"-"; else o<<" "; } o<<(i->second / avgcount); o<<std::endl; } } typedef std::map<std::string, float> GraphValues; void graphAdd(const std::string &id, float value) { MutexAutoLock lock(m_mutex); std::map<std::string, float>::iterator i = m_graphvalues.find(id); if(i == m_graphvalues.end()) m_graphvalues[id] = value; else i->second += value; } void graphGet(GraphValues &result) { MutexAutoLock lock(m_mutex); result = m_graphvalues; m_graphvalues.clear(); } void remove(const std::string& name) { MutexAutoLock lock(m_mutex); m_avgcounts.erase(name); m_data.erase(name); } private: Mutex m_mutex; std::map<std::string, float> m_data; std::map<std::string, int> m_avgcounts; std::map<std::string, float> m_graphvalues; }; enum ScopeProfilerType{ SPT_ADD, SPT_AVG, SPT_GRAPH_ADD }; class ScopeProfiler { public: ScopeProfiler(Profiler *profiler, const std::string &name, enum ScopeProfilerType type = SPT_ADD): m_profiler(profiler), m_name(name), m_timer(NULL), m_type(type) { if(m_profiler) m_timer = new TimeTaker(m_name.c_str()); } // name is copied ScopeProfiler(Profiler *profiler, const char *name,