X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMain.cc;h=051b22c5a4998e71a5ecb61468227f4fafbe3cec;hp=2cd0f0c08aaf87f62fe3a2ba99c17684a0309a60;hb=351a86a5275f355b55f3827175a72853995f2aaa;hpb=987971a961454d97082c6448fdc0bbeb540281bb diff --git a/src/Main.cc b/src/Main.cc index 2cd0f0c..051b22c 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1,32 +1,16 @@ -/******************************************************************************* - - Copyright (c) 2009, Charles McGarvey - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*******************************************************************************/ +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ #include // atexit, getenv +#include #include #include #include // access @@ -36,7 +20,6 @@ #include #include #include -#include #include #include "ErrorHandler.hh" @@ -50,35 +33,27 @@ #include "version.h" -Main::Main() +Main::Main(Mf::Settings& settings, Mf::Video& video) : + Mf::View(settings, video) { - mDispatchHandler = Mf::core.addHandler("video.newcontext", - boost::bind(&Main::contextRecreated)); + Mf::Dispatch& dispatch = Mf::Dispatch::global(); + mNewContextDispatch = dispatch.addTarget("video.newcontext", + boost::bind(&Main::setupGL)); setupGL(); } -void Main::addedToCore() -{ - //Mf::Scalar coeff[] = {0.0, 1.0}; - //Mf::Lerp interp(coeff, 0.25); - - //Mf::LayerP gameLayer = GameLayer::alloc(); - //Mf::Transition::Ptr transition = - //Mf::Transition::alloc(gameLayer, Mf::LayerP(), interp); - //core.push(transition); - //core.push(GameLayer::alloc()); - Mf::core.push(TitleLayer::alloc()); -} - void Main::update(Mf::Scalar t, Mf::Scalar dt) { - if (Mf::core.getSize() == 1) + if (children().size() == 0) { - // this is the only layer left on the stack - //Mf::core.push(TitleLayer::alloc()); - Mf::core.clear(); + //Mf::logWarning("main view has no children"); + //stop(); + //return; + addChild(TitleLayer::alloc()); } + + Mf::View::update(t, dt); } void Main::draw(Mf::Scalar alpha) const @@ -90,25 +65,25 @@ void Main::draw(Mf::Scalar alpha) const glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + + Mf::View::draw(alpha); } bool Main::handleEvent(const Mf::Event& event) { + if (Mf::View::handleEvent(event)) return true; + switch (event.type) { case SDL_KEYUP: - if (event.key.keysym.sym == SDLK_ESCAPE) + if (event.key.keysym.sym == SDLK_f) { - Mf::core.clear(); - } - else if (event.key.keysym.sym == SDLK_f) - { - Mf::video->toggleFull(); + video().toggleFull(); } else if (event.key.keysym.sym == SDLK_l) { - Mf::video->toggleCursorGrab(); - Mf::video->toggleCursorVisible(); + video().toggleCursorGrab(); + video().toggleCursorVisible(); } break; @@ -117,8 +92,8 @@ bool Main::handleEvent(const Mf::Event& event) break; case SDL_QUIT: - Mf::core.clear(); - break; + stop(); + return true; } return false; @@ -152,9 +127,10 @@ std::string Main::getConfigPath() // 3. $HOME/.yoinkrc // 4. YOINKRC (environment) - std::string path = Mf::Resource::getPath("yoinkrc"); + std::string path("yoinkrc"); + Mf::Resource::getPath(path); -#if !defined(_WIN32) && !defined(__WIN32__) +#if !defined(_WIN32) path += ":/etc/yoinkrc"; #endif path += ":$HOME/.yoinkrc"; @@ -195,18 +171,11 @@ void Main::setupGL() //glMatrixMode(GL_MODELVIEW); } -void Main::contextRecreated() -{ - // whenever the context is destroyed and a new one created, it probably - // won't contain our state so we need to set that up again - setupGL(); -} - - void Main::printUsage() { - std::cout << "Usage: "PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." + std::cout << "Usage: " + << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." << std::endl << "The alien-smashing action game." << std::endl << std::endl @@ -220,7 +189,7 @@ void Main::printUsage() << " fullscreen=true|false" << std::endl << " if true, uses the entire display" << std::endl << " framerate=num" << std::endl - << " the target number of frames per second" << std::endl + << " number of frames to draw per second" << std::endl << std::endl << "See documentation for more options." << std::endl; } @@ -252,11 +221,18 @@ void Main::printInfo(int argc, char* argv[]) } std::cout << " Executable: " << argv[0] << std::endl +#ifdef YOINK_GITHEAD + << " Commit: "YOINK_GITHEAD << std::endl +#endif << " Version: "VERSION << std::endl << " Built: " << COMPILE_TIME << std::endl << " Compiler: "COMPILER_STRING << std::endl << " Assets: " << assets << std::endl << "Build options: " +#ifndef HAVE_CLOCK_GETTIME + << "-" +#endif + << "clock_gettime " #ifdef NDEBUG << "-" #endif @@ -299,8 +275,67 @@ void goodbye() std::cout << std::endl << "Goodbye..." << std::endl << std::endl; } + +#include + int main(int argc, char* argv[]) { + Mf::ResolverTask task("4950", "compy", SOCK_DGRAM); + task.run(); + + int i = task.wait(); + Mf::logWarning << "task ended with code: " << i << std::endl; + + std::vector::const_iterator it; + for (it = task.addresses().begin(); it != task.addresses().end(); ++it) + { + Mf::SocketAddress addr = *it; + + Mf::logInfo << "address: " << addr.name() << ":" << addr.port() + << " (" << addr.type() << ")" << std::endl; + } + + + std::vector hi; + for (int a = 0; a < 4000; a++) + { + hi.push_back(a); + } + + Mf::logInfo << "array size: " << hi.size() << std::endl; + Mf::Packet packet; + packet << hi; + + Mf::SocketAddress addr("4950", "155.98.111.159", SOCK_DGRAM); + //Mf::SocketAddress addr = Mf::SocketAddress::broadcast("4950"); + //Mf::SocketAddress addr("4950", "155.98.109.255", SOCK_DGRAM); + //Mf::logInfo << "local addr: " << addr.name() << std::endl; + + //for (it = task.addresses().begin(); it != task.addresses().end(); ++it) + //{ + int bcast = 0; + + //Mf::SocketAddress addr = *it; + Mf::Socket sock(addr); + sock.connect(); + + sock.get(SO_BROADCAST, bcast); + Mf::logInfo << "bcast: " << bcast << std::endl; + + sock.set(SO_BROADCAST, 1); + + sock.get(SO_BROADCAST, bcast); + Mf::logInfo << "bcast: " << bcast << std::endl; + + Mf::logInfo << "sending packet of size: " << packet.size() << std::endl; + //sock.write(packet); + sock.write(&bcast, sizeof(bcast)); + //} + + + return 0; + + if (argc > 1) { std::string arg(argv[1]); @@ -321,34 +356,32 @@ int main(int argc, char* argv[]) Mf::Resource::addSearchPaths(Main::getSearchPath()); - Mf::settings.loadFromFiles(Main::getConfigPath()); - Mf::settings.parseArgs(argc, argv); + Mf::Settings settings(argc, argv, Main::getConfigPath()); - Mf::Log::Level logLevel; - if (Mf::settings.get("loglevel", logLevel)) Mf::Log::setLevel(logLevel); + Mf::Log::Level logLevel = Mf::Log::INFO; + settings.get("loglevel", logLevel); + Mf::Log::setLevel(logLevel); try { - Mf::Video video(PACKAGE_STRING, Mf::Resource::getPath(PACKAGE".png")); - MainP app = Main::alloc(); - Mf::core.push(app); - Mf::core.run(); + Mf::Video::Attributes attributes(settings); + attributes.caption = PACKAGE_STRING; + attributes.icon = Mf::Resource::getPath(PACKAGE".png"); + + Mf::Video video(attributes); + Main mainView(settings, video); + + mainView.run(); + return 0; } catch (const Mf::Error& error) { - Mf::ModalDialog dialog; - dialog.title = PACKAGE_STRING; - dialog.text1 = "Unhandled Exception"; - dialog.text2 = getErrorString(error); - dialog.type = Mf::ModalDialog::CRITICAL; - dialog.run(); + Mf::ModalDialog dialog(Mf::ModalDialog::CRITICAL, + PACKAGE_STRING, "Unhandled Exception", + getErrorString(error)); + dialog.run(); return 1; } - - return 0; } - -/** vim: set ts=4 sw=4 tw=80: *************************************************/ -