Imported from archive.
[mudpy.git] / muff / muffmain.py
1 """Main loop for the MUFF Engine"""
2
3 # Copyright (c) 2005 mudpy, Jeremy Stanley <fungi@yuggoth.org>, all rights reserved.
4 # Licensed per terms in the LICENSE file distributed with this software.
5
6 # string.strip is used to clean up leading/trailing whitespace in user input
7 import string
8
9 # time.sleep is used in the loop to save cpu and provide crude pulse timing
10 import time
11
12 # hack to load all modules in the muff package
13 import muff
14 for module in muff.__all__:
15         exec("import " + module)
16
17 def main():
18         """The main loop."""
19
20         # loop indefinitely while the world is not flagged for termination or
21         # there are connected users
22         while not muffvars.terminate_world or muffvars.userlist:
23
24                 # the world was flagged for a reload of all code/data
25                 if muffvars.reload_modules:
26
27                         # reload the muff package
28                         reload(muff)
29
30                         # reload all modules listed in the muff package
31                         for module in muff.__all__:
32                                 exec("reload(muff." + module + ")")
33
34                         # move data into new persistent objects
35                         muffmisc.reload_data()
36
37                         # reset the reload flag
38                         muffvars.reload_modules = False
39
40                 # do what needs to be done on each pulse
41                 muffmisc.on_pulse()
42
43         # the loop has terminated, so save persistent data
44         muffuniv.universe.save()
45
46         # log a final message
47         muffmisc.log("Shutting down now.")
48