[Toss-devel-svn] SF.net SVN: toss:[1253] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2010-12-18 00:52:34
|
Revision: 1253 http://toss.svn.sourceforge.net/toss/?rev=1253&view=rev Author: lukaszkaiser Date: 2010-12-18 00:52:28 +0000 (Sat, 18 Dec 2010) Log Message: ----------- Store only models in WebClient plays, each game only once. Chess works reasonably now. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ArenaParser.mly trunk/Toss/Play/Server.ml trunk/Toss/WebClient/README trunk/Toss/WebClient/TossDefaultStyle.js trunk/Toss/WebClient/TossHandler.py trunk/Toss/WebClient/TossMain.js trunk/Toss/WebClient/TossStyle.css trunk/Toss/WebClient/Wrapper.py trunk/Toss/WebClient/index.html Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/Arena.ml 2010-12-18 00:52:28 UTC (rev 1253) @@ -173,6 +173,9 @@ (List.length old_rules) (List.length old_locs); ); (* }}} *) + let rev_models_at_end l = + let m, n = List.partition (function StateStruc _ -> true | _ -> false) l in + n @ (List.rev m) in let rules, locations, players, defined_rels, state, time, cur_loc, data = List.fold_right (fun def (rules, locations, players, defined_rels, @@ -203,7 +206,7 @@ | StateData more_data -> (rules, locations, players, defined_rels, state, time, cur_loc, data @ more_data) - ) defs ([], [], players, defined_rels, + ) (rev_models_at_end defs) ([], [], players, defined_rels, state, time, cur_loc, data) in (* {{{ log entry *) if !debug_level > 2 then ( @@ -469,6 +472,7 @@ | SetTime of float * float (* Set time step and time *) | GetTime (* Get time step and time *) | SetState of game_state (* Set the full state *) + | GetModel (* Return the current model*) | GetState (* Return the state *) @@ -870,4 +874,5 @@ (state, string_of_float (ts) ^ " / " ^ string_of_float (t)) | SetState s -> (s, "STATE SET") + | GetModel -> (state, Structure.sprint state.struc) | GetState -> (state, state_str state) Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/Arena.mli 2010-12-18 00:52:28 UTC (rev 1253) @@ -175,6 +175,7 @@ | SetTime of float * float (** Set time step and time *) | GetTime (** Get time step and time *) | SetState of game_state (** Set the full state *) + | GetModel (** Return the model *) | GetState (** Return the state *) val handle_request : game_state -> request -> game_state * string Modified: trunk/Toss/Arena/ArenaParser.mly =================================================================== --- trunk/Toss/Arena/ArenaParser.mly 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Arena/ArenaParser.mly 2010-12-18 00:52:28 UTC (rev 1253) @@ -135,6 +135,7 @@ | GET_CMD SIG_MOD id_int { GetArity ($3) } | SET_CMD STATE_SPEC gs=game_state { SetState gs } | GET_CMD STATE_SPEC { GetState } + | GET_CMD MODEL_SPEC { GetModel } | ADD_CMD ELEM_MOD struct_location { AddElem ($3) } | ADD_CMD REL_MOD Modified: trunk/Toss/Play/Server.ml =================================================================== --- trunk/Toss/Play/Server.ml 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/Play/Server.ml 2010-12-18 00:52:28 UTC (rev 1253) @@ -117,6 +117,7 @@ | Arena.SetTime _ -> false (* TODO: rethink when working on dyns *) | Arena.GetTime -> false | Arena.SetState _ -> true + | Arena.GetModel -> false | Arena.GetState -> false exception Found of int Modified: trunk/Toss/WebClient/README =================================================================== --- trunk/Toss/WebClient/README 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/README 2010-12-18 00:52:28 UTC (rev 1253) @@ -19,12 +19,11 @@ TODO: - - better register html - - back button handler (reload), enter for login - - enable google (or other) analytics - - refresh (async?) plays in which the other player moves + - better register html and user table - move interface: first click all, second click toggle, if one - confirm msg - after the above: remove left-of-board div, confirm in the middle - after the above: show game result in the middle / instead of move - - option to give up game and offer a draw - sort plays by who's turn it is + - option to give up game and offer a draw + - enable google (or other) analytics + - refresh (async?) plays in which the other player moves Modified: trunk/Toss/WebClient/TossDefaultStyle.js =================================================================== --- trunk/Toss/WebClient/TossDefaultStyle.js 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossDefaultStyle.js 2010-12-18 00:52:28 UTC (rev 1253) @@ -38,14 +38,14 @@ var DEFbishop = '<g transform="translate(-22.5,-22.5)"> \ <path \ d="M 9,36 C 12.385,35.028 19.115,36.431 22.5,34 C 25.885,36.431 32.615,35.028 36,36 C 36,36 37.646,36.542 39,38 C 38.323,38.972 37.354,38.986 36,38.5 C 32.615,37.528 25.885,38.958 22.5,37.5 C 19.115,38.958 12.385,37.528 9,38.5 C 7.6459,38.986 6.6771,38.972 6,38 C 7.3541,36.055 9,36 9,36 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <path \ d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z " \ style="stroke-linecap:butt;" class="chess-path-B" /> \ <path \ d="M 25 10 A 2.5 2.5 0 1 1 20,10 A 2.5 2.5 0 1 1 25 10 z" \ transform="translate(0,-2)" \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <path \ d="M 17.5,26 L 27.5,26" \ style="stroke-linecap:butt;" class="chess-path-D" /> \ @@ -63,10 +63,10 @@ var DEFrook = '<g transform="translate(-22.5,-22.5)"> \ <path \ d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <path \ d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " \ - style="stroke-linecap:butt;" class="chess-path-B" /> \ + style="stroke-linecap:butt;" class="chess-path-Bx" /> \ <path \ d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14" \ style="stroke-linecap:butt;" class="chess-path-B" /> \ @@ -78,7 +78,7 @@ style="stroke-linecap:butt;" class="chess-path-B" /> \ <path \ d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" \ - class="chess-path-B" /> \ + class="chess-path-Bx" /> \ <path \ d="M 11,14 L 34,14" \ class="chess-path-D" /> \ Modified: trunk/Toss/WebClient/TossHandler.py =================================================================== --- trunk/Toss/WebClient/TossHandler.py 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossHandler.py 2010-12-18 00:52:28 UTC (rev 1253) @@ -10,7 +10,7 @@ TUID = "toss_id_05174_" def tmp_log (str): - file = open ("/tmp/th.log", 'w') + file = open ("/tmp/th.log", 'a') file.write (str) file.close() @@ -27,23 +27,37 @@ time.sleep (0.1) return (port) +def get_global_lock (db): + cur = db.cursor () + cur.execute ("update lock set locked='true' " + + " where locked='false' and tid='" + str(TUID) + "'") + db.commit () + if cur.rowcount == 1: + return + time.sleep (0.1) + get_global_lock (db) + +def release_global_lock (db): + db.execute ("update lock set locked='false' " + + " where locked='true' and tid='" + str(TUID) + "'") + db.commit () + def get_toss_port (db): + get_global_lock (db) free_ports = get_all_from_db (db, "ports", "locked='false'") if len(free_ports) == 0: fid = 0 for f in db.execute ("select count(*) from ports"): fid = int(f[0]) port = 8110+fid+1 - # WARNING: two proc can get same fid! Avoid by sqlite write-atomicity! db.execute ("insert into ports(port, locked) values (?, ?)", (port, 'true')) - db.commit () + release_global_lock (db) open_toss_server (port) return (port) (port, _) = free_ports[0] db.execute ("update ports set locked='true' where port=" + str(port)) - # This could give same port to 2 proc (1st line). Avoid by sql-write! - db.commit () + release_global_lock (db) return (port) def release_toss_port (db, port): @@ -84,7 +98,8 @@ (_, toss) = res[0] client.open_from_str (toss) info = get_game_info (client) - db_cur_insert (db, game, p1, p2, pid, move, toss, info, "") + model = client.get_model () + db_cur_insert (db, game, p1, p2, pid, move, model, info, "") return (info) def game_select_s (g, p1, p2, pid, m): @@ -102,10 +117,12 @@ select_s = game_select_s (g, p1, p2, pid, m) old_res = get_all_from_db (db, "cur_states", select_s) (_, _, _, _, _, old_toss, old_info, old_svg) = old_res[0] - client.open_from_str (old_toss) + res = get_all_from_db (db, "games", "game='" + g + "'") + (_, game_toss) = res[0] + client.open_from_str (game_toss + "\n MODEL " + old_toss) (move1, move2, move3) = move_tup client.make_move (move1, move2, move3) - new_toss = client.get_state () + new_toss = client.get_model () new_info = get_game_info (client) db.execute ("delete from cur_states where " + select_s) db_old_insert (db, g, p1, p2, pid, m, old_toss, old_info, old_svg) Modified: trunk/Toss/WebClient/TossMain.js =================================================================== --- trunk/Toss/WebClient/TossMain.js 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossMain.js 2010-12-18 00:52:28 UTC (rev 1253) @@ -161,8 +161,8 @@ } function play_click (game, play_id, pi) { - list_plays (game) - game_click (game) + list_plays (game); + game_click (game); document.getElementById ("game-title").innerHTML = game; document.getElementById("game-disp").style.display = "block"; document.getElementById("play-number").innerHTML = "" + play_id; @@ -324,6 +324,8 @@ UNAME = un document.getElementById("topuser").innerHTML = "Welcome " + un; document.getElementById("loginform").style.display = "none"; + document.getElementById("topright-register").style.display = "none"; + document.getElementById("topright").style.display = "inline"; document.getElementById("welcome").style.display = "none"; document.getElementById("plays").style.display = "block"; list_plays ("Breakthrough"); @@ -333,6 +335,18 @@ list_plays ("Tic-Tac-Toe"); } +// Clear view +function clear_view () { + document.getElementById("loginform").style.display = "inline"; + document.getElementById("topright-register").style.display = "inline"; + document.getElementById("topright").style.display = "none"; + document.getElementById("topuser").innerHTML = ""; + document.getElementById("plays").style.display = "none"; + document.getElementById("game-title").style.display = "none"; + document.getElementById("game-disp").style.display = "none"; + document.getElementById("welcome").style.display = "block"; +} + function startup () { if (navigator.userAgent.indexOf('MSIE') !=-1) { document.getElementById("nosvg").style.display = "block"; @@ -357,10 +371,5 @@ // Logout function logout () { - document.getElementById("loginform").style.display = "inline"; - document.getElementById("topuser").innerHTML = ""; - document.getElementById("plays").style.display = "none"; - document.getElementById("game-title").style.display = "none"; - document.getElementById("game-disp").style.display = "none"; - document.getElementById("welcome").style.display = "block"; + clear_view (); } Modified: trunk/Toss/WebClient/TossStyle.css =================================================================== --- trunk/Toss/WebClient/TossStyle.css 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/TossStyle.css 2010-12-18 00:52:28 UTC (rev 1253) @@ -58,8 +58,14 @@ #topright { float: right; margin-right: 0em; + display: none; } +#topright-register { + float: right; + margin-right: 0em; +} + #bottom { position: relative; bottom: 0px; @@ -410,7 +416,7 @@ .chessB .chess-path-B { opacity:1; - fill:#400827; + fill: #400827; fill-opacity:1; fill-rule:evenodd; stroke:#260314; @@ -422,6 +428,34 @@ stroke-opacity:1; } +.chessW .chess-path-Bx { + opacity:1; + fill:#ffe4aa; + fill-opacity:1; + fill-rule:evenodd; + stroke:#260314; + stroke-width:1.5; + stroke-linecap:round; + stroke-linejoin:round; + stroke-miterlimit:4; + stroke-dasharray:none; + stroke-opacity:1; +} + +.chessB .chess-path-Bx { + opacity:1; + fill: #ffe4aa; + fill-opacity:1; + fill-rule:evenodd; + stroke: #400827; + stroke-width:1.5; + stroke-linecap:round; + stroke-linejoin:round; + stroke-miterlimit:4; + stroke-dasharray:none; + stroke-opacity:1; +} + .chessW .chess-path-C { opacity:1; fill:#400827; Modified: trunk/Toss/WebClient/Wrapper.py =================================================================== --- trunk/Toss/WebClient/Wrapper.py 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/Wrapper.py 2010-12-18 00:52:28 UTC (rev 1253) @@ -117,6 +117,9 @@ def get_state (self): return (self.msg ("GET STATE")) + def get_model (self): + return (self.msg ("GET MODEL")) + def set_state (self, state): m = self.msg ("SET STATE " + state) return (m) Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2010-12-16 22:53:03 UTC (rev 1252) +++ trunk/Toss/WebClient/index.html 2010-12-18 00:52:28 UTC (rev 1253) @@ -21,15 +21,17 @@ <form id="loginform" style="display: inline;"> Username: <input type="text" name="username" id="username" /> -Password: <input type="password" name="password" id="password" /> +Password: <input type="password" name="password" id="password" + onkeypress="if (window.event && window.event.keyCode == 13) { login () }" /> <a id="login" href="#" onclick="login()">Login</a> - -(<a href="register.html">Register</a>) </form> <span id="topright"> <a id="logout" href="#" onclick="logout()">Logout</a> </span> +<span id="topright-register"> + <a href="register.html">Register</a> +</span> </div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |