Cleanup: use "g_" prefixed static walk variables, enable strict flags
This commit is contained in:
@@ -50,6 +50,8 @@
|
||||
#include "view3d_intern.h" /* own include */
|
||||
#include "view3d_navigate.hh"
|
||||
|
||||
#include "BLI_strict_flags.h"
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Modal Key-map
|
||||
* \{ */
|
||||
@@ -173,8 +175,8 @@ struct FlyInfo {
|
||||
int mval[2];
|
||||
/** Center mouse values. */
|
||||
int center_mval[2];
|
||||
/** Camera viewport dimensions. */
|
||||
float width, height;
|
||||
/** Camera viewport size. */
|
||||
float viewport_size[2];
|
||||
|
||||
#ifdef WITH_INPUT_NDOF
|
||||
/** Latest 3D mouse values. */
|
||||
@@ -226,13 +228,12 @@ static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg
|
||||
FlyInfo *fly = static_cast<FlyInfo *>(arg);
|
||||
rctf viewborder;
|
||||
int xoff, yoff;
|
||||
float x1, x2, y1, y2;
|
||||
|
||||
if (ED_view3d_cameracontrol_object_get(fly->v3d_camera_control)) {
|
||||
ED_view3d_calc_camera_border(
|
||||
fly->scene, fly->depsgraph, fly->region, fly->v3d, fly->rv3d, &viewborder, false);
|
||||
xoff = viewborder.xmin;
|
||||
yoff = viewborder.ymin;
|
||||
xoff = int(viewborder.xmin);
|
||||
yoff = int(viewborder.ymin);
|
||||
}
|
||||
else {
|
||||
xoff = 0;
|
||||
@@ -242,10 +243,10 @@ static void drawFlyPixel(const bContext * /*C*/, ARegion * /*region*/, void *arg
|
||||
/* Draws 4 edge brackets that frame the safe area where the
|
||||
* mouse can move during fly mode without spinning the view. */
|
||||
|
||||
x1 = xoff + 0.45f * fly->width;
|
||||
y1 = yoff + 0.45f * fly->height;
|
||||
x2 = xoff + 0.55f * fly->width;
|
||||
y2 = yoff + 0.55f * fly->height;
|
||||
const float x1 = float(xoff) + 0.45f * fly->viewport_size[0];
|
||||
const float y1 = float(yoff) + 0.45f * fly->viewport_size[1];
|
||||
const float x2 = float(xoff) + 0.55f * fly->viewport_size[0];
|
||||
const float y2 = float(yoff) + 0.55f * fly->viewport_size[1];
|
||||
|
||||
GPUVertFormat *format = immVertexFormat();
|
||||
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||
@@ -393,18 +394,18 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
|
||||
ED_view3d_calc_camera_border(
|
||||
fly->scene, fly->depsgraph, fly->region, fly->v3d, fly->rv3d, &viewborder, false);
|
||||
|
||||
fly->width = BLI_rctf_size_x(&viewborder);
|
||||
fly->height = BLI_rctf_size_y(&viewborder);
|
||||
fly->viewport_size[0] = BLI_rctf_size_x(&viewborder);
|
||||
fly->viewport_size[1] = BLI_rctf_size_y(&viewborder);
|
||||
|
||||
fly->center_mval[0] = viewborder.xmin + fly->width / 2;
|
||||
fly->center_mval[1] = viewborder.ymin + fly->height / 2;
|
||||
fly->center_mval[0] = int(viewborder.xmin + (fly->viewport_size[0] / 2.0f));
|
||||
fly->center_mval[1] = int(viewborder.ymin + (fly->viewport_size[1] / 2));
|
||||
}
|
||||
else {
|
||||
fly->width = fly->region->winx;
|
||||
fly->height = fly->region->winy;
|
||||
fly->viewport_size[0] = fly->region->winx;
|
||||
fly->viewport_size[1] = fly->region->winy;
|
||||
|
||||
fly->center_mval[0] = fly->width / 2;
|
||||
fly->center_mval[1] = fly->height / 2;
|
||||
fly->center_mval[0] = int(fly->viewport_size[0] / 2.0f);
|
||||
fly->center_mval[1] = int(fly->viewport_size[1] / 2.0f);
|
||||
}
|
||||
|
||||
/* Center the mouse, probably the UI mafia are against this but without its quite annoying. */
|
||||
@@ -540,7 +541,7 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event)
|
||||
}
|
||||
/* Speed adjusting with mouse-pan (track-pad). */
|
||||
case FLY_MODAL_SPEED: {
|
||||
float fac = 0.02f * (event->prev_xy[1] - event->xy[1]);
|
||||
float fac = 0.02f * float(event->prev_xy[1] - event->xy[1]);
|
||||
|
||||
/* Allowing to brake immediate. */
|
||||
if (fac > 0.0f && fly->speed < 0.0f) {
|
||||
@@ -779,9 +780,6 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
|
||||
float moffset[2]; /* Mouse offset from the views center. */
|
||||
float tmp_quat[4]; /* Used for rotating the view. */
|
||||
|
||||
/* X and Y margin defining the safe area where the mouse's movement won't rotate the view. */
|
||||
int xmargin, ymargin;
|
||||
|
||||
#ifdef NDOF_FLY_DEBUG
|
||||
{
|
||||
static uint iteration = 1;
|
||||
@@ -789,14 +787,15 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
|
||||
}
|
||||
#endif
|
||||
|
||||
xmargin = fly->width / 20.0f;
|
||||
ymargin = fly->height / 20.0f;
|
||||
/* X and Y margin defining the safe area where the mouse's movement won't rotate the view. */
|
||||
const float xmargin = fly->viewport_size[0] / 20.0f;
|
||||
const float ymargin = fly->viewport_size[1] / 20.0f;
|
||||
|
||||
{
|
||||
|
||||
/* Mouse offset from the center. */
|
||||
moffset[0] = fly->mval[0] - fly->center_mval[0];
|
||||
moffset[1] = fly->mval[1] - fly->center_mval[1];
|
||||
moffset[0] = float(fly->mval[0] - fly->center_mval[0]);
|
||||
moffset[1] = float(fly->mval[1] - fly->center_mval[1]);
|
||||
|
||||
/* Enforce a view margin. */
|
||||
if (moffset[0] > xmargin) {
|
||||
@@ -825,12 +824,12 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm)
|
||||
* the mouse moves isn't linear. */
|
||||
|
||||
if (moffset[0]) {
|
||||
moffset[0] /= fly->width - (xmargin * 2);
|
||||
moffset[0] /= fly->viewport_size[0] - (xmargin * 2);
|
||||
moffset[0] *= fabsf(moffset[0]);
|
||||
}
|
||||
|
||||
if (moffset[1]) {
|
||||
moffset[1] /= fly->height - (ymargin * 2);
|
||||
moffset[1] /= fly->viewport_size[1] - (ymargin * 2);
|
||||
moffset[1] *= fabsf(moffset[1]);
|
||||
}
|
||||
|
||||
@@ -1065,13 +1064,12 @@ static void flyApply_ndof(bContext *C, FlyInfo *fly, bool is_confirm)
|
||||
static int fly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
FlyInfo *fly;
|
||||
|
||||
if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
fly = MEM_cnew<FlyInfo>("FlyOperation");
|
||||
FlyInfo *fly = MEM_cnew<FlyInfo>("FlyOperation");
|
||||
|
||||
op->customdata = fly;
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
#include "view3d_intern.h" /* own include */
|
||||
#include "view3d_navigate.hh"
|
||||
|
||||
#include "BLI_strict_flags.h"
|
||||
|
||||
#ifdef WITH_INPUT_NDOF
|
||||
//# define NDOF_WALK_DEBUG
|
||||
/* NOTE(@ideasman42): Is this needed for NDOF? commented so redraw doesn't thrash. */
|
||||
@@ -343,7 +345,7 @@ struct WalkInfo {
|
||||
static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm);
|
||||
#endif /* WITH_INPUT_NDOF */
|
||||
static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm);
|
||||
static float getVelocityZeroTime(const float gravity, const float velocity);
|
||||
static float walk_calc_velocity_zero_time(const float gravity, const float velocity);
|
||||
|
||||
static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg)
|
||||
{
|
||||
@@ -358,8 +360,8 @@ static void drawWalkPixel(const bContext * /*C*/, ARegion *region, void *arg)
|
||||
if (ED_view3d_cameracontrol_object_get(walk->v3d_camera_control)) {
|
||||
ED_view3d_calc_camera_border(
|
||||
walk->scene, walk->depsgraph, region, walk->v3d, walk->rv3d, &viewborder, false);
|
||||
xoff = viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f;
|
||||
yoff = viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f;
|
||||
xoff = int(viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f);
|
||||
yoff = int(viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f);
|
||||
}
|
||||
else {
|
||||
xoff = walk->region->winx / 2;
|
||||
@@ -426,7 +428,6 @@ static bool walk_floor_distance_get(RegionView3D *rv3d,
|
||||
float location_dummy[3];
|
||||
float normal_dummy[3];
|
||||
float dvec_tmp[3];
|
||||
bool ret;
|
||||
|
||||
*r_distance = BVH_RAYCAST_DIST_MAX;
|
||||
|
||||
@@ -440,15 +441,15 @@ static bool walk_floor_distance_get(RegionView3D *rv3d,
|
||||
/* Avoid having to convert the edit-mesh to a regular mesh. */
|
||||
snap_params.edit_mode_type = SNAP_GEOM_EDIT;
|
||||
|
||||
ret = ED_transform_snap_object_project_ray(walk->snap_context,
|
||||
walk->depsgraph,
|
||||
walk->v3d,
|
||||
&snap_params,
|
||||
ray_start,
|
||||
ray_normal,
|
||||
r_distance,
|
||||
location_dummy,
|
||||
normal_dummy);
|
||||
const bool ret = ED_transform_snap_object_project_ray(walk->snap_context,
|
||||
walk->depsgraph,
|
||||
walk->v3d,
|
||||
&snap_params,
|
||||
ray_start,
|
||||
ray_normal,
|
||||
r_distance,
|
||||
location_dummy,
|
||||
normal_dummy);
|
||||
|
||||
/* Artificially scale the distance to the scene size. */
|
||||
*r_distance /= walk->grid;
|
||||
@@ -501,11 +502,18 @@ static bool walk_ray_cast(RegionView3D *rv3d,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Keep the previous speed and jump height until user changes preferences. */
|
||||
static float base_speed = -1.0f;
|
||||
static float userdef_speed = -1.0f;
|
||||
static float jump_height = -1.0f;
|
||||
static float userdef_jump_height = -1.0f;
|
||||
/** Keep the previous speed and jump height until user changes preferences. */
|
||||
static struct {
|
||||
float base_speed;
|
||||
float userdef_speed;
|
||||
float jump_height;
|
||||
float userdef_jump_height;
|
||||
} g_walk = {
|
||||
/*base_speed*/ -1.0f,
|
||||
/*userdef_speed*/ -1.0f,
|
||||
/*jump_height*/ -1.0f,
|
||||
/*userdef_jump_height*/ -1.0f,
|
||||
};
|
||||
|
||||
static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int mval[2])
|
||||
{
|
||||
@@ -548,14 +556,14 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int
|
||||
|
||||
walk->state = WALK_RUNNING;
|
||||
|
||||
if (fabsf(U.walk_navigation.walk_speed - userdef_speed) > 0.1f) {
|
||||
base_speed = U.walk_navigation.walk_speed;
|
||||
userdef_speed = U.walk_navigation.walk_speed;
|
||||
if (fabsf(U.walk_navigation.walk_speed - g_walk.userdef_speed) > 0.1f) {
|
||||
g_walk.base_speed = U.walk_navigation.walk_speed;
|
||||
g_walk.userdef_speed = U.walk_navigation.walk_speed;
|
||||
}
|
||||
|
||||
if (fabsf(U.walk_navigation.jump_height - userdef_jump_height) > 0.1f) {
|
||||
jump_height = U.walk_navigation.jump_height;
|
||||
userdef_jump_height = U.walk_navigation.jump_height;
|
||||
if (fabsf(U.walk_navigation.jump_height - g_walk.userdef_jump_height) > 0.1f) {
|
||||
g_walk.jump_height = U.walk_navigation.jump_height;
|
||||
g_walk.userdef_jump_height = U.walk_navigation.jump_height;
|
||||
}
|
||||
|
||||
walk->jump_height = 0.0f;
|
||||
@@ -780,11 +788,11 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event)
|
||||
break;
|
||||
}
|
||||
case WALK_MODAL_ACCELERATE: {
|
||||
base_speed *= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
|
||||
g_walk.base_speed *= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
|
||||
break;
|
||||
}
|
||||
case WALK_MODAL_DECELERATE: {
|
||||
base_speed /= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
|
||||
g_walk.base_speed /= 1.0f + (walk->is_slow ? 0.01f : 0.1f);
|
||||
break;
|
||||
}
|
||||
/* Implement WASD keys. */
|
||||
@@ -886,7 +894,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event)
|
||||
t * (JUMP_SPEED_MAX - JUMP_SPEED_MIN) / JUMP_TIME_MAX;
|
||||
|
||||
/* When jumping, duration is how long it takes before we start going down. */
|
||||
walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump);
|
||||
walk->teleport.duration = walk_calc_velocity_zero_time(walk->gravity, walk->speed_jump);
|
||||
|
||||
/* No more increase of jump speed. */
|
||||
walk->gravity_state = WALK_GRAVITY_STATE_ON;
|
||||
@@ -910,7 +918,7 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event)
|
||||
copy_v2_v2(walk->teleport.direction, walk->dvec_prev);
|
||||
|
||||
/* When jumping, duration is how long it takes before we start going down. */
|
||||
walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump);
|
||||
walk->teleport.duration = walk_calc_velocity_zero_time(walk->gravity, walk->speed_jump);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -974,11 +982,11 @@ static void walkEvent(WalkInfo *walk, const wmEvent *event)
|
||||
#define JUMP_HEIGHT_MAX 10.0f
|
||||
|
||||
case WALK_MODAL_INCREASE_JUMP: {
|
||||
jump_height = min_ff(jump_height * JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MAX);
|
||||
g_walk.jump_height = min_ff(g_walk.jump_height * JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MAX);
|
||||
break;
|
||||
}
|
||||
case WALK_MODAL_DECREASE_JUMP: {
|
||||
jump_height = max_ff(jump_height / JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MIN);
|
||||
g_walk.jump_height = max_ff(g_walk.jump_height / JUMP_HEIGHT_FACTOR, JUMP_HEIGHT_MIN);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1006,24 +1014,24 @@ static void walkMoveCamera(bContext *C,
|
||||
}
|
||||
}
|
||||
|
||||
static float getFreeFallDistance(const float gravity, const float time)
|
||||
static float walk_calc_free_fall_distance(const float gravity, const float time)
|
||||
{
|
||||
return gravity * (time * time) * 0.5f;
|
||||
}
|
||||
|
||||
static float getVelocityZeroTime(const float gravity, const float velocity)
|
||||
static float walk_calc_velocity_zero_time(const float gravity, const float velocity)
|
||||
{
|
||||
return velocity / gravity;
|
||||
}
|
||||
|
||||
static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
|
||||
{
|
||||
#define WALK_ROTATE_TABLET_FAC 8.8f /* Higher is faster, relative to region size. */
|
||||
#define WALK_ROTATE_CONSTANT_FAC DEG2RAD(0.15f) /* Higher is faster, radians per-pixel. */
|
||||
#define WALK_ROTATE_TABLET_FAC 8.8f /* Higher is faster, relative to region size. */
|
||||
#define WALK_ROTATE_CONSTANT_FAC DEG2RADF(0.15f) /* Higher is faster, radians per-pixel. */
|
||||
#define WALK_TOP_LIMIT DEG2RADF(85.0f)
|
||||
#define WALK_BOTTOM_LIMIT DEG2RADF(-80.0f)
|
||||
#define WALK_MOVE_SPEED base_speed
|
||||
#define WALK_JUMP_HEIGHT jump_height
|
||||
#define WALK_MOVE_SPEED (0 ? 0.0f : g_walk.base_speed)
|
||||
#define WALK_JUMP_HEIGHT (0 ? 0.0f : g_walk.jump_height)
|
||||
#define WALK_BOOST_FACTOR ((void)0, walk->speed_factor)
|
||||
#define WALK_ZUP_CORRECT_FAC 0.1f /* Amount to correct per step. */
|
||||
#define WALK_ZUP_CORRECT_ACCEL 0.05f /* Increase upright momentum each step. */
|
||||
@@ -1301,7 +1309,6 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
|
||||
{
|
||||
float ray_distance;
|
||||
float difference = -100.0f;
|
||||
float fall_distance;
|
||||
|
||||
if (walk_floor_distance_get(rv3d, walk, dvec, &ray_distance)) {
|
||||
difference = walk->view_height - ray_distance;
|
||||
@@ -1309,7 +1316,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
|
||||
|
||||
/* The distance we would fall naturally smoothly enough that we
|
||||
* can manually drop the object without activating gravity. */
|
||||
fall_distance = time_redraw * walk->speed * WALK_BOOST_FACTOR;
|
||||
const float fall_distance = time_redraw * walk->speed * WALK_BOOST_FACTOR;
|
||||
|
||||
if (fabsf(difference) < fall_distance) {
|
||||
/* slope/stairs */
|
||||
@@ -1342,7 +1349,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
|
||||
|
||||
const float z_cur = walk->rv3d->viewinv[3][2] / walk->grid;
|
||||
const float z_new = ((walk->teleport.origin[2] / walk->grid) -
|
||||
getFreeFallDistance(walk->gravity, t)) +
|
||||
walk_calc_free_fall_distance(walk->gravity, t)) +
|
||||
/* Jump. */
|
||||
(t * walk->speed_jump);
|
||||
|
||||
@@ -1460,13 +1467,11 @@ static void walkApply_ndof(bContext *C, WalkInfo *walk, bool is_confirm)
|
||||
static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
WalkInfo *walk;
|
||||
|
||||
if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
walk = MEM_cnew<WalkInfo>("NavigationWalkOperation");
|
||||
WalkInfo *walk = MEM_cnew<WalkInfo>("NavigationWalkOperation");
|
||||
|
||||
op->customdata = walk;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user