X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMain.cc;h=8361b39d3dffe7a5e24eda753650e2722aad6092;hp=bb6b35bc1fd30ecde0c4b3dfb06108a4269c76ef;hb=e0fb747f2e647115d0b8953615c254d25c045345;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/Main.cc b/src/Main.cc index bb6b35b..8361b39 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -9,12 +9,16 @@ * **************************************************************************/ -#include // atexit, getenv +#include "../config.h" + +#include // atexit #include #include #include #include -#include // access + +#include +#include #include #include @@ -26,10 +30,6 @@ #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; } @@ -278,73 +279,110 @@ void goodbye() #include -int main(int argc, char* argv[]) +#include + +class MyAsset { - moof::resolver_task task("4950", "lappy"); - task.run(); +public: + MyAsset(const std::string& path) + { + moof::log_info("MyAsset loading:", path); + + char buffer[1024]; + + std::ifstream stream(path.c_str()); + stream.getline(buffer, sizeof(buffer)); + str = buffer; + stream.close(); - int i = task.wait(); - moof::log_warning("task ended with code:", i); + cool(); + } - std::vector::const_iterator it; - for (it = task.addresses().begin(); it != task.addresses().end(); ++it) + void cool() { - moof::socket::address addr = *it; + moof::log_info("MyAsset COOL:", str); + } - moof::log_info("address:", addr, "(", addr.type(), ")"); + void groovy() + { + moof::log_info("MyAsset GROOVY!!!!", str); } - //ASSERT(5 == 8 && "uh oh that's not right"); - + std::string str; +}; + +typedef moof::resource_handle MyAsset_handle; + +class AnotherAsset +{ +public: + AnotherAsset(const std::string& path, double d = 5.0) + { + moof::log_info("AnotherAsset loading:", path); + dude = d; + } + + + void cool() + { + moof::log_info("AnotherAsset cool", dude); + } - std::vector hi; - for (int a = 0; a < 4000; a++) + void groovy() { - hi.push_back(a); + moof::log_info("AnotherAsset GROOVY!!!!", dude); } - moof::log_info("array size:", hi.size()); - moof::packet packet; - packet << hi; + double dude; +}; + - //for (it = task.addresses().begin(); it != task.addresses().end(); ++it) +int main(int argc, char* argv[]) +{ + moof::resource::register_type("mine"); + + //moof::resource::add_type("k"); + //{ - //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]); - } + //moof::resource_ptr myAsset = moof::resource::load(assetName, + //"prefix", "mine"); - 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"); - //} + //MyAsset_handle aCopy = myAsset; + + //MyAsset_handle copy2 = moof::resource::load(assetName, "asdfas", "mine"); + + ////if (myAsset->check()) myAsset->get()->cool(); + //myAsset->get()->cool(); + ////myAsset->get()->groovy(); + + //aCopy.get()->cool(); + //copy2.get()->cool(); + + //log_info("rsrc ptr:", moof::resource::load(assetName, "", "mine")); //} + //log_info("rsrc ptr:", moof::resource::load(assetName, "", "k")); + //moof::resource::load(assetName, "", "mine")->get()->cool(); + ////if (myAsset) myAsset.get()->cool(); + ////else moof::log_error("asset not obtained..."); + + MyAsset_handle myAsset = moof::resource::load("/home/chaz/meh.mine"); + MyAsset* asset = myAsset.get(); + if (asset) asset->cool(); + else moof::log_warning("no asset obtained!!"); - //return 0; + //moof::timer reloadTimer( + //boost::bind(&moof::resource::reload_as_needed), + //SCALAR(2.0), + //moof::timer::repeat); + for (;;) + { + if (myAsset) myAsset.get()->cool(); + moof::resource::reload_as_needed(); + sleep(1); + } + if (argc > 1) { @@ -375,7 +413,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();