/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugFPS = [ PFPS_instance : PInstance, PFPS_iMinFps : I, PFPS_iMaxLag : I, PFPS_iLagTick : I, PFPS_iLastTick : I, PFPS_iNb : I, PFPS_bDownsample : I, PFPS_fRatio : F ] MkPlugFPS;; var iCountFPS = 30;; fun deleteOb(inst, obstr)= setPluginInstanceCbPreRender inst nil; if (!obstr.PFPS_bDownsample) then nil else let (V3DgetSessionView c3dXsession) -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let SO3BufferGetStereoMode viewstr.V3D_buffer -> mode in ( //SO3DebugSetEnable viewportstr.V3D_viewport 0; if (mode != SO3_SM_MONO) then nil else SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_NONE; //reset to auto if (mode == SO3_SM_OCULUS2 || mode == SO3_SM_OCULUS) then nil else SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer [1 1] [1 1]; ); 0;; fun ResetCount(inst, from, action, param, rep, obstr)= set obstr.PFPS_iLagTick = 0; set obstr.PFPS_iNb = 0; set obstr.PFPS_fRatio = 1.0; if (!obstr.PFPS_bDownsample) then nil else let (V3DgetSessionView c3dXsession) -> viewstr in let SO3BufferGetStereoMode viewstr.V3D_buffer -> mode in ( if (mode != SO3_SM_MONO) then nil else SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_NONE; //reset to auto if (mode == SO3_SM_OCULUS2 || mode == SO3_SM_OCULUS) then nil else SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer [1 1] [1 1]; ); 0;; fun setMinimumFPS(inst, from, action, param, rep, obstr)= if (param == nil) || ((atoi param) <= 0) then nil else ( set obstr.PFPS_iMinFps = (atoi param); set obstr.PFPS_iLagTick = 0; set obstr.PFPS_iNb = 0; ); 0;; fun cbResizeCtrl(inst, viewstr, vw, vh, obstr)= if (!obstr.PFPS_bDownsample) then nil else let SO3BufferGetStereoMode viewstr.V3D_buffer -> mode in if (mode == SO3_SM_OCULUS2 || mode == SO3_SM_OCULUS) then nil else ( let [ftoi ((itof vw) *. obstr.PFPS_fRatio) ftoi ((itof vh) *. obstr.PFPS_fRatio)] -> [nw nh] in if (nw < 32) || (nh < 32) then nil else ( SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer [nw nh] [nw nh]; ); ); 0;; fun cbCalcFps(inst, sessionstr, etime, obstr)= if ((_tickcount - obstr.PFPS_iLastTick) < 200) then nil else let (V3DgetSessionView c3dXsession) -> viewstr in let ftoi SO3BufferGetAverageFPS viewstr.V3D_buffer -> curfps in let if curfps >= obstr.PFPS_iMinFps then 0 else 1 -> islag in let V3DgetDefaultCamera sessionstr -> cam in ( set obstr.PFPS_iLastTick = _tickcount; //addLogMessage strcat ">> FPS : " (itoa curfps); SendPluginEvent inst "FPS" (itoa curfps) nil; SendPluginEvent inst "Polygon count" (itoa (SO3CameraGetTriangleCount cam)) nil; SendPluginEvent inst "Batch count" (itoa (SO3CameraGetBatchCount cam)) nil; if (islag) then ( set obstr.PFPS_iNb = obstr.PFPS_iNb + 1; ) else ( set obstr.PFPS_iNb = 0; set obstr.PFPS_iLagTick = 0; ); if ((obstr.PFPS_iNb < iCountFPS) || (obstr.PFPS_iLagTick != 0)) then nil else set obstr.PFPS_iLagTick = _tickcount; if ((obstr.PFPS_iNb > iCountFPS) && ((_tickcount - obstr.PFPS_iLagTick) > obstr.PFPS_iMaxLag)) then ( if (!obstr.PFPS_bDownsample) then ( SendPluginEvent inst "Low FPS detected" nil nil; 0; ) else ( if (obstr.PFPS_fRatio <=. 0.5) then ( SendPluginEvent inst "Low FPS detected" nil nil; 0; ) else ( set obstr.PFPS_fRatio = obstr.PFPS_fRatio -. 0.1; let SO3BufferGetStereoMode viewstr.V3D_buffer -> mode in if (mode == SO3_SM_OCULUS2 || mode == SO3_SM_OCULUS) then nil else ( if (mode != SO3_SM_NONE) then nil else SO3BufferSetStereoMode viewstr.V3D_buffer SO3_SM_MONO; let (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let [ftoi ((itof vw) *. obstr.PFPS_fRatio) ftoi ((itof vh) *. obstr.PFPS_fRatio)] -> [nw nh] in if (nw < 32) || (nh < 32) then nil else ( SO3BufferSetStereoMeshTextureSize viewstr.V3D_buffer [nw nh] [nw nh]; ); ); 0; ); ); addLogMessage strcatn "OS3D Low FPS detected "::(itoa curfps)::" for "::(itoa (_tickcount - obstr.PFPS_iLagTick))::" millisecond."::nil; set obstr.PFPS_iNb = 0; set obstr.PFPS_iLagTick = 0; ) else nil; ); 0;; fun getBoolString(b)= if b then "Yes" else "No";; fun sysConfig(obstr)= setPluginInstanceCbScenePreRender obstr.PFPS_instance mkfun4 @cbCalcFps obstr; setPluginInstanceCbResizeView obstr.PFPS_instance mkfun5 @cbResizeCtrl obstr; /*let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in SO3DebugSetEnable viewportstr.V3D_viewport 1; let _getmodifypack strcatn "stats/dcns_perf/system"::".csv"::nil -> wfile in let "2" -> minNbProc in let "1024" -> minRam in let "vs_2_0" -> minVPprofile in let "ps_2_0" -> minFPprofile in let "vs_3_0" -> minVPprofile3 in let "ps_3_0" -> minFPprofile3 in let SO3GetGeneralInfo -> [vendeurCPU nameCPU nbProcesseurs RAM OS GraphicCard Driver versionDirectX] in let SO3GetRenderInfo -> [maxtex nonpow nonpowlimited automipmap cubemap geoprog vertprog fragprog comptex fixedfun] in ( _appendpack (strcat vendeurCPU ";") wfile; _appendpack (strcat nameCPU ";") wfile; _appendpack (strcat nbProcesseurs ";") wfile; _appendpack (strcat RAM ";") wfile; _appendpack (strcat OS ";") wfile; _appendpack (strcat GraphicCard ";") wfile; _appendpack (strcat Driver ";") wfile; _appendpack (strcat versionDirectX ";") wfile; _appendpack (strcat getBoolString maxtex ";") wfile; _appendpack (strcat getBoolString nonpow ";") wfile; _appendpack (strcat getBoolString nonpowlimited ";") wfile; _appendpack (strcat getBoolString automipmap ";") wfile; _appendpack (strcat getBoolString cubemap ";") wfile; _appendpack (strcat getBoolString geoprog ";") wfile; _appendpack (strcat getBoolString vertprog ";") wfile; _appendpack (strcat getBoolString fragprog ";") wfile; _appendpack (strcat getBoolString comptex ";") wfile; _appendpack (strcat getBoolString fixedfun ";") wfile; _appendpack (strcat (getBoolString (SO3IsShaderProfileSupported minVPprofile)) ";") wfile; _appendpack (strcat (getBoolString (SO3IsShaderProfileSupported minFPprofile)) ";") wfile; _appendpack (strcat (getBoolString (SO3IsShaderProfileSupported minVPprofile3)) ";") wfile; _appendpack (strcat (getBoolString (SO3IsShaderProfileSupported minFPprofile3)) ";") wfile; _fooS strcat "Constructor : " vendeurCPU; _fooS strcat "Cpu : " nameCPU; _fooS strcat "Nb Cpu : " nbProcesseurs; _fooS strcat "RAM (32bits) : " RAM; _fooS strcat "OS : " OS; _fooS strcat "Graphic card : " GraphicCard; _fooS strcat "CG Driver : " Driver; _fooS strcat "DirectX version : " versionDirectX; _fooS strcat "Maximum textures : " getBoolString maxtex; _fooS strcat "Non power of two textures support : " getBoolString nonpow; _fooS strcat "Non power of two textures support limited : " getBoolString nonpowlimited; _fooS strcat "Auto mipmap support : " getBoolString automipmap; _fooS strcat "Cube map support : " getBoolString cubemap; _fooS strcat "Geometry programs support : " getBoolString geoprog; _fooS strcat "Vertex programs support : " getBoolString vertprog; _fooS strcat "Fragment programs support : " getBoolString fragprog; _fooS strcat "Textures compression support : " getBoolString comptex; _fooS strcat "Fixed functions support : " getBoolString fixedfun; _fooS strcatn "Vertex program profile support for "::minVPprofile::" : "::(getBoolString (SO3IsShaderProfileSupported minVPprofile))::nil; _fooS strcatn "Fragment program profile support for "::minFPprofile::" : "::(getBoolString (SO3IsShaderProfileSupported minFPprofile))::nil; _fooS strcatn "Vertex program profile support for "::minVPprofile3::" : "::(getBoolString (SO3IsShaderProfileSupported minVPprofile3))::nil; _fooS strcatn "Fragment program profile support for "::minFPprofile3::" : "::(getBoolString (SO3IsShaderProfileSupported minFPprofile3))::nil; let if ((atoi minNbProc) == nil) || ((atoi nbProcesseurs) >= (atoi minNbProc)) then 1 else 0 -> nbp in let if ((atoi minRam) == nil) || ((atoi RAM) >= (atoi minRam)) then 1 else 0 -> ramp in let if (minVPprofile == nil) || (SO3IsShaderProfileSupported minVPprofile) then 1 else 0 -> vpp in let if (minFPprofile == nil) || (SO3IsShaderProfileSupported minFPprofile) then 1 else 0 -> fpp in ( if (nbp && ramp && vpp && fpp) then ( _fooS "Configuration : valid"; _appendpack (strcat "Configuration : valid" ";\n") wfile; ) else ( _fooS "Configuration : not valid"; _appendpack (strcat "Configuration : not valid" ";\n") wfile; 0; ); ); );*/ 0;; fun cbInitPlugs(inst, obstr)= sysConfig obstr; 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "minfps") -> minfps in let if minfps == nil then 20 else minfps -> minfps in let atoi (getPluginInstanceParam inst "maxlag") -> maxlag in let if maxlag == nil then 2000 else maxlag -> maxlag in let /*atoi (getPluginInstanceParam inst "downsample")*/ 0 -> downsample in let if downsample == nil then 0 else downsample -> downsample in let MkPlugFPS [inst minfps maxlag 0 0 0 downsample 1.0] -> obstr in ( PluginRegisterAction inst "Set minimum FPS" mkfun6 @setMinimumFPS obstr; PluginRegisterAction inst "Reset" mkfun6 @ResetCount obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; if inst.INST_groupstr.GRP_project.PRJ_bPluginsLoaded then ( sysConfig obstr; 0; ) else ( setPluginInstanceCbAllPluginsLoaded inst mkfun2 @cbInitPlugs obstr; 0; ); ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;