-/*******************************************************************************
-
- 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 <cstdlib> // atexit, getenv
+#include <functional>
#include <iostream>
#include <string>
#include <unistd.h> // access
#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::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<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
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;
break;
case SDL_QUIT:
- Mf::core.clear();
- break;
+ stop();
+ return true;
}
return false;
// 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";
//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
<< " 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;
}
}
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
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]);
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: *************************************************/
-