Bunch of logging

This commit is contained in:
Adrian Hedqvist 2017-09-17 22:09:14 +02:00
parent c43a4a01c0
commit cb7f0263d8
3 changed files with 20 additions and 8 deletions

View file

@ -70,6 +70,7 @@ void init() {
hero = nullptr; hero = nullptr;
} }
SDL_Log("Creating tilemap...\n");
tilemap = new Tilemap(32, 32); tilemap = new Tilemap(32, 32);
int y = 0; int y = 0;
int x = 0; int x = 0;
@ -104,19 +105,23 @@ void init() {
} }
x++; x++;
} }
SDL_Log("Done.\n");
SDL_Log("Calculating initial FOV...\n");
hero->CalcFOV(); hero->CalcFOV();
SDL_Log("Done.\n");
} }
void load(Renderer* rend, Input* inp) { void load(Renderer* rend, Input* inp) {
renderer = rend; renderer = rend;
input = inp; input = inp;
ascii = new Tileset(renderer, "assets/12x12.bmp", 192, 192, 12, 12); ascii = new Tileset(renderer, "./assets/12x12.bmp", 192, 192, 12, 12);
//testsprite = renderer->CreateSprite("assets/12x12.bmp", 0, 0, 192, 192); SDL_Log("Created tileset.\n");
input->bindkey(SDLK_r, ACTION_RESET); input->bindkey(SDLK_r, ACTION_RESET);
input->bindkey(SDLK_SPACE, ACTION_PAUSE); input->bindkey(SDLK_SPACE, ACTION_PAUSE);
input->bindkey(SDLK_RETURN, ACTION_STEP); input->bindkey(SDLK_RETURN, ACTION_STEP);
input->bindkey(SDLK_F1, ACTION_TOGGLE_DEBUG); input->bindkey(SDLK_F1, ACTION_TOGGLE_DEBUG);
SDL_Log("Bound keybinds.\n");
init(); init();
} }

View file

@ -42,6 +42,7 @@ int main(int argc, char* argv[]) {
SDL_Quit(); SDL_Quit();
return 1; return 1;
} }
SDL_Log("SDL initialized.\n");
renderer = new Renderer(); renderer = new Renderer();
if (!renderer->Init("Dungeon", windowWidth, windowHeight)) { if (!renderer->Init("Dungeon", windowWidth, windowHeight)) {
@ -126,6 +127,7 @@ int main(int argc, char* argv[]) {
} }
delete renderer; delete renderer;
SDL_Quit(); SDL_Quit();
SDL_Log("Quit.");
return 0; return 0;
} }

View file

@ -30,7 +30,7 @@ GLuint LoadShader(const char* path, GLenum shadertype) {
shaderstream.close(); shaderstream.close();
} }
else { else {
printf("ERROR: Could not open shader file \"%s\".\n", path); SDL_Log("ERROR: Could not open shader file \"%s\".\n", path);
getchar(); getchar();
return 0; return 0;
} }
@ -38,7 +38,7 @@ GLuint LoadShader(const char* path, GLenum shadertype) {
GLint result = GL_FALSE; GLint result = GL_FALSE;
int infologlength; int infologlength;
printf("Compiling shader: %s\n", path); SDL_Log("Compiling shader: %s\n", path);
char const * source = shadersource.c_str(); char const * source = shadersource.c_str();
glShaderSource(shaderId, 1, &source, NULL); glShaderSource(shaderId, 1, &source, NULL);
glCompileShader(shaderId); glCompileShader(shaderId);
@ -48,13 +48,14 @@ GLuint LoadShader(const char* path, GLenum shadertype) {
if (infologlength > 0) { if (infologlength > 0) {
std::vector<char> errorlog(infologlength + 1); std::vector<char> errorlog(infologlength + 1);
glGetShaderInfoLog(shaderId, infologlength, NULL, &errorlog[0]); glGetShaderInfoLog(shaderId, infologlength, NULL, &errorlog[0]);
printf("Errors in \"%s\":\n%s\n", path, &errorlog[0]); SDL_Log("Errors in \"%s\":\n%s\n", path, &errorlog[0]);
} }
SDL_Log("Done.");
return shaderId; return shaderId;
} }
GLuint CreateShaderProgram(GLuint vertshader, GLuint fragshader) { GLuint CreateShaderProgram(GLuint vertshader, GLuint fragshader) {
printf("Linking shader program...\n"); SDL_Log("Linking shader program...\n");
GLuint programId = glCreateProgram(); GLuint programId = glCreateProgram();
glAttachShader(programId, vertshader); glAttachShader(programId, vertshader);
glAttachShader(programId, fragshader); glAttachShader(programId, fragshader);
@ -68,12 +69,12 @@ GLuint CreateShaderProgram(GLuint vertshader, GLuint fragshader) {
if (infologlength > 0) { if (infologlength > 0) {
std::vector<char> errorlog(infologlength + 1); std::vector<char> errorlog(infologlength + 1);
glGetShaderInfoLog(programId, infologlength, NULL, &errorlog[0]); glGetShaderInfoLog(programId, infologlength, NULL, &errorlog[0]);
printf("Errors when creating shader program:\n%s\n", &errorlog[0]); SDL_Log("Errors when creating shader program:\n%s\n", &errorlog[0]);
} }
glDetachShader(programId, vertshader); glDetachShader(programId, vertshader);
glDetachShader(programId, fragshader); glDetachShader(programId, fragshader);
SDL_Log("Done.");
return programId; return programId;
} }
@ -98,6 +99,7 @@ Renderer::~Renderer() {
SDL_GL_DeleteContext(context); SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = nullptr; window = nullptr;
SDL_Log("Renderer destroyed.");
} }
GLuint shaderProg; GLuint shaderProg;
@ -162,6 +164,7 @@ bool Renderer::Init(std::string title, int width, int height) {
SetWindowSize(width, height); SetWindowSize(width, height);
SDL_Log("Renderer initialized.\n");
return true; return true;
} }
@ -190,6 +193,7 @@ void Renderer::SetWindowSize(int width, int height) {
glm::mat4 view = glm::scale(glm::vec3(widthmult, heightmult, 1)) * glm::translate(glm::vec3(-windowwidth / 2, -windowheight / 2, 0)) * glm::mat4(1); glm::mat4 view = glm::scale(glm::vec3(widthmult, heightmult, 1)) * glm::translate(glm::vec3(-windowwidth / 2, -windowheight / 2, 0)) * glm::mat4(1);
screenVPmat = projection * view; screenVPmat = projection * view;
SDL_Log("Window size set to %dx%d.\n", width, height);
} }
void Renderer::SetClearColor(float r, float g, float b, float a) { void Renderer::SetClearColor(float r, float g, float b, float a) {
@ -257,6 +261,7 @@ Texture * Renderer::LoadTexture(std::string path) {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
textures.insert(std::pair<std::string, Texture>(path, t)); textures.insert(std::pair<std::string, Texture>(path, t));
SDL_Log("Loaded texture \"%s\"\n", path.c_str());
return &textures[path]; return &textures[path];
} }
else { else {