Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting and general output #2694

Merged
merged 6 commits into from Jan 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Body.cpp
Expand Up @@ -194,7 +194,7 @@ void Body::UpdateFrame()
if (m_frame->GetRadius() < GetPosition().Length()) {
Frame *newFrame = GetFrame()->GetParent();
if (newFrame) { // don't fall out of root frame
printf("%s leaves frame %s\n", GetLabel().c_str(), GetFrame()->GetLabel().c_str());
Output("%s leaves frame %s\n", GetLabel().c_str(), GetFrame()->GetLabel().c_str());
SwitchToFrame(newFrame);
return;
}
Expand All @@ -205,7 +205,7 @@ void Body::UpdateFrame()
vector3d pos = GetPositionRelTo(*it);
if (pos.Length() >= (*it)->GetRadius()) continue;
SwitchToFrame(*it);
printf("%s enters frame %s\n", GetLabel().c_str(), (*it)->GetLabel().c_str());
Output("%s enters frame %s\n", GetLabel().c_str(), (*it)->GetLabel().c_str());
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CityOnPlanet.cpp
Expand Up @@ -186,7 +186,7 @@ static void lookupBuildingListModels(citybuildinglist_t *list)
}
}
assert(!models.empty());
//printf("Got %d buildings of tag %s\n", models.size(), list->modelTagName);
//Output("Got %d buildings of tag %s\n", models.size(), list->modelTagName);
list->buildings = new citybuilding_t[models.size()];
list->numBuildings = models.size();

Expand All @@ -198,7 +198,7 @@ static void lookupBuildingListModels(citybuildinglist_t *list)
const double maxx = std::max(fabs(aabb.max.x), fabs(aabb.min.x));
const double maxy = std::max(fabs(aabb.max.z), fabs(aabb.min.z));
list->buildings[i].xzradius = sqrt(maxx*maxx + maxy*maxy);
//printf("%s: %f\n", list->buildings[i].modelname, list->buildings[i].xzradius);
//Output("%s: %f\n", list->buildings[i].modelname, list->buildings[i].xzradius);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DynamicBody.cpp
Expand Up @@ -176,7 +176,7 @@ void DynamicBody::TimeStepUpdate(const float timeStep)
SetPosition(GetPosition() + m_vel * double(timeStep));

//if (this->IsType(Object::PLAYER))
//printf("pos = %.1f,%.1f,%.1f, vel = %.1f,%.1f,%.1f, force = %.1f,%.1f,%.1f, external = %.1f,%.1f,%.1f\n",
//Output("pos = %.1f,%.1f,%.1f, vel = %.1f,%.1f,%.1f, force = %.1f,%.1f,%.1f, external = %.1f,%.1f,%.1f\n",
// pos.x, pos.y, pos.z, m_vel.x, m_vel.y, m_vel.z, m_force.x, m_force.y, m_force.z,
// m_externalForce.x, m_externalForce.y, m_externalForce.z);

Expand Down
4 changes: 2 additions & 2 deletions src/FaceGenManager.cpp
Expand Up @@ -14,7 +14,7 @@ namespace
void LoadImage(const std::string &filename, std::vector<SDLSurfacePtr> &vec) {
SDLSurfacePtr pSurf = LoadSurfaceFromFile(filename);
if(!pSurf)
printf("Failed to load image %s\n", filename.c_str());
Output("Failed to load image %s\n", filename.c_str());
vec.push_back(pSurf);
}

Expand Down Expand Up @@ -318,7 +318,7 @@ void FaceGenManager::Init()
m_species.push_back(new Species(index));
}

printf("Face Generation source images loaded.\n");
Output("Face Generation source images loaded.\n");
}

//static
Expand Down
8 changes: 4 additions & 4 deletions src/Factions.cpp
Expand Up @@ -241,11 +241,11 @@ static int l_fac_add_to_factions(lua_State *L)
if (!facbld->registered && !facbld->skip) {
/* XXX maybe useful for debugging, leaving for now
if (facbld->fac->hasHomeworld) {
printf("l_fac_add_to_factions: added (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
Output("l_fac_add_to_factions: added (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
, fac->homeworld.sectorX, fac->homeworld.sectorY, fac->homeworld.sectorZ, fac->foundingDate, fac->expansionRate, fac->name.c_str(), factionName.c_str());
}
else {
printf("l_fac_add_to_factions: added '%s' [%s]\n", fac->name.c_str(), factionName.c_str());
Output("l_fac_add_to_factions: added '%s' [%s]\n", fac->name.c_str(), factionName.c_str());
}
*/

Expand All @@ -261,7 +261,7 @@ static int l_fac_add_to_factions(lua_State *L)
return 0;
} else if (facbld->skip) {
/* XXX maybe useful for debugging, leaving for now
printf("l_fac_add_to_factions: invalid homeworld, skipped (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
Output("l_fac_add_to_factions: invalid homeworld, skipped (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
, fac->homeworld.sectorX, fac->homeworld.sectorY, fac->homeworld.sectorZ, fac->foundingDate, fac->expansionRate, fac->name.c_str(), factionName.c_str());
*/
return 0;
Expand Down Expand Up @@ -340,7 +340,7 @@ void Faction::Init()
LUA_DEBUG_END(L, 0);
lua_close(L);

printf("Number of factions added: " SIZET_FMT "\n", s_factions.size());
Output("Number of factions added: " SIZET_FMT "\n", s_factions.size());
StarSystem::ShrinkCache(); // clear the star system cache of anything we used for faction generation
}

Expand Down
5 changes: 3 additions & 2 deletions src/FileSourceZip.cpp
Expand Up @@ -2,6 +2,7 @@
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "FileSourceZip.h"
#include "utils.h"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
Expand All @@ -19,7 +20,7 @@ FileSourceZip::FileSourceZip(FileSourceFS &fs, const std::string &zipPath) : Fil
mz_zip_archive *zip = static_cast<mz_zip_archive*>(std::calloc(1, sizeof(mz_zip_archive)));
FILE *file = fs.OpenReadStream(zipPath);
if (!mz_zip_reader_init_file_stream(zip, file, 0)) {
printf("FileSourceZip: unable to open '%s'\n", zipPath.c_str());
Output("FileSourceZip: unable to open '%s'\n", zipPath.c_str());
std::free(zip);
return;
}
Expand Down Expand Up @@ -126,7 +127,7 @@ RefCountedPtr<FileData> FileSourceZip::ReadFile(const std::string &path)

char *data = static_cast<char*>(std::malloc(st.size));
if (!mz_zip_reader_extract_to_mem(zip, st.index, data, st.size, 0)) {
printf("FileSourceZip::ReadFile: couldn't extract '%s'\n", path.c_str());
Output("FileSourceZip::ReadFile: couldn't extract '%s'\n", path.c_str());
return RefCountedPtr<FileData>();
}

Expand Down
10 changes: 5 additions & 5 deletions src/Game.cpp
Expand Up @@ -113,9 +113,9 @@ Game::Game(Serializer::Reader &rd) :

// version check
rd.SetStreamVersion(rd.Int32());
fprintf(stderr, "savefile version: %d\n", rd.StreamVersion());
Output("savefile version: %d\n", rd.StreamVersion());
if (rd.StreamVersion() != s_saveVersion) {
fprintf(stderr, "can't load savefile, expected version: %d\n", s_saveVersion);
Output("can't load savefile, expected version: %d\n", s_saveVersion);
throw SavedGameWrongVersionException();
}

Expand Down Expand Up @@ -395,7 +395,7 @@ void Game::SwitchToHyperspace()
m_hyperspaceClouds.push_back(cloud);
}

printf(SIZET_FMT " clouds brought over\n", m_hyperspaceClouds.size());
Output(SIZET_FMT " clouds brought over\n", m_hyperspaceClouds.size());

// remove the player from space
m_space->RemoveBody(m_player.get());
Expand Down Expand Up @@ -423,7 +423,7 @@ void Game::SwitchToHyperspace()
m_state = STATE_HYPERSPACE;
m_wantHyperspace = false;

printf("Started hyperspacing...\n");
Output("Started hyperspacing...\n");
}

void Game::SwitchToNormalSpace()
Expand Down Expand Up @@ -710,7 +710,7 @@ void Game::DestroyViews()

Game *Game::LoadGame(const std::string &filename)
{
printf("Game::LoadGame('%s')\n", filename.c_str());
Output("Game::LoadGame('%s')\n", filename.c_str());
auto file = FileSystem::userFiles.ReadFile(FileSystem::JoinPathBelow(Pi::SAVE_DIR_NAME, filename));
if (!file) throw CouldNotOpenFileException();
Serializer::Reader rd(file->AsByteRange());
Expand Down
4 changes: 2 additions & 2 deletions src/GeoSphere.cpp
Expand Up @@ -26,7 +26,7 @@ static const int detail_edgeLen[5] = {
7, 15, 25, 35, 55
};

#define PRINT_VECTOR(_v) printf("%f,%f,%f\n", (_v).x, (_v).y, (_v).z);
#define PRINT_VECTOR(_v) Output("%f,%f,%f\n", (_v).x, (_v).y, (_v).z);

static const int geo_sphere_edge_friends[NUM_PATCHES][4] = {
{ 3, 4, 1, 2 },
Expand All @@ -53,7 +53,7 @@ void GeoSphere::Uninit()

static void print_info(const SystemBody *sbody, const Terrain *terrain)
{
printf(
Output(
"%s:\n"
" height fractal: %s\n"
" colour fractal: %s\n"
Expand Down
2 changes: 1 addition & 1 deletion src/GeoSphere.h
Expand Up @@ -43,7 +43,7 @@ class GeoSphere {
// Fractals absolutely MUST return heights >= 0.0 (one planet radius)
// otherwise atmosphere and other things break.
if (h < 0.0) {
fprintf(stderr, "GetHeight({ %f, %f, %f }) returned %f\n", p.x, p.y, p.z, h);
Output("GetHeight({ %f, %f, %f }) returned %f\n", p.x, p.y, p.z, h);
m_terrain->DebugDump();
assert(h >= 0.0);
}
Expand Down
5 changes: 3 additions & 2 deletions src/IniConfig.cpp
Expand Up @@ -5,6 +5,7 @@
#include "IniConfig.h"
#include "FileSystem.h"
#include "StringRange.h"
#include "utils.h"
#include <cstdlib>
#include <sstream>

Expand Down Expand Up @@ -98,7 +99,7 @@ void IniConfig::Read(const FileSystem::FileData &data)
const char *kend = line.FindChar('=');
// if there's no '=' sign, skip the line
if (kend == line.end) {
fprintf(stderr, "WARNING: ignoring invalid line in config file:\n '%.*s'\n", int(line.Size()), line.begin);
Output("WARNING: ignoring invalid line in config file:\n '%.*s'\n", int(line.Size()), line.begin);
continue;
}

Expand All @@ -119,7 +120,7 @@ bool IniConfig::Write(FileSystem::FileSourceFS &fs, const std::string &path)
{
FILE *f = fs.OpenWriteStream(path, FileSystem::FileSourceFS::WRITE_TEXT);
if (!f) {
fprintf(stderr, "Could not write config file '%s'\n", FileSystem::JoinPath(fs.GetRoot(), path).c_str());
Output("Could not write config file '%s'\n", FileSystem::JoinPath(fs.GetRoot(), path).c_str());
return false;
}
for (SectionMapType::const_iterator secIt = m_map.begin(); secIt != m_map.end(); ++secIt) {
Expand Down
4 changes: 2 additions & 2 deletions src/KeyBindings.cpp
Expand Up @@ -239,7 +239,7 @@ void KeyAction::SetFromString(const char *str)
const size_t len = strlen(str);
char buf[BUF_SIZE];
if (len >= BUF_SIZE) {
fprintf(stderr, "invalid KeyAction string\n");
Output("invalid KeyAction string\n");
binding1 = KeyBinding::FromString(str);
binding2.Clear();
} else {
Expand Down Expand Up @@ -444,7 +444,7 @@ void InitAxisBinding(AxisBinding &ab, const std::string &bindName, const std::st

// set the binding from the configured or default value
if (!AxisBinding::FromString(axisName.c_str(), ab)) {
fprintf(stderr, "invalid axis binding '%s' in config file for %s\n", axisName.c_str(), bindName.c_str());
Output("invalid axis binding '%s' in config file for %s\n", axisName.c_str(), bindName.c_str());
ab.Clear();
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Lang.cpp
Expand Up @@ -43,12 +43,12 @@ bool Resource::Load()
std::string filename = "lang/" + m_name + "/" + m_langCode + ".json";
RefCountedPtr<FileSystem::FileData> fd = FileSystem::gameDataFiles.ReadFile(filename);
if (!fd) {
fprintf(stderr, "couldn't open language file '%s'\n", filename.c_str());
Output("couldn't open language file '%s'\n", filename.c_str());
return false;
}

if (!reader.parse(fd->GetData(), fd->GetData()+fd->GetSize(), data)) {
fprintf(stderr, "couldn't read language file '%s': %s\n", filename.c_str(), reader.getFormattedErrorMessages().c_str());
Output("couldn't read language file '%s': %s\n", filename.c_str(), reader.getFormattedErrorMessages().c_str());
return false;
}

Expand All @@ -57,28 +57,28 @@ bool Resource::Load()
for (Json::Value::iterator i = data.begin(); i != data.end(); ++i) {
const std::string token(i.key().asString());
if (token.empty()) {
fprintf(stderr, "%s: found empty token, skipping it\n", filename.c_str());
Output("%s: found empty token, skipping it\n", filename.c_str());
continue;
}
if (!valid_token(token)) {
fprintf(stderr, "%s: invalid token '%s', skipping it\n", filename.c_str(), token.c_str());
Output("%s: invalid token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}

Json::Value message((*i).get("message", Json::nullValue));
if (message.isNull()) {
fprintf(stderr, "%s: no 'message' key for token '%s', skipping it\n", filename.c_str(), token.c_str());
Output("%s: no 'message' key for token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}

if (!message.isString()) {
fprintf(stderr, "%s: value for token '%s' is not a string, skipping it\n", filename.c_str(), token.c_str());
Output("%s: value for token '%s' is not a string, skipping it\n", filename.c_str(), token.c_str());
continue;
}

std::string text(message.asString());
if (text.empty()) {
fprintf(stderr, "%s: empty value for token '%s', skipping it\n", filename.c_str(), token.c_str());
Output("%s: empty value for token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}

Expand Down Expand Up @@ -187,12 +187,12 @@ void MakeCore(Resource &res)
std::string text = res.Get(token);

if (text.empty()) {
fprintf(stderr, "%s/%s: token '%s' not found\n", res.GetName().c_str(), res.GetLangCode().c_str(), token.c_str());
Output("%s/%s: token '%s' not found\n", res.GetName().c_str(), res.GetLangCode().c_str(), token.c_str());
text = token;
}

if (text.size() > size_t(STRING_RECORD_SIZE)) {
fprintf(stderr, "%s/%s: text for token '%s' is too long and will be truncated\n", res.GetName().c_str(), res.GetLangCode().c_str(), token.c_str());
Output("%s/%s: text for token '%s' is too long and will be truncated\n", res.GetName().c_str(), res.GetLangCode().c_str(), token.c_str());
text.resize(STRING_RECORD_SIZE);
}

Expand Down Expand Up @@ -223,13 +223,13 @@ Resource GetResource(const std::string &name, const std::string &langCode)
bool loaded = res.Load();
if (!loaded) {
if (langCode != "en") {
fprintf(stderr, "couldn't load language resource %s/%s, trying %s/en\n", name.c_str(), langCode.c_str(), name.c_str());
Output("couldn't load language resource %s/%s, trying %s/en\n", name.c_str(), langCode.c_str(), name.c_str());
res = Lang::Resource(name, "en");
loaded = res.Load();
key = name + ":" + "en";
}
if (!loaded)
fprintf(stderr, "couldn't load language resource %s/en\n", name.c_str());
Output("couldn't load language resource %s/en\n", name.c_str());
}

if (loaded)
Expand Down
6 changes: 3 additions & 3 deletions src/LuaConsole.cpp
Expand Up @@ -86,7 +86,7 @@ void LuaConsole::RunAutoexec() {
if (ret != LUA_OK) {
if (ret == LUA_ERRSYNTAX) {
const char *msg = lua_tostring(L, -1);
fprintf(stderr, "console.lua: %s\n", msg);
Output("console.lua: %s\n", msg);
lua_pop(L, 1);
}
AddOutput("Failed to run console.lua");
Expand All @@ -103,7 +103,7 @@ void LuaConsole::RunAutoexec() {
ret = lua_pcall(L, 0, 0, -2);
if (ret != LUA_OK) {
const char *msg = lua_tostring(L, -1);
fprintf(stderr, "console.lua:\n%s\n", msg);
Output("console.lua:\n%s\n", msg);
AddOutput("Failed to run console.lua");
lua_pop(L, 1);
}
Expand Down Expand Up @@ -452,7 +452,7 @@ static int l_console_print(lua_State *L) {
lua_pop(L, 1);
}
lua_pop(L, 1);
printf("%s\n", line.c_str());
Output("%s\n", line.c_str());
if (Pi::luaConsole) {
Pi::luaConsole->AddOutput(line);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LuaManager.cpp
Expand Up @@ -9,7 +9,7 @@ bool instantiated = false;

LuaManager::LuaManager() : m_lua(0) {
if (instantiated) {
fprintf(stderr, "Can't instantiate more than one LuaManager");
Output("Can't instantiate more than one LuaManager");
abort();
}

Expand Down
2 changes: 1 addition & 1 deletion src/LuaMatrix.cpp
Expand Up @@ -92,7 +92,7 @@ static int l_matrix_new_scale(lua_State *L)
static int l_matrix_print(lua_State *L)
{
matrix4x4f *v = checkMatrix(L, 1);
printf("[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n\n",
Output("[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n[%f,%f,%f,%f]\n\n",
(*v)[0], (*v)[1], (*v)[2], (*v)[3],
(*v)[4], (*v)[5], (*v)[6], (*v)[7],
(*v)[8], (*v)[9], (*v)[10], (*v)[11],
Expand Down