add log.cpp
This commit is contained in:
parent
d2449abd61
commit
7c156dacb7
@ -28,23 +28,21 @@ bool ban(VertexType t) {
|
||||
return t == VertexType::Mountain || t == VertexType::Capital;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void upmin(T& x, const T& y) {
|
||||
if (y < x)
|
||||
x = y;
|
||||
}
|
||||
|
||||
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
|
||||
|
||||
bool findCut(pos_t w, pos_t h, vector<vector<VertexType>> &vertex_type) {
|
||||
bool findCut(pos_t w, pos_t h, vector<vector<VertexType>>& vertex_type) {
|
||||
int idx = 0;
|
||||
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
|
||||
function<void(int, int, int, int, bool)> tarjan =
|
||||
[&](int x, int y, int fx, int fy, bool rt) {
|
||||
function<void(int, int, int, int, bool)> tarjan
|
||||
= [&](int x, int y, int fx, int fy, bool rt) {
|
||||
dfn[x][y] = low[x][y] = ++idx;
|
||||
int ch = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const int xx = x + dx[i], yy = y + dy[i];
|
||||
const int xx = x + direction_dx[i], yy = y + direction_dy[i];
|
||||
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
||||
continue;
|
||||
|
||||
@ -88,7 +86,6 @@ pair<bool, vector<Point>> generateCapital(
|
||||
pos_t h,
|
||||
vector<vector<VertexType>>& vertex_type,
|
||||
int r) {
|
||||
|
||||
vector<Point> res(r);
|
||||
for (int i = 0; i <= r; i++) {
|
||||
if (!findCut(w, h, vertex_type))
|
||||
@ -172,7 +169,8 @@ GameBoard ImportedTerrain::makeGameBoard(const InitInfo& init_info) {
|
||||
for (pos_t y = 0; y < w; y++) {
|
||||
if (g.at(x, y).type == TileType::Capital) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const int xx = x + dx[i], yy = y + dy[i];
|
||||
const int xx = x + direction_dx[i],
|
||||
yy = y + direction_dy[i];
|
||||
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
||||
continue;
|
||||
if (g.at(xx, yy).type == TileType::Capital)
|
||||
@ -185,8 +183,9 @@ GameBoard ImportedTerrain::makeGameBoard(const InitInfo& init_info) {
|
||||
int T = 5;
|
||||
|
||||
while (T--) {
|
||||
vector<vector<VertexType>> vertex_type(h
|
||||
, vector<VertexType>(w, VertexType::Ordinary));
|
||||
vector<vector<VertexType>> vertex_type(
|
||||
h,
|
||||
vector<VertexType>(w, VertexType::Ordinary));
|
||||
for (pos_t i = 0; i < h; i++) {
|
||||
for (pos_t j = 0; j < w; j++) {
|
||||
if (g.at(i, j).type == TileType::Mountain)
|
||||
@ -250,8 +249,9 @@ ImportedTerrain importTerrain(const ImportTerrainConfig& in) {
|
||||
error();
|
||||
|
||||
vector<vector<vector<Point>>> vec(27, vector<vector<Point>>(101));
|
||||
vector<vector<VertexType>> vertex_type(t.h
|
||||
, vector<VertexType>(t.w, VertexType::Ordinary));
|
||||
vector<vector<VertexType>> vertex_type(
|
||||
t.h,
|
||||
vector<VertexType>(t.w, VertexType::Ordinary));
|
||||
for (pos_t i = 0; i < t.h; i++) {
|
||||
for (pos_t j = 0; j < t.w; j++) {
|
||||
auto& p = t.tiles[i][j];
|
||||
|
@ -42,4 +42,3 @@ private:
|
||||
ImportedTerrain importTerrain(const ImportTerrainConfig& in);
|
||||
|
||||
#endif
|
||||
|
||||
|
51
processor/utility/log.cpp
Normal file
51
processor/utility/log.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "log.h"
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
Logger* Logger::getInstance() {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void Logger::debug(const std::string& s) const {
|
||||
_log(LogLevel::Debug, s);
|
||||
}
|
||||
|
||||
void Logger::info(const std::string& s) const {
|
||||
_log(LogLevel::Info, s);
|
||||
}
|
||||
|
||||
void Logger::warn(const std::string& s) const {
|
||||
_log(LogLevel::Warn, s);
|
||||
}
|
||||
|
||||
void Logger::error(const std::string& s) const {
|
||||
_log(LogLevel::Error, s);
|
||||
}
|
||||
|
||||
void Logger::fatal(const std::string& s) const {
|
||||
_log(LogLevel::Fatal, s);
|
||||
}
|
||||
|
||||
void Logger::setLogLeval(LogLevel v) {
|
||||
filter = v;
|
||||
}
|
||||
|
||||
Logger::Logger() {
|
||||
filter = LogLevel::Warn;
|
||||
}
|
||||
|
||||
Logger* const Logger::instance_ = new Logger();
|
||||
|
||||
void Logger::_log(LogLevel v, const std::string& s) const {
|
||||
if (v >= filter) {
|
||||
time_t now = time(NULL);
|
||||
static char buff[100];
|
||||
strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", localtime(&now));
|
||||
const char* mp = "DIWEF";
|
||||
fprintf(stderr, "%s [%c] %s\n", buff, mp[(int)v], s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Logger* Log() {
|
||||
return Logger::getInstance();
|
||||
}
|
@ -1,27 +1,30 @@
|
||||
#ifndef OG_LOG_H_
|
||||
#define OG_LOG_H_
|
||||
|
||||
#include "pc/commcode.h"
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include "pc/commcode.h"
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
Logger *getInstance() const;
|
||||
static Logger* getInstance();
|
||||
|
||||
void debug(const std::string &) const;
|
||||
void info(const std::string &) const;
|
||||
void warn(const std::string &) const;
|
||||
void error(const std::string &) const;
|
||||
void fatal(const std::string &) const;
|
||||
void debug(const std::string&) const;
|
||||
void info(const std::string&) const;
|
||||
void warn(const std::string&) const;
|
||||
void error(const std::string&) const;
|
||||
void fatal(const std::string&) const;
|
||||
void setLogLeval(LogLevel v);
|
||||
|
||||
private:
|
||||
Logger();
|
||||
void _log(LogLevel v, const std::string &) const;
|
||||
static Logger* const instance_;
|
||||
|
||||
void _log(LogLevel v, const std::string&) const;
|
||||
|
||||
LogLevel filter;
|
||||
};
|
||||
|
||||
Logger *Log();
|
||||
Logger* Log();
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user