]> Dogcows Code - chaz/yoink/blobdiff - src/Main.cc
sockets documentation and cleanup
[chaz/yoink] / src / Main.cc
index 91a8d080ba04d14df9114e8a112f3ba179e4a63c..051b22c5a4998e71a5ecb61468227f4fafbe3cec 100644 (file)
@@ -10,6 +10,7 @@
 **************************************************************************/
 
 #include <cstdlib>             // atexit, getenv
+#include <functional>
 #include <iostream>
 #include <string>
 #include <unistd.h>            // access
@@ -19,7 +20,6 @@
 #include <Moof/OpenGL.hh>
 #include <Moof/Resource.hh>
 #include <Moof/Settings.hh>
-#include <Moof/Transition.hh>
 #include <Moof/Video.hh>
 
 #include "ErrorHandler.hh"
 #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::contextCreated));
+       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<Mf::Lerp>::Ptr transition =
-               //Mf::Transition<Mf::Lerp>::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
@@ -73,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;
 
@@ -100,8 +92,8 @@ bool Main::handleEvent(const Mf::Event& event)
                        break;
 
                case SDL_QUIT:
-                       Mf::core.clear();
-                       break;
+                       stop();
+                       return true;
        }
 
        return false;
@@ -135,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";
@@ -178,14 +171,6 @@ void Main::setupGL()
        //glMatrixMode(GL_MODELVIEW);
 }
 
-void Main::contextCreated()
-{
-       // 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()
 {
@@ -236,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
@@ -283,8 +275,67 @@ void goodbye()
        std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
 }
 
+
+#include <Moof/Socket.hh>
+
 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<Mf::SocketAddress>::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<uint8_t> 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]);
@@ -305,33 +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 = Mf::Log::INFO;
-       Mf::settings.get("loglevel", logLevel);
+       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;
 }
 
This page took 0.028347 seconds and 4 git commands to generate.