]>
Dogcows Code - chaz/yoink/blob - src/Main.cc
bb6b35bc1fd30ecde0c4b3dfb06108a4269c76ef
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #include <cstdlib> // atexit, getenv
17 #include <unistd.h> // access
19 #include <moof/log.hh>
20 #include <moof/modal_dialog.hh>
21 #include <moof/opengl.hh>
22 #include <moof/resource.hh>
23 #include <moof/settings.hh>
24 #include <moof/video.hh>
26 #include "GameLayer.hh"
28 #include "TitleLayer.hh"
36 Main::Main(moof::settings
& settings
, moof::video
& video
) :
37 moof::view(settings
, video
)
39 moof::dispatcher
& dispatcher
= moof::dispatcher::global();
40 mNewContextDispatch
= dispatcher
.add_target("video.newcontext",
41 boost::bind(&Main::setupGL
));
46 void Main::update(moof::scalar t
, moof::scalar dt
)
48 if (children().size() == 0)
50 //moof::log_warning("main view has no children");
53 add_child(TitleLayer::alloc());
56 moof::view::update(t
, dt
);
59 void Main::draw(moof::scalar alpha
) const
61 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
63 glMatrixMode(GL_PROJECTION
);
66 glMatrixMode(GL_MODELVIEW
);
69 moof::view::draw(alpha
);
72 bool Main::handle_event(const moof::event
& event
)
74 if (moof::view::handle_event(event
)) return true;
79 if (event
.key
.keysym
.sym
== SDLK_f
)
81 video().toggle_fullscreen();
83 else if (event
.key
.keysym
.sym
== SDLK_l
)
85 video().toggle_cursor_captured();
86 video().toggle_cursor_visible();
91 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
103 std::string
Main::getSearchPath()
105 // Add search paths; they should be searched in this order:
106 // 1. YOINK_DATADIR (environment)
107 // 2. YOINK_DATADIR (configure)
111 char* dataDir
= getenv("YOINK_DATADIR");
117 path
+= YOINK_DATADIR
;
122 std::string
Main::getConfigPath()
124 // Build the list of config files to search for, in this order:
125 // 1. YOINK_DATADIR/yoinkrc
126 // 2. /etc/yoinkrc (not for Windows)
128 // 4. YOINKRC (environment)
130 std::string
path("yoinkrc");
131 moof::resource::find_path(path
);
134 path
+= ":/etc/yoinkrc";
136 path
+= ":$HOME/.yoinkrc";
138 char* configFile
= getenv("YOINKRC");
151 glEnable(GL_TEXTURE_2D
);
152 glEnable(GL_DEPTH_TEST
);
154 glEnable(GL_LINE_SMOOTH
);
155 glEnable(GL_POLYGON_SMOOTH
);
156 glShadeModel(GL_SMOOTH
);
158 //glEnable(GL_BLEND);
159 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
160 glEnable(GL_ALPHA_TEST
);
161 glAlphaFunc(GL_GREATER
, 0.0);
163 glClearColor(0.0, 0.0, 0.0, 1.0);
165 //glMatrixMode(GL_PROJECTION);
167 //moof::scalar ratio = moof::core.getVideo()->width() /
168 //moof::core.getVideo()->height();
169 //gluPerspective(60.0, ratio, 1.0, 250.0);
171 //glMatrixMode(GL_MODELVIEW);
175 void Main::printUsage()
177 std::cout
<< "Usage: "
178 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
180 << "The alien-smashing action game." << std::endl
182 << "Options:" << std::endl
183 << " -h, --help" << std::endl
184 << " show this help and exit" << std::endl
185 << " -i, --info" << std::endl
186 << " show version and build information" << std::endl
187 << " detail=1|2|3" << std::endl
188 << " the level of detail of game scenes" << std::endl
189 << " fullscreen=true|false" << std::endl
190 << " if true, uses the entire display" << std::endl
191 << " framerate=num" << std::endl
192 << " number of frames to draw per second" << std::endl
194 << "See documentation for more options." << std::endl
;
197 void Main::printInfo(int argc
, char* argv
[])
203 assets
.assign(YOINK_DATADIR
);
204 int accessible
= access(assets
.c_str(), R_OK
);
205 if (accessible
!= 0) assets
+= " (no access)";
207 char* temp
= getenv("YOINK_DATADIR");
211 accessible
= access(temp
, R_OK
);
212 if (accessible
!= 0) datadir
+= " (no access)";
215 temp
= getenv("YOINKRC");
219 accessible
= access(temp
, R_OK
);
220 if (accessible
!= 0) config
+= " (no access)";
223 std::cout
<< " Executable: " << argv
[0] << std::endl
225 << " Commit: "YOINK_GITHEAD
<< std::endl
227 << " Version: "VERSION
<< std::endl
228 << " Built: " << COMPILE_TIME
<< std::endl
229 << " Compiler: "COMPILER_STRING
<< std::endl
230 << " Assets: " << assets
<< std::endl
232 #ifndef HAVE_CLOCK_GETTIME
240 #ifndef USE_DOUBLE_PRECISION
243 << "double-precision "
248 #ifndef PROFILING_ENABLED
259 << "threads" << std::endl
260 << " YOINKRC: " << config
<< std::endl
261 << "YOINK_DATADIR: " << datadir
<< std::endl
;
267 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
268 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
269 << "Send patches and bug reports to <"
270 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
275 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
279 #include <moof/socket.hh>
281 int main(int argc
, char* argv
[])
283 moof::resolver_task
task("4950", "lappy");
287 moof::log_warning("task ended with code:", i
);
289 std::vector
<moof::socket::address
>::const_iterator it
;
290 for (it
= task
.addresses().begin(); it
!= task
.addresses().end(); ++it
)
292 moof::socket::address addr
= *it
;
294 moof::log_info("address:", addr
, "(", addr
.type(), ")");
297 //ASSERT(5 == 8 && "uh oh that's not right");
300 std::vector
<uint8_t> hi
;
301 for (int a
= 0; a
< 4000; a
++)
306 moof::log_info("array size:", hi
.size());
310 //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
312 //moof::socket sock(*it);
313 moof::socket
sock(moof::socket::address::broadcast("4950"));
314 //moof::socket sock("4950", "lappy", SOCK_DGRAM);
315 sock
.set(SO_BROADCAST
, 1);
318 //if (sock.isConnected())
321 pack
<< "hello world";
323 //sock.write(pack, sock.address());
324 moof::log_info("sent", pack
.size(), "bytes");
326 const char* data
= pack
.bytes();
327 for (unsigned i
= 0; i
< pack
.size(); ++i
)
329 moof::log_warning("meh:", data
[i
]);
333 pack
.read(data2
, 13);
334 for (int i
= 0; i
< 13; ++i
)
336 moof::log_warning("meh:", data2
[i
]);
341 //moof::log_error("NOT CONNECTED");
351 std::string
arg(argv
[1]);
352 if (arg
== "-h" || arg
== "--help")
357 else if (arg
== "-i" || arg
== "--info")
359 Main::printInfo(argc
, argv
);
367 moof::resource::add_search_paths(Main::getSearchPath());
369 moof::settings
settings(argc
, argv
, Main::getConfigPath());
371 enum moof::log::level logLevel
= moof::log::info
;
372 settings
.get("loglevel", logLevel
);
373 moof::log::level(logLevel
);
377 std::string
iconPath(PACKAGE
".png");
378 moof::resource::find_path(iconPath
);
379 moof::image
icon(iconPath
);
382 class moof::video::attributes
attributes(settings
);
383 moof::video
video(PACKAGE_STRING
, attributes
);
384 Main
mainView(settings
, video
);
389 catch (const std::exception
& e
)
391 moof::modal_dialog
dialog(moof::modal_dialog::error
,
392 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.046319 seconds and 4 git commands to generate.