aboutsummaryrefslogtreecommitdiff
path: root/bridges.c (follow)
Commit message (Collapse)AuthorAge
* Add method for frontends to query the backend's cursor location.Franklin Wei2020-12-07
| | | | | | | | | | | | | | | | The Rockbox frontend allows games to be displayed in a "zoomed-in" state targets with small displays. Currently we use a modal interface -- a "viewing" mode in which the cursor keys are used to pan around the rendered bitmap; and an "interaction" mode that actually sends keys to the game. This commit adds a midend_get_cursor_location() function to allow the frontend to retrieve the backend's cursor location or other "region of interest" -- such as the player location in Cube or Inertia. With this information, the Rockbox frontend can now intelligently follow the cursor around in the zoomed-in state, eliminating the need for a modal interface.
* Add missing 'static' to game-internal declarations.Simon Tatham2018-11-13
| | | | | | | | | Another thing I spotted while trawling the whole source base was that a couple of games had omitted 'static' on a lot of their internal functions. Checking with nm, there turned out to be quite a few more than I'd spotted by eye, so this should fix them all. Also added one missing 'const', on the lookup table nbits[] in Tracks.
* Use C99 bool within source modules.Simon Tatham2018-11-13
| | | | | | | | | | This is the main bulk of this boolification work, but although it's making the largest actual change, it should also be the least disruptive to anyone interacting with this code base downstream of me, because it doesn't modify any interface between modules: all the inter-module APIs were updated one by one in the previous commits. This just cleans up the code within each individual source file to use bool in place of int where I think that makes things clearer.
* Replace TRUE/FALSE with C99 true/false throughout.Simon Tatham2018-11-13
| | | | | | This commit removes the old #defines of TRUE and FALSE from puzzles.h, and does a mechanical search-and-replace throughout the code to replace them with the C99 standard lowercase spellings.
* Adopt C99 bool in the game backend API.Simon Tatham2018-11-13
| | | | | | | | | | | encode_params, validate_params and new_desc now take a bool parameter; fetch_preset, can_format_as_text_now and timing_state all return bool; and the data fields is_timed, wants_statusbar and can_* are all bool. All of those were previously typed as int, but semantically boolean. This commit changes the API declarations in puzzles.h, updates all the games to match (including the unfinisheds), and updates the developer docs as well.
* Add a request_keys() function with a midend wrapper.Franklin Wei2018-04-22
| | | | | | | | This function gives the front end a way to find out what keys the back end requires; and as such it is mostly useful for ports without a keyboard. It is based on changes originally found in Chris Boyle's Android port, though some modifications were needed to make it more flexible.
* Return error messages as 'const char *', not 'char *'.Simon Tatham2017-10-01
| | | | | They're never dynamically allocated, and are almost always string literals, so const is more appropriate.
* Use a proper union in struct config_item.Simon Tatham2017-10-01
| | | | | | This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES.
* New name UI_UPDATE for interpret_move's return "".Simon Tatham2017-10-01
| | | | | | | | | | | | | Now midend.c directly tests the returned pointer for equality to this value, instead of checking whether it's the empty string. A minor effect of this is that games may now return a dynamically allocated empty string from interpret_move() and treat it as just another legal move description. But I don't expect anyone to be perverse enough to actually do that! The main purpose is that it avoids returning a string literal from a function whose return type is a pointer to _non-const_ char, i.e. we are now one step closer to being able to make this code base clean under -Wwrite-strings.
* Rework the preset menu system to permit submenus.Simon Tatham2017-04-26
| | | | | | | | | | | | | | | | | | | | To do this, I've completely replaced the API between mid-end and front end, so any downstream front end maintainers will have to do some rewriting of their own (sorry). I've done the necessary work in all five of the front ends I keep in-tree here - Windows, GTK, OS X, Javascript/Emscripten, and Java/NestedVM - and I've done it in various different styles (as each front end found most convenient), so that should provide a variety of sample code to show downstreams how, if they should need it. I've left in the old puzzle back-end API function to return a flat list of presets, so for the moment, all the puzzle backends are unchanged apart from an extra null pointer appearing in their top-level game structure. In a future commit I'll actually use the new feature in a puzzle; perhaps in the further future it might make sense to migrate all the puzzles to the new API and stop providing back ends with two alternative ways of doing things, but this seemed like enough upheaval for one day.
* Bridges: use the new findloop for loop detection.Simon Tatham2016-02-24
| | | | | | | | | | | | | Bridges only needs a loop detector for its non-default 'don't allow loops' mode. But the one it had was using the graph-pruning strategy, which means it had the dumb-bell bug - two loops joined by a path would highlight the path as well as the loops. Switching to the new findloop system fixes that bug. A side effect is that I've been able to remove the 'scratch' array from the game_state, which was only used by the old loop finder, so that should save memory.
* Allow unlocking an island despite moving slightly.Chris Boyle2015-11-28
| | | | | | Previously moving 1 pixel would be treated as a failed drag and not an unlock. Now you only have to release the button somewhere on the island you started on.
* Expand keyboard input options in Bridges, for faster entry.Jonas Kölker2015-10-18
| | | | | | - Lay bridges (crosess) with Control-arrow (Shift-arrow) - Jump (non-orthogonally) to nearby islands with number keys, a..f - Mark islands as done with a single tap on the space bar
* Fix a typo in a Bridges error message.Jonas Kölker2015-10-18
| | | | 'contain_ER_s' becomes 'contains'.
* Fix Bridges keyboard cursor vertical out-of-bounds error.Jonas Kölker2015-10-18
| | | | | | Position the cursor in the top (bottom) row, press enter and press up (down). The game acts as if you had pressed right, both with Enter- and Space-based dragging.
* Fix error highlighting of closed subgraphs in Bridges.Simon Tatham2014-10-29
| | | | | | | | | | | | | | When I did the recent rewrite of the Bridges drawing code, I spotted and replicated the code in game_redraw that set G_WARN at redraw time on an island with unsatisfiable clues, but didn't spot the code elsewhere (e.g. map_group_check) which might have set G_WARN ahead of time, so I failed to check for that. As a result, if you join some islands together into a subgraph with no further room for expansion (e.g. connect a pair of 1s together, or a pair of 2s with a double bridge) then all the bridges in that subgraph light up red but the islands themselves forget to. Trivial one-line fix.
* Fix antialiasing artifacts around edges of Bridges islands.Simon Tatham2014-10-07
| | | | | | | | | | | | | | | | | | When an island changes colour (because it becomes locked or highlighted, or goes back to plain COL_FOREGROUND from one of those states), we were just redrawing a filled circle over the previous one, which only really worked before antialiasing was introduced. Fixed by reworking the entire drawing edifice to be grid-square based, so that every grid square is either redrawn in full or left alone. Grid squares come in two types - island and bridge - but a bridge square can have neighbouring islands overlap into it, and the bridges entering an island overlap the island square too, so we end up with quite a large collection of bitfields describing each square's contents, and some care must be taken to draw each square in the right order. [originally from svn r10282]
* Giant const patch of doom: add a 'const' to every parameter in everySimon Tatham2013-04-13
| | | | | | | | | | | | | | puzzle backend function which ought to have it, and propagate those consts through to per-puzzle subroutines as needed. I've recently had to do that to a few specific parameters which were being misused by particular puzzles (r9657, r9830), which suggests that it's probably a good idea to do the whole lot pre-emptively before the next such problem shows up. [originally from svn r9832] [r9657 == 3b250baa02a7332510685948bf17576c397b8ceb] [r9830 == 0b93de904a98f119b1a95d3a53029f1ed4bfb9b3]
* Add 'const' to the game_params arguments in validate_desc andSimon Tatham2013-04-12
| | | | | | | | | | | | new_desc. Oddities in the 'make test' output brought to my attention that a few puzzles have been modifying their input game_params for various reasons; they shouldn't do that, because that's the game_params held permanently by the midend and it will affect subsequent game generations if they modify it. So now those arguments are const, and all the games which previously modified their game_params now take a copy and modify that instead. [originally from svn r9830]
* New rule: interpret_move() is passed a pointer to the game_drawstateSimon Tatham2012-09-09
| | | | | | | | | | | | | | | | basically just so that it can divide mouse coordinates by the tile size, but is definitely not expected to _write_ to it, and it hadn't previously occurred to me that anyone might try. Therefore, interpret_move() now gets a pointer to a _const_ game_drawstate instead of a writable one. All existing puzzles cope fine with this API change (as long as the new const qualifier is also added to a couple of subfunctions to which interpret_move delegates work), except for the just-committed Undead, which somehow had ds->ascii and ui->ascii the wrong way round but is otherwise unproblematic. [originally from svn r9657]
* Remove the speed optimisation in the stage 3 solver which makes theSimon Tatham2012-06-01
| | | | | | | | | | | | | | | | | | | | | | first loop only handle rightward or downward bridges (on the basis that that way every bridge is looked at once rather than twice). This seems to be breaking in the wake of recent changes to the solver, in cases such as when island A is left of island B and has enough other outgoing edges that only one bridge remains to potentially go to B, but B is as yet unconstrained. In this situation the only code which is able to adjust the maximum bridge count for that edge is the stage 3 solver (nothing else calls solve_join with is_max true), but it will only do so if it _tries_ putting two bridges there and finds it impossible, and when it starts from island A it won't even try. Game ID which was insoluble just before this commit: 15x15m2:2a4d3b3c2h2d2a2a3c3w4a3m1d1a4a5a2d4d6e4q3e6a2a1e1b2g3a3o2g1d32l4b2c3a4c2b22l4a This probably means I've done something else in recent checkins which was not in accordance with the original solver design. However, this fix will do for the moment. [originally from svn r9548]
* Another uninitialised-variable fix, this one pointing out a real bug.Simon Tatham2012-06-01
| | | | | | | Simplest fix is to just remove the 'n' parameter from solve_island_subgroup, replacing it with a robust island_countbridges. [originally from svn r9547]
* Add pointless initialisations to placate a gcc warning.Simon Tatham2012-06-01
| | | | | | | | | (I'm confident these can't happen. maxb is initialised whenever we break from the first loop with y < h, and when we don't break from that loop the second loop which uses maxb is run zero times. But gcc can't work that out, sigh.) [originally from svn r9546]
* Write a comment outlining a design for a rewritten faster solver.Simon Tatham2012-05-31
| | | | [originally from svn r9544]
* Bridges solver enhancement. In the stage 3 solver, we were consideringSimon Tatham2012-05-31
| | | | | | | | | | | | | | | the possibility that an island might form an isolated subgraph by connecting to one of its neighbours (and, if so, reducing the maximum bridge count in that direction so that some bridge would have to go elsewhere), but we were not also considering the possibility that it might form an isolated subgraph by connecting to _more_ than one of its neighbours. For instance, if you have a 3 adjacent to a 1, a 2 and something else, then at least one bridge must go to the something-else. Previously insoluble test case: 10x10m2:a2b4a5a2a2a1ga2d3b33a3a4c2aa3e1a22b2a4b4aa3b1a2b33a1e3aa2a1a2c23a3a3a4a2a [originally from svn r9543]
* Bridges solver fix: in map_update_possibles, collect values fromSimon Tatham2012-05-31
| | | | | | maxh/maxv for squares between islands as well as on islands. [originally from svn r9542]
* Fix a bug causing premature defeatism in the Bridges solver. DeducingSimon Tatham2012-01-17
| | | | | | | | | | | a better upper bound on the number of bridges leaving a given island in a given direction was not counted as having 'done something'; so a solver run could make several such deductions, but then terminate in the belief that it hadn't achieved anything, when just going back round the main solver loop would have enabled it to make further deductions based on those new bounds. [originally from svn r9377]
* Changed my mind about midend_is_solved: I've now reprototyped it asSimon Tatham2011-06-19
| | | | | | | | | | | | | | | | midend_status(), and given it three return codes for win, (permanent) loss and game-still-in-play. Depending on what the front end wants to use it for, it may find any or all of these three states worth distinguishing from each other. (I suppose a further enhancement might be to add _non_-permanent loss as a fourth distinct status, to describe situations in which you can't play further without pressing Undo but doing so is not completely pointless. That might reasonably include dead-end situations in Same Game and Pegs, and blown-self-up situations in Mines and Inertia. However, I haven't done this at present.) [originally from svn r9179]
* Fix warnings generated by gcc 4.6.0 about variables set but notSimon Tatham2011-05-04
| | | | | | | | | | thereafter read. Most of these changes are just removal of pointless stuff or trivial reorganisations; one change is actually substantive, and fixes a bug in Keen's clue selection (the variable 'bad' was unreferenced not because I shouldn't have set it, but because I _should_ have referenced it!). [originally from svn r9164]
* Add a function to every game backend which indicates whether a gameSimon Tatham2011-04-02
| | | | | | | | | | | state is in a solved position, and a midend function wrapping it. (Or, at least, a situation in which further play is pointless. The point is, given that game state, would it be a good idea for a front end that does that sort of thing to proactively provide the option to start a fresh game?) [originally from svn r9140]
* The printing function in Bridges was unable to cope with more than twoSimon Tatham2011-02-03
| | | | | | | bridges between a pair of islands! Good grief. How did we never spot that before? [originally from svn r9083]
* Error highlighting bug in Bridges: when counting the number of extraSimon Tatham2010-03-21
| | | | | | | | | | | | bridges that could go to an island, the game was not correctly accounting for existing bridges in all circumstances. (E.g. in 7x7m2:2a6a2a1g4a6c4i1a1h23c2b, connect the top right 1 to the 2 left of it, and the 6 left of that correctly lights up red. But now connect the 6 to the 6 below it, and it wrongly unlights again.) [originally from svn r8905]
* Minor bug fixes from James Harvey.Simon Tatham2009-12-17
| | | | [originally from svn r8785]
* Memory management and other fixes from James H.Simon Tatham2009-06-17
| | | | [originally from svn r8596]
* Keyboard control patch for Bridges, from James H.Simon Tatham2009-02-05
| | | | [originally from svn r8446]
* New infrastructure feature. Games are now permitted to beSimon Tatham2008-09-06
| | | | | | | | | | | | | | | | | | | | | | _conditionally_ able to format the current puzzle as text to be sent to the clipboard. For instance, if a game were to support playing on a square grid and on other kinds of grid such as hexagonal, then it might reasonably feel that only the former could be sensibly rendered in ASCII art; so it can now arrange for the "Copy" menu item to be greyed out depending on the game_params. To do this I've introduced a new backend function (can_format_as_text_now()), and renamed the existing static backend field "can_format_as_text" to "can_format_as_text_ever". The latter will cause compile errors for anyone maintaining a third-party front end; if any such person is reading this, I apologise to them for the inconvenience, but I did do it deliberately so that they'd know to update their front end. As yet, no checked-in game actually uses this feature; all current games can still either copy always or copy never. [originally from svn r8161]
* Dariusz Olszewski's changes to support compiling for PocketPC. ThisSimon Tatham2007-02-26
| | | | | | | | | | | | is mostly done with ifdefs in windows.c; so mkfiles.pl generates a new makefile (Makefile.wce) and Recipe enables it, but it's hardly any different from Makefile.vc apart from a few definitions at the top of the files. Currently the PocketPC build is not enabled in the build script, but with any luck I'll be able to do so reasonably soon. [originally from svn r7337]
* HTML Help support for Puzzles, with the same kind of automaticSimon Tatham2006-12-24
| | | | | | fallback behaviour as PuTTY's support. [originally from svn r7009]
* Mike's changes to dsf.c alter the internal storage format of dsfSimon Tatham2006-11-01
| | | | | | | | | structures, meaning that ad-hoc initialisation now doesn't work. Hence, this checkin converts all ad-hoc dsf initialisations into calls to dsf_init() or snew_dsf(). At least, I _hope_ I've caught all of them. [originally from svn r6888]
* Patch from Phil Bordelon to improve Bridges' appearance by adjustingSimon Tatham2006-02-19
| | | | | | the font size. [originally from svn r6573]
* Laurent Thioudellet reports that gcc4's ultra-cautious data flowSimon Tatham2005-12-26
| | | | | | | | | | | | | | | | | | warnings require two more variables to be explicitly initialised. In fact these variables are reliably initialised by a subfunction; gcc3 was happy to assume I knew what I was doing when it couldn't prove they were definitely used uninitialised, whereas gcc4 apparently takes the view that the onus is on me to allow it to prove they _aren't_. I regard this as a step backwards, since the effect will be to make explicit initialisation commonplace in cases where the initialiser value is chosen arbitrarily and never expected to be used, at which point (a) it will be less clear which initialisers have genuine purpose and which are compiler-placating fluff, and (b) valgrind's run-time uninitialised-data tracking will become less useful. Still, the effect doesn't seem great as yet, so here's the gcc4-placating checkin. [originally from svn r6508]
* Correct w/h mixup in grid edge checks.Simon Tatham2005-11-10
| | | | [originally from svn r6452]
* Work around a couple of minor display issues with max bridges set to 4:Jacob Nevins2005-10-22
| | | | | | | | | | | | | - the highlighting for a set of 4 lines spilled outside the tile, so would leave white residue if undone; - the endpoints of sets of 4 lines were not completely overprinted by the circle of an island (at least on Windows), which was untidy. Fixed by reducing the gap width for groups of lines which wouldn't otherwise fit in a tile (only). [originally from svn r6421]
* Cleanup: it was absolutely stupid for game_wants_statusbar() to be aSimon Tatham2005-10-22
| | | | | | | | | function, since it took no parameters by which to vary its decision, and in any case it's hard to imagine a game which only _conditionally_ wants a status bar. Changed it into a boolean data field in the backend structure. [originally from svn r6417]
* Cleanup: remove the game_state parameter to game_colours(). No gameSimon Tatham2005-10-22
| | | | | | | | | | | | was actually using it, and also it wasn't being called again for different game states or different game parameters, so it would have been a mistake to depend on anything in that game state. Games are now expected to commit in advance to a single fixed list of all the colours they will ever need, which was the case in practice already and simplifies any later port to a colour-poor platform. Also this change has removed a lot of unnecessary faff from midend_colours(). [originally from svn r6416]
* Cleanup: the `mouse_priorities' field in the back end has been aSimon Tatham2005-10-22
| | | | | | | more general-purpose flags word for some time now. Rename it to `flags'. [originally from svn r6414]
* New puzzle from James H: `Bridges', another Nikoli job.Simon Tatham2005-10-21
[originally from svn r6409]