]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider_picmip.c
minelayer model with placeholder texture
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_picmip.c
1 #ifdef INTERFACE
2 CLASS(XonoticPicmipSlider) EXTENDS(XonoticTextSlider)
3         METHOD(XonoticPicmipSlider, configureXonoticPicmipSlider, void(entity))
4         METHOD(XonoticPicmipSlider, draw, void(entity))
5         METHOD(XonoticPicmipSlider, autofix, void(entity))
6 ENDCLASS(XonoticPicmipSlider)
7 entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues!
8 #endif
9
10 #ifdef IMPLEMENTATION
11 entity makeXonoticPicmipSlider()
12 {
13         entity me;
14         me = spawnXonoticPicmipSlider();
15         me.configureXonoticPicmipSlider(me);
16         return me;
17 }
18 void XonoticPicmipSlider_configureXonoticPicmipSlider(entity me)
19 {
20         me.configureXonoticTextSlider(me, "gl_picmip");
21         me.autofix(me);
22 }
23 float texmemsize()
24 {
25         return
26         (
27                   2500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_other")))
28                 + 1500 * pow(0.5, max(0, cvar("gl_picmip") + cvar("gl_picmip_world")))
29         ) * ((cvar("r_texture_dds_load") || cvar("gl_texturecompression")) ? 0.4 : 1.0); // TC: normalmaps 50%, other 25%, few incompressible, guessing 40% as conservative average
30 }
31 void XonoticPicmipSlider_autofix(entity me)
32 {
33         float max_hard, max_soft;
34         max_hard = cvar("sys_memsize_virtual");
35         max_soft = cvar("sys_memsize_physical");
36         if(max_hard > 0)
37         {
38                 while(me.value > 0 && texmemsize() > max_hard)
39                         me.setValue(me, me.value - 1);
40         }
41         // TODO also check the soft limit!
42         // TODO better handling than clamping the slider!
43 }
44 void XonoticPicmipSlider_draw(entity me)
45 {
46         me.autofix(me);
47         SUPER(XonoticPicmipSlider).draw(me);
48 }
49 #endif