diff --git a/app/src/control.c b/app/src/control.c index 0b072dff..ece452da 100644 --- a/app/src/control.c +++ b/app/src/control.c @@ -28,7 +28,7 @@ void controller_destroy(struct controller *controller) { control_event_queue_destroy(&controller->queue); } -SDL_bool controller_push_event(struct controller *controller, struct control_event *event) { +SDL_bool controller_push_event(struct controller *controller, const struct control_event *event) { SDL_bool res; mutex_lock(controller->mutex); SDL_bool was_empty = control_event_queue_is_empty(&controller->queue); @@ -40,7 +40,7 @@ SDL_bool controller_push_event(struct controller *controller, struct control_eve return res; } -static SDL_bool process_event(struct controller *controller, struct control_event *event) { +static SDL_bool process_event(struct controller *controller, const struct control_event *event) { unsigned char serialized_event[SERIALIZED_EVENT_MAX_SIZE]; int length = control_event_serialize(event, serialized_event); if (!length) { diff --git a/app/src/control.h b/app/src/control.h index 3efd14f9..14b93a2a 100644 --- a/app/src/control.h +++ b/app/src/control.h @@ -24,6 +24,6 @@ void controller_stop(struct controller *controller); void controller_join(struct controller *controller); // expose simple API to hide control_event_queue -SDL_bool controller_push_event(struct controller *controller, struct control_event *event); +SDL_bool controller_push_event(struct controller *controller, const struct control_event *event); #endif diff --git a/app/src/controlevent.c b/app/src/controlevent.c index fda49d11..9436139a 100644 --- a/app/src/controlevent.c +++ b/app/src/controlevent.c @@ -17,7 +17,7 @@ static inline void write32(Uint8 *buf, Uint32 value) { buf[3] = value; } -int control_event_serialize(struct control_event *event, unsigned char *buf) { +int control_event_serialize(const struct control_event *event, unsigned char *buf) { buf[0] = event->type; switch (event->type) { case CONTROL_EVENT_TYPE_KEYCODE: @@ -53,11 +53,11 @@ int control_event_serialize(struct control_event *event, unsigned char *buf) { } } -SDL_bool control_event_queue_is_empty(struct control_event_queue *queue) { +SDL_bool control_event_queue_is_empty(const struct control_event_queue *queue) { return queue->head == queue->tail; } -SDL_bool control_event_queue_is_full(struct control_event_queue *queue) { +SDL_bool control_event_queue_is_full(const struct control_event_queue *queue) { return (queue->head + 1) % CONTROL_EVENT_QUEUE_SIZE == queue->tail; } @@ -72,7 +72,7 @@ void control_event_queue_destroy(struct control_event_queue *queue) { // nothing to do in the current implementation } -SDL_bool control_event_queue_push(struct control_event_queue *queue, struct control_event *event) { +SDL_bool control_event_queue_push(struct control_event_queue *queue, const struct control_event *event) { if (control_event_queue_is_full(queue)) { return SDL_FALSE; } diff --git a/app/src/controlevent.h b/app/src/controlevent.h index 0c4d1f03..d0534ed2 100644 --- a/app/src/controlevent.h +++ b/app/src/controlevent.h @@ -51,16 +51,16 @@ struct control_event_queue { }; // buf size must be at least SERIALIZED_EVENT_MAX_SIZE -int control_event_serialize(struct control_event *event, unsigned char *buf); +int control_event_serialize(const struct control_event *event, unsigned char *buf); SDL_bool control_event_queue_init(struct control_event_queue *queue); void control_event_queue_destroy(struct control_event_queue *queue); -SDL_bool control_event_queue_is_empty(struct control_event_queue *queue); -SDL_bool control_event_queue_is_full(struct control_event_queue *queue); +SDL_bool control_event_queue_is_empty(const struct control_event_queue *queue); +SDL_bool control_event_queue_is_full(const struct control_event_queue *queue); // event is copied, the queue does not use the event after the function returns -SDL_bool control_event_queue_push(struct control_event_queue *queue, struct control_event *event); +SDL_bool control_event_queue_push(struct control_event_queue *queue, const struct control_event *event); SDL_bool control_event_queue_take(struct control_event_queue *queue, struct control_event *event); #endif diff --git a/app/src/convert.c b/app/src/convert.c index 0c5cf163..c063a078 100644 --- a/app/src/convert.c +++ b/app/src/convert.c @@ -117,7 +117,7 @@ static enum android_motionevent_buttons convert_mouse_buttons(Uint32 state) { return buttons; } -SDL_bool input_key_from_sdl_to_android(SDL_KeyboardEvent *from, struct control_event *to) { +SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from, struct control_event *to) { to->type = CONTROL_EVENT_TYPE_KEYCODE; if (!convert_keycode_action(from->type, &to->keycode_event.action)) { @@ -133,7 +133,7 @@ SDL_bool input_key_from_sdl_to_android(SDL_KeyboardEvent *from, struct control_e return SDL_TRUE; } -SDL_bool mouse_button_from_sdl_to_android(SDL_MouseButtonEvent *from, struct control_event *to) { +SDL_bool mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from, struct control_event *to) { to->type = CONTROL_EVENT_TYPE_MOUSE; if (!convert_mouse_action(from->type, &to->mouse_event.action)) { @@ -147,7 +147,7 @@ SDL_bool mouse_button_from_sdl_to_android(SDL_MouseButtonEvent *from, struct con return SDL_TRUE; } -SDL_bool mouse_motion_from_sdl_to_android(SDL_MouseMotionEvent *from, struct control_event *to) { +SDL_bool mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from, struct control_event *to) { to->type = CONTROL_EVENT_TYPE_MOUSE; to->mouse_event.action = AMOTION_EVENT_ACTION_MOVE; to->mouse_event.buttons = convert_mouse_buttons(from->state); @@ -157,7 +157,7 @@ SDL_bool mouse_motion_from_sdl_to_android(SDL_MouseMotionEvent *from, struct con return SDL_TRUE; } -SDL_bool mouse_wheel_from_sdl_to_android(struct complete_mouse_wheel_event *from, struct control_event *to) { +SDL_bool mouse_wheel_from_sdl_to_android(const struct complete_mouse_wheel_event *from, struct control_event *to) { to->type = CONTROL_EVENT_TYPE_SCROLL; to->scroll_event.x = from->x; diff --git a/app/src/convert.h b/app/src/convert.h index 03d3f3aa..12a89ad3 100644 --- a/app/src/convert.h +++ b/app/src/convert.h @@ -12,9 +12,9 @@ struct complete_mouse_wheel_event { Sint32 y; }; -SDL_bool input_key_from_sdl_to_android(SDL_KeyboardEvent *from, struct control_event *to); -SDL_bool mouse_button_from_sdl_to_android(SDL_MouseButtonEvent *from, struct control_event *to); -SDL_bool mouse_motion_from_sdl_to_android(SDL_MouseMotionEvent *from, struct control_event *to); -SDL_bool mouse_wheel_from_sdl_to_android(struct complete_mouse_wheel_event *from, struct control_event *to); +SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from, struct control_event *to); +SDL_bool mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from, struct control_event *to); +SDL_bool mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from, struct control_event *to); +SDL_bool mouse_wheel_from_sdl_to_android(const struct complete_mouse_wheel_event *from, struct control_event *to); #endif diff --git a/app/src/screen.c b/app/src/screen.c index efc756c1..2c749c89 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -203,8 +203,7 @@ static inline SDL_bool prepare_for_frame(SDL_Window *window, SDL_Renderer *rende return SDL_TRUE; } - -static void update_texture(AVFrame *frame, SDL_Texture *texture) { +static void update_texture(const AVFrame *frame, SDL_Texture *texture) { SDL_UpdateYUVTexture(texture, NULL, frame->data[0], frame->linesize[0], frame->data[1], frame->linesize[1], @@ -258,7 +257,7 @@ static SDL_bool handle_new_frame(void) { return SDL_TRUE; } -static void handle_text_input(SDL_TextInputEvent *event) { +static void handle_text_input(const SDL_TextInputEvent *event) { struct control_event control_event; control_event.type = CONTROL_EVENT_TYPE_TEXT; strncpy(control_event.text_event.text, event->text, TEXT_MAX_LENGTH); @@ -268,7 +267,7 @@ static void handle_text_input(SDL_TextInputEvent *event) { } } -static void handle_key(SDL_KeyboardEvent *event) { +static void handle_key(const SDL_KeyboardEvent *event) { SDL_Keycode keycode = event->keysym.sym; SDL_bool ctrl = event->keysym.mod & (KMOD_LCTRL | KMOD_RCTRL); SDL_bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT); @@ -305,7 +304,7 @@ static void handle_key(SDL_KeyboardEvent *event) { } } -static void handle_mouse_motion(SDL_MouseMotionEvent *event) { +static void handle_mouse_motion(const SDL_MouseMotionEvent *event) { struct control_event control_event; if (mouse_motion_from_sdl_to_android(event, &control_event)) { if (!controller_push_event(&controller, &control_event)) { @@ -314,7 +313,7 @@ static void handle_mouse_motion(SDL_MouseMotionEvent *event) { } } -static void handle_mouse_button(SDL_MouseButtonEvent *event) { +static void handle_mouse_button(const SDL_MouseButtonEvent *event) { struct control_event control_event; if (mouse_button_from_sdl_to_android(event, &control_event)) { if (!controller_push_event(&controller, &control_event)) { @@ -323,7 +322,7 @@ static void handle_mouse_button(SDL_MouseButtonEvent *event) { } } -static void handle_mouse_wheel(struct complete_mouse_wheel_event *event) { +static void handle_mouse_wheel(const struct complete_mouse_wheel_event *event) { struct control_event control_event; if (mouse_wheel_from_sdl_to_android(event, &control_event)) { if (!controller_push_event(&controller, &control_event)) {