|
|
|
@ -364,8 +364,8 @@ void set_motor_max_velocity(Body *thing, int motorID, double max) {
@@ -364,8 +364,8 @@ void set_motor_max_velocity(Body *thing, int motorID, double max) {
|
|
|
|
|
thing->motors[motorID].max_velocity = max; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void set_motor_ttl(Body *thing, int motorID, double ttl) { |
|
|
|
|
thing->motors[motorID].TTL = ttl; |
|
|
|
|
void set_motor_timeout(Body *thing, int motorID, uint32_t timeout) { |
|
|
|
|
thing->motors[motorID].timeout = timeout; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void set_motor_newtons(Body *thing, int motorID, double x, double y) { |
|
|
|
@ -386,7 +386,7 @@ void add_motor(Body *thing, double x, double y) {
@@ -386,7 +386,7 @@ void add_motor(Body *thing, double x, double y) {
|
|
|
|
|
motor.x = x; |
|
|
|
|
motor.y = y; |
|
|
|
|
|
|
|
|
|
motor.TTL = INFINITY; |
|
|
|
|
motor.timeout = -1; |
|
|
|
|
motor.max_velocity = 999899; |
|
|
|
|
|
|
|
|
|
motor.update_motor = default_motor_curve; |
|
|
|
@ -448,13 +448,15 @@ void advance_thing(Body * thing) {
@@ -448,13 +448,15 @@ void advance_thing(Body * thing) {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint32_t time_delta = SDL_GetTicks() - thing->last_advance_time ; |
|
|
|
|
uint32_t now = SDL_GetTicks(); |
|
|
|
|
|
|
|
|
|
uint32_t time_delta = now - thing->last_advance_time ; |
|
|
|
|
thing->last_advance_time = SDL_GetTicks(); // in milliseconds
|
|
|
|
|
//time_delta = 17;
|
|
|
|
|
|
|
|
|
|
// motors
|
|
|
|
|
for (int i = 0; i < thing->num_motors; i++) { |
|
|
|
|
if (thing->motors[i].TTL <= 0) { |
|
|
|
|
if (thing->motors[i].timeout < now) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -469,10 +471,6 @@ void advance_thing(Body * thing) {
@@ -469,10 +471,6 @@ void advance_thing(Body * thing) {
|
|
|
|
|
double dirF = atan2(F.y, F.x); |
|
|
|
|
double dirV = atan2(V.y, V.x); |
|
|
|
|
|
|
|
|
|
if (thing->motors[i].TTL != INFINITY) { |
|
|
|
|
thing->motors[i].TTL--; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double diff = dirV > dirF ? dirV - dirF: dirF - dirV; |
|
|
|
|
|
|
|
|
|
if (thing->motors[i].max_velocity > vect_mag(vel_in_dir) |
|
|
|
@ -625,8 +623,6 @@ void step(int interval) {
@@ -625,8 +623,6 @@ void step(int interval) {
|
|
|
|
|
const uint8_t * keyboard; |
|
|
|
|
keyboard = SDL_GetKeyboardState(NULL); |
|
|
|
|
|
|
|
|
|
//set_motor_ms(&player.physics, 0 ,0);
|
|
|
|
|
//
|
|
|
|
|
set_motor_newtons(player.physics, M_PLAYER_WALK, 0, 0); |
|
|
|
|
|
|
|
|
|
if (keyboard[SDL_SCANCODE_W]) { |
|
|
|
@ -643,9 +639,9 @@ void step(int interval) {
@@ -643,9 +639,9 @@ void step(int interval) {
|
|
|
|
|
&& !keyboard[SDL_SCANCODE_A] |
|
|
|
|
&& !keyboard[SDL_SCANCODE_S] |
|
|
|
|
&& !keyboard[SDL_SCANCODE_D]) { |
|
|
|
|
set_motor_ttl(player.physics, M_PLAYER_WALK, 90);
|
|
|
|
|
set_motor_timeout(player.physics, M_PLAYER_WALK, SDL_GetTicks()+1000*2);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
advance_things(); |
|
|
|
|
logwrite(DEBUG, "Update Physics \n"); |
|
|
|
|
logwrite(DEBUG, "Updated Physics \n"); |
|
|
|
|
} |
|
|
|
|