[gnome-tetravex] Use uint8.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Use uint8.
- Date: Wed, 18 Sep 2019 00:45:51 +0000 (UTC)
commit d581ac24c7cb2a4d76192abc2366a39f7d3951da
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Sep 17 05:48:16 2019 +0200
Use uint8.
src/gnome-tetravex.vala | 2 +-
src/history.vala | 10 +++---
src/puzzle-view.vala | 40 ++++++++++-----------
src/puzzle.vala | 94 ++++++++++++++++++++++++-------------------------
src/score-dialog.vala | 14 ++++----
src/theme.vala | 4 +--
6 files changed, 82 insertions(+), 82 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index dc5953d..39ae451 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -293,7 +293,7 @@ private class Tetravex : Gtk.Application
SignalHandler.disconnect_by_func (puzzle, null, this);
int size = settings.get_int (KEY_GRID_SIZE);
- puzzle = new Puzzle (size);
+ puzzle = new Puzzle ((uint8) size);
puzzle.tick.connect (tick_cb);
puzzle.solved.connect (solved_cb);
view.puzzle = puzzle;
diff --git a/src/history.vala b/src/history.vala
index 88f95d8..4d88dda 100644
--- a/src/history.vala
+++ b/src/history.vala
@@ -52,8 +52,8 @@ private class History : Object
if (date == null)
continue;
- int size = int.parse (tokens[1]);
- int duration = int.parse (tokens[2]);
+ uint8 size = (uint8) int.parse (tokens[1]);
+ uint duration = (uint) int.parse (tokens[2]);
// FIXME use try_parse
@@ -67,7 +67,7 @@ private class History : Object
foreach (HistoryEntry entry in entries)
{
- string line = "%s %u %u\n".printf (entry.date.to_string (), entry.size, entry.duration);
+ string line = "%s %hu %u\n".printf (entry.date.to_string (), entry.size, entry.duration);
contents += line;
}
@@ -104,10 +104,10 @@ private class History : Object
private class HistoryEntry : Object // TODO make struct? needs using HistoryEntry? for the List...
{
[CCode (notify = false)] public DateTime date { internal get; protected construct; }
- [CCode (notify = false)] public uint size { internal get; protected construct; }
+ [CCode (notify = false)] public uint8 size { internal get; protected construct; }
[CCode (notify = false)] public uint duration { internal get; protected construct; }
- internal HistoryEntry (DateTime date, uint size, uint duration)
+ internal HistoryEntry (DateTime date, uint8 size, uint duration)
{
Object (date: date, size: size, duration: duration);
}
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 8fea2e9..5db3a3d 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -55,9 +55,9 @@ private class PuzzleView : Gtk.DrawingArea
_puzzle = value;
tiles.remove_all ();
- for (uint y = 0; y < puzzle.size; y++)
+ for (uint8 y = 0; y < puzzle.size; y++)
{
- for (uint x = 0; x < puzzle.size * 2; x++)
+ for (uint8 x = 0; x < puzzle.size * 2; x++)
{
Tile? tile = puzzle.get_tile (x, y);
if (tile == null)
@@ -112,9 +112,9 @@ private class PuzzleView : Gtk.DrawingArea
if (puzzle.is_solved)
return false;
- for (uint y = 0; y < puzzle.size; y++)
+ for (uint8 y = 0; y < puzzle.size; y++)
{
- for (uint x = puzzle.size; x < puzzle.size * 2; x++)
+ for (uint8 x = puzzle.size; x < puzzle.size * 2; x++)
{
if (puzzle.get_tile (x, y) == null)
return true;
@@ -144,7 +144,7 @@ private class PuzzleView : Gtk.DrawingArea
move_tile (image, target_x, target_y, duration);
}
- private void move_tile (TileImage image, double x, double y, double duration = 0)
+ private void move_tile (TileImage image, double x, double y, double duration = 0) // FIXME double x
and y, really?
{
if (image.x == x && image.y == y)
return;
@@ -246,7 +246,7 @@ private class PuzzleView : Gtk.DrawingArea
y = (get_allocated_height () - puzzle.size * size) / 2;
}
- private void tile_moved_cb (Puzzle puzzle, Tile tile, uint x, uint y)
+ private void tile_moved_cb (Puzzle puzzle, Tile tile, uint8 x, uint8 y)
{
move_tile_to_location (tiles.lookup (tile), x, y, 0.2);
}
@@ -261,7 +261,7 @@ private class PuzzleView : Gtk.DrawingArea
TileImage image;
if (!iter.next (out tile, out image))
break;
- uint x, y;
+ uint8 x, y;
puzzle.get_tile_location (tile, out x, out y);
move_tile_to_location (image, x, y);
}
@@ -424,27 +424,27 @@ private class PuzzleView : Gtk.DrawingArea
x += size * 0.5 - selected_x_offset;
y += size * 0.5 - selected_x_offset;
- int tile_y = ((int) Math.floor ((y - y_offset) / size));
- tile_y = tile_y.clamp (0, (int) puzzle.size - 1);
+ int16 tile_y = (int16) Math.floor ((y - y_offset) / size);
+ tile_y = tile_y.clamp (0, (int16) puzzle.size - 1);
/* Check which side we are on */
- int tile_x;
+ int16 tile_x;
if (on_right_half (x))
{
- tile_x = (int) puzzle.size + (int) Math.floor ((x - (x_offset + puzzle.size * size + gap)) /
size);
- tile_x = tile_x.clamp ((int) puzzle.size, 2 * (int) puzzle.size - 1);
+ tile_x = (int16) puzzle.size + (int16) Math.floor ((x - (x_offset + puzzle.size * size + gap)) /
size);
+ tile_x = tile_x.clamp ((int16) puzzle.size, 2 * (int16) puzzle.size - 1);
}
else
{
- tile_x = (int) Math.floor ((x - x_offset) / size);
- tile_x = tile_x.clamp (0, (int) puzzle.size - 1);
+ tile_x = (int16) Math.floor ((x - x_offset) / size);
+ tile_x = tile_x.clamp (0, (int16) puzzle.size - 1);
}
/* Drop the tile here, or move it back if can't */
- uint selected_x, selected_y;
+ uint8 selected_x, selected_y;
puzzle.get_tile_location (selected_tile.tile, out selected_x, out selected_y);
- if (puzzle.can_switch (selected_x, selected_y, (uint) tile_x, (uint) tile_y))
- puzzle.switch_tiles (selected_x, selected_y, (uint) tile_x, (uint) tile_y);
+ if (puzzle.can_switch (selected_x, selected_y, (uint8) tile_x, (uint8) tile_y))
+ puzzle.switch_tiles (selected_x, selected_y, (uint8) tile_x, (uint8) tile_y);
else
move_tile_to_location (selected_tile, selected_x, selected_y, 0.2);
selected_tile = null;
@@ -454,13 +454,13 @@ private class PuzzleView : Gtk.DrawingArea
private void move_tile_to_right_half (TileImage image)
{
/* Pick the first open spot on the right side of the board */
- for (uint y = 0; y < puzzle.size; y++)
+ for (uint8 y = 0; y < puzzle.size; y++)
{
- for (uint x = puzzle.size; x < puzzle.size * 2; x++)
+ for (uint8 x = puzzle.size; x < puzzle.size * 2; x++)
{
if (puzzle.get_tile (x, y) == null)
{
- uint source_x, source_y;
+ uint8 source_x, source_y;
puzzle.get_tile_location (image.tile, out source_x, out source_y);
puzzle.switch_tiles (source_x, source_y, x, y);
return;
diff --git a/src/puzzle.vala b/src/puzzle.vala
index fd333bc..5b7805c 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -12,16 +12,16 @@
private class Tile : Object
{
/* Edge colors */
- internal int north; // TODO make uint8
- internal int west;
- internal int east;
- internal int south;
+ internal uint8 north;
+ internal uint8 west;
+ internal uint8 east;
+ internal uint8 south;
/* Solution location */
- [CCode (notify = false)] public uint x { internal get; protected construct; }
- [CCode (notify = false)] public uint y { internal get; protected construct; }
+ [CCode (notify = false)] public uint8 x { internal get; protected construct; }
+ [CCode (notify = false)] public uint8 y { internal get; protected construct; }
- internal Tile (uint x, uint y)
+ internal Tile (uint8 x, uint8 y)
{
Object (x: x, y: y);
}
@@ -29,7 +29,7 @@ private class Tile : Object
private class Puzzle : Object
{
- [CCode (notify = false)] public uint size { internal get; protected construct; } // TODO make uint8
+ [CCode (notify = false)] public uint8 size { internal get; protected construct; }
private Tile [,] board;
/* Game timer */
@@ -64,7 +64,7 @@ private class Puzzle : Object
internal get { return _paused; }
}
- internal signal void tile_moved (Tile tile, uint x, uint y);
+ internal signal void tile_moved (Tile tile, uint8 x, uint8 y);
internal signal void solved ();
internal signal void tick ();
@@ -74,9 +74,9 @@ private class Puzzle : Object
{
/* Solved if entire left hand side is complete (we ensure only tiles
that fit are allowed */
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
{
Tile? tile = board [x, y];
if (tile == null)
@@ -88,7 +88,7 @@ private class Puzzle : Object
}
}
- internal Puzzle (uint size)
+ internal Puzzle (uint8 size)
{
Object (size: size);
}
@@ -96,39 +96,39 @@ private class Puzzle : Object
construct
{
board = new Tile [size * 2, size];
- for (uint x = 0; x < size; x++)
- for (uint y = 0; y < size; y++)
+ for (uint8 x = 0; x < size; x++)
+ for (uint8 y = 0; y < size; y++)
board [x, y] = new Tile (x, y);
/* Pick random colours for edges */
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
{
- for (uint y = 0; y <= size; y++)
+ for (uint8 y = 0; y <= size; y++)
{
- int32 n = Random.int_range (0, 10);
+ uint8 n = (uint8) Random.int_range (0, 10);
if (y >= 1)
- board [x, y - 1].south = (int) n;
+ board [x, y - 1].south = n;
if (y < size)
- board [x, y].north = (int) n;
+ board [x, y].north = n;
}
}
- for (uint x = 0; x <= size; x++)
+ for (uint8 x = 0; x <= size; x++)
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
{
- int32 n = Random.int_range (0, 10);
+ uint8 n = (uint8) Random.int_range (0, 10);
if (x >= 1)
- board [x - 1, y].east = (int) n;
+ board [x - 1, y].east = n;
if (x < size)
- board [x, y].west = (int) n;
+ board [x, y].west = n;
}
}
/* Pick up the tiles... */
List<Tile> tiles = new List<Tile> ();
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
{
tiles.append (board [x, y]);
board [x, y] = null;
@@ -136,9 +136,9 @@ private class Puzzle : Object
}
/* ...and place then randomly on the right hand side */
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
{
int32 n = Random.int_range (0, (int32) tiles.length ());
Tile tile = tiles.nth_data ((uint) n);
@@ -150,12 +150,12 @@ private class Puzzle : Object
start_clock ();
}
- internal Tile? get_tile (uint x, uint y)
+ internal Tile? get_tile (uint8 x, uint8 y)
{
return board [x, y];
}
- internal void get_tile_location (Tile tile, out uint x, out uint y)
+ internal void get_tile_location (Tile tile, out uint8 x, out uint8 y)
{
y = 0; // garbage
for (x = 0; x < size * 2; x++)
@@ -164,7 +164,7 @@ private class Puzzle : Object
return;
}
- private bool tile_fits (uint x0, uint y0, uint x1, uint y1)
+ private bool tile_fits (uint8 x0, uint8 y0, uint8 x1, uint8 y1)
{
Tile? tile = board [x0, y0];
if (tile == null)
@@ -182,7 +182,7 @@ private class Puzzle : Object
return true;
}
- internal bool can_switch (uint x0, uint y0, uint x1, uint y1)
+ internal bool can_switch (uint8 x0, uint8 y0, uint8 x1, uint8 y1)
{
if (x0 == x1 && y0 == y1)
return false;
@@ -203,7 +203,7 @@ private class Puzzle : Object
return true;
}
- internal void switch_tiles (uint x0, uint y0, uint x1, uint y1)
+ internal void switch_tiles (uint8 x0, uint8 y0, uint8 x1, uint8 y1)
{
if (x0 == x1 && y0 == y1)
return;
@@ -234,13 +234,13 @@ private class Puzzle : Object
if (!can_move_up ())
return;
- for (uint y = 1; y < size; y++)
- for (uint x = 0; x < size; x++)
+ for (uint8 y = 1; y < size; y++)
+ for (uint8 x = 0; x < size; x++)
switch_tiles (x, y, x, y - 1);
}
private bool can_move_up ()
{
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
if (board [x, 0] != null)
return false;
return true;
@@ -251,13 +251,13 @@ private class Puzzle : Object
if (!can_move_down ())
return;
- for (uint y = size - 1; y > 0; y--)
- for (uint x = 0; x < size; x++)
+ for (uint8 y = size - 1; y > 0; y--)
+ for (uint8 x = 0; x < size; x++)
switch_tiles (x, y - 1, x, y);
}
private bool can_move_down ()
{
- for (uint x = 0; x < size; x++)
+ for (uint8 x = 0; x < size; x++)
if (board [x, size - 1] != null)
return false;
return true;
@@ -268,13 +268,13 @@ private class Puzzle : Object
if (!can_move_left ())
return;
- for (uint x = 1; x < size; x++)
- for (uint y = 0; y < size; y++)
+ for (uint8 x = 1; x < size; x++)
+ for (uint8 y = 0; y < size; y++)
switch_tiles (x, y, x - 1, y);
}
private bool can_move_left ()
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
if (board [0, y] != null)
return false;
return true;
@@ -285,13 +285,13 @@ private class Puzzle : Object
if (!can_move_right ())
return;
- for (uint x = size - 1; x > 0; x--)
- for (uint y = 0; y < size; y++)
+ for (uint8 x = size - 1; x > 0; x--)
+ for (uint8 y = 0; y < size; y++)
switch_tiles (x - 1, y, x, y);
}
private bool can_move_right ()
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
if (board [size - 1, y] != null)
return false;
return true;
@@ -304,9 +304,9 @@ private class Puzzle : Object
internal void solve ()
{
List<Tile> wrong_tiles = null;
- for (uint x = 0; x < size * 2; x++)
+ for (uint8 x = 0; x < size * 2; x++)
{
- for (uint y = 0; y < size; y++)
+ for (uint8 y = 0; y < size; y++)
{
Tile? tile = board [x, y];
if (tile != null && (tile.x != x || tile.y != y))
diff --git a/src/score-dialog.vala b/src/score-dialog.vala
index 77c8703..31d219e 100644
--- a/src/score-dialog.vala
+++ b/src/score-dialog.vala
@@ -79,7 +79,7 @@ private class ScoreDialog : Gtk.Dialog
entry_added_cb (entry);
}
- internal void set_size (uint size)
+ internal void set_size (uint8 size)
{
score_model.clear ();
@@ -103,7 +103,7 @@ private class ScoreDialog : Gtk.Dialog
Gtk.TreeIter iter;
score_model.append (out iter);
- score_model.set (iter, 0, date_label, 1, time_label, 2, weight);
+ score_model.@set (iter, 0, date_label, 1, time_label, 2, weight);
if (entry == selected_entry)
{
@@ -137,8 +137,8 @@ private class ScoreDialog : Gtk.Dialog
return;
int size;
- combo.model.get (iter, 1, out size);
- set_size ((uint) size);
+ combo.model.@get (iter, 1, out size);
+ set_size ((uint8) size);
}
private void entry_added_cb (HistoryEntry entry)
@@ -151,7 +151,7 @@ private class ScoreDialog : Gtk.Dialog
do
{
int size;
- size_model.get (iter, 1, out size, -1);
+ size_model.@get (iter, 1, out size, -1);
if (size == entry.size)
{
have_size_entry = true;
@@ -162,10 +162,10 @@ private class ScoreDialog : Gtk.Dialog
if (!have_size_entry)
{
- var label = "%u × %u".printf (entry.size, entry.size);
+ var label = "%hu × %hu".printf (entry.size, entry.size);
size_model.append (out iter);
- size_model.set (iter, 0, label, 1, entry.size);
+ size_model.@set (iter, 0, label, 1, entry.size);
/* Select this entry if don't have any */
if (size_combo.get_active () == -1)
diff --git a/src/theme.vala b/src/theme.vala
index 4b557fc..b2c404d 100644
--- a/src/theme.vala
+++ b/src/theme.vala
@@ -272,9 +272,9 @@ private class Theme : Object
context.stroke ();
}
- private void draw_number (Cairo.Context context, double x, double y, uint number)
+ private void draw_number (Cairo.Context context, double x, double y, uint8 number)
{
- string text = "%u".printf (number);
+ string text = "%hu".printf (number);
Cairo.TextExtents extents;
context.text_extents (text, out extents);
context.move_to (x - extents.width / 2.0, y + extents.height / 2.0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]