]>
Dogcows Code - chaz/yoink/blob - src/Main.cc
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"
33 Main::Main(moof::settings
& settings
, moof::video
& video
) :
34 moof::view(settings
, video
)
36 moof::dispatcher
& dispatcher
= moof::dispatcher::global();
37 mNewContextDispatch
= dispatcher
.add_target("video.newcontext",
38 boost::bind(&Main::setupGL
));
43 void Main::update(moof::scalar t
, moof::scalar dt
)
45 if (children().size() == 0)
47 //moof::log_warning("main view has no children");
50 add_child(TitleLayer::alloc());
53 moof::view::update(t
, dt
);
56 void Main::draw(moof::scalar alpha
) const
58 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
60 glMatrixMode(GL_PROJECTION
);
63 glMatrixMode(GL_MODELVIEW
);
66 moof::view::draw(alpha
);
69 bool Main::handle_event(const moof::event
& event
)
71 if (moof::view::handle_event(event
)) return true;
76 if (event
.key
.keysym
.sym
== SDLK_f
)
78 video().toggle_fullscreen();
80 else if (event
.key
.keysym
.sym
== SDLK_l
)
82 video().toggle_cursor_captured();
83 video().toggle_cursor_visible();
88 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
100 std::string
Main::getSearchPath()
102 // Add search paths; they should be searched in this order:
103 // 1. YOINK_DATADIR (environment)
104 // 2. YOINK_DATADIR (configure)
108 char* dataDir
= getenv("YOINK_DATADIR");
114 path
+= YOINK_DATADIR
;
119 std::string
Main::getConfigPath()
121 // Build the list of config files to search for, in this order:
122 // 1. YOINK_DATADIR/yoinkrc
123 // 2. /etc/yoinkrc (not for Windows)
125 // 4. YOINKRC (environment)
127 std::string
path("yoinkrc");
128 moof::resource::find(path
);
131 path
+= ":/etc/yoinkrc";
133 path
+= ":$HOME/.yoinkrc";
135 char* configFile
= getenv("YOINKRC");
148 glEnable(GL_TEXTURE_2D
);
149 glEnable(GL_DEPTH_TEST
);
151 glEnable(GL_LINE_SMOOTH
);
152 glEnable(GL_POLYGON_SMOOTH
);
153 glShadeModel(GL_SMOOTH
);
155 //glEnable(GL_BLEND);
156 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
157 glEnable(GL_ALPHA_TEST
);
158 glAlphaFunc(GL_GREATER
, 0.0);
160 glClearColor(0.0, 0.0, 0.0, 1.0);
162 //glMatrixMode(GL_PROJECTION);
164 //moof::scalar ratio = moof::core.getVideo()->width() /
165 //moof::core.getVideo()->height();
166 //gluPerspective(60.0, ratio, 1.0, 250.0);
168 //glMatrixMode(GL_MODELVIEW);
172 void Main::printUsage()
174 std::cout
<< "Usage: "
175 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
177 << "The alien-smashing action game." << std::endl
179 << "Options:" << std::endl
180 << " -h, --help" << std::endl
181 << " show this help and exit" << std::endl
182 << " -i, --info" << std::endl
183 << " show version and build information" << std::endl
184 << " detail=1|2|3" << std::endl
185 << " the level of detail of game scenes" << std::endl
186 << " fullscreen=true|false" << std::endl
187 << " if true, uses the entire display" << std::endl
188 << " framerate=num" << std::endl
189 << " number of frames to draw per second" << std::endl
191 << "See documentation for more options." << std::endl
;
194 void Main::printInfo(int argc
, char* argv
[])
200 assets
.assign(YOINK_DATADIR
);
201 int accessible
= access(assets
.c_str(), R_OK
);
202 if (accessible
!= 0) assets
+= " (no access)";
204 char* temp
= getenv("YOINK_DATADIR");
208 accessible
= access(temp
, R_OK
);
209 if (accessible
!= 0) datadir
+= " (no access)";
212 temp
= getenv("YOINKRC");
216 accessible
= access(temp
, R_OK
);
217 if (accessible
!= 0) config
+= " (no access)";
220 std::cout
<< " Executable: " << argv
[0] << std::endl
222 << " Commit: "YOINK_GITHEAD
<< std::endl
224 << " Version: "VERSION
<< std::endl
225 << " Built: " << COMPILE_TIME
<< std::endl
226 << " Compiler: "COMPILER_STRING
<< std::endl
227 << " Assets: " << assets
<< std::endl
229 #ifndef HAVE_CLOCK_GETTIME
237 #ifndef USE_DOUBLE_PRECISION
240 << "double-precision "
245 #ifndef USE_HOTLOADING
249 #ifndef PROFILING_ENABLED
260 << "threads" << std::endl
261 << " YOINKRC: " << config
<< std::endl
262 << "YOINK_DATADIR: " << datadir
<< std::endl
;
268 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
269 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
270 << "Send patches and bug reports to <"
271 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
276 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
280 #include <moof/socket.hh>
287 MyAsset(const std::string
& path
)
289 moof::log_info("MyAsset loading:", path
);
293 std::ifstream
stream(path
.c_str());
294 stream
.getline(buffer
, sizeof(buffer
));
303 moof::log_info("MyAsset COOL:", str
);
308 moof::log_info("MyAsset GROOVY!!!!", str
);
314 typedef moof::resource_handle
<MyAsset
> MyAsset_handle
;
319 AnotherAsset(const std::string
& path
, double d
= 5.0)
321 moof::log_info("AnotherAsset loading:", path
);
328 moof::log_info("AnotherAsset cool", dude
);
333 moof::log_info("AnotherAsset GROOVY!!!!", dude
);
340 int main(int argc
, char* argv
[])
342 moof::resource::register_type
<MyAsset
>("mine");
343 //moof::resource::add_type<AnotherAsset>("k");
346 //moof::resource_ptr myAsset = moof::resource::load(assetName,
349 //MyAsset_handle aCopy = myAsset;
351 //MyAsset_handle copy2 = moof::resource::load(assetName, "asdfas", "mine");
353 ////if (myAsset->check<MyAsset>()) myAsset->get<AnotherAsset>()->cool();
354 //myAsset->get<MyAsset>()->cool();
355 ////myAsset->get<AnotherAsset>()->groovy();
357 //aCopy.get()->cool();
358 //copy2.get()->cool();
360 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "mine"));
362 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "k"));
363 //moof::resource::load(assetName, "", "mine")->get<MyAsset>()->cool();
365 ////if (myAsset) myAsset.get()->cool();
366 ////else moof::log_error("asset not obtained...");
368 MyAsset_handle myAsset
= moof::resource::load("/home/chaz/meh.mine");
369 MyAsset
* asset
= myAsset
.get();
370 if (asset
) asset
->cool();
371 else moof::log_warning("no asset obtained!!");
373 moof::timer
reloadTimer(
374 boost::bind(&moof::resource::reload_as_needed
),
376 moof::timer::repeat
);
380 //myAsset.get()->cool();
381 //moof::resource::reload_as_needed();
387 moof::resolver_task
task("4950", "lappy");
391 moof::log_warning("task ended with code:", i
);
393 std::vector
<moof::socket::address
>::const_iterator it
;
394 for (it
= task
.addresses().begin(); it
!= task
.addresses().end(); ++it
)
396 moof::socket::address addr
= *it
;
398 moof::log_info("address:", addr
, "(", addr
.type(), ")");
401 //ASSERT(5 == 8 && "uh oh that's not right");
404 std::vector
<uint8_t> hi
;
405 for (int a
= 0; a
< 4000; a
++)
410 moof::log_info("array size:", hi
.size());
414 //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
416 //moof::socket sock(*it);
417 moof::socket
sock(moof::socket::address::broadcast("4950"));
418 //moof::socket sock("4950", "lappy", SOCK_DGRAM);
419 sock
.set(SO_BROADCAST
, 1);
422 //if (sock.isConnected())
425 pack
<< "hello world";
427 //sock.write(pack, sock.address());
428 moof::log_info("sent", pack
.size(), "bytes");
430 const char* data
= pack
.bytes();
431 for (unsigned i
= 0; i
< pack
.size(); ++i
)
433 moof::log_warning("meh:", data
[i
]);
437 pack
.read(data2
, 13);
438 for (int i
= 0; i
< 13; ++i
)
440 moof::log_warning("meh:", data2
[i
]);
445 //moof::log_error("NOT CONNECTED");
455 std::string
arg(argv
[1]);
456 if (arg
== "-h" || arg
== "--help")
461 else if (arg
== "-i" || arg
== "--info")
463 Main::printInfo(argc
, argv
);
471 moof::resource::add_search_paths(Main::getSearchPath());
473 moof::settings
settings(argc
, argv
, Main::getConfigPath());
475 enum moof::log::level logLevel
= moof::log::info
;
476 settings
.get("loglevel", logLevel
);
477 moof::log::level(logLevel
);
481 std::string
iconPath(PACKAGE
".png");
482 moof::resource::find(iconPath
);
483 moof::image
icon(iconPath
);
486 class moof::video::attributes
attributes(settings
);
487 moof::video
video(PACKAGE_STRING
, attributes
);
488 Main
mainView(settings
, video
);
493 catch (const std::exception
& e
)
495 moof::modal_dialog
dialog(moof::modal_dialog::error
,
496 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.05664 seconds and 4 git commands to generate.