chess: cursor axis inversion, initial "animator" concept
This commit is contained in:
parent
5e80d9ecfc
commit
ebb1955500
@ -2,6 +2,7 @@
|
||||
|
||||
#include "chess.hpp"
|
||||
#include "sh7091/serial.hpp"
|
||||
|
||||
namespace chess {
|
||||
|
||||
xy position_to_xy(int8_t position)
|
||||
@ -281,7 +282,7 @@ static void board_init(game_state& game_state)
|
||||
|
||||
void game_init(game_state& game_state)
|
||||
{
|
||||
game_state.turn = -1; // white
|
||||
game_state.turn = 1; // white
|
||||
game_state.en_passant_target = -1;
|
||||
game_state.halfmove_number = 0;
|
||||
game_state.fullmove_number = 0;
|
||||
@ -452,6 +453,14 @@ void clear_annotations(game_state& game_state)
|
||||
game_state.interaction.annotation_list.length = 0;
|
||||
}
|
||||
|
||||
void delete_annotation(annotation_list& annotation_list, int i)
|
||||
{
|
||||
annotation_list.length -= 1;
|
||||
for (int j = i; j < annotation_list.length; j++) {
|
||||
annotation_list.annotation[j] = annotation_list.annotation[j + 1];
|
||||
}
|
||||
}
|
||||
|
||||
void annotate_position(game_state& game_state, int8_t x, int8_t y)
|
||||
{
|
||||
int8_t position = xy_to_position(x, y);
|
||||
@ -459,6 +468,7 @@ void annotate_position(game_state& game_state, int8_t x, int8_t y)
|
||||
|
||||
for (int i = 0; i < annotation_list.length; i++) {
|
||||
if (annotation_list.annotation[i].from_position == position) {
|
||||
delete_annotation(annotation_list, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -34,16 +34,23 @@ void cursor_update(struct render::cursor_state& cursor_state, uint32_t frame_ix)
|
||||
continue;
|
||||
auto& cursor = cursor_state.cur[cursor_ix];
|
||||
|
||||
float invert = port_ix % 2 == 0 ? 1.f : -1.f;
|
||||
|
||||
auto& port = input::state.port[port_ix];
|
||||
if (port.function_type & function_type::controller) {
|
||||
auto& bus_data = port.host_response_data_transfer_ft0->bus_data;
|
||||
auto& data_fields = bus_data.data_fields;
|
||||
if (std::byteswap(data_fields.function_type) & function_type::controller) {
|
||||
auto& data = data_fields.data;
|
||||
cursor.x += static_cast<float>(data.analog_coordinate_axis[2] - 0x80) * 0.0035;
|
||||
cursor.y += static_cast<float>(data.analog_coordinate_axis[3] - 0x80) * -0.0035;
|
||||
cursor.x += static_cast<float>(data.analog_coordinate_axis[2] - 0x80) * 0.0015 * invert;
|
||||
cursor.y += static_cast<float>(data.analog_coordinate_axis[3] - 0x80) * -0.0015 * invert;
|
||||
cursor.button[frame_ix].a = ft0::data_transfer::digital_button::a(data.digital_button) == 0;
|
||||
cursor.button[frame_ix].b = ft0::data_transfer::digital_button::b(data.digital_button) == 0;
|
||||
bool start = ft0::data_transfer::digital_button::start(data.digital_button) == 0;
|
||||
if (start) {
|
||||
cursor.x = 3.5f;
|
||||
cursor.y = 3.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (port.function_type & function_type::pointing) {
|
||||
@ -51,13 +58,23 @@ void cursor_update(struct render::cursor_state& cursor_state, uint32_t frame_ix)
|
||||
auto& data_fields = bus_data.data_fields;
|
||||
if (std::byteswap(data_fields.function_type) & function_type::pointing) {
|
||||
auto& data = data_fields.data;
|
||||
cursor.x += static_cast<float>(data.analog_coordinate_axis[0] - 0x200) * 0.0035;
|
||||
cursor.y += static_cast<float>(data.analog_coordinate_axis[1] - 0x200) * -0.0035;
|
||||
cursor.x += static_cast<float>(data.analog_coordinate_axis[0] - 0x200) * 0.0065 * invert;
|
||||
cursor.y += static_cast<float>(data.analog_coordinate_axis[1] - 0x200) * -0.0065 * invert;
|
||||
cursor.button[frame_ix].a = ft9::data_transfer::digital_button::a(data.digital_button) == 0;
|
||||
cursor.button[frame_ix].b = ft9::data_transfer::digital_button::b(data.digital_button) == 0;
|
||||
bool w = ft9::data_transfer::digital_button::w(data.digital_button) == 0;
|
||||
if (w) {
|
||||
cursor.x = 3.5f;
|
||||
cursor.y = 3.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor.x < -1.0f) cursor.x = -1.0f;
|
||||
if (cursor.x > 8.0f) cursor.x = 8.0f;
|
||||
if (cursor.y < -0.5f) cursor.y = -0.5f;
|
||||
if (cursor.y > 7.5f) cursor.y = 7.5f;
|
||||
}
|
||||
}
|
||||
|
||||
void cursor_events(chess::game_state& game_state, struct render::cursor_state& cursor_state, uint32_t frame_ix)
|
||||
@ -100,7 +117,7 @@ void main()
|
||||
|
||||
core_init();
|
||||
region_array2(640 / 32, 480 / 32, opb_size);
|
||||
background_parameter(0xff0000ff);
|
||||
background_parameter(0xff223311);
|
||||
|
||||
chess::game_state game_state;
|
||||
chess::game_init(game_state);
|
||||
@ -116,13 +133,22 @@ void main()
|
||||
vt.piece_rotation = 0.f;
|
||||
vt.board_rotation = 0.f;
|
||||
|
||||
auto piece_rotation_animator = render::animator<float>(0.f);
|
||||
|
||||
struct render::cursor_state cursor_state = render::cursor_state();
|
||||
|
||||
constexpr float pi = 3.141592653589793f;
|
||||
|
||||
while (true) {
|
||||
input::state_update(send_buf, recv_buf);
|
||||
cursor_update(cursor_state, frame_ix);
|
||||
cursor_events(game_state, cursor_state, frame_ix);
|
||||
|
||||
float target = game_state.turn == 1 ? 0.f : pi;
|
||||
piece_rotation_animator.set_target(target, 60);
|
||||
//vt.board_rotation = piece_rotation_animator.interpolate();
|
||||
//vt.piece_rotation = piece_rotation_animator.interpolate();
|
||||
|
||||
ta_polygon_converter_init(opb_size.total(),
|
||||
ta_alloc,
|
||||
640 / 32,
|
||||
|
@ -282,8 +282,8 @@ void draw_pieces(const view_transform vt,
|
||||
|
||||
uint32_t cursor_colors[4] = {
|
||||
0xffff00ff,
|
||||
0xff0000ff,
|
||||
0xff00ff00,
|
||||
0xffffff00,
|
||||
0xffff0000,
|
||||
};
|
||||
|
||||
|
@ -11,6 +11,38 @@ struct view_transform {
|
||||
float board_rotation;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct animator {
|
||||
T start;
|
||||
T end;
|
||||
int steps;
|
||||
int step;
|
||||
|
||||
constexpr animator(T initial)
|
||||
: start(initial), end(initial), steps(0), step(0)
|
||||
{ }
|
||||
|
||||
void set_target(T target_value, int target_steps)
|
||||
{
|
||||
if (target_value != end) {
|
||||
start = interpolate();
|
||||
end = target_value;
|
||||
steps = target_steps;
|
||||
step = 0;
|
||||
}
|
||||
}
|
||||
|
||||
T interpolate()
|
||||
{
|
||||
if (step == steps)
|
||||
return end;
|
||||
|
||||
T value = start + ((end - start) * step) / steps;
|
||||
step += 1;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
struct button {
|
||||
bool a;
|
||||
bool b;
|
||||
@ -22,7 +54,7 @@ struct cursor {
|
||||
struct button button[2];
|
||||
|
||||
constexpr cursor()
|
||||
: x(4.f), y(4.f)
|
||||
: x(3.5f), y(3.5f)
|
||||
{
|
||||
button[0] = {false, false};
|
||||
button[1] = {false, false};
|
||||
|
@ -15,8 +15,8 @@ namespace ft9 {
|
||||
constexpr uint32_t u() { return 0b1 << 4; }
|
||||
constexpr uint32_t u(uint32_t reg) { return (reg >> 4) & 0b1; }
|
||||
|
||||
constexpr uint32_t s() { return 0b1 << 3; }
|
||||
constexpr uint32_t s(uint32_t reg) { return (reg >> 3) & 0b1; }
|
||||
constexpr uint32_t w() { return 0b1 << 3; }
|
||||
constexpr uint32_t w(uint32_t reg) { return (reg >> 3) & 0b1; }
|
||||
|
||||
constexpr uint32_t a() { return 0b1 << 2; }
|
||||
constexpr uint32_t a(uint32_t reg) { return (reg >> 2) & 0b1; }
|
||||
|
@ -1,5 +1,5 @@
|
||||
"data_transfer",7,6,5,4,3,2,1,0
|
||||
"digital_button","r","l","d","u","s","a","b","c"
|
||||
"digital_button","r","l","d","u","w","a","b","c"
|
||||
"option",,,,,,,"batt","wire"
|
||||
"analog_coordinate_overflow",,,,,,,,
|
||||
"reserved",,,,,,,,
|
||||
|
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user