From 8d21f39ad983e3d686efe37db4c1413b3d5a7c73 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 30 Apr 2017 21:15:05 +0200 Subject: [PATCH] more mouse code cleanup - remove sensitivity training (should be rewritten in cubescript, if actually required) - more documentation on mouse sensitivity parameters - some renaming DOCREF findsens --- source/src/main.cpp | 14 +--- source/src/physics.cpp | 143 ++++----------------------------------- source/src/rendergl.cpp | 12 ++-- source/src/renderhud.cpp | 2 - 4 files changed, 20 insertions(+), 151 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index b8bd02e1..020e7972 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -755,20 +755,8 @@ void checkinput() case SDL_KEYDOWN: case SDL_KEYUP: - extern bool senst; entropy_add_byte(event.key.keysym.sym ^ totalmillis); - if (event.key.keysym.sym <= SDLK_5 && event.key.keysym.sym >= SDLK_1 && senst) - { - if (event.key.state==SDL_PRESSED) - { - extern int tsens(int x); - tsens(event.key.keysym.sym); - } - } - else - { - keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, event.key.keysym.unicode, event.key.keysym.mod); - } + keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, event.key.keysym.unicode, event.key.keysym.mod); break; case SDL_ACTIVEEVENT: diff --git a/source/src/physics.cpp b/source/src/physics.cpp index f880b97d..825c1927 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -905,153 +905,36 @@ void fixcamerarange(physent *cam) while(cam->yaw>=360.0f) cam->yaw -= 360.0f; } -FVARP(sensitivity, 1e-3f, 3.0f, 1000.0f); -FVARP(scopesensscale, 1e-3f, 0.5f, 1000.0f); -FVARP(sensitivityscale, 1e-3f, 1, 1000); -FVARP(scopesens, 0, 0, 1000); -VARP(invmouse, 0, 0, 1); -FVARP(mouseaccel, 0, 0, 1000); -FVARP(mfilter, 0.0f, 0.0f, 6.0f); -VARP(autoscopesens, 0, 0, 1); +FVARP(sensitivity, 1e-3f, 3.0f, 1000.0f); // general mouse sensitivity ("unscoped") +FVARP(scopesens, 0, 0, 1000); // scoped mouse sensitivity (if zero, autoscopesens determines, how sensitivity is changed during scoping) +FVARP(sensitivityscale, 1e-3f, 1, 1000); // scale all sensitivity values (if unsure, keep at default value "1"- this parameter achieves cosmetic value changes only) -float testsens=0; -bool senst=0; -int tsens(int x) -{ - static bool highlock=0,lowlock=0; - static bool hightry=0,lowtry=0; - static float sensn=0,sensl=0,sensh=0; - static int nstep=1; - if (x==-2000) { // RENDERING PART!!! - if(senst) { - draw_textf( - "\fJSensitivity Training (hotkeys):\n\fE1. try High Sens. %s\n2. try Low Sens. %s\n\fJ%s :" - "\fE\n3. choose: High Sens.\n4. choose: Low Sens.\n\fIrepeat the steps above until the training stops.\n\f35. Stop Training.", - VIRTW/4 , VIRTH/3, - hightry?"(TRIED)":"" , lowtry?"(TRIED)":"", - hightry&&lowtry?"after trying both choose the one you liked most":"now you can choose the sensitivity you preferred"); - glPushMatrix(); glScalef(2,2,2); - draw_textf("step: \f0%d",VIRTW/2 , VIRTH/3*2,nstep); - glPopMatrix(); - } - return 0; - } - if (x == SDLK_3 || x == SDLK_4) - { - if(!hightry || !lowtry) { - if(!hightry && !lowtry) { - conoutf("--- \f3ERROR:\f0before choosing a sensitivity, first try both higher and lower sens."); - } else { - conoutf("--- \f3ERROR:\f0try the %s%ser sensitivity too.",hightry?"":"high",lowtry?"":"low"); - } - } else { - if (x == SDLK_3) //high sens - { - lowlock=1; - if (highlock) - { - sensl=sensn; - sensn=(sensh+sensl)/2.0f; - } - else - { - sensl=sensn; - sensn=sensh; - sensh=sensn*2.0f; - } - } - if (x == SDLK_4) //low sens - { - highlock=1; - if (lowlock) - { - sensh=sensn; - sensn=(sensh+sensl)/2.0f; - } - else - { - sensh=sensn; - sensn=sensl; - sensl=sensn/2.0f; - } - } - if(sensh/sensn > 1.04f) { - conoutf("--- \f0you chose the %ser sensitivity.",x==SDLK_3?"higher":"lower"); - conoutf("--- \f0repeat previous steps by trying both higher and lower sens and then by choosing the one you like most."); - hudoutf("next step!"); - nstep++; - } - testsens=sensn; - hightry=lowtry=0; - } +VARP(autoscopesens, 0, 0, 1); // switches between scopesensscale and autoscopesensscale to calculate a scoped sensitivity (if scopesens is 0) +FVARP(scopesensscale, 1e-3f, 0.5f, 1000.0f); // if scoped, sens = sensitivity * scopesensscale (roughly) +float autoscopesensscale = 0.4663077f; // roughly scopefov/fov, recalculated if fov or scopefov changes (init value fits defaults fov 90 and scopefov 50, update, if defaults change) - } - if (x == SDLK_2) - { - testsens=sensl; - conoutf("--- \f0You are now %strying the lower sensitivity.",lowtry?"re-":""); lowtry=1; - } - if (x == SDLK_1) - { - testsens=sensh; - conoutf("--- \f0You are now %strying the higher sensitivity.",hightry?"re-":""); hightry=1; - } - if (x==-1000) - { - float factor=rnd(800)+600; - factor/=1000; - sensh=sensitivity*factor*2.0f; - sensl=sensitivity*factor/2.0f; - sensn=sensitivity*factor; - } - if (sensh/sensn <= 1.04f || x == SDLK_5) - { - senst=0; - if(sensh/sensn <= 1.04f) { - conoutf("--- \f0Sensitivity Training Ended. happy fragging."); - sensitivity=sensn; - } else { - conoutf("--- \f0Sensitivity Training Stopped."); - } - hightry=lowtry=highlock=lowlock=0; - sensn=sensl=sensh=0; - testsens=0; - nstep=1; - } - return 0; -} - -void findsens() -{ - if(!watchingdemo) { - senst=1; - tsens(-1000); - testsens=sensitivity; - conoutf("--- \f0Sensitivity Training Started."); - return; - } -} -COMMAND(findsens, ""); +VARP(invmouse, 0, 0, 1); // invert y-axis movement (if "1") +FVARP(mouseaccel, 0, 0, 1000); // make fast movement even faster (zero deactivates the feature) +FVARP(mfilter, 0.0f, 0.0f, 6.0f); // simple lowpass filtering (zero deactivates the feature) void mousemove(int idx, int idy) { - static float fdx = 0, fdy = 0; if(intermission || (player1->isspectating() && player1->spectatemode==SM_FOLLOW1ST)) return; bool zooming = player1->weaponsel->type == GUN_SNIPER && ((sniperrifle *)player1->weaponsel)->scoped; // check if player uses scope float dx = idx, dy = idy; if(mfilter > 0.0001f) - { // simple IIR filter (1st order lowpass) + { // simple IIR-like filter (1st order lowpass) + static float fdx = 0, fdy = 0; float k = mfilter * 0.1f; dx = fdx = dx * ( 1.0f - k ) + fdx * k; dy = fdy = dy * ( 1.0f - k ) + fdy * k; } - extern float scopesensfunc; - double cursens = senst ? testsens : sensitivity; // basic unscoped sensitivity + double cursens = sensitivity; // basic unscoped sensitivity if(mouseaccel > 0.0001f && curtime && (idx || idy)) cursens += 0.02f * mouseaccel * sqrtf(dx*dx + dy*dy)/curtime; // optionally accelerated if(zooming) { // when scoped: if(scopesens > 0.0001f) cursens = scopesens; // if specified, use dedicated (fixed) scope sensitivity - else cursens *= autoscopesens ? scopesensfunc : scopesensscale; // or adjust sensitivity by given (fixed) factor or based on fov/scopefov + else cursens *= autoscopesens ? autoscopesensscale : scopesensscale; // or adjust sensitivity by given (fixed) factor or based on scopefov/fov } cursens /= 33.0f * sensitivityscale; // final scaling diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index ec2650e9..0873e9ab 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -464,14 +464,14 @@ void fixresizedscreen() #endif } -float scopesensfunc = 0.4663077f; -void scopefunc(); -FVARFP(fov, 75, 90, 120, scopefunc()); -VARFP(scopefov, 5, 50, 60, scopefunc()); +void fovchanged(); +FVARFP(fov, 75, 90, 120, fovchanged()); +VARFP(scopefov, 5, 50, 60, fovchanged()); VARP(spectfov, 5, 110, 120); -void scopefunc() +void fovchanged() { - scopesensfunc = tan(((float)scopefov)*0.5f*RAD)/tan(fov*0.5f*RAD); + extern float autoscopesensscale; + autoscopesensscale = tan(((float)scopefov)*0.5f*RAD)/tan(fov*0.5f*RAD); } float dynfov() diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index ee6759a5..551b8a53 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -848,8 +848,6 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat else if(targetplayer && showtargetname) draw_text(colorname(targetplayer), HUDPOS_X_BOTTOMLEFT, HUDPOS_Y_BOTTOMLEFT); glLoadIdentity(); glOrtho(0, VIRTW*2, VIRTH*2, 0, -1, 1); - extern int tsens(int x); - tsens(-2000); extern void r_accuracy(int h); extern void *scoremenu; extern gmenu *curmenu;