Commit e459d8ee authored by François Heremans's avatar François Heremans
Browse files

user inputs same function SDL/websocket

parent 2f8ee663
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#include "realtime.h" #include "realtime.h"
#include "events_sdl.h"
#include "user_realtime.h" #include "user_realtime.h"
#ifdef SDL
#if defined(REAL_TIME)
/*! \brief handle inputs comming from the keyboard /*! \brief handle inputs comming from the keyboard
* *
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* wait_key(realtime, cur_t_usec, 0.1); * wait_key(realtime, cur_t_usec, 0.1);
* } * }
*/ */
void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int cur_t_usec, const Uint8 *keystates) void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int cur_t_usec, const uint8_t *keystates)
{ {
} }
...@@ -94,9 +94,3 @@ void user_joystick_buttons(MbsData* mbs_data, int buttonID) ...@@ -94,9 +94,3 @@ void user_joystick_buttons(MbsData* mbs_data, int buttonID)
} }
#endif #endif
#ifdef WEBSOCKET
void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int keyevent, int state){
}
#endif
\ No newline at end of file
...@@ -124,6 +124,11 @@ function(flags_check) ...@@ -124,6 +124,11 @@ function(flags_check)
set( FLAG_OPEN_GL OFF ) set( FLAG_OPEN_GL OFF )
endif( ) endif( )
# SDL only if no websocket
if (FLAG_WEBSOCKET)
set( FLAG_PLOT OFF )
endif( )
# separate build # separate build
if (NOT FLAG_SEPARATE_BUILD) if (NOT FLAG_SEPARATE_BUILD)
set( FLAG_SEPARATE_SYMBOLIC OFF ) set( FLAG_SEPARATE_SYMBOLIC OFF )
......
...@@ -9,14 +9,20 @@ ...@@ -9,14 +9,20 @@
#include "user_realtime_visu.h" #include "user_realtime_visu.h"
#include <stdint.h> #include <stdint.h>
#ifdef SDL #ifdef SDL
#include "SDL.h" #include "SDL.h"
#include "events_sdl.h"
#endif
#if defined(SDL) || defined(WEBSOCKET)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void user_realtime_plot(MbsData* mbs_data); void user_realtime_plot(MbsData* mbs_data);
void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int cur_t_usec, const Uint8 *keystates); void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int cur_t_usec, const uint8_t *keystates);
void user_joystick_axes(MbsData* mbs_data, Simu_realtime *realtime, int nb_joysticks); void user_joystick_axes(MbsData* mbs_data, Simu_realtime *realtime, int nb_joysticks);
void user_joystick_buttons(MbsData* mbs_data, int buttonID); void user_joystick_buttons(MbsData* mbs_data, int buttonID);
void wait_key(Simu_realtime *realtime, int cur_t_usec, double tsim); void wait_key(Simu_realtime *realtime, int cur_t_usec, double tsim);
...@@ -25,17 +31,6 @@ extern "C" { ...@@ -25,17 +31,6 @@ extern "C" {
#endif #endif
#endif #endif
#ifdef WEBSOCKET
#ifdef __cplusplus
extern "C" {
#endif
void user_realtime_plot(MbsData* mbs_data);
void user_keyboard(MbsData* mbs_data, Simu_realtime *realtime, int keyevent, int state);
#ifdef __cplusplus
}
#endif
#endif
#endif #endif
......
...@@ -27,6 +27,9 @@ struct pollfd pfds[1]; // More if you want to monitor more ...@@ -27,6 +27,9 @@ struct pollfd pfds[1]; // More if you want to monitor more
bool pause_sim = false; bool pause_sim = false;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
#define KEYS_LEN 256
uint8_t key_states[KEYS_LEN];
#define PORT 65432 #define PORT 65432
#define START_VIEWPOINT 0 ///< default initial viewpoint #define START_VIEWPOINT 0 ///< default initial viewpoint
#define FRAMERATE 18.0 #define FRAMERATE 18.0
...@@ -72,6 +75,10 @@ void init_websocket(Realtime_visu *visu, MbsData *mbs_data, int nb_models, int * ...@@ -72,6 +75,10 @@ void init_websocket(Realtime_visu *visu, MbsData *mbs_data, int nb_models, int *
std::cout << "Nb_models for anim should be positive (not " << nb_models << ") !" << std::endl; std::cout << "Nb_models for anim should be positive (not " << nb_models << ") !" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for(int i=0; i<KEYS_LEN; ++i){
key_states[i] = 0;
}
visu_in = new VisuIn; visu_in = new VisuIn;
...@@ -196,7 +203,8 @@ void process_msg(Simu_realtime *realtime){ ...@@ -196,7 +203,8 @@ void process_msg(Simu_realtime *realtime){
state = (int) subobject->number_; state = (int) subobject->number_;
// Apply the key press actions // Apply the key press actions
user_keyboard(mbs_data, realtime, key, state); key_states[key] = state;
user_keyboard(mbs_data, realtime, 0, key_states);
} }
// Check if message is of type speedControl // Check if message is of type speedControl
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment