Twinklebear / LPCGame

Working on a C++ tile based 'engine' using SDL
MIT License
18 stars 1 forks source link

Logging Feature #18

Open btstevens89 opened 11 years ago

btstevens89 commented 11 years ago

There should be a logging feature added to replace the runtime errors that slow down the program dramatically.

I'm guessing it should be placed at the root of the program in main. Then pass the pointer on and on so any class can access it.

Twinklebear commented 11 years ago

Ah so then instead of throwing an error the issue will simply be logged to a file? This sounds like a good idea, I used to have a pure-static class that would allow you to write some string to file from anywhere in the program but I removed it in favor of debugging through stdout. It'd be good to have it back in for error/debug logging though, so instead of throwing errors you just dump it to a file with a timestamp.

Twinklebear commented 11 years ago

The time stamp in this case could just be the value of SDL_GetTicks() adjusted into HH:MM:SS elapsed since the program started, we wouldn't really need the system time

Twinklebear commented 11 years ago

It should also have a Lua API so that it can be used from Lua scripts as well, by 'require "Logging" ' or whatever the module ends up being named

btstevens89 commented 11 years ago

Yeah, the more flexible the better.

I tried running the program using the 20x20 grid I generated with the editor and I'm running at ~12fps. The original 10x10 grid is giving me ~47fps (which works fine, but doesn't really mean much because it's so small). I'm hoping that by taking out the exceptions we can get the framerate way up.

Nevermind The slowdown is not due to exceptions. I'll look into it separately.

Twinklebear commented 11 years ago

Ya the engine hasn't received any real optimization at all, i don't think exceptions are thrown outside of the "failed to find/parse X" exceptions, but those aren't really critical so they may as well be converted into logging

I'm not sure where the slowdowns are, but I haven't spent much time looking into it. One thing I've heard mentioned around was batching draw calls, but i wasn't sure where to begin with that and moved on to other stuff.

I'll make optimization into it's own issue, separate from this logging one.

Twinklebear commented 11 years ago

I've written a very simple logger that will take a string and print it to debug.log along with the time since the program began. Next work todo will be moving over the various potential cases of errors being thrown to instead simply write to the log.

Perhaps also support for ToString type functions for various classes to enable dumping of object data?

Twinklebear commented 11 years ago

I've migrated all errors but those thrown by Window::Init to be logged instead. The ones thrown by Window::Init are still thrown and will cause the program to quit but will be logged as well. A sample log:

0:0:0 - JsonHandler: Failed to find: ../res/img/introback.json
0:0:1 - Image: No filename specified
0:0:1 - Image: No filename specified
0:0:1 - NPC Init: Debugging test!
0:0:3 - JsonHandler: Failed to find: ../res/img/introback.json

Where time is HH:MM:SS and is the time that the program has been running

Have yet to do the various ToString functions