X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMain.cc;h=13681ee0625fa74d578fd1dcdb24f49db5e5129e;hp=ae183ec49ab845ee9f5921f8b47642e6445526be;hb=6f1b787a10d8ab1a3117a4b8c004dd2d90599608;hpb=c143f7e806766a73cd69dc6e084e977641019ce6 diff --git a/src/Main.cc b/src/Main.cc index ae183ec..13681ee 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -17,6 +17,12 @@ #include #include +#if !defined(__WIN32) +#include +#else +int isatty(int dummy) { return 0; } +#endif + #include #include @@ -25,6 +31,7 @@ #include #include #include +#include #include #include "GameLayer.hh" @@ -37,9 +44,15 @@ Main::Main(moof::settings& settings, moof::video& video) : moof::view(settings, video) { moof::dispatcher& dispatcher = moof::dispatcher::global(); - mNewContextDispatch = dispatcher.add_target("video.newcontext", - boost::bind(&Main::setupGL)); - setupGL(); + video_reloaded_ = dispatcher.add_target("video.newcontext", + boost::bind(&Main::setup_opengl)); + setup_opengl(); + +#if USE_HOTLOADING + hotload_timer_.init(boost::bind(&moof::resource::reload_as_needed), + SCALAR(0.25), + moof::timer::repeat); +#endif } @@ -100,7 +113,7 @@ bool Main::handle_event(const moof::event& event) } -std::string Main::getSearchPath() +std::string Main::search_paths() { // Add search paths; they should be searched in this order: // 1. YOINK_DATADIR (environment) @@ -118,7 +131,7 @@ std::string Main::getSearchPath() return path; } -std::string Main::getConfigPath() +std::string Main::config_paths() { // Build the list of config files to search for, in this order: // 1. YOINK_DATADIR/yoinkrc @@ -144,17 +157,19 @@ std::string Main::getConfigPath() } -void Main::setupGL() +void Main::setup_opengl() { glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); + //glEnable(GL_CULL_FACE); - glEnable(GL_LINE_SMOOTH); - glEnable(GL_POLYGON_SMOOTH); + //glEnable(GL_POINT_SMOOTH); + //glEnable(GL_LINE_SMOOTH); + //glEnable(GL_POLYGON_SMOOTH); glShadeModel(GL_SMOOTH); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + //glEnable(GL_BLEND); + //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0); @@ -163,21 +178,21 @@ void Main::setupGL() //glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - float light[] = {1.0f, 1.0f, 1.0f, 1.0f}; - glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, light); + glEnable(GL_COLOR_MATERIAL); + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + float amb[] = {0.1f, 0.1f, 0.1f, 1.0f}; + float dif[] = {0.6f, 0.6f, 0.6f, 1.0f}; + //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light); + glLightfv(GL_LIGHT0, GL_AMBIENT, amb); + glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); - //glMatrixMode(GL_PROJECTION); - //glLoadIdentity(); - //moof::scalar ratio = moof::core.getVideo()->width() / - //moof::core.getVideo()->height(); - //gluPerspective(60.0, ratio, 1.0, 250.0); - - //glMatrixMode(GL_MODELVIEW); + float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; + glLightfv(GL_LIGHT0, GL_SPECULAR, spec); } -void Main::printUsage() +void Main::print_usage() { std::cout << "Usage: " << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." @@ -199,18 +214,33 @@ void Main::printUsage() << "See documentation for more options." << std::endl; } -void Main::printInfo(int argc, char* argv[]) + +void Main::print_info(int argc, char* argv[]) { + bool color = (isatty(1) == 1); + stlplus::env_vector environment; std::string assets; assets.assign(YOINK_DATADIR); - if (!stlplus::file_readable(assets)) assets += " (no access)"; + if (!stlplus::file_readable(assets)) + { + assets += " "; + if (color) assets += "\033[1;91m"; + assets += "(no access)"; + if (color) assets += "\033[0m"; + } std::string datadir = environment["YOINK_DATADIR"]; if (!datadir.empty()) { - if (!stlplus::folder_readable(datadir)) datadir += " (no access)"; + if (!stlplus::folder_readable(datadir)) + { + datadir += " "; + if (color) datadir += "\033[1;91m"; + datadir += "(no access)"; + if (color) datadir += "\033[0m"; + } } std::string rc_file = environment["YOINKRC"]; @@ -227,55 +257,75 @@ void Main::printInfo(int argc, char* argv[]) << " Built: " << COMPILE_TIME << std::endl << " Compiler: " << COMPILER_STRING << std::endl << " Assets: " << assets << std::endl - << "Build options: " -#if !USE_CLOCK_GETTIME - << "-" -#endif - << "clock_gettime " -#if !DEBUG - << "-" + << "Build options: "; + +#if USE_CLOCK_GETTIME + print_option("clock_gettime", true); +#else + print_option("clock_gettime", false); #endif - << "debug " -#if !USE_DOUBLE_PRECISION - << "-" +#if DEBUG + print_option("debug", true); +#else + print_option("debug", false); #endif - << "double-precision " -#if !USE_GTK - << "-" +#if USE_GTK + print_option("gtk", true); +#else + print_option("gtk", false); #endif - << "gtk " -#if !USE_HOTLOADING - << "-" +#if USE_HOTLOADING + print_option("hotload", true); +#else + print_option("hotload", false); #endif - << "hotloading " -#if !PROFILING_ENABLED - << "-" +#if PROFILING_ENABLED + print_option("profile", true); +#else + print_option("profile", false); #endif - << "profile " -#if !USE_QT4 - << "-" +#if USE_QT4 + print_option("qt4", true); +#else + print_option("qt4", false); #endif - << "qt4 " -#if !USE_THREADS - << "-" +#if USE_THREADS + print_option("threads", true); +#else + print_option("threads", false); #endif - << "threads" << std::endl - << " YOINKRC: " << rc_file << std::endl + std::cout << std::endl; + std::cout << " YOINKRC: " << rc_file << std::endl << "YOINK_DATADIR: " << datadir << std::endl; } +void Main::print_option(const std::string& option, bool enabled) +{ + if (isatty(1) == 1) + { + if (enabled) std::cout << "\033[1;94m"; + else std::cout << "\033[1m"; + } + if (!enabled) std::cout << "-"; + std::cout << option; + if (isatty(1) == 1) std::cout << "\033[0m"; + std::cout << " "; +} + void hello() { + if (isatty(1) == 1) std::cout << "\033[94m"; std::cout << std::endl << PACKAGE_STRING << std::endl << "Compiled " << __TIME__ " " __DATE__ << std::endl << "Send patches and bug reports to <" - PACKAGE_BUGREPORT << ">." << std::endl << std::endl; + PACKAGE_BUGREPORT << ">." << std::endl << moof::log::endl; } void goodbye() { - std::cout << std::endl << "Goodbye..." << std::endl << std::endl; + if (isatty(1) == 1) std::cout << "\033[94m"; + std::cout << std::endl << "Goodbye." << std::endl << moof::log::endl; } @@ -283,22 +333,17 @@ int main(int argc, char* argv[]) { moof::backend backend; - // FIXME: This is temporary. - moof::timer reloadTimer(boost::bind(&moof::resource::reload_as_needed), - SCALAR(2.0), - moof::timer::repeat); - if (argc > 1) { std::string arg(argv[1]); if (arg == "-h" || arg == "--help") { - Main::printUsage(); + Main::print_usage(); return 0; } else if (arg == "-i" || arg == "--info") { - Main::printInfo(argc, argv); + Main::print_info(argc, argv); return 0; } } @@ -306,9 +351,9 @@ int main(int argc, char* argv[]) hello(); atexit(goodbye); - moof::resource::add_search_paths(Main::getSearchPath()); + moof::resource::set_search_paths(Main::search_paths()); - moof::settings settings(argc, argv, Main::getConfigPath()); + moof::settings settings(argc, argv, Main::config_paths()); enum moof::log::level logLevel = moof::log::info; settings.get("loglevel", logLevel); @@ -335,11 +380,18 @@ int main(int argc, char* argv[]) catch (const std::exception& e) { moof::modal_dialog dialog(moof::modal_dialog::error, - PACKAGE_STRING, "Unhandled Exception", + PACKAGE_STRING, "unhandled exception", e.what()); - dialog.run(); - return 1; } + catch (const char* e) + { + moof::modal_dialog dialog(moof::modal_dialog::error, + PACKAGE_STRING, "unhandled exception", + e); + dialog.run(); + } + + return 1; }