Inverted control flow, engine as library
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
@@ -206,36 +207,34 @@ double distance_squared(double x1, double y1, double x2, double y2) {
|
||||
return dx*dx + dy*dy;
|
||||
}
|
||||
|
||||
std::string get_file_contents(const std::string &fn) {
|
||||
static std::string get_file_contents(const std::string &fn) {
|
||||
std::ifstream fs(fn);
|
||||
std::stringstream buffer;
|
||||
buffer << fs.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
StringVec get_file_lines(const std::string &path) {
|
||||
StringVec result;
|
||||
std::ifstream f;
|
||||
f.open(path);
|
||||
if (f) {
|
||||
std::string line;
|
||||
while (std::getline(f, line)) {
|
||||
result.push_back(line);
|
||||
static StringVec read_control_lst(const std::string &path) {
|
||||
StringVec lines = split(get_file_contents(path), '\n');
|
||||
util::StringVec result;
|
||||
for (int i = 0; i < int(lines.size()); i++) {
|
||||
std::string trimmed = trim(lines[i]);
|
||||
if ((trimmed.size() > 0) && (trimmed[0] != '#')) {
|
||||
result.push_back(trimmed);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string get_file_fingerprint(const std::string &fn) {
|
||||
struct stat result;
|
||||
if(stat(fn.c_str(), &result)==0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << result.st_mtime;
|
||||
return ss.str();
|
||||
LuaSource read_lua_source(const std::string &dir) {
|
||||
StringVec files = read_control_lst(dir + "/control.lst");
|
||||
assert (!files.empty());
|
||||
LuaSource result;
|
||||
for (const std::string &file : files) {
|
||||
std::string data = get_file_contents(dir + "/" + file);
|
||||
result.emplace_back(file, data);
|
||||
}
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string XYZ::debug_string() const {
|
||||
|
||||
Reference in New Issue
Block a user