Permalink
Browse files

* experimental ldb integration

 * better '-h' help option for infon. -w and -h renamed to -x and -y
 * Lua upgraded to 5.1.2


git-svn-id: http://infon.googlecode.com/svn/trunk@187 8171fb75-e542-0410-96e4-03d5dd800671
  • Loading branch information...
1 parent 1c97f07 commit 845b9317e2aac6afa447ba7f1bae0b3b36eb41e2 @dividuum committed Apr 14, 2007
View
@@ -1,7 +1,7 @@
all: targets
ifndef REVISION
-REVISION := $(shell svnversion . || echo 'exported')
+-include REVISION
endif
# EVENT_NAME = Computer Night 2006
@@ -143,6 +143,7 @@ endif
targets: infond $(INFON_EXECUTABLE) $(RENDERER)
dist:
+ $(MAKE) distclean
$(MAKE) source-dist
$(MAKE) clean
WINDOWS=1 $(MAKE) win32-client-dist
@@ -151,7 +152,7 @@ dist:
$(MAKE) clean
$(MAKE) linux-server-dist
-source-dist: distclean
+source-dist: REVISION
tar cvzh -C.. --exclude ".svn" --exclude "infon-source*" --file infon-source-r$(REVISION).tgz infon
win32-client-dist: $(INFON_EXECUTABLE) $(SDL_RENDERER) $(GL_RENDERER)
@@ -202,8 +203,11 @@ lua-5.1.1/src/liblua.a:
%.o:%.cpp
$(CXX) $(CPPFLAGS) $^ -c -o $@
-clean:
- -rm -f *.o *.so *.dll infond infond-static infon infon.exe infon.res tags
+REVISION:
+ echo "REVISION=`svnversion .`" > $@
+
+clean:
+ -rm -f *.o *.so *.dll infond infond-static infon infon.exe infon.res tags REVISION
distclean: clean
$(MAKE) -C lua-5.1.1 clean
View
@@ -104,11 +104,11 @@ License:
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- The server uses a modified lua 5.1.1:
+ The server uses a modified lua 5.1.2:
lua http://www.lua.org/
- Copyright (C) 1994-2006 Lua.org, PUC-Rio.
+ Copyright (C) 1994-2007 Lua.org, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -252,10 +252,29 @@ function Creature:sleep(msec)
end
function Creature:main_restarter()
- while true do
- self:main()
- self:wait_for_next_round()
+ local wrap do
+ if self.onThreadFatal then
+ wrap = function(func, ...)
+ while true do
+ local _, msg = pcall(func, ...)
+ if not self:onThreadFatal(msg) then break end
+ end
+ error("thread terminated")
+ end
+ else
+ wrap = function(func, ...)
+ return func(...)
+ end
+ end
end
+
+ wrap(function ()
+ if self.onRestart then self:onRestart() end
+ while true do
+ self:main()
+ self:wait_for_next_round()
+ end
+ end)
end
function Creature:traceback()
@@ -264,20 +283,117 @@ end
function Creature:restart()
set_state(self.id, CREATURE_IDLE)
- self.thread = coroutine.create(self.main_restarter)
- if self.onRestart then
- local ok, msg = pcall(self.onRestart, self)
- if not ok then
- print("restarting main failed: " .. msg)
- end
- else
- print("onRestart method deleted")
- end
+ self.message = nil
+ self.thread = coroutine.create(self.main_restarter)
+ if self.onThreadStart then self:onThreadStart() end
end
function Creature:wait_for_next_round()
assert(can_yield, "you cannot wait_for_next_round() in interactive mode")
coroutine.yield()
+ if self.onThreadResume then self:onThreadResume() end
+end
+
+function Creature:assert(...)
+ return assert(...)
+end
+
+if ldb then
+ local debugged_creature_id
+
+ function Creature:onThreadStart()
+ self.is_in_debugger = nil
+ end
+
+ function Creature:onThreadFatal(msg)
+ self:enter_debugger(msg, {"up 2"})
+ return false
+ end
+
+ function Creature:onThreadResume()
+ if self.debug_me then
+ local msg = self.debug_me
+ self.debug_me = nil
+ self:enter_debugger(msg, {"up 4"})
+ end
+ end
+
+ function Creature:enter_debugger(msg, cmd)
+ self.is_in_debugger = true
+ self.message = "Debugger active (activate with 'd" .. self.id .. "')"
+ debugged_creature_id = self.id
+ print("debugger started for creature " .. self)
+ local ok, msg = pcall(ldb, msg, cmd)
+ if not ok then
+ print("internal debugger error: " .. msg)
+ end
+ self.is_in_debugger = nil
+ self.message = nil
+ debugged_creature_id = nil
+ coroutine.yield()
+ end
+
+ function Creature:assert(v, msg)
+ if not v then
+ self:enter_debugger(msg or "assertation failed", {"up 3"})
+ return nil
+ else
+ return v
+ end
+ end
+
+ function onCommand(cmd)
+ local id = tonumber(cmd:match("^d([0-9]+)$"))
+ if id then
+ if id == debugged_creature_id then
+ print("already debugging creature " .. id)
+ elseif not creatures[id] then
+ print("creature " .. id .. " does not exist")
+ elseif not creatures[id].is_in_debugger then
+ creatures[id].debug_me = "execution stopped"
+ else
+ debugged_creature_id = id
+ print("debugging creature " .. creatures[debugged_creature_id])
+ coroutine.resume(creatures[debugged_creature_id].thread, "bt")
+ end
+ return
+ end
+
+ local debugger_available = creatures[debugged_creature_id] and
+ creatures[debugged_creature_id].is_in_debugger
+
+ if cmd == "help" then
+ print(" d<id> attach debugger to creature <id>")
+ print(" clist show creature list")
+ if debugger_available then
+ coroutine.resume(creatures[debugged_creature_id].thread, cmd)
+ end
+ elseif cmd == "clist" then
+ print("creatures (* = active debugger, ! = in debug mode):")
+ for id, creature in pairs(creatures) do
+ print(string.format("%s%s %d - %s",
+ debugged_creature_id == id and "*" or " ",
+ creature.is_in_debugger and "!" or " ",
+ id, tostring(creature)))
+ end
+ elseif debugger_available then
+ coroutine.resume(creatures[debugged_creature_id].thread, cmd)
+ else
+ print("Huh? Try '?' for help on infon, or 'help' for help on the debugger")
+ end
+ end
+
+ function onRoundStart()
+ onRoundStart = nil
+ print("-----------------------------------------")
+ print("This server has the ldb debugger enabled.")
+ print("Type 'help' to get the debugger commands.")
+ print("-----------------------------------------")
+ end
+
+ function debug_hook(creature)
+ return not creature.is_in_debugger
+ end
end
------------------------------------------------------------------------
@@ -377,21 +493,18 @@ function player_think(events)
creature.message = 'main() terminated (maybe it was killed for using too much cpu/memory?)'
end
else
- if creature.debug then
- thread_trace(creature.thread, creature.id)
- else
- thread_untrace(creature.thread)
- end
- local ok, msg = coroutine.resume(creature.thread, creature)
- if not ok then
- creature.message = msg
- -- If the coroutine was interrupted for using too much
- -- CPU, the following function call will abort the
- -- player_think function (since no more function calls
- -- are possible at this point). The code that caused
- -- too much CPU can be seen by inspecting the traceback
- -- that was saved in creature.message. Use 'i' in the client.
- this_function_call_fails_if_cpu_limit_exceeded()
+ if not debug_hook or debug_hook(creature) then
+ local ok, msg = coroutine.resume(creature.thread, creature)
+ if not ok then
+ creature.message = msg
+ -- If the coroutine was interrupted for using too much
+ -- CPU, the following function call will abort the
+ -- player_think function (since no more function calls
+ -- are possible at this point). The code that caused
+ -- too much CPU can be seen by inspecting the traceback
+ -- that was saved in creature.message. Use 'i' in the client.
+ this_function_call_fails_if_cpu_limit_exceeded()
+ end
end
end
end
View
@@ -98,6 +98,7 @@ function setupCreature()
end
function restart()
+ message = nil
reload()
_set_state("restarting")
_restart_thread()
View
@@ -58,6 +58,17 @@ dofile_allowed = {
menu = "Botcode Menu System";
}
+-- Disable Linehook Function.
+-- This function offers some advanced debugging features,
+-- but has not been tested enough. Do not enable, unless
+-- you know what you're doing.
+linehook = false
+
+-- DO NOT ENABLE THE DEBUGGER IF OTHER PLAYERS CAN CONNECT
+-- TO YOUR SERVER. The debugger is not yet secured against
+-- malicious users.
+debugger = false
+
-- competition = {
-- log = "competition.log";
-- bots = {
View
@@ -110,6 +110,11 @@ static int luaSetRealtime(lua_State *L) {
return 0;
}
+static int luaSetPaused(lua_State *L) {
+ game_paused = lua_toboolean(L, 1);
+ return 0;
+}
+
static int luaGameIntermission(lua_State *L) {
snprintf(intermission, sizeof(intermission), "%s", luaL_checkstring(L, 1));
game_send_intermission(SEND_BROADCAST);
@@ -162,6 +167,7 @@ void game_init() {
lua_register(L, "hex_decode", luaHexDecode);
lua_register(L, "set_realtime", luaSetRealtime);
+ lua_register(L, "set_paused", luaSetPaused);
lua_register(L, "shutdown", luaShutdown);
lua_register_constant (L, MAXPLAYERS);
@@ -238,20 +244,28 @@ void game_one_game() {
// Runde starten
game_send_round_info(SEND_BROADCAST, delta);
+ // Rule Handler
+ game_call_rule_handler("onRound", 0);
+
// World Zeugs
world_tick();
+ }
+
+ player_round();
+ if (!game_paused) {
// Spielerprogramme ausfuehren
player_think();
+ }
+ player_sync();
+
+ if (!game_paused) {
// Viecher bewegen
creature_moveall(delta);
// Zeit weiterlaufen lassen
game_time += delta;
-
- // Rule Handler
- game_call_rule_handler("onRound", 0);
}
// IO Lesen/Schreiben
View
@@ -107,14 +107,25 @@ int main(int argc, char *argv[]) {
opterr = 0;
int opt;
- while ((opt = getopt(argc, argv, ":fvw:h:r:")) != -1) {
+ while ((opt = getopt(argc, argv, ":fvx:y:r:h")) != -1) {
switch (opt) {
- case '?': die("you specified an unknown option -%c", optopt);
- case ':': die("missing argument to option -%c", optopt);
+ case '?': die("you specified an unknown option -%c.", optopt);
+ case ':': die("missing argument to option -%c.", optopt);
case 'r': renderer = optarg; break;
case 'f': fullscreen = 1; break;
- case 'w': width = atoi(optarg); break;
- case 'h': height = atoi(optarg); break;
+ case 'x': width = atoi(optarg); break;
+ case 'y': height = atoi(optarg); break;
+ case 'h': die("usage: %s [-r <renderer>] [-f] [-x <width>] [-y <height>] [-v] [-h] <server[:port]>\n"
+ "\n"
+ " -r <renderer> - renderer to use (sdl_gui, gl_gui, ...)\n"
+ " -x <width> - initial screen width.\n"
+ " -y <height> - initial screen height.\n"
+ " -f - start in fullscreen mode.\n"
+ " -v - display version information.\n"
+ " -h - this help.\n"
+ "\n"
+ "<server[:port]> - ip/hostname of an infon game server.\n"
+ " if not port is given, 1234 is used.\n", argv[0]);
case 'v': info(); exit(EXIT_SUCCESS);
}
}
@@ -140,7 +151,8 @@ int main(int argc, char *argv[]) {
}
#else
if (!host)
- die("usage: %s <serverip[:port]>", argv[0]);
+ die("usage: %s [options] <server[:port]>\n"
+ "see %s -h for a full list of options", argv[0], argv[0]);
#endif
Oops, something went wrong.

0 comments on commit 845b931

Please sign in to comment.