Announcement

Collapse
No announcement yet.

Trying to understand darkplaces source code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Hm, the enviroment is so strict because of the -Wall option in the makefile, it enables all warnings. I could just disable it, but, decided to look at what they report first. And I'm scared of changing too much.


    Rewrote that function with macros, not sure if it's better this way.

    Code:
    static void RotateBBox(const vec3_t mins, const vec3_t maxs, const vec3_t angles, vec3_t rotatedmins, vec3_t rotatedmaxs)
    {
    #define _vec3_min(rotatedmins, u) \
        if(rotatedmins[0] > u[0]) rotatedmins[0] = u[0]; \
        if(rotatedmins[1] > u[1]) rotatedmins[1] = u[1]; \
        if(rotatedmins[2] > u[2]) rotatedmins[2] = u[2];
    #define _vec3_max(rotatedmaxs, u) \
        if(rotatedmaxs[0] > u[0]) rotatedmaxs[0] = u[0]; \
        if(rotatedmaxs[1] > u[1]) rotatedmaxs[1] = u[1]; \
        if(rotatedmaxs[2] > u[2]) rotatedmaxs[2] = u[2];
    
        vec3_t v, u;
        matrix4x4_t m;
        Matrix4x4_CreateFromQuakeEntity(&m, 0, 0, 0, angles[PITCH], angles[YAW], angles[ROLL], 1.0);
    
        v[0] = mins[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
            VectorCopy(u, rotatedmins); VectorCopy(u, rotatedmaxs);
        v[0] = maxs[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = mins[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = maxs[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = mins[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = maxs[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = mins[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
        v[0] = maxs[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
            _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
    
    #undef _vec3_min
    #undef _vec3_max
    }
    I wonder if version with functions will be prettier.

    Comment


    • #32
      Yeah, with extra functions it's prettier. But longer, and there are two functions now that are used only once.

      Code:
      static void _vec3_min(vec3_t a, const vec3_t v) {
          if(v[0]<a[0]) a[0]=v[0];
          if(v[1]<a[1]) a[1]=v[1];
          if(v[2]<a[2]) a[2]=v[2];
      }
      
      static void _vec3_max(vec3_t a, const vec3_t v) {
          if(v[0]>a[0]) a[0]=v[0];
          if(v[1]>a[1]) a[1]=v[1];
          if(v[2]>a[2]) a[2]=v[2];
      }
      
      static void RotateBBox(const vec3_t mins, const vec3_t maxs, const vec3_t angles, vec3_t rotatedmins, vec3_t rotatedmaxs)
      {
          vec3_t v, u;
          matrix4x4_t m;
          Matrix4x4_CreateFromQuakeEntity(&m, 0, 0, 0, angles[PITCH], angles[YAW], angles[ROLL], 1.0);
      
          v[0] = mins[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
              VectorCopy(u, rotatedmins); VectorCopy(u, rotatedmaxs);
          v[0] = maxs[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = mins[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = maxs[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = mins[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = maxs[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = mins[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
          v[0] = maxs[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
              _vec3_min(rotatedmins, u); _vec3_max(rotatedmaxs, u);
      }

      Comment


      • #33
        You couldn't possibly have written that. You're a fake modder, right? 😉
        http://www.nextgenquake.com

        Comment


        • #34
          I never really modded anything...

          So, I opened E1M5.MAP with TrenchBroom, but looks like textures are missing.



          There is no gfx\medieval.wad file in my id1 directory, there are only a bunch of .lmp files.

          Comment


          • #35
            ok, wad files can be downloaded here

            https://www.quaddicted.com/files/wads/

            and they should be placed in the directory relative to TrenchBroom itself.

            Comment


            • #36
              I'm curious what those files are.

              Code:
              progs.h
                  pr_comp.h // defs shared with qcc
              progsvm.h
                  progdefs.h   // generated by program cdefs
                  clprogdefs.h // generated by program cdefs
                  prvm_offsets.h
              What is cdefs? How those files are generated, and from what?

              Comment


              • #37
                downloaded rtlights from darkplaces site, didn't notice the difference. Still lags on high settings.

                Comment


                • #38
                  I'll just dump this here. It's a list of all files included by sys_win.c, but without repeats. Made it by copying files one by one and seeing what will the compiler complain about.

                  This somehow looks simplier than doxygen generated docs, just because headers that are too common are shown only once, and don't create much noize. There probably is a way to generate it automatically, but whatever.

                  Code:
                  sys_win.c
                      qtypes.h
                      quakedef.h
                          zone.h
                          fs.h
                          common.h
                          cvar.h
                          bspfile.h
                          sys.h
                          vid.h
                          mathlib.h
                  
                          r_textures.h
                  
                          crypto.h
                              lhnet.h
                          draw.h
                          screen.h
                          netconn.h
                          protocol.h
                          cmd.h
                          sbar.h
                          sound.h
                              matrixlib.h
                          model_shared.h
                              bih.h
                              model_brush.h
                              model_sprite.h
                                  spritegn.h
                              model_alias.h
                                  modelgen.h
                  
                                  model_zymotic.h
                                  model_dpmodel.h
                                  model_psk.h
                                  model_iqm.h
                  
                          world.h
                              collision.h
                          client.h
                              snd_main.h
                              cl_screen.h
                          render.h
                              svbsp.h
                              r_modules.h
                              meshqueue.h
                              r_lerpanim.h
                              gl_backend.h
                          progs.h
                              pr_comp.h // defs shared with qcc
                          progsvm.h
                              progdefs.h   // generated by program cdefs
                              clprogdefs.h // generated by program cdefs
                              prvm_offsets.h
                          server.h
                  
                          input.h
                          keys.h
                          console.h
                  
                          csprogs.h
                  
                          glquake.h
                          palette.h
                  
                      resource.h
                      conproc.h
                  Next I'll need to do this with the rest of c files. Maybe.

                  Comment


                  • #39
                    Found why minimizing volume acts the same as pressing c.

                    WM_KEYDOWN
                    virtual key = VK_VOLUME_DOWN
                    state = 0x012e0001

                    WM_KEYDOWN
                    virtual key = VK_C
                    state = 0x002e0001

                    darkplaces only looks at scancodes (and is_extended flag). Scancode is same (2e), is_extended is different.

                    the real keyboard handling is in vid_wgl.c , in functions MainWndProc and MapKey.

                    I'm thinking what to change in MapKey now. I changed last "return result;" to "return 0;". Decreasing volume no longer causes me to load state, but arrow keys no longer work as well.

                    Now I'm curious where fteqw and quakespasm handle keyboard messages. There are so many files, I don't know where to look.

                    Extra info:
                    https://msdn.microsoft.com/ru-ru/lib...(v=vs.85).aspx
                    https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html

                    Window Detective was really helpful.

                    Placing those in the code helped as well:
                    Con_Printf("modified: %2x result: %2x\n", modified, result);
                    Con_Printf("wParam: %2x lParam: %8x vkey: %2x\n", wParam, lParam, vkey);
                    Con_Printf("====================================== ==\n");

                    Comment


                    • #40
                      Looking for jr_med.wad

                      Comment


                      • #41
                        Just a little more progress, pressing alt-down no longer causes darkplaces to load quicksave for me. I replaced "Send {Volume_Down 3}" with "SoundSet -5" in my autohotkey.

                        autohotkey was sending lParam 0x002e0001, exactly the same code as for "c" key. It's probably a bug on their side, they should've been sending 0x012e0001.

                        I really wonder if getting input like that is a good idea, darkplaces probably should check wParam too. I kind of like it though, just need to find more documentation on those scancodes. Have no idea if they are more or less standard between different keyboard manufactors and it's safe to use them, or if everyone can do whatever they want.

                        Next step is to fix arrow keys, I broke them while disabling VK_VOLUME_DOWN. Also I'd kind of want to use wasd instead of arrows anyway, but gonna find where I can change it first.

                        vid_wgl.c
                        MainWndProc
                        vkey = MapKey(lParam, wParam);
                        int is_repeat = lParam & (1 << 26);
                        int is_keyup = lParam & (1 << 30);
                        if (!is_repeat && !is_keyup) {
                        Con_Printf("lParam: %08x vkey: %2x\n", lParam, vkey);
                        }

                        Comment


                        • #42
                          Okay, arrows work.

                          vid_wgl.c
                          MapKey

                          Code:
                              else
                              {
                                  if(virtualkey == VK_NUMLOCK)
                                      return K_NUMLOCK;
                          
                                  Con_Printf("res: 0x%02x\n", result);
                                  switch ( result )
                                  {
                                  case 0x0D:
                                      return K_KP_ENTER;
                                  case 0x2F:
                                      return K_KP_SLASH;
                                  case 0xAF:
                                      return K_KP_PLUS;
                                  case 0x80:
                                      return 0x80;
                                  case 0x81:
                                      return 0x81;
                                  case 0x82:
                                      return 0x82;
                                  case 0x83:
                                      return 0x83;
                                  }
                                  //return result;
                                  return 0;
                              }
                          Intrigued by WM_INPUT, looks like I can get raw input without directx after all.

                          Comment


                          • #43
                            Gonna fuck with other two engines now.

                            FTE actually works for android, wow. Interesting what the controls are.

                            Comment


                            • #44
                              I'll just increase my post counter while nobody's watching

                              Comment


                              • #45
                                @ I'll just increase my post counter while nobody's watching

                                How do you think I got to over 5000
                                http://www.nextgenquake.com

                                Comment

                                Working...
                                X