]>
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 "../config.h"
14 #include <cstdlib> // atexit, getenv
19 #include <unistd.h> // access
21 #include <moof/log.hh>
22 #include <moof/modal_dialog.hh>
23 #include <moof/opengl.hh>
24 #include <moof/resource.hh>
25 #include <moof/settings.hh>
26 #include <moof/video.hh>
28 #include "GameLayer.hh"
30 #include "TitleLayer.hh"
34 Main::Main(moof::settings
& settings
, moof::video
& video
) :
35 moof::view(settings
, video
)
37 moof::dispatcher
& dispatcher
= moof::dispatcher::global();
38 mNewContextDispatch
= dispatcher
.add_target("video.newcontext",
39 boost::bind(&Main::setupGL
));
44 void Main::update(moof::scalar t
, moof::scalar dt
)
46 if (children().size() == 0)
48 //moof::log_warning("main view has no children");
51 add_child(TitleLayer::alloc());
54 moof::view::update(t
, dt
);
57 void Main::draw(moof::scalar alpha
) const
59 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
61 glMatrixMode(GL_PROJECTION
);
64 glMatrixMode(GL_MODELVIEW
);
67 moof::view::draw(alpha
);
70 bool Main::handle_event(const moof::event
& event
)
72 if (moof::view::handle_event(event
)) return true;
77 if (event
.key
.keysym
.sym
== SDLK_f
)
79 video().toggle_fullscreen();
81 else if (event
.key
.keysym
.sym
== SDLK_l
)
83 video().toggle_cursor_captured();
84 video().toggle_cursor_visible();
89 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
101 std::string
Main::getSearchPath()
103 // Add search paths; they should be searched in this order:
104 // 1. YOINK_DATADIR (environment)
105 // 2. YOINK_DATADIR (configure)
109 char* dataDir
= getenv("YOINK_DATADIR");
115 path
+= YOINK_DATADIR
;
120 std::string
Main::getConfigPath()
122 // Build the list of config files to search for, in this order:
123 // 1. YOINK_DATADIR/yoinkrc
124 // 2. /etc/yoinkrc (not for Windows)
126 // 4. YOINKRC (environment)
128 std::string
path("yoinkrc");
129 moof::resource::find(path
);
132 path
+= ":/etc/yoinkrc";
134 path
+= ":$HOME/.yoinkrc";
136 char* configFile
= getenv("YOINKRC");
149 glEnable(GL_TEXTURE_2D
);
150 glEnable(GL_DEPTH_TEST
);
152 glEnable(GL_LINE_SMOOTH
);
153 glEnable(GL_POLYGON_SMOOTH
);
154 glShadeModel(GL_SMOOTH
);
156 //glEnable(GL_BLEND);
157 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
158 glEnable(GL_ALPHA_TEST
);
159 glAlphaFunc(GL_GREATER
, 0.0);
161 glClearColor(0.0, 0.0, 0.0, 1.0);
163 //glMatrixMode(GL_PROJECTION);
165 //moof::scalar ratio = moof::core.getVideo()->width() /
166 //moof::core.getVideo()->height();
167 //gluPerspective(60.0, ratio, 1.0, 250.0);
169 //glMatrixMode(GL_MODELVIEW);
173 void Main::printUsage()
175 std::cout
<< "Usage: "
176 << PACKAGE
" [-h|--help] [-i|--info] [OPTION=VALUE]..."
178 << "The alien-smashing action game." << std::endl
180 << "Options:" << std::endl
181 << " -h, --help" << std::endl
182 << " show this help and exit" << std::endl
183 << " -i, --info" << std::endl
184 << " show version and build information" << std::endl
185 << " detail=1|2|3" << std::endl
186 << " the level of detail of game scenes" << std::endl
187 << " fullscreen=true|false" << std::endl
188 << " if true, uses the entire display" << std::endl
189 << " framerate=num" << std::endl
190 << " number of frames to draw per second" << std::endl
192 << "See documentation for more options." << std::endl
;
195 void Main::printInfo(int argc
, char* argv
[])
201 assets
.assign(YOINK_DATADIR
);
202 int accessible
= access(assets
.c_str(), R_OK
);
203 if (accessible
!= 0) assets
+= " (no access)";
205 char* temp
= getenv("YOINK_DATADIR");
209 accessible
= access(temp
, R_OK
);
210 if (accessible
!= 0) datadir
+= " (no access)";
213 temp
= getenv("YOINKRC");
217 accessible
= access(temp
, R_OK
);
218 if (accessible
!= 0) config
+= " (no access)";
221 std::cout
<< " Executable: " << argv
[0] << std::endl
223 << " Commit: "YOINK_GITHEAD
<< std::endl
225 << " Version: "VERSION
<< std::endl
226 << " Built: " << COMPILE_TIME
<< std::endl
227 << " Compiler: "COMPILER_STRING
<< std::endl
228 << " Assets: " << assets
<< std::endl
230 #ifndef HAVE_CLOCK_GETTIME
238 #ifndef USE_DOUBLE_PRECISION
241 << "double-precision "
246 #ifndef USE_HOTLOADING
250 #ifndef PROFILING_ENABLED
261 << "threads" << std::endl
262 << " YOINKRC: " << config
<< std::endl
263 << "YOINK_DATADIR: " << datadir
<< std::endl
;
269 std::cout
<< std::endl
<< PACKAGE_STRING
<< std::endl
270 << "Compiled " << __TIME__
" " __DATE__
<< std::endl
271 << "Send patches and bug reports to <"
272 PACKAGE_BUGREPORT
<< ">." << std::endl
<< std::endl
;
277 std::cout
<< std::endl
<< "Goodbye..." << std::endl
<< std::endl
;
281 #include <moof/socket.hh>
288 MyAsset(const std::string
& path
)
290 moof::log_info("MyAsset loading:", path
);
294 std::ifstream
stream(path
.c_str());
295 stream
.getline(buffer
, sizeof(buffer
));
304 moof::log_info("MyAsset COOL:", str
);
309 moof::log_info("MyAsset GROOVY!!!!", str
);
315 typedef moof::resource_handle
<MyAsset
> MyAsset_handle
;
320 AnotherAsset(const std::string
& path
, double d
= 5.0)
322 moof::log_info("AnotherAsset loading:", path
);
329 moof::log_info("AnotherAsset cool", dude
);
334 moof::log_info("AnotherAsset GROOVY!!!!", dude
);
341 int main(int argc
, char* argv
[])
343 moof::resource::register_type
<MyAsset
>("mine");
345 //moof::resource::add_type<AnotherAsset>("k");
348 //moof::resource_ptr myAsset = moof::resource::load(assetName,
351 //MyAsset_handle aCopy = myAsset;
353 //MyAsset_handle copy2 = moof::resource::load(assetName, "asdfas", "mine");
355 ////if (myAsset->check<MyAsset>()) myAsset->get<AnotherAsset>()->cool();
356 //myAsset->get<MyAsset>()->cool();
357 ////myAsset->get<AnotherAsset>()->groovy();
359 //aCopy.get()->cool();
360 //copy2.get()->cool();
362 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "mine"));
364 //log_info("rsrc ptr:", moof::resource::load(assetName, "", "k"));
365 //moof::resource::load(assetName, "", "mine")->get<MyAsset>()->cool();
367 ////if (myAsset) myAsset.get()->cool();
368 ////else moof::log_error("asset not obtained...");
370 MyAsset_handle myAsset
= moof::resource::load("/home/chaz/meh.mine");
371 MyAsset
* asset
= myAsset
.get();
372 if (asset
) asset
->cool();
373 else moof::log_warning("no asset obtained!!");
375 moof::timer
reloadTimer(
376 boost::bind(&moof::resource::reload_as_needed
),
378 moof::timer::repeat
);
382 //myAsset.get()->cool();
383 //moof::resource::reload_as_needed();
389 moof::resolver_task
task("4950", "lappy");
393 moof::log_warning("task ended with code:", i
);
395 std::vector
<moof::socket::address
>::const_iterator it
;
396 for (it
= task
.addresses().begin(); it
!= task
.addresses().end(); ++it
)
398 moof::socket::address addr
= *it
;
400 moof::log_info("address:", addr
, "(", addr
.type(), ")");
403 //ASSERT(5 == 8 && "uh oh that's not right");
406 std::vector
<uint8_t> hi
;
407 for (int a
= 0; a
< 4000; a
++)
412 moof::log_info("array size:", hi
.size());
416 //for (it = task.addresses().begin(); it != task.addresses().end(); ++it)
418 //moof::socket sock(*it);
419 moof::socket
sock(moof::socket::address::broadcast("4950"));
420 //moof::socket sock("4950", "lappy", SOCK_DGRAM);
421 sock
.set(SO_BROADCAST
, 1);
424 //if (sock.isConnected())
427 pack
<< "hello world";
429 //sock.write(pack, sock.address());
430 moof::log_info("sent", pack
.size(), "bytes");
432 const char* data
= pack
.bytes();
433 for (unsigned i
= 0; i
< pack
.size(); ++i
)
435 moof::log_warning("meh:", data
[i
]);
439 pack
.read(data2
, 13);
440 for (int i
= 0; i
< 13; ++i
)
442 moof::log_warning("meh:", data2
[i
]);
447 //moof::log_error("NOT CONNECTED");
457 std::string
arg(argv
[1]);
458 if (arg
== "-h" || arg
== "--help")
463 else if (arg
== "-i" || arg
== "--info")
465 Main::printInfo(argc
, argv
);
473 moof::resource::add_search_paths(Main::getSearchPath());
475 moof::settings
settings(argc
, argv
, Main::getConfigPath());
477 enum moof::log::level logLevel
= moof::log::info
;
478 settings
.get("loglevel", logLevel
);
479 moof::log::level(logLevel
);
483 std::string
iconPath(PACKAGE
".png");
484 moof::resource::find(iconPath
);
485 moof::image
icon(iconPath
);
488 class moof::video::attributes
attributes(settings
);
489 moof::video
video(PACKAGE_STRING
, attributes
);
490 Main
mainView(settings
, video
);
495 catch (const std::exception
& e
)
497 moof::modal_dialog
dialog(moof::modal_dialog::error
,
498 PACKAGE_STRING
, "Unhandled Exception",
This page took 0.059213 seconds and 4 git commands to generate.