add log.cpp
This commit is contained in:
parent
d2449abd61
commit
7c156dacb7
@ -34,17 +34,15 @@ void upmin(T& x, const T& y) {
|
|||||||
x = y;
|
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;
|
int idx = 0;
|
||||||
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
|
vector<vector<int>> dfn(h, vector<int>(w)), low = dfn;
|
||||||
function<void(int, int, int, int, bool)> tarjan =
|
function<void(int, int, int, int, bool)> tarjan
|
||||||
[&](int x, int y, int fx, int fy, bool rt) {
|
= [&](int x, int y, int fx, int fy, bool rt) {
|
||||||
dfn[x][y] = low[x][y] = ++idx;
|
dfn[x][y] = low[x][y] = ++idx;
|
||||||
int ch = 0;
|
int ch = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
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)
|
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -88,7 +86,6 @@ pair<bool, vector<Point>> generateCapital(
|
|||||||
pos_t h,
|
pos_t h,
|
||||||
vector<vector<VertexType>>& vertex_type,
|
vector<vector<VertexType>>& vertex_type,
|
||||||
int r) {
|
int r) {
|
||||||
|
|
||||||
vector<Point> res(r);
|
vector<Point> res(r);
|
||||||
for (int i = 0; i <= r; i++) {
|
for (int i = 0; i <= r; i++) {
|
||||||
if (!findCut(w, h, vertex_type))
|
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++) {
|
for (pos_t y = 0; y < w; y++) {
|
||||||
if (g.at(x, y).type == TileType::Capital) {
|
if (g.at(x, y).type == TileType::Capital) {
|
||||||
for (int i = 0; i < 4; i++) {
|
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)
|
if (xx < 0 || xx >= h || yy < 0 || yy >= w)
|
||||||
continue;
|
continue;
|
||||||
if (g.at(xx, yy).type == TileType::Capital)
|
if (g.at(xx, yy).type == TileType::Capital)
|
||||||
@ -185,8 +183,9 @@ GameBoard ImportedTerrain::makeGameBoard(const InitInfo& init_info) {
|
|||||||
int T = 5;
|
int T = 5;
|
||||||
|
|
||||||
while (T--) {
|
while (T--) {
|
||||||
vector<vector<VertexType>> vertex_type(h
|
vector<vector<VertexType>> vertex_type(
|
||||||
, vector<VertexType>(w, VertexType::Ordinary));
|
h,
|
||||||
|
vector<VertexType>(w, VertexType::Ordinary));
|
||||||
for (pos_t i = 0; i < h; i++) {
|
for (pos_t i = 0; i < h; i++) {
|
||||||
for (pos_t j = 0; j < w; j++) {
|
for (pos_t j = 0; j < w; j++) {
|
||||||
if (g.at(i, j).type == TileType::Mountain)
|
if (g.at(i, j).type == TileType::Mountain)
|
||||||
@ -250,8 +249,9 @@ ImportedTerrain importTerrain(const ImportTerrainConfig& in) {
|
|||||||
error();
|
error();
|
||||||
|
|
||||||
vector<vector<vector<Point>>> vec(27, vector<vector<Point>>(101));
|
vector<vector<vector<Point>>> vec(27, vector<vector<Point>>(101));
|
||||||
vector<vector<VertexType>> vertex_type(t.h
|
vector<vector<VertexType>> vertex_type(
|
||||||
, vector<VertexType>(t.w, VertexType::Ordinary));
|
t.h,
|
||||||
|
vector<VertexType>(t.w, VertexType::Ordinary));
|
||||||
for (pos_t i = 0; i < t.h; i++) {
|
for (pos_t i = 0; i < t.h; i++) {
|
||||||
for (pos_t j = 0; j < t.w; j++) {
|
for (pos_t j = 0; j < t.w; j++) {
|
||||||
auto& p = t.tiles[i][j];
|
auto& p = t.tiles[i][j];
|
||||||
|
@ -42,4 +42,3 @@ private:
|
|||||||
ImportedTerrain importTerrain(const ImportTerrainConfig& in);
|
ImportedTerrain importTerrain(const ImportTerrainConfig& in);
|
||||||
|
|
||||||
#endif
|
#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,22 +1,25 @@
|
|||||||
#ifndef OG_LOG_H_
|
#ifndef OG_LOG_H_
|
||||||
#define OG_LOG_H_
|
#define OG_LOG_H_
|
||||||
|
|
||||||
|
#include "pc/commcode.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "pc/commcode.h"
|
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
public:
|
||||||
Logger *getInstance() const;
|
static Logger* getInstance();
|
||||||
|
|
||||||
void debug(const std::string&) const;
|
void debug(const std::string&) const;
|
||||||
void info(const std::string&) const;
|
void info(const std::string&) const;
|
||||||
void warn(const std::string&) const;
|
void warn(const std::string&) const;
|
||||||
void error(const std::string&) const;
|
void error(const std::string&) const;
|
||||||
void fatal(const std::string&) const;
|
void fatal(const std::string&) const;
|
||||||
|
void setLogLeval(LogLevel v);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Logger();
|
Logger();
|
||||||
|
static Logger* const instance_;
|
||||||
|
|
||||||
void _log(LogLevel v, const std::string&) const;
|
void _log(LogLevel v, const std::string&) const;
|
||||||
|
|
||||||
LogLevel filter;
|
LogLevel filter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user