mirror of
https://github.com/haya3218/SDfmL.git
synced 2024-08-14 23:57:09 +00:00
Fuck it, better logging
This commit is contained in:
parent
bf21c5f869
commit
d2bb4ee85b
3 changed files with 87 additions and 14 deletions
13
bin/log.txt
Normal file
13
bin/log.txt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
0:00.050 LOG: (Render.cpp:209) SoLoud has been successfully initialized.
|
||||||
|
0:00.133 LOG: (Render.cpp:214) SDL has been successfully initialized.
|
||||||
|
0:00.135 LOG: (Render.cpp:219) SDL_image has been successfully initialized.
|
||||||
|
0:00.137 LOG: (Render.cpp:224) SDL_ttf has been successfully initialized.
|
||||||
|
0:00.569 LOG: (Render.cpp:230) A window has been created.
|
||||||
|
0:00.649 LOG: (Render.cpp:236) A renderer has been created.
|
||||||
|
0:00.651 LOG: (Render.cpp:245) Finalized initialization. Command over.
|
||||||
|
0:00.652 LOG: (Render.cpp:337) Switching states...
|
||||||
|
0:00.652 LOG: (Render.cpp:349) Success! Calling Create()....
|
||||||
|
0:00.658 LOG: (Render.cpp:354) Played sound from data/flixel.ogg
|
||||||
|
0:03.857 LOG: (Render.cpp:337) Switching states...
|
||||||
|
0:03.858 LOG: (Render.cpp:349) Success! Calling Create()....
|
||||||
|
0:03.859 LOG: (Render.cpp:394) Played midi from data/canyon.mid with soundfont data/gm.sf2
|
|
@ -1,8 +1,11 @@
|
||||||
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "SDL2/SDL.h"
|
#include "SDL2/SDL.h"
|
||||||
|
@ -13,6 +16,10 @@
|
||||||
#include "SoLoud/soloud.h"
|
#include "SoLoud/soloud.h"
|
||||||
#include "SoLoud/soloud_wav.h"
|
#include "SoLoud/soloud_wav.h"
|
||||||
#include "SoLoud/soloud_openmpt.h"
|
#include "SoLoud/soloud_openmpt.h"
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <winuser.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Render;
|
using namespace Render;
|
||||||
|
@ -192,42 +199,45 @@ void Render::Object::centerSelf(AXIS axis) {
|
||||||
bool Render::Init(string window_name) {
|
bool Render::Init(string window_name) {
|
||||||
consoleD = GetConsoleWindow();
|
consoleD = GetConsoleWindow();
|
||||||
SetWindowTextA(consoleD, "Logging window");
|
SetWindowTextA(consoleD, "Logging window");
|
||||||
|
std::ofstream logFile;
|
||||||
|
logFile.open("log.txt", std::ofstream::out | std::ofstream::trunc);
|
||||||
|
logFile.close();
|
||||||
if (se.init() > 0) {
|
if (se.init() > 0) {
|
||||||
cout << "SoLoud has failed to load. Is your dll broken?" << endl;
|
log("Render.cpp", 202, "SoLoud", " has failed to load. Is your dll broken?", ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (music.init() > 0) {
|
if (music.init() > 0) {
|
||||||
cout << "SoLoud has failed to load. Is your dll broken?" << endl;
|
log("Render.cpp", 206, "SoLoud", " has failed to load. Is your dll broken?", ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully initialized the SoLoud audio system. Command next." << endl;
|
log("Render.cpp", 209, "SoLoud", " has been successfully initialized.", NORMAL);
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||||
cout << "SDL has failed to initialize. Is your dll broken? " << SDL_GetError() << endl;
|
log("Render.cpp", 211, "SDL", " has failed to load. Is your dll broken? " + string(SDL_GetError()), ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully initialized SDL. Command next." << endl;
|
log("Render.cpp", 214, "SDL", " has been successfully initialized.", NORMAL);
|
||||||
if (IMG_Init(IMG_INIT_PNG) == 0) {
|
if (IMG_Init(IMG_INIT_PNG) == 0) {
|
||||||
cout << "SDL_image has failed to initialize. Is your dll broken? " << SDL_GetError() << endl;
|
log("Render.cpp", 216, "SDL_image", " has failed to load. Is your dll broken? " + string(SDL_GetError()), ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully initialized SDL_image. Command next." << endl;
|
log("Render.cpp", 219, "SDL_image", " has been successfully initialized.", NORMAL);
|
||||||
if (TTF_Init() < 0) {
|
if (TTF_Init() < 0) {
|
||||||
cout << "SDL_ttf has failed to initialize. Is your dll broken? " << SDL_GetError() << endl;
|
log("Render.cpp", 221, "SDL_ttf", " has failed to load. Is your dll broken? " + string(SDL_GetError()), ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully initialized SDL_ttf. Command next." << endl;
|
log("Render.cpp", 224, "SDL_ttf", " has been successfully initialized.", NORMAL);
|
||||||
window = SDL_CreateWindow(window_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
|
window = SDL_CreateWindow(window_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
|
||||||
if (window == nullptr) {
|
if (window == nullptr) {
|
||||||
cout << "Window has failed to initialize. "<< SDL_GetError() << endl;
|
log("Render.cpp", 227, "A window", " failed to be created. " + string(SDL_GetError()), ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully made a window. Command next." << endl;
|
log("Render.cpp", 230, "A window", " has been created.", NORMAL);
|
||||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
if (renderer == nullptr) {
|
if (renderer == nullptr) {
|
||||||
cout << "Renderer has failed to initialize. "<< SDL_GetError() << endl;
|
log("Render.cpp", 223, "A renderer", " failed to be created. " + string(SDL_GetError()), ERROR_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "Successfully made a renderer. Command next." << endl;
|
log("Render.cpp", 236, "A renderer", " has been created.", NORMAL);
|
||||||
|
|
||||||
current_sf.load(SOUNDFONT);
|
current_sf.load(SOUNDFONT);
|
||||||
|
|
||||||
|
@ -236,7 +246,7 @@ bool Render::Init(string window_name) {
|
||||||
SDL_GetWindowWMInfo(window, &wmInfo);
|
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||||
hwnd = wmInfo.info.win.window;
|
hwnd = wmInfo.info.win.window;
|
||||||
|
|
||||||
cout << "Finalized initialization. Command over." << endl;
|
log("Render.cpp", 245, "", "Finalized initialization. Command over.", NORMAL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -328,6 +338,7 @@ bool Render::Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::SwitchState(State* state) {
|
void Render::SwitchState(State* state) {
|
||||||
|
log("Render.cpp", 337, "", "Switching states...");
|
||||||
if (current_state != nullptr) {
|
if (current_state != nullptr) {
|
||||||
_ticks = {};
|
_ticks = {};
|
||||||
_call = {};
|
_call = {};
|
||||||
|
@ -338,10 +349,12 @@ void Render::SwitchState(State* state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
current_state = state;
|
current_state = state;
|
||||||
|
log("Render.cpp", 349, "Success!", " Calling Create()....");
|
||||||
current_state->Create();
|
current_state->Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Render::playSound(string path, bool override) {
|
bool Render::playSound(string path, bool override) {
|
||||||
|
log("Render.cpp", 354, "", "Played sound from " + path);
|
||||||
waveLoader.setLooping(false);
|
waveLoader.setLooping(false);
|
||||||
if (override) {
|
if (override) {
|
||||||
se.stop(seIndex);
|
se.stop(seIndex);
|
||||||
|
@ -354,9 +367,11 @@ bool Render::playSound(string path, bool override) {
|
||||||
|
|
||||||
bool Render::playMusic(string path) {
|
bool Render::playMusic(string path) {
|
||||||
if (path == "") {
|
if (path == "") {
|
||||||
|
log("Render.cpp", 367, "", "Silence." + path);
|
||||||
music.stopAll();
|
music.stopAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
log("Render.cpp", 371, "", "Played music from " + path);
|
||||||
if (currentMusic == path) {
|
if (currentMusic == path) {
|
||||||
music.stopAll();
|
music.stopAll();
|
||||||
}
|
}
|
||||||
|
@ -370,6 +385,7 @@ bool Render::playMusic(string path) {
|
||||||
|
|
||||||
bool Render::playModPlug(string path) {
|
bool Render::playModPlug(string path) {
|
||||||
if (path == "") {
|
if (path == "") {
|
||||||
|
log("Render.cpp", 385, "", "Silence." + path);
|
||||||
music.stopAll();
|
music.stopAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -378,6 +394,7 @@ bool Render::playModPlug(string path) {
|
||||||
}
|
}
|
||||||
// midis
|
// midis
|
||||||
if (path.find(".mid") != string::npos) {
|
if (path.find(".mid") != string::npos) {
|
||||||
|
log("Render.cpp", 394, "", "Played midi from " + path + " with soundfont " + SOUNDFONT);
|
||||||
midiLoader.load(path.c_str(), current_sf);
|
midiLoader.load(path.c_str(), current_sf);
|
||||||
midiLoader.setLooping(true);
|
midiLoader.setLooping(true);
|
||||||
music.play(midiLoader);
|
music.play(midiLoader);
|
||||||
|
@ -385,6 +402,7 @@ bool Render::playModPlug(string path) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
log("Render.cpp", 402, "", "Played mod tracker from " + path);
|
||||||
modLoader.load(path.c_str());
|
modLoader.load(path.c_str());
|
||||||
modLoader.setLooping(true);
|
modLoader.setLooping(true);
|
||||||
music.play(modLoader);
|
music.play(modLoader);
|
||||||
|
@ -413,4 +431,38 @@ void Render::pointTo(SDL_Rect* camera, Object object) {
|
||||||
{
|
{
|
||||||
camera->y = camera->h;
|
camera->y = camera->h;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shoutouts to gedehari for doing this
|
||||||
|
void Render::log(string file, int line, string prefix, string msg, LOG_TYPE type) {
|
||||||
|
clock_t now = std::clock();
|
||||||
|
|
||||||
|
double now_n = (double)now / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
string typeName = "LOG";
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case NORMAL:
|
||||||
|
break;
|
||||||
|
case WARNING:
|
||||||
|
typeName = "WARNING";
|
||||||
|
break;
|
||||||
|
case ERROR_:
|
||||||
|
typeName = "ERROR";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream buf;
|
||||||
|
|
||||||
|
buf << (int)(now_n/60) << ":"
|
||||||
|
<< std::setfill('0') << std::setw(2) << (int)((int)now_n % 60) << "."
|
||||||
|
<< std::setfill('0') << std::setw(3) << (int)((now_n - (int)now_n) * 1000) << " "
|
||||||
|
<< typeName << ": (" << file << ":" << line << ") " << prefix << msg << endl;
|
||||||
|
|
||||||
|
std::ofstream logFile;
|
||||||
|
logFile.open("log.txt", std::ios::app);
|
||||||
|
logFile << buf.str();
|
||||||
|
logFile.close();
|
||||||
|
|
||||||
|
cout << buf.str();
|
||||||
}
|
}
|
|
@ -53,6 +53,12 @@ enum CLOSE_CODES {
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum LOG_TYPE {
|
||||||
|
NORMAL,
|
||||||
|
WARNING,
|
||||||
|
ERROR_
|
||||||
|
};
|
||||||
|
|
||||||
namespace Render {
|
namespace Render {
|
||||||
extern SDL_Window* window;
|
extern SDL_Window* window;
|
||||||
extern SDL_Renderer* renderer;
|
extern SDL_Renderer* renderer;
|
||||||
|
@ -264,6 +270,8 @@ namespace Render {
|
||||||
*/
|
*/
|
||||||
void pointTo(SDL_Rect* camera, Object object);
|
void pointTo(SDL_Rect* camera, Object object);
|
||||||
|
|
||||||
|
void log(string file, int line, string prefix, string msg, LOG_TYPE type = NORMAL);
|
||||||
|
|
||||||
inline int Sec2Tick(float time) {
|
inline int Sec2Tick(float time) {
|
||||||
return FRAMERATE*time;
|
return FRAMERATE*time;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue