]> Dogcows Code - chaz/yoink/blobdiff - src/Main.cc
begin cleaning up resource management
[chaz/yoink] / src / Main.cc
index bb6b35bc1fd30ecde0c4b3dfb06108a4269c76ef..6cdadaf23ff4e8087845e697ea2120233a906bbc 100644 (file)
@@ -9,12 +9,16 @@
 *
 **************************************************************************/
 
-#include <cstdlib>             // atexit, getenv
+#include "../config.h"
+
+#include <cstdlib>             // atexit
 #include <exception>
 #include <functional>
 #include <iostream>
 #include <string>
-#include <unistd.h>            // access
+
+#include <stlplus/portability/file_system.hpp>
+#include <stlplus/portability/subprocesses.hpp>
 
 #include <moof/log.hh>
 #include <moof/modal_dialog.hh>
 #include "GameLayer.hh"
 #include "Main.hh"
 #include "TitleLayer.hh"
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
 #include "version.h"
 
 
@@ -106,12 +106,13 @@ std::string Main::getSearchPath()
        // 1. YOINK_DATADIR (environment)
        // 2. YOINK_DATADIR (configure)
        
-       std::string path;
+       std::string                     path;
+       stlplus::env_vector     environment;
 
-       char* dataDir = getenv("YOINK_DATADIR");
-       if (dataDir)
+       std::string datadir = environment["YOINK_DATADIR"];
+       if (!datadir.empty())
        {
-               path += dataDir;
+               path += datadir;
                path += ":";
        }
        path += YOINK_DATADIR;
@@ -128,18 +129,20 @@ std::string Main::getConfigPath()
        // 4. YOINKRC (environment)
 
        std::string path("yoinkrc");
-       moof::resource::find_path(path);
+       moof::resource::find(path);
+
+       stlplus::env_vector environment;
 
 #if !defined(_WIN32)
        path += ":/etc/yoinkrc";
 #endif
        path += ":$HOME/.yoinkrc";
 
-       char* configFile = getenv("YOINKRC");
-       if (configFile)
+       std::string rc_file = environment["YOINKRC"];
+       if (!rc_file.empty())
        {
                path += ":";
-               path += configFile;
+               path += rc_file;
        }
 
        return path;
@@ -196,28 +199,22 @@ void Main::printUsage()
 
 void Main::printInfo(int argc, char* argv[])
 {
-       std::string assets;
-       std::string datadir;
-       std::string config;
+       stlplus::env_vector environment;
 
+       std::string assets;
        assets.assign(YOINK_DATADIR);
-       int accessible = access(assets.c_str(), R_OK);
-       if (accessible != 0) assets += " (no access)";
+       if (!stlplus::file_readable(assets)) assets += " (no access)";
 
-       char* temp = getenv("YOINK_DATADIR");
-       if (temp)
+       std::string datadir = environment["YOINK_DATADIR"];
+       if (!datadir.empty())
        {
-               datadir = temp;
-               accessible = access(temp, R_OK);
-               if (accessible != 0) datadir += " (no access)";
+               if (!stlplus::folder_readable(datadir)) datadir += " (no access)";
        }
 
-       temp = getenv("YOINKRC");
-       if (temp)
+       std::string rc_file = environment["YOINKRC"];
+       if (!rc_file.empty())
        {
-               config = temp;
-               accessible = access(temp, R_OK);
-               if (accessible != 0) config += " (no access)";
+               if (!stlplus::file_readable(rc_file)) rc_file += " (no access)";
        }
 
        std::cout << "   Executable: " << argv[0] << std::endl
@@ -245,6 +242,10 @@ void Main::printInfo(int argc, char* argv[])
                          << "-"
 #endif
                          << "gtk "
+#ifndef USE_HOTLOADING
+                         << "-"
+#endif
+                         << "hotloading "
 #ifndef PROFILING_ENABLED
                          << "-"
 #endif
@@ -257,7 +258,7 @@ void Main::printInfo(int argc, char* argv[])
                          << "-"
 #endif
                          << "threads" << std::endl
-                         << "      YOINKRC: " << config << std::endl
+                         << "      YOINKRC: " << rc_file << std::endl
                          << "YOINK_DATADIR: " << datadir << std::endl;
 }
 
@@ -276,75 +277,11 @@ void goodbye()
 }
 
 
-#include <moof/socket.hh>
-
 int main(int argc, char* argv[])
 {
-       moof::resolver_task task("4950", "lappy");
-       task.run();
-
-       int i = task.wait();
-       moof::log_warning("task ended with code:", i);
-
-       std::vector<moof::socket::address>::const_iterator it;
-       for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
-       {
-               moof::socket::address addr = *it;
-
-               moof::log_info("address:", addr, "(", addr.type(), ")");
-       }
-
-       //ASSERT(5 == 8 && "uh oh that's not right");
-       
-
-       std::vector<uint8_t> hi;
-       for (int a = 0; a < 4000; a++)
-       {
-               hi.push_back(a);
-       }
-
-       moof::log_info("array size:", hi.size());
-       moof::packet packet;
-       packet << hi;
-
-       //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
-       //{
-               //moof::socket sock(*it);
-               moof::socket sock(moof::socket::address::broadcast("4950"));
-               //moof::socket sock("4950", "lappy", SOCK_DGRAM);
-               sock.set(SO_BROADCAST, 1);
-               sock.connect();
-
-               //if (sock.isConnected())
-               //{
-                       moof::packet pack;
-                       pack << "hello world";
-                       sock.write(pack);
-                       //sock.write(pack, sock.address());
-                       moof::log_info("sent", pack.size(), "bytes");
-
-                       const char* data = pack.bytes();
-                       for (unsigned i = 0; i < pack.size(); ++i)
-                       {
-                               moof::log_warning("meh:", data[i]);
-                       }
-
-                       char data2[56];
-                       pack.read(data2, 13);
-                       for (int i = 0; i < 13; ++i)
-                       {
-                               moof::log_warning("meh:", data2[i]);
-                       }
-               //}
-               //else
-               //{
-                       //moof::log_error("NOT CONNECTED");
-               //}
-       //}
-
-
-       //return 0;
-
+       moof::timer reloadTimer(boost::bind(&moof::resource::reload_as_needed),
+                                                       SCALAR(2.0),
+                                                       moof::timer::repeat);
 
        if (argc > 1)
        {
@@ -375,7 +312,7 @@ int main(int argc, char* argv[])
        try
        {
                std::string iconPath(PACKAGE".png");
-               moof::resource::find_path(iconPath);
+               moof::resource::find(iconPath);
                moof::image icon(iconPath);
                icon.set_as_icon();
 
This page took 0.022179 seconds and 4 git commands to generate.