Make vehicles fully framerate independent

isolation_bkp/dynres
Dominik Madarász 2021-10-27 14:32:52 +02:00
parent 4ca2dc4e96
commit a607515424
3 changed files with 19 additions and 17 deletions

View File

@ -74,20 +74,20 @@ entity_view world_build_entity_view(int64_t e) {
view.selected_item = in->selected_item; view.selected_item = in->selected_item;
} }
Chunk *chpos = 0; Chunk *chunk = 0;
if ((chpos = ecs_get_mut_if(world_ecs(), e, Chunk))) { if ((chunk = ecs_get_mut_if(world_ecs(), e, Chunk))) {
view.x = chpos->x; view.x = chunk->x;
view.y = chpos->y; view.y = chunk->y;
view.blocks_used = 1; view.blocks_used = 1;
view.is_dirty = chpos->is_dirty; view.is_dirty = chunk->is_dirty;
chpos->is_dirty = false; chunk->is_dirty = false;
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.blocks[i] = world.block_mapping[chpos->id][i]; view.blocks[i] = world.block_mapping[chunk->id][i];
} }
for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) { for (int i = 0; i < world.chunk_size*world.chunk_size; i += 1) {
view.outer_blocks[i] = world.outer_block_mapping[chpos->id][i]; view.outer_blocks[i] = world.outer_block_mapping[chunk->id][i];
} }
} }

View File

@ -80,7 +80,8 @@ void EnterVehicle(ecs_iter_t *it) {
#define VEHICLE_FORCE 340.8f #define VEHICLE_FORCE 340.8f
#define VEHICLE_ACCEL 0.12f #define VEHICLE_ACCEL 0.12f
#define VEHICLE_DECEL 0.28f #define VEHICLE_DECEL 0.28f
#define VEHICLE_STEER 3.89f #define VEHICLE_STEER 9.89f
#define VEHICLE_STEER_REVERT 6.0941816f
#define VEHICLE_POWER 34.89f #define VEHICLE_POWER 34.89f
#define VEHICLE_BRAKE_FORCE 0.84f #define VEHICLE_BRAKE_FORCE 0.84f
@ -112,9 +113,9 @@ void VehicleHandling(ecs_iter_t *it) {
if (zpl_abs(car->force) < 5.5f) if (zpl_abs(car->force) < 5.5f)
car->force = 0.0f; car->force = 0.0f;
} }
car->steer *= 0.97f; car->steer = zpl_lerp(car->steer, 0.0f, safe_dt(it)*VEHICLE_STEER_REVERT);
car->steer += (in->x * VEHICLE_STEER)*safe_dt(it); car->steer += (in->x * VEHICLE_STEER)*safe_dt(it);
car->steer = zpl_clamp(car->steer, -40.0f, 40.0f); car->steer = zpl_clamp(car->steer, -60.0f, 60.0f);
} }
} }
@ -130,13 +131,13 @@ void VehicleHandling(ecs_iter_t *it) {
world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y); world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y);
float drag = zpl_clamp(blocks_get_drag(lookup.block_id), 0.0f, 1.0f); float drag = zpl_clamp(blocks_get_drag(lookup.block_id), 0.0f, 1.0f);
bk_x += car->force * drag * zpl_cos(car->heading); bk_x += car->force * drag * zpl_cos(car->heading) * safe_dt(it);
bk_y += car->force * drag * zpl_sin(car->heading); bk_y += car->force * drag * zpl_sin(car->heading) * safe_dt(it);
fr_x += car->force * drag * zpl_cos(car->heading + zpl_to_radians(car->steer)); fr_x += car->force * drag * zpl_cos(car->heading + zpl_to_radians(car->steer)) * safe_dt(it)*VEHICLE_POWER;
fr_y += car->force * drag * zpl_sin(car->heading + zpl_to_radians(car->steer)); fr_y += car->force * drag * zpl_sin(car->heading + zpl_to_radians(car->steer)) * safe_dt(it)*VEHICLE_POWER;
v[i].x += ((fr_x + bk_x) / 2.0f - p[i].x)*safe_dt(it)*VEHICLE_POWER; v[i].x += ((fr_x + bk_x) / 2.0f - p[i].x);
v[i].y += ((fr_y + bk_y) / 2.0f - p[i].y)*safe_dt(it)*VEHICLE_POWER; v[i].y += ((fr_y + bk_y) / 2.0f - p[i].y);
car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x); car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x);
world_block_lookup lookahead = world_block_from_realpos(p[i].x+PHY_LOOKAHEAD(v[i].x), p[i].y+PHY_LOOKAHEAD(v[i].y)); world_block_lookup lookahead = world_block_from_realpos(p[i].x+PHY_LOOKAHEAD(v[i].x), p[i].y+PHY_LOOKAHEAD(v[i].y));

View File

@ -1,4 +1,5 @@
@echo off @echo off
call package.bat call package.bat
cls
pkg\eco2d.exe -d %* pkg\eco2d.exe -d %*