From: xolatile Date: Sun, 17 Aug 2025 16:28:28 +0000 (+0200) Subject: Compiles, removed a lot of code, do not run it... X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;p=xolatile-badassbug.git Compiles, removed a lot of code, do not run it... --- diff --git a/config.cfg b/config.cfg index d12049a..50e7f8d 100644 --- a/config.cfg +++ b/config.cfg @@ -29,10 +29,7 @@ autosortservers 1 autoupdateservers 1 bilinear 1 blood 1 -blurshadowmap 1 -blursmsigma 100 bumpmodels 1 -chainsawhudgun 1 clockerror 1000000 clockfix 0 compresspng 9 @@ -58,7 +55,6 @@ deathscore 1 decalfade 10000 decals 1 demodir "demo" -dynlightdist 1024 editinview 1 emitmillis 17 entcamdir 1 @@ -67,7 +63,6 @@ fewparticles 100 filltjoints 1 fixwav 1 fov 120 -fpshadowmap 0 fullbrightmodels 60 fullconfilter 65535 fullconsize 75 @@ -125,7 +120,6 @@ lightthreads 0 maxcon 200 maxdecaldistance 512 maxdecaltris 1024 -maxdynlights 5 maxfps 60 maxhistory 1000 maxparticledistance 1024 @@ -153,9 +147,6 @@ outlinemeters 0 particlesize 100 particletext 1 playermodel 0 -ragdoll 1 -ragdollfade 1000 -ragdollmillis 10000 reducefilter 1 relativemouse 1 savebak 2 @@ -169,14 +160,6 @@ sensitivityscale 1.0 servpingdecay 15000 servpingrate 5000 shaderdetail 3 -shadowmap 1 -shadowmapbias 5 -shadowmapdist 256 -shadowmapintensity 40 -shadowmappeelbias 20 -shadowmapprecision 0 -shadowmapradius 96 -shadowmapsize 9 showclientnum 1 showconnecting 0 showdamagedealt 1 @@ -210,7 +193,6 @@ teamcolortext 1 teamcrosshair 1 teamhudguns 1 teamskins 0 -teamsounds 1 texcompress 1025 texcompressquality -1 texgui2d 1 @@ -358,7 +340,6 @@ modifier = [0] multiplier = [1] multiplier2 = [16] newname = [xolatile] -skelanimlength = [192] universaldelta = "^n do [delta_@(if $editing [ result edit ] [ result game ])_@modifier @arg1]^n" listcomplete clearents [ diff --git a/data/glsl.cfg b/data/glsl.cfg index 91e6e8e..6942793 100644 --- a/data/glsl.cfg +++ b/data/glsl.cfg @@ -274,8 +274,6 @@ worldshader = [ texcoord1 = vtexcoord1 * @lmcoordscale; @arg2 - - //:shadowmap } ] [ @(if (>= $numargs 5) [result $arg5]) @@ -293,13 +291,6 @@ worldshader = [ vec4 diffuse = vec4(texture2D(diffusemap, texcoord0).rgb, 1.0); ]) vec4 lm = texture2D(lightmap, texcoord1); - - //:shadowmap lm - - @arg3 - - diffuse *= colorparams; - @(if (|| (< $numargs 4) [=s $arg4 []]) [result [gl_FragColor = diffuse * lm;]] [result $arg4]) } ] ] @@ -630,11 +621,6 @@ bumpvariantshader = [ @(if (btopt "G") [result [ pulse = abs(fract(millis*pulseglowspeed.x)*2.0 - 1.0); ]]) - - @(if (! (btopt "i")) [result [ - //:shadowmap - //:water - ]]) } ] [ uniform vec4 colorparams; @@ -706,18 +692,6 @@ bumpvariantshader = [ ]]) ]]) - @(if (|| (! (btopt "i")) (btopt "s")) [result [ - lmc.rgb = max(lmc.rgb*clamp(dot(lmlv, bump), 0.0, 1.0), ambient.xyz); - @(if (btopt "i") [result [ - - @(? (btopt "g") "diffuse.rgb" "gl_FragColor.rgb") = diffuse.rgb * lmc.rgb; - ]] [result [ - //:shadowmap lmc - - @(? (|| (btopt "g") (btopt "r")) "diffuse.rgb" "gl_FragColor.rgb") = diffuse.rgb * lmc.rgb; - ]]) - ]]) - @(if (btopt "r") [result [ vec3 rvec; @(if (btopt "t") [result [ @@ -994,55 +968,6 @@ skelanim = [ ] ] -// model shadowmapping - -shadowmapcastervertexshader = [ - result [ - @(if (>= $numargs 2) [result $arg1]) - attribute vec4 vvertex; - uniform mat4 modelmatrix; - uniform vec4 shadowintensity; - varying vec4 shadowmapvals; - void main(void) - { - @(if (>= $numargs 2) [result $arg2] [result [ - #define mpos vvertex - ]]) - gl_Position = modelmatrix * mpos; - shadowmapvals = vec4(1.0 - gl_Position.z, 1.0, 0.0, shadowintensity.x); - } - ] -] - -shader 0 shadowmapcaster (shadowmapcastervertexshader) [ - varying vec4 shadowmapvals; - void main(void) - { - gl_FragColor = shadowmapvals; - } -] -loop i 4 [ - variantshader 0 shadowmapcaster 0 (shadowmapcastervertexshader (skelanimdefs (+ $i 1)) (skelanim (+ $i 1))) [] -] - -shader 0 "shadowmapreceiver" [ - attribute vec4 vvertex; - uniform mat4 shadowmatrix; - uniform vec2 shadowmapbias; - varying vec4 shadowmapvals; - void main(void) - { - gl_Position = shadowmatrix * vvertex; - shadowmapvals = vec4(0.0, 0.0, shadowmapbias.y - gl_Position.z, 0.0); - } -] [ - varying vec4 shadowmapvals; - void main(void) - { - gl_FragColor = shadowmapvals; - } -] - // model stenciling notexturemodelvertexshader = [ diff --git a/data/menus.cfg b/data/menus.cfg index 6d58e7c..f4d772f 100644 --- a/data/menus.cfg +++ b/data/menus.cfg @@ -343,17 +343,6 @@ newgui options [ /////////////////////////////////////////////////////////////// ] guicheckbox "show scoreboard at death" deathscore guicheckbox "blood" blood - guilist [ - guicheckbox "ragdoll deaths" ragdoll - if $ragdoll [ - guibar - guicheckbox "keep after respawn" ragdollmillis 10000 - ] - guibar - guicheckbox "hide dead players" hidedead - ] - guitext "ragdoll velocity multiplier" - guislider deadpush guilist [ guicheckbox "fullbright player models" fullbrightmodels 60 0 if $fullbrightmodels [ @@ -425,17 +414,6 @@ newgui options [ /////////////////////////////////////////////////////////////// guibar guiradio "^f2high detail" shaderdetail 3 ] - guilist [ - guicheckbox "^f3soft shadows^t" shadowmap - if $shadowmap [ - guibar - guiradio "^f2medium quality" shadowmapsize 9 [blurshadowmap 1] - guibar - guiradio "^f3high quality" shadowmapsize 10 [blurshadowmap 2] - ] [ - guibar - ] - ] guilist [ guicheckbox "^f0decals^t^t" decals if $decals [ diff --git a/src/Makefile b/src/Makefile index 28c7cf6..efd780a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -84,7 +84,6 @@ CLIENT_OBJS= \ shared/tools.o \ shared/zip.o \ engine/3dgui.o \ - engine/bih.o \ engine/client.o \ engine/command.o \ engine/console.o \ @@ -106,7 +105,6 @@ CLIENT_OBJS= \ engine/server.o \ engine/serverbrowser.o \ engine/shader.o \ - engine/shadowmap.o \ engine/sound.o \ engine/texture.o \ engine/world.o \ @@ -200,12 +198,6 @@ server: $(SERVER_OBJS) master: $(MASTER_OBJS) $(CXX) $(CXXFLAGS) -o sauer_master $(MASTER_OBJS) $(MASTER_LIBS) -shared/cube2font.o: shared/cube2font.c - $(CXX) $(CXXFLAGS) -c -o $@ $< `freetype-config --cflags` - -cube2font: shared/cube2font.o - $(CXX) $(CXXFLAGS) -o cube2font shared/cube2font.o `freetype-config --libs` -lz - ifneq (,$(findstring DARWIN,$(PLATFORM))) install: client cp sauer_client ../sauerbraten.app/Contents/MacOS/sauerbraten_universal @@ -248,147 +240,137 @@ shared/zip.o: shared/iengine.h shared/igame.h engine/3dgui.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/3dgui.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/3dgui.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/3dgui.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/3dgui.o: engine/lightmap.h engine/texture.h engine/3dgui.o: engine/model.h engine/textedit.h -engine/bih.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h -engine/bih.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h -engine/bih.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/bih.o: engine/lightmap.h engine/bih.h engine/texture.h engine/model.h engine/client.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/client.o: shared/ents.h shared/command.h shared/glexts.h engine/client.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/client.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/client.o: engine/world.h engine/octa.h engine/lightmap.h engine/client.o: engine/texture.h engine/model.h engine/command.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/command.o: shared/ents.h shared/command.h shared/glexts.h engine/command.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/command.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/command.o: engine/world.h engine/octa.h engine/lightmap.h engine/command.o: engine/texture.h engine/model.h engine/console.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/console.o: shared/ents.h shared/command.h shared/glexts.h engine/console.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/console.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/console.o: engine/world.h engine/octa.h engine/lightmap.h engine/console.o: engine/texture.h engine/model.h engine/decal.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/decal.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/decal.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/decal.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/decal.o: engine/lightmap.h engine/texture.h engine/decal.o: engine/model.h engine/lightmap.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/lightmap.o: shared/ents.h shared/command.h shared/glexts.h engine/lightmap.o: shared/glemu.h shared/iengine.h shared/igame.h engine/lightmap.o: engine/world.h engine/octa.h engine/lightmap.h -engine/lightmap.o: engine/bih.h engine/texture.h engine/model.h +engine/lightmap.o: engine/texture.h engine/model.h engine/main.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/main.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/main.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/main.o: engine/lightmap.h engine/bih.h engine/texture.h engine/model.h +engine/main.o: engine/lightmap.h engine/texture.h engine/model.h engine/material.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/material.o: shared/ents.h shared/command.h shared/glexts.h engine/material.o: shared/glemu.h shared/iengine.h shared/igame.h engine/material.o: engine/world.h engine/octa.h engine/lightmap.h -engine/material.o: engine/bih.h engine/texture.h engine/model.h +engine/material.o: engine/texture.h engine/model.h engine/menus.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/menus.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/menus.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/menus.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/menus.o: engine/lightmap.h engine/texture.h engine/menus.o: engine/model.h engine/normal.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/normal.o: shared/ents.h shared/command.h shared/glexts.h engine/normal.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/normal.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/normal.o: engine/world.h engine/octa.h engine/lightmap.h engine/normal.o: engine/texture.h engine/model.h engine/octa.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/octa.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/octa.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/octa.o: engine/lightmap.h engine/bih.h engine/texture.h engine/model.h +engine/octa.o: engine/lightmap.h engine/texture.h engine/model.h engine/octaedit.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/octaedit.o: shared/ents.h shared/command.h shared/glexts.h engine/octaedit.o: shared/glemu.h shared/iengine.h shared/igame.h engine/octaedit.o: engine/world.h engine/octa.h engine/lightmap.h -engine/octaedit.o: engine/bih.h engine/texture.h engine/model.h +engine/octaedit.o: engine/texture.h engine/model.h engine/octarender.o: engine/engine.h shared/cube.h shared/tools.h engine/octarender.o: shared/geom.h shared/ents.h shared/command.h engine/octarender.o: shared/glexts.h shared/glemu.h shared/iengine.h engine/octarender.o: shared/igame.h engine/world.h engine/octa.h -engine/octarender.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/octarender.o: engine/lightmap.h engine/texture.h engine/octarender.o: engine/model.h engine/physics.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/physics.o: shared/ents.h shared/command.h shared/glexts.h engine/physics.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/physics.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/physics.o: engine/world.h engine/octa.h engine/lightmap.h engine/physics.o: engine/texture.h engine/model.h engine/mpr.h engine/rendergl.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/rendergl.o: shared/ents.h shared/command.h shared/glexts.h engine/rendergl.o: shared/glemu.h shared/iengine.h shared/igame.h engine/rendergl.o: engine/world.h engine/octa.h engine/lightmap.h -engine/rendergl.o: engine/bih.h engine/texture.h engine/model.h +engine/rendergl.o: engine/texture.h engine/model.h engine/rendermodel.o: engine/engine.h shared/cube.h shared/tools.h engine/rendermodel.o: shared/geom.h shared/ents.h shared/command.h engine/rendermodel.o: shared/glexts.h shared/glemu.h shared/iengine.h engine/rendermodel.o: shared/igame.h engine/world.h engine/octa.h -engine/rendermodel.o: engine/lightmap.h engine/bih.h engine/texture.h -engine/rendermodel.o: engine/model.h engine/ragdoll.h engine/animmodel.h +engine/rendermodel.o: engine/lightmap.h engine/texture.h +engine/rendermodel.o: engine/model.h engine/animmodel.h engine/rendermodel.o: engine/skelmodel.h engine/rendermodel.o: engine/md5.h engine/iqm.h engine/renderparticles.o: engine/engine.h shared/cube.h shared/tools.h engine/renderparticles.o: shared/geom.h shared/ents.h shared/command.h engine/renderparticles.o: shared/glexts.h shared/glemu.h shared/iengine.h engine/renderparticles.o: shared/igame.h engine/world.h engine/octa.h -engine/renderparticles.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/renderparticles.o: engine/lightmap.h engine/texture.h engine/renderparticles.o: engine/model.h engine/rendertarget.h engine/rendertext.o: engine/engine.h shared/cube.h shared/tools.h engine/rendertext.o: shared/geom.h shared/ents.h shared/command.h engine/rendertext.o: shared/glexts.h shared/glemu.h shared/iengine.h engine/rendertext.o: shared/igame.h engine/world.h engine/octa.h -engine/rendertext.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/rendertext.o: engine/lightmap.h engine/texture.h engine/rendertext.o: engine/model.h engine/renderva.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/renderva.o: shared/ents.h shared/command.h shared/glexts.h engine/renderva.o: shared/glemu.h shared/iengine.h shared/igame.h engine/renderva.o: engine/world.h engine/octa.h engine/lightmap.h -engine/renderva.o: engine/bih.h engine/texture.h engine/model.h +engine/renderva.o: engine/texture.h engine/model.h engine/server.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/server.o: shared/ents.h shared/command.h shared/glexts.h engine/server.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/server.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/server.o: engine/world.h engine/octa.h engine/lightmap.h engine/server.o: engine/texture.h engine/model.h engine/serverbrowser.o: engine/engine.h shared/cube.h shared/tools.h engine/serverbrowser.o: shared/geom.h shared/ents.h shared/command.h engine/serverbrowser.o: shared/glexts.h shared/glemu.h shared/iengine.h engine/serverbrowser.o: shared/igame.h engine/world.h engine/octa.h -engine/serverbrowser.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/serverbrowser.o: engine/lightmap.h engine/texture.h engine/serverbrowser.o: engine/model.h engine/shader.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/shader.o: shared/ents.h shared/command.h shared/glexts.h engine/shader.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/shader.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/shader.o: engine/world.h engine/octa.h engine/lightmap.h engine/shader.o: engine/texture.h engine/model.h -engine/shadowmap.o: engine/engine.h shared/cube.h shared/tools.h -engine/shadowmap.o: shared/geom.h shared/ents.h shared/command.h -engine/shadowmap.o: shared/glexts.h shared/glemu.h shared/iengine.h -engine/shadowmap.o: shared/igame.h engine/world.h engine/octa.h -engine/shadowmap.o: engine/lightmap.h engine/bih.h engine/texture.h -engine/shadowmap.o: engine/model.h engine/rendertarget.h engine/sound.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/sound.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/sound.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/sound.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/sound.o: engine/lightmap.h engine/texture.h engine/sound.o: engine/model.h engine/texture.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/texture.o: shared/ents.h shared/command.h shared/glexts.h engine/texture.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/texture.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/texture.o: engine/world.h engine/octa.h engine/lightmap.h engine/texture.o: engine/texture.h engine/model.h engine/world.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/world.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h engine/world.o: shared/iengine.h shared/igame.h engine/world.h engine/octa.h -engine/world.o: engine/lightmap.h engine/bih.h engine/texture.h +engine/world.o: engine/lightmap.h engine/texture.h engine/world.o: engine/model.h engine/worldio.o: engine/engine.h shared/cube.h shared/tools.h shared/geom.h engine/worldio.o: shared/ents.h shared/command.h shared/glexts.h engine/worldio.o: shared/glemu.h shared/iengine.h shared/igame.h -engine/worldio.o: engine/world.h engine/octa.h engine/lightmap.h engine/bih.h +engine/worldio.o: engine/world.h engine/octa.h engine/lightmap.h engine/worldio.o: engine/texture.h engine/model.h fpsgame/ai.o: fpsgame/game.h shared/cube.h shared/tools.h shared/geom.h fpsgame/ai.o: shared/ents.h shared/command.h shared/glexts.h shared/glemu.h @@ -413,7 +395,6 @@ fpsgame/scoreboard.o: shared/igame.h fpsgame/ai.h fpsgame/server.o: fpsgame/game.h shared/cube.h shared/tools.h shared/geom.h fpsgame/server.o: shared/ents.h shared/command.h shared/glexts.h fpsgame/server.o: shared/glemu.h shared/iengine.h shared/igame.h fpsgame/ai.h -fpsgame/server.o: fpsgame/extinfo.h fpsgame/aiman.h fpsgame/waypoint.o: fpsgame/game.h shared/cube.h shared/tools.h shared/geom.h fpsgame/waypoint.o: shared/ents.h shared/command.h shared/glexts.h fpsgame/waypoint.o: shared/glemu.h shared/iengine.h shared/igame.h @@ -428,7 +409,7 @@ shared/cube.h.gch: shared/iengine.h shared/igame.h engine/engine.h.gch: shared/cube.h shared/tools.h shared/geom.h shared/ents.h engine/engine.h.gch: shared/command.h shared/glexts.h shared/glemu.h engine/engine.h.gch: shared/iengine.h shared/igame.h engine/world.h -engine/engine.h.gch: engine/octa.h engine/lightmap.h engine/bih.h +engine/engine.h.gch: engine/octa.h engine/lightmap.h engine/engine.h.gch: engine/texture.h engine/model.h fpsgame/game.h.gch: shared/cube.h shared/tools.h shared/geom.h shared/ents.h fpsgame/game.h.gch: shared/command.h shared/glexts.h shared/glemu.h @@ -458,8 +439,6 @@ fpsgame/entities-standalone.o: shared/iengine.h shared/igame.h fpsgame/ai.h fpsgame/server-standalone.o: fpsgame/game.h shared/cube.h shared/tools.h fpsgame/server-standalone.o: shared/geom.h shared/ents.h shared/command.h fpsgame/server-standalone.o: shared/iengine.h shared/igame.h fpsgame/ai.h -fpsgame/server-standalone.o: fpsgame/extinfo.h -fpsgame/server-standalone.o: fpsgame/aiman.h engine/master-standalone.o: shared/cube.h shared/tools.h shared/geom.h engine/master-standalone.o: shared/ents.h shared/command.h shared/iengine.h engine/master-standalone.o: shared/igame.h diff --git a/src/engine/animmodel.h b/src/engine/animmodel.h index e94aea5..da90969 100644 --- a/src/engine/animmodel.h +++ b/src/engine/animmodel.h @@ -133,9 +133,6 @@ struct animmodel : model { void cleanup() { if(shader && shader->standard) shader = NULL; } - void preloadBIH() { - if(tex->type&Texture::ALPHA && !tex->alphamask) loadalphamask(tex); - } void preloadshader() { //~if(force) cleanup(); loadshader(); @@ -148,8 +145,7 @@ struct animmodel : model { else if(cullface && !enablecullface) { glEnable(GL_CULL_FACE); enablecullface = true; } if(as->cur.anim&ANIM_NOSKIN) { if(enablealphablend) { glDisable(GL_BLEND); enablealphablend = false; } - if(shadowmapping) SETMODELSHADER(b, shadowmapcaster); - else /*if(as->cur.anim&ANIM_SHADOW)*/ SETMODELSHADER(b, notexturemodel); + else SETMODELSHADER(b, notexturemodel); return; } setshader(b); @@ -196,22 +192,6 @@ struct animmodel : model { DELETEA(name); } virtual void calcbb(vec &bbmin, vec &bbmax, const matrix4x3 &m) = 0; - virtual void genBIH(BIH::mesh &m) = 0; - void genBIH(skin &s, vector &bih, const matrix4x3 &t) { - BIH::mesh &m = bih.add(); - m.xform = t; - m.tex = s.tex; - if(s.tex->type&Texture::ALPHA) m.flags |= BIH::MESH_ALPHA; - if(noclip) m.flags |= BIH::MESH_NOCLIP; - if(s.cullface) m.flags |= BIH::MESH_CULLFACE; - genBIH(m); - while(bih.last().numtris > BIH::mesh::MAXTRIS) { - BIH::mesh &overflow = bih.dup(); - overflow.tris += BIH::mesh::MAXTRIS; - overflow.numtris -= BIH::mesh::MAXTRIS; - bih[bih.length()-2].numtris = BIH::mesh::MAXTRIS; - } - } virtual void setshader(Shader *s) { s->set(); } @@ -357,9 +337,6 @@ struct animmodel : model { void calcbb(vec &bbmin, vec &bbmax, const matrix4x3 &m) { loopv(meshes) meshes[i]->calcbb(bbmin, bbmax, m); } - void genBIH(vector &skins, vector &bih, const matrix4x3 &t) { - loopv(meshes) meshes[i]->genBIH(skins[i], bih, t); - } virtual void *animkey() { return this; } virtual int totalframes() const { return 1; } bool hasframe(int i) const { return i>=0 && icalcbb(bbmin, bbmax, n); } } - void genBIH(vector &bih, const matrix4x3 &m) { - matrix4x3 t = m; - t.scale(model->scale); - t.translate(translate); - meshes->genBIH(skins, bih, t); - loopv(links) { - matrix4x3 n; - meshes->concattagtransform(this, links[i].tag, m, n); - n.translate(links[i].translate, model->scale); - links[i].p->genBIH(bih, n); - } - } bool link(part *p, const char *tag, const vec &translate = vec(0, 0, 0), int anim = -1, int basetime = 0, vec *pos = NULL) { int i = meshes ? meshes->findtag(tag) : -1; if(i<0) { @@ -524,9 +489,6 @@ struct animmodel : model { loopv(skins) if(skins[i].tangents()) return true; return false; } - void preloadBIH() { - loopv(skins) skins[i].preloadBIH(); - } void preloadshaders() { loopv(skins) skins[i].preloadshader(); } @@ -600,11 +562,7 @@ struct animmodel : model { animinterpinfo &ai = d->animinterp[interp]; if((info.anim&ANIM_CLAMP)==ANIM_CLAMP) aitime = min(aitime, int(info.range*info.speed*0.5e-3f)); void *ak = meshes->animkey(); - if(d->ragdoll && !(anim&ANIM_RAGDOLL)) { - ai.prev.range = ai.cur.range = 0; - ai.lastswitch = -1; - } - else if(ai.lastmodel!=ak || ai.lastswitch<0 || lastmillis-d->lastrendered>aitime) { + if(ai.lastmodel!=ak || ai.lastswitch<0 || lastmillis-d->lastrendered>aitime) { ai.prev = ai.cur = info; ai.lastswitch = lastmillis-aitime*2; } @@ -653,7 +611,7 @@ struct animmodel : model { matrixstack[matrixpos].transposedtransformnormal(forward, oforward); if(!(anim&ANIM_NORENDER)) { matrix4 modelmatrix; - modelmatrix.mul(shadowmapping ? shadowmatrix : camprojmatrix, matrixstack[matrixpos]); + modelmatrix.mul(camprojmatrix, matrixstack[matrixpos]); if(model->scale!=1) modelmatrix.scale(model->scale); if(!translate.iszero()) modelmatrix.translate(translate); GLOBALPARAM(modelmatrix, modelmatrix); @@ -769,7 +727,7 @@ struct animmodel : model { vec axis(0, -1, 0), forward(1, 0, 0); matrixpos = 0; matrixstack[0].identity(); - if(!d || !d->ragdoll || anim&ANIM_RAGDOLL) { + if(!d) { matrixstack[0].settranslation(o); matrixstack[0].rotate_around_z(yaw*RAD); matrixstack[0].transformnormal(vec(axis), axis); @@ -836,23 +794,6 @@ struct animmodel : model { if(offsetyaw) m.rotate_around_z(offsetyaw*RAD); if(offsetpitch) m.rotate_around_y(-offsetpitch*RAD); } - void genBIH(vector &bih) { - if(parts.empty()) return; - matrix4x3 m; - initmatrix(m); - parts[0]->genBIH(bih, m); - } - void preloadBIH() { - model::preloadBIH(); - if(bih) loopv(parts) parts[i]->preloadBIH(); - } - BIH *setBIH() { - if(bih) return bih; - vector meshes; - genBIH(meshes); - bih = new BIH(meshes); - return bih; - } bool link(part *p, const char *tag, const vec &translate = vec(0, 0, 0), int anim = -1, int basetime = 0, vec *pos = NULL) { if(parts.empty()) return false; return parts[0]->link(p, tag, translate, anim, basetime, pos); diff --git a/src/engine/bih.cpp b/src/engine/bih.cpp index e406008..e5c6e2a 100644 --- a/src/engine/bih.cpp +++ b/src/engine/bih.cpp @@ -262,9 +262,6 @@ BIH::~BIH() { bool mmintersect(const extentity &e, const vec &o, const vec &ray, float maxdist, int mode, float &dist) { model *m = loadmapmodel(e.attr2); if(!m) return false; - if(mode&RAY_SHADOW) { - if(!m->shadow || e.flags&EF_NOSHADOW) return false; - } else if((mode&RAY_ENTS)!=RAY_ENTS && (!m->collide || e.flags&EF_NOCOLLIDE)) return false; if(!m->bih && (lightmapping > 1 || !m->setBIH())) return false; vec mo = vec(o).sub(e.o), mray(ray); @@ -278,4 +275,3 @@ bool mmintersect(const extentity &e, const vec &o, const vec &ray, float maxdist } return m->bih->traverse(mo, mray, maxdist ? maxdist : 1e16f, dist, mode); } - diff --git a/src/engine/command.cpp b/src/engine/command.cpp index 5248899..20312a7 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -919,23 +919,23 @@ static void compilelookup(vector &code, const char *&p, int ltype) { case ID_SVAR: code.add(CODE_SVAR|((ltype >= VAL_ANY ? VAL_STR : ltype)<index<<8)); goto done; case ID_ALIAS: code.add((id->index < MAXARGS ? CODE_LOOKUPARG : CODE_LOOKUP)|((ltype >= VAL_ANY ? VAL_STR : ltype)<index<<8)); goto done; case ID_COMMAND: { - int comtype = CODE_COM, numargs = 0; + int comtype = CODE_COM; code.add(CODE_ENTER); for(const char *fmt = id->args; *fmt; fmt++) switch(*fmt) { - case 's': compilestr(code, NULL, 0, true); numargs++; break; - case 'i': compileint(code); numargs++; break; - case 'b': compileint(code, INT_MIN); numargs++; break; - case 'f': compilefloat(code); numargs++; break; - case 't': compilenull(code); numargs++; break; - case 'e': compileblock(code); numargs++; break; - case 'r': compileident(code); numargs++; break; - case '$': compileident(code, id); numargs++; break; - case 'N': compileint(code, -1); numargs++; break; + case 's': compilestr(code, NULL, 0, true); break; + case 'i': compileint(code); break; + case 'b': compileint(code, INT_MIN); break; + case 'f': compilefloat(code); break; + case 't': compilenull(code); break; + case 'e': compileblock(code); break; + case 'r': compileident(code); break; + case '$': compileident(code, id); break; + case 'N': compileint(code, -1); break; #ifndef STANDALONE - case 'D': comtype = CODE_COMD; numargs++; break; + case 'D': comtype = CODE_COMD; break; #endif - case 'C': comtype = CODE_COMC; numargs = 1; goto endfmt; - case 'V': comtype = CODE_COMV; numargs = 2; goto endfmt; + case 'C': comtype = CODE_COMC; goto endfmt; + case 'V': comtype = CODE_COMV; goto endfmt; case '1': case '2': case '3': case '4': break; } endfmt: diff --git a/src/engine/engine.h b/src/engine/engine.h index 1b1d82f..c4a534a 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -8,7 +8,6 @@ #include "octa.h" #include "lightmap.h" -#include "bih.h" #include "texture.h" #include "model.h" @@ -82,20 +81,6 @@ extern int compactvslots(); extern void reloadtextures(); extern void cleanuptextures(); -// shadowmap - -extern int shadowmap, shadowmapcasters; -extern bool shadowmapping; -extern matrix4 shadowmatrix; - -extern bool isshadowmapcaster(const vec &o, float rad); -extern bool addshadowmapcaster(const vec &o, float xyrad, float zrad); -extern bool isshadowmapreceiver(vtxarray *va); -extern void rendershadowmap(); -extern void pushshadowmap(); -extern void rendershadowmapreceivers(); -extern void guessshadowdir(); - // rendergl extern bool hasVAO, hasFBO, hasAFBO, hasDS, hasTF, hasTRG, hasTSW, hasS3TC, hasFXT1, hasLATC, hasRGTC, hasAF, hasFBB, hasUBO, hasMBR; extern int glversion, glslversion, glcompat; @@ -353,11 +338,6 @@ extern void mousemove(int dx, int dy); extern bool overlapsdynent(const vec &o, float radius); extern void rotatebb(vec ¢er, vec &radius, int yaw); extern float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity *t = NULL); -struct ShadowRayCache; -extern ShadowRayCache *newshadowraycache(); -extern void freeshadowraycache(ShadowRayCache *&cache); -extern void resetshadowraycache(ShadowRayCache *cache); -extern float shadowray(ShadowRayCache *cache, const vec &o, const vec &ray, float radius, int mode, extentity *t = NULL); // world @@ -381,7 +361,7 @@ extern mapmodelinfo *getmminfo(int i); extern void startmodelquery(occludequery *query); extern void endmodelquery(); extern void preloadmodelshaders(); -extern void preloadusedmapmodels(bool msg = false, bool bih = false); +extern void preloadusedmapmodels(bool msg = false); static inline model *loadmapmodel(int n) { extern vector mapmodels; diff --git a/src/engine/lightmap.cpp b/src/engine/lightmap.cpp index 3840d58..9cc835e 100644 --- a/src/engine/lightmap.cpp +++ b/src/engine/lightmap.cpp @@ -20,7 +20,6 @@ struct lightmapworker { VSlot *vslot; Slot *slot; vector lights; - ShadowRayCache *shadowraycache; bool needspace, doneworking; SDL_cond *spacecond; SDL_Thread *thread; @@ -377,7 +376,7 @@ static uint generatelumel(lightmapworker *w, const float tolerance, uint lightma float angle = -ray.dot(normal); if(angle <= 0) continue; if(lmshadows && mag) { - float dist = shadowray(w->shadowraycache, light.o, ray, mag - tolerance, RAY_SHADOW | (lmshadows > 1 ? RAY_ALPHAPOLY : 0)); + float dist = shadowray(light.o, ray, mag - tolerance, RAY_SHADOW | (lmshadows > 1 ? RAY_ALPHAPOLY : 0)); if(dist < mag - tolerance) continue; } lightused |= 1< 0 ? lightthreads : numcpus; - if(numthreads > 1) preloadusedmapmodels(false, true); + if(numthreads > 1) preloadusedmapmodels(false); resetlightmaps(false); clearsurfaces(worldroot); taskprogress = progress = 0; diff --git a/src/engine/lightmap.h b/src/engine/lightmap.h index d15c6a7..2744257 100644 --- a/src/engine/lightmap.h +++ b/src/engine/lightmap.h @@ -100,9 +100,7 @@ extern void lerpnormal(float u, float v, const lerpvert *lv, int numv, lerpbound #define CHECK_CALCLIGHT_PROGRESS_LOCKED(exit, show_calclight_progress, before, after) \ if(check_calclight_progress) { \ - \ if(!calclight_canceled) { \ - \ before; \ show_calclight_progress(); \ check_calclight_canceled(); \ diff --git a/src/engine/main.cpp b/src/engine/main.cpp index 83aebaa..a3d4c09 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -593,14 +593,12 @@ void resetgl() { extern void cleanupdecals(); extern void cleanupmodels(); extern void cleanuplightmaps(); - extern void cleanshadowmap(); cleanupva(); cleanupparticles(); cleanupdecals(); cleanupmodels(); cleanuptextures(); cleanuplightmaps(); - cleanshadowmap(); cleanupshaders(); cleanupgl(); setupscreen(); diff --git a/src/engine/material.cpp b/src/engine/material.cpp index 55151a1..222d93b 100644 --- a/src/engine/material.cpp +++ b/src/engine/material.cpp @@ -251,16 +251,12 @@ int optimizematsurfs(materialsurface *matbuf, int matsurfs) { } void setupmaterials(int start, int len) { - int hasmat = 0; - unionfind uf; if(!len) len = valist.length(); for(int i = start; i < len; i++) { vtxarray *va = valist[i]; materialsurface *skip = NULL; loopj(va->matsurfs) { materialsurface &m = va->matbuf[j]; - int matvol = 0; - if(matvol) hasmat |= 1<material && m.orient == skip->orient && skip->skip < 0xFFFF) skip->skip++; diff --git a/src/engine/md5.h b/src/engine/md5.h index e508cb3..f7e32b0 100644 --- a/src/engine/md5.h +++ b/src/engine/md5.h @@ -326,4 +326,3 @@ struct md5 : skelloader { }; skelcommands md5commands; - diff --git a/src/engine/model.h b/src/engine/model.h index 16f1629..40b8b00 100644 --- a/src/engine/model.h +++ b/src/engine/model.h @@ -3,20 +3,21 @@ enum { MDL_MD5, MDL_IQM, NUMMODELTYPES }; struct model { char *name; float spinyaw, spinpitch, offsetyaw, offsetpitch; - bool collide, ellipsecollide, shadow, alphadepth, depthoffset; + bool collide, ellipsecollide, alphadepth, depthoffset; float scale; vec translate; - BIH *bih; vec bbcenter, bbradius, bbextend, collidecenter, collideradius; float rejectradius, eyeheight, collidexyradius, collideheight; int batch; - model(const char *name) : name(name ? newstring(name) : NULL), spinyaw(0), spinpitch(0), offsetyaw(0), offsetpitch(0), collide(true), ellipsecollide(false), shadow(true), alphadepth(true), depthoffset(false), scale(1.0f), translate(0, 0, 0), bih(0), bbcenter(0, 0, 0), bbradius(-1, -1, -1), bbextend(0, 0, 0), collidecenter(0, 0, 0), collideradius(-1, -1, -1), rejectradius(-1), eyeheight(0.9f), collidexyradius(0), collideheight(0), batch(-1) {} - virtual ~model() { DELETEA(name); DELETEP(bih); } + model(const char *name) : name(name ? newstring(name) : NULL), spinyaw(0), spinpitch(0), offsetyaw(0), offsetpitch(0), collide(true), ellipsecollide(false), + alphadepth(true), depthoffset(false), scale(1.0f), translate(0, 0, 0), bbcenter(0, 0, 0), bbradius(-1, -1, -1), bbextend(0, 0, 0), + collidecenter(0, 0, 0), collideradius(-1, -1, -1), rejectradius(-1), eyeheight(0.9f), collidexyradius(0), collideheight(0), batch(-1) {} + + virtual ~model() { DELETEA(name); } virtual void calcbb(vec ¢er, vec &radius) = 0; virtual void render(int anim, int basetime, int basetime2, const vec &o, float yaw, float pitch, dynent *d, modelattach *a = NULL, const vec &color = vec(0, 0, 0), const vec &dir = vec(0, 0, 0), float transparent = 1) = 0; virtual bool load() = 0; virtual int type() const = 0; - virtual BIH *setBIH() { return 0; } virtual bool skeletal() const { return false; } virtual void setshader(Shader *) {} virtual void setspec(float) {} @@ -25,7 +26,6 @@ struct model { virtual void setalphablend(bool) {} virtual void setfullbright(float) {} virtual void setcullface(bool) {} - virtual void preloadBIH() { if(!bih) setBIH(); } virtual void preloadshaders() {} virtual void preloadmeshes() {} virtual void cleanup() {} diff --git a/src/engine/octa.h b/src/engine/octa.h index 0bc4762..82d194d 100644 --- a/src/engine/octa.h +++ b/src/engine/octa.h @@ -103,14 +103,12 @@ struct vtxarray { ivec o; int size; // location and size of cube. ivec geommin, geommax; // BB of geom - ivec shadowmapmin, shadowmapmax; // BB of shadowmapped surfaces ivec matmin, matmax; // BB of any materials ivec bbmin, bbmax; // BB of everything including children uchar curvfc, occluded; occludequery *query; vector mapmodels; int hasmerges, mergelevel; - bool shadowed; }; struct cube; diff --git a/src/engine/octaedit.cpp b/src/engine/octaedit.cpp index 4ba5e17..8652ed6 100644 --- a/src/engine/octaedit.cpp +++ b/src/engine/octaedit.cpp @@ -1610,7 +1610,7 @@ void rendertexturepanel(int w, int h) { hudmatrix.scale(h/1800.0f, h/1800.0f, 1); flushhudmatrix(false); SETSHADER(hudrgb); - int y = 50, gap = 10; + int y = 50, gap = 10;(void)y; gle::defvertex(2); gle::deftexcoord0(); loopi(7) { diff --git a/src/engine/octarender.cpp b/src/engine/octarender.cpp index aa1da76..7096f47 100644 --- a/src/engine/octarender.cpp +++ b/src/engine/octarender.cpp @@ -390,29 +390,6 @@ int recalcprogress = 0; vector tjoints; -vec shadowmapmin, shadowmapmax; - -int calcshadowmask(vec *pos, int numpos) { - extern vec shadowdir; - int mask = 0, used = 1; - vec pe = vec(pos[1]).sub(pos[0]); - loopk(numpos-2) { - vec e = vec(pos[k+2]).sub(pos[0]); - if(vec().cross(pe, e).dot(shadowdir)>0) { - mask |= 1<geommin = bbmin; va->geommax = bbmax; calcmatbb(co, size, va->matmin, va->matmax); - va->shadowmapmin = ivec(shadowmapmin.mul(8)).shr(3); - va->shadowmapmax = ivec(shadowmapmax.mul(8)).add(7).shr(3); va->hasmerges = vahasmerges; va->mergelevel = vamergemax; } @@ -1233,7 +1206,6 @@ void allchanged(bool load) { clearvas(worldroot); resetqueries(); resetclipplanes(); - guessshadowdir(); entitiesinoctanodes(); tjoints.setsize(0); if(filltjoints) findtjoints(); diff --git a/src/engine/physics.cpp b/src/engine/physics.cpp index f7e5342..5fa7c3f 100644 --- a/src/engine/physics.cpp +++ b/src/engine/physics.cpp @@ -95,38 +95,35 @@ extern void entselectionbox(const entity &e, vec &eo, vec &es); float hitentdist; int hitent, hitorient; -static float disttoent(octaentities *oc, const vec &o, const vec &ray, float radius, int mode, extentity *t) { - vec eo, es; - int orient = -1; - float dist = radius, f = 0.0f; - const vector &ents = entities::getents(); - #define entintersect(mask, type, func) {\ - if((mode&(mask))==(mask)) loopv(oc->type) { \ - \ - extentity &e = *ents[oc->type[i]]; \ - if(!(e.flags&EF_OCTA) || &e==t) continue; \ - func; \ - if(f0 && vec(ray).mul(f).add(o).insidebb(oc->o, oc->size)) { \ - \ - hitentdist = dist = f; \ - hitent = oc->type[i]; \ - hitorient = orient; \ - } \ - } \ - } - entintersect(RAY_POLY, mapmodels, - if(!mmintersect(e, o, ray, radius, mode, f)) continue; - ); - entintersect(RAY_ENTS, other, - entselectionbox(e, eo, es); - if(!rayboxintersect(eo, es, o, ray, f, orient)) continue; - ); - entintersect(RAY_ENTS, mapmodels, - entselectionbox(e, eo, es); - if(!rayboxintersect(eo, es, o, ray, f, orient)) continue; - ); - return dist; -} +//~static float disttoent(octaentities *oc, const vec &o, const vec &ray, float radius, int mode, extentity *t) { + //~vec eo, es; + //~int orient = -1; + //~float dist = radius, f = 0.0f; + //~const vector &ents = entities::getents(); + //~#define entintersect(mask, type, func) {\ + //~if((mode&(mask))==(mask)) loopv(oc->type) { \ + //~\ + //~extentity &e = *ents[oc->type[i]]; \ + //~if(!(e.flags&EF_OCTA) || &e==t) continue; \ + //~func; \ + //~if(f0 && vec(ray).mul(f).add(o).insidebb(oc->o, oc->size)) { \ + //~\ + //~hitentdist = dist = f; \ + //~hitent = oc->type[i]; \ + //~hitorient = orient; \ + //~} \ + //~} \ + //~} + //~entintersect(RAY_ENTS, other, + //~entselectionbox(e, eo, es); + //~if(!rayboxintersect(eo, es, o, ray, f, orient)) continue; + //~); + //~entintersect(RAY_ENTS, mapmodels, + //~entselectionbox(e, eo, es); + //~if(!rayboxintersect(eo, es, o, ray, f, orient)) continue; + //~); + //~return dist; +//~} static float disttooutsideent(const vec &o, const vec &ray, float radius, extentity *t) { vec eo, es; @@ -147,19 +144,6 @@ static float disttooutsideent(const vec &o, const vec &ray, float radius, extent return dist; } -// optimized shadow version -static float shadowent(octaentities *oc, const vec &o, const vec &ray, float radius, int mode, extentity *t) { - float dist = radius, f = 0.0f; - const vector &ents = entities::getents(); - loopv(oc->mapmodels) { - extentity &e = *ents[oc->mapmodels[i]]; - if(!(e.flags&EF_OCTA) || &e==t) continue; - if(!mmintersect(e, o, ray, radius, mode, f)) continue; - if(f>0 && f 0 ? radius : 1e16f; \ vec v(o), invray(ray.x ? 1/ray.x : 1e16f, ray.y ? 1/ray.y : 1e16f, ray.z ? 1/ray.z : 1e16f); \ @@ -167,6 +151,7 @@ static float shadowent(octaentities *oc, const vec &o, const vec &ray, float rad levels[worldscale] = worldroot; \ int lshift = worldscale, elvl = mode&RAY_BB ? worldscale : 0; \ ivec lsizemask(invray.x>0 ? 1 : 0, invray.y>0 ? 1 : 0, invray.z>0 ? 1 : 0); \ + (void) elvl; (void) dent; #define CHECKINSIDEWORLD \ if(!insideworld(o)) { \ @@ -189,26 +174,25 @@ static float shadowent(octaentities *oc, const vec &o, const vec &ray, float rad dist += disttoworld; \ } -#define DOWNOCTREE(disttoent, earlyexit) \ - cube *lc = levels[lshift]; \ - for(;;) { \ - \ - lshift--; \ - lc += octastep(x, y, z, lshift); \ - if(lc->ext && lc->ext->ents && lshift < elvl) { \ - \ - float edist = disttoent(lc->ext->ents, o, ray, dent, mode, t); \ - if(edist < dent) { \ - \ - earlyexit return min(edist, dist); \ - elvl = lshift; \ - dent = min(dent, edist); \ - } \ - } \ - if(lc->children==NULL) break; \ - lc = lc->children; \ - levels[lshift] = lc; \ - } +//~#define DOWNOCTREE(disttoent, earlyexit) \ + //~cube *lc = levels[lshift]; \ + //~for(;;) { \ + //~lshift--; \ + //~lc += octastep(x, y, z, lshift); \ + //~if(lc->ext && lc->ext->ents && lshift < elvl) { \ + //~\ + //~float edist = disttoent(lc->ext->ents, o, ray, dent, mode, t); \ + //~if(edist < dent) { \ + //~\ + //~earlyexit return min(edist, dist); \ + //~elvl = lshift; \ + //~dent = min(dent, edist); \ + //~} \ + //~} \ + //~if(lc->children==NULL) break; \ + //~lc = lc->children; \ + //~levels[lshift] = lc; \ + //~} #define FINDCLOSEST(xclosest, yclosest, zclosest) \ float dx = (lo.x+(lsizemask.x<ext && lc->ext->ents && lshift < elvl) { + //~float edist = disttoent(lc->ext->ents, o, ray, dent, mode, t); + //~if(edist < dent) { + //~return min(edist, dist); + //~elvl = lshift; + //~dent = min(dent, edist); + //~} + //~} + if(lc->children==NULL) break; + lc = lc->children; + levels[lshift] = lc; + } + int lsize = 1<0 || !(mode&RAY_SKIPFIRST)) && @@ -267,60 +267,31 @@ float raycube(const vec &o, const vec &ray, float radius, int mode, int size, ex } // optimized version for lightmap shadowing... every cycle here counts!!! + float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity *t) { INITRAYCUBE; CHECKINSIDEWORLD; int side = O_BOTTOM, x = int(v.x), y = int(v.y), z = int(v.z); (void) side; for(;;) { - DOWNOCTREE(shadowent, ); - cube &c = *lc; - ivec lo(x&(~0U<= 0) { - return dist+max(enterdist+0.1f, 0.0f); - } - } + //~DOWNOCTREE(shadowent, ); + + cube *lc = levels[lshift]; + for(;;) { + lshift--; + lc += octastep(x, y, z, lshift); + //~if(lc->ext && lc->ext->ents && lshift < elvl) { + //~float edist = shadowent(lc->ext->ents, o, ray, dent, mode, t); + //~if(edist < dent) { + //~return min(edist, dist); + //~elvl = lshift; + //~dent = min(dent, edist); + //~} + //~} + if(lc->children==NULL) break; + lc = lc->children; + levels[lshift] = lc; } - nextcube: - FINDCLOSEST(side = O_RIGHT - lsizemask.x, side = O_FRONT - lsizemask.y, side = O_TOP - lsizemask.z); - if(dist>=radius) return dist; - UPOCTREE(return radius); - } -} - -// thread safe version -struct ShadowRayCache { - clipplanes clipcache[MAXCLIPPLANES]; - int version; - ShadowRayCache() : version(-1) {} -}; - -ShadowRayCache *newshadowraycache() { return new ShadowRayCache; } - -void freeshadowraycache(ShadowRayCache *&cache) { delete cache; cache = NULL; } - -void resetshadowraycache(ShadowRayCache *cache) { - cache->version++; - if(!cache->version) { - memclear(cache->clipcache); - cache->version = 1; - } -} - -float shadowray(ShadowRayCache *cache, const vec &o, const vec &ray, float radius, int mode, extentity *t) { - INITRAYCUBE; - CHECKINSIDEWORLD; - int side = O_BOTTOM, x = int(v.x), y = int(v.y), z = int(v.z); (void) side; - for(;;) { - DOWNOCTREE(shadowent, ); cube &c = *lc; ivec lo(x&(~0U<clipcache[int(&c - worldroot)&(MAXCLIPPLANES-1)]; - if(p.owner != &c || p.version != cache->version) { p.owner = &c; p.version = cache->version; genclipplanes(c, lo, 1<= 0) { diff --git a/src/engine/ragdoll.h b/src/engine/ragdoll.h deleted file mode 100644 index 915076e..0000000 --- a/src/engine/ragdoll.h +++ /dev/null @@ -1,424 +0,0 @@ -struct ragdollskel { - struct vert { - vec pos; - float radius, weight; - }; - struct tri { - int vert[3]; - bool shareverts(const tri &t) const { - loopi(3) loopj(3) if(vert[i] == t.vert[j]) return true; - return false; - } - }; - struct distlimit { - int vert[2]; - float mindist, maxdist; - }; - struct rotlimit { - int tri[2]; - float maxangle; - matrix3 middle; - }; - struct rotfriction { - int tri[2]; - matrix3 middle; - }; - struct joint { - int bone, tri, vert[3]; - float weight; - matrix4x3 orient; - }; - struct reljoint { - int bone, parent; - }; - bool loaded, animjoints; - int eye; - vector verts; - vector tris; - vector distlimits; - vector rotlimits; - vector rotfrictions; - vector joints; - vector reljoints; - ragdollskel() : loaded(false), animjoints(false), eye(-1) {} - void setupjoints() { - loopv(verts) verts[i].weight = 0; - loopv(joints) { - joint &j = joints[i]; - j.weight = 0; - vec pos(0, 0, 0); - loopk(3) if(j.vert[k]>=0) { - pos.add(verts[j.vert[k]].pos); - j.weight++; - verts[j.vert[k]].weight++; - } - if(j.weight) j.weight = 1/j.weight; - pos.mul(j.weight); - tri &t = tris[j.tri]; - matrix4x3 &m = j.orient; - const vec &v1 = verts[t.vert[0]].pos, - &v2 = verts[t.vert[1]].pos, - &v3 = verts[t.vert[2]].pos; - m.a = vec(v2).sub(v1).normalize(); - m.c.cross(m.a, vec(v3).sub(v1)).normalize(); - m.b.cross(m.c, m.a); - m.d = pos; - m.transpose(); - } - loopv(verts) if(verts[i].weight) verts[i].weight = 1/verts[i].weight; - reljoints.shrink(0); - } - void setuprotfrictions() { - rotfrictions.shrink(0); - loopv(tris) for(int j = i+1; j < tris.length(); j++) if(tris[i].shareverts(tris[j])) { - rotfriction &r = rotfrictions.add(); - r.tri[0] = i; - r.tri[1] = j; - } - } - void setup() { - setupjoints(); - setuprotfrictions(); - loaded = true; - } - void addreljoint(int bone, int parent) { - reljoint &r = reljoints.add(); - r.bone = bone; - r.parent = parent; - } -}; - -struct ragdolldata { - struct vert { - vec oldpos, pos, newpos; - float weight; - bool collided, stuck; - vert() : pos(0, 0, 0), newpos(0, 0, 0), weight(0), collided(false), stuck(true) {} - }; - ragdollskel *skel; - int millis, collidemillis, collisions, floating, lastmove, unsticks; - vec offset, center; - float radius, timestep, scale; - vert *verts; - matrix3 *tris; - matrix4x3 *animjoints; - dualquat *reljoints; - ragdolldata(ragdollskel *skel, float scale = 1) - : skel(skel), - millis(lastmillis), - collidemillis(0), - collisions(0), - floating(0), - lastmove(lastmillis), - unsticks(INT_MAX), - radius(0), - timestep(0), - scale(scale), - verts(new vert[skel->verts.length()]), - tris(new matrix3[skel->tris.length()]), - animjoints(!skel->animjoints || skel->joints.empty() ? NULL : new matrix4x3[skel->joints.length()]), - reljoints(skel->reljoints.empty() ? NULL : new dualquat[skel->reljoints.length()]) { - } - ~ragdolldata() { - delete[] verts; - delete[] tris; - if(animjoints) delete[] animjoints; - if(reljoints) delete[] reljoints; - } - void calcanimjoint(int i, const matrix4x3 &anim) { - if(!animjoints) return; - ragdollskel::joint &j = skel->joints[i]; - vec pos(0, 0, 0); - loopk(3) if(j.vert[k]>=0) pos.add(verts[j.vert[k]].pos); - pos.mul(j.weight); - ragdollskel::tri &t = skel->tris[j.tri]; - matrix4x3 m; - const vec &v1 = verts[t.vert[0]].pos, - &v2 = verts[t.vert[1]].pos, - &v3 = verts[t.vert[2]].pos; - m.a = vec(v2).sub(v1).normalize(); - m.c.cross(m.a, vec(v3).sub(v1)).normalize(); - m.b.cross(m.c, m.a); - m.d = pos; - animjoints[i].transposemul(m, anim); - } - void calctris() { - loopv(skel->tris) { - ragdollskel::tri &t = skel->tris[i]; - matrix3 &m = tris[i]; - const vec &v1 = verts[t.vert[0]].pos, - &v2 = verts[t.vert[1]].pos, - &v3 = verts[t.vert[2]].pos; - m.a = vec(v2).sub(v1).normalize(); - m.c.cross(m.a, vec(v3).sub(v1)).normalize(); - m.b.cross(m.c, m.a); - } - } - void calcboundsphere() { - center = vec(0, 0, 0); - loopv(skel->verts) center.add(verts[i].pos); - center.div(skel->verts.length()); - radius = 0; - loopv(skel->verts) radius = max(radius, verts[i].pos.dist(center)); - } - void init(dynent *d) { - extern int ragdolltimestepmin; - float ts = ragdolltimestepmin/1000.0f; - loopv(skel->verts) (verts[i].oldpos = verts[i].pos).sub(vec(d->vel).add(d->falling).mul(ts)); - timestep = ts; - calctris(); - calcboundsphere(); - offset = d->o; - offset.sub(skel->eye >= 0 ? verts[skel->eye].pos : center); - offset.z += (d->eyeheight + d->aboveeye)/2; - } - void move(dynent *pl, float ts); - void updatepos(); - void constrain(); - void constraindist(); - void applyrotlimit(ragdollskel::tri &t1, ragdollskel::tri &t2, float angle, const vec &axis); - void constrainrot(); - void calcrotfriction(); - void applyrotfriction(float ts); - void tryunstick(float speed); - static inline bool collidevert(const vec &pos, const vec &dir, float radius) { - static struct vertent : physent { - vertent() { - type = ENT_BOUNCE; - radius = xradius = yradius = eyeheight = aboveeye = 1; - } - } v; - v.o = pos; - if(v.radius != radius) v.radius = v.xradius = v.yradius = v.eyeheight = v.aboveeye = radius; - return collide(&v, dir, 0, false); - } -}; - -/* - seed particle position = avg(modelview * base2anim * spherepos) - mapped transform = invert(curtri) * origtrig - parented transform = parent{invert(curtri) * origtrig} * (invert(parent{base2anim}) * base2anim) -*/ - -void ragdolldata::constraindist() { - float invscale = 1.0f/scale; - loopv(skel->distlimits) { - ragdollskel::distlimit &d = skel->distlimits[i]; - vert &v1 = verts[d.vert[0]], &v2 = verts[d.vert[1]]; - vec dir = vec(v2.pos).sub(v1.pos); - float dist = dir.magnitude()*invscale, cdist; - if(dist < d.mindist) cdist = d.mindist; - else if(dist > d.maxdist) cdist = d.maxdist; - else continue; - if(dist > 1e-4f) dir.mul(cdist*0.5f/dist); - else dir = vec(0, 0, cdist*0.5f/invscale); - vec center = vec(v1.pos).add(v2.pos).mul(0.5f); - v1.newpos.add(vec(center).sub(dir)); - v1.weight++; - v2.newpos.add(vec(center).add(dir)); - v2.weight++; - } -} - -inline void ragdolldata::applyrotlimit(ragdollskel::tri &t1, ragdollskel::tri &t2, float angle, const vec &axis) { - vert &v1a = verts[t1.vert[0]], &v1b = verts[t1.vert[1]], &v1c = verts[t1.vert[2]], - &v2a = verts[t2.vert[0]], &v2b = verts[t2.vert[1]], &v2c = verts[t2.vert[2]]; - vec m1 = vec(v1a.pos).add(v1b.pos).add(v1c.pos).div(3), - m2 = vec(v2a.pos).add(v2b.pos).add(v2c.pos).div(3), - q1a, q1b, q1c, q2a, q2b, q2c; - float w1 = q1a.cross(axis, vec(v1a.pos).sub(m1)).magnitude() + - q1b.cross(axis, vec(v1b.pos).sub(m1)).magnitude() + - q1c.cross(axis, vec(v1c.pos).sub(m1)).magnitude(), - w2 = q2a.cross(axis, vec(v2a.pos).sub(m2)).magnitude() + - q2b.cross(axis, vec(v2b.pos).sub(m2)).magnitude() + - q2c.cross(axis, vec(v2c.pos).sub(m2)).magnitude(); - angle /= w1 + w2 + 1e-9f; - float a1 = angle*w2, a2 = -angle*w1, - s1 = sinf(a1), s2 = sinf(a2); - vec c1 = vec(axis).mul(1 - cosf(a1)), c2 = vec(axis).mul(1 - cosf(a2)); - v1a.newpos.add(vec().cross(c1, q1a).madd(q1a, s1).add(v1a.pos)); - v1a.weight++; - v1b.newpos.add(vec().cross(c1, q1b).madd(q1b, s1).add(v1b.pos)); - v1b.weight++; - v1c.newpos.add(vec().cross(c1, q1c).madd(q1c, s1).add(v1c.pos)); - v1c.weight++; - v2a.newpos.add(vec().cross(c2, q2a).madd(q2a, s2).add(v2a.pos)); - v2a.weight++; - v2b.newpos.add(vec().cross(c2, q2b).madd(q2b, s2).add(v2b.pos)); - v2b.weight++; - v2c.newpos.add(vec().cross(c2, q2c).madd(q2c, s2).add(v2c.pos)); - v2c.weight++; -} - -void ragdolldata::constrainrot() { - loopv(skel->rotlimits) { - ragdollskel::rotlimit &r = skel->rotlimits[i]; - matrix3 rot; - rot.mul(tris[r.tri[0]], r.middle); - rot.multranspose(tris[r.tri[1]]); - vec axis; - float angle; - if(!rot.calcangleaxis(angle, axis)) continue; - angle = r.maxangle - fabs(angle); - if(angle >= 0) continue; - angle += 1e-3f; - applyrotlimit(skel->tris[r.tri[0]], skel->tris[r.tri[1]], angle, axis); - } -} - -VAR(ragdolltimestepmin, 1, 5, 50); -VAR(ragdolltimestepmax, 1, 10, 50); -FVAR(ragdollrotfric, 0, 0.85f, 1); -FVAR(ragdollrotfricstop, 0, 0.1f, 1); - -void ragdolldata::calcrotfriction() { - loopv(skel->rotfrictions) { - ragdollskel::rotfriction &r = skel->rotfrictions[i]; - r.middle.transposemul(tris[r.tri[0]], tris[r.tri[1]]); - } -} - -void ragdolldata::applyrotfriction(float ts) { - calctris(); - float stopangle = 2*M_PI*ts*ragdollrotfricstop, rotfric = 1.0f - pow(ragdollrotfric, ts*1000.0f/ragdolltimestepmin); - loopv(skel->rotfrictions) { - ragdollskel::rotfriction &r = skel->rotfrictions[i]; - matrix3 rot; - rot.mul(tris[r.tri[0]], r.middle); - rot.multranspose(tris[r.tri[1]]); - vec axis; - float angle; - if(rot.calcangleaxis(angle, axis)) { - angle *= -(fabs(angle) >= stopangle ? rotfric : 1.0f); - applyrotlimit(skel->tris[r.tri[0]], skel->tris[r.tri[1]], angle, axis); - } - } - loopv(skel->verts) { - vert &v = verts[i]; - if(v.weight) v.pos = v.newpos.div(v.weight); - v.newpos = vec(0, 0, 0); - v.weight = 0; - } -} - -void ragdolldata::tryunstick(float speed) { - vec unstuck(0, 0, 0); - int stuck = 0; - loopv(skel->verts) { - vert &v = verts[i]; - if(v.stuck) { - if(collidevert(v.pos, vec(0, 0, 0), skel->verts[i].radius)) { stuck++; continue; } - v.stuck = false; - } - unstuck.add(v.pos); - } - unsticks = 0; - if(!stuck || stuck >= skel->verts.length()) return; - unstuck.div(skel->verts.length() - stuck); - loopv(skel->verts) { - vert &v = verts[i]; - if(v.stuck) { - v.pos.add(vec(unstuck).sub(v.pos).rescale(speed)); - unsticks++; - } - } -} - -void ragdolldata::updatepos() { - loopv(skel->verts) { - vert &v = verts[i]; - if(v.weight) { - v.newpos.div(v.weight); - if(!collidevert(v.newpos, vec(v.newpos).sub(v.pos), skel->verts[i].radius)) v.pos = v.newpos; - else { - vec dir = vec(v.newpos).sub(v.oldpos); - if(dir.dot(collidewall) < 0) v.oldpos = vec(v.pos).sub(dir.reflect(collidewall)); - v.collided = true; - } - } - v.newpos = vec(0, 0, 0); - v.weight = 0; - } -} - -VAR(ragdollconstrain, 1, 5, 100); - -void ragdolldata::constrain() { - loopi(ragdollconstrain) { - constraindist(); - updatepos(); - calctris(); - constrainrot(); - updatepos(); - } -} - -FVAR(ragdollbodyfric, 0, 0.95f, 1); -FVAR(ragdollbodyfricscale, 0, 2, 10); -FVAR(ragdollgroundfric, 0, 0.8f, 1); -FVAR(ragdollairfric, 0, 0.996f, 1); -FVAR(ragdollunstick, 0, 10, 1e3f); -VAR(ragdollexpireoffset, 0, 1500, 30000); - -void ragdolldata::move(dynent *pl, float ts) { - extern const float GRAVITY; - if(collidemillis && lastmillis > collidemillis) return; - pl->inwater = MAT_AIR; - calcrotfriction(); - float tsfric = timestep ? ts/timestep : 1, - airfric = ragdollairfric + min((ragdollbodyfricscale*collisions)/skel->verts.length(), 1.0f)*(ragdollbodyfric - ragdollairfric); - collisions = 0; - loopv(skel->verts) { - vert &v = verts[i]; - vec dpos = vec(v.pos).sub(v.oldpos); - dpos.z -= GRAVITY*ts*ts; - dpos.mul(pow(1.0f * (v.collided ? ragdollgroundfric : airfric), ts*1000.0f/ragdolltimestepmin)*tsfric); - v.oldpos = v.pos; - v.pos.add(dpos); - } - applyrotfriction(ts); - loopv(skel->verts) { - vert &v = verts[i]; - if(v.pos.z < 0) { v.pos.z = 0; v.oldpos = v.pos; collisions++; } - vec dir = vec(v.pos).sub(v.oldpos); - v.collided = collidevert(v.pos, dir, skel->verts[i].radius); - if(v.collided) { - v.pos = v.oldpos; - v.oldpos.sub(dir.reflect(collidewall)); - collisions++; - } - } - if(unsticks && ragdollunstick) tryunstick(ts*ragdollunstick); - timestep = ts; - if(collisions) { - floating = 0; - if(!collidemillis) collidemillis = lastmillis + ragdollexpireoffset; - } - else if(++floating > 1 && lastmillis < collidemillis) collidemillis = 0; - constrain(); - calctris(); - calcboundsphere(); -} - -FVAR(ragdolleyesmooth, 0, 0.5f, 1); -VAR(ragdolleyesmoothmillis, 1, 250, 10000); - -void moveragdoll(dynent *d) { - if(!curtime || !d->ragdoll) return; - if(!d->ragdoll->collidemillis || lastmillis < d->ragdoll->collidemillis) { - int lastmove = d->ragdoll->lastmove; - while(d->ragdoll->lastmove + (lastmove == d->ragdoll->lastmove ? ragdolltimestepmin : ragdolltimestepmax) <= lastmillis) { - int timestep = min(ragdolltimestepmax, lastmillis - d->ragdoll->lastmove); - d->ragdoll->move(d, timestep/1000.0f); - d->ragdoll->lastmove += timestep; - } - } - vec eye = d->ragdoll->skel->eye >= 0 ? d->ragdoll->verts[d->ragdoll->skel->eye].pos : d->ragdoll->center; - eye.add(d->ragdoll->offset); - float k = pow(ragdolleyesmooth, float(curtime)/ragdolleyesmoothmillis); - d->o.mul(k).add(eye.mul(1-k)); -} - -void cleanragdoll(dynent *d) { - DELETEP(d->ragdoll); -} diff --git a/src/engine/rendergl.cpp b/src/engine/rendergl.cpp index e448415..2cdfff7 100644 --- a/src/engine/rendergl.cpp +++ b/src/engine/rendergl.cpp @@ -308,9 +308,6 @@ void gl_checkextensions() { hwcubetexsize = val; if(glversion >= 300 || hasext("GL_ARB_texture_float") || hasext("GL_ATI_texture_float")) { hasTF = true; - shadowmap = 1; - extern int smoothshadowmappeel; - smoothshadowmappeel = 1; } if(glversion >= 300 || hasext("GL_ARB_texture_rg")) { hasTRG = true; @@ -876,7 +873,7 @@ bool renderedgame = false; void rendergame(bool mainpass) { game::rendergame(mainpass); - if(!shadowmapping) renderedgame = true; + renderedgame = true; } int drawtex = 0; diff --git a/src/engine/rendermodel.cpp b/src/engine/rendermodel.cpp index 8174e22..eb75b69 100644 --- a/src/engine/rendermodel.cpp +++ b/src/engine/rendermodel.cpp @@ -5,7 +5,6 @@ VAR(animationinterpolationtime, 0, 150, 1000); model *loadingmodel = NULL; -#include "ragdoll.h" #include "animmodel.h" #include "skelmodel.h" @@ -152,13 +151,6 @@ void mdlpitch(float *angle) { COMMAND(mdlpitch, "f"); -void mdlshadow(int *shadow) { - checkmdl; - loadingmodel->shadow = *shadow!=0; -} - -COMMAND(mdlshadow, "i"); - void mdlbb(float *rad, float *h, float *eyeheight) { checkmdl; loadingmodel->collidexyradius = *rad; @@ -182,79 +174,6 @@ void mdlname() { COMMAND(mdlname, ""); -#define checkragdoll \ - checkmdl; \ - if(!loadingmodel->skeletal()) { conoutf(CON_ERROR, "not loading a skeletal model"); return; } \ - skelmodel *m = (skelmodel *)loadingmodel; \ - if(m->parts.empty()) return; \ - skelmodel::skelmeshgroup *meshes = (skelmodel::skelmeshgroup *)m->parts.last()->meshes; \ - if(!meshes) return; \ - skelmodel::skeleton *skel = meshes->skel; \ - if(!skel->ragdoll) skel->ragdoll = new ragdollskel; \ - ragdollskel *ragdoll = skel->ragdoll; \ - if(ragdoll->loaded) return; - -void rdvert(float *x, float *y, float *z, float *radius) { - checkragdoll; - ragdollskel::vert &v = ragdoll->verts.add(); - v.pos = vec(*x, *y, *z); - v.radius = *radius > 0 ? *radius : 1; -} -COMMAND(rdvert, "ffff"); - -void rdeye(int *v) { - checkragdoll; - ragdoll->eye = *v; -} -COMMAND(rdeye, "i"); - -void rdtri(int *v1, int *v2, int *v3) { - checkragdoll; - ragdollskel::tri &t = ragdoll->tris.add(); - t.vert[0] = *v1; - t.vert[1] = *v2; - t.vert[2] = *v3; -} -COMMAND(rdtri, "iii"); - -void rdjoint(int *n, int *t, int *v1, int *v2, int *v3) { - checkragdoll; - if(*n < 0 || *n >= skel->numbones) return; - ragdollskel::joint &j = ragdoll->joints.add(); - j.bone = *n; - j.tri = *t; - j.vert[0] = *v1; - j.vert[1] = *v2; - j.vert[2] = *v3; -} -COMMAND(rdjoint, "iibbb"); - -void rdlimitdist(int *v1, int *v2, float *mindist, float *maxdist) { - checkragdoll; - ragdollskel::distlimit &d = ragdoll->distlimits.add(); - d.vert[0] = *v1; - d.vert[1] = *v2; - d.mindist = *mindist; - d.maxdist = max(*maxdist, *mindist); -} -COMMAND(rdlimitdist, "iiff"); - -void rdlimitrot(int *t1, int *t2, float *maxangle, float *qx, float *qy, float *qz, float *qw) { - checkragdoll; - ragdollskel::rotlimit &r = ragdoll->rotlimits.add(); - r.tri[0] = *t1; - r.tri[1] = *t2; - r.maxangle = *maxangle * RAD; - r.middle = matrix3(quat(*qx, *qy, *qz, *qw)); -} -COMMAND(rdlimitrot, "iifffff"); - -void rdanimjoints(int *on) { - checkragdoll; - ragdoll->animjoints = *on!=0; -} -COMMAND(rdanimjoints, "i"); - // mapmodels vector mapmodels; @@ -303,7 +222,7 @@ void flushpreloadedmodels(bool msg) { loadprogress = 0; } -void preloadusedmapmodels(bool msg, bool bih) { +void preloadusedmapmodels(bool msg) { vector &ents = entities::getents(); vector mapmodels; loopv(ents) { @@ -317,7 +236,6 @@ void preloadusedmapmodels(bool msg, bool bih) { if(!mmi) { if(msg) conoutf(CON_WARN, "could not find map model: %d", mmindex); } else if(mmi->name[0] && !loadmodel(NULL, mmindex, msg)) { if(msg) conoutf(CON_WARN, "could not load model: %s", mmi->name); } else if(mmi->m) { - if(bih) mmi->m->preloadBIH(); mmi->m->preloadmeshes(); } } @@ -471,14 +389,8 @@ void renderbatchedmodel(model *m, batchedmodel &b) { modelattach *a = NULL; if(b.attached>=0) a = &modelattached[b.attached]; int anim = b.anim; - if(shadowmapping) { - anim |= ANIM_NOSKIN; - GLOBALPARAMF(shadowintensity, b.transparent); - } - else { - if(b.flags&MDL_FULLBRIGHT) anim |= ANIM_FULLBRIGHT; - if(b.flags&MDL_GHOST) anim |= ANIM_GHOST; - } + if(b.flags&MDL_FULLBRIGHT) anim |= ANIM_FULLBRIGHT; + if(b.flags&MDL_GHOST) anim |= ANIM_GHOST; m->render(anim, b.basetime, b.basetime2, b.pos, b.yaw, b.pitch, b.d, a, b.color, b.dir, b.transparent); } @@ -519,11 +431,10 @@ void endmodelbatches() { query = bm.query; if(query) startquery(query); } - if(bm.transparent < 1 && (!query || query->owner==bm.d) && !shadowmapping) { + if(bm.transparent < 1 && (!query || query->owner==bm.d)) { transparentmodel &tm = transparent.add(); tm.m = b.m; tm.batched = &bm; - tm.dist = camera1->o.dist(bm.d && bm.d->ragdoll ? bm.d->ragdoll->center : bm.pos); continue; } if(!rendered) { b.m->startrender(); rendered = true; } @@ -617,17 +528,7 @@ static inline void disablecullmodelquery() { static inline int cullmodel(const vec ¢er, float radius, int flags, dynent *d = NULL) { if(flags&MDL_CULL_DIST && center.dist(camera1->o)/radius>maxmodelradiusdistance) return MDL_CULL_DIST; - if(flags&MDL_CULL_VFC) { - if(shadowmapping && !isshadowmapcaster(center, radius)) return MDL_CULL_VFC; - } - if(shadowmapping) { - if(d) { - if(flags&MDL_CULL_OCCLUDED && d->occluded>=OCCLUDE_PARENT) return MDL_CULL_OCCLUDED; - if(flags&MDL_CULL_QUERY && d->occluded+1>=OCCLUDE_BB && d->query && d->query->owner==d && checkquery(d->query)) return MDL_CULL_QUERY; - } - if(!addshadowmapcaster(center, radius, radius)) return MDL_CULL_VFC; - } - else if(flags&MDL_CULL_OCCLUDED && modeloccluded(center, radius)) { + if(flags&MDL_CULL_OCCLUDED && modeloccluded(center, radius)) { if(d) d->occluded = OCCLUDE_PARENT; return MDL_CULL_OCCLUDED; } @@ -639,26 +540,18 @@ static inline int cullmodel(const vec ¢er, float radius, int flags, dynent * } void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, float yaw, float pitch, int flags, dynent *d, modelattach *a, int basetime, int basetime2, float trans) { - if(shadowmapping && !(flags&(MDL_SHADOW|MDL_DYNSHADOW))) return; model *m = loadmodel(mdl); if(!m) return; vec center(0, 0, 0), bbradius(0, 0, 0); float radius = 0; - bool shadow = !shadowmap && (flags&(MDL_SHADOW|MDL_DYNSHADOW)); - if(flags&(MDL_CULL_VFC|MDL_CULL_DIST|MDL_CULL_OCCLUDED|MDL_CULL_QUERY|MDL_SHADOW|MDL_DYNSHADOW)) { + if(flags&(MDL_CULL_VFC|MDL_CULL_DIST|MDL_CULL_OCCLUDED|MDL_CULL_QUERY)) { if(flags&MDL_CULL_QUERY) { if(!oqfrags || !oqdynent || !d) flags &= ~MDL_CULL_QUERY; } m->boundbox(center, bbradius); radius = bbradius.magnitude(); - if(d && d->ragdoll) { - radius = max(radius, d->ragdoll->radius); - center = d->ragdoll->center; - } - else { - center.rotate_around_z(yaw*RAD); - center.add(o); - } + center.rotate_around_z(yaw*RAD); + center.add(o); int culled = cullmodel(center, radius, flags, d); if(culled) { if(culled&(MDL_CULL_OCCLUDED|MDL_CULL_QUERY) && flags&MDL_CULL_QUERY) { @@ -668,10 +561,9 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl } return; } - if(shadowmapping) flags &= ~MDL_CULL_QUERY; } if(flags&MDL_NORENDER) anim |= ANIM_NORENDER; - else if(showboundingbox && !shadowmapping && editmode) { + else if(showboundingbox && editmode) { notextureshader->set(); if(d && showboundingbox==1) { render3dbox(d->o, d->eyeheight, d->aboveeye, d->radius); @@ -687,32 +579,26 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl } } vec lightcolor(1, 1, 1), lightdir(0, 0, 1); - if(!shadowmapping) { - vec pos = o; - if(d) { - d->occluded = OCCLUDE_NOTHING; - if(!light) light = &d->light; - if(flags&MDL_LIGHT && light->millis!=lastmillis) { - if(d->ragdoll) { - pos = d->ragdoll->center; - pos.z += radius/2; - } - else if(d->type < ENT_CAMERA) pos.z += 0.75f*(d->eyeheight + d->aboveeye); - lightreaching(pos, light->color, light->dir); - light->millis = lastmillis; - } + vec pos = o; + if(d) { + d->occluded = OCCLUDE_NOTHING; + if(!light) light = &d->light; + if(flags&MDL_LIGHT && light->millis!=lastmillis) { + if(d->type < ENT_CAMERA) pos.z += 0.75f*(d->eyeheight + d->aboveeye); + lightreaching(pos, light->color, light->dir); + light->millis = lastmillis; } - else if(flags&MDL_LIGHT) { - if(!light) { - lightreaching(pos, lightcolor, lightdir); - } - else if(light->millis!=lastmillis) { - lightreaching(pos, light->color, light->dir); - light->millis = lastmillis; - } + } + else if(flags&MDL_LIGHT) { + if(!light) { + lightreaching(pos, lightcolor, lightdir); + } + else if(light->millis!=lastmillis) { + lightreaching(pos, light->color, light->dir); + light->millis = lastmillis; } - if(light) { lightcolor = light->color; lightdir = light->dir; } } + if(light) { lightcolor = light->color; lightdir = light->dir; } if(a) for(int i = 0; a[i].tag; i++) { if(a[i].name) a[i].m = loadmodel(a[i].name); //if(a[i].m && a[i].m->type()!=m->type()) a[i].m = NULL; @@ -731,10 +617,7 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl b.basetime2 = basetime2; b.transparent = trans; b.flags = flags & ~(MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED); - if(!shadow) { - b.flags &= ~(MDL_SHADOW|MDL_DYNSHADOW); - if(flags&MDL_CULL_VFC) b.flags |= MDL_CULL_VFC; - } + if(flags&MDL_CULL_VFC) b.flags |= MDL_CULL_VFC; mb.flags |= b.flags; b.d = d; b.attached = a ? modelattached.length() : -1; @@ -743,14 +626,8 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl return; } m->startrender(); - if(shadowmapping) { - anim |= ANIM_NOSKIN; - GLOBALPARAMF(shadowintensity, trans); - } - else { - if(flags&MDL_FULLBRIGHT) anim |= ANIM_FULLBRIGHT; - if(flags&MDL_GHOST) anim |= ANIM_GHOST; - } + if(flags&MDL_FULLBRIGHT) anim |= ANIM_FULLBRIGHT; + if(flags&MDL_GHOST) anim |= ANIM_GHOST; if(flags&MDL_CULL_QUERY) { d->query = newquery(d); if(d->query) startquery(d->query); @@ -760,12 +637,6 @@ void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, fl m->endrender(); } -void abovemodel(vec &o, const char *mdl) { - model *m = loadmodel(mdl); - if(!m) return; - o.z += m->above(); -} - bool matchanim(const char *name, const char *pattern) { for(;; pattern++) { const char *s = name; @@ -831,7 +702,7 @@ VAR(animoverride, -1, 0, NUMANIMS-1); VAR(testanims, 0, 0, 1); VAR(testpitch, -90, 0, 90); -void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade, bool ragdoll) { +void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade) { int anim = hold ? hold : ANIM_IDLE|ANIM_LOOP; float yaw = testanims && d==player ? 0 : d->yaw+90, pitch = testpitch && d==player ? testpitch : d->pitch; @@ -841,13 +712,7 @@ void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int else if(d->state==CS_DEAD) { anim = ANIM_DYING|ANIM_NOPITCH; basetime = lastpain; - if(ragdoll) { - if(!d->ragdoll || d->ragdoll->millis < basetime) { - DELETEP(d->ragdoll); - anim |= ANIM_RAGDOLL; - } - } - else if(lastmillis-basetime>1000) anim = ANIM_DEAD|ANIM_LOOP|ANIM_NOPITCH; + if(lastmillis-basetime>1000) anim = ANIM_DEAD|ANIM_LOOP|ANIM_NOPITCH; } else if(d->state==CS_EDITING || d->state==CS_SPECTATOR) anim = ANIM_EDIT|ANIM_LOOP; else if(d->state==CS_LAGGED) anim = ANIM_LAG|ANIM_LOOP; @@ -872,15 +737,13 @@ void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int } if((anim&ANIM_INDEX)==ANIM_IDLE && (anim>>ANIM_SECONDARY)&ANIM_INDEX) anim >>= ANIM_SECONDARY; } - if(d->ragdoll && (!ragdoll || (anim&ANIM_INDEX)!=ANIM_DYING)) DELETEP(d->ragdoll); if(!((anim>>ANIM_SECONDARY)&ANIM_INDEX)) anim |= (ANIM_IDLE|ANIM_LOOP)<type==ENT_PLAYER) flags |= MDL_FULLBRIGHT; else flags |= MDL_CULL_DIST; if(d->state==CS_LAGGED) fade = min(fade, 0.3f); - else flags |= MDL_DYNSHADOW; - if(drawtex == DRAWTEX_MODELPREVIEW) flags &= ~(MDL_LIGHT | MDL_FULLBRIGHT | MDL_CULL_VFC | MDL_CULL_OCCLUDED | MDL_CULL_QUERY | MDL_CULL_DIST | MDL_DYNSHADOW); + if(drawtex == DRAWTEX_MODELPREVIEW) flags &= ~(MDL_LIGHT | MDL_FULLBRIGHT | MDL_CULL_VFC | MDL_CULL_OCCLUDED | MDL_CULL_QUERY | MDL_CULL_DIST); rendermodel(NULL, mdlname, anim, o, yaw, pitch, flags, d, attachments, basetime, 0, fade); } diff --git a/src/engine/renderparticles.cpp b/src/engine/renderparticles.cpp index a3cc91f..f96dc45 100644 --- a/src/engine/renderparticles.cpp +++ b/src/engine/renderparticles.cpp @@ -800,7 +800,7 @@ static void regularsplash(int type, int color, int radius, int num, int fade, co } bool canaddparticles() { - return !renderedgame && !shadowmapping && !minimized; + return !renderedgame && !minimized; } void regular_particle_splash(int type, int num, int fade, const vec &p, int color, float size, int radius, int gravity, int delay) { @@ -1099,18 +1099,15 @@ void updateparticles() { } else canemit = false; if(!editmode || showparticles) { - int emitted = 0, replayed = 0; addedparticles = 0; loopv(emitters) { particleemitter &pe = emitters[i]; extentity &e = *pe.ent; if(e.o.dist(camera1->o) > maxparticledistance) { pe.lastemit = lastmillis; continue; } makeparticles(e); - emitted++; if(replayparticles && pe.maxfade > 5 && pe.lastcull > pe.lastemit) { for(emitoffset = max(pe.lastemit + emitmillis - lastmillis, -pe.maxfade); emitoffset < 0; emitoffset += emitmillis) { makeparticles(e); - replayed++; } emitoffset = 0; } diff --git a/src/engine/renderva.cpp b/src/engine/renderva.cpp index be57ab3..16ad334 100644 --- a/src/engine/renderva.cpp +++ b/src/engine/renderva.cpp @@ -30,11 +30,6 @@ int isvisiblesphere(float rad, const vec &cv) { return v; } -static inline int ishiddencube(const ivec &o, int size) { - loopi(5) if(o.dist(vfcP[i]) < -vfcDfar[i]*size) return true; - return false; -} - int isvisiblecube(const ivec &o, int size) { int v = VFC_FULL_VISIBLE; float dist; @@ -477,41 +472,6 @@ void renderoutline() { gle::disablevertex(); } -void rendershadowmapreceivers() { - SETSHADER(shadowmapreceiver); - gle::enablevertex(); - glCullFace(GL_FRONT); - glDepthMask(GL_FALSE); - glDepthFunc(GL_GREATER); - extern int ati_minmax_bug; - if(!ati_minmax_bug) glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE); - glEnable(GL_BLEND); - glBlendEquation_(GL_MAX); - glBlendFunc(GL_ONE, GL_ONE); - vtxarray *prev = NULL; - for(vtxarray *va = visibleva; va; va = va->next) { - if(!va->texs || !isshadowmapreceiver(va)) continue; - if(!prev || va->vbuf != prev->vbuf) { - gle::bindvbo(va->vbuf); - gle::bindebo(va->ebuf); - const vertex *ptr = 0; - gle::vertexpointer(sizeof(vertex), ptr->pos.v); - } - drawvatris(va, 3*va->tris, va->edata); - xtravertsva += va->verts; - prev = va; - } - glDisable(GL_BLEND); - glBlendEquation_(GL_FUNC_ADD); - glCullFace(GL_BACK); - glDepthMask(GL_TRUE); - glDepthFunc(GL_LESS); - if(!ati_minmax_bug) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - gle::clearvbo(); - gle::clearebo(); - gle::disablevertex(); -} - VAR(oqdist, 0, 256, 1024); VAR(zpass, 0, 1, 1); VAR(envpass, 0, 1, 1); @@ -528,7 +488,8 @@ struct renderstate { VSlot *vslot, *texgenvslot; vec2 texgenscroll; int texgendim; - renderstate() : colormask(true), depthmask(true), blending(false), alphaing(0), vbuf(0), vattribs(false), vquery(false), colorscale(1, 1, 1), alphascale(0), slot(NULL), texgenslot(NULL), vslot(NULL), texgenvslot(NULL), texgenscroll(0, 0), texgendim(-1) { + renderstate() : colormask(true), depthmask(true), blending(false), alphaing(0), vbuf(0), vattribs(false), vquery(false), colorscale(1, 1, 1), alphascale(0), + slot(NULL), texgenslot(NULL), vslot(NULL), texgenvslot(NULL), texgenscroll(0, 0), texgendim(-1) { loopk(8) textures[k] = 0; } }; @@ -779,33 +740,19 @@ static void changetexgen(renderstate &cur, int dim, Slot &slot, VSlot &vslot) { } static void renderbatch(geombatch &b) { - geombatch *shadowed = NULL; int rendered = -1; for(geombatch *curbatch = &b;; curbatch = &geombatches[curbatch->batch]) { - ushort len = curbatch->es.length[curbatch->va->shadowed ? 0 : 1]; + ushort len = curbatch->es.length[1]; if(len) { if(rendered < 0) { rendered = 0; gbatches++; } ushort minvert = curbatch->es.minvert[0], maxvert = curbatch->es.maxvert[0]; - if(!curbatch->va->shadowed) { minvert = min(minvert, curbatch->es.minvert[1]); maxvert = max(maxvert, curbatch->es.maxvert[1]); } + minvert = min(minvert, curbatch->es.minvert[1]); maxvert = max(maxvert, curbatch->es.maxvert[1]); drawtris(len, curbatch->edata, minvert, maxvert); vtris += len/3; } - if(curbatch->es.length[1] > len && !shadowed) shadowed = curbatch; - if(curbatch->batch < 0) break; - } - if(shadowed) for(geombatch *curbatch = shadowed;; curbatch = &geombatches[curbatch->batch]) { - if(curbatch->va->shadowed && curbatch->es.length[1] > curbatch->es.length[0]) { - if(rendered < 1) { - rendered = 1; - gbatches++; - } - ushort len = curbatch->es.length[1] - curbatch->es.length[0]; - drawtris(len, curbatch->edata + curbatch->es.length[0], curbatch->es.minvert[1], curbatch->es.maxvert[1]); - vtris += len/3; - } if(curbatch->batch < 0) break; } } @@ -854,10 +801,9 @@ void renderzpass(renderstate &cur, vtxarray *va) { if(cur.vbuf!=va->vbuf) changevbuf(cur, RENDERPASS_Z, va); if(!cur.depthmask) { cur.depthmask = true; glDepthMask(GL_TRUE); } if(cur.colormask) { cur.colormask = false; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); } - int firsttex = 0, numtris = va->tris; + int numtris = va->tris; ushort *edata = va->edata; if(cur.alphaing) { - firsttex += va->texs + va->blends; edata += 3*(va->tris + va->blendtris); numtris = va->alphatris; xtravertsva += 3*numtris; @@ -891,10 +837,6 @@ void renderva(renderstate &cur, vtxarray *va, int pass = RENDERPASS_LIGHTMAP, bo switch(pass) { case RENDERPASS_LIGHTMAP: if(!cur.alphaing) vverts += va->verts; - va->shadowed = false; - if(!drawtex && !cur.alphaing) { - va->shadowed = isshadowmapreceiver(va); - } if(doquery) startvaquery(va, { if(geombatches.length()) renderbatches(cur, pass); }); mergetexs(cur, va); if(doquery) endvaquery(va, { if(geombatches.length()) renderbatches(cur, pass); }); @@ -939,17 +881,14 @@ VAR(oqgeom, 0, 1, 1); void rendergeom(void) { bool mainpass = !drawtex, doOQ = oqfrags && oqgeom && mainpass, - doZP = doOQ && zpass, - doSM = shadowmap && !drawtex; + doZP = doOQ && zpass; renderstate cur; if(mainpass) { flipqueries(); vtris = vverts = 0; } if(!doZP) { - if(shadowmap && mainpass) rendershadowmap(); setupgeom(); - if(doSM) pushshadowmap(); } resetbatches(); int blends = 0; @@ -974,8 +913,7 @@ void rendergeom(void) { } continue; } - } - else { + } else { va->query = NULL; va->occluded = OCCLUDE_NOTHING; } @@ -991,9 +929,7 @@ void rendergeom(void) { bool multipassing = false; if(doZP) { glFlush(); - if(shadowmap && mainpass) rendershadowmap(); setupgeom(); - if(doSM) pushshadowmap(); if(!multipassing) { multipassing = true; glDepthFunc(GL_LEQUAL); } cur.texgendim = -1; for(vtxarray *va = visibleva; va; va = va->next) { diff --git a/src/engine/shader.cpp b/src/engine/shader.cpp index eb10720..6d88f9f 100644 --- a/src/engine/shader.cpp +++ b/src/engine/shader.cpp @@ -302,7 +302,6 @@ void Shader::allocparams(Slot *slot) { tmu++; } else UNIFORMTEX("lightmap", 1); - UNIFORMTEX("shadowmap", 7); int stex = 0; loopv(slot->sts) { Slot::Tex &t = slot->sts[i]; @@ -622,56 +621,6 @@ static void gengenericvariant(Shader &s, const char *sname, const char *vs, cons newshader(s.type, varname, vschanged ? vsv.getbuf() : reuse, pschanged ? psv.getbuf() : reuse, &s, row); } -static void genshadowmapvariant(Shader &s, const char *sname, const char *vs, const char *ps, int row = 1) { - const char *vspragma = strstr(vs, "//:shadowmap"), *pspragma = strstr(ps, "//:shadowmap"); - if(!vspragma || !pspragma) return; - string pslight; - vspragma += strcspn(vspragma, "\n"); - if(*vspragma) vspragma++; - if(sscanf(pspragma, "//:shadowmap %100s", pslight)!=1) return; - pspragma += strcspn(pspragma, "\n"); - if(*pspragma) pspragma++; - const char *vsmain = findglslmain(vs), *psmain = findglslmain(ps); - if(vsmain > vspragma) vsmain = vs; - if(psmain > pspragma) psmain = ps; - vector vssm, pssm; - if(vsmain >= vs) vssm.put(vs, vsmain - vs); - if(psmain >= ps) pssm.put(ps, psmain - ps); - const char *vsdecl = - "uniform mat4 shadowmapproject;\n" - "varying vec3 shadowmaptc;\n"; - vssm.put(vsdecl, strlen(vsdecl)); - const char *psdecl = - "uniform sampler2D shadowmap;\n" - "uniform vec4 shadowmapambient;\n" - "varying vec3 shadowmaptc;\n"; - pssm.put(psdecl, strlen(psdecl)); - vssm.put(vsmain, vspragma-vsmain); - pssm.put(psmain, pspragma-psmain); - extern int smoothshadowmappeel; - const char *tcgen = - "shadowmaptc = vec3(shadowmapproject * vvertex);\n"; - vssm.put(tcgen, strlen(tcgen)); - const char *sm = - smoothshadowmappeel ? - "vec4 smvals = texture2D(shadowmap, shadowmaptc.xy);\n" - "vec2 smdiff = clamp(smvals.xz - shadowmaptc.zz*smvals.y, 0.0, 1.0);\n" - "float shadowed = clamp((smdiff.x > 0.0 ? smvals.w : 0.0) - 8.0*smdiff.y, 0.0, 1.0);\n" : - "vec4 smvals = texture2D(shadowmap, shadowmaptc.xy);\n" - "float smtest = shadowmaptc.z*smvals.y;\n" - "float shadowed = smtest < smvals.x && smtest > smvals.z ? smvals.w : 0.0;\n"; - pssm.put(sm, strlen(sm)); - defformatstring(smlight, - "%s.rgb -= shadowed*clamp(%s.rgb - shadowmapambient.rgb, 0.0, 1.0);\n", - pslight, pslight); - pssm.put(smlight, strlen(smlight)); - vssm.put(vspragma, strlen(vspragma)+1); - pssm.put(pspragma, strlen(pspragma)+1); - defformatstring(name, "%s", sname); - Shader *variant = newshader(s.type, name, vssm.getbuf(), pssm.getbuf(), &s, row); - if(!variant) return; -} - static void genuniformdefs(vector &vsbuf, vector &psbuf, const char *vs, const char *ps, Shader *variant = NULL) { if(variant ? variant->defaultparams.empty() : slotparams.empty()) return; const char *vsmain = findglslmain(vs), *psmain = findglslmain(ps); @@ -785,9 +734,6 @@ void shader(int *type, char *name, char *vs, char *ps) { } GENSHADER(slotparams.length(), genuniformdefs(vsbuf, psbuf, vs, ps)); Shader *s = newshader(*type, name, vs, ps); - if(s) { - if(strstr(vs, "//:shadowmap")) genshadowmapvariant(*s, s->name, vs, ps); - } slotparams.shrink(0); } diff --git a/src/engine/shadowmap.cpp b/src/engine/shadowmap.cpp deleted file mode 100644 index e86f65f..0000000 --- a/src/engine/shadowmap.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "engine.h" -#include "rendertarget.h" - -VARP(shadowmap, 0, 0, 1); - -extern void cleanshadowmap(); -VARFP(shadowmapsize, 7, 9, 11, cleanshadowmap()); -VARP(shadowmapradius, 64, 96, 256); -VAR(shadowmapheight, 0, 32, 128); -VARP(shadowmapdist, 128, 256, 512); -VARFP(fpshadowmap, 0, 0, 1, cleanshadowmap()); -VARFP(shadowmapprecision, 0, 0, 1, cleanshadowmap()); -bvec shadowmapambientcolor(0, 0, 0); -HVARFR(shadowmapambient, 0, 0, 0xFFFFFF, { - if(shadowmapambient <= 255) shadowmapambient |= (shadowmapambient<<8) | (shadowmapambient<<16); - shadowmapambientcolor = bvec((shadowmapambient>>16)&0xFF, (shadowmapambient>>8)&0xFF, shadowmapambient&0xFF); -}); -VARP(shadowmapintensity, 0, 40, 100); - -VARP(blurshadowmap, 0, 1, 3); -VARP(blursmsigma, 1, 100, 200); - -#define SHADOWSKEW 0.7071068f - -vec shadowoffset(0, 0, 0), shadowfocus(0, 0, 0), shadowdir(0, SHADOWSKEW, 1); -VAR(shadowmapcasters, 1, 0, 0); -float shadowmapmaxz = 0; - -void setshadowdir(int angle) { - shadowdir = vec(0, SHADOWSKEW, 1); - shadowdir.rotate_around_z(angle*RAD); -} - -VARFR(shadowmapangle, 0, 0, 360, setshadowdir(shadowmapangle)); - -void guessshadowdir() { - if(shadowmapangle) return; - vec dir; { - vec lightpos(0, 0, 0), casterpos(0, 0, 0); - int numlights = 0, numcasters = 0; - const vector &ents = entities::getents(); - loopv(ents) { - extentity &e = *ents[i]; - switch(e.type) { - case ET_LIGHT: - if(!e.attr1) { lightpos.add(e.o); numlights++; } - break; - case ET_MAPMODEL: - casterpos.add(e.o); - numcasters++; - break; - default: - if(e.typeyaw*RAD); - vec dir; - vecfromyawpitch(camera1->yaw, camera1->pitch, 1, 0, dir); - dir.z = 0; - dir.mul(shadowmapradius); - vec dirx, diry; - vecfromyawpitch(camera1->yaw, 0, 0, 1, dirx); - vecfromyawpitch(camera1->yaw, 0, 1, 0, diry); - shadowoffset.x = -fmod(dirx.dot(camera1->o) - skewdir.x*camera1->o.z, 2.0f*shadowmapradius/vieww); - shadowoffset.y = -fmod(diry.dot(camera1->o) - skewdir.y*camera1->o.z, 2.0f*shadowmapradius/viewh); - shadowmatrix.ortho(-shadowmapradius, shadowmapradius, -shadowmapradius, shadowmapradius, -shadowmapdist, shadowmapdist); - shadowmatrix.mul(matrix3(vec(1, 0, 0), vec(0, 1, 0), vec(skewdir.x, skewdir.y, 1))); - shadowmatrix.translate(skewdir.x*shadowmapheight + shadowoffset.x, skewdir.y*shadowmapheight + shadowoffset.y + dir.magnitude(), -shadowmapheight); - shadowmatrix.rotate_around_z((camera1->yaw+180)*-RAD); - shadowmatrix.translate(vec(camera1->o).neg()); - GLOBALPARAM(shadowmatrix, shadowmatrix); - shadowfocus = camera1->o; - shadowfocus.add(dir); - shadowfocus.add(vec(shadowdir).mul(shadowmapheight)); - shadowfocus.add(dirx.mul(shadowoffset.x)); - shadowfocus.add(diry.mul(shadowoffset.y)); - gle::colorf(0, 0, 0); - GLOBALPARAMF(shadowmapbias, -shadowmapbias/float(shadowmapdist), 1 - (shadowmapbias + (smoothshadowmappeel ? 0 : shadowmappeelbias))/float(shadowmapdist)); - shadowmapcasters = 0; - shadowmapmaxz = shadowfocus.z - shadowmapdist; - shadowmapping = true; - rendergame(); - shadowmapping = false; - shadowmapmaxz = min(shadowmapmaxz, shadowfocus.z); - if(shadowmapcasters && smdepthpeel) { - int sx, sy, sw, sh; - bool scissoring = rtscissor && scissorblur(sx, sy, sw, sh) && sw > 0 && sh > 0; - if(scissoring) glScissor(sx, sy, sw, sh); - if(!rtscissor || scissoring) rendershadowmapreceivers(); - } - return shadowmapcasters>0; - } -} shadowmaptex; - -void cleanshadowmap() { - shadowmaptex.cleanup(true); -} - -void calcshadowmapbb(const vec &o, float xyrad, float zrad, float &x1, float &y1, float &x2, float &y2) { - vec skewdir(shadowdir); - skewdir.rotate_around_z(-camera1->yaw*RAD); - vec ro(o); - ro.sub(camera1->o); - ro.rotate_around_z(-(camera1->yaw+180)*RAD); - ro.x += ro.z * skewdir.x + shadowoffset.x; - ro.y += ro.z * skewdir.y + shadowmapradius * cosf(camera1->pitch*RAD) + shadowoffset.y; - vec high(ro), low(ro); - high.x += zrad * skewdir.x; - high.y += zrad * skewdir.y; - low.x -= zrad * skewdir.x; - low.y -= zrad * skewdir.y; - x1 = (min(high.x, low.x) - xyrad) / shadowmapradius; - y1 = (min(high.y, low.y) - xyrad) / shadowmapradius; - x2 = (max(high.x, low.x) + xyrad) / shadowmapradius; - y2 = (max(high.y, low.y) + xyrad) / shadowmapradius; -} - -bool addshadowmapcaster(const vec &o, float xyrad, float zrad) { - if(o.z + zrad <= shadowfocus.z - shadowmapdist || o.z - zrad >= shadowfocus.z) return false; - shadowmapmaxz = max(shadowmapmaxz, o.z + zrad); - float x1, y1, x2, y2; - calcshadowmapbb(o, xyrad, zrad, x1, y1, x2, y2); - if(!shadowmaptex.addblurtiles(x1, y1, x2, y2, 2)) return false; - shadowmapcasters++; - return true; -} - -bool isshadowmapreceiver(vtxarray *va) { - if(!shadowmap || !shadowmapcasters) return false; - if(va->shadowmapmax.z <= shadowfocus.z - shadowmapdist || va->shadowmapmin.z >= shadowmapmaxz) return false; - float xyrad = SQRT2*0.5f*max(va->shadowmapmax.x-va->shadowmapmin.x, va->shadowmapmax.y-va->shadowmapmin.y), - zrad = 0.5f*(va->shadowmapmax.z-va->shadowmapmin.z), - x1, y1, x2, y2; - if(xyrad<0 || zrad<0) return false; - vec center = vec(va->shadowmapmin).add(vec(va->shadowmapmax)).mul(0.5f); - calcshadowmapbb(center, xyrad, zrad, x1, y1, x2, y2); - return shadowmaptex.checkblurtiles(x1, y1, x2, y2, 2); -} - -bool isshadowmapcaster(const vec &o, float rad) { - // cheaper inexact test - float dz = o.z - shadowfocus.z; - float cx = shadowfocus.x + dz*shadowdir.x, cy = shadowfocus.y + dz*shadowdir.y; - float skew = rad*SHADOWSKEW; - if(!shadowmapping || - o.z + rad <= shadowfocus.z - shadowmapdist || o.z - rad >= shadowfocus.z || - o.x + rad <= cx - shadowmapradius-skew || o.x - rad >= cx + shadowmapradius+skew || - o.y + rad <= cy - shadowmapradius-skew || o.y - rad >= cy + shadowmapradius+skew) - return false; - return true; -} - -void pushshadowmap() { - if(!shadowmap || !shadowmaptex.rendertex) return; - glActiveTexture_(GL_TEXTURE7); - glBindTexture(GL_TEXTURE_2D, shadowmaptex.rendertex); - matrix4 m = shadowmatrix; - m.projective(-1, 1-shadowmapbias/float(shadowmapdist)); - GLOBALPARAM(shadowmapproject, m); - glActiveTexture_(GL_TEXTURE0); - float r, g, b; - if(!shadowmapambient) { - r = max(25.0f, 2.0f*ambientcolor[0]); - g = max(25.0f, 2.0f*ambientcolor[1]); - b = max(25.0f, 2.0f*ambientcolor[2]); - } - else { r = shadowmapambientcolor[0]; g = shadowmapambientcolor[1]; b = shadowmapambientcolor[2]; } - GLOBALPARAMF(shadowmapambient, r/255.0f, g/255.0f, b/255.0f); -} - -void rendershadowmap() { - if(!shadowmap) return; - shadowmaptex.render(1<= ragdoll->lastmove); + return pitch==c.pitch && partmask==c.partmask; } }; struct vbocacheentry : animcacheentry { @@ -160,14 +156,6 @@ struct skelmodel : animmodel { } } } - void genBIH(BIH::mesh &m) { - m.tris = (const BIH::tri *)tris; - m.numtris = numtris; - m.pos = (const uchar *)&verts->pos; - m.posstride = sizeof(vert); - m.tc = (const uchar *)&verts->tc; - m.tcstride = sizeof(vert); - } static inline void assignvert(vvertn &vv, int j, vert &v, blendcombo &c) { (void)j;(void)c; vv.pos = v.pos; @@ -312,10 +300,10 @@ struct skelmodel : animmodel { }; struct boneinfo { const char *name; - int parent, children, next, group, scheduled, interpindex, interpparent, ragdollindex, correctindex; + int parent, children, next, group, scheduled, interpindex, interpparent, correctindex; float pitchscale, pitchoffset, pitchmin, pitchmax; dualquat base, invbase; - boneinfo() : name(NULL), parent(-1), children(-1), next(-1), group(INT_MAX), scheduled(-1), interpindex(-1), interpparent(-1), ragdollindex(-1), correctindex(-1), pitchscale(0), pitchoffset(0), pitchmin(0), pitchmax(0) {} + boneinfo() : name(NULL), parent(-1), children(-1), next(-1), group(INT_MAX), scheduled(-1), interpindex(-1), interpparent(-1), correctindex(-1), pitchscale(0), pitchoffset(0), pitchmin(0), pitchmax(0) {} ~boneinfo() { DELETEA(name); } @@ -348,20 +336,18 @@ struct skelmodel : animmodel { vector skelanims; vector tags; vector antipodes; - ragdollskel *ragdoll; vector pitchdeps; vector pitchtargets; vector pitchcorrects; bool usegpuskel; vector skelcache; hashtable blendoffsets; - skeleton() : name(NULL), shared(0), bones(NULL), numbones(0), numinterpbones(0), numgpubones(0), numframes(0), framebones(NULL), ragdoll(NULL), usegpuskel(false), blendoffsets(32) { + skeleton() : name(NULL), shared(0), bones(NULL), numbones(0), numinterpbones(0), numgpubones(0), numframes(0), framebones(NULL), usegpuskel(false), blendoffsets(32) { } ~skeleton() { DELETEA(name); DELETEA(bones); DELETEA(framebones); - DELETEP(ragdoll); loopv(skelcache) { DELETEA(skelcache[i].bdata); } @@ -440,7 +426,6 @@ struct skelmodel : animmodel { loopi(numbones) { boneinfo &info = bones[i]; info.interpindex = -1; - info.ragdollindex = -1; } numgpubones = 0; loopv(users) { @@ -471,13 +456,6 @@ struct skelmodel : animmodel { boneinfo &info = bones[tags[i].bone]; if(info.interpindex < 0) info.interpindex = numinterpbones++; } - if(ragdoll) { - loopv(ragdoll->joints) { - boneinfo &info = bones[ragdoll->joints[i].bone]; - if(info.interpindex < 0) info.interpindex = numinterpbones++; - info.ragdollindex = i; - } - } loopi(numbones) { boneinfo &info = bones[i]; if(info.interpindex < 0) continue; @@ -489,15 +467,6 @@ struct skelmodel : animmodel { if(info.interpindex < 0) continue; info.interpparent = info.parent >= 0 ? bones[info.parent].interpindex : -1; } - if(ragdoll) { - loopi(numbones) { - boneinfo &info = bones[i]; - if(info.interpindex < 0 || info.ragdollindex >= 0) continue; - for(int parent = info.parent; parent >= 0; parent = bones[parent].parent) { - if(bones[parent].ragdollindex >= 0) { ragdoll->addreljoint(i, bones[parent].ragdollindex); break; } - } - } - } calcantipodes(); } @@ -572,7 +541,6 @@ struct skelmodel : animmodel { } void optimize() { cleanup(); - if(ragdoll) ragdoll->setup(); remapbones(); initpitchdeps(); } @@ -694,56 +662,6 @@ struct skelmodel : animmodel { } loopv(antipodes) sc.bdata[antipodes[i].child].fixantipodal(sc.bdata[antipodes[i].parent]); } - void initragdoll(ragdolldata &d, skelcacheentry &sc, part *p) { - const dualquat *bdata = sc.bdata; - loopv(ragdoll->joints) { - const ragdollskel::joint &j = ragdoll->joints[i]; - const boneinfo &b = bones[j.bone]; - const dualquat &q = bdata[b.interpindex]; - loopk(3) if(j.vert[k] >= 0) { - ragdollskel::vert &v = ragdoll->verts[j.vert[k]]; - ragdolldata::vert &dv = d.verts[j.vert[k]]; - dv.pos.add(q.transform(v.pos).mul(v.weight)); - } - } - if(ragdoll->animjoints) loopv(ragdoll->joints) { - const ragdollskel::joint &j = ragdoll->joints[i]; - const boneinfo &b = bones[j.bone]; - const dualquat &q = bdata[b.interpindex]; - d.calcanimjoint(i, matrix4x3(q)); - } - loopv(ragdoll->verts) { - ragdolldata::vert &dv = d.verts[i]; - matrixstack[matrixpos].transform(vec(dv.pos).add(p->translate).mul(p->model->scale), dv.pos); - } - loopv(ragdoll->reljoints) { - const ragdollskel::reljoint &r = ragdoll->reljoints[i]; - const ragdollskel::joint &j = ragdoll->joints[r.parent]; - const boneinfo &br = bones[r.bone], &bj = bones[j.bone]; - d.reljoints[i].mul(dualquat(bdata[bj.interpindex]).invert(), bdata[br.interpindex]); - } - } - void genragdollbones(ragdolldata &d, skelcacheentry &sc, part *p) { - if(!sc.bdata) sc.bdata = new dualquat[numinterpbones]; - sc.nextversion(); - loopv(ragdoll->joints) { - const ragdollskel::joint &j = ragdoll->joints[i]; - const boneinfo &b = bones[j.bone]; - vec pos(0, 0, 0); - loopk(3) if(j.vert[k]>=0) pos.add(d.verts[j.vert[k]].pos); - pos.mul(j.weight/p->model->scale).sub(p->translate); - matrix4x3 m; - m.mul(d.tris[j.tri], pos, d.animjoints ? d.animjoints[i] : j.orient); - sc.bdata[b.interpindex] = dualquat(m); - } - loopv(ragdoll->reljoints) { - const ragdollskel::reljoint &r = ragdoll->reljoints[i]; - const ragdollskel::joint &j = ragdoll->joints[r.parent]; - const boneinfo &br = bones[r.bone], &bj = bones[j.bone]; - sc.bdata[br.interpindex].mul(sc.bdata[bj.interpindex], d.reljoints[i]); - } - loopv(antipodes) sc.bdata[antipodes[i].child].fixantipodal(sc.bdata[antipodes[i].parent]); - } void concattagtransform(part *p, int i, const matrix4x3 &m, matrix4x3 &n) { (void)i;(void)m;(void)n;(void)p; matrix4x3 t; @@ -781,7 +699,8 @@ struct skelmodel : animmodel { usegpuskel = gpuaccelerate(); } } - skelcacheentry &checkskelcache(part *p, const animstate *as, float pitch, const vec &axis, const vec &forward, ragdolldata *rdata) { + skelcacheentry &checkskelcache(part *p, const animstate *as, float pitch, const vec &axis, const vec &forward) { + (void) p; if(skelcache.empty()) { usegpuskel = gpuaccelerate(); } @@ -792,7 +711,7 @@ struct skelmodel : animmodel { loopv(skelcache) { skelcacheentry &c = skelcache[i]; loopj(numanimparts) if(c.as[j]!=as[j]) goto mismatch; - if(c.pitch != pitch || c.partmask != partmask || c.ragdoll != rdata || (rdata && c.millis < rdata->lastmove)) goto mismatch; + if(c.pitch != pitch || c.partmask != partmask) goto mismatch; match = true; sc = &c; break; @@ -804,9 +723,7 @@ struct skelmodel : animmodel { loopi(numanimparts) sc->as[i] = as[i]; sc->pitch = pitch; sc->partmask = partmask; - sc->ragdoll = rdata; - if(rdata) genragdollbones(*rdata, *sc, p); - else interpbones(as, pitch, axis, forward, numanimparts, partmask, *sc); + interpbones(as, pitch, axis, forward, numanimparts, partmask, *sc); } sc->millis = lastmillis; return *sc; @@ -1117,7 +1034,7 @@ struct skelmodel : animmodel { skel->calctags(p); return; } - skelcacheentry &sc = skel->checkskelcache(p, as, pitch, axis, forward, as->cur.anim&ANIM_RAGDOLL || !d || !d->ragdoll || d->ragdoll->skel != skel->ragdoll ? NULL : d->ragdoll); + skelcacheentry &sc = skel->checkskelcache(p, as, pitch, axis, forward); if(!(as->cur.anim&ANIM_NORENDER)) { int owner = &sc-&skel->skelcache[0]; vbocacheentry &vc = skel->usegpuskel ? *vbocache : checkvbocache(sc, owner); @@ -1152,11 +1069,6 @@ struct skelmodel : animmodel { } } skel->calctags(p, &sc); - if(as->cur.anim&ANIM_RAGDOLL && skel->ragdoll && !d->ragdoll) { - d->ragdoll = new ragdolldata(skel->ragdoll, p->model->scale); - skel->initragdoll(*d->ragdoll, sc, p); - d->ragdoll->init(d); - } } }; struct animpartmask { @@ -1429,4 +1341,3 @@ template struct skelcommands : modelcommands &key, Slot::Tex &t, bool combined = false, cons static void texcombine(Slot &s, int index, Slot::Tex &t, bool forceload = false) { vector key; addname(key, t); - int texmask = 0; if(!forceload) switch(t.type) { case TEX_DIFFUSE: case TEX_NORMAL: { int i = findtextype(s, t.type==TEX_DIFFUSE ? (s.texmask&(1<uval[3] = w; } template - T *reserve(int n = 1) { return (T *)resolve()->buf; } + T *reserve(int n = 1) { (void)n;return (T *)resolve()->buf; } }; struct LocalShaderParam { diff --git a/src/engine/world.cpp b/src/engine/world.cpp index d2941d0..a410c69 100644 --- a/src/engine/world.cpp +++ b/src/engine/world.cpp @@ -323,7 +323,6 @@ void entselectionbox(const entity &e, vec &eo, vec &es) { } VAR(entselsnap, 0, 0, 1); -VAR(entmovingshadow, 0, 1, 1); extern void boxs(int orient, vec o, const vec &s, float size); extern void boxs(int orient, vec o, const vec &s); @@ -475,7 +474,7 @@ void renderentselection(bool entmoving) { gle::colorub(0, 40, 0); entfocus(enthover, entselectionbox(e, eo, es)); // also ensures enthover is back in focus boxs3D(eo, es, 1); - if(entmoving && entmovingshadow==1) { + if(entmoving) { vec a, b; gle::colorub(20, 20, 20); (a = eo).x = eo.x - fmod(eo.x, worldsize); (b = es).x = a.x + worldsize; boxs3D(a, b, 1); diff --git a/src/fpsgame/ai.cpp b/src/fpsgame/ai.cpp index b59dbd3..5c74fe4 100644 --- a/src/fpsgame/ai.cpp +++ b/src/fpsgame/ai.cpp @@ -10,7 +10,6 @@ namespace ai { ICOMMAND(addbot, "s", (char *s), addmsg(N_ADDBOT, "ri", *s ? clamp(parseint(s), 1, 101) : -1)); ICOMMAND(delbot, "", (), addmsg(N_DELBOT, "r")); ICOMMAND(botlimit, "i", (int *n), addmsg(N_BOTLIMIT, "ri", *n)); - ICOMMAND(botbalance, "i", (int *n), addmsg(N_BOTBALANCE, "ri", *n)); float viewdist(int x) { return x <= 100 ? clamp((SIGHTMIN+(SIGHTMAX-SIGHTMIN))/100.f*float(x), float(SIGHTMIN), 10000.0f) : 10000.0f; } @@ -904,16 +903,13 @@ namespace ai { shoot(d, d->ai->target); } if(!intermission) { - if(d->ragdoll) cleanragdoll(d); moveplayer(d, 10, true); if(allowmove && !b.idle) timeouts(d); if(d->quadmillis) entities::checkquad(curtime, d); entities::checkitems(d); } - } - else if(d->state == CS_DEAD) { - if(d->ragdoll) moveragdoll(d); - else if(lastmillis-d->lastpain<2000) { + } else if(d->state == CS_DEAD) { + if(lastmillis-d->lastpain<2000) { d->move = d->strafe = 0; moveplayer(d, 10, false); } @@ -1074,4 +1070,3 @@ namespace ai { } } } - diff --git a/src/fpsgame/ai.h b/src/fpsgame/ai.h index 81b1e26..4328963 100644 --- a/src/fpsgame/ai.h +++ b/src/fpsgame/ai.h @@ -234,4 +234,3 @@ namespace ai { extern void itemspawned(int ent); extern void render(); } - diff --git a/src/fpsgame/aiman.h b/src/fpsgame/aiman.h deleted file mode 100644 index f926d44..0000000 --- a/src/fpsgame/aiman.h +++ /dev/null @@ -1,212 +0,0 @@ -// server-side ai manager -namespace aiman { - bool dorefresh = false, botbalance = true; - VARN(serverbotlimit, botlimit, 0, 8, MAXBOTS); - VAR(serverbotbalance, 0, 1, 1); - void calcteams(vector &teams) { - static const char * const defaults[2] = { "good", "evil" }; - loopv(clients) { - clientinfo *ci = clients[i]; - if(ci->state.state==CS_SPECTATOR || !ci->team[0]) continue; - teamscore *t = NULL; - loopvj(teams) if(!strcmp(teams[j].team, ci->team)) { t = &teams[j]; break; } - if(t) t->score++; - else teams.add(teamscore(ci->team, 1)); - } - teams.sort(teamscore::compare); - if(teams.length() < int(sizeof(defaults)/sizeof(defaults[0]))) { - loopi(sizeof(defaults)/sizeof(defaults[0])) if(teams.htfind(defaults[i]) < 0) teams.add(teamscore(defaults[i], 0)); - } - } - void balanceteams() { - vector teams; - calcteams(teams); - vector reassign; - loopv(bots) if(bots[i]) reassign.add(bots[i]); - while(reassign.length() && teams.length() && teams[0].score > teams.last().score + 1) { - teamscore &t = teams.last(); - clientinfo *bot = NULL; - loopv(reassign) if(reassign[i] && !strcmp(reassign[i]->team, teams[0].team)) { - bot = reassign.removeunordered(i); - teams[0].score--; - t.score++; - for(int j = teams.length() - 2; j >= 0; j--) { - if(teams[j].score >= teams[j+1].score) break; - swap(teams[j], teams[j+1]); - } - break; - } - if(bot) { - copystring(bot->team, t.team, MAXTEAMLEN+1); - sendf(-1, 1, "riisi", N_SETTEAM, bot->clientnum, bot->team, 0); - } - else teams.remove(0, 1); - } - } - const char *chooseteam() { - vector teams; - calcteams(teams); - return teams.length() ? teams.last().team : ""; - } - static inline bool validaiclient(clientinfo *ci) { - return ci->clientnum >= 0 && ci->state.aitype == AI_NONE && (ci->state.state!=CS_SPECTATOR || ci->local || (ci->privilege && !ci->warned)); - } - clientinfo *findaiclient(clientinfo *exclude = NULL) { - clientinfo *least = NULL; - loopv(clients) { - clientinfo *ci = clients[i]; - if(!validaiclient(ci) || ci==exclude) continue; - if(!least || ci->bots.length() < least->bots.length()) least = ci; - } - return least; - } - bool addai(int skill, int limit) { - int numai = 0, cn = -1, maxai = limit >= 0 ? min(limit, MAXBOTS) : MAXBOTS; - loopv(bots) { - clientinfo *ci = bots[i]; - if(!ci || ci->ownernum < 0) { if(cn < 0) cn = i; continue; } - numai++; - } - if(numai >= maxai) return false; - if(bots.inrange(cn)) { - clientinfo *ci = bots[cn]; - if(ci) { - // reuse a slot that was going to removed - clientinfo *owner = findaiclient(); - ci->ownernum = owner ? owner->clientnum : -1; - if(owner) owner->bots.add(ci); - ci->aireinit = 2; - dorefresh = true; - return true; - } - } - else { cn = bots.length(); bots.add(NULL); } - const char *team = m_teammode ? chooseteam() : ""; - if(!bots[cn]) bots[cn] = new clientinfo; - clientinfo *ci = bots[cn]; - ci->clientnum = MAXCLIENTS + cn; - ci->state.aitype = AI_BOT; - clientinfo *owner = findaiclient(); - ci->ownernum = owner ? owner->clientnum : -1; - if(owner) owner->bots.add(ci); - ci->state.skill = skill <= 0 ? rnd(50) + 51 : clamp(skill, 1, 101); - clients.add(ci); - ci->state.lasttimeplayed = lastmillis; - copystring(ci->name, "bot", MAXNAMELEN+1); - ci->state.state = CS_DEAD; - copystring(ci->team, team, MAXTEAMLEN+1); - ci->playermodel = 0; - ci->aireinit = 2; - ci->connected = true; - dorefresh = true; - return true; - } - void deleteai(clientinfo *ci) { - int cn = ci->clientnum - MAXCLIENTS; - if(!bots.inrange(cn)) return; - sendf(-1, 1, "ri2", N_CDIS, ci->clientnum); - clientinfo *owner = (clientinfo *)getclientinfo(ci->ownernum); - if(owner) owner->bots.removeobj(ci); - clients.removeobj(ci); - DELETEP(bots[cn]); - dorefresh = true; - } - bool deleteai() { - loopvrev(bots) if(bots[i] && bots[i]->ownernum >= 0) { - deleteai(bots[i]); - return true; - } - return false; - } - void reinitai(clientinfo *ci) { - if(ci->ownernum < 0) deleteai(ci); - else if(ci->aireinit >= 1) { - sendf(-1, 1, "ri6ss", N_INITAI, ci->clientnum, ci->ownernum, ci->state.aitype, ci->state.skill, ci->playermodel, ci->name, ci->team); - if(ci->aireinit == 2) { - ci->reassign(); - if(ci->state.state==CS_ALIVE) sendspawn(ci); - else sendresume(ci); - } - ci->aireinit = 0; - } - } - void shiftai(clientinfo *ci, clientinfo *owner = NULL) { - clientinfo *prevowner = (clientinfo *)getclientinfo(ci->ownernum); - if(prevowner) prevowner->bots.removeobj(ci); - if(!owner) { ci->aireinit = 0; ci->ownernum = -1; } - else if(ci->ownernum != owner->clientnum) { ci->aireinit = 2; ci->ownernum = owner->clientnum; owner->bots.add(ci); } - dorefresh = true; - } - void removeai(clientinfo *ci) { - // either schedules a removal, or someone else to assign to - loopvrev(ci->bots) shiftai(ci->bots[i], findaiclient(ci)); - } - bool reassignai() { - clientinfo *hi = NULL, *lo = NULL; - loopv(clients) { - clientinfo *ci = clients[i]; - if(!validaiclient(ci)) continue; - if(!lo || ci->bots.length() < lo->bots.length()) lo = ci; - if(!hi || ci->bots.length() > hi->bots.length()) hi = ci; - } - if(hi && lo && hi->bots.length() - lo->bots.length() > 1) { - loopvrev(hi->bots) { - shiftai(hi->bots[i], lo); - return true; - } - } - return false; - } - - void checksetup() { - if(m_teammode && botbalance) balanceteams(); - loopvrev(bots) if(bots[i]) reinitai(bots[i]); - } - void clearai() { - // clear and remove all ai immediately - loopvrev(bots) if(bots[i]) deleteai(bots[i]); - } - void checkai() { - if(!dorefresh) return; - dorefresh = false; - if(m_botmode && numclients(-1, false, true)) { - checksetup(); - while(reassignai()); - } - else clearai(); - } - void reqadd(clientinfo *ci, int skill) { - if(!ci->local && !ci->privilege) return; - if(!addai(skill, !ci->local && ci->privilege < PRIV_ADMIN ? botlimit : -1)) sendf(ci->clientnum, 1, "ris", N_SERVMSG, "failed to create or assign bot"); - } - void reqdel(clientinfo *ci) { - if(!ci->local && !ci->privilege) return; - if(!deleteai()) sendf(ci->clientnum, 1, "ris", N_SERVMSG, "failed to remove any bots"); - } - void setbotlimit(clientinfo *ci, int limit) { - if(ci && !ci->local && ci->privilege < PRIV_ADMIN) return; - botlimit = clamp(limit, 0, MAXBOTS); - dorefresh = true; - defformatstring(msg, "bot limit is now %d", botlimit); - sendservmsg(msg); - } - void setbotbalance(clientinfo *ci, bool balance) { - if(ci && !ci->local && !ci->privilege) return; - botbalance = balance ? 1 : 0; - dorefresh = true; - defformatstring(msg, "bot team balancing is now %s", botbalance ? "enabled" : "disabled"); - sendservmsg(msg); - } - - void changemap() { - dorefresh = true; - loopv(clients) if(clients[i]->local || clients[i]->privilege) return; - if(botbalance != (serverbotbalance != 0)) setbotbalance(NULL, serverbotbalance != 0); - } - void addclient(clientinfo *ci) { - if(ci->state.aitype == AI_NONE) dorefresh = true; - } - void changeteam(clientinfo *ci) { - if(ci->state.aitype == AI_NONE) dorefresh = true; - } -} diff --git a/src/fpsgame/client.cpp b/src/fpsgame/client.cpp index 83aa385..620c262 100644 --- a/src/fpsgame/client.cpp +++ b/src/fpsgame/client.cpp @@ -281,7 +281,6 @@ namespace game { if(i>=0) addmsg(N_SPECTATOR, "rii", i, val); } ICOMMAND(spectator, "is", (int *val, char *who), togglespectator(*val, who)); - ICOMMAND(checkmaps, "", (), addmsg(N_CHECKMAPS, "r")); int gamemode = INT_MAX, nextmode = INT_MAX; string clientmap = ""; void changemapserv(const char *name, int mode) { // forced map change from the server { @@ -1014,10 +1013,7 @@ namespace game { clientdisconnected(getint(p)); break; case N_SPAWN: { - if(d) { - if(d->state==CS_DEAD && d->lastpain) saveragdoll(d); - d->respawn(); - } + if(d) d->respawn(); parsestate(d, p); if(!d) break; d->state = CS_SPAWNING; @@ -1029,7 +1025,6 @@ namespace game { int scn = getint(p); fpsent *s = getclient(scn); if(!s) { parsestate(NULL, p); break; } - if(s->state==CS_DEAD && s->lastpain) saveragdoll(s); if(s==player1) { if(editmode) toggleedit(); stopfollowing(); diff --git a/src/fpsgame/entities.cpp b/src/fpsgame/entities.cpp index 656a9b0..f8c037c 100644 --- a/src/fpsgame/entities.cpp +++ b/src/fpsgame/entities.cpp @@ -93,7 +93,7 @@ namespace entities { if(mdlname) { vec p = e.o; p.z += 1+sinf(lastmillis/100.0+e.o.x+e.o.y)/20; - rendermodel(&e.light, mdlname, ANIM_MAPMODEL|ANIM_LOOP, p, lastmillis/(float)revs, 0, MDL_SHADOW | MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED); + rendermodel(&e.light, mdlname, ANIM_MAPMODEL|ANIM_LOOP, p, lastmillis/(float)revs, 0, MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED); } } } diff --git a/src/fpsgame/extinfo.h b/src/fpsgame/extinfo.h deleted file mode 100644 index b467a8c..0000000 --- a/src/fpsgame/extinfo.h +++ /dev/null @@ -1,112 +0,0 @@ - -#define EXT_ACK -1 -#define EXT_VERSION 105 -#define EXT_NO_ERROR 0 -#define EXT_ERROR 1 -#define EXT_PLAYERSTATS_RESP_IDS -10 -#define EXT_PLAYERSTATS_RESP_STATS -11 -#define EXT_UPTIME 0 -#define EXT_PLAYERSTATS 1 -#define EXT_TEAMSCORE 2 - -/* - Client: - ----- - A: 0 EXT_UPTIME - B: 0 EXT_PLAYERSTATS cn #a client number or -1 for all players# - C: 0 EXT_TEAMSCORE - Server: - -------- - A: 0 EXT_UPTIME EXT_ACK EXT_VERSION uptime #in seconds# - B: 0 EXT_PLAYERSTATS cn #send by client# EXT_ACK EXT_VERSION 0 or 1 #error, if cn was > -1 and client does not exist# ... - EXT_PLAYERSTATS_RESP_IDS pid(s) #1 packet# - EXT_PLAYERSTATS_RESP_STATS pid playerdata #1 packet for each player# - C: 0 EXT_TEAMSCORE EXT_ACK EXT_VERSION 0 or 1 #error, no teammode# remaining_time gamemode loop(teamdata [numbases bases] or -1) - Errors: - -------------- - B:C:default: 0 command EXT_ACK EXT_VERSION EXT_ERROR -*/ - VAR(extinfoip, 0, 0, 1); - void extinfoplayer(ucharbuf &p, clientinfo *ci) { - ucharbuf q = p; - putint(q, EXT_PLAYERSTATS_RESP_STATS); // send player stats following - putint(q, ci->clientnum); //add player id - putint(q, ci->ping); - sendstring(ci->name, q); - sendstring(ci->team, q); - putint(q, ci->state.frags); - putint(q, ci->state.flags); - putint(q, ci->state.deaths); - putint(q, ci->state.teamkills); - putint(q, ci->state.damage*100/max(ci->state.shotdamage,1)); - putint(q, ci->state.health); - putint(q, ci->state.armour); - putint(q, ci->state.gunselect); - putint(q, ci->privilege); - putint(q, ci->state.state); - uint ip = extinfoip ? getclientip(ci->clientnum) : 0; - q.put((uchar*)&ip, 3); - sendserverinforeply(q); - } - static inline void extinfoteamscore(ucharbuf &p, const char *team, int score) { - sendstring(team, p); - putint(p, score); - putint(p,-1); //no bases follow - } - void extinfoteams(ucharbuf &p) { - putint(p, m_teammode ? 0 : 1); - putint(p, gamemode); - putint(p, max((gamelimit - gamemillis)/1000, 0)); - if(!m_teammode) return; - vector scores; - loopv(clients) { - clientinfo *ci = clients[i]; - if(ci->state.state!=CS_SPECTATOR && ci->team[0] && scores.htfind(ci->team) < 0) { - teaminfo *ti = teaminfos.access(ci->team); - scores.add(teamscore(ci->team, ti ? ti->frags : 0)); - } - } - loopv(scores) extinfoteamscore(p, scores[i].team, scores[i].score); - } - void extserverinforeply(ucharbuf &req, ucharbuf &p) { - int extcmd = getint(req); // extended commands - //Build a new packet - putint(p, EXT_ACK); //send ack - putint(p, EXT_VERSION); //send version of extended info - switch(extcmd) { - case EXT_UPTIME: { - putint(p, totalsecs); //in seconds - break; - } - case EXT_PLAYERSTATS: { - int cn = getint(req); //a special player, -1 for all - clientinfo *ci = NULL; - if(cn >= 0) { - loopv(clients) if(clients[i]->clientnum == cn) { ci = clients[i]; break; } - if(!ci) { - putint(p, EXT_ERROR); //client requested by id was not found - sendserverinforeply(p); - return; - } - } - putint(p, EXT_NO_ERROR); //so far no error can happen anymore - ucharbuf q = p; //remember buffer position - putint(q, EXT_PLAYERSTATS_RESP_IDS); //send player ids following - if(ci) putint(q, ci->clientnum); - else loopv(clients) putint(q, clients[i]->clientnum); - sendserverinforeply(q); - if(ci) extinfoplayer(p, ci); - else loopv(clients) extinfoplayer(p, clients[i]); - return; - } - case EXT_TEAMSCORE: { - extinfoteams(p); - break; - } - default: { - putint(p, EXT_ERROR); - break; - } - } - sendserverinforeply(p); - } diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp index d5501c4..0f0e3b1 100644 --- a/src/fpsgame/fps.cpp +++ b/src/fpsgame/fps.cpp @@ -139,8 +139,7 @@ namespace game { loopv(players) { fpsent *d = players[i]; if(d == player1 || d->ai) continue; - if(d->state==CS_DEAD && d->ragdoll) moveragdoll(d); - else if(!intermission) { + if(!intermission) { if(lastmillis - d->lastaction >= d->gunwait) d->gunwait = 0; if(d->quadmillis) entities::checkquad(curtime, d); } @@ -154,7 +153,7 @@ namespace game { if(smoothmove && d->smoothmillis>0) predictplayer(d, true); else moveplayer(d, 1, false); } - else if(d->state==CS_DEAD && !d->ragdoll && lastmillis-d->lastpain<2000) moveplayer(d, 1, true); + else if(d->state==CS_DEAD && lastmillis-d->lastpain<2000) moveplayer(d, 1, true); } } void checkslowmo() { @@ -176,18 +175,15 @@ namespace game { updateweapons(curtime); otherplayers(curtime); ai::update(); - moveragdolls(); gets2c(); if(connected) { if(player1->state == CS_DEAD) { - if(player1->ragdoll) moveragdoll(player1); - else if(lastmillis-player1->lastpain<2000) { + if(lastmillis-player1->lastpain<2000) { player1->move = player1->strafe = 0; moveplayer(player1, 10, true); } } else if(!intermission) { - if(player1->ragdoll) cleanragdoll(player1); moveplayer(player1, 10, true); swayhudgun(curtime); entities::checkitems(player1); @@ -201,7 +197,6 @@ namespace game { float a = x - lower, b = x - upper; return (b * b) / (a * a + b * b); } - static inline float harmonicmean(float a, float b) { return a + b > 0 ? 2 * a * b / (a + b) : 0.0f; } // avoid spawning near other players float ratespawn(dynent *d, const extentity &e) { fpsent *p = (fpsent *)d; @@ -427,7 +422,6 @@ namespace game { void startgame() { clearprojectiles(); clearbouncers(); - clearragdolls(); clearteaminfo(); // reset perma-state loopv(players) { diff --git a/src/fpsgame/game.h b/src/fpsgame/game.h index 92d4fd1..ed62052 100644 --- a/src/fpsgame/game.h +++ b/src/fpsgame/game.h @@ -139,7 +139,7 @@ enum { N_AUTHTRY, N_AUTHKICK, N_AUTHCHAL, N_AUTHANS, N_REQAUTH, N_PAUSEGAME, N_GAMESPEED, N_ADDBOT, N_DELBOT, N_INITAI, N_FROMAI, N_BOTLIMIT, N_BOTBALANCE, - N_MAPCRC, N_CHECKMAPS, + N_MAPCRC, N_SWITCHNAME, N_SWITCHMODEL, N_SWITCHTEAM, N_INITTOKENS, N_TAKETOKEN, N_EXPIRETOKENS, N_DROPTOKENS, N_DEPOSITTOKENS, N_STEALTOKENS, N_SERVCMD, @@ -166,7 +166,7 @@ static const int msgsizes[] = { // size inclusive message token, 0 for vari N_AUTHTRY, 0, N_AUTHKICK, 0, N_AUTHCHAL, 0, N_AUTHANS, 0, N_REQAUTH, 0, N_PAUSEGAME, 0, N_GAMESPEED, 0, N_ADDBOT, 2, N_DELBOT, 1, N_INITAI, 0, N_FROMAI, 2, N_BOTLIMIT, 2, N_BOTBALANCE, 2, - N_MAPCRC, 0, N_CHECKMAPS, 1, + N_MAPCRC, 0, N_SWITCHNAME, 0, N_SWITCHMODEL, 2, N_SWITCHTEAM, 0, N_INITTOKENS, 0, N_TAKETOKEN, 2, N_EXPIRETOKENS, 0, N_DROPTOKENS, 0, N_DEPOSITTOKENS, 2, N_STEALTOKENS, 0, N_SERVCMD, 0, @@ -587,12 +587,8 @@ namespace game { const char *ffa, *blueteam, *redteam, *hudguns, *vwep, *quad, *armour[3], *ffaicon, *blueicon, *redicon; - bool ragdoll; }; extern int playermodel, teamskins, testteam; - extern void saveragdoll(fpsent *d); - extern void clearragdolls(); - extern void moveragdolls(); extern const playermodelinfo &getplayermodelinfo(fpsent *d); extern void swayhudgun(int curtime); extern vec hudgunorigin(int gun, const vec &from, const vec &to, fpsent *d); diff --git a/src/fpsgame/render.cpp b/src/fpsgame/render.cpp index fff917e..dd8a5ee 100644 --- a/src/fpsgame/render.cpp +++ b/src/fpsgame/render.cpp @@ -6,42 +6,16 @@ extern float gatherspawninfos(dynent *d, int tag, vector &spawninfos) namespace game { vector bestplayers; vector bestteams; - VARP(ragdoll, 0, 1, 1); - VARP(ragdollmillis, 0, 10000, 300000); - VARP(ragdollfade, 0, 1000, 300000); VARP(playermodel, 0, 0, 0); VARP(hidedead, 0, 0, 2); - vector ragdolls; - void saveragdoll(fpsent *d) { - if(!d->ragdoll || !ragdollmillis || (!ragdollfade && lastmillis > d->lastpain + ragdollmillis)) return; - fpsent *r = new fpsent(*d); - r->lastupdate = ragdollfade && lastmillis > d->lastpain + max(ragdollmillis - ragdollfade, 0) ? lastmillis - max(ragdollmillis - ragdollfade, 0) : d->lastpain; - r->edit = NULL; - r->ai = NULL; - r->attackchan = r->idlechan = -1; - if(d==player1) r->playermodel = playermodel; - ragdolls.add(r); - d->ragdoll = NULL; - } - void clearragdolls() { - ragdolls.deletecontents(); - } - void moveragdolls() { - loopv(ragdolls) { - fpsent *d = ragdolls[i]; - if(lastmillis > d->lastupdate + ragdollmillis) { - delete ragdolls.remove(i--); - continue; - } - moveragdoll(d); - } - } - static const playermodelinfo playermodels[1] = { - { - "mrfixit", "mrfixit/blue", "mrfixit/red", "mrfixit/hudguns", NULL, "mrfixit/horns", { - "mrfixit/armor/blue", "mrfixit/armor/green", "mrfixit/armor/yellow" }, - "mrfixit", "mrfixit_blue", "mrfixit_red", true }, - }; + static const playermodelinfo playermodels[1] = { { + //~const char *ffa, *blueteam, *redteam, *hudguns, + //~*vwep, *quad, *armour[3], + //~*ffaicon, *blueicon, *redicon; + "mrfixit", "mrfixit/blue", "mrfixit/red", "mrfixit/hudguns", NULL, "mrfixit/horns", + { "mrfixit/armor/blue", "mrfixit/armor/green", "mrfixit/armor/yellow" }, + "mrfixit", "mrfixit_blue", "mrfixit_red" + } }; const playermodelinfo *getplayermodelinfo(int n) { (void) n; return &playermodels[0]; @@ -108,7 +82,7 @@ namespace game { case 1: mdlname = mdl.blueteam; break; case 2: mdlname = mdl.redteam; break; } - renderclient(d, mdlname, a[0].tag ? a : NULL, hold, attack, delay, lastaction, intermission && d->state!=CS_DEAD ? 0 : d->lastpain, fade, ragdoll && mdl.ragdoll); + renderclient(d, mdlname, a[0].tag ? a : NULL, hold, attack, delay, lastaction, intermission && d->state!=CS_DEAD ? 0 : d->lastpain, fade); } VARP(teamskins, 0, 0, 1); VARP(statusicons, 0, 1, 1); @@ -194,15 +168,6 @@ namespace game { renderstatusicons(d, team, offset); } } - loopv(ragdolls) { - fpsent *d = ragdolls[i]; - int team = 0; - if(teamskins || m_teammode) team = isteam(player1->team, d->team) ? 1 : 2; - float fade = 1.0f; - if(ragdollmillis && ragdollfade) - fade -= clamp(float(lastmillis - (d->lastupdate + max(ragdollmillis - ragdollfade, 0)))/min(ragdollmillis, ragdollfade), 0.0f, 1.0f); - renderplayer(d, getplayermodelinfo(d), team, fade, mainpass); - } if(isthirdperson() && !followingplayer() && (player1->state!=CS_DEAD || hidedead != 1)) renderplayer(player1, getplayermodelinfo(player1), teamskins || m_teammode ? 1 : 0, 1, mainpass); entities::renderentities(); renderbouncers(); @@ -212,7 +177,6 @@ namespace game { VARP(hudgun, 0, 1, 1); VARP(hudgunsway, 0, 1, 1); VARP(teamhudguns, 0, 1, 1); - VARP(chainsawhudgun, 0, 1, 1); VAR(testhudgun, 0, 0, 1); FVAR(swaystep, 1, 35.0f, 100); FVAR(swayside, 0, 0.04f, 1); @@ -263,7 +227,7 @@ namespace game { d->muzzle = vec(-1, -1, -1); a[0] = modelattach("tag_muzzle", &d->muzzle); dynent *interp = NULL; - if(d->gunselect==GUN_FIST && chainsawhudgun) { + if(d->gunselect==GUN_FIST) { anim |= ANIM_LOOP; base = 0; interp = &guninterp; diff --git a/src/fpsgame/scoreboard.cpp b/src/fpsgame/scoreboard.cpp index b1c7477..851b57d 100644 --- a/src/fpsgame/scoreboard.cpp +++ b/src/fpsgame/scoreboard.cpp @@ -334,23 +334,23 @@ namespace game { /// PW g.separator(); g.pushlist(); - g.textf(" %d%% ", 0x787878, "chainsaw.png", pwaccuracy[0]); - g.textf(" %d%% ", 0xfba6a6, "shotgun.png", pwaccuracy[1]); - g.textf(" %d%% ", 0x7bc77a, "chaingun.png", pwaccuracy[2]); - g.textf(" %d%% ", 0xefd7a6, "rocket_launcher.png", pwaccuracy[3]); - g.textf(" %d%% ", 0x8f91e7, "rifle.png", pwaccuracy[4]); - g.textf(" %d%% ", 0x9ee5e5, "grenade_launcher.png", pwaccuracy[5]); - g.textf(" %d%% ", 0xc3c3c3, "pistol.png", pwaccuracy[6]); + g.textf("%d%% ", 0x787878, "chainsaw.png", pwaccuracy[0]); + g.textf("%d%% ", 0xfba6a6, "shotgun.png", pwaccuracy[1]); + g.textf("%d%% ", 0x7bc77a, "chaingun.png", pwaccuracy[2]); + g.textf("%d%% ", 0xefd7a6, "rocket_launcher.png", pwaccuracy[3]); + g.textf("%d%% ", 0x8f91e7, "rifle.png", pwaccuracy[4]); + g.textf("%d%% ", 0x9ee5e5, "grenade_launcher.png", pwaccuracy[5]); + g.textf("%d%% ", 0xc3c3c3, "pistol.png", pwaccuracy[6]); g.poplist(); g.separator(); g.pushlist(); - g.textf(" x %d ", 0xffffff, "blue_armour.png", pwitemspicked[0]); - g.textf(" x %d ", 0xffffff, "green_armour.png", pwitemspicked[1]); - g.textf(" x %d ", 0xffffff, "yellow_armour.png", pwitemspicked[2]); - g.textf(" x %d ", 0xffffff, "tiny_health.png", pwitemspicked[3]); - g.textf(" x %d ", 0xffffff, "health.png", pwitemspicked[4]); - g.textf(" x %d ", 0xffffff, "health_boost.png", pwitemspicked[5]); - g.textf(" x %d ", 0xffffff, "quad_damage.png", pwitemspicked[6]); + g.textf("%d ", 0xffffff, "blue_armour.png", pwitemspicked[0]); + g.textf("%d ", 0xffffff, "green_armour.png", pwitemspicked[1]); + g.textf("%d ", 0xffffff, "yellow_armour.png", pwitemspicked[2]); + g.textf("%d ", 0xffffff, "tiny_health.png", pwitemspicked[3]); + g.textf("%d ", 0xffffff, "health.png", pwitemspicked[4]); + g.textf("%d ", 0xffffff, "health_boost.png", pwitemspicked[5]); + g.textf("%d ", 0xffffff, "quad_damage.png", pwitemspicked[6]); g.poplist(); } struct scoreboardgui : g3d_callback { diff --git a/src/fpsgame/server.cpp b/src/fpsgame/server.cpp index 341b050..8f17ee2 100644 --- a/src/fpsgame/server.cpp +++ b/src/fpsgame/server.cpp @@ -263,7 +263,6 @@ namespace server { extern void reqadd(clientinfo *ci, int skill); extern void reqdel(clientinfo *ci); extern void setbotlimit(clientinfo *ci, int limit); - extern void setbotbalance(clientinfo *ci, bool balance); extern void changemap(); extern void addclient(clientinfo *ci); extern void changeteam(clientinfo *ci); @@ -1894,63 +1893,12 @@ namespace server { crcinfo(int crc, int matches) : crc(crc), matches(matches) {} static bool compare(const crcinfo &x, const crcinfo &y) { return x.matches > y.matches; } }; - VAR(modifiedmapspectator, 0, 1, 2); - void checkmaps(int req = -1) { - if(m_edit || !smapname[0]) return; - vector crcs; - int total = 0, unsent = 0, invalid = 0; - if(mcrc) crcs.add(crcinfo(mcrc, clients.length() + 1)); - loopv(clients) { - clientinfo *ci = clients[i]; - if(ci->state.state==CS_SPECTATOR || ci->state.aitype != AI_NONE) continue; - total++; - if(!ci->clientmap[0]) { - if(ci->mapcrc < 0) invalid++; - else if(!ci->mapcrc) unsent++; - } - else { - crcinfo *match = NULL; - loopvj(crcs) if(crcs[j].crc == ci->mapcrc) { match = &crcs[j]; break; } - if(!match) crcs.add(crcinfo(ci->mapcrc, 1)); - else match->matches++; - } - } - if(!mcrc && total - unsent < min(total, 4)) return; - crcs.sort(crcinfo::compare); - string msg; - loopv(clients) { - clientinfo *ci = clients[i]; - if(ci->state.state==CS_SPECTATOR || ci->state.aitype != AI_NONE || ci->clientmap[0] || ci->mapcrc >= 0 || (req < 0 && ci->warned)) continue; - formatstring(msg, "%s has modified map \"%s\"", colorname(ci), smapname); - sendf(req, 1, "ris", N_SERVMSG, msg); - if(req < 0) ci->warned = true; - } - if(crcs.length() >= 2) loopv(crcs) { - crcinfo &info = crcs[i]; - if(i || info.matches <= crcs[i+1].matches) loopvj(clients) { - clientinfo *ci = clients[j]; - if(ci->state.state==CS_SPECTATOR || ci->state.aitype != AI_NONE || !ci->clientmap[0] || ci->mapcrc != info.crc || (req < 0 && ci->warned)) continue; - formatstring(msg, "%s has modified map \"%s\"", colorname(ci), smapname); - sendf(req, 1, "ris", N_SERVMSG, msg); - if(req < 0) ci->warned = true; - } - } - if(req < 0 && modifiedmapspectator && (mcrc || modifiedmapspectator > 1)) loopv(clients) { - clientinfo *ci = clients[i]; - if(!ci->local && ci->warned && ci->state.state != CS_SPECTATOR) forcespectator(ci); - } - } - bool shouldspectate(clientinfo *ci) { - return !ci->local && ci->warned && modifiedmapspectator && (mcrc || modifiedmapspectator > 1); - } void unspectate(clientinfo *ci) { - if(shouldspectate(ci)) return; ci->state.state = CS_DEAD; ci->state.respawn(); ci->state.lasttimeplayed = lastmillis; aiman::addclient(ci); sendf(-1, 1, "ri3", N_SPECTATOR, ci->clientnum, 0); - if(ci->clientmap[0] || ci->mapcrc) checkmaps(); if(!hasmap(ci)) rotatemap(true); } void sendservinfo(clientinfo *ci) { @@ -2350,18 +2298,13 @@ namespace server { } copystring(ci->clientmap, text); ci->mapcrc = text[0] ? crc : 1; - checkmaps(); if(cq && cq != ci && cq->ownernum != ci->clientnum) cq = NULL; break; } - case N_CHECKMAPS: - checkmaps(sender); - break; case N_TRYSPAWN: if(!ci || !cq || cq->state.state!=CS_DEAD || cq->state.lastspawn>=0) break; if(!ci->clientmap[0] && !ci->mapcrc) { ci->mapcrc = -1; - checkmaps(); if(ci == cq) { if(ci->state.state != CS_DEAD) break; } else if(cq->ownernum != ci->clientnum) { cq = NULL; break; } } @@ -2700,11 +2643,6 @@ namespace server { if(ci) aiman::setbotlimit(ci, limit); break; } - case N_BOTBALANCE: { - int balance = getint(p); - if(ci) aiman::setbotbalance(ci, balance!=0); - break; - } case N_AUTHTRY: { string desc, name; getstring(desc, p, sizeof(desc)); @@ -2819,7 +2757,102 @@ namespace server { const char *defaultmaster() { return "master.sauerbraten.org"; } int masterport() { return SAUERBRATEN_MASTER_PORT; } int numchannels() { return 3; } - #include "extinfo.h" + +#define EXT_ACK -1 +#define EXT_VERSION 105 +#define EXT_NO_ERROR 0 +#define EXT_ERROR 1 +#define EXT_PLAYERSTATS_RESP_IDS -10 +#define EXT_PLAYERSTATS_RESP_STATS -11 +#define EXT_UPTIME 0 +#define EXT_PLAYERSTATS 1 +#define EXT_TEAMSCORE 2 + + VAR(extinfoip, 0, 0, 1); + void extinfoplayer(ucharbuf &p, clientinfo *ci) { + ucharbuf q = p; + putint(q, EXT_PLAYERSTATS_RESP_STATS); // send player stats following + putint(q, ci->clientnum); //add player id + putint(q, ci->ping); + sendstring(ci->name, q); + sendstring(ci->team, q); + putint(q, ci->state.frags); + putint(q, ci->state.flags); + putint(q, ci->state.deaths); + putint(q, ci->state.teamkills); + putint(q, ci->state.damage*100/max(ci->state.shotdamage,1)); + putint(q, ci->state.health); + putint(q, ci->state.armour); + putint(q, ci->state.gunselect); + putint(q, ci->privilege); + putint(q, ci->state.state); + uint ip = extinfoip ? getclientip(ci->clientnum) : 0; + q.put((uchar*)&ip, 3); + sendserverinforeply(q); + } + static inline void extinfoteamscore(ucharbuf &p, const char *team, int score) { + sendstring(team, p); + putint(p, score); + putint(p,-1); //no bases follow + } + void extinfoteams(ucharbuf &p) { + putint(p, m_teammode ? 0 : 1); + putint(p, gamemode); + putint(p, max((gamelimit - gamemillis)/1000, 0)); + if(!m_teammode) return; + vector scores; + loopv(clients) { + clientinfo *ci = clients[i]; + if(ci->state.state!=CS_SPECTATOR && ci->team[0] && scores.htfind(ci->team) < 0) { + teaminfo *ti = teaminfos.access(ci->team); + scores.add(teamscore(ci->team, ti ? ti->frags : 0)); + } + } + loopv(scores) extinfoteamscore(p, scores[i].team, scores[i].score); + } + void extserverinforeply(ucharbuf &req, ucharbuf &p) { + int extcmd = getint(req); // extended commands + //Build a new packet + putint(p, EXT_ACK); //send ack + putint(p, EXT_VERSION); //send version of extended info + switch(extcmd) { + case EXT_UPTIME: { + putint(p, totalsecs); //in seconds + break; + } + case EXT_PLAYERSTATS: { + int cn = getint(req); //a special player, -1 for all + clientinfo *ci = NULL; + if(cn >= 0) { + loopv(clients) if(clients[i]->clientnum == cn) { ci = clients[i]; break; } + if(!ci) { + putint(p, EXT_ERROR); //client requested by id was not found + sendserverinforeply(p); + return; + } + } + putint(p, EXT_NO_ERROR); //so far no error can happen anymore + ucharbuf q = p; //remember buffer position + putint(q, EXT_PLAYERSTATS_RESP_IDS); //send player ids following + if(ci) putint(q, ci->clientnum); + else loopv(clients) putint(q, clients[i]->clientnum); + sendserverinforeply(q); + if(ci) extinfoplayer(p, ci); + else loopv(clients) extinfoplayer(p, clients[i]); + return; + } + case EXT_TEAMSCORE: { + extinfoteams(p); + break; + } + default: { + putint(p, EXT_ERROR); + break; + } + } + sendserverinforeply(p); + } + void serverinforeply(ucharbuf &req, ucharbuf &p) { if(req.remaining() && !getint(req)) { extserverinforeply(req, p); @@ -2840,6 +2873,183 @@ namespace server { sendstring(serverdesc, p); sendserverinforeply(p); } - #include "aiman.h" + + // server-side ai manager + namespace aiman { + bool dorefresh = false; + VARN(serverbotlimit, botlimit, 0, 8, MAXBOTS); + void calcteams(vector &teams) { + static const char * const defaults[2] = { "good", "evil" }; + loopv(clients) { + clientinfo *ci = clients[i]; + if(ci->state.state==CS_SPECTATOR || !ci->team[0]) continue; + teamscore *t = NULL; + loopvj(teams) if(!strcmp(teams[j].team, ci->team)) { t = &teams[j]; break; } + if(t) t->score++; + else teams.add(teamscore(ci->team, 1)); + } + teams.sort(teamscore::compare); + if(teams.length() < int(sizeof(defaults)/sizeof(defaults[0]))) { + loopi(sizeof(defaults)/sizeof(defaults[0])) if(teams.htfind(defaults[i]) < 0) teams.add(teamscore(defaults[i], 0)); + } + } + + const char *chooseteam() { + vector teams; + calcteams(teams); + return teams.length() ? teams.last().team : ""; + } + static inline bool validaiclient(clientinfo *ci) { + return ci->clientnum >= 0 && ci->state.aitype == AI_NONE && (ci->state.state!=CS_SPECTATOR || ci->local || (ci->privilege && !ci->warned)); + } + clientinfo *findaiclient(clientinfo *exclude = NULL) { + clientinfo *least = NULL; + loopv(clients) { + clientinfo *ci = clients[i]; + if(!validaiclient(ci) || ci==exclude) continue; + if(!least || ci->bots.length() < least->bots.length()) least = ci; + } + return least; + } + bool addai(int skill, int limit) { + int numai = 0, cn = -1, maxai = limit >= 0 ? min(limit, MAXBOTS) : MAXBOTS; + loopv(bots) { + clientinfo *ci = bots[i]; + if(!ci || ci->ownernum < 0) { if(cn < 0) cn = i; continue; } + numai++; + } + if(numai >= maxai) return false; + if(bots.inrange(cn)) { + clientinfo *ci = bots[cn]; + if(ci) { + // reuse a slot that was going to removed + clientinfo *owner = findaiclient(); + ci->ownernum = owner ? owner->clientnum : -1; + if(owner) owner->bots.add(ci); + ci->aireinit = 2; + dorefresh = true; + return true; + } + } + else { cn = bots.length(); bots.add(NULL); } + const char *team = m_teammode ? chooseteam() : ""; + if(!bots[cn]) bots[cn] = new clientinfo; + clientinfo *ci = bots[cn]; + ci->clientnum = MAXCLIENTS + cn; + ci->state.aitype = AI_BOT; + clientinfo *owner = findaiclient(); + ci->ownernum = owner ? owner->clientnum : -1; + if(owner) owner->bots.add(ci); + ci->state.skill = skill <= 0 ? rnd(50) + 51 : clamp(skill, 1, 101); + clients.add(ci); + ci->state.lasttimeplayed = lastmillis; + copystring(ci->name, "bot", MAXNAMELEN+1); + ci->state.state = CS_DEAD; + copystring(ci->team, team, MAXTEAMLEN+1); + ci->playermodel = 0; + ci->aireinit = 2; + ci->connected = true; + dorefresh = true; + return true; + } + void deleteai(clientinfo *ci) { + int cn = ci->clientnum - MAXCLIENTS; + if(!bots.inrange(cn)) return; + sendf(-1, 1, "ri2", N_CDIS, ci->clientnum); + clientinfo *owner = (clientinfo *)getclientinfo(ci->ownernum); + if(owner) owner->bots.removeobj(ci); + clients.removeobj(ci); + DELETEP(bots[cn]); + dorefresh = true; + } + bool deleteai() { + loopvrev(bots) if(bots[i] && bots[i]->ownernum >= 0) { + deleteai(bots[i]); + return true; + } + return false; + } + void reinitai(clientinfo *ci) { + if(ci->ownernum < 0) deleteai(ci); + else if(ci->aireinit >= 1) { + sendf(-1, 1, "ri6ss", N_INITAI, ci->clientnum, ci->ownernum, ci->state.aitype, ci->state.skill, ci->playermodel, ci->name, ci->team); + if(ci->aireinit == 2) { + ci->reassign(); + if(ci->state.state==CS_ALIVE) sendspawn(ci); + else sendresume(ci); + } + ci->aireinit = 0; + } + } + void shiftai(clientinfo *ci, clientinfo *owner = NULL) { + clientinfo *prevowner = (clientinfo *)getclientinfo(ci->ownernum); + if(prevowner) prevowner->bots.removeobj(ci); + if(!owner) { ci->aireinit = 0; ci->ownernum = -1; } + else if(ci->ownernum != owner->clientnum) { ci->aireinit = 2; ci->ownernum = owner->clientnum; owner->bots.add(ci); } + dorefresh = true; + } + void removeai(clientinfo *ci) { + // either schedules a removal, or someone else to assign to + loopvrev(ci->bots) shiftai(ci->bots[i], findaiclient(ci)); + } + bool reassignai() { + clientinfo *hi = NULL, *lo = NULL; + loopv(clients) { + clientinfo *ci = clients[i]; + if(!validaiclient(ci)) continue; + if(!lo || ci->bots.length() < lo->bots.length()) lo = ci; + if(!hi || ci->bots.length() > hi->bots.length()) hi = ci; + } + if(hi && lo && hi->bots.length() - lo->bots.length() > 1) { + loopvrev(hi->bots) { + shiftai(hi->bots[i], lo); + return true; + } + } + return false; + } + + void checksetup() { + loopvrev(bots) if(bots[i]) reinitai(bots[i]); + } + void clearai() { + // clear and remove all ai immediately + loopvrev(bots) if(bots[i]) deleteai(bots[i]); + } + void checkai() { + if(!dorefresh) return; + dorefresh = false; + if(m_botmode && numclients(-1, false, true)) { + checksetup(); + while(reassignai()); + } + else clearai(); + } + void reqadd(clientinfo *ci, int skill) { + if(!ci->local && !ci->privilege) return; + if(!addai(skill, !ci->local && ci->privilege < PRIV_ADMIN ? botlimit : -1)) sendf(ci->clientnum, 1, "ris", N_SERVMSG, "failed to create or assign bot"); + } + void reqdel(clientinfo *ci) { + if(!ci->local && !ci->privilege) return; + if(!deleteai()) sendf(ci->clientnum, 1, "ris", N_SERVMSG, "failed to remove any bots"); + } + void setbotlimit(clientinfo *ci, int limit) { + if(ci && !ci->local && ci->privilege < PRIV_ADMIN) return; + botlimit = clamp(limit, 0, MAXBOTS); + dorefresh = true; + defformatstring(msg, "bot limit is now %d", botlimit); + sendservmsg(msg); + } + void changemap() { + dorefresh = true; + loopv(clients) if(clients[i]->local || clients[i]->privilege) return; + } + void addclient(clientinfo *ci) { + if(ci->state.aitype == AI_NONE) dorefresh = true; + } + void changeteam(clientinfo *ci) { + if(ci->state.aitype == AI_NONE) dorefresh = true; + } + } } diff --git a/src/fpsgame/weapon.cpp b/src/fpsgame/weapon.cpp index 30d2da8..4c85a36 100644 --- a/src/fpsgame/weapon.cpp +++ b/src/fpsgame/weapon.cpp @@ -408,14 +408,13 @@ namespace game { else p.o = v; } } - extern int chainsawhudgun; VARP(muzzleflash, 0, 1, 1); VARP(muzzlelight, 0, 1, 1); void shoteffects(int gun, const vec &from, const vec &to, fpsent *d, bool local, int id, int prevaction) { // create visual effect from a shot { int sound = guns[gun].sound, pspeed = 25; switch(gun) { case GUN_FIST: - if(d->type==ENT_PLAYER && chainsawhudgun) sound = S_CHAINSAW_ATTACK; + if(d->type==ENT_PLAYER) sound = S_CHAINSAW_ATTACK; break; case GUN_SG: { if(!local) createrays(gun, from, to); @@ -613,7 +612,7 @@ namespace game { } pitch = -bnc.roll; if(bnc.bouncetype==BNC_GRENADE) - rendermodel(&bnc.light, "projectiles/grenade", ANIM_MAPMODEL|ANIM_LOOP, pos, yaw, pitch, MDL_CULL_VFC|MDL_CULL_OCCLUDED|MDL_LIGHT|MDL_LIGHT_FAST|MDL_DYNSHADOW); + rendermodel(&bnc.light, "projectiles/grenade", ANIM_MAPMODEL|ANIM_LOOP, pos, yaw, pitch, MDL_CULL_VFC|MDL_CULL_OCCLUDED|MDL_LIGHT|MDL_LIGHT_FAST); else { const char *mdl = NULL; int cull = MDL_CULL_VFC|MDL_CULL_DIST|MDL_CULL_OCCLUDED; @@ -643,7 +642,7 @@ namespace game { int gun = -1; switch(d->attacksound) { case S_CHAINSAW_ATTACK: - if(chainsawhudgun) gun = GUN_FIST; + gun = GUN_FIST; break; default: return; @@ -660,7 +659,7 @@ namespace game { int sound = -1, radius = 0; if(d->clientnum >= 0 && d->state == CS_ALIVE) switch(d->gunselect) { case GUN_FIST: - if(chainsawhudgun && d->attacksound < 0) { + if(d->attacksound < 0) { sound = S_CHAINSAW_IDLE; radius = 50; } @@ -711,9 +710,10 @@ namespace game { /// Rough accuracy code, client-side only. int pwshotsfired [NUMGUNS] = { 0 }; -int pwshotshit [NUMGUNS] = { 0 }; +int pwshotshit [NUMGUNS] = { 0 }; int pwdamagedealt [NUMGUNS] = { 0 }; -int pwaccuracy [NUMGUNS] = { 0 }; +int pwaccuracy [NUMGUNS] = { 0 }; + int pwavgaccuracy = 0; void pwshot(int gun) { diff --git a/src/shared/cube2font.c b/src/shared/cube2font.c deleted file mode 100644 index c411862..0000000 --- a/src/shared/cube2font.c +++ /dev/null @@ -1,547 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include FT_FREETYPE_H -#include FT_STROKER_H -#include FT_GLYPH_H - -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned int uint; - -int imin(int a, int b) { return a < b ? a : b; } -int imax(int a, int b) { return a > b ? a : b; } - -void fatal(const char *fmt, ...) { - - va_list v; - va_start(v, fmt); - vfprintf(stderr, fmt, v); - va_end(v); - fputc('\n', stderr); - - exit(EXIT_FAILURE); -} - -uint bigswap(uint n) { - - const int islittleendian = 1; - return *(const uchar *)&islittleendian ? (n<<24) | (n>>24) | ((n>>8)&0xFF00) | ((n<<8)&0xFF0000) : n; -} - -size_t writebig(FILE *f, uint n) { - - n = bigswap(n); - return fwrite(&n, 1, sizeof(n), f); -} - -void writepngchunk(FILE *f, const char *type, uchar *data, uint len) { - - uint crc; - writebig(f, len); - fwrite(type, 1, 4, f); - fwrite(data, 1, len, f); - - crc = crc32(0, Z_NULL, 0); - crc = crc32(crc, (const Bytef *)type, 4); - if(data) crc = crc32(crc, data, len); - writebig(f, crc); -} - -struct pngihdr { - - uint width, height; - uchar bitdepth, colortype, compress, filter, interlace; -}; - -void savepng(const char *filename, uchar *data, int w, int h, int bpp, int flip) { - - const uchar signature[] = { 137, 80, 78, 71, 13, 10, 26, 10 }; - struct pngihdr ihdr; - FILE *f; - long idat; - uint len, crc; - z_stream z; - uchar buf[1<<12]; - int i, j; - - memset(&ihdr, 0, sizeof(ihdr)); - ihdr.width = bigswap(w); - ihdr.height = bigswap(h); - ihdr.bitdepth = 8; - switch(bpp) { - - case 1: ihdr.colortype = 0; break; - case 2: ihdr.colortype = 4; break; - case 3: ihdr.colortype = 2; break; - case 4: ihdr.colortype = 6; break; - default: fatal("cube2font: invalid PNG bpp"); return; - } - f = fopen(filename, "wb"); - if(!f) { fatal("cube2font: could not write to %s", filename); return; } - - fwrite(signature, 1, sizeof(signature), f); - - writepngchunk(f, "IHDR", (uchar *)&ihdr, 13); - - idat = ftell(f); - len = 0; - fwrite("\0\0\0\0IDAT", 1, 8, f); - crc = crc32(0, Z_NULL, 0); - crc = crc32(crc, (const Bytef *)"IDAT", 4); - - z.zalloc = NULL; - z.zfree = NULL; - z.opaque = NULL; - - if(deflateInit(&z, Z_BEST_COMPRESSION) != Z_OK) - goto error; - - z.next_out = (Bytef *)buf; - z.avail_out = sizeof(buf); - - for(i = 0; i < h; i++) { - - uchar filter = 0; - for(j = 0; j < 2; j++) { - - z.next_in = j ? (Bytef *)data + (flip ? h-i-1 : i)*w*bpp : (Bytef *)&filter; - z.avail_in = j ? w*bpp : 1; - while(z.avail_in > 0) { - - if(deflate(&z, Z_NO_FLUSH) != Z_OK) goto cleanuperror; - #define FLUSHZ do { \ - int flush = sizeof(buf) - z.avail_out; \ - crc = crc32(crc, buf, flush); \ - len += flush; \ - fwrite(buf, 1, flush, f); \ - z.next_out = (Bytef *)buf; \ - z.avail_out = sizeof(buf); \ - } while(0) - FLUSHZ; - } - } - } - - for(;;) { - - int err = deflate(&z, Z_FINISH); - if(err != Z_OK && err != Z_STREAM_END) goto cleanuperror; - FLUSHZ; - if(err == Z_STREAM_END) break; - } - - deflateEnd(&z); - - fseek(f, idat, SEEK_SET); - writebig(f, len); - fseek(f, 0, SEEK_END); - writebig(f, crc); - - writepngchunk(f, "IEND", NULL, 0); - - fclose(f); - return; - -cleanuperror: - deflateEnd(&z); - -error: - fclose(f); - - fatal("cube2font: failed saving PNG to %s", filename); -} - -enum { - - CT_PRINT = 1<<0, - CT_SPACE = 1<<1, - CT_DIGIT = 1<<2, - CT_ALPHA = 1<<3, - CT_LOWER = 1<<4, - CT_UPPER = 1<<5, - CT_UNICODE = 1<<6 -}; -#define CUBECTYPE(s, p, d, a, A, u, U) \ - 0, U, U, U, U, U, U, U, U, s, s, s, s, s, U, U, \ - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, \ - s, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, \ - d, d, d, d, d, d, d, d, d, d, p, p, p, p, p, p, \ - p, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, \ - A, A, A, A, A, A, A, A, A, A, A, p, p, p, p, p, \ - p, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, \ - a, a, a, a, a, a, a, a, a, a, a, p, p, p, p, U, \ - U, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, \ - u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, U, \ - u, U, u, U, u, U, u, U, u, U, u, U, u, U, u, U, \ - u, U, u, U, u, U, u, U, u, U, u, U, u, U, u, U, \ - u, U, u, U, u, U, u, U, U, u, U, u, U, u, U, U, \ - U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, \ - U, U, U, U, u, u, u, u, u, u, u, u, u, u, u, u, \ - u, u, u, u, u, u, u, u, u, u, u, u, u, u, U, u -const uchar cubectype[256] = { - - CUBECTYPE(CT_SPACE, - CT_PRINT, - CT_PRINT|CT_DIGIT, - CT_PRINT|CT_ALPHA|CT_LOWER, - CT_PRINT|CT_ALPHA|CT_UPPER, - CT_PRINT|CT_UNICODE|CT_ALPHA|CT_LOWER, - CT_PRINT|CT_UNICODE|CT_ALPHA|CT_UPPER) -}; -int iscubeprint(uchar c) { return cubectype[c]&CT_PRINT; } -int iscubespace(uchar c) { return cubectype[c]&CT_SPACE; } -int iscubealpha(uchar c) { return cubectype[c]&CT_ALPHA; } -int iscubealnum(uchar c) { return cubectype[c]&(CT_ALPHA|CT_DIGIT); } -int iscubelower(uchar c) { return cubectype[c]&CT_LOWER; } -int iscubeupper(uchar c) { return cubectype[c]&CT_UPPER; } -const int cube2unichars[256] = { - - 0, 192, 193, 194, 195, 196, 197, 198, 199, 9, 10, 11, 12, 13, 200, 201, - 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 220, - 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, - 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253, 255, 0x104, - 0x105, 0x106, 0x107, 0x10C, 0x10D, 0x10E, 0x10F, 0x118, 0x119, 0x11A, 0x11B, 0x11E, 0x11F, 0x130, 0x131, 0x141, - 0x142, 0x143, 0x144, 0x147, 0x148, 0x150, 0x151, 0x152, 0x153, 0x158, 0x159, 0x15A, 0x15B, 0x15E, 0x15F, 0x160, - 0x161, 0x164, 0x165, 0x16E, 0x16F, 0x170, 0x171, 0x178, 0x179, 0x17A, 0x17B, 0x17C, 0x17D, 0x17E, 0x404, 0x411, - 0x413, 0x414, 0x416, 0x417, 0x418, 0x419, 0x41B, 0x41F, 0x423, 0x424, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, - 0x42C, 0x42D, 0x42E, 0x42F, 0x431, 0x432, 0x433, 0x434, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, - 0x43F, 0x442, 0x444, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x454, 0x490, 0x491 -}; -int cube2uni(uchar c) { - - return cube2unichars[c]; -} - -const char *encodeutf8(int uni) { - - static char buf[7]; - char *dst = buf; - if(uni <= 0x7F) { *dst++ = uni; goto uni1; } - else if(uni <= 0x7FF) { *dst++ = 0xC0 | (uni>>6); goto uni2; } - else if(uni <= 0xFFFF) { *dst++ = 0xE0 | (uni>>12); goto uni3; } - else if(uni <= 0x1FFFFF) { *dst++ = 0xF0 | (uni>>18); goto uni4; } - else if(uni <= 0x3FFFFFF) { *dst++ = 0xF8 | (uni>>24); goto uni5; } - else if(uni <= 0x7FFFFFFF) { *dst++ = 0xFC | (uni>>30); goto uni6; } - else goto uni1; -uni6: *dst++ = 0x80 | ((uni>>24)&0x3F); -uni5: *dst++ = 0x80 | ((uni>>18)&0x3F); -uni4: *dst++ = 0x80 | ((uni>>12)&0x3F); -uni3: *dst++ = 0x80 | ((uni>>6)&0x3F); -uni2: *dst++ = 0x80 | (uni&0x3F); -uni1: *dst++ = '\0'; - return buf; -} - -struct fontchar { int code, uni, tex, x, y, w, h, offx, offy, offset, advance; FT_BitmapGlyph color, alpha; }; - -const char *texdir = ""; - -const char *texfilename(const char *name, int texnum) { - - static char file[256]; - snprintf(file, sizeof(file), "%s%d.png", name, texnum); - return file; -} - -const char *texname(const char *name, int texnum) { - - static char file[512]; - snprintf(file, sizeof(file), "%s%s", texdir, texfilename(name, texnum)); - return file; -} - -void writetexs(const char *name, struct fontchar *chars, int numchars, int numtexs, int tw, int th) { - - int tex; - uchar *pixels = (uchar *)malloc(tw*th*2); - if(!pixels) fatal("cube2font: failed allocating textures"); - for(tex = 0; tex < numtexs; tex++) { - - const char *file = texfilename(name, tex); - int texchars = 0, i; - uchar *dst, *src; - memset(pixels, 0, tw*th*2); - for(i = 0; i < numchars; i++) { - - struct fontchar *c = &chars[i]; - int x, y; - if(c->tex != tex) continue; - texchars++; - dst = &pixels[2*((c->y + c->offy - c->color->top)*tw + c->x + c->color->left - c->offx)]; - src = (uchar *)c->color->bitmap.buffer; - for(y = 0; y < c->color->bitmap.rows; y++) { - - for(x = 0; x < c->color->bitmap.width; x++) - dst[2*x] = src[x]; - src += c->color->bitmap.pitch; - dst += 2*tw; - } - dst = &pixels[2*((c->y + c->offy - c->alpha->top)*tw + c->x + c->alpha->left - c->offx)]; - src = (uchar *)c->alpha->bitmap.buffer; - for(y = 0; y < c->alpha->bitmap.rows; y++) { - - for(x = 0; x < c->alpha->bitmap.width; x++) - dst[2*x+1] = src[x]; - src += c->alpha->bitmap.pitch; - dst += 2*tw; - } - } - printf("cube2font: writing %d chars to %s\n", texchars, file); - savepng(file, pixels, tw, th, 2, 0); - } - free(pixels); -} - -void writecfg(const char *name, struct fontchar *chars, int numchars, int x1, int y1, int x2, int y2, int sw, int sh, int argc, char **argv) { - - FILE *f; - char file[256]; - int i, lastcode = 0, lasttex = 0; - snprintf(file, sizeof(file), "%s.cfg", name); - f = fopen(file, "w"); - if(!f) fatal("cube2font: failed writing %s", file); - printf("cube2font: writing %d chars to %s\n", numchars, file); - fprintf(f, "//"); - for(i = 1; i < argc; i++) - fprintf(f, " %s", argv[i]); - fprintf(f, "\n"); - fprintf(f, "font \"%s\" \"%s\" %d %d\n", name, texname(name, 0), sw, sh); - for(i = 0; i < numchars; i++) { - - struct fontchar *c = &chars[i]; - if(!lastcode && lastcode < c->code) { - - fprintf(f, "fontoffset \"%s\"\n", encodeutf8(c->uni)); - lastcode = c->code; - } - else if(lastcode < c->code) { - - if(lastcode + 1 == c->code) - fprintf(f, "fontskip // %d\n", lastcode); - else - fprintf(f, "fontskip %d // %d .. %d\n", c->code - lastcode, lastcode, c->code-1); - lastcode = c->code; - } - if(lasttex != c->tex) { - - fprintf(f, "\nfonttex \"%s\"\n", texname(name, c->tex)); - lasttex = c->tex; - } - if(c->code != c->uni) - fprintf(f, "fontchar %d %d %d %d %d %d %d // %s (%d -> 0x%X)\n", c->x, c->y, c->w, c->h, c->offx+c->offset, y2-c->offy, c->advance, encodeutf8(c->uni), c->code, c->uni); - else - fprintf(f, "fontchar %d %d %d %d %d %d %d // %s (%d)\n", c->x, c->y, c->w, c->h, c->offx+c->offset, y2-c->offy, c->advance, encodeutf8(c->uni), c->code); - lastcode++; - } - fclose(f); -} - -int groupchar(int c) { - - switch(c) { - - case 0x152: case 0x153: case 0x178: return 1; - } - if(c < 127 || c >= 0x2000) return 0; - if(c < 0x100) return 1; - if(c < 0x400) return 2; - return 3; -} - -int sortchars(const void *x, const void *y) { - - const struct fontchar *xc = *(const struct fontchar **)x, *yc = *(const struct fontchar **)y; - int xg = groupchar(xc->uni), yg = groupchar(yc->uni); - if(xg < yg) return -1; - if(xg > yg) return 1; - if(xc->h != yc->h) return yc->h - xc->h; - if(xc->w != yc->w) return yc->w - xc->w; - return yc->uni - xc->uni; -} - -int scorechar(struct fontchar *f, int pad, int tw, int th, int rw, int rh, int ry) { - - int score = 0; - if(rw + f->w > tw) { ry += rh + pad; score = 1; } - if(ry + f->h > th) score = 2; - return score; -} - -int main(int argc, char **argv) { - - FT_Library l; - FT_Face f; - FT_Stroker s, s2; - int i, pad, offset, advance, w, h, tw, th, c, trial = -2, rw = 0, rh = 0, ry = 0, x1 = INT_MAX, x2 = INT_MIN, y1 = INT_MAX, y2 = INT_MIN, w2 = 0, h2 = 0, sw = 0, sh = 0; - float outborder = 0, inborder = 0; - struct fontchar chars[256]; - struct fontchar *order[256]; - int numchars = 0, numtex = 0; - if(argc < 11) - fatal("Usage: cube2font infile outfile outborder[:inborder] pad offset advance charwidth charheight texwidth texheight [spacewidth spaceheight texdir]"); - sscanf(argv[3], "%f:%f", &outborder, &inborder); - pad = atoi(argv[4]); - offset = atoi(argv[5]); - advance = atoi(argv[6]); - w = atoi(argv[7]); - h = atoi(argv[8]); - tw = atoi(argv[9]); - th = atoi(argv[10]); - if(argc > 11) sw = atoi(argv[11]); - if(argc > 12) sh = atoi(argv[12]); - if(argc > 13) texdir = argv[13]; - if(FT_Init_FreeType(&l)) - fatal("cube2font: failed initing freetype"); - if(FT_New_Face(l, argv[1], 0, &f) || - FT_Set_Charmap(f, f->charmaps[0]) || - FT_Set_Pixel_Sizes(f, w, h) || - FT_Stroker_New(l, &s) || - FT_Stroker_New(l, &s2)) - fatal("cube2font: failed loading font %s", argv[1]); - if(outborder > 0) FT_Stroker_Set(s, (FT_Fixed)(outborder * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); - if(inborder > 0) FT_Stroker_Set(s2, (FT_Fixed)(inborder * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); - for(c = 0; c < 256; c++) if(iscubeprint(c)) { - - FT_Glyph p, p2; - FT_BitmapGlyph b, b2; - struct fontchar *dst = &chars[numchars]; - dst->code = c; - dst->uni = cube2uni(c); - if(FT_Load_Char(f, dst->uni, FT_LOAD_DEFAULT)) - fatal("cube2font: failed loading character %s", encodeutf8(dst->uni)); - FT_Get_Glyph(f->glyph, &p); - p2 = p; - if(outborder > 0) FT_Glyph_StrokeBorder(&p, s, 0, 0); - if(inborder > 0) FT_Glyph_StrokeBorder(&p2, s2, 1, 0); - FT_Glyph_To_Bitmap(&p, FT_RENDER_MODE_NORMAL, 0, 1); - if(inborder > 0 || outborder > 0) FT_Glyph_To_Bitmap(&p2, FT_RENDER_MODE_NORMAL, 0, 1); - else p2 = p; - b = (FT_BitmapGlyph)p; - b2 = (FT_BitmapGlyph)p2; - dst->tex = -1; - dst->x = INT_MIN; - dst->y = INT_MIN; - dst->offx = imin(b->left, b2->left); - dst->offy = imax(b->top, b2->top); - dst->offset = offset; - dst->advance = offset + ((p->advance.x+0xFFFF)>>16) + advance; - dst->w = imax(b->left + b->bitmap.width, b2->left + b2->bitmap.width) - dst->offx; - dst->h = dst->offy - imin(b->top - b->bitmap.rows, b2->top - b2->bitmap.rows); - dst->alpha = b; - dst->color = b2; - order[numchars++] = dst; - } - qsort(order, numchars, sizeof(order[0]), sortchars); - for(i = 0; i < numchars;) { - - struct fontchar *dst; - int j, k, trial0, prevscore, dstscore, fitscore; - for(trial0 = trial, prevscore = -1; (trial -= 2) >= trial0-512;) { - - int g, fw = rw, fh = rh, fy = ry, curscore = 0, reused = 0; - for(j = i; j < numchars; j++) { - - dst = order[j]; - if(dst->tex >= 0 || dst->tex <= trial) continue; - g = groupchar(dst->uni); - dstscore = scorechar(dst, pad, tw, th, fw, fh, fy); - for(k = j; k < numchars; k++) { - - struct fontchar *fit = order[k]; - if(fit->tex >= 0 || fit->tex <= trial) continue; - if(fit->tex >= trial0 && groupchar(fit->uni) != g) break; - fitscore = scorechar(fit, pad, tw, th, fw, fh, fy); - if(fitscore < dstscore || (fitscore == dstscore && fit->h > dst->h)) { - - dst = fit; - dstscore = fitscore; - } - } - if(fw + dst->w > tw) { - - fy += fh + pad; - fw = fh = 0; - } - if(fy + dst->h > th) { - - fy = fw = fh = 0; - if(curscore > 0) break; - } - if(dst->tex >= trial+1 && dst->tex <= trial+2) { dst->tex = trial; reused++; } - else dst->tex = trial; - fw += dst->w + pad; - fh = imax(fh, dst->h); - if(dst != order[j]) --j; - curscore++; - } - if(reused < prevscore || curscore <= prevscore) break; - prevscore = curscore; - } - for(; i < numchars; i++) { - - dst = order[i]; - if(dst->tex >= 0) continue; - dstscore = scorechar(dst, pad, tw, th, rw, rh, ry); - for(j = i; j < numchars; j++) { - - struct fontchar *fit = order[j]; - if(fit->tex < trial || fit->tex > trial+2) continue; - fitscore = scorechar(fit, pad, tw, th, rw, rh, ry); - if(fitscore < dstscore || (fitscore == dstscore && fit->h > dst->h)) { - - dst = fit; - dstscore = fitscore; - } - } - if(dst->tex < trial || dst->tex > trial+2) break; - if(rw + dst->w > tw) { - - ry += rh + pad; - rw = rh = 0; - } - if(ry + dst->h > th) { - - ry = rw = rh = 0; - numtex++; - } - dst->tex = numtex; - dst->x = rw; - dst->y = ry; - rw += dst->w + pad; - rh = imax(rh, dst->h); - y1 = imin(y1, dst->offy - dst->h); - y2 = imax(y2, dst->offy); - x1 = imin(x1, dst->offx); - x2 = imax(x2, dst->offx + dst->w); - w2 = imax(w2, dst->w); - h2 = imax(h2, dst->h); - if(dst != order[i]) --i; - } - } - if(rh > 0) numtex++; - if(sh <= 0) sh = y2 - y1; - if(sw <= 0) sw = sh/3; - writetexs(argv[2], chars, numchars, numtex, tw, th); - writecfg(argv[2], chars, numchars, x1, y1, x2, y2, sw, sh, argc, argv); - for(i = 0; i < numchars; i++) { - if(chars[i].alpha != chars[i].color) FT_Done_Glyph((FT_Glyph)chars[i].alpha); - FT_Done_Glyph((FT_Glyph)chars[i].color); - } - FT_Stroker_Done(s); - FT_Stroker_Done(s2); - FT_Done_FreeType(l); - printf("cube2font: (%d, %d) .. (%d, %d) = (%d, %d) / (%d, %d), %d texs\n", x1, y1, x2, y2, x2 - x1, y2 - y1, w2, h2, numtex); - return EXIT_SUCCESS; -} - diff --git a/src/shared/ents.h b/src/shared/ents.h index fece7bf..e47f4c7 100644 --- a/src/shared/ents.h +++ b/src/shared/ents.h @@ -21,7 +21,6 @@ struct entitylight { enum { EF_NOVIS = 1<<0, - EF_NOSHADOW = 1<<1, EF_NOCOLLIDE = 1<<2, EF_ANIM = 1<<3, EF_OCTA = 1<<4, @@ -140,7 +139,6 @@ static const char * const animnames[] = { #define ANIM_FULLBRIGHT (1<<24) #define ANIM_REUSE (1<<25) #define ANIM_NORENDER (1<<26) -#define ANIM_RAGDOLL (1<<27) #define ANIM_SETSPEED (1<<28) #define ANIM_NOPITCH (1<<29) #define ANIM_GHOST (1<<30) @@ -166,25 +164,18 @@ struct animinterpinfo { // used for animation blending of animated characters { #define MAXANIMPARTS 3 struct occludequery; -struct ragdolldata; struct dynent : physent { // animated characters, or characters that can receive input { bool k_left, k_right, k_up, k_down; // see input code entitylight light; animinterpinfo animinterp[MAXANIMPARTS]; - ragdolldata *ragdoll; occludequery *query; int lastrendered; uchar occluded; - dynent() : ragdoll(NULL), query(NULL), lastrendered(0), occluded(0) { + dynent() : query(NULL), lastrendered(0), occluded(0) { reset(); } - ~dynent() { -#ifndef STANDALONE - extern void cleanragdoll(dynent *d); - if(ragdoll) cleanragdoll(this); -#endif - } + ~dynent() { } void stopmoving() { k_left = k_right = k_up = k_down = jumping = false; move = strafe = 0; diff --git a/src/shared/glemu.cpp b/src/shared/glemu.cpp index c728b9f..5a5b3df 100644 --- a/src/shared/glemu.cpp +++ b/src/shared/glemu.cpp @@ -69,7 +69,9 @@ namespace gle { if(offset >= MAXQUADS) return; count = MAXQUADS - offset; } - glDrawRangeElements_(GL_TRIANGLES, offset*4, (offset + count)*4-1, count*6, GL_UNSIGNED_SHORT, (ushort *)0 + offset*6); + //~glDrawRangeElements_(GL_TRIANGLES, offset*4, (offset + count)*4-1, count*6, GL_UNSIGNED_SHORT, (ushort*)0+offset*6); + glDrawRangeElements_(GL_TRIANGLES, offset*4, (offset + count)*4-1, count*6, GL_UNSIGNED_SHORT, (const void *)((unsigned long int) (offset*6))); // Fuck you... + //~glDrawRangeElements_(GL_TRIANGLES, offset*4, (offset + count)*4-1, count*6, GL_UNSIGNED_SHORT, (const void *)(offset*6)); } void defattrib(int type, int size, int format) { if(type == ATTRIB_VERTEX) { @@ -217,7 +219,8 @@ namespace gle { else glBufferSubData_(GL_ARRAY_BUFFER, vbooffset, attribbuf.length(), attribbuf.getbuf()); } else glUnmapBuffer_(GL_ARRAY_BUFFER); - buf = (uchar *)0 + vbooffset; + buf = (uchar*)((unsigned long int)vbooffset); /// Fucking piece of shit... + //~buf = (const void*)vbooffset; if(vertexsize == lastvertexsize && buf >= lastbuf) { start = int(buf - lastbuf)/vertexsize; if(primtype == GL_QUADS && (start%4 || start + attribbuf.length()/vertexsize >= 4*MAXQUADS)) diff --git a/src/shared/iengine.h b/src/shared/iengine.h index 58698ab..ce29912 100644 --- a/src/shared/iengine.h +++ b/src/shared/iengine.h @@ -368,7 +368,7 @@ extern void stopsounds(); extern void initsound(); // rendermodel -enum { MDL_CULL_VFC = 1<<0, MDL_CULL_DIST = 1<<1, MDL_CULL_OCCLUDED = 1<<2, MDL_CULL_QUERY = 1<<3, MDL_SHADOW = 1<<4, MDL_DYNSHADOW = 1<<5, MDL_LIGHT = 1<<6, MDL_DYNLIGHT = 1<<7, MDL_FULLBRIGHT = 1<<8, MDL_NORENDER = 1<<9, MDL_LIGHT_FAST = 1<<10, MDL_HUD = 1<<11, MDL_GHOST = 1<<12 }; +enum { MDL_CULL_VFC = 1<<0, MDL_CULL_DIST = 1<<1, MDL_CULL_OCCLUDED = 1<<2, MDL_CULL_QUERY = 1<<3, MDL_LIGHT = 1<<6, MDL_DYNLIGHT = 1<<7, MDL_FULLBRIGHT = 1<<8, MDL_NORENDER = 1<<9, MDL_LIGHT_FAST = 1<<10, MDL_HUD = 1<<11, MDL_GHOST = 1<<12 }; struct model; struct modelattach { @@ -384,9 +384,7 @@ struct modelattach { extern void startmodelbatches(); extern void endmodelbatches(); extern void rendermodel(entitylight *light, const char *mdl, int anim, const vec &o, float yaw = 0, float pitch = 0, int cull = MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED | MDL_LIGHT, dynent *d = NULL, modelattach *a = NULL, int basetime = 0, int basetime2 = 0, float trans = 1); -extern void abovemodel(vec &o, const char *mdl); -extern void rendershadow(dynent *d); -extern void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade = 1, bool ragdoll = false); +extern void renderclient(dynent *d, const char *mdlname, modelattach *attachments, int hold, int attack, int attackdelay, int lastaction, int lastpain, float fade = 1); extern void interpolateorientation(dynent *d, float &interpyaw, float &interppitch); extern void setbbfrommodel(dynent *d, const char *mdl); extern const char *mapmodelname(int i); @@ -394,11 +392,6 @@ extern model *loadmodel(const char *name, int i = -1, bool msg = false); extern void preloadmodel(const char *name); extern void flushpreloadedmodels(bool msg = true); -// ragdoll - -extern void moveragdoll(dynent *d); -extern void cleanragdoll(dynent *d); - // server #define MAXCLIENTS 128 // DO NOT set this any higher #define MAXTRANS 5000 // max amount of data to swallow in 1 go diff --git a/src/shared/tools.h b/src/shared/tools.h index 44be57d..94bf23a 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -782,35 +782,6 @@ template struct hashtable : hashbase, hashtabl #define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(void *ec = (ht).chains[i]; ec;) { k &e = (ht).enumkey(ec); t &f = (ht).enumdata(ec); ec = (ht).enumnext(ec); b; } #define enumerate(ht,t,e,b) loopi((ht).size) for(void *ec = (ht).chains[i]; ec;) { t &e = (ht).enumdata(ec); ec = (ht).enumnext(ec); b; } -struct unionfind { - struct ufval { - int rank, next; - ufval() : rank(0), next(-1) {} - }; - vector ufvals; - int find(int k) { - if(k>=ufvals.length()) return k; - while(ufvals[k].next>=0) k = ufvals[k].next; - return k; - } - int compressfind(int k) { - if(ufvals[k].next<0) return k; - return ufvals[k].next = compressfind(ufvals[k].next); - } - void unite (int x, int y) { - while(ufvals.length() <= max(x, y)) ufvals.add(); - x = compressfind(x); - y = compressfind(y); - if(x==y) return; - ufval &xval = ufvals[x], &yval = ufvals[y]; - if(xval.rank < yval.rank) xval.next = y; - else { - yval.next = x; - if(xval.rank==yval.rank) yval.rank++; - } - } -}; - template struct queue { int head, tail, len; T data[SIZE];