Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Avara.msvc/AvaraCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@
<ClInclude Include="..\src\util\huffman\CAbstractPipe.h" />
<ClInclude Include="..\src\util\huffman\CHuffProcessor.h" />
<ClInclude Include="..\src\util\JSONify.h" />
<ClInclude Include="..\src\util\Logging.h" />
<ClInclude Include="..\src\util\RamFiles.h" />
<ClInclude Include="..\src\util\RayHit.h" />
<ClInclude Include="..\src\util\RolloverCounter.h" />
<ClInclude Include="..\src\util\SlidingHistogram.h" />
<ClInclude Include="..\vendor\AudioFile.h" />
<ClInclude Include="..\vendor\backward.hpp" />
<ClInclude Include="..\vendor\cute_files.h" />
<ClInclude Include="..\vendor\glm\glm.hpp" />
<ClInclude Include="..\vendor\httplib.h" />
Expand Down Expand Up @@ -368,6 +370,7 @@
<ClInclude Include="..\vendor\nanovg\stb_truetype.h" />
<ClInclude Include="..\vendor\pugixml\pugiconfig.hpp" />
<ClInclude Include="..\vendor\pugixml\pugixml.hpp" />
<ClInclude Include="..\vendor\signalhandling.h" />
<ClInclude Include="..\vendor\stb_image_write.h" />
<ClInclude Include="..\vendor\stb_vorbis.h" />
<ClInclude Include="..\vendor\utf8.h" />
Expand Down Expand Up @@ -507,6 +510,7 @@
<ClCompile Include="..\src\util\huffman\CAbstractHuffPipe.cpp" />
<ClCompile Include="..\src\util\huffman\CAbstractPipe.cpp" />
<ClCompile Include="..\src\util\huffman\CHuffProcessor.cpp" />
<ClCompile Include="..\src\util\Logging.cpp" />
<ClCompile Include="..\src\util\RamFiles.cpp" />
<ClCompile Include="..\vendor\csscolorparser.cpp" />
<ClCompile Include="..\vendor\nanogui\button.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions Avara.msvc/AvaraCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<ClInclude Include="..\vendor\nanovg\nanovg_gl_utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\vendor\backward.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\vendor\signalhandling.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\vendor\pugixml\pugiconfig.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -165,6 +171,9 @@
<ClInclude Include="..\src\util\huffman\CAbstractPipe.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\util\Logging.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\util\CharWordLongPointer.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -662,6 +671,9 @@
<ClCompile Include="..\src\util\FastMat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\util\Logging.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\util\RamFiles.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
17 changes: 17 additions & 0 deletions Avara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
601893AF2ECF106900AB3A6D /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 601893AE2ECF106900AB3A6D /* Logging.cpp */; };
601893B02ECF106900AB3A6D /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 601893AE2ECF106900AB3A6D /* Logging.cpp */; };
601893B12ECF106900AB3A6D /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 601893AE2ECF106900AB3A6D /* Logging.cpp */; };
6025AE4E2C255E6A00A57EFB /* LegacyOpenGLRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 60C274E22C23EBE9005B67A9 /* LegacyOpenGLRenderer.cpp */; };
6055BF212DEA8A79005E3CFB /* BasePath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6055BF202DEA8A79005E3CFB /* BasePath.cpp */; };
6055BF222DEA8A79005E3CFB /* BasePath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6055BF202DEA8A79005E3CFB /* BasePath.cpp */; };
Expand Down Expand Up @@ -571,6 +574,10 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
601893AD2ECF0FB000AB3A6D /* Logging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Logging.h; sourceTree = "<group>"; };
601893AE2ECF106900AB3A6D /* Logging.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Logging.cpp; sourceTree = "<group>"; };
601893B22ED2CB6700AB3A6D /* backward.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = backward.hpp; sourceTree = "<group>"; };
601893B72ED5A1F500AB3A6D /* signalhandling.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = signalhandling.hpp; sourceTree = "<group>"; };
6055BF1F2DEA8A79005E3CFB /* BasePath.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BasePath.h; sourceTree = "<group>"; };
6055BF202DEA8A79005E3CFB /* BasePath.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BasePath.cpp; sourceTree = "<group>"; };
60C274E22C23EBE9005B67A9 /* LegacyOpenGLRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyOpenGLRenderer.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1419,6 +1426,8 @@
E5890BB029895118007A875D /* RolloverCounter.h */,
E5890BB129895118007A875D /* SlidingHistogram.h */,
E2D76F732A1680FD000D24B3 /* JSONify.h */,
601893AD2ECF0FB000AB3A6D /* Logging.h */,
601893AE2ECF106900AB3A6D /* Logging.cpp */,
);
path = util;
sourceTree = "<group>";
Expand Down Expand Up @@ -1709,6 +1718,8 @@
isa = PBXGroup;
children = (
E5890ED829895124007A875D /* AudioFile.h */,
601893B22ED2CB6700AB3A6D /* backward.hpp */,
601893B72ED5A1F500AB3A6D /* signalhandling.hpp */,
E5890D3F29895123007A875D /* csscolorparser.cpp */,
E5890EDB29895124007A875D /* csscolorparser.hpp */,
E5890D1829895123007A875D /* cute_files.h */,
Expand Down Expand Up @@ -2531,6 +2542,7 @@
E517F0E4299713DB0036B206 /* vscrollpanel.cpp in Sources */,
E517F0E5299713DB0036B206 /* widget.cpp in Sources */,
E517F0E6299713DB0036B206 /* window.cpp in Sources */,
601893B12ECF106900AB3A6D /* Logging.cpp in Sources */,
E517F0E7299713DB0036B206 /* pugixml.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -2702,6 +2714,7 @@
E5890CFD29895118007A875D /* CBSPPart.cpp in Sources */,
E5890CEF29895118007A875D /* CWallSolid.cpp in Sources */,
E5890CB529895118007A875D /* CFreeSolid.cpp in Sources */,
601893AF2ECF106900AB3A6D /* Logging.cpp in Sources */,
E5890CC529895118007A875D /* CGuardActor.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -2777,6 +2790,7 @@
E5A219F82DC59135007D54FF /* CParasite.cpp in Sources */,
E5A219F92DC59135007D54FF /* CPill.cpp in Sources */,
E5A219FA2DC59135007D54FF /* CPlacedActors.cpp in Sources */,
601893B02ECF106900AB3A6D /* Logging.cpp in Sources */,
E5A219FB2DC59135007D54FF /* CPlayerActor.cpp in Sources */,
E5A219FC2DC59135007D54FF /* CPlayerManager.cpp in Sources */,
E5A219FD2DC59135007D54FF /* CPlayerMissile.cpp in Sources */,
Expand Down Expand Up @@ -3059,6 +3073,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = "";
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -3077,6 +3092,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 1.0;
OTHER_CFLAGS = (
"$(inherited)",
Expand Down Expand Up @@ -3118,6 +3134,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 1.0;
OTHER_CFLAGS = (
"$(inherited)",
Expand Down
6 changes: 6 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ https://github.com/adamstark/AudioFile/
MIT License
Copyright (c) 2017 Adam Stark.

backward-cpp
https://github.com/bombela/backward-cpp
François-Xavier Bourlet bombela@gmail.com
MIT License
Copyright 2013-2017 Google Inc. All Rights Reserved.

css-color-parser-cpp
https://github.com/mapbox/css-color-parser-cpp
MIT License
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ else
LDFLAGS += $(shell ${PKG_CONFIG} --libs-only-l sdl2)
CPPFLAGS += $(shell ${PKG_CONFIG} --cflags-only-I directfb)
CPPFLAGS += $(shell ${PKG_CONFIG} --cflags-only-I sdl2)
CPPFLAGS += -fPIC
CPPFLAGS += -fPIC
POST_PROCESS ?= ls -lh
endif

Expand Down
11 changes: 8 additions & 3 deletions src/Avara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "FastMat.h"
#include "Preferences.h"
#include "BasePath.h"

#include "Logging.h"
#include "signal.h"
#include "signalhandling.hpp"
#ifdef _WIN32
#include <Windows.h>
#include <ShellAPI.h>
Expand All @@ -42,6 +44,8 @@ void SetHiDPI() {
#include <sstream>
#include <string>

SignalHandling sh;

using namespace nanogui;

void NullLogger(void *userdata, int category, SDL_LogPriority priority, const char *message) {}
Expand Down Expand Up @@ -83,6 +87,8 @@ std::vector<std::string> combinedArgs(std::string defaultArgs, int argc, char* a
}

int main(int argc, char *argv[]) {
// Open log file.
Logging::OpenLog();
// Check basepath override.
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--basepath") == 0) {
Expand Down Expand Up @@ -162,15 +168,14 @@ int main(int argc, char *argv[]) {
} else if(connectAddress.size() > 0) {
app->GetNet()->ChangeNet(kClientNet, connectAddress);
}

// outside of the game, use INACTIVE_LOOP_REFRESH (no need to poll when not playing)
mainloop(INACTIVE_LOOP_REFRESH);

app->Done();

// Shut it down!!
shutdown();

Logging::CloseLog();
return 0;
}

Expand Down
14 changes: 9 additions & 5 deletions src/gui/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <json.hpp>
#include <SDL2/SDL.h>
#include <fstream>
#include <sstream>
#include <string>

using json = nlohmann::json;
Expand Down Expand Up @@ -220,13 +221,16 @@ static json defaultPrefs = {
{kControllerDamperMillis, 500.0}
};



static std::string PrefPath() {
static std::string PrefPath(const char* fn) {
char *prefPath = SDL_GetPrefPath("Avaraline", "Avara");
std::string jsonPath = std::string(prefPath) + "prefs.json";
std::string filePath = std::string(prefPath);
filePath.append(fn);
SDL_free(prefPath);
return jsonPath;
return filePath;
}

static std::string PrefPath() {
return PrefPath("prefs.json");
}

static inline json ReadDefaultPrefs() {
Expand Down
48 changes: 48 additions & 0 deletions src/util/Logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Logging.h"
#include "Preferences.h"

std::ofstream Logging::logFile;


static const char * const _priority_names[] = {
NULL,
"TRACE",
"VERBOSE",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"CRITICAL"
};

void Logging::OpenLog() {
try {
std::string logPath = PrefPath("avara.log");
logFile.open(logPath, std::ios::out | std::ios::trunc);
if (logFile.fail()) {
SDL_Log("Failed to open log file at %s.", logPath.c_str());
}
else {
SDL_LogSetOutputFunction(Logging::Log, nullptr);
}
}
catch (std::exception e) {
SDL_Log("Error opening log file.");
}
}

void Logging::Log(void *userdata, int category, SDL_LogPriority priority, const char *message) {
if (logFile.is_open()) {
std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
logFile << std::put_time(&tm, "%Y%m%d %H%M%S ");
logFile << SDL_GetTicks64() << " " << _priority_names[priority] << ": " << message << "\n";
logFile.flush();
}
printf("%s: %s\n", _priority_names[priority], message);
}

void Logging::CloseLog() {
logFile.flush();
logFile.close();
}
14 changes: 14 additions & 0 deletions src/util/Logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <fstream>
#include <SDL2/SDL.h>

class Logging {
private:
static std::ofstream logFile;
public:
static void OpenLog();
static void Log(void *userdata, int category, SDL_LogPriority priority, const char *message);
static void CloseLog();
static std::ofstream& LogFile() { return logFile; }
};
Loading
Loading