Announcement

Collapse
No announcement yet.

Trying to understand darkplaces source code

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

  • vibok
    replied
    vid_wgl.c/VID_InitModeSOFT()

    Awesome, I actually needed some stuff from there.

    Strange how it still calls GL_Clear() at the end of vid_shared.c/VID_Soft_SharedSetup(), software rendering still uses opengl somehow?

    Leave a comment:


  • vibok
    replied
    Looks like you just specify int64_t type, and gcc compiler will use 64bit arithmetics automatically. Didn't knew it was this smart. It's I think 4 times slower though? No idea.

    Not sure if there is other 64bit specific code anywhere. I guess I'll just read everything, and eventually I'll stumble on it.

    Leave a comment:


  • vibok
    replied
    Curious how different engines handle transition to 64bit processors. The difference is only in types used, or there is difference in logic too?

    what I found so far:

    quakespasm-source/Quake/q_stdinc.h

    /* NOTES on TYPE SIZES:
    Quake/Hexen II engine relied on 32 bit int type size
    with ILP32 (not LP32) model in mind. We now support
    LP64 and LLP64, too. We expect:
    sizeof (char) == 1
    sizeof (short) == 2
    sizeof (int) == 4
    sizeof (float) == 4
    sizeof (long) == 4 / 8
    sizeof (pointer *) == 4 / 8
    For this, we need stdint.h (or inttypes.h)
    FIXME: On some platforms, only inttypes.h is available.
    FIXME: Properly replace certain short and int usage
    with int16_t and int32_t.
    */

    Leave a comment:


  • vibok
    replied
    what's "darkplaces.opt"?

    fs.c/FS_Init_SelfPack()

    Leave a comment:


  • vibok
    replied
    I'm getting this warning:
    warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]

    in vid_wgl.c/AdjustWindowBounds()
    int workWidth = workArea.right - workArea.left;

    Not sure how to get rid of it. Adding -std=c99 didn't help. Don't want to rewrite too, it's just fine as it is.

    Here is the full compiler log. Strange that compiler error shows up after linking, but who knows what went wrong, maybe it's just my ide being buggy.

    Code:
    gcc.exe -std=c99 -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes -fno-strict-aliasing -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES -DCONFIG_MENU -DCONFIG_CD -DSVNREVISION=- -DBUILDTYPE=release_sure -g -D_WIN32 -DWIN32  -c D:\games-outside\quake-extra\clients\darkplaces\vid_wgl.c -o ..\darkplaces-obj\debug\vid_wgl.o
    g++.exe  -o _darkplaces_debug.exe ..\darkplaces-obj\debug\bih.o ..\darkplaces-obj\debug\builddate.o ..\darkplaces-obj\debug\cap_avi.o ..\darkplaces-obj\debug\cap_ogg.o ..\darkplaces-obj\debug\cd_shared.o ..\darkplaces-obj\debug\cd_win.o ..\darkplaces-obj\debug\cl_collision.o ..\darkplaces-obj\debug\cl_demo.o ..\darkplaces-obj\debug\cl_dyntexture.o ..\darkplaces-obj\debug\cl_input.o ..\darkplaces-obj\debug\cl_main.o ..\darkplaces-obj\debug\cl_parse.o ..\darkplaces-obj\debug\cl_particles.o ..\darkplaces-obj\debug\cl_screen.o ..\darkplaces-obj\debug\cl_video.o ..\darkplaces-obj\debug\clvm_cmds.o ..\darkplaces-obj\debug\cmd.o ..\darkplaces-obj\debug\collision.o ..\darkplaces-obj\debug\common.o ..\darkplaces-obj\debug\conproc.o ..\darkplaces-obj\debug\console.o ..\darkplaces-obj\debug\crypto.o ..\darkplaces-obj\debug\csprogs.o ..\darkplaces-obj\debug\curves.o ..\darkplaces-obj\debug\cvar.o ..\darkplaces-obj\debug\dpsoftrast.o ..\darkplaces-obj\debug\dpvsimpledecode.o ..\darkplaces-obj\debug\filematch.o ..\darkplaces-obj\debug\fractalnoise.o ..\darkplaces-obj\debug\fs.o ..\darkplaces-obj\debug\ft2.o ..\darkplaces-obj\debug\gl_backend.o ..\darkplaces-obj\debug\gl_draw.o ..\darkplaces-obj\debug\gl_rmain.o ..\darkplaces-obj\debug\gl_rsurf.o ..\darkplaces-obj\debug\gl_textures.o ..\darkplaces-obj\debug\hmac.o ..\darkplaces-obj\debug\host.o ..\darkplaces-obj\debug\host_cmd.o ..\darkplaces-obj\debug\image.o ..\darkplaces-obj\debug\image_png.o ..\darkplaces-obj\debug\jpeg.o ..\darkplaces-obj\debug\keys.o ..\darkplaces-obj\debug\lhnet.o ..\darkplaces-obj\debug\libcurl.o ..\darkplaces-obj\debug\mathlib.o ..\darkplaces-obj\debug\matrixlib.o ..\darkplaces-obj\debug\mdfour.o ..\darkplaces-obj\debug\menu.o ..\darkplaces-obj\debug\meshqueue.o ..\darkplaces-obj\debug\mod_skeletal_animatevertices_generic.o ..\darkplaces-obj\debug\mod_skeletal_animatevertices_sse.o ..\darkplaces-obj\debug\model_alias.o ..\darkplaces-obj\debug\model_brush.o ..\darkplaces-obj\debug\model_shared.o ..\darkplaces-obj\debug\model_sprite.o ..\darkplaces-obj\debug\mvm_cmds.o ..\darkplaces-obj\debug\netconn.o ..\darkplaces-obj\debug\palette.o ..\darkplaces-obj\debug\polygon.o ..\darkplaces-obj\debug\portals.o ..\darkplaces-obj\debug\protocol.o ..\darkplaces-obj\debug\prvm_cmds.o ..\darkplaces-obj\debug\prvm_edict.o ..\darkplaces-obj\debug\prvm_exec.o ..\darkplaces-obj\debug\r_explosion.o ..\darkplaces-obj\debug\r_lerpanim.o ..\darkplaces-obj\debug\r_lightning.o ..\darkplaces-obj\debug\r_modules.o ..\darkplaces-obj\debug\r_shadow.o ..\darkplaces-obj\debug\r_sky.o ..\darkplaces-obj\debug\r_sprites.o ..\darkplaces-obj\debug\sbar.o ..\darkplaces-obj\debug\snd_main.o ..\darkplaces-obj\debug\snd_mem.o ..\darkplaces-obj\debug\snd_mix.o ..\darkplaces-obj\debug\snd_ogg.o ..\darkplaces-obj\debug\snd_wav.o ..\darkplaces-obj\debug\snd_win.o ..\darkplaces-obj\debug\sv_demo.o ..\darkplaces-obj\debug\sv_main.o ..\darkplaces-obj\debug\sv_move.o ..\darkplaces-obj\debug\sv_phys.o ..\darkplaces-obj\debug\sv_user.o ..\darkplaces-obj\debug\svbsp.o ..\darkplaces-obj\debug\svvm_cmds.o ..\darkplaces-obj\debug\sys_shared.o ..\darkplaces-obj\debug\sys_win.o ..\darkplaces-obj\debug\thread_null.o ..\darkplaces-obj\debug\utf8lib.o ..\darkplaces-obj\debug\vid_shared.o ..\darkplaces-obj\debug\vid_wgl.o ..\darkplaces-obj\debug\view.o ..\darkplaces-obj\debug\wad.o ..\darkplaces-obj\debug\world.o ..\darkplaces-obj\debug\zone.o  ..\darkplaces-obj\debug\resource.res -mwindows -static-libstdc++ -static-libgcc -static  -lws2_32 -lwinmm -luser32 -lgdi32
    D:\games-outside\quake-extra\clients\darkplaces\vid_wgl.c: In function 'AdjustWindowBounds':
    D:\games-outside\quake-extra\clients\darkplaces\vid_wgl.c:1363:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
       int workWidth = workArea.right - workArea.left;
       ^~~
    Output file is _darkplaces_debug.exe with size 17.80 MB
    Process terminated with status 0 (0 minute(s), 5 second(s))
    0 error(s), 1 warning(s) (0 minute(s), 5 second(s))
    Maybe full recompile will help, but that's too long.

    Inteeresting how there are a lot of qboolean variables in darkplaces code. When quake was made, C99 standard didn't exist yet, and it introduced bool type and allowed creating variables in the middle of the code.

    Difference between C99 and C11 isn't that clear to me. Doesn't seem that useful.
    Last edited by vibok; 08-30-2017, 06:40 AM.

    Leave a comment:


  • vibok
    replied
    Replaced all global_hInstance with (HINSTANCE)0x400000, they are all in vid_wgl.c

    Leave a comment:


  • vibok
    replied
    sys_win.c/WinMain()
    Strange that darkplaces parces arguments manually instead of calling CommandLineToArgv.
    Strange that darkplaces actually stores hInstance, instead of just using 0x400000 everywhere. As far as I know, it's always 0x400000 in 32bit apps.

    Wish somebody actually paid me for this.
    Last edited by vibok; 08-30-2017, 02:12 AM.

    Leave a comment:


  • vibok
    replied
    -basedir

    Leave a comment:


  • vibok
    replied
    Problem I have right now is, I have three different quake engines, and they all require almost the same data (music, levels). And it's copied for each one of them. I wonder if there is a way to make them read from the same source, I need to save harddrive space.

    Darkplaces also keeps trying to write something in %USERPROFILE%, and I want to use it as a portable app.

    Leave a comment:


  • vibok
    replied
    wha

    Leave a comment:


  • ChaosEsqueEd
    replied
    Do not try.

    Do.

    Leave a comment:


  • vibok
    replied
    >Basically anything more complicated than RLE, i.e. Huffman would have been covered by patents like GIF, JBIG, JPEG2000, etc.

    Huh, Carmack would've probably used more advanced compression, if he made quake today. I wonder what would fit, for textures and maps.

    Leave a comment:


  • vibok
    replied
    sys_shared.c/Sys_DirtyTime()

    It looks like there is no need to call QueryPerformanceFrequency on every frame, it will always be the same. Windows will fix the value of QueryPerformanceCounter by itself if internal cpu frequency changes. Or something.

    Wonder if it works the same on linux.

    Wonder if it even worth creating an extra global variable for, considering it's not even the default timer used.

    Links:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    http://www.windowstimestamp.com/description
    https://randomascii.wordpress.com/20...-gettickcount/



    Tried to email darkplaces author(s) some time ago, not about this, got no reply so far. Could be wrong email, or bad spamfilter. Torturing you for answers isn't that productive.

    Tried arcane dimensions on darkplaces, it's noticeably slow. On quakespasm it's pretty fast. Maybe because darkplaces is 32 bit, and BSP2 uses 64 bit data. Or I did something wrong with compilation, who knows.

    Still haven't looked at physics, curious how they are done.

    ogre3d has some usable code for timer. Valve did something weird with their timer, but it's not fully open source, only headers.



    static cvar_t sys_usequeryperformancecounter = {CVAR_SAVE, "sys_usequeryperformancecounter", "0", "use windows QueryPerformanceCounter timer (which has issues on multicore/multiprocessor machines and processors which are designed to conserve power) for timing rather than timeGetTime function (which has issues on some motherboards)"};

    Leave a comment:


  • vibok
    replied
    By the way, thank you for your replies. Feet kinda reluctant to write just a simple thank you, without anything else, that's why it's so slow.

    Leave a comment:


  • vibok
    replied
    ok, so I figured out why my potato showed such a low fps.

    the r_speeds 2 was priceless for that. After typing it, I saw that "shadowmaps" takes suspiciously much of rendering time. The code for rendering is in gl_rmain.c/R_RenderScene(). Statistics are gathered with this snippet:

    if (r_timereport_active)
    R_TimeReport("shadowmaps");


    I tried to see which part of drawing shadows was the slowest by placing my own probes, and saw that the chain R_Shadow_DrawShadowMaps()/R_Shadow_ClearShadowMapTexture()/GL_Clear()/qglClear() takes all of rendering time. This thread https://www.opengl.org/discussion_bo...Clear-too-slow suggested that it means nothing, because driver groups opengl calls.

    So instead of figuring this code out I just commented the whole shadow rendering. I couldn't spot the difference, honestly. Levels are still shaded, monsters get darker then go into the dark areas. I guess monsters don't cast shadows now, but I never seen that anyway for some reason. LATER check if dlight from rockets still works.

    Now my potato can play it, it got to 60 fps.

    I wonder if there is a way to disable it with just cvars, without commenting out and recompiling.



    One weird thing I spotted, inside R_Shadow_ClearShadowMapTexture(), there is R_Mesh_ResetTextureState() and R_Shadow_RenderMode_Reset() called one after another. If you look inside the second one, you'll see first one called again. Dunno if it's supposed to be like that or not, but it's pretty suspicious.

    http://quakeone.com/forums/quake-hel...ally-slow.html

    http://www.paulsprojects.net/opengl/...shadowmap.html

    Leave a comment:

Working...
X