2005-08-26 22:49:36 +00:00
# include "quakedef.h"
2007-05-25 22:16:29 +00:00
2012-04-09 19:12:12 +00:00
# ifdef TERRAIN
2005-08-26 22:49:36 +00:00
# include "glquake.h"
2009-11-04 21:16:50 +00:00
# include "shader.h"
2005-08-26 22:49:36 +00:00
2012-04-09 19:12:12 +00:00
# include "pr_common.h"
2012-07-21 04:43:31 +00:00
//#define STRICTEDGES //strict (ugly) grid
# define TERRAINTHICKNESS 16
2013-10-29 17:38:22 +00:00
# define TERRAINACTIVESECTIONS 3000
2012-07-21 04:43:31 +00:00
2012-11-27 03:23:19 +00:00
/*
a note on networking :
By default terrain is NOT networked . This means content is loaded without networking delays .
If you wish to edit the terrain collaboratively , you can enable the mod_terrain_networked cvar .
When set , changes on the server will notify clients that a section has changed , and the client will reload it as needed .
Changes on the client WILL NOT notify the server , and will get clobbered if the change is also made on the server .
This means for editing purposes , you MUST funnel it via ssqc with your own permission checks .
It also means for explosions and local stuff , the server will merely restate changes from impacts if you do them early . BUT DO NOT CALL THE EDIT FUNCTION IF THE SERVER HAS ALREADY APPLIED THE CHANGE .
*/
cvar_t mod_terrain_networked = CVARD ( " mod_terrain_networked " , " 0 " , " Terrain edits are networked. Clients will download sections on demand, and servers will notify clients of changes. " ) ;
2013-10-29 17:38:22 +00:00
cvar_t mod_terrain_defaulttexture = CVARD ( " mod_terrain_defaulttexture " , " " , " Newly created terrain tiles will use this texture. This should generally be updated by the terrain editor. " ) ;
2013-11-21 23:02:28 +00:00
cvar_t mod_terrain_savever = CVARD ( " mod_terrain_savever " , " " , " Which terrain section version to write if terrain was edited. " ) ;
2012-11-27 03:23:19 +00:00
2013-10-29 17:38:22 +00:00
/*
terminology :
tile :
a single grid tile of 2 * 2 height samples .
iterrated for collisions but otherwise unused .
section :
16 * 16 tiles , with a single texture spread over them .
samples have an overlap with the neighbouring section ( so 17 * 17 height samples ) . texture samples do not quite match height frequency ( 63 * 63 vs 16 * 16 ) .
smallest unit for culling .
block :
16 * 16 sections . forms a single disk file . used only to avoid 16777216 files in a single directory , instead getting 65536 files for a single fully populated map . . . much smaller . . .
each block file is about 4 mb each . larger can be detrimental to automatic downloads .
cluster :
64 * 64 sections
internal concept to avoid a single pointer array of 16 million entries per terrain .
*/
2005-08-26 22:49:36 +00:00
2012-09-30 05:52:03 +00:00
int Surf_NewLightmaps ( int count , int width , int height , qboolean deluxe ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
# define MAXCLUSTERS 64
# define MAXSECTIONS 64 //this many sections within each cluster in each direction
2012-07-22 02:56:22 +00:00
# define SECTHEIGHTSIZE 17 //this many height samples per section
2013-10-29 17:38:22 +00:00
# define SECTTEXSIZE 64 //this many texture samples per section
# define SECTIONSPERBLOCK 16
2005-08-26 22:49:36 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
//each section is this many sections higher in world space, to keep the middle centered at '0 0'
2013-10-29 17:38:22 +00:00
# define CHUNKBIAS (MAXCLUSTERS*MAXSECTIONS / 2)
# define CHUNKLIMIT (MAXCLUSTERS*MAXSECTIONS)
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
# define LMCHUNKS 8 //(LMBLOCK_WIDTH/SECTTEXSIZE)
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
# define HMLMSTRIDE (LMCHUNKS*SECTTEXSIZE)
# define SECTION_MAGIC (*(int*)"HMMS")
2013-11-21 23:02:28 +00:00
# define SECTION_VER_DEFAULT 1
2012-07-22 02:56:22 +00:00
/*simple version history:
ver = 0
SECTHEIGHTSIZE = 16
2013-10-29 17:38:22 +00:00
ver = 1
SECTHEIGHTSIZE = 17 ( oops , makes holes more usable )
2013-11-21 23:02:28 +00:00
( holes in this format are no longer supported )
ver = 2
uses deltas instead of absolute values
variable length image names
2012-07-22 02:56:22 +00:00
*/
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
# define TGS_NOLOAD 0
2014-10-05 20:04:11 +00:00
# define TGS_LAZYLOAD 1 //see if its available, if not, queue it. don't create too much work at once. peace man
# define TGS_TRYLOAD 2 //try and get it, but don't stress if its not available yet
# define TGS_WAITLOAD 4 //load it, wait for it if needed.
# define TGS_ANYSTATE 8 //returns the section regardless of its current state, even if its loading.
# define TGS_NODOWNLOAD 16 //don't queue it for download
# define TGS_NORENDER 32 //don't upload any textures or whatever
# define TGS_DEFAULTONFAIL 64 //if it failed to load, generate a default anyway
2013-10-29 17:38:22 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
enum
{
2012-07-20 01:46:05 +00:00
//these flags can be found on disk
2013-11-21 23:02:28 +00:00
TSF_HASWATER_V0 = 1u < < 0 , //no longer flagged.
2012-08-04 11:28:39 +00:00
TSF_HASCOLOURS = 1u < < 1 ,
2013-11-21 23:02:28 +00:00
TSF_HASHEIGHTS = 1u < < 2 ,
TSF_HASSHADOW = 1u < < 3 ,
2012-07-20 01:46:05 +00:00
2013-10-29 17:38:22 +00:00
//these flags are found only on disk
TSF_COMPRESSED = 1u < < 31 ,
2012-07-20 01:46:05 +00:00
//these flags should not be found on disk
2012-11-29 13:37:48 +00:00
TSF_NOTIFY = 1u < < 28 , //modified on server, waiting for clients to be told about the change.
2012-07-20 01:46:05 +00:00
TSF_RELIGHT = 1u < < 29 , //height edited, needs relighting.
TSF_DIRTY = 1u < < 30 , //its heightmap has changed, the mesh needs rebuilding
TSF_EDITED = 1u < < 31 //says it needs to be written if saved
2014-10-05 20:04:11 +00:00
# define TSF_INTERNAL (TSF_RELIGHT|TSF_DIRTY|TSF_EDITED|TSF_NOTIFY)
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
} ;
2013-11-21 23:02:28 +00:00
enum
{
TMF_SCALE = 1u < < 0 ,
//what else do we want? alpha? colormod perhaps?
} ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2012-07-20 01:46:05 +00:00
typedef struct
{
int size ;
vec3_t axisorg [ 4 ] ;
float scale ;
int reserved3 ;
int reserved2 ;
int reserved1 ;
//char modelname[1+];
2014-05-10 13:42:13 +00:00
} dsmesh_v1_t ;
2013-10-29 17:38:22 +00:00
2012-04-09 19:12:12 +00:00
typedef struct
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
unsigned int flags ;
2013-11-21 23:02:28 +00:00
char texname [ 4 ] [ 32 ] ;
unsigned int texmap [ SECTTEXSIZE ] [ SECTTEXSIZE ] ;
2012-04-09 19:12:12 +00:00
float heights [ SECTHEIGHTSIZE * SECTHEIGHTSIZE ] ;
2013-11-21 23:02:28 +00:00
unsigned short holes ;
2013-10-29 17:38:22 +00:00
unsigned short reserved0 ;
2013-11-21 23:02:28 +00:00
float waterheight ;
2012-07-14 17:25:21 +00:00
float minh ;
float maxh ;
2012-08-04 11:28:39 +00:00
int ents_num ;
int reserved1 ;
int reserved4 ;
2012-07-20 01:46:05 +00:00
int reserved3 ;
int reserved2 ;
2013-10-29 17:38:22 +00:00
} dsection_v1_t ;
//file header for a single section
typedef struct
{
int magic ;
int ver ;
2012-04-09 19:12:12 +00:00
} dsection_t ;
2012-08-04 11:28:39 +00:00
2013-10-29 17:38:22 +00:00
//file header for a block of sections.
//(because 16777216 files in a single directory is a bad plan. windows really doesn't like it.)
typedef struct
{
//a block is a X*Y group of sections
//if offset==0, the section isn't present.
//the data length of the section preceeds the actual data.
int magic ;
int ver ;
unsigned int offset [ SECTIONSPERBLOCK * SECTIONSPERBLOCK ] ;
} dblock_t ;
2012-08-04 11:28:39 +00:00
typedef struct hmpolyset_s
{
struct hmpolyset_s * next ;
shader_t * shader ;
mesh_t mesh ;
mesh_t * amesh ;
vbo_t vbo ;
} hmpolyset_t ;
2013-11-21 23:02:28 +00:00
struct hmwater_s
{
struct hmwater_s * next ;
unsigned int contentmask ;
2014-02-07 08:38:40 +00:00
qboolean simple ; //no holes, one height
2013-11-21 23:02:28 +00:00
float minheight ;
float maxheight ;
2014-10-05 20:04:11 +00:00
char shadername [ MAX_QPATH ] ;
2013-11-21 23:02:28 +00:00
shader_t * shader ;
qbyte holes [ 8 ] ;
float heights [ 9 * 9 ] ;
} ;
2014-10-05 20:04:11 +00:00
enum
{
TSLS_NOTLOADED ,
TSLS_LOADING1 , //section is queued to the worker (and may be loaded as part of another section)
TSLS_LOADING2 , //waiting for main thread to finish, worker will ignore
TSLS_LOADED ,
TSLS_FAILED
} ;
2012-04-09 19:12:12 +00:00
typedef struct
{
2012-07-21 08:06:07 +00:00
link_t recycle ;
int sx , sy ;
2014-10-05 20:04:11 +00:00
int loadstate ;
2012-04-09 19:12:12 +00:00
float heights [ SECTHEIGHTSIZE * SECTHEIGHTSIZE ] ;
2013-11-21 23:02:28 +00:00
unsigned char holes [ 8 ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
unsigned int flags ;
2013-11-21 23:02:28 +00:00
float maxh_cull ; //includes water+mesh heights
2012-07-14 17:25:21 +00:00
float minh , maxh ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
struct heightmap_s * hmmod ;
2013-11-21 23:02:28 +00:00
struct hmwater_s * water ;
2014-05-10 13:42:13 +00:00
size_t traceseq ;
2012-04-09 19:12:12 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
pvscache_t pvscache ;
vec4_t colours [ SECTHEIGHTSIZE * SECTHEIGHTSIZE ] ; //FIXME: make bytes
char texname [ 4 ] [ MAX_QPATH ] ;
2012-04-09 19:12:12 +00:00
int lightmap ;
int lmx , lmy ;
texnums_t textures ;
vbo_t vbo ;
mesh_t mesh ;
mesh_t * amesh ;
2012-07-20 01:46:05 +00:00
2012-08-04 11:28:39 +00:00
hmpolyset_t * polys ;
2012-04-09 19:12:12 +00:00
# endif
2014-05-10 13:42:13 +00:00
int numents ;
int maxents ;
struct hmentity_s * * ents ;
2012-04-09 19:12:12 +00:00
} hmsection_t ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
typedef struct
{
hmsection_t * section [ MAXSECTIONS * MAXSECTIONS ] ;
} hmcluster_t ;
2015-04-14 23:12:17 +00:00
# ifndef SERVERONLY
typedef struct brushbatch_s
2015-01-07 13:34:05 +00:00
{
vbo_t vbo ;
mesh_t mesh ;
mesh_t * pmesh ;
2015-04-14 23:12:17 +00:00
int lightmap ;
struct brushbatch_s * next ;
avec4_t align ; //meh, cos we can.
} brushbatch_t ;
# endif
typedef struct brushtex_s
{
char shadername [ MAX_QPATH ] ;
# ifndef SERVERONLY
shader_t * shader ;
//for rebuild performance
int firstlm ;
int lmcount ;
struct brushbatch_s * batches ;
# endif
2015-01-07 13:34:05 +00:00
qboolean rebuild ;
struct brushtex_s * next ;
} brushtex_t ;
2015-04-14 23:12:17 +00:00
2015-01-07 13:34:05 +00:00
typedef struct
{
2015-04-14 23:12:17 +00:00
unsigned int contents ;
unsigned int id ; //networked/gamecode id.
unsigned int numplanes ;
qboolean selected ; //different shader stuff
vec4_t * planes ;
vec3_t mins , maxs ; //for optimisation and stuff
2015-01-07 13:34:05 +00:00
struct brushface_s
{
brushtex_t * tex ;
2015-04-14 23:12:17 +00:00
vec4_t stdir [ 2 ] ;
vec3_t * points ;
unsigned short numpoints ;
unsigned short lmscale ;
int lightmap ;
unsigned short lmbase [ 2 ] ; //min st coord of the lightmap atlas, in texels.
unsigned int relight : 1 ;
unsigned int relit : 1 ;
int lmbias [ 2 ] ;
unsigned short lmextents [ 2 ] ;
qbyte * lightdata ;
2015-01-07 13:34:05 +00:00
} * faces ;
} brushes_t ;
2012-07-21 08:06:07 +00:00
typedef struct heightmap_s
{
2005-08-26 22:49:36 +00:00
char path [ MAX_QPATH ] ;
2014-10-05 20:04:11 +00:00
char skyname [ MAX_QPATH ] ;
char groundshadername [ MAX_QPATH ] ;
2014-05-10 13:42:13 +00:00
char defaultwatershader [ MAX_QPATH ] ; //typically the name of the ocean or whatever.
float defaultwaterheight ;
float defaultgroundheight ;
char defaultgroundtexture [ MAX_QPATH ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
int firstsegx , firstsegy ;
int maxsegx , maxsegy ; //tex/cull sections
2012-04-09 19:12:12 +00:00
float sectionsize ; //each section is this big, in world coords
2013-10-29 17:38:22 +00:00
hmcluster_t * cluster [ MAXCLUSTERS * MAXCLUSTERS ] ;
2011-05-20 04:10:46 +00:00
shader_t * skyshader ;
shader_t * shader ;
mesh_t skymesh ;
mesh_t * askymesh ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
unsigned int exteriorcontents ;
2014-10-05 20:04:11 +00:00
unsigned int loadingsections ; //number of sections currently being loaded. avoid loading extras while non-zero.
2014-05-10 13:42:13 +00:00
size_t traceseq ;
size_t drawnframe ;
enum
{
DGT_SOLID , //invalid/new areas should be completely solid until painted.
DGT_HOLES , //invalid/new sections should be non-solid+invisible
DGT_FLAT //invalid/new sections should be filled with ground by default
} defaultgroundtype ;
2013-10-29 17:38:22 +00:00
enum
{
HMM_TERRAIN ,
HMM_BLOCKS
} mode ;
2012-08-04 11:28:39 +00:00
int tilecount [ 2 ] ;
int tilepixcount [ 2 ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2012-07-21 08:06:07 +00:00
int activesections ;
2013-10-29 17:38:22 +00:00
link_t recycle ; //section list in lru order
// link_t collected; //memory that may be reused, to avoid excess reallocs.
2012-07-21 08:06:07 +00:00
2014-05-10 13:42:13 +00:00
struct hmentity_s
{
size_t drawnframe ; //don't add it to the scene multiple times.
size_t traceseq ; //don't trace through this entity multiple times if its in different sections.
int refs ; //entity is free/reusable when its no longer referenced by any sections
entity_t ent ;
struct hmentity_s * next ; //used for freeing/allocating an entity
} * entities ;
2014-10-05 20:04:11 +00:00
void * entitylock ; //lock this if you're going to read/write entities of any kind.
2014-05-10 13:42:13 +00:00
2012-07-14 17:25:21 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
unsigned int numusedlmsects ; //to track leaks and stats
unsigned int numunusedlmsects ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
struct lmsect_s
{
struct lmsect_s * next ;
int lm , x , y ;
} * unusedlmsects ;
2012-07-14 17:25:21 +00:00
# endif
2012-07-20 01:46:05 +00:00
# ifndef SERVERONLY
//I'm putting this here because we might have some quite expensive lighting routines going on
//and that'll make editing the terrain jerky as fook, so relighting it a few texels at a time will help maintain a framerate while editing
hmsection_t * relight ;
unsigned int relightidx ;
vec2_t relightmin ;
# endif
2015-01-07 13:34:05 +00:00
2015-06-12 14:44:50 +00:00
char * texmask ; //for editing - visually masks off the areas which CANNOT accept this texture
2015-04-14 23:12:17 +00:00
struct relight_ctx_s * relightcontext ;
struct llightinfo_s * lightthreadmem ;
qboolean inheritedlightthreadmem ;
qboolean recalculatebrushlighting ;
lmalloc_t brushlmalloc ;
float brushlmscale ;
unsigned int * brushlmremaps ;
unsigned int brushmaxlms ;
2015-01-07 13:34:05 +00:00
brushtex_t * brushtextures ;
brushes_t * wbrushes ;
2015-04-14 23:12:17 +00:00
unsigned int numbrushes ;
unsigned int brushidseq ;
2005-08-26 22:49:36 +00:00
} heightmap_t ;
2013-05-11 05:03:07 +00:00
# ifndef SERVERONLY
2012-07-20 01:46:05 +00:00
static void ted_dorelight ( heightmap_t * hm ) ;
2013-05-11 05:03:07 +00:00
# endif
2013-03-31 04:21:08 +00:00
static qboolean Terr_Collect ( heightmap_t * hm ) ;
2013-10-29 17:38:22 +00:00
static hmsection_t * Terr_GetSection ( heightmap_t * hm , int x , int y , unsigned int flags ) ;
2014-10-05 20:04:11 +00:00
static void Terr_LoadSectionWorker ( void * ctx , void * data , size_t a , size_t b ) ;
static void Terr_WorkerLoadedSectionLightmap ( void * ctx , void * data , size_t a , size_t b ) ;
static void Terr_WorkerLoadedSection ( void * ctx , void * data , size_t a , size_t b ) ;
static void Terr_WorkerFailedSection ( void * ctx , void * data , size_t a , size_t b ) ;
2012-07-20 01:46:05 +00:00
2015-04-14 23:12:17 +00:00
static void Terr_Brush_DeleteIdx ( heightmap_t * hm , size_t idx ) ;
static void Terr_Brush_Draw ( heightmap_t * hm , batch_t * * batches , entity_t * e ) ;
2015-01-07 13:34:05 +00:00
2012-07-21 04:43:31 +00:00
# ifndef SERVERONLY
static texid_t Terr_LoadTexture ( char * name )
{
extern texid_t missing_texture ;
texid_t id ;
if ( * name )
{
id = R_LoadHiResTexture ( name , NULL , 0 ) ;
if ( ! TEXVALID ( id ) )
{
id = missing_texture ;
Con_Printf ( " Unable to load texture %s \n " , name ) ;
}
}
else
id = missing_texture ;
return id ;
}
# endif
2012-07-20 01:46:05 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
static void Terr_LoadSectionTextures ( hmsection_t * s )
2012-04-09 19:12:12 +00:00
{
# ifndef SERVERONLY
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
extern texid_t missing_texture ;
2014-10-05 20:04:11 +00:00
struct hmwater_s * w ;
2014-03-30 08:55:06 +00:00
if ( isDedicated )
return ;
2012-04-09 19:12:12 +00:00
//CL_CheckOrEnqueDownloadFile(s->texname[0], NULL, 0);
//CL_CheckOrEnqueDownloadFile(s->texname[1], NULL, 0);
//CL_CheckOrEnqueDownloadFile(s->texname[2], NULL, 0);
//CL_CheckOrEnqueDownloadFile(s->texname[3], NULL, 0);
2013-10-29 17:38:22 +00:00
switch ( s - > hmmod - > mode )
2012-08-04 11:28:39 +00:00
{
2013-10-29 17:38:22 +00:00
case HMM_BLOCKS :
2012-08-04 11:28:39 +00:00
s - > textures . base = Terr_LoadTexture ( va ( " maps/%s/atlas.tga " , s - > hmmod - > path ) ) ;
s - > textures . fullbright = Terr_LoadTexture ( va ( " maps/%s/atlas_luma.tga " , s - > hmmod - > path ) ) ;
s - > textures . bump = Terr_LoadTexture ( va ( " maps/%s/atlas_norm.tga " , s - > hmmod - > path ) ) ;
s - > textures . specular = Terr_LoadTexture ( va ( " maps/%s/atlas_spec.tga " , s - > hmmod - > path ) ) ;
s - > textures . upperoverlay = missing_texture ;
s - > textures . loweroverlay = missing_texture ;
2013-10-29 17:38:22 +00:00
break ;
case HMM_TERRAIN :
2012-08-04 11:28:39 +00:00
s - > textures . base = Terr_LoadTexture ( s - > texname [ 0 ] ) ;
s - > textures . upperoverlay = Terr_LoadTexture ( s - > texname [ 1 ] ) ;
s - > textures . loweroverlay = Terr_LoadTexture ( s - > texname [ 2 ] ) ;
s - > textures . fullbright = Terr_LoadTexture ( s - > texname [ 3 ] ) ;
s - > textures . bump = * s - > texname [ 0 ] ? R_LoadHiResTexture ( va ( " %s_norm " , s - > texname [ 0 ] ) , NULL , 0 ) : r_nulltex ;
s - > textures . specular = * s - > texname [ 0 ] ? R_LoadHiResTexture ( va ( " %s_spec " , s - > texname [ 0 ] ) , NULL , 0 ) : r_nulltex ;
2013-10-29 17:38:22 +00:00
break ;
2012-08-04 11:28:39 +00:00
}
2014-10-05 20:04:11 +00:00
for ( w = s - > water ; w ; w = w - > next )
{
w - > shader = R_RegisterCustom ( w - > shadername , SUF_NONE , Shader_DefaultWaterShader , NULL ) ;
R_BuildDefaultTexnums ( NULL , w - > shader ) ; //this might get expensive. hideously so.
}
2012-04-09 19:12:12 +00:00
# endif
}
2012-07-14 17:25:21 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
static qboolean Terr_InitLightmap ( hmsection_t * s , qboolean initialise )
2012-04-09 19:12:12 +00:00
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
heightmap_t * hm = s - > hmmod ;
2013-10-29 17:38:22 +00:00
if ( s - > lightmap < 0 )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
2013-10-29 17:38:22 +00:00
struct lmsect_s * lms ;
if ( ! hm - > unusedlmsects )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
2013-10-29 17:38:22 +00:00
int lm ;
int i ;
lm = Surf_NewLightmaps ( 1 , SECTTEXSIZE * LMCHUNKS , SECTTEXSIZE * LMCHUNKS , false ) ;
for ( i = 0 ; i < LMCHUNKS * LMCHUNKS ; i + + )
{
lms = BZ_Malloc ( sizeof ( * lms ) ) ;
lms - > lm = lm ;
lms - > x = ( i & ( LMCHUNKS - 1 ) ) * SECTTEXSIZE ;
lms - > y = ( i / LMCHUNKS ) * SECTTEXSIZE ;
lms - > next = hm - > unusedlmsects ;
hm - > unusedlmsects = lms ;
hm - > numunusedlmsects + + ;
}
}
lms = hm - > unusedlmsects ;
hm - > unusedlmsects = lms - > next ;
s - > lightmap = lms - > lm ;
s - > lmx = lms - > x ;
s - > lmy = lms - > y ;
hm - > numunusedlmsects - - ;
hm - > numusedlmsects + + ;
Z_Free ( lms ) ;
2015-06-12 14:44:50 +00:00
initialise = true ;
2013-10-29 17:38:22 +00:00
}
if ( initialise & & s - > lightmap > = 0 )
{
int x , y ;
unsigned char * lm ;
lm = lightmap [ s - > lightmap ] - > lightmaps ;
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
for ( x = 0 ; x < SECTTEXSIZE ; x + + )
{
lm [ x * 4 + 0 ] = 0 ;
lm [ x * 4 + 1 ] = 0 ;
lm [ x * 4 + 2 ] = 0 ;
lm [ x * 4 + 3 ] = 255 ;
}
lm + = ( HMLMSTRIDE ) * lightmap_bytes ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
}
2013-10-29 17:38:22 +00:00
if ( s - > lightmap > = 0 )
{
lightmap [ s - > lightmap ] - > modified = true ;
lightmap [ s - > lightmap ] - > rectchange . l = 0 ;
lightmap [ s - > lightmap ] - > rectchange . t = 0 ;
lightmap [ s - > lightmap ] - > rectchange . w = HMLMSTRIDE ;
lightmap [ s - > lightmap ] - > rectchange . h = HMLMSTRIDE ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
return s - > lightmap > = 0 ;
2012-04-09 19:12:12 +00:00
}
2012-07-14 17:25:21 +00:00
# endif
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2014-10-05 20:04:11 +00:00
static char * genextendedhex ( int n , char * buf )
2013-10-29 17:38:22 +00:00
{
char * ret ;
static char nibble [ 16 ] = " 0123456789abcdef " ;
unsigned int m ;
int i ;
for ( i = 7 ; i > = 1 ; i - - ) //>=1 ensures at least two nibbles appear.
{
m = 0xfffffff8 < < ( i * 4 ) ;
if ( ( n & m ) ! = m & & ( n & m ) ! = 0 )
break ;
}
ret = buf ;
for ( i + + ; i > = 0 ; i - - )
* buf + + = nibble [ ( n > > i * 4 ) & 0xf ] ;
* buf + + = 0 ;
return ret ;
}
2014-10-05 20:04:11 +00:00
static char * Terr_DiskBlockName ( heightmap_t * hm , int sx , int sy , char * out , size_t outsize )
2013-10-29 17:38:22 +00:00
{
char xpart [ 9 ] ;
char ypart [ 9 ] ;
//using a naming scheme centered around 0 means we can gracefully expand the map away from 0,0
sx - = CHUNKBIAS ;
sy - = CHUNKBIAS ;
//wrap cleanly
sx & = CHUNKLIMIT - 1 ;
sy & = CHUNKLIMIT - 1 ;
sx / = SECTIONSPERBLOCK ;
sy / = SECTIONSPERBLOCK ;
2013-11-21 23:02:28 +00:00
if ( sx > = CHUNKBIAS / SECTIONSPERBLOCK )
sx | = 0xffffff00 ;
if ( sy > = CHUNKBIAS / SECTIONSPERBLOCK )
sy | = 0xffffff00 ;
2014-10-05 20:04:11 +00:00
Q_snprintfz ( out , outsize , " maps/%s/block_%s_%s.hms " , hm - > path , genextendedhex ( sx , xpart ) , genextendedhex ( sy , ypart ) ) ;
return out ;
2013-10-29 17:38:22 +00:00
}
2014-10-05 20:04:11 +00:00
static char * Terr_DiskSectionName ( heightmap_t * hm , int sx , int sy , char * out , size_t outsize )
2012-04-09 19:12:12 +00:00
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
sx - = CHUNKBIAS ;
sy - = CHUNKBIAS ;
//wrap cleanly
sx & = CHUNKLIMIT - 1 ;
sy & = CHUNKLIMIT - 1 ;
2014-10-05 20:04:11 +00:00
Q_snprintfz ( out , outsize , " maps/%s/sect_%03x_%03x.hms " , hm - > path , sx , sy ) ;
return out ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2014-03-30 08:55:06 +00:00
# ifndef SERVERONLY
2012-11-27 03:23:19 +00:00
static char * Terr_TempDiskSectionName ( heightmap_t * hm , int sx , int sy )
{
sx - = CHUNKBIAS ;
sy - = CHUNKBIAS ;
//wrap cleanly
sx & = CHUNKLIMIT - 1 ;
sy & = CHUNKLIMIT - 1 ;
return va ( " temp/%s/sect_%03x_%03x.hms " , hm - > path , sx , sy ) ;
}
2014-03-30 08:55:06 +00:00
# endif
2012-11-29 13:37:48 +00:00
static int dehex_e ( int i , qboolean * error )
{
if ( i > = ' 0 ' & & i < = ' 9 ' )
return ( i - ' 0 ' ) ;
else if ( i > = ' A ' & & i < = ' F ' )
return ( i - ' A ' + 10 ) ;
else if ( i > = ' a ' & & i < = ' f ' )
return ( i - ' a ' + 10 ) ;
else
* error = true ;
return 0 ;
}
static qboolean Terr_IsSectionFName ( heightmap_t * hm , char * fname , int * sx , int * sy )
{
int l ;
qboolean error = false ;
* sx = 0xdeafbeef ; //something clearly invalid
* sy = 0xdeafbeef ;
//not this model...
if ( ! hm )
return false ;
//expect the first 5 chars to be maps/ or temp/
fname + = 5 ;
l = strlen ( hm - > path ) ;
if ( strncmp ( fname , hm - > path , l ) | | fname [ l ] ! = ' / ' )
return false ;
fname + = l + 1 ;
//fname now has a fixed length.
if ( strlen ( fname ) ! = 16 )
return false ;
if ( strncmp ( fname , " sect_ " , 5 ) | | fname [ 8 ] ! = ' _ ' | | ( strcmp ( fname + 12 , " .hms " ) & & strcmp ( fname + 12 , " .tmp " ) ) )
return false ;
* sx = 0 ;
* sx + = dehex_e ( fname [ 5 ] , & error ) < < 8 ;
* sx + = dehex_e ( fname [ 6 ] , & error ) < < 4 ;
* sx + = dehex_e ( fname [ 7 ] , & error ) < < 0 ;
* sy = 0 ;
* sy + = dehex_e ( fname [ 9 ] , & error ) < < 8 ;
* sy + = dehex_e ( fname [ 10 ] , & error ) < < 4 ;
* sy + = dehex_e ( fname [ 11 ] , & error ) < < 0 ;
* sx + = CHUNKBIAS ;
* sy + = CHUNKBIAS ;
if ( ( unsigned ) * sx > = CHUNKLIMIT )
* sx - = CHUNKLIMIT ;
if ( ( unsigned ) * sy > = CHUNKLIMIT )
* sy - = CHUNKLIMIT ;
//make sure its a valid section index.
if ( ( unsigned ) * sx > = CHUNKLIMIT )
return false ;
if ( ( unsigned ) * sy > = CHUNKLIMIT )
return false ;
return true ;
}
2012-04-09 19:12:12 +00:00
2014-10-05 20:04:11 +00:00
static hmsection_t * Terr_GenerateSection ( heightmap_t * hm , int sx , int sy , qboolean scheduleload )
2013-10-29 17:38:22 +00:00
{
hmsection_t * s ;
hmcluster_t * cluster ;
int clusternum = ( sx / MAXSECTIONS ) + ( sy / MAXSECTIONS ) * MAXCLUSTERS ;
2014-10-05 20:04:11 +00:00
# ifdef LOADERTHREAD
Sys_LockMutex ( com_resourcemutex ) ;
# endif
2013-10-29 17:38:22 +00:00
cluster = hm - > cluster [ clusternum ] ;
if ( ! cluster )
cluster = hm - > cluster [ clusternum ] = Z_Malloc ( sizeof ( * cluster ) ) ;
s = cluster - > section [ ( sx % MAXSECTIONS ) + ( sy % MAXSECTIONS ) * MAXSECTIONS ] ;
if ( ! s )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
2014-10-05 20:04:11 +00:00
s = Z_Malloc ( sizeof ( * s ) ) ;
if ( ! s )
2012-07-22 02:56:22 +00:00
{
2014-10-05 20:04:11 +00:00
# ifdef LOADERTHREAD
Sys_UnlockMutex ( com_resourcemutex ) ;
# endif
return NULL ;
2012-07-22 02:56:22 +00:00
}
2013-10-29 17:58:20 +00:00
# ifndef SERVERONLY
2014-10-05 20:04:11 +00:00
s - > lightmap = - 1 ;
# endif
# ifndef SERVERONLY
s - > numents = 0 ;
2013-10-29 17:58:20 +00:00
# endif
2012-07-21 08:06:07 +00:00
s - > sx = sx ;
s - > sy = sy ;
2013-10-29 17:38:22 +00:00
cluster - > section [ ( sx % MAXSECTIONS ) + ( sy % MAXSECTIONS ) * MAXSECTIONS ] = s ;
2012-07-21 08:06:07 +00:00
hm - > activesections + + ;
2013-10-29 17:38:22 +00:00
s - > hmmod = hm ;
2014-10-05 20:04:11 +00:00
s - > flags = TSF_DIRTY ;
hm - > loadingsections + = 1 ;
s - > loadstate = TSLS_LOADING1 ;
2015-06-22 11:49:15 +00:00
if ( ! scheduleload )
return s ;
# ifdef LOADERTHREAD
Sys_UnlockMutex ( com_resourcemutex ) ;
# endif
COM_AddWork ( 1 , Terr_LoadSectionWorker , s , hm , sx , sy ) ;
return s ;
2013-10-29 17:38:22 +00:00
}
2015-06-22 11:49:15 +00:00
if ( scheduleload )
2014-10-05 20:04:11 +00:00
# ifdef LOADERTHREAD
2015-06-22 11:49:15 +00:00
Sys_UnlockMutex ( com_resourcemutex ) ;
2013-10-29 17:58:20 +00:00
# endif
2013-10-29 17:38:22 +00:00
return s ;
}
2014-05-10 13:42:13 +00:00
//generates some water
2013-11-21 23:02:28 +00:00
static void * Terr_GenerateWater ( hmsection_t * s , float maxheight )
{
int i ;
struct hmwater_s * w ;
w = Z_Malloc ( sizeof ( * s - > water ) ) ;
w - > next = s - > water ;
s - > water = w ;
2014-10-05 20:04:11 +00:00
Q_strncpyz ( w - > shadername , s - > hmmod - > defaultwatershader , sizeof ( w - > shadername ) ) ;
2013-11-21 23:02:28 +00:00
w - > simple = true ;
2014-02-07 08:38:40 +00:00
w - > contentmask = FTECONTENTS_WATER ;
2013-11-21 23:02:28 +00:00
memset ( w - > holes , 0 , sizeof ( w - > holes ) ) ;
for ( i = 0 ; i < 9 * 9 ; i + + )
w - > heights [ i ] = maxheight ;
w - > maxheight = w - > minheight = maxheight ;
if ( s - > maxh_cull < w - > maxheight )
s - > maxh_cull = w - > maxheight ;
return w ;
}
2014-05-10 13:42:13 +00:00
//embeds a mesh
static void Terr_AddMesh ( heightmap_t * hm , int loadflags , model_t * mod , vec3_t epos , vec3_t axis [ 3 ] , float scale )
{
struct hmentity_s * e , * f = NULL ;
hmsection_t * s ;
int min [ 2 ] , max [ 2 ] , coord [ 2 ] ;
int i ;
if ( ! mod )
return ;
if ( ! scale )
scale = 1 ;
if ( axis [ 0 ] [ 0 ] ! = 1 | | axis [ 0 ] [ 1 ] ! = 0 | | axis [ 0 ] [ 2 ] ! = 0 | |
axis [ 1 ] [ 0 ] ! = 0 | | axis [ 1 ] [ 1 ] ! = 1 | | axis [ 1 ] [ 2 ] ! = 0 | |
axis [ 2 ] [ 0 ] ! = 0 | | axis [ 2 ] [ 1 ] ! = 0 | | axis [ 2 ] [ 2 ] ! = 1 )
{
min [ 0 ] = floor ( ( epos [ 0 ] - mod - > radius * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
min [ 1 ] = floor ( ( epos [ 1 ] - mod - > radius * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
min [ 0 ] = bound ( hm - > firstsegx , min [ 0 ] , hm - > maxsegx - 1 ) ;
min [ 1 ] = bound ( hm - > firstsegy , min [ 1 ] , hm - > maxsegy - 1 ) ;
max [ 0 ] = floor ( ( epos [ 0 ] + mod - > radius * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
max [ 1 ] = floor ( ( epos [ 1 ] + mod - > radius * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
max [ 0 ] = bound ( hm - > firstsegx , max [ 0 ] , hm - > maxsegx - 1 ) ;
max [ 1 ] = bound ( hm - > firstsegy , max [ 1 ] , hm - > maxsegy - 1 ) ;
}
else
{
min [ 0 ] = floor ( ( epos [ 0 ] + mod - > mins [ 0 ] * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
min [ 1 ] = floor ( ( epos [ 1 ] + mod - > mins [ 1 ] * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
min [ 0 ] = bound ( hm - > firstsegx , min [ 0 ] , hm - > maxsegx - 1 ) ;
min [ 1 ] = bound ( hm - > firstsegy , min [ 1 ] , hm - > maxsegy - 1 ) ;
max [ 0 ] = floor ( ( epos [ 0 ] + mod - > maxs [ 0 ] * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
max [ 1 ] = floor ( ( epos [ 1 ] + mod - > maxs [ 1 ] * scale ) / hm - > sectionsize ) + CHUNKBIAS ;
max [ 0 ] = bound ( hm - > firstsegx , max [ 0 ] , hm - > maxsegx - 1 ) ;
max [ 1 ] = bound ( hm - > firstsegy , max [ 1 ] , hm - > maxsegy - 1 ) ;
}
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( hm - > entitylock ) ;
2014-05-10 13:42:13 +00:00
//try to find the ent if it already exists (don't do dupes)
for ( e = hm - > entities ; e ; e = e - > next )
{
if ( ! e - > refs )
f = e ;
else
{
if ( e - > ent . origin [ 0 ] ! = epos [ 0 ] | | e - > ent . origin [ 1 ] ! = epos [ 1 ] | | e - > ent . origin [ 2 ] ! = epos [ 2 ] )
continue ;
if ( e - > ent . model ! = mod | | e - > ent . scale ! = scale )
continue ;
2014-09-20 04:11:39 +00:00
if ( memcmp ( axis , e - > ent . axis , sizeof ( e - > ent . axis ) ) )
2014-05-10 13:42:13 +00:00
continue ;
break ; //looks like a match.
}
}
//allocate it if needed
if ( ! e )
{
if ( f )
e = f ; //can reuse a released one
else
{ //allocate one
e = Z_Malloc ( sizeof ( * e ) ) ;
e - > next = hm - > entities ;
hm - > entities = e ;
}
e - > ent . drawflags = SCALE_ORIGIN_ORIGIN ;
e - > ent . scale = scale ;
e - > ent . playerindex = - 1 ;
e - > ent . shaderRGBAf [ 0 ] = 1 ;
e - > ent . shaderRGBAf [ 1 ] = 1 ;
e - > ent . shaderRGBAf [ 2 ] = 1 ;
e - > ent . shaderRGBAf [ 3 ] = 1 ;
VectorCopy ( epos , e - > ent . origin ) ;
memcpy ( e - > ent . axis , axis , sizeof ( e - > ent . axis ) ) ;
e - > ent . model = mod ;
}
for ( coord [ 0 ] = min [ 0 ] ; coord [ 0 ] < = max [ 0 ] ; coord [ 0 ] + + )
{
for ( coord [ 1 ] = min [ 1 ] ; coord [ 1 ] < = max [ 1 ] ; coord [ 1 ] + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , coord [ 0 ] , coord [ 1 ] , loadflags | TGS_ANYSTATE ) ;
2014-05-10 13:42:13 +00:00
if ( ! s )
continue ;
//don't add pointless dupes
for ( i = 0 ; i < s - > numents ; i + + )
{
if ( s - > ents [ i ] = = e )
break ;
}
if ( i < s - > numents )
continue ;
2014-10-05 20:04:11 +00:00
//FIXME: while technically correct, this causes issues with the v1 format.
2014-05-10 13:42:13 +00:00
s - > flags | = TSF_EDITED ;
2014-10-05 20:04:11 +00:00
//FIXME: race condition - main thread might be walking the entity list.
//FIXME: even worse: the editor might be running through this routine adding/removing entities at the same time as the loader.
2014-05-10 13:42:13 +00:00
if ( s - > maxents = = s - > numents )
{
s - > maxents + + ;
s - > ents = realloc ( s - > ents , sizeof ( * s - > ents ) * ( s - > maxents ) ) ;
}
s - > ents [ s - > numents + + ] = e ;
e - > refs + + ;
}
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( hm - > entitylock ) ;
2014-05-10 13:42:13 +00:00
}
2013-10-29 17:38:22 +00:00
static void * Terr_ReadV1 ( heightmap_t * hm , hmsection_t * s , void * ptr , int len )
{
2014-03-30 08:55:06 +00:00
# ifndef SERVERONLY
2014-05-10 13:42:13 +00:00
dsmesh_v1_t * dm ;
2013-10-29 17:38:22 +00:00
float * colours ;
2014-10-05 20:04:11 +00:00
qbyte * lmstart ;
2014-03-30 08:55:06 +00:00
# endif
2013-10-29 17:38:22 +00:00
dsection_v1_t * ds = ptr ;
int i ;
unsigned int flags = LittleLong ( ds - > flags ) ;
2013-11-21 23:02:28 +00:00
s - > flags | = flags & ~ ( TSF_INTERNAL | TSF_HASWATER_V0 ) ;
2013-10-29 17:38:22 +00:00
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
s - > heights [ i ] = LittleFloat ( ds - > heights [ i ] ) ;
2012-04-09 19:12:12 +00:00
}
2013-10-29 17:38:22 +00:00
s - > minh = ds - > minh ;
s - > maxh = ds - > maxh ;
2013-11-21 23:02:28 +00:00
if ( flags & TSF_HASWATER_V0 )
Terr_GenerateWater ( s , ds - > waterheight ) ;
memset ( s - > holes , 0 , sizeof ( s - > holes ) ) ;
2014-02-11 17:51:29 +00:00
for ( i = 0 ; i < 8 * 8 ; i + + )
{
int x = ( i & 7 ) ;
int y = ( i > > 3 ) ;
2014-02-13 23:37:33 +00:00
int b = ( 1u < < ( x > > 1 ) ) < < ( ( y > > 1 ) < < 2 ) ;
if ( ds - > holes & b )
2014-02-11 17:51:29 +00:00
s - > holes [ y ] | = 1u < < x ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
ptr = ds + 1 ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
/*deal with textures*/
Q_strncpyz ( s - > texname [ 0 ] , ds - > texname [ 0 ] , sizeof ( s - > texname [ 0 ] ) ) ;
Q_strncpyz ( s - > texname [ 1 ] , ds - > texname [ 1 ] , sizeof ( s - > texname [ 1 ] ) ) ;
Q_strncpyz ( s - > texname [ 2 ] , ds - > texname [ 2 ] , sizeof ( s - > texname [ 2 ] ) ) ;
Q_strncpyz ( s - > texname [ 3 ] , ds - > texname [ 3 ] , sizeof ( s - > texname [ 3 ] ) ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
/*load in the mixture/lighting*/
2014-10-05 20:04:11 +00:00
lmstart = BZ_Malloc ( SECTTEXSIZE * SECTTEXSIZE * 4 ) ;
memcpy ( lmstart , ds - > texmap , SECTTEXSIZE * SECTTEXSIZE * 4 ) ;
COM_AddWork ( 0 , Terr_WorkerLoadedSectionLightmap , hm , lmstart , s - > sx , s - > sy ) ;
2012-08-04 11:28:39 +00:00
2013-10-29 17:38:22 +00:00
s - > mesh . colors4f_array [ 0 ] = s - > colours ;
if ( flags & TSF_HASCOLOURS )
{
for ( i = 0 , colours = ( float * ) ptr ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + , colours + = 4 )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
s - > colours [ i ] [ 0 ] = LittleFloat ( colours [ 0 ] ) ;
s - > colours [ i ] [ 1 ] = LittleFloat ( colours [ 1 ] ) ;
s - > colours [ i ] [ 2 ] = LittleFloat ( colours [ 2 ] ) ;
s - > colours [ i ] [ 3 ] = LittleFloat ( colours [ 3 ] ) ;
2012-04-09 19:12:12 +00:00
}
2013-10-29 17:38:22 +00:00
ptr = colours ;
}
else
{
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
2012-08-04 11:28:39 +00:00
{
2013-10-29 17:38:22 +00:00
s - > colours [ i ] [ 0 ] = 1 ;
s - > colours [ i ] [ 1 ] = 1 ;
s - > colours [ i ] [ 2 ] = 1 ;
s - > colours [ i ] [ 3 ] = 1 ;
2012-08-04 11:28:39 +00:00
}
2013-10-29 17:38:22 +00:00
}
/*load any static ents*/
2014-05-10 13:42:13 +00:00
for ( i = 0 , dm = ( dsmesh_v1_t * ) ptr ; i < ds - > ents_num ; i + + , dm = ( dsmesh_v1_t * ) ( ( qbyte * ) dm + dm - > size ) )
2013-10-29 17:38:22 +00:00
{
2014-05-10 13:42:13 +00:00
vec3_t org ;
org [ 0 ] = dm - > axisorg [ 3 ] [ 0 ] + ( s - > sx - CHUNKBIAS ) * hm - > sectionsize ;
org [ 1 ] = dm - > axisorg [ 3 ] [ 1 ] + ( s - > sy - CHUNKBIAS ) * hm - > sectionsize ;
org [ 2 ] = dm - > axisorg [ 3 ] [ 2 ] ;
Terr_AddMesh ( hm , TGS_NOLOAD , Mod_ForName ( ( char * ) ( dm + 1 ) , MLV_WARN ) , org , dm - > axisorg , dm - > scale ) ;
2013-10-29 17:38:22 +00:00
}
# endif
return ptr ;
}
2012-08-04 11:28:39 +00:00
2013-11-21 23:02:28 +00:00
struct terrstream_s
{
qbyte * buffer ;
int maxsize ;
int pos ;
} ;
//I really hope these get inlined properly.
static int Terr_Read_SInt ( struct terrstream_s * strm )
{
int val ;
strm - > pos = ( strm - > pos + sizeof ( val ) - 1 ) & ~ ( sizeof ( val ) - 1 ) ;
val = * ( int * ) ( strm - > buffer + strm - > pos ) ;
strm - > pos + = sizeof ( val ) ;
return LittleLong ( val ) ;
}
static qbyte Terr_Read_Byte ( struct terrstream_s * strm )
{
qbyte val ;
val = * ( qbyte * ) ( strm - > buffer + strm - > pos ) ;
strm - > pos + = sizeof ( val ) ;
return val ;
}
static float Terr_Read_Float ( struct terrstream_s * strm )
{
float val ;
strm - > pos = ( strm - > pos + sizeof ( val ) - 1 ) & ~ ( sizeof ( val ) - 1 ) ;
val = * ( float * ) ( strm - > buffer + strm - > pos ) ;
strm - > pos + = sizeof ( val ) ;
return LittleFloat ( val ) ;
}
static char * Terr_Read_String ( struct terrstream_s * strm , char * val , int maxlen )
{
int len = strlen ( strm - > buffer + strm - > pos ) ;
maxlen = min ( len , maxlen - 1 ) ; //truncate
memcpy ( val , strm - > buffer + strm - > pos , maxlen ) ;
val [ maxlen ] = 0 ;
strm - > pos + = len + 1 ;
return val ;
}
# ifndef SERVERONLY
static void Terr_Write_SInt ( struct terrstream_s * strm , int val )
{
val = LittleLong ( val ) ;
strm - > pos = ( strm - > pos + sizeof ( val ) - 1 ) & ~ ( sizeof ( val ) - 1 ) ;
* ( int * ) ( strm - > buffer + strm - > pos ) = val ;
strm - > pos + = sizeof ( val ) ;
}
static void Terr_Write_Byte ( struct terrstream_s * strm , qbyte val )
{
* ( qbyte * ) ( strm - > buffer + strm - > pos ) = val ;
strm - > pos + = sizeof ( val ) ;
}
static void Terr_Write_Float ( struct terrstream_s * strm , float val )
{
val = LittleFloat ( val ) ;
strm - > pos = ( strm - > pos + sizeof ( val ) - 1 ) & ~ ( sizeof ( val ) - 1 ) ;
* ( float * ) ( strm - > buffer + strm - > pos ) = val ;
strm - > pos + = sizeof ( val ) ;
}
static void Terr_Write_String ( struct terrstream_s * strm , char * val )
{
int len = strlen ( val ) + 1 ;
memcpy ( strm - > buffer + strm - > pos , val , len ) ;
strm - > pos + = len ;
}
static void Terr_TrimWater ( hmsection_t * s )
{
int i ;
struct hmwater_s * w , * * link ;
2014-02-07 08:38:40 +00:00
for ( link = & s - > water ; ( w = * link ) ; )
2013-11-21 23:02:28 +00:00
{
//one has a height above the terrain?
for ( i = 0 ; i < 9 * 9 ; i + + )
if ( w - > heights [ i ] > s - > minh )
break ;
if ( i = = 9 * 9 )
{
* link = w - > next ;
Z_Free ( w ) ;
continue ;
}
2014-02-07 08:38:40 +00:00
else
link = & ( * link ) - > next ;
2013-11-21 23:02:28 +00:00
}
}
static void Terr_SaveV2 ( heightmap_t * hm , hmsection_t * s , vfsfile_t * f , int sx , int sy )
{
qbyte buffer [ 65536 ] , last , delta , * lm ;
struct terrstream_s strm = { buffer , sizeof ( buffer ) , 0 } ;
unsigned int flags = s - > flags ;
int i , j , x , y ;
struct hmwater_s * w ;
flags & = ~ ( TSF_INTERNAL ) ;
flags & = ~ ( TSF_HASCOLOURS | TSF_HASHEIGHTS | TSF_HASSHADOW ) ;
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
if ( s - > colours [ i ] [ 0 ] ! = 1 | | s - > colours [ i ] [ 1 ] ! = 1 | | s - > colours [ i ] [ 2 ] ! = 1 | | s - > colours [ i ] [ 3 ] ! = 1 )
{
flags | = TSF_HASCOLOURS ;
break ;
}
}
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
if ( s - > heights [ i ] ! = s - > heights [ 0 ] )
{
flags | = TSF_HASHEIGHTS ;
break ;
}
}
lm = lightmap [ s - > lightmap ] - > lightmaps ;
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
for ( x = 0 ; x < SECTTEXSIZE ; x + + )
{
if ( lm [ x * 4 + 3 ] ! = 255 )
{
flags | = TSF_HASSHADOW ;
y = SECTTEXSIZE ;
break ;
}
}
lm + = ( HMLMSTRIDE ) * lightmap_bytes ;
}
//write the flags so the loader knows what to load
Terr_Write_SInt ( & strm , flags ) ;
//if heights are compressed, only the first is present.
if ( ! ( flags & TSF_HASHEIGHTS ) )
Terr_Write_Float ( & strm , s - > heights [ 0 ] ) ;
else
{
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
Terr_Write_Float ( & strm , s - > heights [ i ] ) ;
}
for ( i = 0 ; i < sizeof ( s - > holes ) ; i + + )
Terr_Write_Byte ( & strm , s - > holes [ i ] ) ;
Terr_TrimWater ( s ) ;
for ( j = 0 , w = s - > water ; w ; j + + )
w = w - > next ;
Terr_Write_SInt ( & strm , j ) ;
2014-02-07 08:38:40 +00:00
for ( i = 0 , w = s - > water ; i < j ; i + + , w = w - > next )
2013-11-21 23:02:28 +00:00
{
char * shadername = w - > shader - > name ;
int fl = 0 ;
2014-05-10 13:42:13 +00:00
if ( strcmp ( shadername , hm - > defaultwatershader ) )
2013-11-21 23:02:28 +00:00
fl | = 1 ;
for ( x = 0 ; x < 8 ; x + + )
if ( w - > holes [ x ] )
break ;
fl | = ( ( x = = 8 ) ? 0 : 2 ) ;
for ( x = 0 ; x < 9 * 9 ; x + + )
if ( w - > heights [ x ] ! = w - > heights [ 0 ] )
break ;
fl | = ( ( x = = 9 * 9 ) ? 0 : 4 ) ;
Terr_Write_SInt ( & strm , fl ) ;
Terr_Write_SInt ( & strm , w - > contentmask ) ;
if ( fl & 1 )
Terr_Write_String ( & strm , shadername ) ;
if ( fl & 2 )
{
for ( x = 0 ; x < 8 ; x + + )
Terr_Write_Byte ( & strm , w - > holes [ x ] ) ;
}
if ( fl & 4 )
{
for ( x = 0 ; x < 9 * 9 ; x + + )
Terr_Write_Float ( & strm , w - > heights [ x ] ) ;
}
else
Terr_Write_Float ( & strm , w - > heights [ 0 ] ) ;
}
if ( flags & TSF_HASCOLOURS )
{
//FIXME: bytes? channels?
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
Terr_Write_Float ( & strm , s - > colours [ i ] [ 0 ] ) ;
Terr_Write_Float ( & strm , s - > colours [ i ] [ 1 ] ) ;
Terr_Write_Float ( & strm , s - > colours [ i ] [ 2 ] ) ;
Terr_Write_Float ( & strm , s - > colours [ i ] [ 3 ] ) ;
}
}
for ( j = 0 ; j < 4 ; j + + )
Terr_Write_String ( & strm , s - > texname [ j ] ) ;
for ( j = 0 ; j < 4 ; j + + )
{
if ( j = = 3 )
{
//only write the channel if it has actual data
if ( ! ( flags & TSF_HASSHADOW ) )
continue ;
}
else
{
//only write the data if there's actually a texture.
//its not meant to be possible to delete a texture without deleting its data too.
//
if ( ! * s - > texname [ 2 - j ] )
continue ;
}
//write the channel
last = 0 ;
lm = lightmap [ s - > lightmap ] - > lightmaps ;
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
for ( x = 0 ; x < SECTTEXSIZE ; x + + )
{
delta = lm [ x * 4 + j ] - last ;
last = lm [ x * 4 + j ] ;
Terr_Write_Byte ( & strm , delta ) ;
}
lm + = ( HMLMSTRIDE ) * lightmap_bytes ;
}
}
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( hm - > entitylock ) ;
2013-11-21 23:02:28 +00:00
Terr_Write_SInt ( & strm , s - > numents ) ;
for ( i = 0 ; i < s - > numents ; i + + )
{
unsigned int mf ;
//make sure we don't overflow. we should always be aligned at this point.
if ( strm . pos > strm . maxsize / 2 )
{
VFS_WRITE ( f , strm . buffer , strm . pos ) ;
strm . pos = 0 ;
}
2014-02-07 08:38:40 +00:00
mf = 0 ;
2014-05-10 13:42:13 +00:00
if ( s - > ents [ i ] - > ent . scale ! = 1 )
2014-02-07 08:38:40 +00:00
mf | = TMF_SCALE ;
Terr_Write_SInt ( & strm , mf ) ;
2014-05-10 13:42:13 +00:00
if ( s - > ents [ i ] - > ent . model )
Terr_Write_String ( & strm , s - > ents [ i ] - > ent . model - > name ) ;
2013-11-21 23:02:28 +00:00
else
Terr_Write_String ( & strm , " *invalid " ) ;
2014-05-10 13:42:13 +00:00
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . origin [ 0 ] + ( CHUNKBIAS - sx ) * hm - > sectionsize ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . origin [ 1 ] + ( CHUNKBIAS - sy ) * hm - > sectionsize ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . origin [ 2 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 0 ] [ 0 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 0 ] [ 1 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 0 ] [ 2 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 1 ] [ 0 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 1 ] [ 1 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 1 ] [ 2 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 2 ] [ 0 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 2 ] [ 1 ] ) ;
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . axis [ 2 ] [ 2 ] ) ;
2013-11-21 23:02:28 +00:00
if ( mf & TMF_SCALE )
2014-05-10 13:42:13 +00:00
Terr_Write_Float ( & strm , s - > ents [ i ] - > ent . scale ) ;
2013-11-21 23:02:28 +00:00
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( hm - > entitylock ) ;
2013-11-21 23:02:28 +00:00
//reset it in case the buffer is getting a little full
strm . pos = ( strm . pos + sizeof ( int ) - 1 ) & ~ ( sizeof ( int ) - 1 ) ;
VFS_WRITE ( f , strm . buffer , strm . pos ) ;
strm . pos = 0 ;
}
2014-10-05 20:04:11 +00:00
static void Terr_WorkerLoadedSectionLightmap ( void * ctx , void * data , size_t a , size_t b )
{
heightmap_t * hm = ctx ;
hmsection_t * s = Terr_GetSection ( hm , a , b , TGS_NOLOAD | TGS_ANYSTATE ) ;
qbyte * inlm = data ;
qbyte * outlm ;
int y ;
if ( s )
if ( lightmap_bytes = = 4 & & Terr_InitLightmap ( s , false ) )
{
outlm = lightmap [ s - > lightmap ] - > lightmaps ;
outlm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
memcpy ( outlm , inlm , SECTTEXSIZE * 4 ) ;
inlm + = SECTTEXSIZE * 4 ;
outlm + = ( HMLMSTRIDE ) * lightmap_bytes ;
}
}
BZ_Free ( data ) ;
}
2013-11-21 23:02:28 +00:00
# endif
static void * Terr_ReadV2 ( heightmap_t * hm , hmsection_t * s , void * ptr , int len )
{
2014-03-30 08:55:06 +00:00
# ifndef SERVERONLY
2013-11-21 23:02:28 +00:00
char modelname [ MAX_QPATH ] ;
2014-03-30 08:55:06 +00:00
qbyte last ;
int y ;
qboolean present ;
2014-10-05 20:04:11 +00:00
qbyte * lmstart = NULL , * lm , delta ;
2014-03-30 08:55:06 +00:00
# endif
2013-11-21 23:02:28 +00:00
struct terrstream_s strm = { ptr , len , 0 } ;
float f ;
2014-03-30 08:55:06 +00:00
int i , j , x ;
2013-11-21 23:02:28 +00:00
unsigned int flags = Terr_Read_SInt ( & strm ) ;
s - > flags | = flags & ~ TSF_INTERNAL ;
if ( flags & TSF_HASHEIGHTS )
{
s - > minh = s - > maxh = s - > heights [ 0 ] = Terr_Read_Float ( & strm ) ;
for ( i = 1 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
f = Terr_Read_Float ( & strm ) ;
if ( s - > minh > f )
s - > minh = f ;
if ( s - > maxh < f )
s - > maxh = f ;
s - > heights [ i ] = f ;
}
}
else
{
s - > minh = s - > maxh = f = Terr_Read_Float ( & strm ) ;
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
s - > heights [ i ] = f ;
}
for ( i = 0 ; i < sizeof ( s - > holes ) ; i + + )
s - > holes [ i ] = Terr_Read_Byte ( & strm ) ;
j = Terr_Read_SInt ( & strm ) ;
for ( i = 0 ; i < j ; i + + )
{
struct hmwater_s * w = Z_Malloc ( sizeof ( * w ) ) ;
int fl = Terr_Read_SInt ( & strm ) ;
w - > next = s - > water ;
s - > water = w ;
2014-02-07 08:38:40 +00:00
w - > simple = true ;
2013-11-21 23:02:28 +00:00
w - > contentmask = Terr_Read_SInt ( & strm ) ;
if ( fl & 1 )
2014-10-05 20:04:11 +00:00
Terr_Read_String ( & strm , w - > shadername , sizeof ( w - > shadername ) ) ;
2013-11-21 23:02:28 +00:00
else
2014-10-05 20:04:11 +00:00
Q_strncpyz ( w - > shadername , hm - > defaultwatershader , sizeof ( w - > shadername ) ) ;
2013-11-21 23:02:28 +00:00
if ( fl & 2 )
{
for ( x = 0 ; x < 8 ; x + + )
w - > holes [ i ] = Terr_Read_Byte ( & strm ) ;
2014-02-07 08:38:40 +00:00
w - > simple = false ;
2013-11-21 23:02:28 +00:00
}
if ( fl & 4 )
{
for ( x = 0 ; x < 9 * 9 ; x + + )
{
w - > heights [ x ] = Terr_Read_Float ( & strm ) ;
}
2014-02-07 08:38:40 +00:00
w - > simple = false ;
2013-11-21 23:02:28 +00:00
}
else
{ //all heights the same can be used as a way to compress the data
w - > minheight = w - > maxheight = Terr_Read_Float ( & strm ) ;
for ( x = 0 ; x < 9 * 9 ; x + + )
w - > heights [ x ] = w - > minheight = w - > maxheight ;
}
}
//dedicated server can stop reading here.
# ifndef SERVERONLY
if ( flags & TSF_HASCOLOURS )
{
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
s - > colours [ i ] [ 0 ] = Terr_Read_Float ( & strm ) ;
s - > colours [ i ] [ 1 ] = Terr_Read_Float ( & strm ) ;
s - > colours [ i ] [ 2 ] = Terr_Read_Float ( & strm ) ;
s - > colours [ i ] [ 3 ] = Terr_Read_Float ( & strm ) ;
}
}
else
{
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
s - > colours [ i ] [ 0 ] = 1 ;
s - > colours [ i ] [ 1 ] = 1 ;
s - > colours [ i ] [ 2 ] = 1 ;
s - > colours [ i ] [ 3 ] = 1 ;
}
}
for ( j = 0 ; j < 4 ; j + + )
Terr_Read_String ( & strm , s - > texname [ j ] , sizeof ( s - > texname [ j ] ) ) ;
for ( j = 0 ; j < 4 ; j + + )
{
if ( j = = 3 )
present = ! ! ( flags & TSF_HASSHADOW ) ;
else
present = ! ! ( * s - > texname [ 2 - j ] ) ;
2014-10-05 20:04:11 +00:00
//should be able to skip this if no shadows or textures
if ( ! lmstart )
lmstart = BZ_Malloc ( SECTTEXSIZE * SECTTEXSIZE * 4 ) ;
2013-11-21 23:02:28 +00:00
if ( present )
{
//read the channel
2014-10-05 20:04:11 +00:00
last = 0 ;
lm = lmstart ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
2013-11-21 23:02:28 +00:00
{
2014-10-05 20:04:11 +00:00
for ( x = 0 ; x < SECTTEXSIZE ; x + + )
2013-11-21 23:02:28 +00:00
{
2014-10-05 20:04:11 +00:00
delta = Terr_Read_Byte ( & strm ) ;
last = ( last + delta ) & 0xff ;
lm [ x * 4 + j ] = last ;
2013-11-21 23:02:28 +00:00
}
2014-10-05 20:04:11 +00:00
lm + = x * 4 ;
2013-11-21 23:02:28 +00:00
}
}
2014-10-05 20:04:11 +00:00
else
2013-11-21 23:02:28 +00:00
{
last = ( ( j = = 3 ) ? 255 : 0 ) ;
2014-10-05 20:04:11 +00:00
lm = lmstart ;
2013-11-21 23:02:28 +00:00
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
for ( x = 0 ; x < SECTTEXSIZE ; x + + )
lm [ x * 4 + j ] = last ;
2014-10-05 20:04:11 +00:00
lm + = x * 4 ;
2013-11-21 23:02:28 +00:00
}
}
}
2014-10-05 20:04:11 +00:00
if ( lmstart )
COM_AddWork ( 0 , Terr_WorkerLoadedSectionLightmap , hm , lmstart , s - > sx , s - > sy ) ;
2013-11-21 23:02:28 +00:00
/*load any static ents*/
2014-05-10 13:42:13 +00:00
j = Terr_Read_SInt ( & strm ) ;
for ( i = 0 ; i < j ; i + + )
2013-11-21 23:02:28 +00:00
{
2014-05-10 13:42:13 +00:00
vec3_t axis [ 3 ] ;
vec3_t org ;
2013-11-21 23:02:28 +00:00
unsigned int mf ;
2014-05-10 13:42:13 +00:00
model_t * mod ;
float scale ;
2013-11-21 23:02:28 +00:00
mf = Terr_Read_SInt ( & strm ) ;
2014-05-10 13:42:13 +00:00
mod = Mod_FindName ( Terr_Read_String ( & strm , modelname , sizeof ( modelname ) ) ) ;
org [ 0 ] = Terr_Read_Float ( & strm ) ;
org [ 1 ] = Terr_Read_Float ( & strm ) ;
org [ 2 ] = Terr_Read_Float ( & strm ) ;
axis [ 0 ] [ 0 ] = Terr_Read_Float ( & strm ) ;
axis [ 0 ] [ 1 ] = Terr_Read_Float ( & strm ) ;
axis [ 0 ] [ 2 ] = Terr_Read_Float ( & strm ) ;
axis [ 1 ] [ 0 ] = Terr_Read_Float ( & strm ) ;
axis [ 1 ] [ 1 ] = Terr_Read_Float ( & strm ) ;
axis [ 1 ] [ 2 ] = Terr_Read_Float ( & strm ) ;
axis [ 2 ] [ 0 ] = Terr_Read_Float ( & strm ) ;
axis [ 2 ] [ 1 ] = Terr_Read_Float ( & strm ) ;
axis [ 2 ] [ 2 ] = Terr_Read_Float ( & strm ) ;
scale = ( mf & TMF_SCALE ) ? Terr_Read_Float ( & strm ) : 1 ;
org [ 0 ] + = ( s - > sx - CHUNKBIAS ) * hm - > sectionsize ;
org [ 1 ] + = ( s - > sy - CHUNKBIAS ) * hm - > sectionsize ;
Terr_AddMesh ( hm , TGS_NOLOAD , mod , org , axis , scale ) ;
2013-11-21 23:02:28 +00:00
}
# endif
return ptr ;
}
2014-02-07 08:38:40 +00:00
//#include "gl_adt.inc"
2014-10-05 20:04:11 +00:00
static void Terr_ClearSection ( hmsection_t * s )
{
struct hmwater_s * w ;
int i ;
Sys_LockMutex ( s - > hmmod - > entitylock ) ;
for ( i = 0 ; i < s - > numents ; i + + )
s - > ents [ i ] - > refs - = 1 ;
s - > numents = 0 ;
Sys_UnlockMutex ( s - > hmmod - > entitylock ) ;
while ( s - > water )
{
w = s - > water ;
s - > water = w - > next ;
Z_Free ( w ) ;
}
}
2013-10-29 17:38:22 +00:00
static void Terr_GenerateDefault ( heightmap_t * hm , hmsection_t * s )
{
int i ;
2013-11-21 23:02:28 +00:00
memset ( s - > holes , 0 , sizeof ( s - > holes ) ) ;
2013-10-29 17:38:22 +00:00
2013-10-29 17:58:20 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
Q_strncpyz ( s - > texname [ 0 ] , " " , sizeof ( s - > texname [ 0 ] ) ) ;
Q_strncpyz ( s - > texname [ 1 ] , " " , sizeof ( s - > texname [ 1 ] ) ) ;
Q_strncpyz ( s - > texname [ 2 ] , " " , sizeof ( s - > texname [ 2 ] ) ) ;
2014-05-10 13:42:13 +00:00
Q_strncpyz ( s - > texname [ 3 ] , hm - > defaultgroundtexture , sizeof ( s - > texname [ 3 ] ) ) ;
2013-10-29 17:38:22 +00:00
if ( s - > lightmap > = 0 )
{
int j ;
qbyte * lm ;
lm = lightmap [ s - > lightmap ] - > lightmaps ;
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
for ( i = 0 ; i < SECTTEXSIZE ; i + + )
2012-07-20 01:46:05 +00:00
{
2013-10-29 17:38:22 +00:00
for ( j = 0 ; j < SECTTEXSIZE ; j + + )
2012-07-20 01:46:05 +00:00
{
2013-10-29 17:38:22 +00:00
lm [ j * 4 + 0 ] = 0 ;
lm [ j * 4 + 0 ] = 0 ;
lm [ j * 4 + 0 ] = 0 ;
lm [ j * 4 + 3 ] = 255 ;
2012-07-20 01:46:05 +00:00
}
2013-10-29 17:38:22 +00:00
lm + = ( HMLMSTRIDE ) * lightmap_bytes ;
2012-07-20 01:46:05 +00:00
}
2013-10-29 17:38:22 +00:00
lightmap [ s - > lightmap ] - > modified = true ;
lightmap [ s - > lightmap ] - > rectchange . l = 0 ;
lightmap [ s - > lightmap ] - > rectchange . t = 0 ;
lightmap [ s - > lightmap ] - > rectchange . w = HMLMSTRIDE ;
lightmap [ s - > lightmap ] - > rectchange . h = HMLMSTRIDE ;
2012-04-09 19:12:12 +00:00
}
2013-10-29 17:38:22 +00:00
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
s - > colours [ i ] [ 0 ] = 1 ;
s - > colours [ i ] [ 1 ] = 1 ;
s - > colours [ i ] [ 2 ] = 1 ;
s - > colours [ i ] [ 3 ] = 1 ;
}
2013-11-21 23:02:28 +00:00
s - > mesh . colors4f_array [ 0 ] = s - > colours ;
2013-10-29 17:38:22 +00:00
# endif
2012-07-20 01:46:05 +00:00
2014-05-10 13:42:13 +00:00
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
s - > heights [ i ] = hm - > defaultgroundheight ;
if ( hm - > defaultwaterheight > hm - > defaultgroundheight )
Terr_GenerateWater ( s , hm - > defaultwaterheight ) ;
2013-10-29 17:38:22 +00:00
#if 0 //def DEBUG
void * f ;
2014-02-07 08:38:40 +00:00
if ( lightmap_bytes = = 4 & & lightmap_bgra & & FS_LoadFile ( va ( " maps/%s/splatt.png " , hm - > path ) , & f ) ! = ( qofs_t ) - 1 )
2013-10-29 17:38:22 +00:00
{
//temp
int vx , vy ;
int x , y ;
extern qbyte * Read32BitImageFile ( qbyte * buf , int len , int * width , int * height , qboolean * hasalpha , char * fname ) ;
int sw , sh ;
qboolean hasalpha ;
unsigned char * splatter = Read32BitImageFile ( f , com_filesize , & sw , & sh , & hasalpha , " splattermap " ) ;
if ( splatter )
2012-09-30 05:52:03 +00:00
{
lm = lightmap [ s - > lightmap ] - > lightmaps ;
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
2013-10-29 17:38:22 +00:00
for ( vx = 0 ; vx < SECTTEXSIZE ; vx + + )
2012-09-30 05:52:03 +00:00
{
2013-10-29 17:38:22 +00:00
x = sw * ( ( ( float ) sy ) + ( ( float ) vx / ( SECTTEXSIZE - 1 ) ) ) / hm - > numsegsx ;
if ( x > sw - 1 )
x = sw - 1 ;
for ( vy = 0 ; vy < SECTTEXSIZE ; vy + + )
2013-03-31 04:21:08 +00:00
{
2013-10-29 17:38:22 +00:00
y = sh * ( ( ( float ) sx ) + ( ( float ) vy / ( SECTTEXSIZE - 1 ) ) ) / hm - > numsegsy ;
if ( y > sh - 1 )
y = sh - 1 ;
lm [ 2 ] = splatter [ ( y + x * sh ) * 4 + 0 ] ;
lm [ 1 ] = splatter [ ( y + x * sh ) * 4 + 1 ] ;
lm [ 0 ] = splatter [ ( y + x * sh ) * 4 + 2 ] ;
lm [ 3 ] = splatter [ ( y + x * sh ) * 4 + 3 ] ;
lm + = 4 ;
2013-03-31 04:21:08 +00:00
}
2013-10-29 17:38:22 +00:00
lm + = ( HMLMSTRIDE - SECTTEXSIZE ) * lightmap_bytes ;
2012-09-30 05:52:03 +00:00
}
2013-10-29 17:38:22 +00:00
BZ_Free ( splatter ) ;
2012-09-30 05:52:03 +00:00
lightmap [ s - > lightmap ] - > modified = true ;
lightmap [ s - > lightmap ] - > rectchange . l = 0 ;
lightmap [ s - > lightmap ] - > rectchange . t = 0 ;
lightmap [ s - > lightmap ] - > rectchange . w = HMLMSTRIDE ;
lightmap [ s - > lightmap ] - > rectchange . h = HMLMSTRIDE ;
}
2013-10-29 17:38:22 +00:00
FS_FreeFile ( f ) ;
}
2012-09-30 05:52:03 +00:00
2014-02-07 08:38:40 +00:00
if ( lightmap_bytes = = 4 & & lightmap_bgra & & ! qofs_Error ( FS_LoadFile ( va ( " maps/%s/heightmap.png " , hm - > path ) , & f ) ) )
2013-10-29 17:38:22 +00:00
{
//temp
int vx , vy ;
int x , y ;
extern qbyte * Read32BitImageFile ( qbyte * buf , int len , int * width , int * height , qboolean * hasalpha , char * fname ) ;
int sw , sh ;
float * h ;
qboolean hasalpha ;
unsigned char * hmimage = Read32BitImageFile ( f , com_filesize , & sw , & sh , & hasalpha , " heightmap " ) ;
if ( hmimage )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
h = s - > heights ;
2012-04-09 19:12:12 +00:00
2013-10-29 17:38:22 +00:00
for ( vx = 0 ; vx < SECTHEIGHTSIZE ; vx + + )
{
x = sw * ( ( ( float ) sy ) + ( ( float ) vx / ( SECTHEIGHTSIZE - 1 ) ) ) / hm - > numsegsx ;
if ( x > sw - 1 )
x = sw - 1 ;
for ( vy = 0 ; vy < SECTHEIGHTSIZE ; vy + + )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
y = sh * ( ( ( float ) sx ) + ( ( float ) vy / ( SECTHEIGHTSIZE - 1 ) ) ) / hm - > numsegsy ;
if ( y > sh - 1 )
y = sh - 1 ;
* h = 0 ;
* h + = hmimage [ ( y + x * sh ) * 4 + 0 ] ;
* h + = hmimage [ ( y + x * sh ) * 4 + 1 ] < < 8 ;
* h + = hmimage [ ( y + x * sh ) * 4 + 2 ] < < 16 ;
* h * = 4.0f / ( 1 < < 16 ) ;
h + + ;
2012-04-09 19:12:12 +00:00
}
}
2013-10-29 17:38:22 +00:00
BZ_Free ( hmimage ) ;
2012-04-09 19:12:12 +00:00
}
2013-10-29 17:38:22 +00:00
FS_FreeFile ( f ) ;
}
# endif
}
2014-10-05 20:04:11 +00:00
static void Terr_WorkerLoadedSection ( void * ctx , void * data , size_t a , size_t b )
{
hmsection_t * s = ctx ;
Terr_LoadSectionTextures ( s ) ;
COM_AssertMainThread ( " foo " ) ;
InsertLinkBefore ( & s - > recycle , & s - > hmmod - > recycle ) ;
s - > hmmod - > loadingsections - = 1 ;
s - > flags & = ~ TSF_EDITED ;
s - > loadstate = TSLS_LOADED ;
}
static void Terr_WorkerFailedSection ( void * ctx , void * data , size_t a , size_t b )
{
hmsection_t * s = ctx ;
Terr_WorkerLoadedSection ( ctx , data , a , b ) ;
s - > flags & = ~ TSF_EDITED ;
s - > loadstate = TSLS_FAILED ;
}
2013-10-29 17:38:22 +00:00
2014-10-05 20:04:11 +00:00
static hmsection_t * Terr_ReadSection ( heightmap_t * hm , hmsection_t * s , int ver , void * filebase , unsigned int filelen )
{
qboolean failed = false ;
void * ptr = filebase ;
2013-10-29 17:38:22 +00:00
2013-11-21 23:02:28 +00:00
if ( ptr & & ver = = 1 )
2013-10-29 17:38:22 +00:00
Terr_ReadV1 ( hm , s , ptr , filelen ) ;
2013-11-21 23:02:28 +00:00
else if ( ptr & & ver = = 2 )
Terr_ReadV2 ( hm , s , ptr , filelen ) ;
2013-10-29 17:38:22 +00:00
else
{
// s->flags |= TSF_RELIGHT;
Terr_GenerateDefault ( hm , s ) ;
2014-10-05 20:04:11 +00:00
failed = true ;
2012-04-09 19:12:12 +00:00
}
2014-10-05 20:04:11 +00:00
s - > flags & = ~ TSF_EDITED ; //its just been loaded (and was probably edited by the loader), make sure it doesn't get saved or whatever
s - > loadstate = TSLS_LOADING2 ;
if ( failed )
COM_AddWork ( 0 , Terr_WorkerFailedSection , s , NULL , s - > sx , s - > sy ) ;
else
COM_AddWork ( 0 , Terr_WorkerLoadedSection , s , NULL , s - > sx , s - > sy ) ;
2012-04-09 19:12:12 +00:00
return s ;
}
2012-11-29 13:37:48 +00:00
# ifndef SERVERONLY
qboolean Terr_DownloadedSection ( char * fname )
{
2014-10-05 20:04:11 +00:00
/*
2014-02-07 08:38:40 +00:00
qofs_t len ;
2013-10-29 17:38:22 +00:00
dsection_t * fileptr ;
2012-11-29 13:37:48 +00:00
int x , y ;
heightmap_t * hm ;
2013-10-29 17:38:22 +00:00
int ver = 0 ;
2012-11-29 13:37:48 +00:00
if ( ! cl . worldmodel )
return false ;
hm = cl . worldmodel - > terrain ;
if ( Terr_IsSectionFName ( hm , fname , & x , & y ) )
{
2013-10-29 17:38:22 +00:00
fileptr = NULL ;
2014-02-07 08:38:40 +00:00
len = FS_LoadFile ( fname , ( void * * ) & fileptr ) ;
2012-11-29 13:37:48 +00:00
2014-02-07 08:38:40 +00:00
if ( ! qofs_Error ( len ) & & len > = sizeof ( * fileptr ) & & fileptr - > magic = = SECTION_MAGIC )
2013-10-29 17:38:22 +00:00
Terr_ReadSection ( hm , ver , x , y , fileptr + 1 , len - sizeof ( * fileptr ) ) ;
else
Terr_ReadSection ( hm , ver , x , y , NULL , 0 ) ;
2012-11-29 13:37:48 +00:00
if ( fileptr )
FS_FreeFile ( fileptr ) ;
return true ;
}
2014-10-05 20:04:11 +00:00
*/
2012-11-29 13:37:48 +00:00
return false ;
}
# endif
2013-10-29 17:38:22 +00:00
static void Terr_LoadSection ( heightmap_t * hm , hmsection_t * s , int sx , int sy , unsigned int flags )
2012-11-29 13:37:48 +00:00
{
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
//when using networked terrain, the client will never load a section from disk, but will only load it from the server
//one section at a time.
2012-11-29 13:37:48 +00:00
if ( mod_terrain_networked . ival & & ! sv . state )
{
2014-10-05 20:04:11 +00:00
char fname [ MAX_QPATH ] ;
2013-10-29 17:38:22 +00:00
if ( flags & TGS_NODOWNLOAD )
return ;
2012-11-29 13:37:48 +00:00
//try to download it now...
if ( ! cl . downloadlist )
2014-10-05 20:04:11 +00:00
CL_CheckOrEnqueDownloadFile ( Terr_DiskSectionName ( hm , sx , sy , fname , sizeof ( fname ) ) , Terr_TempDiskSectionName ( hm , sx , sy ) , DLLF_OVERWRITE | DLLF_TEMPORARY ) ;
2013-10-29 17:38:22 +00:00
return ;
2012-11-29 13:37:48 +00:00
}
# endif
2014-10-05 20:04:11 +00:00
if ( ! s )
{
Terr_GenerateSection ( hm , sx , sy , true ) ;
}
}
static void Terr_LoadSectionWorker ( void * ctx , void * data , size_t a , size_t b )
{
heightmap_t * hm = data ;
hmsection_t * s = ctx ;
int sx = a ;
int sy = b ;
int flags = 0 ;
void * diskimage ;
qofs_t len ;
char fname [ MAX_QPATH ] ;
//already processed, or not otherwise valid
if ( s - > loadstate ! = TSLS_LOADING1 )
return ;
2013-10-29 17:38:22 +00:00
# if SECTIONSPERBLOCK > 1
2014-10-05 20:04:11 +00:00
len = FS_LoadFile ( Terr_DiskBlockName ( hm , sx , sy , fname , sizeof ( fname ) ) , ( void * * ) & diskimage ) ;
2014-02-07 08:38:40 +00:00
if ( ! qofs_Error ( len ) )
2012-11-29 13:37:48 +00:00
{
2013-10-29 17:38:22 +00:00
int offset ;
int x , y ;
int ver ;
dblock_t * block = diskimage ;
if ( block - > magic ! = SECTION_MAGIC | | ! ( block - > ver & 0x80000000 ) )
2012-11-29 13:37:48 +00:00
{
2013-10-29 17:38:22 +00:00
//give it a dummy so we don't constantly hit the disk
2014-10-05 20:04:11 +00:00
Terr_ReadSection ( hm , s , 0 , NULL , 0 ) ;
2013-10-29 17:38:22 +00:00
}
else
{
sx & = ~ ( SECTIONSPERBLOCK - 1 ) ;
sy & = ~ ( SECTIONSPERBLOCK - 1 ) ;
ver = block - > ver & ~ 0x80000000 ;
for ( y = 0 ; y < SECTIONSPERBLOCK ; y + + )
for ( x = 0 ; x < SECTIONSPERBLOCK ; x + + )
{
//noload avoids recursion.
2014-10-05 20:04:11 +00:00
s = Terr_GenerateSection ( hm , sx + x , sy + y , false ) ;
2015-06-22 11:49:15 +00:00
if ( s )
2013-10-29 17:38:22 +00:00
{
2015-06-22 11:49:15 +00:00
if ( s - > loadstate = = TSLS_LOADING1 )
{
s - > loadstate = TSLS_LOADING1 ;
# ifdef LOADERTHREAD
Sys_UnlockMutex ( com_resourcemutex ) ;
# endif
offset = block - > offset [ x + y * SECTIONSPERBLOCK ] ;
if ( ! offset )
Terr_ReadSection ( hm , s , ver , NULL , 0 ) ; //no data in the file for this section
else
Terr_ReadSection ( hm , s , ver , ( char * ) diskimage + offset , len - offset ) ;
}
# ifdef LOADERTHREAD
2013-10-29 17:38:22 +00:00
else
2015-06-22 11:49:15 +00:00
Sys_UnlockMutex ( com_resourcemutex ) ;
# endif
2013-10-29 17:38:22 +00:00
}
}
}
FS_FreeFile ( diskimage ) ;
return ;
}
2012-11-29 13:37:48 +00:00
# endif
2013-10-29 17:38:22 +00:00
//legacy one-section-per-file format.
2014-10-05 20:04:11 +00:00
len = FS_LoadFile ( Terr_DiskSectionName ( hm , sx , sy , fname , sizeof ( fname ) ) , ( void * * ) & diskimage ) ;
2014-02-07 08:38:40 +00:00
if ( ! qofs_Error ( len ) )
2013-10-29 17:38:22 +00:00
{
dsection_t * h = diskimage ;
if ( len > = sizeof ( * h ) & & h - > magic = = SECTION_MAGIC )
{
2014-10-05 20:04:11 +00:00
Terr_ReadSection ( hm , s , h - > ver , h + 1 , len - sizeof ( * h ) ) ;
2013-10-29 17:38:22 +00:00
FS_FreeFile ( diskimage ) ;
return ;
2012-11-29 13:37:48 +00:00
}
2013-10-29 17:38:22 +00:00
if ( diskimage )
FS_FreeFile ( diskimage ) ;
2012-11-29 13:37:48 +00:00
}
2013-11-21 23:02:28 +00:00
# ifdef ADT
if ( Terr_ImportADT ( hm , sx , sy , flags ) )
return ;
# endif
2013-10-29 17:38:22 +00:00
//generate a dummy one
2014-10-05 20:04:11 +00:00
Terr_ReadSection ( hm , s , 0 , NULL , 0 ) ;
2012-11-29 13:37:48 +00:00
}
2012-04-09 19:12:12 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
static void Terr_SaveV1 ( heightmap_t * hm , hmsection_t * s , vfsfile_t * f , int sx , int sy )
{
2012-04-09 19:12:12 +00:00
int i ;
2014-05-10 13:42:13 +00:00
dsmesh_v1_t dm ;
2013-10-29 17:38:22 +00:00
qbyte * lm ;
dsection_v1_t ds ;
2012-08-04 11:28:39 +00:00
vec4_t dcolours [ SECTHEIGHTSIZE * SECTHEIGHTSIZE ] ;
2013-10-29 17:38:22 +00:00
int nothing = 0 ;
2013-11-21 23:02:28 +00:00
struct hmwater_s * w = s - > water ;
2012-04-09 19:12:12 +00:00
2012-07-20 01:46:05 +00:00
memset ( & ds , 0 , sizeof ( ds ) ) ;
memset ( & dm , 0 , sizeof ( dm ) ) ;
//mask off the flags which are only valid in memory
2013-11-21 23:02:28 +00:00
ds . flags = s - > flags & ~ ( TSF_INTERNAL | TSF_HASWATER_V0 ) ;
2012-07-20 01:46:05 +00:00
//kill the haswater flag if its entirely above any possible water anyway.
2013-11-21 23:02:28 +00:00
if ( w )
ds . flags | = TSF_HASWATER_V0 ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
ds . flags & = ~ TSF_HASCOLOURS ; //recalculated
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2012-04-09 19:12:12 +00:00
Q_strncpyz ( ds . texname [ 0 ] , s - > texname [ 0 ] , sizeof ( ds . texname [ 0 ] ) ) ;
Q_strncpyz ( ds . texname [ 1 ] , s - > texname [ 1 ] , sizeof ( ds . texname [ 1 ] ) ) ;
Q_strncpyz ( ds . texname [ 2 ] , s - > texname [ 2 ] , sizeof ( ds . texname [ 2 ] ) ) ;
Q_strncpyz ( ds . texname [ 3 ] , s - > texname [ 3 ] , sizeof ( ds . texname [ 3 ] ) ) ;
2014-02-11 17:51:29 +00:00
for ( i = 0 ; i < 8 * 8 ; i + + )
{
int x = ( i & 7 ) ;
int y = ( i > > 3 ) ;
2014-02-13 23:37:33 +00:00
int b = ( 1u < < ( x > > 1 ) ) < < ( ( y > > 1 ) < < 2 ) ;
2014-02-11 17:51:29 +00:00
if ( s - > holes [ y ] & ( 1u < < x ) )
2014-02-13 23:37:33 +00:00
ds . holes | = b ;
2014-02-11 17:51:29 +00:00
}
2014-02-13 23:37:33 +00:00
//make sure the user can see the holes they just saved.
memset ( s - > holes , 0 , sizeof ( s - > holes ) ) ;
for ( i = 0 ; i < 8 * 8 ; i + + )
{
int x = ( i & 7 ) ;
int y = ( i > > 3 ) ;
int b = ( 1u < < ( x > > 1 ) ) < < ( ( y > > 1 ) < < 2 ) ;
if ( ds . holes & b )
s - > holes [ y ] | = 1u < < x ;
}
s - > flags | = TSF_DIRTY ;
2012-04-09 19:12:12 +00:00
lm = lightmap [ s - > lightmap ] - > lightmaps ;
2012-08-04 11:28:39 +00:00
lm + = ( s - > lmy * HMLMSTRIDE + s - > lmx ) * lightmap_bytes ;
2012-04-09 19:12:12 +00:00
for ( i = 0 ; i < SECTTEXSIZE ; i + + )
{
memcpy ( ds . texmap + i , lm , sizeof ( ds . texmap [ 0 ] ) ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
lm + = ( HMLMSTRIDE ) * lightmap_bytes ;
2012-04-09 19:12:12 +00:00
}
for ( i = 0 ; i < SECTHEIGHTSIZE * SECTHEIGHTSIZE ; i + + )
{
ds . heights [ i ] = LittleFloat ( s - > heights [ i ] ) ;
2012-08-04 11:28:39 +00:00
if ( s - > colours [ i ] [ 0 ] ! = 1 | | s - > colours [ i ] [ 1 ] ! = 1 | | s - > colours [ i ] [ 2 ] ! = 1 | | s - > colours [ i ] [ 3 ] ! = 1 )
{
ds . flags | = TSF_HASCOLOURS ;
dcolours [ i ] [ 0 ] = LittleFloat ( s - > colours [ i ] [ 0 ] ) ;
dcolours [ i ] [ 1 ] = LittleFloat ( s - > colours [ i ] [ 1 ] ) ;
dcolours [ i ] [ 2 ] = LittleFloat ( s - > colours [ i ] [ 2 ] ) ;
dcolours [ i ] [ 3 ] = LittleFloat ( s - > colours [ i ] [ 3 ] ) ;
}
else
{
dcolours [ i ] [ 0 ] = dcolours [ i ] [ 1 ] = dcolours [ i ] [ 2 ] = dcolours [ i ] [ 3 ] = LittleFloat ( 1 ) ;
}
2012-04-09 19:12:12 +00:00
}
2013-11-21 23:02:28 +00:00
ds . waterheight = w ? w - > heights [ 4 * 8 + 4 ] : s - > minh ;
2012-07-14 17:33:44 +00:00
ds . minh = s - > minh ;
ds . maxh = s - > maxh ;
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( hm - > entitylock ) ;
2012-08-04 11:28:39 +00:00
ds . ents_num = s - > numents ;
2012-04-09 19:12:12 +00:00
2012-07-20 01:46:05 +00:00
VFS_WRITE ( f , & ds , sizeof ( ds ) ) ;
2012-08-04 11:28:39 +00:00
if ( ds . flags & TSF_HASCOLOURS )
VFS_WRITE ( f , dcolours , sizeof ( dcolours ) ) ;
2012-07-20 01:46:05 +00:00
for ( i = 0 ; i < s - > numents ; i + + )
{
int pad ;
2014-05-10 13:42:13 +00:00
dm . scale = s - > ents [ i ] - > ent . scale ;
VectorCopy ( s - > ents [ i ] - > ent . axis [ 0 ] , dm . axisorg [ 0 ] ) ;
VectorCopy ( s - > ents [ i ] - > ent . axis [ 1 ] , dm . axisorg [ 1 ] ) ;
VectorCopy ( s - > ents [ i ] - > ent . axis [ 2 ] , dm . axisorg [ 2 ] ) ;
VectorCopy ( s - > ents [ i ] - > ent . origin , dm . axisorg [ 3 ] ) ;
2012-07-20 01:46:05 +00:00
dm . axisorg [ 3 ] [ 0 ] + = ( CHUNKBIAS - sx ) * hm - > sectionsize ;
dm . axisorg [ 3 ] [ 1 ] + = ( CHUNKBIAS - sy ) * hm - > sectionsize ;
2014-05-10 13:42:13 +00:00
dm . size = sizeof ( dm ) + strlen ( s - > ents [ i ] - > ent . model - > name ) + 1 ;
2012-07-20 01:46:05 +00:00
if ( dm . size & 3 )
pad = 4 - ( dm . size & 3 ) ;
else
pad = 0 ;
dm . size + = pad ;
VFS_WRITE ( f , & dm , sizeof ( dm ) ) ;
2014-05-10 13:42:13 +00:00
VFS_WRITE ( f , s - > ents [ i ] - > ent . model - > name , strlen ( s - > ents [ i ] - > ent . model - > name ) + 1 ) ;
2012-07-20 01:46:05 +00:00
if ( pad )
VFS_WRITE ( f , & nothing , pad ) ;
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( hm - > entitylock ) ;
2013-10-29 17:38:22 +00:00
}
2013-11-21 23:02:28 +00:00
static void Terr_Save ( heightmap_t * hm , hmsection_t * s , vfsfile_t * f , int sx , int sy , int ver )
{
if ( ver = = 1 )
Terr_SaveV1 ( hm , s , f , sx , sy ) ;
else if ( ver = = 2 )
Terr_SaveV2 ( hm , s , f , sx , sy ) ;
}
2013-10-29 17:38:22 +00:00
# endif
//doesn't clear edited/dirty flags or anything
static qboolean Terr_SaveSection ( heightmap_t * hm , hmsection_t * s , int sx , int sy , qboolean blocksave )
{
# ifdef SERVERONLY
return true ;
# else
vfsfile_t * f ;
2014-10-05 20:04:11 +00:00
char fname [ MAX_QPATH ] ;
2013-10-29 17:38:22 +00:00
int x , y ;
2013-11-21 23:02:28 +00:00
int writever = mod_terrain_savever . ival ;
if ( ! writever )
writever = SECTION_VER_DEFAULT ;
2013-10-29 17:38:22 +00:00
//if its invalid or doesn't contain all the data...
if ( ! s | | s - > lightmap < 0 )
return true ;
# if SECTIONSPERBLOCK > 1
if ( blocksave )
{
dblock_t dbh ;
sx = sx & ~ ( SECTIONSPERBLOCK - 1 ) ;
sy = sy & ~ ( SECTIONSPERBLOCK - 1 ) ;
//make sure its loaded before we replace the file
for ( y = 0 ; y < SECTIONSPERBLOCK ; y + + )
{
for ( x = 0 ; x < SECTIONSPERBLOCK ; x + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx + x , sy + y , TGS_WAITLOAD | TGS_NODOWNLOAD ) ;
2013-10-29 17:38:22 +00:00
if ( s )
s - > flags | = TSF_EDITED ; //stop them from getting reused for something else.
}
}
2014-10-05 20:04:11 +00:00
//make sure all lightmap info was loaded.
COM_WorkerFullSync ( ) ;
Terr_DiskBlockName ( hm , sx , sy , fname , sizeof ( fname ) ) ;
2013-10-29 17:38:22 +00:00
FS_CreatePath ( fname , FS_GAMEONLY ) ;
f = FS_OpenVFS ( fname , " wb " , FS_GAMEONLY ) ;
if ( ! f )
{
Con_Printf ( " Failed to open %s \n " , fname ) ;
return false ;
}
memset ( & dbh , 0 , sizeof ( dbh ) ) ;
dbh . magic = LittleLong ( SECTION_MAGIC ) ;
2013-11-21 23:02:28 +00:00
dbh . ver = LittleLong ( writever | 0x80000000 ) ;
2013-10-29 17:38:22 +00:00
VFS_WRITE ( f , & dbh , sizeof ( dbh ) ) ;
for ( y = 0 ; y < SECTIONSPERBLOCK ; y + + )
{
for ( x = 0 ; x < SECTIONSPERBLOCK ; x + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx + x , sy + y , TGS_WAITLOAD | TGS_NODOWNLOAD ) ;
2015-06-12 14:44:50 +00:00
if ( s & & s - > loadstate = = TSLS_LOADED & & Terr_InitLightmap ( s , false ) )
2013-10-29 17:38:22 +00:00
{
dbh . offset [ y * SECTIONSPERBLOCK + x ] = VFS_TELL ( f ) ;
2013-11-21 23:02:28 +00:00
Terr_Save ( hm , s , f , sx + x , sy + y , writever ) ;
2013-10-29 17:38:22 +00:00
s - > flags & = ~ TSF_EDITED ;
}
else
dbh . offset [ y * SECTIONSPERBLOCK + x ] = 0 ;
}
}
VFS_SEEK ( f , 0 ) ;
VFS_WRITE ( f , & dbh , sizeof ( dbh ) ) ;
VFS_CLOSE ( f ) ;
}
else
2012-04-09 19:12:12 +00:00
# endif
2013-10-29 17:38:22 +00:00
{
dsection_t dsh ;
2014-10-05 20:04:11 +00:00
Terr_DiskSectionName ( hm , sx , sy , fname , sizeof ( fname ) ) ;
// if (s && (s->flags & (TSF_EDITED|TSF_FAILEDLOAD)) != TSF_FAILEDLOAD)
// return FS_Remove(fname, FS_GAMEONLY); //delete the file if the section got reverted to default, and wasn't later modified.
2013-10-29 17:38:22 +00:00
2014-10-05 20:04:11 +00:00
//make sure all lightmap info was loaded.
COM_WorkerFullSync ( ) ;
2014-06-16 20:45:44 +00:00
2013-10-29 17:38:22 +00:00
FS_CreatePath ( fname , FS_GAMEONLY ) ;
f = FS_OpenVFS ( fname , " wb " , FS_GAMEONLY ) ;
if ( ! f )
{
Con_Printf ( " Failed to open %s \n " , fname ) ;
return false ;
}
memset ( & dsh , 0 , sizeof ( dsh ) ) ;
dsh . magic = SECTION_MAGIC ;
2013-11-21 23:02:28 +00:00
dsh . ver = writever ;
2013-10-29 17:38:22 +00:00
VFS_WRITE ( f , & dsh , sizeof ( dsh ) ) ;
2013-11-21 23:02:28 +00:00
Terr_Save ( hm , s , f , sx , sy , writever ) ;
2013-10-29 17:38:22 +00:00
VFS_CLOSE ( f ) ;
}
2012-07-21 04:43:31 +00:00
return true ;
2013-10-29 17:38:22 +00:00
# endif
2012-04-09 19:12:12 +00:00
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
/*convienience function*/
2013-03-31 04:21:08 +00:00
static hmsection_t * Terr_GetSection ( heightmap_t * hm , int x , int y , unsigned int flags )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
hmcluster_t * cluster ;
hmsection_t * section ;
int cx = x / MAXSECTIONS ;
int cy = y / MAXSECTIONS ;
int sx = x & ( MAXSECTIONS - 1 ) ;
int sy = y & ( MAXSECTIONS - 1 ) ;
2013-10-29 17:38:22 +00:00
cluster = hm - > cluster [ cx + cy * MAXCLUSTERS ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! cluster )
2014-10-05 20:04:11 +00:00
section = NULL ;
else
section = cluster - > section [ sx + sy * MAXSECTIONS ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! section )
{
2014-10-05 20:04:11 +00:00
if ( flags & ( TGS_LAZYLOAD | TGS_TRYLOAD | TGS_WAITLOAD ) )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
2014-10-05 20:04:11 +00:00
if ( ( flags & TGS_LAZYLOAD ) & & hm - > loadingsections )
2013-10-29 17:38:22 +00:00
return NULL ;
2014-10-05 20:04:11 +00:00
section = Terr_GenerateSection ( hm , x , y , true ) ;
2013-03-31 04:21:08 +00:00
}
}
# ifndef SERVERONLY
//when using networked terrain, the client will never load a section from disk, but only loading it from the server
2014-10-05 20:04:11 +00:00
//this means we need to send a new request to download the section if it was flagged as modified.
2013-10-29 17:38:22 +00:00
if ( ! ( flags & TGS_NODOWNLOAD ) )
2013-03-31 04:21:08 +00:00
if ( section & & ( section - > flags & TSF_NOTIFY ) & & mod_terrain_networked . ival & & ! sv . state )
{
//try to download it now...
if ( ! cl . downloadlist )
{
2014-10-05 20:04:11 +00:00
char fname [ MAX_QPATH ] ;
CL_CheckOrEnqueDownloadFile ( Terr_DiskSectionName ( hm , x , y , fname , sizeof ( fname ) ) , Terr_TempDiskSectionName ( hm , x , y ) , DLLF_OVERWRITE | DLLF_TEMPORARY ) ;
2013-03-31 04:21:08 +00:00
section - > flags & = ~ TSF_NOTIFY ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
}
2013-03-31 04:21:08 +00:00
# endif
2014-10-05 20:04:11 +00:00
if ( section )
2013-10-29 17:38:22 +00:00
{
2014-10-05 20:04:11 +00:00
//wait for it to load if we're meant to be doing that.
if ( section - > loadstate = = TSLS_LOADING1 & & ( flags & TGS_WAITLOAD ) )
{
//process the load
COM_WorkerPartialSync ( section , & section - > loadstate , TSLS_LOADING1 ) ;
}
if ( section - > loadstate = = TSLS_LOADING2 & & ( flags & TGS_WAITLOAD ) )
COM_MainThreadFlush ( ) ; //make sure any associated lightmaps also got read+handled
//if it failed, generate a default (for editing)
if ( section - > loadstate = = TSLS_FAILED & & ( flags & TGS_DEFAULTONFAIL ) )
{
section - > flags = ( section - > flags & ~ TSF_EDITED ) ;
2015-06-12 14:44:50 +00:00
section - > loadstate = TSLS_LOADED ;
2014-10-05 20:04:11 +00:00
Terr_ClearSection ( section ) ;
Terr_GenerateDefault ( hm , section ) ;
}
if ( ( section - > loadstate ! = TSLS_LOADED ) & & ! ( flags & TGS_ANYSTATE ) )
2013-10-29 17:38:22 +00:00
section = NULL ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
return section ;
}
2012-04-09 19:12:12 +00:00
/*save all currently loaded sections*/
2012-11-27 03:23:19 +00:00
int Heightmap_Save ( heightmap_t * hm )
2012-04-09 19:12:12 +00:00
{
2014-10-05 20:04:11 +00:00
hmsection_t * s ;
int x , y ;
2012-07-20 01:46:05 +00:00
int sectionssaved = 0 ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
for ( x = hm - > firstsegx ; x < hm - > maxsegx ; x + + )
2012-04-09 19:12:12 +00:00
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
for ( y = hm - > firstsegy ; y < hm - > maxsegy ; y + + )
2012-04-09 19:12:12 +00:00
{
2013-03-31 04:21:08 +00:00
s = Terr_GetSection ( hm , x , y , TGS_NOLOAD ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! s )
continue ;
2012-07-20 01:46:05 +00:00
if ( s - > flags & TSF_EDITED )
{
2014-10-05 20:04:11 +00:00
/* //make sure all the parts are loaded before trying to write them, so we don't try reading partial files, which would be bad, mmkay?
2013-10-29 17:38:22 +00:00
for ( sy = y & ~ ( SECTIONSPERBLOCK - 1 ) ; sy < y + SECTIONSPERBLOCK & & sy < hm - > maxsegy ; sy + + )
{
for ( sx = x & ~ ( SECTIONSPERBLOCK - 1 ) ; sx < x + SECTIONSPERBLOCK & & sx < hm - > maxsegx ; sx + + )
{
2014-10-05 20:04:11 +00:00
os = Terr_GetSection ( hm , sx , sy , TGS_WAITLOAD | TGS_NODOWNLOAD | TGS_NORENDER ) ;
2013-10-29 17:38:22 +00:00
if ( os )
os - > flags | = TSF_EDITED ;
}
}
2014-10-05 20:04:11 +00:00
*/
2013-10-29 17:38:22 +00:00
if ( Terr_SaveSection ( hm , s , x , y , true ) )
2012-07-21 04:43:31 +00:00
{
s - > flags & = ~ TSF_EDITED ;
sectionssaved + + ;
}
2012-07-20 01:46:05 +00:00
}
2012-04-09 19:12:12 +00:00
}
}
2012-07-20 01:46:05 +00:00
return sectionssaved ;
2012-04-09 19:12:12 +00:00
}
2012-11-27 03:23:19 +00:00
# ifndef CLIENTONLY
//on servers, we can get requests to download current map sections. if so, give them it.
qboolean Terrain_LocateSection ( char * name , flocation_t * loc )
{
heightmap_t * hm ;
hmsection_t * s ;
int x , y ;
2014-10-05 20:04:11 +00:00
char fname [ MAX_QPATH ] ;
2012-11-27 03:23:19 +00:00
//reject if its not in maps
if ( strncmp ( name , " maps/ " , 5 ) )
return false ;
2012-11-29 13:37:48 +00:00
if ( ! sv . world . worldmodel )
2012-11-27 03:23:19 +00:00
return false ;
hm = sv . world . worldmodel - > terrain ;
2012-11-29 13:37:48 +00:00
if ( ! Terr_IsSectionFName ( hm , name , & x , & y ) )
2012-11-27 03:23:19 +00:00
return false ;
//verify that its valid
2014-10-05 20:04:11 +00:00
if ( strcmp ( name , Terr_DiskSectionName ( hm , x , y , fname , sizeof ( fname ) ) ) )
2012-11-27 03:23:19 +00:00
return false ;
2013-03-31 04:21:08 +00:00
s = Terr_GetSection ( hm , x , y , TGS_NOLOAD ) ;
2012-11-27 03:23:19 +00:00
if ( ! s | | ! ( s - > flags & TSF_EDITED ) )
return false ; //its not been edited, might as well just use the regular file
2013-10-29 17:38:22 +00:00
if ( ! Terr_SaveSection ( hm , s , x , y , false ) )
2012-11-27 03:23:19 +00:00
return false ;
return FS_FLocateFile ( name , FSLFRT_IFFOUND , loc ) ;
}
# endif
2014-06-16 20:45:44 +00:00
void Terr_DestroySection ( heightmap_t * hm , hmsection_t * s , qboolean lightmapreusable )
{
2014-10-05 20:04:11 +00:00
if ( s & & s - > loadstate = = TSLS_LOADING1 )
COM_WorkerPartialSync ( s , & s - > loadstate , TSLS_LOADING1 ) ;
if ( s & & s - > loadstate = = TSLS_LOADING2 )
COM_MainThreadFlush ( ) ; //make sure any associated lightmaps also got read+handled
2014-06-16 20:45:44 +00:00
RemoveLink ( & s - > recycle ) ;
Terr_ClearSection ( s ) ;
2012-07-14 17:25:21 +00:00
# ifndef SERVERONLY
2013-10-29 17:38:22 +00:00
if ( s - > lightmap > = 0 )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
struct lmsect_s * lms ;
2013-10-29 17:38:22 +00:00
if ( lightmapreusable )
{
lms = BZ_Malloc ( sizeof ( * lms ) ) ;
lms - > lm = s - > lightmap ;
lms - > x = s - > lmx ;
lms - > y = s - > lmy ;
lms - > next = hm - > unusedlmsects ;
hm - > unusedlmsects = lms ;
hm - > numunusedlmsects + + ;
}
hm - > numusedlmsects - - ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2012-07-21 08:06:07 +00:00
if ( hm - > relight = = s )
hm - > relight = NULL ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
# ifdef GLQUAKE
2012-11-27 03:23:19 +00:00
if ( qrenderer = = QR_OPENGL & & qglDeleteBuffersARB )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
qglDeleteBuffersARB ( 1 , & s - > vbo . coord . gl . vbo ) ;
qglDeleteBuffersARB ( 1 , & s - > vbo . indicies . gl . vbo ) ;
}
# endif
2013-03-31 04:21:08 +00:00
Z_Free ( s - > ents ) ;
Z_Free ( s - > mesh . xyz_array ) ;
Z_Free ( s - > mesh . indexes ) ;
2012-07-14 17:25:21 +00:00
# endif
2013-03-31 04:21:08 +00:00
Z_Free ( s ) ;
2012-07-21 08:06:07 +00:00
hm - > activesections - - ;
}
2014-03-30 08:55:06 +00:00
# ifndef SERVERONLY
//dedicated servers do not support editing. no lightmap info causes problems.
2014-10-05 20:04:11 +00:00
//when a terrain section has the notify flag set on the server, the server needs to go through and set out notifications to replicate it to the various clients
//so the clients know to re-download the section.
2013-03-31 04:21:08 +00:00
static void Terr_DoEditNotify ( heightmap_t * hm )
{
int i ;
char * cmd ;
hmsection_t * s ;
link_t * ln = & hm - > recycle ;
if ( ! sv . state )
return ;
for ( i = 0 ; i < sv . allocated_client_slots ; i + + )
{
2014-03-30 08:55:06 +00:00
if ( svs . clients [ i ] . state > = cs_connected & & svs . clients [ i ] . netchan . remote_address . type ! = NA_LOOPBACK )
2013-03-31 04:21:08 +00:00
{
if ( svs . clients [ i ] . backbuf . cursize )
return ;
}
}
for ( ln = & hm - > recycle ; ln - > next ! = & hm - > recycle ; ln = & s - > recycle )
{
s = ( hmsection_t * ) ln - > next ;
if ( s - > flags & TSF_NOTIFY )
{
s - > flags & = ~ TSF_NOTIFY ;
cmd = va ( " mod_terrain_reload %s %i %i \n " , hm - > path , s - > sx - CHUNKBIAS , s - > sy - CHUNKBIAS ) ;
for ( i = 0 ; i < sv . allocated_client_slots ; i + + )
{
2014-03-30 08:55:06 +00:00
if ( svs . clients [ i ] . state > = cs_connected & & svs . clients [ i ] . netchan . remote_address . type ! = NA_LOOPBACK )
2013-03-31 04:21:08 +00:00
{
SV_StuffcmdToClient ( & svs . clients [ i ] , cmd ) ;
}
}
return ;
}
}
}
2012-07-21 08:06:07 +00:00
//garbage collect the oldest section, to make space for another
2013-03-31 04:21:08 +00:00
static qboolean Terr_Collect ( heightmap_t * hm )
2012-07-21 08:06:07 +00:00
{
hmcluster_t * c ;
hmsection_t * s ;
int cx , cy ;
int sx , sy ;
link_t * ln = & hm - > recycle ;
for ( ln = & hm - > recycle ; ln - > next ! = & hm - > recycle ; )
{
s = ( hmsection_t * ) ln - > next ;
2014-10-05 20:04:11 +00:00
if ( ( s - > flags & TSF_EDITED ) | | s - > loadstate = = TSLS_LOADING1 | | s - > loadstate = = TSLS_LOADING2 )
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
ln = & s - > recycle ;
else
{
cx = s - > sx / MAXSECTIONS ;
cy = s - > sy / MAXSECTIONS ;
2013-10-29 17:38:22 +00:00
c = hm - > cluster [ cx + cy * MAXCLUSTERS ] ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
sx = s - > sx & ( MAXSECTIONS - 1 ) ;
sy = s - > sy & ( MAXSECTIONS - 1 ) ;
if ( c - > section [ sx + sy * MAXSECTIONS ] ! = s )
Sys_Error ( " invalid section collection " ) ;
c - > section [ sx + sy * MAXSECTIONS ] = NULL ;
2013-10-29 17:38:22 +00:00
#if 0
if ( hm - > relight = = s )
hm - > relight = NULL ;
RemoveLink ( & s - > recycle ) ;
InsertLinkAfter ( & s - > recycle , & hm - > collected ) ;
hm - > activesections - - ;
# else
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
Terr_DestroySection ( hm , s , true ) ;
2013-10-29 17:38:22 +00:00
# endif
2013-03-31 04:21:08 +00:00
return true ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
}
2012-07-21 08:06:07 +00:00
}
2013-03-31 04:21:08 +00:00
return false ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2014-03-30 08:55:06 +00:00
# endif
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
/*purge all sections, but not root
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
lightmaps only are purged whenever the client rudely kills lightmaps
we ' ll reload those when its next seen .
( lightmaps will already have been destroyed , so no poking them )
*/
2012-07-21 05:52:35 +00:00
void Terr_PurgeTerrainModel ( model_t * mod , qboolean lightmapsonly , qboolean lightmapreusable )
2012-04-09 19:12:12 +00:00
{
heightmap_t * hm = mod - > terrain ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
hmcluster_t * c ;
2012-04-09 19:12:12 +00:00
hmsection_t * s ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
int cx , cy ;
int sx , sy ;
2012-07-21 05:52:35 +00:00
2013-10-29 17:38:22 +00:00
// Con_Printf("PrePurge: %i lm chunks used, %i unused\n", hm->numusedlmsects, hm->numunusedlmsects);
for ( cy = 0 ; cy < MAXCLUSTERS ; cy + + )
for ( cx = 0 ; cx < MAXCLUSTERS ; cx + + )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
int numremaining = 0 ;
c = hm - > cluster [ cx + cy * MAXCLUSTERS ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! c )
continue ;
for ( sy = 0 ; sy < MAXSECTIONS ; sy + + )
for ( sx = 0 ; sx < MAXSECTIONS ; sx + + )
2012-04-09 19:12:12 +00:00
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
s = c - > section [ sx + sy * MAXSECTIONS ] ;
if ( ! s )
{
}
else if ( lightmapsonly )
2012-07-14 17:25:21 +00:00
{
2013-10-29 17:38:22 +00:00
numremaining + + ;
2012-07-14 17:25:21 +00:00
# ifndef SERVERONLY
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
s - > lightmap = - 1 ;
2012-07-14 17:25:21 +00:00
# endif
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else
{
c - > section [ sx + sy * MAXSECTIONS ] = NULL ;
2012-07-21 05:52:35 +00:00
Terr_DestroySection ( hm , s , lightmapreusable ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
}
2013-10-29 17:38:22 +00:00
if ( ! numremaining )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
hm - > cluster [ cx + cy * MAXSECTIONS ] = NULL ;
2013-03-31 04:21:08 +00:00
BZ_Free ( c ) ;
2012-04-09 19:12:12 +00:00
}
}
2012-07-14 17:25:21 +00:00
# ifndef SERVERONLY
2012-07-21 05:52:35 +00:00
if ( ! lightmapreusable )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
2012-07-21 05:52:35 +00:00
while ( hm - > unusedlmsects )
{
struct lmsect_s * lms ;
lms = hm - > unusedlmsects ;
hm - > unusedlmsects = lms - > next ;
2013-03-31 04:21:08 +00:00
BZ_Free ( lms ) ;
2013-10-29 17:38:22 +00:00
hm - > numunusedlmsects - - ;
2012-07-21 05:52:35 +00:00
}
2015-04-14 23:12:17 +00:00
hm - > recalculatebrushlighting = true ;
BZ_Free ( hm - > brushlmremaps ) ;
hm - > brushlmremaps = NULL ;
hm - > brushmaxlms = 0 ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2012-07-14 17:25:21 +00:00
# endif
2013-10-29 17:38:22 +00:00
// Con_Printf("PostPurge: %i lm chunks used, %i unused\n", hm->numusedlmsects, hm->numunusedlmsects);
}
void Terr_FreeModel ( model_t * mod )
{
heightmap_t * hm = mod - > terrain ;
if ( hm )
{
2015-04-14 23:12:17 +00:00
while ( hm - > numbrushes )
Terr_Brush_DeleteIdx ( hm , hm - > numbrushes - 1 ) ;
while ( hm - > brushtextures )
{
brushtex_t * bt = hm - > brushtextures ;
# ifndef SERVERONLY
brushbatch_t * bb ;
while ( ( bb = bt - > batches ) )
{
bt - > batches = bb - > next ;
BE_VBO_Destroy ( & bb - > vbo . coord ) ;
BE_VBO_Destroy ( & bb - > vbo . indicies ) ;
BZ_Free ( bb ) ;
}
# endif
hm - > brushtextures = bt - > next ;
BZ_Free ( bt ) ;
}
# ifdef RUNTIMELIGHTING
if ( hm - > relightcontext )
LightShutdown ( hm - > relightcontext , mod ) ;
if ( hm - > lightthreadmem & & ! hm - > inheritedlightthreadmem )
BZ_Free ( hm - > lightthreadmem ) ;
# endif
BZ_Free ( hm - > wbrushes ) ;
2013-10-29 17:38:22 +00:00
Terr_PurgeTerrainModel ( mod , false , false ) ;
2015-02-03 09:44:27 +00:00
while ( hm - > entities )
{
struct hmentity_s * n = hm - > entities - > next ;
Z_Free ( hm - > entities ) ;
hm - > entities = n ;
}
2015-04-14 23:12:17 +00:00
Sys_DestroyMutex ( hm - > entitylock ) ;
2013-10-29 17:38:22 +00:00
Z_Free ( hm ) ;
mod - > terrain = NULL ;
}
2012-04-09 19:12:12 +00:00
}
# ifndef SERVERONLY
2013-11-21 23:02:28 +00:00
void Terr_DrawTerrainWater ( heightmap_t * hm , float * mins , float * maxs , struct hmwater_s * w )
2012-07-20 01:46:05 +00:00
{
scenetris_t * t ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
int flags = BEF_NOSHADOWS ;
2013-10-29 17:38:22 +00:00
int firstv ;
2013-11-21 23:02:28 +00:00
int y , x ;
2012-09-30 05:52:03 +00:00
2013-10-29 17:38:22 +00:00
//need to filter by height too, or reflections won't work properly.
2013-11-21 23:02:28 +00:00
if ( cl_numstris & & cl_stris [ cl_numstris - 1 ] . shader = = w - > shader & & cl_stris [ cl_numstris - 1 ] . flags = = flags & & cl_strisvertv [ cl_stris [ cl_numstris - 1 ] . firstvert ] [ 2 ] = = w - > maxheight )
2012-07-20 01:46:05 +00:00
{
t = & cl_stris [ cl_numstris - 1 ] ;
}
else
{
if ( cl_numstris = = cl_maxstris )
{
cl_maxstris + = 8 ;
cl_stris = BZ_Realloc ( cl_stris , sizeof ( * cl_stris ) * cl_maxstris ) ;
}
t = & cl_stris [ cl_numstris + + ] ;
2013-11-21 23:02:28 +00:00
t - > shader = w - > shader ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
t - > flags = flags ;
2012-07-20 01:46:05 +00:00
t - > firstidx = cl_numstrisidx ;
t - > firstvert = cl_numstrisvert ;
t - > numvert = 0 ;
t - > numidx = 0 ;
}
2013-11-21 23:02:28 +00:00
if ( ! w - > simple )
2012-07-20 01:46:05 +00:00
{
2013-11-21 23:02:28 +00:00
float step = ( maxs [ 0 ] - mins [ 0 ] ) / 8 ;
if ( cl_numstrisidx + 9 * 9 * 6 > cl_maxstrisidx )
{
cl_maxstrisidx = cl_numstrisidx + 12 + 9 * 9 * 6 * 4 ;
cl_strisidx = BZ_Realloc ( cl_strisidx , sizeof ( * cl_strisidx ) * cl_maxstrisidx ) ;
}
if ( cl_numstrisvert + 9 * 9 > cl_maxstrisvert )
{
cl_maxstrisvert + = 9 * 9 + 64 ;
cl_strisvertv = BZ_Realloc ( cl_strisvertv , sizeof ( * cl_strisvertv ) * cl_maxstrisvert ) ;
cl_strisvertt = BZ_Realloc ( cl_strisvertt , sizeof ( * cl_strisvertt ) * cl_maxstrisvert ) ;
cl_strisvertc = BZ_Realloc ( cl_strisvertc , sizeof ( * cl_strisvertc ) * cl_maxstrisvert ) ;
}
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
firstv = t - > numvert ;
for ( y = 0 ; y < 9 ; y + + )
{
for ( x = 0 ; x < 9 ; x + + )
{
cl_strisvertv [ cl_numstrisvert ] [ 0 ] = mins [ 0 ] + step * x ;
cl_strisvertv [ cl_numstrisvert ] [ 1 ] = mins [ 1 ] + step * y ;
2014-02-07 08:38:40 +00:00
cl_strisvertv [ cl_numstrisvert ] [ 2 ] = w - > heights [ x + y * 9 ] ;
2013-11-21 23:02:28 +00:00
cl_strisvertt [ cl_numstrisvert ] [ 0 ] = cl_strisvertv [ cl_numstrisvert ] [ 0 ] / 64 ;
cl_strisvertt [ cl_numstrisvert ] [ 1 ] = cl_strisvertv [ cl_numstrisvert ] [ 1 ] / 64 ;
Vector4Set ( cl_strisvertc [ cl_numstrisvert ] , 1 , 1 , 1 , 1 )
cl_numstrisvert + + ;
}
}
for ( y = 0 ; y < 8 ; y + + )
{
for ( x = 0 ; x < 8 ; x + + )
{
if ( w - > holes [ y ] & ( 1u < < x ) )
continue ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 0 ) + ( y + 0 ) * 9 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 0 ) + ( y + 1 ) * 9 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 1 ) + ( y + 0 ) * 9 ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 1 ) + ( y + 0 ) * 9 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 0 ) + ( y + 1 ) * 9 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + ( x + 1 ) + ( y + 1 ) * 9 ;
}
}
t - > numidx = cl_numstrisidx - t - > firstidx ;
t - > numvert = cl_numstrisvert - t - > firstvert ;
2012-07-20 01:46:05 +00:00
}
2013-11-21 23:02:28 +00:00
else
{
if ( cl_numstrisidx + 12 > cl_maxstrisidx )
{
cl_maxstrisidx = cl_numstrisidx + 12 + 64 ;
cl_strisidx = BZ_Realloc ( cl_strisidx , sizeof ( * cl_strisidx ) * cl_maxstrisidx ) ;
}
if ( cl_numstrisvert + 4 > cl_maxstrisvert )
{
cl_maxstrisvert + = 64 ;
cl_strisvertv = BZ_Realloc ( cl_strisvertv , sizeof ( * cl_strisvertv ) * cl_maxstrisvert ) ;
cl_strisvertt = BZ_Realloc ( cl_strisvertt , sizeof ( * cl_strisvertt ) * cl_maxstrisvert ) ;
cl_strisvertc = BZ_Realloc ( cl_strisvertc , sizeof ( * cl_strisvertc ) * cl_maxstrisvert ) ;
}
{
VectorSet ( cl_strisvertv [ cl_numstrisvert ] , mins [ 0 ] , mins [ 1 ] , w - > maxheight ) ;
Vector4Set ( cl_strisvertc [ cl_numstrisvert ] , 1 , 1 , 1 , 1 )
Vector2Set ( cl_strisvertt [ cl_numstrisvert ] , mins [ 0 ] / 64 , mins [ 1 ] / 64 ) ;
cl_numstrisvert + + ;
VectorSet ( cl_strisvertv [ cl_numstrisvert ] , mins [ 0 ] , maxs [ 1 ] , w - > maxheight ) ;
Vector4Set ( cl_strisvertc [ cl_numstrisvert ] , 1 , 1 , 1 , 1 )
Vector2Set ( cl_strisvertt [ cl_numstrisvert ] , mins [ 0 ] / 64 , maxs [ 1 ] / 64 ) ;
cl_numstrisvert + + ;
VectorSet ( cl_strisvertv [ cl_numstrisvert ] , maxs [ 0 ] , maxs [ 1 ] , w - > maxheight ) ;
Vector4Set ( cl_strisvertc [ cl_numstrisvert ] , 1 , 1 , 1 , 1 )
Vector2Set ( cl_strisvertt [ cl_numstrisvert ] , maxs [ 0 ] / 64 , maxs [ 1 ] / 64 ) ;
cl_numstrisvert + + ;
VectorSet ( cl_strisvertv [ cl_numstrisvert ] , maxs [ 0 ] , mins [ 1 ] , w - > maxheight ) ;
Vector4Set ( cl_strisvertc [ cl_numstrisvert ] , 1 , 1 , 1 , 1 )
Vector2Set ( cl_strisvertt [ cl_numstrisvert ] , maxs [ 0 ] / 64 , mins [ 1 ] / 64 ) ;
cl_numstrisvert + + ;
}
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
firstv = t - > numvert ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
/*build the triangles*/
cl_strisidx [ cl_numstrisidx + + ] = firstv + 0 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 1 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 2 ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
cl_strisidx [ cl_numstrisidx + + ] = firstv + 0 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 2 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 3 ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
cl_strisidx [ cl_numstrisidx + + ] = firstv + 3 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 2 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 1 ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
cl_strisidx [ cl_numstrisidx + + ] = firstv + 3 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 1 ;
cl_strisidx [ cl_numstrisidx + + ] = firstv + 0 ;
2012-07-20 01:46:05 +00:00
2013-11-21 23:02:28 +00:00
t - > numidx = cl_numstrisidx - t - > firstidx ;
t - > numvert = cl_numstrisvert - t - > firstvert ;
}
2012-07-20 01:46:05 +00:00
}
2013-10-29 17:38:22 +00:00
static void Terr_RebuildMesh ( model_t * model , hmsection_t * s , int x , int y )
2012-07-20 01:46:05 +00:00
{
int vx , vy ;
int v ;
mesh_t * mesh = & s - > mesh ;
heightmap_t * hm = s - > hmmod ;
2013-10-29 17:38:22 +00:00
Terr_InitLightmap ( s , false ) ;
2012-07-20 01:46:05 +00:00
s - > minh = 9999999999999999.f ;
s - > maxh = - 9999999999999999.f ;
2013-10-29 17:38:22 +00:00
switch ( hm - > mode )
2012-07-20 01:46:05 +00:00
{
2013-10-29 17:38:22 +00:00
case HMM_BLOCKS :
2014-02-07 08:38:40 +00:00
//tiles, like dungeon keeper
2012-08-04 11:28:39 +00:00
if ( mesh - > xyz_array )
BZ_Free ( mesh - > xyz_array ) ;
2012-07-20 01:46:05 +00:00
{
2012-08-04 11:28:39 +00:00
mesh - > xyz_array = BZ_Malloc ( ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) ) * ( SECTHEIGHTSIZE - 1 ) * ( SECTHEIGHTSIZE - 1 ) * 4 * 3 ) ;
mesh - > st_array = ( void * ) ( mesh - > xyz_array + ( SECTHEIGHTSIZE - 1 ) * ( SECTHEIGHTSIZE - 1 ) * 4 * 3 ) ;
mesh - > lmst_array [ 0 ] = ( void * ) ( mesh - > st_array + ( SECTHEIGHTSIZE - 1 ) * ( SECTHEIGHTSIZE - 1 ) * 4 * 3 ) ;
2012-07-20 01:46:05 +00:00
}
2012-08-04 11:28:39 +00:00
mesh - > numvertexes = 0 ;
2012-07-20 01:46:05 +00:00
2012-08-04 11:28:39 +00:00
if ( mesh - > indexes )
BZ_Free ( mesh - > indexes ) ;
2013-06-29 23:46:34 +00:00
mesh - > indexes = BZ_Malloc ( sizeof ( index_t ) * SECTHEIGHTSIZE * SECTHEIGHTSIZE * 6 * 3 ) ;
2012-08-04 11:28:39 +00:00
mesh - > numindexes = 0 ;
2013-08-27 13:18:09 +00:00
mesh - > colors4f_array [ 0 ] = NULL ;
2012-07-20 01:46:05 +00:00
for ( vy = 0 ; vy < SECTHEIGHTSIZE - 1 ; vy + + )
{
2012-08-04 11:28:39 +00:00
for ( vx = 0 ; vx < SECTHEIGHTSIZE - 1 ; vx + + )
{
float st [ 2 ] , inst [ 2 ] ;
2013-11-21 23:02:28 +00:00
# if SECTHEIGHTSIZE == 17
2012-08-04 11:28:39 +00:00
int holebit ;
2013-11-21 23:02:28 +00:00
int holerow ;
2012-07-20 01:46:05 +00:00
2012-08-04 11:28:39 +00:00
//skip generation of the mesh above holes
2014-02-13 23:37:33 +00:00
holerow = ( ( vy < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
holebit = 1u < < ( ( vx < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
2013-11-21 23:02:28 +00:00
if ( s - > holes [ holerow ] & holebit )
2012-08-04 11:28:39 +00:00
continue ;
2012-07-20 01:46:05 +00:00
# endif
2012-08-04 11:28:39 +00:00
//top face
v = mesh - > numvertexes ;
mesh - > numvertexes + = 4 ;
mesh - > xyz_array [ v + 0 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 2 ] = s - > heights [ vx + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 1 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 2 ] = s - > heights [ vx + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 2 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 2 ] = s - > heights [ vx + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 3 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 2 ] = s - > heights [ vx + vy * SECTHEIGHTSIZE ] ;
if ( s - > maxh < mesh - > xyz_array [ v ] [ 2 ] )
s - > maxh = mesh - > xyz_array [ v ] [ 2 ] ;
if ( s - > minh > mesh - > xyz_array [ v ] [ 2 ] )
s - > minh = mesh - > xyz_array [ v ] [ 2 ] ;
st [ 0 ] = 1.0f / hm - > tilecount [ 0 ] * vx ;
st [ 1 ] = 1.0f / hm - > tilecount [ 1 ] * vy ;
inst [ 0 ] = 0.5f / ( hm - > tilecount [ 0 ] * hm - > tilepixcount [ 0 ] ) ;
inst [ 1 ] = 0.5f / ( hm - > tilecount [ 1 ] * hm - > tilepixcount [ 1 ] ) ;
mesh - > st_array [ v + 0 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 0 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 1 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 1 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 2 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 2 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
mesh - > st_array [ v + 3 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 3 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
//calc the position in the range -0.5 to 0.5
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] = ( ( ( float ) vx / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] = ( ( ( float ) vy / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
//scale down to a half-texel
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
//bias it
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmx ) / HMLMSTRIDE ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmy ) / HMLMSTRIDE ) ;
2012-07-20 01:46:05 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
2012-08-04 11:28:39 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
2012-07-20 01:46:05 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
2012-08-04 11:28:39 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + 2 ;
//x boundary
v = mesh - > numvertexes ;
mesh - > numvertexes + = 4 ;
mesh - > xyz_array [ v + 0 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 2 ] = s - > heights [ vx + 0 + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 1 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 2 ] = s - > heights [ ( vx + 1 ) + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 2 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 2 ] = s - > heights [ ( vx + 0 ) + vy * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 3 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 2 ] = s - > heights [ ( vx + 1 ) + vy * SECTHEIGHTSIZE ] ;
if ( s - > maxh < mesh - > xyz_array [ v ] [ 2 ] )
s - > maxh = mesh - > xyz_array [ v ] [ 2 ] ;
if ( s - > minh > mesh - > xyz_array [ v ] [ 2 ] )
s - > minh = mesh - > xyz_array [ v ] [ 2 ] ;
st [ 0 ] = 1.0f / hm - > tilecount [ 0 ] * vx ;
st [ 1 ] = 1.0f / hm - > tilecount [ 1 ] * vy ;
inst [ 0 ] = 0.5f / ( hm - > tilecount [ 0 ] * hm - > tilepixcount [ 0 ] ) ;
inst [ 1 ] = 0.5f / ( hm - > tilecount [ 1 ] * hm - > tilepixcount [ 1 ] ) ;
mesh - > st_array [ v + 0 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 0 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 1 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 1 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
mesh - > st_array [ v + 2 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 2 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 3 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 3 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
//calc the position in the range -0.5 to 0.5
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] = ( ( ( float ) vx / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] = ( ( ( float ) vy / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
//scale down to a half-texel
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
//bias it
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmx ) / HMLMSTRIDE ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmy ) / HMLMSTRIDE ) ;
2012-07-20 01:46:05 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
2012-08-04 11:28:39 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + 2 ;
//y boundary
v = mesh - > numvertexes ;
mesh - > numvertexes + = 4 ;
mesh - > xyz_array [ v + 0 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 0 ] [ 2 ] = s - > heights [ vx + ( vy + 0 ) * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 1 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 1 ] [ 2 ] = s - > heights [ vx + ( vy + 0 ) * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 2 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 0 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 2 ] [ 2 ] = s - > heights [ vx + ( vy + 1 ) * SECTHEIGHTSIZE ] ;
mesh - > xyz_array [ v + 3 ] [ 0 ] = ( x - CHUNKBIAS + ( vx + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 1 ] = ( y - CHUNKBIAS + ( vy + 1 ) / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v + 3 ] [ 2 ] = s - > heights [ vx + ( vy + 1 ) * SECTHEIGHTSIZE ] ;
if ( s - > maxh < mesh - > xyz_array [ v ] [ 2 ] )
s - > maxh = mesh - > xyz_array [ v ] [ 2 ] ;
if ( s - > minh > mesh - > xyz_array [ v ] [ 2 ] )
s - > minh = mesh - > xyz_array [ v ] [ 2 ] ;
st [ 0 ] = 1.0f / hm - > tilecount [ 0 ] * vx ;
st [ 1 ] = 1.0f / hm - > tilecount [ 1 ] * vy ;
inst [ 0 ] = 0.5f / ( hm - > tilecount [ 0 ] * hm - > tilepixcount [ 0 ] ) ;
inst [ 1 ] = 0.5f / ( hm - > tilecount [ 1 ] * hm - > tilepixcount [ 1 ] ) ;
mesh - > st_array [ v + 0 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 0 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 1 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 1 ] [ 1 ] = st [ 1 ] + inst [ 1 ] ;
mesh - > st_array [ v + 2 ] [ 0 ] = st [ 0 ] + inst [ 0 ] ;
mesh - > st_array [ v + 2 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
mesh - > st_array [ v + 3 ] [ 0 ] = st [ 0 ] - inst [ 0 ] + 1.0f / hm - > tilecount [ 0 ] ;
mesh - > st_array [ v + 3 ] [ 1 ] = st [ 1 ] - inst [ 1 ] + 1.0f / hm - > tilecount [ 1 ] ;
//calc the position in the range -0.5 to 0.5
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] = ( ( ( float ) vx / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] = ( ( ( float ) vy / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
//scale down to a half-texel
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
//bias it
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmx ) / HMLMSTRIDE ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmy ) / HMLMSTRIDE ) ;
2012-07-20 01:46:05 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
2012-08-04 11:28:39 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
2012-07-20 01:46:05 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
2012-08-04 11:28:39 +00:00
mesh - > indexes [ mesh - > numindexes + + ] = v + 2 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + 2 ;
}
}
2013-10-29 17:38:22 +00:00
break ;
case HMM_TERRAIN :
2014-02-07 08:38:40 +00:00
//smooth terrain
2012-08-04 11:28:39 +00:00
if ( ! mesh - > xyz_array )
{
mesh - > xyz_array = BZ_Malloc ( ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) ) * ( SECTHEIGHTSIZE ) * ( SECTHEIGHTSIZE ) ) ;
mesh - > st_array = ( void * ) ( mesh - > xyz_array + ( SECTHEIGHTSIZE ) * ( SECTHEIGHTSIZE ) ) ;
mesh - > lmst_array [ 0 ] = ( void * ) ( mesh - > st_array + ( SECTHEIGHTSIZE ) * ( SECTHEIGHTSIZE ) ) ;
}
2013-08-27 13:18:09 +00:00
mesh - > colors4f_array [ 0 ] = s - > colours ;
2012-08-04 11:28:39 +00:00
mesh - > numvertexes = 0 ;
/*64 quads across requires 65 verticies*/
for ( vy = 0 ; vy < SECTHEIGHTSIZE ; vy + + )
{
for ( vx = 0 ; vx < SECTHEIGHTSIZE ; vx + + )
{
v = mesh - > numvertexes + + ;
mesh - > xyz_array [ v ] [ 0 ] = ( x - CHUNKBIAS + vx / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v ] [ 1 ] = ( y - CHUNKBIAS + vy / ( SECTHEIGHTSIZE - 1.0f ) ) * hm - > sectionsize ;
mesh - > xyz_array [ v ] [ 2 ] = s - > heights [ vx + vy * SECTHEIGHTSIZE ] ;
if ( s - > maxh < mesh - > xyz_array [ v ] [ 2 ] )
s - > maxh = mesh - > xyz_array [ v ] [ 2 ] ;
if ( s - > minh > mesh - > xyz_array [ v ] [ 2 ] )
s - > minh = mesh - > xyz_array [ v ] [ 2 ] ;
mesh - > st_array [ v ] [ 0 ] = mesh - > xyz_array [ v ] [ 0 ] / 128 ;
mesh - > st_array [ v ] [ 1 ] = mesh - > xyz_array [ v ] [ 1 ] / 128 ;
//calc the position in the range -0.5 to 0.5
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] = ( ( ( float ) vx / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] = ( ( ( float ) vy / ( SECTHEIGHTSIZE - 1 ) ) - 0.5 ) ;
//scale down to a half-texel
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] * = ( SECTTEXSIZE - 1.0f ) / HMLMSTRIDE ;
//bias it
mesh - > lmst_array [ 0 ] [ v ] [ 0 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmx ) / HMLMSTRIDE ) ;
mesh - > lmst_array [ 0 ] [ v ] [ 1 ] + = ( ( float ) SECTTEXSIZE / ( HMLMSTRIDE * 2 ) ) + ( ( float ) ( s - > lmy ) / HMLMSTRIDE ) ;
}
}
if ( ! mesh - > indexes )
mesh - > indexes = BZ_Malloc ( sizeof ( index_t ) * SECTHEIGHTSIZE * SECTHEIGHTSIZE * 6 ) ;
mesh - > numindexes = 0 ;
for ( vy = 0 ; vy < SECTHEIGHTSIZE - 1 ; vy + + )
{
for ( vx = 0 ; vx < SECTHEIGHTSIZE - 1 ; vx + + )
{
# ifndef STRICTEDGES
float d1 , d2 ;
# endif
2013-11-21 23:02:28 +00:00
# if SECTHEIGHTSIZE == 17
int holerow ;
2012-08-04 11:28:39 +00:00
int holebit ;
//skip generation of the mesh above holes
2014-02-13 23:37:33 +00:00
holerow = ( ( vy < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
holebit = 1u < < ( ( vx < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
2013-11-21 23:02:28 +00:00
if ( s - > holes [ holerow ] & holebit )
2012-08-04 11:28:39 +00:00
continue ;
# endif
v = vx + vy * ( SECTHEIGHTSIZE ) ;
# ifndef STRICTEDGES
d1 = fabs ( mesh - > xyz_array [ v ] [ 2 ] - mesh - > xyz_array [ v + 1 + SECTHEIGHTSIZE ] [ 2 ] ) ;
d2 = fabs ( mesh - > xyz_array [ v + 1 ] [ 2 ] - mesh - > xyz_array [ v + SECTHEIGHTSIZE ] [ 2 ] ) ;
if ( d1 < d2 )
{
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + SECTHEIGHTSIZE ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + SECTHEIGHTSIZE ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + SECTHEIGHTSIZE ;
}
else
# endif
{
mesh - > indexes [ mesh - > numindexes + + ] = v + 0 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + SECTHEIGHTSIZE ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 ;
mesh - > indexes [ mesh - > numindexes + + ] = v + SECTHEIGHTSIZE ;
mesh - > indexes [ mesh - > numindexes + + ] = v + 1 + SECTHEIGHTSIZE ;
}
2012-07-20 01:46:05 +00:00
}
}
2013-10-29 17:38:22 +00:00
break ;
}
//pure holes
if ( ! mesh - > numindexes )
{
memset ( & s - > pvscache , 0 , sizeof ( s - > pvscache ) ) ;
return ;
}
2014-10-05 20:04:11 +00:00
if ( s - > maxh_cull < s - > maxh )
s - > maxh_cull = s - > maxh ;
2013-10-29 17:38:22 +00:00
{
vec3_t mins , maxs ;
mins [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize ;
mins [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize ;
mins [ 2 ] = s - > minh ;
maxs [ 0 ] = ( x + 1 - CHUNKBIAS ) * hm - > sectionsize ;
maxs [ 1 ] = ( y + 1 - CHUNKBIAS ) * hm - > sectionsize ;
2013-11-21 23:02:28 +00:00
maxs [ 2 ] = s - > maxh_cull ;
2013-10-29 17:38:22 +00:00
model - > funcs . FindTouchedLeafs ( model , & s - > pvscache , mins , maxs ) ;
2012-07-20 01:46:05 +00:00
}
# ifdef GLQUAKE
2012-10-08 01:30:41 +00:00
if ( qrenderer = = QR_OPENGL & & qglGenBuffersARB )
2012-07-20 01:46:05 +00:00
{
if ( ! s - > vbo . coord . gl . vbo )
2012-08-04 11:28:39 +00:00
{
2012-07-20 01:46:05 +00:00
qglGenBuffersARB ( 1 , & s - > vbo . coord . gl . vbo ) ;
2012-08-04 11:28:39 +00:00
GL_SelectVBO ( s - > vbo . coord . gl . vbo ) ;
}
else
GL_SelectVBO ( s - > vbo . coord . gl . vbo ) ;
2013-10-29 17:38:22 +00:00
qglBufferDataARB ( GL_ARRAY_BUFFER_ARB , ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) + sizeof ( vec4_t ) ) * ( mesh - > numvertexes ) , NULL , GL_STATIC_DRAW_ARB ) ;
2012-08-04 11:28:39 +00:00
qglBufferSubDataARB ( GL_ARRAY_BUFFER_ARB , 0 , ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) ) * mesh - > numvertexes , mesh - > xyz_array ) ;
2013-08-27 18:09:14 +00:00
if ( mesh - > colors4f_array [ 0 ] )
qglBufferSubDataARB ( GL_ARRAY_BUFFER_ARB , ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) ) * mesh - > numvertexes , sizeof ( vec4_t ) * mesh - > numvertexes , mesh - > colors4f_array [ 0 ] ) ;
2012-07-20 01:46:05 +00:00
GL_SelectVBO ( 0 ) ;
2012-08-04 11:28:39 +00:00
s - > vbo . coord . gl . addr = 0 ;
2012-07-20 01:46:05 +00:00
s - > vbo . texcoord . gl . addr = ( void * ) ( ( char * ) mesh - > st_array - ( char * ) mesh - > xyz_array ) ;
s - > vbo . texcoord . gl . vbo = s - > vbo . coord . gl . vbo ;
s - > vbo . lmcoord [ 0 ] . gl . addr = ( void * ) ( ( char * ) mesh - > lmst_array [ 0 ] - ( char * ) mesh - > xyz_array ) ;
s - > vbo . lmcoord [ 0 ] . gl . vbo = s - > vbo . coord . gl . vbo ;
2013-08-27 13:18:09 +00:00
s - > vbo . colours [ 0 ] . gl . addr = ( void * ) ( ( sizeof ( vecV_t ) + sizeof ( vec2_t ) + sizeof ( vec2_t ) ) * mesh - > numvertexes ) ;
s - > vbo . colours [ 0 ] . gl . vbo = s - > vbo . coord . gl . vbo ;
2012-07-20 01:46:05 +00:00
if ( ! s - > vbo . indicies . gl . vbo )
qglGenBuffersARB ( 1 , & s - > vbo . indicies . gl . vbo ) ;
s - > vbo . indicies . gl . addr = 0 ;
GL_SelectEBO ( s - > vbo . indicies . gl . vbo ) ;
qglBufferDataARB ( GL_ELEMENT_ARRAY_BUFFER_ARB , sizeof ( index_t ) * mesh - > numindexes , mesh - > indexes , GL_STATIC_DRAW_ARB ) ;
GL_SelectEBO ( 0 ) ;
2013-10-29 17:38:22 +00:00
# if 1
Z_Free ( mesh - > xyz_array ) ;
mesh - > xyz_array = NULL ;
mesh - > st_array = NULL ;
mesh - > lmst_array [ 0 ] = NULL ;
Z_Free ( mesh - > indexes ) ;
mesh - > indexes = NULL ;
# endif
2012-07-20 01:46:05 +00:00
}
# endif
2012-09-30 05:52:03 +00:00
# ifdef D3D11QUAKE
if ( qrenderer = = QR_DIRECT3D11 )
{
void D3D11BE_GenBatchVBOs ( vbo_t * * vbochain , batch_t * firstbatch , batch_t * stopbatch ) ;
batch_t batch = { 0 } ;
mesh_t * meshes = & s - > mesh ;
vbo_t * vbo = NULL ;
batch . maxmeshes = 1 ;
batch . mesh = & meshes ;
//BE_ClearVBO(&s->vbo);
D3D11BE_GenBatchVBOs ( & vbo , & batch , NULL ) ;
s - > vbo = * vbo ;
}
# endif
2012-07-20 01:46:05 +00:00
}
2012-11-29 13:37:48 +00:00
struct tdibctx
{
heightmap_t * hm ;
int vx ;
int vy ;
entity_t * ent ;
batch_t * * batches ;
2013-10-29 17:38:22 +00:00
qbyte * pvs ;
model_t * wmodel ;
2012-11-29 13:37:48 +00:00
} ;
void Terr_DrawInBounds ( struct tdibctx * ctx , int x , int y , int w , int h )
{
vec3_t mins , maxs ;
hmsection_t * s ;
2013-11-21 23:02:28 +00:00
struct hmwater_s * wa ;
2014-09-20 04:11:39 +00:00
int i , j ;
2012-11-29 13:37:48 +00:00
batch_t * b ;
heightmap_t * hm = ctx - > hm ;
2013-10-29 17:38:22 +00:00
mins [ 0 ] = ( x + 0 - CHUNKBIAS ) * hm - > sectionsize ;
maxs [ 0 ] = ( x + w - CHUNKBIAS ) * hm - > sectionsize ;
2012-11-29 13:37:48 +00:00
2013-10-29 17:38:22 +00:00
mins [ 1 ] = ( y + 0 - CHUNKBIAS ) * hm - > sectionsize ;
maxs [ 1 ] = ( y + h - CHUNKBIAS ) * hm - > sectionsize ;
2012-11-29 13:37:48 +00:00
2013-10-29 17:38:22 +00:00
mins [ 2 ] = r_origin [ 2 ] - 999999 ;
maxs [ 2 ] = r_origin [ 2 ] + 999999 ;
if ( R_CullBox ( mins , maxs ) )
return ;
2012-11-29 13:37:48 +00:00
2013-10-29 17:38:22 +00:00
if ( w = = 1 & & h = = 1 )
{
s = Terr_GetSection ( hm , x , y , TGS_LAZYLOAD ) ;
2012-11-29 13:37:48 +00:00
if ( ! s )
return ;
2013-10-29 17:38:22 +00:00
/*move to head*/
RemoveLink ( & s - > recycle ) ;
InsertLinkBefore ( & s - > recycle , & hm - > recycle ) ;
2012-11-29 13:37:48 +00:00
if ( s - > lightmap < 0 )
2013-10-29 17:38:22 +00:00
Terr_LoadSection ( hm , s , x , y , TGS_NODOWNLOAD ) ;
2012-11-29 13:37:48 +00:00
if ( s - > flags & TSF_RELIGHT )
{
if ( ! hm - > relight )
{
hm - > relight = s ;
hm - > relightidx = 0 ;
hm - > relightmin [ 0 ] = mins [ 0 ] ;
hm - > relightmin [ 1 ] = mins [ 1 ] ;
}
}
if ( s - > flags & TSF_DIRTY )
{
s - > flags & = ~ TSF_DIRTY ;
2013-10-29 17:38:22 +00:00
Terr_RebuildMesh ( ctx - > wmodel , s , x , y ) ;
2012-11-29 13:37:48 +00:00
}
2013-10-29 17:38:22 +00:00
if ( ctx - > pvs & & ! ctx - > wmodel - > funcs . EdictInFatPVS ( ctx - > wmodel , & s - > pvscache , ctx - > pvs ) )
return ; //this section isn't in any visible bsp leafs
2014-10-05 20:04:11 +00:00
if ( s - > numents )
2012-11-29 13:37:48 +00:00
{
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( hm - > entitylock ) ;
//chuck out any batches for models in this section
for ( i = 0 ; i < s - > numents ; i + + )
{
vec3_t dist ;
float a , dmin , dmax ;
model_t * model ;
//skip the entity if its already been added to some batch this frame.
if ( s - > ents [ i ] - > drawnframe = = hm - > drawnframe )
continue ;
s - > ents [ i ] - > drawnframe = hm - > drawnframe ;
2014-05-10 13:42:13 +00:00
2014-10-05 20:04:11 +00:00
model = s - > ents [ i ] - > ent . model ;
if ( ! model )
continue ;
2013-11-21 23:02:28 +00:00
2014-10-05 20:04:11 +00:00
if ( model - > loadstate = = MLS_NOTLOADED )
{
// if (hm->beinglazy)
// continue;
// hm->beinglazy = true;
Mod_LoadModel ( model , MLV_WARN ) ;
}
if ( model - > loadstate ! = MLS_LOADED )
2013-10-29 17:38:22 +00:00
continue ;
2013-11-21 23:02:28 +00:00
2014-10-05 20:04:11 +00:00
VectorSubtract ( s - > ents [ i ] - > ent . origin , r_origin , dist ) ;
a = VectorLength ( dist ) ;
dmin = 1024 + model - > radius * 160 ;
dmax = dmin + 1024 ;
a = ( a - dmin ) / ( dmax - dmin ) ;
a = 1 - a ;
if ( a < 0 )
continue ;
if ( a > = 1 )
{
a = 1 ;
s - > ents [ i ] - > ent . flags & = ~ RF_TRANSLUCENT ;
}
else
s - > ents [ i ] - > ent . flags | = RF_TRANSLUCENT ;
s - > ents [ i ] - > ent . shaderRGBAf [ 3 ] = a ;
switch ( model - > type )
{
case mod_alias :
R_GAlias_GenerateBatches ( & s - > ents [ i ] - > ent , ctx - > batches ) ;
break ;
case mod_brush :
Surf_GenBrushBatches ( ctx - > batches , & s - > ents [ i ] - > ent ) ;
break ;
default : //FIXME: no sprites! oh noes!
break ;
}
2012-11-29 13:37:48 +00:00
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( hm - > entitylock ) ;
2012-11-29 13:37:48 +00:00
}
2013-11-21 23:02:28 +00:00
for ( wa = s - > water ; wa ; wa = wa - > next )
2012-11-29 13:37:48 +00:00
{
2013-11-21 23:02:28 +00:00
mins [ 2 ] = wa - > minheight ;
maxs [ 2 ] = wa - > maxheight ;
2012-11-29 13:37:48 +00:00
if ( ! R_CullBox ( mins , maxs ) )
{
2013-11-21 23:02:28 +00:00
Terr_DrawTerrainWater ( hm , mins , maxs , wa ) ;
2012-11-29 13:37:48 +00:00
}
}
mins [ 2 ] = s - > minh ;
maxs [ 2 ] = s - > maxh ;
// if (!BoundsIntersect(mins, maxs, r_refdef.vieworg, r_refdef.vieworg))
if ( R_CullBox ( mins , maxs ) )
return ;
2015-06-12 14:44:50 +00:00
if ( hm - > texmask )
{
for ( i = 0 ; i < 4 ; i + + )
{
if ( ! * s - > texname [ i ] )
break ;
if ( ! strcmp ( s - > texname [ i ] , hm - > texmask ) )
break ;
}
if ( i = = 4 )
{ //flicker if the surface cannot accept the named texture
int xor = ( x & 1 ) ^ ( y & 1 ) ;
if ( ( ( int ) ( realtime * 10 ) & 1 ) ^ xor )
return ;
}
}
2012-11-29 13:37:48 +00:00
b = BE_GetTempBatch ( ) ;
if ( ! b )
return ;
b - > ent = ctx - > ent ;
b - > shader = hm - > shader ;
b - > flags = 0 ;
b - > mesh = & s - > amesh ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
b - > mesh [ 0 ] = & s - > mesh ;
2012-11-29 13:37:48 +00:00
b - > meshes = 1 ;
b - > buildmeshes = NULL ;
b - > skin = & s - > textures ;
b - > texture = NULL ;
2013-06-29 23:46:34 +00:00
b - > vbo = & s - > vbo ;
2012-11-29 13:37:48 +00:00
b - > lightmap [ 0 ] = s - > lightmap ;
2014-09-20 04:11:39 +00:00
for ( j = 1 ; j < MAXRLIGHTMAPS ; j + + )
b - > lightmap [ j ] = - 1 ;
2012-11-29 13:37:48 +00:00
b - > next = ctx - > batches [ b - > shader - > sort ] ;
ctx - > batches [ b - > shader - > sort ] = b ;
}
else if ( w & & h )
{
//divide and conquer, radiating outwards from the view.
if ( w > h )
{
i = x + w ;
w = x + w / 2 ;
if ( ctx - > vx > = w )
{
Terr_DrawInBounds ( ctx , w , y , i - w , h ) ;
Terr_DrawInBounds ( ctx , x , y , w - x , h ) ;
}
else
{
Terr_DrawInBounds ( ctx , x , y , w - x , h ) ;
Terr_DrawInBounds ( ctx , w , y , i - w , h ) ;
}
}
else
{
i = y + h ;
h = y + h / 2 ;
if ( ctx - > vy > = h )
{
Terr_DrawInBounds ( ctx , x , h , w , i - h ) ;
Terr_DrawInBounds ( ctx , x , y , w , h - y ) ;
}
else
{
Terr_DrawInBounds ( ctx , x , y , w , h - y ) ;
Terr_DrawInBounds ( ctx , x , h , w , i - h ) ;
}
}
}
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
void Terr_DrawTerrainModel ( batch_t * * batches , entity_t * e )
2005-08-26 22:49:36 +00:00
{
2013-10-29 17:38:22 +00:00
extern qbyte * frustumvis ;
2005-08-26 22:49:36 +00:00
model_t * m = e - > model ;
heightmap_t * hm = m - > terrain ;
2011-05-20 04:10:46 +00:00
batch_t * b ;
2014-09-20 04:11:39 +00:00
int bounds [ 4 ] , j ;
2012-11-29 13:37:48 +00:00
struct tdibctx tdibctx ;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
if ( ! r_refdef . recurse )
2013-03-31 04:21:08 +00:00
{
Terr_DoEditNotify ( hm ) ;
// while (hm->activesections > 0)
// if (!Terr_Collect(hm))
// break;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
while ( hm - > activesections > TERRAINACTIVESECTIONS )
2014-10-05 20:04:11 +00:00
{
2013-03-31 04:21:08 +00:00
if ( ! Terr_Collect ( hm ) )
break ;
2014-10-05 20:04:11 +00:00
break ;
}
2013-03-31 04:21:08 +00:00
}
2012-07-20 01:46:05 +00:00
2014-10-05 20:04:11 +00:00
// hm->beinglazy = false;
2012-07-20 01:46:05 +00:00
if ( hm - > relight )
ted_dorelight ( hm ) ;
2005-08-26 22:49:36 +00:00
2013-10-29 17:38:22 +00:00
if ( e - > model = = cl . worldmodel & & hm - > skyshader )
2005-10-15 20:06:34 +00:00
{
2011-05-20 04:10:46 +00:00
b = BE_GetTempBatch ( ) ;
if ( b )
{
2014-09-20 04:11:39 +00:00
for ( j = 0 ; j < MAXRLIGHTMAPS ; j + + )
b - > lightmap [ j ] = - 1 ;
2011-05-20 04:10:46 +00:00
b - > ent = e ;
b - > shader = hm - > skyshader ;
b - > flags = 0 ;
b - > mesh = & hm - > askymesh ;
b - > mesh [ 0 ] = & hm - > skymesh ;
b - > meshes = 1 ;
b - > buildmeshes = NULL ;
2015-05-03 19:57:46 +00:00
b - > skin = NULL ;
2011-05-20 04:10:46 +00:00
b - > texture = NULL ;
2012-04-09 19:12:12 +00:00
// vbo = b->vbo = hm->vbo[x+y*MAXSECTIONS];
2011-05-20 04:10:46 +00:00
b - > vbo = NULL ;
b - > next = batches [ b - > shader - > sort ] ;
batches [ b - > shader - > sort ] = b ;
}
2005-10-15 20:06:34 +00:00
}
2015-01-07 13:34:05 +00:00
Terr_Brush_Draw ( hm , batches , e ) ;
2012-07-20 01:46:05 +00:00
2014-03-30 08:55:06 +00:00
if ( r_refdef . globalfog . density | | gl_maxdist . value > 0 )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
float culldist ;
extern cvar_t r_fog_exp2 ;
2014-03-30 08:55:06 +00:00
if ( r_refdef . globalfog . density )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
//figure out the eyespace distance required to reach that fog value
culldist = log ( 0.5 / 255.0f ) ;
if ( r_fog_exp2 . ival )
2014-03-30 08:55:06 +00:00
culldist = sqrt ( culldist / ( - r_refdef . globalfog . density * r_refdef . globalfog . density ) ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else
2014-03-30 08:55:06 +00:00
culldist = culldist / ( - r_refdef . globalfog . density ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
//anything drawn beyond this point is fully obscured by fog
culldist + = 4096 ;
}
else
2012-07-14 17:33:44 +00:00
culldist = 999999999999999.f ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( culldist > gl_maxdist . value & & gl_maxdist . value > 0 )
culldist = gl_maxdist . value ;
bounds [ 0 ] = bound ( hm - > firstsegx , ( r_refdef . vieworg [ 0 ] + ( CHUNKBIAS + 0 ) * hm - > sectionsize - culldist ) / hm - > sectionsize , hm - > maxsegx ) ;
bounds [ 1 ] = bound ( hm - > firstsegx , ( r_refdef . vieworg [ 0 ] + ( CHUNKBIAS + 1 ) * hm - > sectionsize + culldist ) / hm - > sectionsize , hm - > maxsegx ) ;
bounds [ 2 ] = bound ( hm - > firstsegy , ( r_refdef . vieworg [ 1 ] + ( CHUNKBIAS + 0 ) * hm - > sectionsize - culldist ) / hm - > sectionsize , hm - > maxsegy ) ;
bounds [ 3 ] = bound ( hm - > firstsegy , ( r_refdef . vieworg [ 1 ] + ( CHUNKBIAS + 1 ) * hm - > sectionsize + culldist ) / hm - > sectionsize , hm - > maxsegy ) ;
}
else
{
bounds [ 0 ] = hm - > firstsegx ;
bounds [ 1 ] = hm - > maxsegx ;
bounds [ 2 ] = hm - > firstsegy ;
bounds [ 3 ] = hm - > maxsegy ;
}
2014-05-10 13:42:13 +00:00
hm - > drawnframe + = 1 ;
2012-11-29 13:37:48 +00:00
tdibctx . hm = hm ;
tdibctx . batches = batches ;
tdibctx . ent = e ;
tdibctx . vx = ( r_refdef . vieworg [ 0 ] + CHUNKBIAS * hm - > sectionsize ) / hm - > sectionsize ;
tdibctx . vy = ( r_refdef . vieworg [ 1 ] + CHUNKBIAS * hm - > sectionsize ) / hm - > sectionsize ;
2013-10-29 17:38:22 +00:00
tdibctx . wmodel = e - > model ;
tdibctx . pvs = ( e - > model = = cl . worldmodel ) ? frustumvis : NULL ;
2012-11-29 13:37:48 +00:00
Terr_DrawInBounds ( & tdibctx , bounds [ 0 ] , bounds [ 2 ] , bounds [ 1 ] - bounds [ 0 ] , bounds [ 3 ] - bounds [ 2 ] ) ;
2005-08-26 22:49:36 +00:00
}
2012-08-04 11:28:39 +00:00
void Terrain_ClipDecal ( fragmentdecal_t * dec , float * center , float radius , model_t * model )
{
int min [ 2 ] , max [ 2 ] , mint [ 2 ] , maxt [ 2 ] ;
int x , y , tx , ty ;
vecV_t vert [ 6 ] ;
hmsection_t * s ;
heightmap_t * hm = model - > terrain ;
min [ 0 ] = floor ( ( center [ 0 ] - radius ) / ( hm - > sectionsize ) ) + CHUNKBIAS ;
min [ 1 ] = floor ( ( center [ 1 ] - radius ) / ( hm - > sectionsize ) ) + CHUNKBIAS ;
max [ 0 ] = ceil ( ( center [ 0 ] + radius ) / ( hm - > sectionsize ) ) + CHUNKBIAS ;
max [ 1 ] = ceil ( ( center [ 1 ] + radius ) / ( hm - > sectionsize ) ) + CHUNKBIAS ;
min [ 0 ] = bound ( hm - > firstsegx , min [ 0 ] , hm - > maxsegx ) ;
min [ 1 ] = bound ( hm - > firstsegy , min [ 1 ] , hm - > maxsegy ) ;
max [ 0 ] = bound ( hm - > firstsegx , max [ 0 ] , hm - > maxsegx ) ;
max [ 1 ] = bound ( hm - > firstsegy , max [ 1 ] , hm - > maxsegy ) ;
for ( y = min [ 1 ] ; y < max [ 1 ] ; y + + )
{
for ( x = min [ 0 ] ; x < max [ 0 ] ; x + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , x , y , TGS_WAITLOAD ) ;
2012-08-04 11:28:39 +00:00
if ( ! s )
continue ;
mint [ 0 ] = floor ( ( center [ 0 ] - radius ) * ( SECTHEIGHTSIZE - 1 ) / ( hm - > sectionsize ) + ( CHUNKBIAS - x ) * ( SECTHEIGHTSIZE - 1 ) ) ;
mint [ 1 ] = floor ( ( center [ 1 ] - radius ) * ( SECTHEIGHTSIZE - 1 ) / ( hm - > sectionsize ) + ( CHUNKBIAS - y ) * ( SECTHEIGHTSIZE - 1 ) ) ;
maxt [ 0 ] = ceil ( ( center [ 0 ] + radius ) * ( SECTHEIGHTSIZE - 1 ) / ( hm - > sectionsize ) + ( CHUNKBIAS - x ) * ( SECTHEIGHTSIZE - 1 ) ) ;
maxt [ 1 ] = ceil ( ( center [ 1 ] + radius ) * ( SECTHEIGHTSIZE - 1 ) / ( hm - > sectionsize ) + ( CHUNKBIAS - y ) * ( SECTHEIGHTSIZE - 1 ) ) ;
mint [ 0 ] = bound ( 0 , mint [ 0 ] , ( SECTHEIGHTSIZE - 1 ) ) ;
mint [ 1 ] = bound ( 0 , mint [ 1 ] , ( SECTHEIGHTSIZE - 1 ) ) ;
maxt [ 0 ] = bound ( 0 , maxt [ 0 ] , ( SECTHEIGHTSIZE - 1 ) ) ;
maxt [ 1 ] = bound ( 0 , maxt [ 1 ] , ( SECTHEIGHTSIZE - 1 ) ) ;
for ( ty = mint [ 1 ] ; ty < maxt [ 1 ] ; ty + + )
{
for ( tx = mint [ 0 ] ; tx < maxt [ 0 ] ; tx + + )
{
# ifndef STRICTEDGES
float d1 , d2 ;
d1 = fabs ( s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] - s - > heights [ ( tx + 1 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ) ;
d2 = fabs ( s - > heights [ ( tx + 1 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] - s - > heights [ ( tx + 0 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ) ;
if ( d1 < d2 )
{
vert [ 0 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 0 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 1 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 1 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 2 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 2 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 3 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 3 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 4 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 4 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 5 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 5 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 0 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 1 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
vert [ 2 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 3 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 4 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
vert [ 5 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
}
else
# endif
{
vert [ 0 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 0 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 1 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 1 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 2 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 2 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 3 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 3 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 4 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 0 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 4 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 5 ] [ 0 ] = ( x - CHUNKBIAS ) * hm - > sectionsize + ( tx + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ; vert [ 5 ] [ 1 ] = ( y - CHUNKBIAS ) * hm - > sectionsize + ( ty + 1 ) / ( float ) ( SECTHEIGHTSIZE - 1 ) * hm - > sectionsize ;
vert [ 0 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 1 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
vert [ 2 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 3 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ;
vert [ 4 ] [ 2 ] = s - > heights [ ( tx + 0 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
vert [ 5 ] [ 2 ] = s - > heights [ ( tx + 1 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ;
}
2015-03-03 00:14:43 +00:00
//fixme: per-section shaders for clutter info. this kinda sucks.
Fragment_ClipPoly ( dec , 3 , & vert [ 0 ] [ 0 ] , hm - > shader ) ;
Fragment_ClipPoly ( dec , 3 , & vert [ 3 ] [ 0 ] , hm - > shader ) ;
2012-08-04 11:28:39 +00:00
}
}
}
}
}
2012-04-09 19:12:12 +00:00
# endif
2007-05-25 22:16:29 +00:00
2006-03-04 20:43:48 +00:00
unsigned int Heightmap_PointContentsHM ( heightmap_t * hm , float clipmipsz , vec3_t org )
2005-08-26 22:49:36 +00:00
{
float x , y ;
float z , tz ;
int sx , sy ;
2013-11-21 23:02:28 +00:00
unsigned int holerow ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
unsigned int holebit ;
2012-04-09 19:12:12 +00:00
hmsection_t * s ;
2013-11-21 23:02:28 +00:00
struct hmwater_s * w ;
unsigned int contents ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
const float wbias = CHUNKBIAS * hm - > sectionsize ;
sx = ( org [ 0 ] + wbias ) / hm - > sectionsize ;
sy = ( org [ 1 ] + wbias ) / hm - > sectionsize ;
if ( sx < hm - > firstsegx | | sy < hm - > firstsegy )
return hm - > exteriorcontents ;
if ( sx > = hm - > maxsegx | | sy > = hm - > maxsegy )
return hm - > exteriorcontents ;
2015-07-30 16:26:15 +00:00
s = Terr_GetSection ( hm , sx , sy , TGS_TRYLOAD | TGS_ANYSTATE ) ;
if ( ! s | | s - > loadstate ! = TSLS_LOADED )
2005-08-26 22:49:36 +00:00
{
2015-07-30 16:26:15 +00:00
if ( s & & s - > loadstate = = TSLS_FAILED )
return hm - > exteriorcontents ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
return FTECONTENTS_SOLID ;
2005-08-26 22:49:36 +00:00
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
x = ( org [ 0 ] + wbias - ( sx * hm - > sectionsize ) ) * ( SECTHEIGHTSIZE - 1 ) / hm - > sectionsize ;
y = ( org [ 1 ] + wbias - ( sy * hm - > sectionsize ) ) * ( SECTHEIGHTSIZE - 1 ) / hm - > sectionsize ;
2012-04-09 19:12:12 +00:00
z = ( org [ 2 ] + clipmipsz ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( z < s - > minh - 16 )
return hm - > exteriorcontents ;
2005-08-26 22:49:36 +00:00
sx = x ; x - = sx ;
sy = y ; y - = sy ;
2014-02-13 23:37:33 +00:00
holerow = ( ( sy < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
holebit = 1u < < ( ( sx < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
2013-11-21 23:02:28 +00:00
if ( s - > holes [ holerow ] & ( 1u < < holebit ) )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
return FTECONTENTS_EMPTY ;
2005-08-26 22:49:36 +00:00
//made of two triangles:
if ( x + y > 1 ) //the 1, 1 triangle
{
float v1 , v2 , v3 ;
v3 = 1 - y ;
v2 = x + y - 1 ;
v1 = 1 - x ;
//0, 1
//1, 1
//1, 0
2012-04-09 19:12:12 +00:00
tz = ( s - > heights [ ( sx + 0 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] * v1 +
s - > heights [ ( sx + 1 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] * v2 +
s - > heights [ ( sx + 1 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] * v3 ) ;
2005-08-26 22:49:36 +00:00
}
else
{
float v1 , v2 , v3 ;
v1 = y ;
v2 = x ;
v3 = 1 - y - x ;
//0, 1
//1, 0
//0, 0
2012-04-09 19:12:12 +00:00
tz = ( s - > heights [ ( sx + 0 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] * v1 +
s - > heights [ ( sx + 1 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] * v2 +
s - > heights [ ( sx + 0 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] * v3 ) ;
2005-08-26 22:49:36 +00:00
}
if ( z < = tz )
return FTECONTENTS_SOLID ; //contained within
2013-11-21 23:02:28 +00:00
contents = FTECONTENTS_EMPTY ;
for ( w = s - > water ; w ; w = w - > next )
{
if ( w - > holes [ holerow ] & ( 1u < < holebit ) )
continue ;
if ( z < w - > maxheight ) //FIXME
contents | = w - > contentmask ;
}
return contents ;
2005-08-26 22:49:36 +00:00
}
2010-08-28 17:14:38 +00:00
unsigned int Heightmap_PointContents ( model_t * model , vec3_t axis [ 3 ] , vec3_t org )
2005-08-26 22:49:36 +00:00
{
heightmap_t * hm = model - > terrain ;
2015-04-14 23:12:17 +00:00
unsigned int cont ;
brushes_t * br ;
unsigned int i , j ;
float dist ;
cont = Heightmap_PointContentsHM ( hm , 0 , org ) ;
if ( cont & FTECONTENTS_SOLID )
return cont ;
for ( i = 0 ; i < hm - > numbrushes ; i + + )
{
br = & hm - > wbrushes [ i ] ;
for ( j = 0 ; j < br - > numplanes ; j + + )
{
/*
for ( k = 0 ; k < 3 ; k + + )
{
if ( in_normals [ j ] [ k ] < 0 )
best [ k ] = br - > maxs [ k ] ;
else
best [ k ] = br - > mins [ k ] ;
}
*/
dist = DotProduct ( org /*best*/ , br - > planes [ j ] ) ;
dist = br - > planes [ j ] [ 3 ] - dist ;
if ( dist < 0 )
break ;
}
if ( j = = br - > numplanes )
{
cont | = br - > contents ;
}
}
return cont ;
2005-08-26 22:49:36 +00:00
}
2010-08-28 17:14:38 +00:00
unsigned int Heightmap_NativeBoxContents ( model_t * model , int hulloverride , int frame , vec3_t axis [ 3 ] , vec3_t org , vec3_t mins , vec3_t maxs )
2006-03-06 01:41:09 +00:00
{
heightmap_t * hm = model - > terrain ;
return Heightmap_PointContentsHM ( hm , mins [ 2 ] , org ) ;
}
2005-08-26 22:49:36 +00:00
2005-09-21 01:21:35 +00:00
void Heightmap_Normal ( heightmap_t * hm , vec3_t org , vec3_t norm )
2005-08-26 22:49:36 +00:00
{
2012-07-20 01:46:05 +00:00
#if 0
2012-04-09 19:12:12 +00:00
norm [ 0 ] = 0 ;
norm [ 1 ] = 0 ;
norm [ 2 ] = 1 ;
2012-07-20 01:46:05 +00:00
# else
2005-08-26 22:49:36 +00:00
float x , y ;
int sx , sy ;
2011-05-20 04:10:46 +00:00
vec3_t d1 , d2 ;
2012-07-20 01:46:05 +00:00
const float wbias = CHUNKBIAS * hm - > sectionsize ;
hmsection_t * s ;
norm [ 0 ] = 0 ;
norm [ 1 ] = 0 ;
norm [ 2 ] = 1 ;
2005-08-26 22:49:36 +00:00
2012-07-20 01:46:05 +00:00
sx = ( org [ 0 ] + wbias ) / hm - > sectionsize ;
sy = ( org [ 1 ] + wbias ) / hm - > sectionsize ;
if ( sx < hm - > firstsegx | | sy < hm - > firstsegy )
return ;
if ( sx > = hm - > maxsegx | | sy > = hm - > maxsegy )
return ;
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx , sy , TGS_TRYLOAD ) ;
2012-07-20 01:46:05 +00:00
if ( ! s )
return ;
2005-08-26 22:49:36 +00:00
2012-07-20 01:46:05 +00:00
x = ( org [ 0 ] + wbias - ( sx * hm - > sectionsize ) ) * ( SECTHEIGHTSIZE - 1 ) / hm - > sectionsize ;
y = ( org [ 1 ] + wbias - ( sy * hm - > sectionsize ) ) * ( SECTHEIGHTSIZE - 1 ) / hm - > sectionsize ;
2012-08-04 11:28:39 +00:00
2005-08-26 22:49:36 +00:00
sx = x ; x - = sx ;
sy = y ; y - = sy ;
if ( x + y > 1 ) //the 1, 1 triangle
{
//0, 1
//1, 1
//1, 0
2012-07-20 01:46:05 +00:00
d1 [ 0 ] = ( hm - > sectionsize / SECTHEIGHTSIZE ) ;
2011-05-20 04:10:46 +00:00
d1 [ 1 ] = 0 ;
2012-07-20 01:46:05 +00:00
d1 [ 2 ] = ( s - > heights [ ( sx + 1 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] - s - > heights [ ( sx + 0 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] ) ;
2011-05-20 04:10:46 +00:00
d2 [ 0 ] = 0 ;
2012-07-20 01:46:05 +00:00
d2 [ 1 ] = ( hm - > sectionsize / SECTHEIGHTSIZE ) ;
d2 [ 2 ] = ( s - > heights [ ( sx + 1 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] - s - > heights [ ( sx + 1 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] ) ;
2005-08-26 22:49:36 +00:00
}
else
2012-04-09 19:12:12 +00:00
{ //the 0,0 triangle
2005-08-26 22:49:36 +00:00
//0, 1
//1, 0
//0, 0
2012-07-20 01:46:05 +00:00
d1 [ 0 ] = ( hm - > sectionsize / SECTHEIGHTSIZE ) ;
2011-05-20 04:10:46 +00:00
d1 [ 1 ] = 0 ;
2012-07-20 01:46:05 +00:00
d1 [ 2 ] = ( s - > heights [ ( sx + 1 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] - s - > heights [ ( sx + 0 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] ) ;
2011-05-20 04:10:46 +00:00
d2 [ 0 ] = 0 ;
2012-07-20 01:46:05 +00:00
d2 [ 1 ] = ( hm - > sectionsize / SECTHEIGHTSIZE ) ;
d2 [ 2 ] = ( s - > heights [ ( sx + 0 ) + ( sy + 1 ) * SECTHEIGHTSIZE ] - s - > heights [ ( sx + 0 ) + ( sy + 0 ) * SECTHEIGHTSIZE ] ) ;
2005-08-26 22:49:36 +00:00
}
2012-04-09 19:12:12 +00:00
VectorNormalize ( d1 ) ;
VectorNormalize ( d2 ) ;
2011-05-20 04:10:46 +00:00
CrossProduct ( d1 , d2 , norm ) ;
2005-08-26 22:49:36 +00:00
VectorNormalize ( norm ) ;
2012-07-20 01:46:05 +00:00
# endif
2005-08-26 22:49:36 +00:00
}
typedef struct {
vec3_t start ;
vec3_t end ;
vec3_t impact ;
2012-04-09 19:12:12 +00:00
vec4_t plane ;
2013-10-29 17:38:22 +00:00
vec3_t mins ;
vec3_t maxs ;
2015-04-14 23:12:17 +00:00
vec3_t absmins ;
vec3_t absmaxs ;
enum { ispoint , iscapsule , isbox } shape ;
2012-04-09 19:12:12 +00:00
float frac ;
2012-07-20 01:46:05 +00:00
float htilesize ;
2005-08-26 22:49:36 +00:00
heightmap_t * hm ;
int contents ;
2013-10-29 17:38:22 +00:00
int hitcontentsmask ;
2014-05-10 13:42:13 +00:00
trace_t * result ;
2005-08-26 22:49:36 +00:00
} hmtrace_t ;
2012-07-20 01:46:05 +00:00
2015-04-14 23:12:17 +00:00
static int Heightmap_Trace_Brush ( hmtrace_t * tr , vec4_t * planes , int numplanes )
2012-07-21 04:43:31 +00:00
{
qboolean startout ;
float * enterplane ;
double enterfrac , exitfrac , nearfrac = 0 ;
double enterdist = 0 ;
double dist , d1 , d2 , f ;
2015-04-14 23:12:17 +00:00
unsigned int i , j ;
vec3_t ofs ;
2012-07-21 04:43:31 +00:00
startout = false ;
enterplane = NULL ;
enterfrac = - 1 ;
exitfrac = 10 ;
for ( i = 0 ; i < numplanes ; i + + )
{
/*calculate the distance based upon the shape of the object we're tracing for*/
2015-04-14 23:12:17 +00:00
switch ( tr - > shape )
{
default :
case isbox : // general box case
// push the plane out apropriately for mins/maxs
// FIXME: use signbits into 8 way lookup for each mins/maxs
for ( j = 0 ; j < 3 ; j + + )
{
if ( planes [ i ] [ j ] < 0 )
ofs [ j ] = tr - > maxs [ j ] ;
else
ofs [ j ] = tr - > mins [ j ] ;
}
dist = DotProduct ( ofs , planes [ i ] ) ;
dist = planes [ i ] [ 3 ] - dist ;
break ;
// capsuledist(dist,plane,mins,maxs)
case ispoint : // special point case
dist = planes [ i ] [ 3 ] ;
break ;
}
2012-07-21 04:43:31 +00:00
d1 = DotProduct ( tr - > start , planes [ i ] ) - dist ;
d2 = DotProduct ( tr - > end , planes [ i ] ) - dist ;
//if we're fully outside any plane, then we cannot possibly enter the brush, skip to the next one
if ( d1 > 0 & & d2 > = d1 )
2015-04-14 23:12:17 +00:00
return false ;
2012-07-21 04:43:31 +00:00
if ( d1 > 0 )
startout = true ;
//if we're fully inside the plane, then whatever is happening is not relevent for this plane
if ( d1 < = 0 & & d2 < = 0 )
continue ;
f = ( d1 ) / ( d1 - d2 ) ;
if ( d1 > d2 )
{
//entered the brush. favour the furthest fraction to avoid extended edges (yay for convex shapes)
if ( enterfrac < f )
{
enterfrac = f ;
nearfrac = ( d1 - ( 0.03125 ) ) / ( d1 - d2 ) ;
enterplane = planes [ i ] ;
enterdist = dist ;
}
}
else
{
//left the brush, favour the nearest plane (smallest frac)
if ( exitfrac > f )
{
exitfrac = f ;
}
}
}
if ( ! startout )
{
tr - > frac = - 1 ;
2015-04-14 23:12:17 +00:00
return false ;
2012-07-21 04:43:31 +00:00
}
if ( enterfrac ! = - 1 & & enterfrac < exitfrac )
{
//impact!
if ( enterfrac < tr - > frac )
{
if ( nearfrac < 0 )
nearfrac = 0 ;
tr - > frac = nearfrac ; //enterfrac;
tr - > plane [ 3 ] = enterdist ;
VectorCopy ( enterplane , tr - > plane ) ;
2015-04-14 23:12:17 +00:00
return ( ( vec4_t * ) enterplane - planes ) + 1 ;
2012-07-21 04:43:31 +00:00
}
}
2015-04-14 23:12:17 +00:00
return false ;
2012-07-21 04:43:31 +00:00
}
2012-07-20 01:46:05 +00:00
//sx,sy are the tile coord
//note that tile SECTHEIGHTSIZE-1 does not exist, as the last sample overlaps the first sample of the next section
2012-07-21 04:43:31 +00:00
static void Heightmap_Trace_Square ( hmtrace_t * tr , int tx , int ty )
2005-08-26 22:49:36 +00:00
{
2012-04-09 19:12:12 +00:00
vec3_t d [ 2 ] ;
2012-07-20 01:46:05 +00:00
vec3_t p [ 4 ] ;
2012-04-09 19:12:12 +00:00
vec4_t n [ 5 ] ;
2012-07-21 04:43:31 +00:00
int t ;
2014-05-10 13:42:13 +00:00
int i ;
2012-04-09 19:12:12 +00:00
2012-07-21 04:43:31 +00:00
# ifndef STRICTEDGES
float d1 , d2 ;
# endif
2012-07-20 01:46:05 +00:00
int sx , sy ;
hmsection_t * s ;
2013-11-21 23:02:28 +00:00
unsigned int holerow ;
2012-07-21 04:43:31 +00:00
unsigned int holebit ;
2012-04-09 19:12:12 +00:00
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
sx = tx / ( SECTHEIGHTSIZE - 1 ) ;
sy = ty / ( SECTHEIGHTSIZE - 1 ) ;
if ( sx < tr - > hm - > firstsegx | | sx > = tr - > hm - > maxsegx )
2015-01-07 13:34:05 +00:00
return ; //s = NULL;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
else if ( sy < tr - > hm - > firstsegy | | sy > = tr - > hm - > maxsegy )
2015-01-07 13:34:05 +00:00
return ; //s = NULL;
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
else
2015-07-30 16:26:15 +00:00
s = Terr_GetSection ( tr - > hm , sx , sy , TGS_TRYLOAD | TGS_WAITLOAD | TGS_ANYSTATE ) ;
2012-07-20 01:46:05 +00:00
2015-07-30 16:26:15 +00:00
if ( ! s | | s - > loadstate ! = TSLS_LOADED )
2012-07-21 08:06:07 +00:00
{
2015-07-30 16:26:15 +00:00
if ( ( tr - > contents & tr - > hm - > exteriorcontents ) | | s - > loadstate ! = TSLS_FAILED )
{
//you're not allowed to walk into sections that have not loaded.
//might as well check the entire section instead of just one tile
Vector4Set ( n [ 0 ] , 1 , 0 , 0 , ( tx / ( SECTHEIGHTSIZE - 1 ) + 1 - CHUNKBIAS ) * tr - > hm - > sectionsize ) ;
Vector4Set ( n [ 1 ] , - 1 , 0 , 0 , - ( tx / ( SECTHEIGHTSIZE - 1 ) + 0 - CHUNKBIAS ) * tr - > hm - > sectionsize ) ;
Vector4Set ( n [ 2 ] , 0 , 1 , 0 , ( ty / ( SECTHEIGHTSIZE - 1 ) + 1 - CHUNKBIAS ) * tr - > hm - > sectionsize ) ;
Vector4Set ( n [ 3 ] , 0 , - 1 , 0 , - ( ty / ( SECTHEIGHTSIZE - 1 ) + 0 - CHUNKBIAS ) * tr - > hm - > sectionsize ) ;
Heightmap_Trace_Brush ( tr , n , 4 ) ;
}
2012-07-21 08:06:07 +00:00
return ;
}
2014-05-10 13:42:13 +00:00
2014-10-05 20:04:11 +00:00
if ( s - > traceseq ! = tr - > hm - > traceseq & & s - > numents )
2013-10-29 17:38:22 +00:00
{
2014-05-10 13:42:13 +00:00
s - > traceseq = tr - > hm - > traceseq ;
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( tr - > hm - > entitylock ) ;
2014-05-10 13:42:13 +00:00
for ( i = 0 ; i < s - > numents ; i + + )
2013-10-29 17:38:22 +00:00
{
2014-05-10 13:42:13 +00:00
vec3_t start_l , end_l ;
trace_t etr ;
model_t * model ;
int frame ;
if ( s - > ents [ i ] - > traceseq = = tr - > hm - > traceseq )
continue ;
s - > ents [ i ] - > traceseq = tr - > hm - > traceseq ;
model = s - > ents [ i ] - > ent . model ;
frame = s - > ents [ i ] - > ent . framestate . g [ FS_REG ] . frame [ 0 ] ;
2014-10-05 20:04:11 +00:00
//FIXME: IGNORE the entity if it isn't loaded yet? surely that's bad?
if ( ! model | | model - > loadstate ! = MLS_LOADED | | ! model - > funcs . NativeTrace )
2014-05-10 13:42:13 +00:00
continue ;
//figure out where on the submodel the trace is.
VectorSubtract ( tr - > start , s - > ents [ i ] - > ent . origin , start_l ) ;
VectorSubtract ( tr - > end , s - > ents [ i ] - > ent . origin , end_l ) ;
start_l [ 2 ] - = tr - > mins [ 2 ] ;
end_l [ 2 ] - = tr - > mins [ 2 ] ;
VectorScale ( start_l , s - > ents [ i ] - > ent . scale , start_l ) ;
VectorScale ( end_l , s - > ents [ i ] - > ent . scale , end_l ) ;
//skip if the local trace points are outside the model's bounds
/* for (j = 0; j < 3; j++)
{
if ( start_l [ j ] + tr - > mins [ j ] > model - > maxs [ j ] & & end_l [ j ] + tr - > mins [ j ] > model - > maxs [ j ] )
continue ;
if ( start_l [ j ] + tr - > maxs [ j ] < model - > mins [ j ] & & end_l [ j ] + tr - > maxs [ j ] < model - > mins [ j ] )
continue ;
}
*/
//do the trace
memset ( & etr , 0 , sizeof ( etr ) ) ;
etr . fraction = 1 ;
2015-04-14 23:12:17 +00:00
model - > funcs . NativeTrace ( model , 0 , frame , s - > ents [ i ] - > ent . axis , start_l , end_l , tr - > mins , tr - > maxs , tr - > shape = = iscapsule , tr - > hitcontentsmask , & etr ) ;
2014-05-10 13:42:13 +00:00
tr - > result - > startsolid | = etr . startsolid ;
tr - > result - > allsolid | = etr . allsolid ;
2013-10-29 17:38:22 +00:00
if ( etr . fraction < tr - > frac )
{
tr - > contents = etr . contents ;
tr - > frac = etr . fraction ;
tr - > plane [ 3 ] = etr . plane . dist ;
tr - > plane [ 0 ] = etr . plane . normal [ 0 ] ;
tr - > plane [ 1 ] = etr . plane . normal [ 1 ] ;
tr - > plane [ 2 ] = etr . plane . normal [ 2 ] ;
}
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( tr - > hm - > entitylock ) ;
2013-10-29 17:38:22 +00:00
}
2014-05-10 13:42:13 +00:00
2012-07-21 04:43:31 +00:00
sx = tx - CHUNKBIAS * ( SECTHEIGHTSIZE - 1 ) ;
sy = ty - CHUNKBIAS * ( SECTHEIGHTSIZE - 1 ) ;
2012-07-20 01:46:05 +00:00
tx = tx % ( SECTHEIGHTSIZE - 1 ) ;
ty = ty % ( SECTHEIGHTSIZE - 1 ) ;
2014-02-13 23:37:33 +00:00
holerow = ( ( ty < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
holebit = 1u < < ( ( tx < < 3 ) / ( SECTHEIGHTSIZE - 1 ) ) ;
2013-11-21 23:02:28 +00:00
if ( s - > holes [ holerow ] & holebit )
2012-07-21 04:43:31 +00:00
return ; //no collision with holes
2013-10-29 17:38:22 +00:00
switch ( tr - > hm - > mode )
2012-08-04 11:28:39 +00:00
{
2013-10-29 17:38:22 +00:00
case HMM_BLOCKS :
2012-08-04 11:28:39 +00:00
//left-most
Vector4Set ( n [ 0 ] , - 1 , 0 , 0 , - tr - > htilesize * ( sx + 0 ) ) ;
//bottom-most
Vector4Set ( n [ 1 ] , 0 , 1 , 0 , tr - > htilesize * ( sy + 1 ) ) ;
//right-most
Vector4Set ( n [ 2 ] , 1 , 0 , 0 , tr - > htilesize * ( sx + 1 ) ) ;
//top-most
Vector4Set ( n [ 3 ] , 0 , - 1 , 0 , - tr - > htilesize * ( sy + 0 ) ) ;
//top
Vector4Set ( n [ 4 ] , 0 , 0 , 1 , s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ) ;
Heightmap_Trace_Brush ( tr , n , 5 ) ;
return ;
2013-10-29 17:38:22 +00:00
case HMM_TERRAIN :
VectorSet ( p [ 0 ] , tr - > htilesize * ( sx + 0 ) , tr - > htilesize * ( sy + 0 ) , s - > heights [ ( tx + 0 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ) ;
VectorSet ( p [ 1 ] , tr - > htilesize * ( sx + 1 ) , tr - > htilesize * ( sy + 0 ) , s - > heights [ ( tx + 1 ) + ( ty + 0 ) * SECTHEIGHTSIZE ] ) ;
VectorSet ( p [ 2 ] , tr - > htilesize * ( sx + 0 ) , tr - > htilesize * ( sy + 1 ) , s - > heights [ ( tx + 0 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ) ;
VectorSet ( p [ 3 ] , tr - > htilesize * ( sx + 1 ) , tr - > htilesize * ( sy + 1 ) , s - > heights [ ( tx + 1 ) + ( ty + 1 ) * SECTHEIGHTSIZE ] ) ;
2012-08-04 11:28:39 +00:00
2012-07-21 04:43:31 +00:00
# ifndef STRICTEDGES
2013-10-29 17:38:22 +00:00
d1 = fabs ( p [ 0 ] [ 2 ] - p [ 3 ] [ 2 ] ) ;
d2 = fabs ( p [ 1 ] [ 2 ] - p [ 2 ] [ 2 ] ) ;
if ( d1 < d2 )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
for ( t = 0 ; t < 2 ; t + + )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
/*generate the brush (in world space*/
if ( t = = 0 )
{
VectorSubtract ( p [ 3 ] , p [ 2 ] , d [ 0 ] ) ;
VectorSubtract ( p [ 2 ] , p [ 0 ] , d [ 1 ] ) ;
//left-most
Vector4Set ( n [ 0 ] , - 1 , 0 , 0 , - tr - > htilesize * ( sx + 0 ) ) ;
//bottom-most
Vector4Set ( n [ 1 ] , 0 , 1 , 0 , tr - > htilesize * ( sy + 1 ) ) ;
//top-right
VectorSet ( n [ 2 ] , 0.70710678118654752440084436210485 , - 0.70710678118654752440084436210485 , 0 ) ;
n [ 2 ] [ 3 ] = DotProduct ( n [ 2 ] , p [ 0 ] ) ;
//top
VectorNormalize ( d [ 0 ] ) ;
VectorNormalize ( d [ 1 ] ) ;
CrossProduct ( d [ 0 ] , d [ 1 ] , n [ 3 ] ) ;
VectorNormalize ( n [ 3 ] ) ;
n [ 3 ] [ 3 ] = DotProduct ( n [ 3 ] , p [ 0 ] ) ;
//down
VectorNegate ( n [ 3 ] , n [ 4 ] ) ;
n [ 4 ] [ 3 ] = DotProduct ( n [ 4 ] , p [ 0 ] ) - n [ 4 ] [ 2 ] * TERRAINTHICKNESS ;
}
else
{
VectorSubtract ( p [ 1 ] , p [ 0 ] , d [ 0 ] ) ;
VectorSubtract ( p [ 3 ] , p [ 1 ] , d [ 1 ] ) ;
//right-most
Vector4Set ( n [ 0 ] , 1 , 0 , 0 , tr - > htilesize * ( sx + 1 ) ) ;
//top-most
Vector4Set ( n [ 1 ] , 0 , - 1 , 0 , - tr - > htilesize * ( sy + 0 ) ) ;
//bottom-left
VectorSet ( n [ 2 ] , - 0.70710678118654752440084436210485 , 0.70710678118654752440084436210485 , 0 ) ;
n [ 2 ] [ 3 ] = DotProduct ( n [ 2 ] , p [ 0 ] ) ;
//top
VectorNormalize ( d [ 0 ] ) ;
VectorNormalize ( d [ 1 ] ) ;
CrossProduct ( d [ 0 ] , d [ 1 ] , n [ 3 ] ) ;
VectorNormalize ( n [ 3 ] ) ;
n [ 3 ] [ 3 ] = DotProduct ( n [ 3 ] , p [ 0 ] ) ;
//down
VectorNegate ( n [ 3 ] , n [ 4 ] ) ;
n [ 4 ] [ 3 ] = DotProduct ( n [ 4 ] , p [ 0 ] ) - n [ 4 ] [ 2 ] * TERRAINTHICKNESS ;
}
Heightmap_Trace_Brush ( tr , n , 5 ) ;
2012-04-09 19:12:12 +00:00
}
}
2013-10-29 17:38:22 +00:00
else
2012-07-21 04:43:31 +00:00
# endif
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
for ( t = 0 ; t < 2 ; t + + )
2012-04-09 19:12:12 +00:00
{
2013-10-29 17:38:22 +00:00
/*generate the brush (in world space*/
if ( t = = 0 )
{
VectorSubtract ( p [ 1 ] , p [ 0 ] , d [ 0 ] ) ;
VectorSubtract ( p [ 2 ] , p [ 0 ] , d [ 1 ] ) ;
//left-most
Vector4Set ( n [ 0 ] , - 1 , 0 , 0 , - tr - > htilesize * ( sx + 0 ) ) ;
//top-most
Vector4Set ( n [ 1 ] , 0 , - 1 , 0 , - tr - > htilesize * ( sy + 0 ) ) ;
//bottom-right
VectorSet ( n [ 2 ] , 0.70710678118654752440084436210485 , 0.70710678118654752440084436210485 , 0 ) ;
n [ 2 ] [ 3 ] = DotProduct ( n [ 2 ] , p [ 1 ] ) ;
//top
VectorNormalize ( d [ 0 ] ) ;
VectorNormalize ( d [ 1 ] ) ;
CrossProduct ( d [ 0 ] , d [ 1 ] , n [ 3 ] ) ;
VectorNormalize ( n [ 3 ] ) ;
n [ 3 ] [ 3 ] = DotProduct ( n [ 3 ] , p [ 1 ] ) ;
//down
VectorNegate ( n [ 3 ] , n [ 4 ] ) ;
n [ 4 ] [ 3 ] = DotProduct ( n [ 4 ] , p [ 1 ] ) - n [ 4 ] [ 2 ] * TERRAINTHICKNESS ;
}
else
{
VectorSubtract ( p [ 3 ] , p [ 2 ] , d [ 0 ] ) ;
VectorSubtract ( p [ 3 ] , p [ 1 ] , d [ 1 ] ) ;
//right-most
Vector4Set ( n [ 0 ] , 1 , 0 , 0 , tr - > htilesize * ( sx + 1 ) ) ;
//bottom-most
Vector4Set ( n [ 1 ] , 0 , 1 , 0 , tr - > htilesize * ( sy + 1 ) ) ;
//top-left
VectorSet ( n [ 2 ] , - 0.70710678118654752440084436210485 , - 0.70710678118654752440084436210485 , 0 ) ;
n [ 2 ] [ 3 ] = DotProduct ( n [ 2 ] , p [ 1 ] ) ;
//top
VectorNormalize ( d [ 0 ] ) ;
VectorNormalize ( d [ 1 ] ) ;
CrossProduct ( d [ 0 ] , d [ 1 ] , n [ 3 ] ) ;
VectorNormalize ( n [ 3 ] ) ;
n [ 3 ] [ 3 ] = DotProduct ( n [ 3 ] , p [ 1 ] ) ;
//down
VectorNegate ( n [ 3 ] , n [ 4 ] ) ;
n [ 4 ] [ 3 ] = DotProduct ( n [ 4 ] , p [ 1 ] ) - n [ 4 ] [ 2 ] * TERRAINTHICKNESS ;
}
Heightmap_Trace_Brush ( tr , n , 5 ) ;
2012-07-21 04:43:31 +00:00
}
2005-08-26 22:49:36 +00:00
}
2013-10-29 17:38:22 +00:00
break ;
2005-08-26 22:49:36 +00:00
}
}
2012-07-20 01:46:05 +00:00
# define DIST_EPSILON 0
2005-08-26 22:49:36 +00:00
/*
Heightmap_TraceRecurse
Traces an arbitary box through a heightmap . ( interface with outside )
Why is recursion good ?
1 : it is consistant with bsp models . : )
2 : it allows us to use any size model we want
3 : we don ' t have to work out the height of the terrain every X units , but can be more precise .
Obviously , we don ' t care all that much about 1
*/
2014-09-17 03:04:08 +00:00
qboolean Heightmap_Trace ( struct model_s * model , int hulloverride , int frame , vec3_t mataxis [ 3 ] , vec3_t start , vec3_t end , vec3_t mins , vec3_t maxs , qboolean capsule , unsigned int against , struct trace_s * trace )
2005-08-26 22:49:36 +00:00
{
2012-07-20 01:46:05 +00:00
vec2_t pos , npos ;
qboolean nudge [ 2 ] ;
vec2_t dir ;
vec2_t frac ;
vec2_t emins ;
vec2_t emaxs ;
2015-04-14 23:12:17 +00:00
vec3_t tmp ;
2012-07-20 01:46:05 +00:00
int x , y ;
int axis ;
int breaklimit = 1000 ;
2012-07-21 05:52:35 +00:00
float wbias ;
2015-04-14 23:12:17 +00:00
float zbias ;
2005-08-26 22:49:36 +00:00
hmtrace_t hmtrace ;
hmtrace . hm = model - > terrain ;
2014-05-10 13:42:13 +00:00
hmtrace . hm - > traceseq + + ;
2012-07-20 01:46:05 +00:00
hmtrace . htilesize = hmtrace . hm - > sectionsize / ( SECTHEIGHTSIZE - 1 ) ;
hmtrace . frac = 1 ;
hmtrace . contents = 0 ;
hmtrace . plane [ 0 ] = 0 ;
hmtrace . plane [ 1 ] = 0 ;
2012-07-21 04:43:31 +00:00
hmtrace . plane [ 2 ] = 0 ;
2012-07-20 01:46:05 +00:00
hmtrace . plane [ 3 ] = 0 ;
2015-04-14 23:12:17 +00:00
if ( capsule )
{
hmtrace . shape = iscapsule ;
zbias = 0 ;
}
else if ( mins [ 0 ] | | mins [ 1 ] | | mins [ 2 ] | | maxs [ 0 ] | | maxs [ 1 ] | | maxs [ 2 ] )
{
hmtrace . shape = isbox ;
zbias = 0 ;
}
else
{
hmtrace . shape = ispoint ;
zbias = mins [ 2 ] ;
}
2005-08-26 22:49:36 +00:00
2012-07-20 01:46:05 +00:00
memset ( trace , 0 , sizeof ( * trace ) ) ;
trace - > fraction = 1 ;
2014-05-10 13:42:13 +00:00
hmtrace . result = trace ;
2012-07-20 01:46:05 +00:00
//to tile space
2012-07-21 04:43:31 +00:00
hmtrace . start [ 0 ] = ( start [ 0 ] ) ;
hmtrace . start [ 1 ] = ( start [ 1 ] ) ;
2015-04-14 23:12:17 +00:00
hmtrace . start [ 2 ] = ( start [ 2 ] + zbias ) ;
2012-07-21 04:43:31 +00:00
hmtrace . end [ 0 ] = ( end [ 0 ] ) ;
hmtrace . end [ 1 ] = ( end [ 1 ] ) ;
2015-04-14 23:12:17 +00:00
hmtrace . end [ 2 ] = ( end [ 2 ] + zbias ) ;
2012-04-09 19:12:12 +00:00
2012-07-20 01:46:05 +00:00
dir [ 0 ] = ( hmtrace . end [ 0 ] - hmtrace . start [ 0 ] ) / hmtrace . htilesize ;
dir [ 1 ] = ( hmtrace . end [ 1 ] - hmtrace . start [ 1 ] ) / hmtrace . htilesize ;
2012-07-21 04:43:31 +00:00
pos [ 0 ] = ( hmtrace . start [ 0 ] + CHUNKBIAS * hmtrace . hm - > sectionsize ) / hmtrace . htilesize ;
pos [ 1 ] = ( hmtrace . start [ 1 ] + CHUNKBIAS * hmtrace . hm - > sectionsize ) / hmtrace . htilesize ;
2012-07-21 05:52:35 +00:00
wbias = CHUNKBIAS * hmtrace . hm - > sectionsize ;
2012-07-20 01:46:05 +00:00
2013-06-29 23:46:34 +00:00
emins [ 0 ] = ( mins [ 0 ] - 1.5 ) / hmtrace . htilesize ;
emins [ 1 ] = ( mins [ 1 ] - 1.5 ) / hmtrace . htilesize ;
emaxs [ 0 ] = ( maxs [ 0 ] + 1.5 ) / hmtrace . htilesize ;
emaxs [ 1 ] = ( maxs [ 1 ] + 1.5 ) / hmtrace . htilesize ;
2012-07-20 01:46:05 +00:00
2013-10-29 17:38:22 +00:00
VectorCopy ( mins , hmtrace . mins ) ;
VectorCopy ( maxs , hmtrace . maxs ) ;
2015-04-14 23:12:17 +00:00
//determine extents
VectorAdd ( hmtrace . start , hmtrace . mins , hmtrace . absmins ) ;
VectorCopy ( hmtrace . absmins , hmtrace . absmaxs ) ;
VectorAdd ( hmtrace . start , hmtrace . maxs , tmp ) ;
AddPointToBounds ( tmp , hmtrace . absmins , hmtrace . absmaxs ) ;
VectorAdd ( hmtrace . end , hmtrace . mins , tmp ) ;
AddPointToBounds ( tmp , hmtrace . absmins , hmtrace . absmaxs ) ;
VectorAdd ( hmtrace . end , hmtrace . maxs , tmp ) ;
AddPointToBounds ( tmp , hmtrace . absmins , hmtrace . absmaxs ) ;
hmtrace . absmaxs [ 0 ] + = 1 ;
hmtrace . absmaxs [ 1 ] + = 1 ;
hmtrace . absmaxs [ 2 ] + = 1 ;
hmtrace . absmins [ 0 ] - = 1 ;
hmtrace . absmins [ 1 ] - = 1 ;
hmtrace . absmins [ 2 ] - = 1 ;
2012-07-20 01:46:05 +00:00
/*fixme:
set pos to the leading corner instead
on boundary changes , scan across multiple blocks
*/
//make sure the start tile is valid
2015-06-12 14:44:50 +00:00
for ( y = pos [ 1 ] + emins [ 1 ] ; y < = ( int ) ( pos [ 1 ] + emaxs [ 1 ] ) ; y + + )
for ( x = pos [ 0 ] + emins [ 0 ] ; x < = ( int ) ( pos [ 0 ] + emaxs [ 0 ] ) ; x + + )
2012-07-20 01:46:05 +00:00
Heightmap_Trace_Square ( & hmtrace , x , y ) ;
for ( ; ; )
{
if ( breaklimit - - < 0 )
break ;
for ( axis = 0 ; axis < 2 ; axis + + )
{
if ( dir [ axis ] > 0 )
{
nudge [ axis ] = false ;
npos [ axis ] = pos [ axis ] + 1 - ( pos [ axis ] - ( int ) pos [ axis ] ) ;
2012-07-21 05:52:35 +00:00
frac [ axis ] = ( npos [ axis ] * hmtrace . htilesize - wbias - hmtrace . start [ axis ] ) / ( hmtrace . end [ axis ] - hmtrace . start [ axis ] ) ;
2012-07-20 01:46:05 +00:00
}
else if ( dir [ axis ] < 0 )
{
npos [ axis ] = pos [ axis ] ;
nudge [ axis ] = ( float ) ( int ) pos [ axis ] = = pos [ axis ] ;
npos [ axis ] = ( int ) npos [ axis ] ;
2012-07-21 05:52:35 +00:00
frac [ axis ] = ( npos [ axis ] * hmtrace . htilesize - wbias - hmtrace . start [ axis ] ) / ( hmtrace . end [ axis ] - hmtrace . start [ axis ] ) ;
2012-07-20 01:46:05 +00:00
npos [ axis ] - = nudge [ axis ] ;
}
else
2012-09-30 05:52:03 +00:00
frac [ axis ] = 1000000000000000.0 ;
2012-07-20 01:46:05 +00:00
}
//which side are we going down?
if ( frac [ 0 ] < frac [ 1 ] )
axis = 0 ;
else
axis = 1 ;
2005-08-26 22:49:36 +00:00
2012-07-20 01:46:05 +00:00
if ( frac [ axis ] > = 1 )
break ;
//touch the neighbour(s)
if ( dir [ axis ] > 0 )
{
pos [ axis ] = ( int ) pos [ axis ] + 1 ;
pos [ axis ] = npos [ axis ] ;
Heightmap_Trace_Square ( & hmtrace , pos [ 0 ] , pos [ 1 ] ) ;
}
else
{
pos [ axis ] = npos [ axis ] ;
Heightmap_Trace_Square ( & hmtrace , pos [ 0 ] , pos [ 1 ] ) ;
}
//and make sure our position on the other axis is correct, for the next time around the loop
if ( frac [ axis ] > hmtrace . frac )
break ;
2012-07-21 05:52:35 +00:00
pos [ ! axis ] = ( ( hmtrace . end [ ! axis ] * frac [ axis ] ) + ( hmtrace . start [ ! axis ] * ( 1 - frac [ axis ] ) ) + CHUNKBIAS * hmtrace . hm - > sectionsize ) / hmtrace . htilesize ;
2012-07-20 01:46:05 +00:00
}
2012-04-09 19:12:12 +00:00
2015-01-07 13:34:05 +00:00
{
brushes_t * brushes = hmtrace . hm - > wbrushes ;
int count = hmtrace . hm - > numbrushes ;
2015-04-14 23:12:17 +00:00
for ( count = hmtrace . hm - > numbrushes ; count - - > 0 ; brushes + + )
2015-01-07 13:34:05 +00:00
{
if ( brushes - > contents & against )
2015-04-14 23:12:17 +00:00
{
int face ;
if ( hmtrace . absmaxs [ 0 ] < brushes - > mins [ 0 ] | |
hmtrace . absmaxs [ 1 ] < brushes - > mins [ 1 ] | |
hmtrace . absmaxs [ 2 ] < brushes - > mins [ 2 ] )
continue ;
if ( hmtrace . absmins [ 0 ] > brushes - > maxs [ 0 ] | |
hmtrace . absmins [ 1 ] > brushes - > maxs [ 1 ] | |
hmtrace . absmins [ 2 ] > brushes - > maxs [ 2 ] )
continue ;
face = Heightmap_Trace_Brush ( & hmtrace , brushes - > planes , brushes - > numplanes ) ;
if ( face )
{
trace - > brush_id = brushes - > id ;
trace - > brush_face = face ;
}
}
2015-01-07 13:34:05 +00:00
}
}
2012-04-09 19:12:12 +00:00
trace - > plane . dist = hmtrace . plane [ 3 ] ;
trace - > plane . normal [ 0 ] = hmtrace . plane [ 0 ] ;
trace - > plane . normal [ 1 ] = hmtrace . plane [ 1 ] ;
trace - > plane . normal [ 2 ] = hmtrace . plane [ 2 ] ;
if ( hmtrace . frac = = - 1 )
{
2013-06-29 23:46:34 +00:00
trace - > fraction = 0 ;
2012-04-09 19:12:12 +00:00
trace - > startsolid = true ;
trace - > allsolid = true ;
2012-07-20 01:46:05 +00:00
VectorCopy ( start , trace - > endpos ) ;
2012-04-09 19:12:12 +00:00
}
else
{
2012-07-20 01:46:05 +00:00
if ( hmtrace . frac < 0 )
hmtrace . frac = 0 ;
2012-04-09 19:12:12 +00:00
trace - > fraction = hmtrace . frac ;
VectorInterpolate ( start , hmtrace . frac , end , trace - > endpos ) ;
}
return trace - > fraction < 1 ;
2005-08-26 22:49:36 +00:00
}
2006-03-06 01:41:09 +00:00
2014-02-07 08:38:40 +00:00
typedef struct
{
int id ;
int x , y ;
} hmpvs_t ;
2009-07-11 18:23:57 +00:00
unsigned int Heightmap_FatPVS ( model_t * mod , vec3_t org , qbyte * pvsbuffer , unsigned int pvssize , qboolean add )
2005-08-26 22:49:36 +00:00
{
2014-02-07 08:38:40 +00:00
//embed the org onto the pvs
hmpvs_t * hmpvs = ( hmpvs_t * ) pvsbuffer ;
hmpvs - > id = 0xdeadbeef ;
hmpvs - > x = org [ 0 ] ;
hmpvs - > y = org [ 1 ] ;
return sizeof ( * hmpvs ) ;
2005-08-26 22:49:36 +00:00
}
2007-08-30 18:27:39 +00:00
# ifndef CLIENTONLY
2010-07-11 02:22:39 +00:00
qboolean Heightmap_EdictInFatPVS ( model_t * mod , struct pvscache_s * edict , qbyte * pvsdata )
2005-08-26 22:49:36 +00:00
{
2014-02-07 08:38:40 +00:00
int x , y ;
hmpvs_t * hmpvs = ( hmpvs_t * ) pvsdata ;
//check distance
x = edict - > areanum - hmpvs - > x ;
y = edict - > areanum2 - hmpvs - > y ;
return ( x * x + y * y ) < 4096 * 4096 ;
2005-08-26 22:49:36 +00:00
}
2010-07-11 02:22:39 +00:00
void Heightmap_FindTouchedLeafs ( model_t * mod , pvscache_t * ent , float * mins , float * maxs )
2005-08-26 22:49:36 +00:00
{
2014-02-07 08:38:40 +00:00
ent - > areanum = ( mins [ 0 ] + maxs [ 0 ] ) * 0.5 ;
ent - > areanum2 = ( mins [ 1 ] + maxs [ 1 ] ) * 0.5 ;
2005-08-26 22:49:36 +00:00
}
2007-08-30 18:27:39 +00:00
# endif
2005-08-26 22:49:36 +00:00
2006-09-17 00:59:22 +00:00
void Heightmap_LightPointValues ( model_t * mod , vec3_t point , vec3_t res_diffuse , vec3_t res_ambient , vec3_t res_dir )
2005-08-26 22:49:36 +00:00
{
2012-04-09 19:12:12 +00:00
float time = realtime ;
res_diffuse [ 0 ] = 128 ;
res_diffuse [ 1 ] = 128 ;
res_diffuse [ 2 ] = 128 ;
res_ambient [ 0 ] = 64 ;
res_ambient [ 1 ] = 64 ;
res_ambient [ 2 ] = 64 ;
2015-04-14 23:12:17 +00:00
res_dir [ 0 ] = 1 ; //sin(time);
res_dir [ 1 ] = 0 ; //cos(time);
res_dir [ 2 ] = 0 ; //sin(time);
2012-04-09 19:12:12 +00:00
VectorNormalize ( res_dir ) ;
2005-08-26 22:49:36 +00:00
}
void Heightmap_StainNode ( mnode_t * node , float * parms )
{
}
void Heightmap_MarkLights ( dlight_t * light , int bit , mnode_t * node )
{
}
2014-05-23 02:02:51 +00:00
qbyte * Heightmap_ClusterPVS ( model_t * model , int num , qbyte * buffer , unsigned int buffersize )
2005-08-26 22:49:36 +00:00
{
2014-05-23 02:02:51 +00:00
return NULL ;
// static qbyte heightmappvs = 255;
// return &heightmappvs;
2005-08-26 22:49:36 +00:00
}
2014-05-23 02:02:51 +00:00
int Heightmap_ClusterForPoint ( model_t * model , vec3_t point )
2005-08-26 22:49:36 +00:00
{
2014-05-23 02:02:51 +00:00
return - 1 ;
2005-08-26 22:49:36 +00:00
}
2012-04-09 19:12:12 +00:00
# ifndef SERVERONLY
static unsigned char * ted_getlightmap ( hmsection_t * s , int idx )
{
unsigned char * lm ;
int x = idx % SECTTEXSIZE , y = idx / SECTTEXSIZE ;
if ( s - > lightmap < 0 )
{
2013-03-31 04:21:08 +00:00
Terr_LoadSection ( s - > hmmod , s , x , y , true ) ;
2013-10-29 17:38:22 +00:00
Terr_InitLightmap ( s , true ) ;
2012-04-09 19:12:12 +00:00
}
2006-03-06 01:41:09 +00:00
2012-07-20 01:46:05 +00:00
s - > flags | = TSF_EDITED ;
2012-04-09 19:12:12 +00:00
lightmap [ s - > lightmap ] - > modified = true ;
lightmap [ s - > lightmap ] - > rectchange . l = 0 ;
lightmap [ s - > lightmap ] - > rectchange . t = 0 ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
lightmap [ s - > lightmap ] - > rectchange . w = HMLMSTRIDE ;
lightmap [ s - > lightmap ] - > rectchange . h = HMLMSTRIDE ;
2012-04-09 19:12:12 +00:00
lm = lightmap [ s - > lightmap ] - > lightmaps ;
2012-08-04 11:28:39 +00:00
lm + = ( ( s - > lmy + y ) * HMLMSTRIDE + ( s - > lmx + x ) ) * lightmap_bytes ;
2012-04-09 19:12:12 +00:00
return lm ;
}
2012-07-20 01:46:05 +00:00
static void ted_dorelight ( heightmap_t * hm )
{
unsigned char * lm = ted_getlightmap ( hm - > relight , 0 ) ;
int x , y ;
# define EXPAND 2
vec3_t surfnorms [ ( SECTTEXSIZE + EXPAND * 2 ) * ( SECTTEXSIZE + EXPAND * 2 ) ] ;
// float scaletab[EXPAND*2*EXPAND*2];
vec3_t ldir = { 0.4 , 0.7 , 2 } ;
hmsection_t * s = hm - > relight ;
2012-07-21 08:06:07 +00:00
s - > flags & = ~ TSF_RELIGHT ;
2012-07-20 01:46:05 +00:00
hm - > relight = NULL ;
2012-09-30 05:52:03 +00:00
if ( s - > lightmap < 0 )
return ;
2012-07-20 01:46:05 +00:00
for ( y = - EXPAND ; y < SECTTEXSIZE + EXPAND ; y + + )
for ( x = - EXPAND ; x < SECTTEXSIZE + EXPAND ; x + + )
{
vec3_t pos ;
pos [ 0 ] = hm - > relightmin [ 0 ] + ( x * hm - > sectionsize / ( SECTTEXSIZE - 1 ) ) ;
pos [ 1 ] = hm - > relightmin [ 1 ] + ( y * hm - > sectionsize / ( SECTTEXSIZE - 1 ) ) ;
pos [ 2 ] = 0 ;
Heightmap_Normal ( s - > hmmod , pos , surfnorms [ x + EXPAND + ( y + EXPAND ) * ( SECTTEXSIZE + EXPAND * 2 ) ] ) ;
}
VectorNormalize ( ldir ) ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + , lm + = ( HMLMSTRIDE - SECTTEXSIZE ) * 4 )
for ( x = 0 ; x < SECTTEXSIZE ; x + + , lm + = 4 )
{
vec3_t norm ;
float d ;
int sx , sy ;
VectorClear ( norm ) ;
for ( sy = - EXPAND ; sy < = EXPAND ; sy + + )
for ( sx = - EXPAND ; sx < = EXPAND ; sx + + )
{
d = sqrt ( ( EXPAND * 2 + 1 ) * ( EXPAND * 2 + 1 ) - sx * sx + sy * sy ) ;
VectorMA ( norm , d , surfnorms [ x + sx + EXPAND + ( y + sy + EXPAND ) * ( SECTTEXSIZE + EXPAND * 2 ) ] , norm ) ;
}
VectorNormalize ( norm ) ;
d = DotProduct ( ldir , norm ) ;
if ( d < 0 )
d = 0 ;
// lm[0] = norm[0]*127 + 128;
// lm[1] = norm[1]*127 + 128;
// lm[2] = norm[2]*127 + 128;
2014-10-05 20:04:11 +00:00
lm [ 3 ] = 127 + d * 128 ;
2012-07-20 01:46:05 +00:00
}
2012-09-30 05:52:03 +00:00
lightmap [ s - > lightmap ] - > modified = true ;
lightmap [ s - > lightmap ] - > rectchange . l = 0 ;
lightmap [ s - > lightmap ] - > rectchange . t = 0 ;
lightmap [ s - > lightmap ] - > rectchange . w = HMLMSTRIDE ;
lightmap [ s - > lightmap ] - > rectchange . h = HMLMSTRIDE ;
2012-07-20 01:46:05 +00:00
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
static void ted_sethole ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
{
2014-02-13 23:37:33 +00:00
unsigned int row = idx / 9 ;
unsigned int col = idx % 9 ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
unsigned int bit ;
unsigned int mask ;
2014-02-13 23:37:33 +00:00
if ( row = = 8 | | col = = 8 )
return ; //meh, our painting function is written with an overlap of 1
if ( w < = 0 )
return ;
mask = 1u < < ( col ) ;
if ( * ( float * ) ctx > 0 )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
bit = mask ;
else
bit = 0 ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED ;
2013-11-21 23:02:28 +00:00
s - > holes [ row ] = ( s - > holes [ row ] & ~ mask ) | bit ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2012-04-09 19:12:12 +00:00
static void ted_heighttally ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
{
/*raise the terrain*/
( ( float * ) ctx ) [ 0 ] + = s - > heights [ idx ] * w ;
( ( float * ) ctx ) [ 1 ] + = w ;
}
static void ted_heightsmooth ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
{
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED | TSF_RELIGHT ;
2012-04-09 19:12:12 +00:00
/*interpolate the terrain towards a certain value*/
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( IS_NAN ( s - > heights [ idx ] ) )
s - > heights [ idx ] = * ( float * ) ctx ;
else
s - > heights [ idx ] = s - > heights [ idx ] * ( 1 - w ) + w * * ( float * ) ctx ;
2012-04-09 19:12:12 +00:00
}
static void ted_heightraise ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float strength )
{
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED | TSF_RELIGHT ;
2012-04-09 19:12:12 +00:00
/*raise the terrain*/
s - > heights [ idx ] + = strength ;
}
static void ted_heightset ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float strength )
{
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED | TSF_RELIGHT ;
2012-04-09 19:12:12 +00:00
/*set the terrain to a specific value*/
s - > heights [ idx ] = * ( float * ) ctx ;
}
2013-11-21 23:02:28 +00:00
static void ted_waterset ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float strength )
{
struct hmwater_s * w = s - > water ;
if ( ! w )
w = Terr_GenerateWater ( s , * ( float * ) ctx ) ;
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED ;
//FIXME: water doesn't render properly. don't let people make dodgy water regions because they can't see it.
//this is temp code.
//for (idx = 0; idx < 9*9; idx++)
//w->heights[idx] = *(float*)ctx;
//end fixme
w - > heights [ idx ] = * ( float * ) ctx ;
if ( w - > minheight > w - > heights [ idx ] )
w - > minheight = w - > heights [ idx ] ;
if ( w - > maxheight < w - > heights [ idx ] )
w - > maxheight = w - > heights [ idx ] ;
//FIXME: what about holes?
}
2014-06-16 20:45:44 +00:00
static void ted_texconcentrate ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
2012-04-09 19:12:12 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_EDITED ;
2012-04-09 19:12:12 +00:00
/*concentrate the lightmap values to a single channel*/
if ( lm [ 0 ] > lm [ 1 ] & & lm [ 0 ] > lm [ 2 ] & & lm [ 0 ] > ( 255 - ( lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ) )
{
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + 255 * ( w ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + 0 * ( w ) ;
}
else if ( lm [ 1 ] > lm [ 2 ] & & lm [ 1 ] > ( 255 - ( lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ) )
{
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + 255 * ( w ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + 0 * ( w ) ;
}
else if ( lm [ 2 ] > ( 255 - ( lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ) )
{
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + 255 * ( w ) ;
}
else
{
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + 0 * ( w ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + 0 * ( w ) ;
}
}
2014-06-16 20:45:44 +00:00
static void ted_texnoise ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
2012-04-09 19:12:12 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
vec4_t v ;
float sc ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_EDITED ;
2012-04-09 19:12:12 +00:00
/*randomize the lightmap somewhat (you'll probably want to concentrate it a bit after)*/
v [ 0 ] = ( rand ( ) & 255 ) ;
v [ 1 ] = ( rand ( ) & 255 ) ;
v [ 2 ] = ( rand ( ) & 255 ) ;
v [ 3 ] = ( rand ( ) & 255 ) ;
sc = v [ 0 ] + v [ 1 ] + v [ 2 ] + v [ 3 ] ;
Vector4Scale ( v , 255 / sc , v ) ;
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + ( v [ 0 ] * ( w ) ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + ( v [ 1 ] * ( w ) ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + ( v [ 2 ] * ( w ) ) ;
}
2014-06-16 20:45:44 +00:00
static void ted_texpaint ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
2014-03-30 08:55:06 +00:00
const char * texname = ctx ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
int t ;
2015-06-12 14:44:50 +00:00
vec4_t newval ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( w > 1 )
w = 1 ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_EDITED ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
for ( t = 0 ; t < 4 ; t + + )
{
if ( ! strncmp ( s - > texname [ t ] , texname , sizeof ( s - > texname [ t ] ) - 1 ) )
{
2015-06-12 14:44:50 +00:00
int extra ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
newval [ 0 ] = ( t = = 0 ) ;
newval [ 1 ] = ( t = = 1 ) ;
newval [ 2 ] = ( t = = 2 ) ;
2015-06-12 14:44:50 +00:00
newval [ 3 ] = ( t = = 3 ) ;
extra = 255 - ( lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + ( 255 * newval [ 0 ] * ( w ) ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + ( 255 * newval [ 1 ] * ( w ) ) ;
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + ( 255 * newval [ 2 ] * ( w ) ) ;
2015-06-12 14:44:50 +00:00
extra = extra * ( 1 - w ) + ( 255 * newval [ 3 ] * ( w ) ) ;
//the extra stuff is to cope with numerical precision. add any lost values to the new texture instead of the implicit one
extra = 255 - ( extra + lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ;
if ( t ! = 3 )
lm [ 2 - t ] + = extra ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
return ;
}
}
2012-07-22 02:56:22 +00:00
/*special handling to make a section accept the first texture painted on it as a base texture. no more chessboard*/
if ( ! * s - > texname [ 0 ] & & ! * s - > texname [ 1 ] & & ! * s - > texname [ 2 ] & & ! * s - > texname [ 3 ] )
{
Q_strncpyz ( s - > texname [ 3 ] , texname , sizeof ( s - > texname [ 3 ] ) ) ;
Terr_LoadSectionTextures ( s ) ;
for ( idx = 0 ; idx < SECTTEXSIZE * SECTTEXSIZE ; idx + + )
{
lm = ted_getlightmap ( s , idx ) ;
lm [ 2 ] = 0 ;
lm [ 1 ] = 0 ;
lm [ 0 ] = 0 ;
}
return ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
for ( t = 0 ; t < 4 ; t + + )
{
if ( ! * s - > texname [ t ] )
{
Q_strncpyz ( s - > texname [ t ] , texname , sizeof ( s - > texname [ t ] ) ) ;
newval [ 0 ] = ( t = = 0 ) ;
newval [ 1 ] = ( t = = 1 ) ;
newval [ 2 ] = ( t = = 2 ) ;
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + ( 255 * newval [ 0 ] * ( w ) ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + ( 255 * newval [ 1 ] * ( w ) ) ;
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + ( 255 * newval [ 2 ] * ( w ) ) ;
Terr_LoadSectionTextures ( s ) ;
return ;
}
}
}
2012-07-20 01:46:05 +00:00
2014-06-16 20:45:44 +00:00
static void ted_texreplace ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
{
if ( w > 0 )
ted_texpaint ( ctx , s , idx , wx , wy , 1 ) ;
}
2012-07-20 01:46:05 +00:00
/*
2014-06-16 20:45:44 +00:00
static void ted_texlight ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
2012-07-20 01:46:05 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
vec3_t pos , pos2 ;
vec3_t norm , tnorm ;
vec3_t ldir = { 0.4 , 0.7 , 2 } ;
float d ;
int x , y ;
trace_t tr ;
VectorClear ( norm ) ;
for ( y = - 4 ; y < 4 ; y + + )
for ( x = - 4 ; x < 4 ; x + + )
{
pos [ 0 ] = wx - ( CHUNKBIAS + x / 64.0 ) * s - > hmmod - > sectionsize ;
pos [ 1 ] = wy - ( CHUNKBIAS + y / 64.0 ) * s - > hmmod - > sectionsize ;
#if 0
pos [ 2 ] = 10000 ;
pos2 [ 0 ] = wx - ( CHUNKBIAS + x / 64.0 ) * s - > hmmod - > sectionsize ;
pos2 [ 1 ] = wy - ( CHUNKBIAS + y / 64.0 ) * s - > hmmod - > sectionsize ;
pos2 [ 2 ] = - 10000 ;
Heightmap_Trace ( cl . worldmodel , 0 , 0 , NULL , pos , pos2 , vec3_origin , vec3_origin , FTECONTENTS_SOLID , & tr ) ;
VectorCopy ( tr . plane . normal , tnorm ) ;
# else
Heightmap_Normal ( s - > hmmod , pos , tnorm ) ;
# endif
d = sqrt ( 32 - x * x + y * y ) ;
VectorMA ( norm , d , tnorm , norm ) ;
}
VectorNormalize ( ldir ) ;
VectorNormalize ( norm ) ;
d = DotProduct ( ldir , norm ) ;
if ( d < 0 )
d = 0 ;
lm [ 3 ] = d * 255 ;
}
*/
2014-06-16 20:45:44 +00:00
static void ted_texset ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
2012-04-09 19:12:12 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( w > 1 )
w = 1 ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_EDITED ;
2012-04-09 19:12:12 +00:00
lm [ 2 ] = lm [ 2 ] * ( 1 - w ) + ( 255 * ( ( float * ) ctx ) [ 0 ] * ( w ) ) ;
lm [ 1 ] = lm [ 1 ] * ( 1 - w ) + ( 255 * ( ( float * ) ctx ) [ 1 ] * ( w ) ) ;
lm [ 0 ] = lm [ 0 ] * ( 1 - w ) + ( 255 * ( ( float * ) ctx ) [ 2 ] * ( w ) ) ;
}
2014-06-16 20:45:44 +00:00
static void ted_textally ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
2012-04-09 19:12:12 +00:00
{
unsigned char * lm = ted_getlightmap ( s , idx ) ;
( ( float * ) ctx ) [ 0 ] + = lm [ 0 ] * w ;
( ( float * ) ctx ) [ 1 ] + = lm [ 1 ] * w ;
( ( float * ) ctx ) [ 2 ] + = lm [ 2 ] * w ;
( ( float * ) ctx ) [ 3 ] + = w ;
}
2012-08-04 11:28:39 +00:00
static void ted_tint ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float w )
{
float * col = s - > colours [ idx ] ;
float * newval = ctx ;
if ( w > 1 )
w = 1 ;
2012-11-29 13:37:48 +00:00
s - > flags | = TSF_NOTIFY | TSF_DIRTY | TSF_EDITED | TSF_HASCOLOURS ; /*dirty because of the vbo*/
2012-08-04 11:28:39 +00:00
col [ 0 ] = col [ 0 ] * ( 1 - w ) + ( newval [ 0 ] * ( w ) ) ;
col [ 1 ] = col [ 1 ] * ( 1 - w ) + ( newval [ 1 ] * ( w ) ) ;
col [ 2 ] = col [ 2 ] * ( 1 - w ) + ( newval [ 2 ] * ( w ) ) ;
col [ 3 ] = col [ 3 ] * ( 1 - w ) + ( newval [ 3 ] * ( w ) ) ;
}
2012-04-09 19:12:12 +00:00
2012-08-04 11:28:39 +00:00
enum
{
tid_linear ,
2014-06-16 20:45:44 +00:00
tid_exponential ,
tid_square_linear ,
tid_square_exponential ,
2014-10-05 20:04:11 +00:00
tid_flat
2012-08-04 11:28:39 +00:00
} ;
2012-04-09 19:12:12 +00:00
//calls 'func' for each tile upon the terrain. the 'tile' can be either height or texel
2012-08-04 11:28:39 +00:00
static void ted_itterate ( heightmap_t * hm , int distribution , float * pos , float radius , float strength , int steps , void ( * func ) ( void * ctx , hmsection_t * s , int idx , float wx , float wy , float strength ) , void * ctx )
2012-04-09 19:12:12 +00:00
{
int tx , ty ;
float wx , wy ;
float sc [ 2 ] ;
int min [ 2 ] , max [ 2 ] ;
int sx , sy ;
hmsection_t * s ;
float w , xd , yd ;
2014-06-16 20:45:44 +00:00
if ( radius < 0 )
{
radius * = - 1 ;
distribution | = 2 ;
}
2012-08-04 11:28:39 +00:00
min [ 0 ] = floor ( ( pos [ 0 ] - radius ) / ( hm - > sectionsize ) - 1.5 ) ;
min [ 1 ] = floor ( ( pos [ 1 ] - radius ) / ( hm - > sectionsize ) - 1.5 ) ;
max [ 0 ] = ceil ( ( pos [ 0 ] + radius ) / ( hm - > sectionsize ) + 1.5 ) ;
max [ 1 ] = ceil ( ( pos [ 1 ] + radius ) / ( hm - > sectionsize ) + 1.5 ) ;
2012-04-09 19:12:12 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
min [ 0 ] = bound ( hm - > firstsegx , min [ 0 ] , hm - > maxsegx ) ;
2012-08-04 11:28:39 +00:00
min [ 1 ] = bound ( hm - > firstsegy , min [ 1 ] , hm - > maxsegy ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
max [ 0 ] = bound ( hm - > firstsegx , max [ 0 ] , hm - > maxsegx ) ;
2012-08-04 11:28:39 +00:00
max [ 1 ] = bound ( hm - > firstsegy , max [ 1 ] , hm - > maxsegy ) ;
2012-04-09 19:12:12 +00:00
sc [ 0 ] = hm - > sectionsize / ( steps - 1 ) ;
sc [ 1 ] = hm - > sectionsize / ( steps - 1 ) ;
2012-08-04 11:28:39 +00:00
for ( sy = min [ 1 ] ; sy < max [ 1 ] ; sy + + )
2012-04-09 19:12:12 +00:00
{
2012-08-04 11:28:39 +00:00
for ( sx = min [ 0 ] ; sx < max [ 0 ] ; sx + + )
2012-04-09 19:12:12 +00:00
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx , sy , TGS_WAITLOAD | TGS_DEFAULTONFAIL ) ;
2012-04-09 19:12:12 +00:00
if ( ! s )
continue ;
2012-08-04 11:28:39 +00:00
for ( ty = 0 ; ty < steps ; ty + + )
2012-04-09 19:12:12 +00:00
{
2012-08-04 11:28:39 +00:00
wy = ( sy * ( steps - 1.0 ) + ty ) * sc [ 1 ] ;
yd = wy - pos [ 1 ] ; // - sc[1]/4;
for ( tx = 0 ; tx < steps ; tx + + )
2012-04-09 19:12:12 +00:00
{
/*both heights and textures have an overlapping/matching sample at the edge, there's no need for any half-pixels or anything here*/
wx = ( sx * ( steps - 1.0 ) + tx ) * sc [ 0 ] ;
2012-08-04 11:28:39 +00:00
xd = wx - pos [ 0 ] ; // - sc[0]/4;
2014-06-16 20:45:44 +00:00
switch ( distribution )
2012-04-09 19:12:12 +00:00
{
2014-06-16 20:45:44 +00:00
case tid_exponential :
w = radius * radius - ( xd * xd + yd * yd ) ;
if ( w > 0 )
func ( ctx , s , tx + ty * steps , wx , wy , sqrt ( w ) * strength / ( radius ) ) ;
break ;
case tid_linear :
w = radius - sqrt ( xd * xd + yd * yd ) ;
if ( w > 0 )
func ( ctx , s , tx + ty * steps , wx , wy , w * strength / ( radius ) ) ;
break ;
case tid_square_exponential :
w = max ( fabs ( xd ) , fabs ( yd ) ) ;
w = radius * radius - w * w ;
if ( w > 0 )
func ( ctx , s , tx + ty * steps , wx , wy , sqrt ( w ) * strength / ( radius ) ) ;
break ;
case tid_square_linear :
w = max ( fabs ( xd ) , fabs ( yd ) ) ;
w = radius - w ;
2012-08-04 11:28:39 +00:00
if ( w > 0 )
func ( ctx , s , tx + ty * steps , wx , wy , w * strength / ( radius ) ) ;
2014-06-16 20:45:44 +00:00
break ;
2014-10-05 20:04:11 +00:00
case tid_flat :
w = max ( fabs ( xd ) , fabs ( yd ) ) ;
w = radius - w ;
if ( w > 0 )
func ( ctx , s , tx + ty * steps , wx , wy , strength ) ;
break ;
2012-04-09 19:12:12 +00:00
}
}
}
}
}
}
2014-03-30 08:55:06 +00:00
void ted_texkill ( hmsection_t * s , const char * killtex )
2013-10-29 17:38:22 +00:00
{
int x , y , t , to ;
if ( ! s )
return ;
for ( t = 0 ; t < 4 ; t + + )
{
if ( ! strcmp ( s - > texname [ t ] , killtex ) )
{
unsigned char * lm = ted_getlightmap ( s , 0 ) ;
s - > flags | = TSF_EDITED ;
s - > texname [ t ] [ 0 ] = 0 ;
for ( to = 0 ; to < 4 ; to + + )
if ( * s - > texname [ to ] )
break ;
if ( to = = 4 )
to = 0 ;
if ( to = = 0 | | to = = 2 )
to = 2 - to ;
if ( t = = 0 | | t = = 2 )
t = 2 - t ;
for ( y = 0 ; y < SECTTEXSIZE ; y + + )
{
for ( x = 0 ; x < SECTTEXSIZE ; x + + , lm + = 4 )
{
if ( t = = 3 )
{
//to won't be 3
lm [ to ] = lm [ to ] + ( 255 - ( lm [ 0 ] + lm [ 1 ] + lm [ 2 ] ) ) ;
}
else
{
if ( to ! = 3 )
2014-10-05 20:04:11 +00:00
lm [ to ] = ( lm [ to ] + lm [ t ] ) & 0xff ;
2013-10-29 17:38:22 +00:00
lm [ t ] = 0 ;
}
}
lm + = SECTTEXSIZE * 4 * ( LMCHUNKS - 1 ) ;
}
if ( t = = 0 | | t = = 2 )
t = 2 - t ;
Terr_LoadSectionTextures ( s ) ;
}
}
}
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
void QCBUILTIN PF_terrain_edit ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
2011-05-20 04:10:46 +00:00
{
2012-04-09 19:12:12 +00:00
world_t * vmw = prinst - > parms - > user ;
int action = G_FLOAT ( OFS_PARM0 ) ;
2012-07-20 01:46:05 +00:00
vec3_t pos ; // G_VECTOR(OFS_PARM1);
2012-04-09 19:12:12 +00:00
float radius = G_FLOAT ( OFS_PARM2 ) ;
float quant = G_FLOAT ( OFS_PARM3 ) ;
// G_FLOAT(OFS_RETURN) = Heightmap_Edit(w->worldmodel, action, pos, radius, quant);
2012-08-04 11:28:39 +00:00
model_t * mod = vmw - > Get_CModel ( vmw , ( ( wedict_t * ) PROG_TO_EDICT ( prinst , * vmw - > g . self ) ) - > v - > modelindex ) ;
2012-04-09 19:12:12 +00:00
heightmap_t * hm ;
vec4_t tally ;
2011-05-20 04:10:46 +00:00
2012-04-09 19:12:12 +00:00
G_FLOAT ( OFS_RETURN ) = 0 ;
2011-05-20 04:10:46 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! mod | | ! mod - > terrain )
2013-10-29 17:38:22 +00:00
{
2015-07-30 16:26:15 +00:00
if ( mod & & mod - > loadstate = = MLS_LOADING )
COM_WorkerPartialSync ( mod , & mod - > loadstate , MLS_LOADING ) ;
if ( mod & & mod - > loadstate = = MLS_LOADED )
2013-10-29 17:38:22 +00:00
{
char basename [ MAX_QPATH ] ;
COM_FileBase ( mod - > name , basename , sizeof ( basename ) ) ;
mod - > terrain = Mod_LoadTerrainInfo ( mod , basename , true ) ;
2015-07-30 16:26:15 +00:00
hm = mod - > terrain ;
if ( ! hm )
return ;
Terr_FinishTerrain ( mod ) ;
2013-10-29 17:38:22 +00:00
}
2015-07-30 16:26:15 +00:00
else
return ;
2013-10-29 17:38:22 +00:00
}
2012-04-09 19:12:12 +00:00
hm = mod - > terrain ;
2011-05-20 04:10:46 +00:00
2012-07-20 01:46:05 +00:00
pos [ 0 ] = G_FLOAT ( OFS_PARM1 + 0 ) + hm - > sectionsize * CHUNKBIAS ;
pos [ 1 ] = G_FLOAT ( OFS_PARM1 + 1 ) + hm - > sectionsize * CHUNKBIAS ;
pos [ 2 ] = G_FLOAT ( OFS_PARM1 + 2 ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2011-05-20 04:10:46 +00:00
switch ( action )
{
case ter_reload :
2013-03-12 23:24:15 +00:00
G_FLOAT ( OFS_RETURN ) = 1 ;
2012-07-21 05:52:35 +00:00
Terr_PurgeTerrainModel ( mod , false , true ) ;
2011-05-20 04:10:46 +00:00
break ;
case ter_save :
2013-03-12 23:24:15 +00:00
quant = Heightmap_Save ( hm ) ;
Con_DPrintf ( " ter_save: %g sections saved \n " , quant ) ;
G_FLOAT ( OFS_RETURN ) = quant ;
2011-05-20 04:10:46 +00:00
break ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
case ter_sethole :
2012-08-04 11:28:39 +00:00
/* {
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
int x , y ;
hmsection_t * s ;
x = pos [ 0 ] * 4 / hm - > sectionsize ;
y = pos [ 1 ] * 4 / hm - > sectionsize ;
2014-05-10 13:42:13 +00:00
x = bound ( hm - > firstsegx * 4 , x , hm - > maxsegx * 4 - 1 ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
y = bound ( hm - > firstsegy * 4 , y , hm - > maxsegy * 4 - 1 ) ;
2013-03-31 04:21:08 +00:00
s = Terr_GetSection ( hm , x / 4 , y / 4 , TGS_FORCELOAD ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! s )
return ;
ted_sethole ( & quant , s , ( x & 3 ) + ( y & 3 ) * 4 , x / 4 , y / 4 , 0 ) ;
}
2013-11-21 23:02:28 +00:00
*/
pos [ 0 ] - = 0.5 * hm - > sectionsize / 8 ;
pos [ 1 ] - = 0.5 * hm - > sectionsize / 8 ;
2014-02-13 23:37:33 +00:00
ted_itterate ( hm , tid_linear , pos , radius , 1 , 9 , ted_sethole , & quant ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
break ;
2012-04-09 19:12:12 +00:00
case ter_height_set :
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_linear , pos , radius , 1 , SECTHEIGHTSIZE , ted_heightset , & quant ) ;
break ;
case ter_height_flatten :
tally [ 0 ] = 0 ;
tally [ 1 ] = 0 ;
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTHEIGHTSIZE , ted_heighttally , & tally ) ;
tally [ 0 ] / = tally [ 1 ] ;
if ( IS_NAN ( tally [ 0 ] ) )
tally [ 0 ] = 0 ;
ted_itterate ( hm , tid_exponential , pos , radius , quant , SECTHEIGHTSIZE , ted_heightsmooth , & tally ) ;
2012-04-09 19:12:12 +00:00
break ;
case ter_height_smooth :
tally [ 0 ] = 0 ;
tally [ 1 ] = 0 ;
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_linear , pos , radius , 1 , SECTHEIGHTSIZE , ted_heighttally , & tally ) ;
2012-04-09 19:12:12 +00:00
tally [ 0 ] / = tally [ 1 ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( IS_NAN ( tally [ 0 ] ) )
tally [ 0 ] = 0 ;
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_linear , pos , radius , quant , SECTHEIGHTSIZE , ted_heightsmooth , & tally ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
break ;
case ter_height_spread :
tally [ 0 ] = 0 ;
tally [ 1 ] = 0 ;
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_exponential , pos , radius / 2 , 1 , SECTHEIGHTSIZE , ted_heighttally , & tally ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
tally [ 0 ] / = tally [ 1 ] ;
if ( IS_NAN ( tally [ 0 ] ) )
tally [ 0 ] = 0 ;
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTHEIGHTSIZE , ted_heightsmooth , & tally ) ;
2011-05-20 04:10:46 +00:00
break ;
2012-07-20 01:46:05 +00:00
case ter_water_set :
2013-11-21 23:02:28 +00:00
ted_itterate ( hm , tid_linear , pos , radius , 1 , 9 , ted_waterset , & quant ) ;
2012-07-20 01:46:05 +00:00
break ;
2012-04-09 19:12:12 +00:00
case ter_lower :
quant * = - 1 ;
2011-05-20 04:10:46 +00:00
case ter_raise :
2012-08-04 11:28:39 +00:00
ted_itterate ( hm , tid_exponential , pos , radius , quant , SECTHEIGHTSIZE , ted_heightraise , & quant ) ;
break ;
case ter_tint :
ted_itterate ( hm , tid_exponential , pos , radius , quant , SECTHEIGHTSIZE , ted_tint , G_VECTOR ( OFS_PARM4 ) ) ; //and parm5 too
2012-04-09 19:12:12 +00:00
break ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
// case ter_mixset:
2012-08-04 11:28:39 +00:00
// ted_itterate(hm, tid_exponential, pos, radius, 1, SECTTEXSIZE, ted_mixset, G_VECTOR(OFS_PARM4));
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
// break;
2014-06-16 20:45:44 +00:00
case ter_tex_blend :
ted_itterate ( hm , tid_exponential , pos , radius , quant / 10 , SECTTEXSIZE , ted_texpaint , ( void * ) PR_GetStringOfs ( prinst , OFS_PARM4 ) ) ;
break ;
case ter_tex_replace :
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTTEXSIZE , ted_texreplace , ( void * ) PR_GetStringOfs ( prinst , OFS_PARM3 ) ) ;
2012-04-09 19:12:12 +00:00
break ;
2014-06-16 20:45:44 +00:00
case ter_tex_concentrate :
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTTEXSIZE , ted_texconcentrate , NULL ) ;
2012-04-09 19:12:12 +00:00
break ;
2014-06-16 20:45:44 +00:00
case ter_tex_noise :
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTTEXSIZE , ted_texnoise , NULL ) ;
2012-04-09 19:12:12 +00:00
break ;
2014-06-16 20:45:44 +00:00
case ter_tex_blur :
2012-04-09 19:12:12 +00:00
Vector4Set ( tally , 0 , 0 , 0 , 0 ) ;
2014-06-16 20:45:44 +00:00
ted_itterate ( hm , tid_exponential , pos , radius , 1 , SECTTEXSIZE , ted_textally , & tally ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
VectorScale ( tally , 1 / ( tally [ 3 ] * 255 ) , tally ) ;
2014-06-16 20:45:44 +00:00
ted_itterate ( hm , tid_exponential , pos , radius , quant , SECTTEXSIZE , ted_texset , & tally ) ;
2012-04-09 19:12:12 +00:00
break ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
case ter_tex_get :
{
int x , y ;
hmsection_t * s ;
x = pos [ 0 ] / hm - > sectionsize ;
y = pos [ 1 ] / hm - > sectionsize ;
2014-05-10 13:42:13 +00:00
x = bound ( hm - > firstsegx , x , hm - > maxsegx - 1 ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
y = bound ( hm - > firstsegy , y , hm - > maxsegy - 1 ) ;
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , x , y , TGS_WAITLOAD | TGS_DEFAULTONFAIL ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! s )
return ;
x = bound ( 0 , quant , 3 ) ;
G_INT ( OFS_RETURN ) = PR_TempString ( prinst , s - > texname [ x ] ) ;
}
break ;
2015-06-12 14:44:50 +00:00
case ter_tex_mask :
Z_Free ( hm - > texmask ) ;
hm - > texmask = NULL ;
if ( G_INT ( OFS_PARM1 ) = = 0 )
hm - > texmask = NULL ;
else
hm - > texmask = Z_StrDup ( PR_GetStringOfs ( prinst , OFS_PARM1 ) ) ;
break ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
case ter_tex_kill :
2011-05-20 04:10:46 +00:00
{
2013-10-29 17:38:22 +00:00
int x , y ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
x = pos [ 0 ] / hm - > sectionsize ;
y = pos [ 1 ] / hm - > sectionsize ;
2014-05-10 13:42:13 +00:00
x = bound ( hm - > firstsegx , x , hm - > maxsegx - 1 ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
y = bound ( hm - > firstsegy , y , hm - > maxsegy - 1 ) ;
2013-10-29 17:38:22 +00:00
2014-10-05 20:04:11 +00:00
ted_texkill ( Terr_GetSection ( hm , x , y , TGS_WAITLOAD | TGS_DEFAULTONFAIL ) , PR_GetStringOfs ( prinst , OFS_PARM4 ) ) ;
2011-05-20 04:10:46 +00:00
}
2014-06-16 20:45:44 +00:00
break ;
case ter_reset :
{
int x , y ;
hmsection_t * s ;
x = pos [ 0 ] / hm - > sectionsize ;
y = pos [ 1 ] / hm - > sectionsize ;
x = bound ( hm - > firstsegx , x , hm - > maxsegx - 1 ) ;
y = bound ( hm - > firstsegy , y , hm - > maxsegy - 1 ) ;
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , x , y , TGS_WAITLOAD | TGS_DEFAULTONFAIL ) ;
2014-06-16 20:45:44 +00:00
if ( s )
{
2014-10-05 20:04:11 +00:00
s - > flags = ( s - > flags & ~ TSF_EDITED ) ;
2014-06-16 20:45:44 +00:00
Terr_ClearSection ( s ) ;
Terr_GenerateDefault ( hm , s ) ;
}
}
2011-05-20 04:10:46 +00:00
break ;
2012-07-20 01:46:05 +00:00
case ter_mesh_add :
{
2014-05-10 13:42:13 +00:00
vec3_t axis [ 3 ] ;
wedict_t * ed = G_WEDICT ( prinst , OFS_PARM1 ) ;
//FIXME: modeltype pitch inversion
AngleVectorsFLU ( ed - > v - > angles , axis [ 0 ] , axis [ 1 ] , axis [ 2 ] ) ;
2014-10-05 20:04:11 +00:00
Terr_AddMesh ( hm , TGS_WAITLOAD | TGS_DEFAULTONFAIL , vmw - > Get_CModel ( vmw , ed - > v - > modelindex ) , ed - > v - > origin , axis , ed - > xv - > scale ) ;
2012-07-20 01:46:05 +00:00
}
break ;
case ter_mesh_kill :
{
2014-05-10 13:42:13 +00:00
int i ;
2012-07-20 01:46:05 +00:00
// entity_t *e;
int x , y ;
// float r;
hmsection_t * s ;
x = pos [ 0 ] / hm - > sectionsize ;
y = pos [ 1 ] / hm - > sectionsize ;
2014-05-10 13:42:13 +00:00
x = bound ( hm - > firstsegx , x , hm - > maxsegx - 1 ) ;
2012-07-20 01:46:05 +00:00
y = bound ( hm - > firstsegy , y , hm - > maxsegy - 1 ) ;
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , x , y , TGS_WAITLOAD | TGS_DEFAULTONFAIL ) ;
2012-07-20 01:46:05 +00:00
if ( ! s )
return ;
2014-10-05 20:04:11 +00:00
Sys_LockMutex ( hm - > entitylock ) ;
//FIXME: this doesn't work properly.
2014-05-10 13:42:13 +00:00
if ( s - > numents )
{
for ( i = 0 ; i < s - > numents ; i + + )
s - > ents [ i ] - > refs - = 1 ;
s - > flags | = TSF_EDITED ;
s - > numents = 0 ;
}
2014-10-05 20:04:11 +00:00
Sys_UnlockMutex ( hm - > entitylock ) ;
2012-07-20 01:46:05 +00:00
}
break ;
2011-05-20 04:10:46 +00:00
}
}
2012-04-09 19:12:12 +00:00
# else
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
void QCBUILTIN PF_terrain_edit ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
2012-04-09 19:12:12 +00:00
{
G_FLOAT ( OFS_RETURN ) = 0 ;
}
# endif
2011-05-20 04:10:46 +00:00
2012-08-04 11:28:39 +00:00
void Terr_ParseEntityLump ( char * data , heightmap_t * heightmap )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
char key [ 128 ] ;
2014-10-05 20:04:11 +00:00
char value [ 2048 ] ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2012-08-04 11:28:39 +00:00
heightmap - > sectionsize = 1024 ;
2013-10-29 17:38:22 +00:00
heightmap - > mode = HMM_TERRAIN ;
2012-08-04 11:28:39 +00:00
2014-05-10 13:42:13 +00:00
heightmap - > defaultgroundheight = 0 ;
heightmap - > defaultwaterheight = 0 ;
2014-10-05 20:04:11 +00:00
Q_snprintfz ( heightmap - > defaultwatershader , sizeof ( heightmap - > defaultwatershader ) , " water/%s " , heightmap - > path ) ;
2014-05-10 13:42:13 +00:00
Q_strncpyz ( heightmap - > defaultgroundtexture , " " , sizeof ( heightmap - > defaultgroundtexture ) ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( data )
2014-10-05 20:04:11 +00:00
if ( ( data = COM_ParseOut ( data , key , sizeof ( key ) ) ) ) //read the map info.
if ( key [ 0 ] = = ' { ' )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
while ( 1 )
{
2014-10-05 20:04:11 +00:00
if ( ! ( data = COM_ParseOut ( data , key , sizeof ( key ) ) ) )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
break ; // error
2014-10-05 20:04:11 +00:00
if ( key [ 0 ] = = ' } ' )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
break ; // end of worldspawn
2014-10-05 20:04:11 +00:00
if ( key [ 0 ] = = ' _ ' )
memmove ( key , key + 1 , strlen ( key ) ) ; //_ vars are for comments/utility stuff that arn't visible to progs and for compat. We want to support these stealth things.
if ( ! ( ( data = COM_ParseOut ( data , value , sizeof ( value ) ) ) ) )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
break ; // error
2012-07-20 01:46:05 +00:00
if ( ! strcmp ( " segmentsize " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > sectionsize = atof ( value ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else if ( ! strcmp ( " minxsegment " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > firstsegx = atoi ( value ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else if ( ! strcmp ( " minysegment " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > firstsegy = atoi ( value ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else if ( ! strcmp ( " maxxsegment " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > maxsegx = atoi ( value ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
else if ( ! strcmp ( " maxysegment " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > maxsegy = atoi ( value ) ;
2014-05-10 13:42:13 +00:00
else if ( ! strcmp ( " defaultwaterheight " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > defaultwaterheight = atof ( value ) ;
2014-05-10 13:42:13 +00:00
else if ( ! strcmp ( " defaultgroundheight " , key ) )
2014-10-05 20:04:11 +00:00
heightmap - > defaultgroundheight = atof ( value ) ;
2014-05-10 13:42:13 +00:00
else if ( ! strcmp ( " defaultgroundtexture " , key ) )
2014-10-05 20:04:11 +00:00
Q_strncpyz ( heightmap - > defaultgroundtexture , value , sizeof ( heightmap - > defaultgroundtexture ) ) ;
2014-05-10 13:42:13 +00:00
else if ( ! strcmp ( " defaultwatertexture " , key ) )
2014-10-05 20:04:11 +00:00
Q_strncpyz ( heightmap - > defaultwatershader , value , sizeof ( heightmap - > defaultwatershader ) ) ;
2012-08-04 11:28:39 +00:00
else if ( ! strcmp ( " tiles " , key ) )
{
char * d ;
2013-10-29 17:38:22 +00:00
heightmap - > mode = HMM_BLOCKS ;
2014-10-05 20:04:11 +00:00
d = value ;
2012-08-04 11:28:39 +00:00
d = COM_ParseOut ( d , key , sizeof ( key ) ) ;
heightmap - > tilepixcount [ 0 ] = atoi ( key ) ;
d = COM_ParseOut ( d , key , sizeof ( key ) ) ;
heightmap - > tilepixcount [ 1 ] = atoi ( key ) ;
d = COM_ParseOut ( d , key , sizeof ( key ) ) ;
heightmap - > tilecount [ 0 ] = atoi ( key ) ;
d = COM_ParseOut ( d , key , sizeof ( key ) ) ;
heightmap - > tilecount [ 1 ] = atoi ( key ) ;
}
}
/*bias and bound it*/
heightmap - > firstsegx + = CHUNKBIAS ;
heightmap - > firstsegy + = CHUNKBIAS ;
heightmap - > maxsegx + = CHUNKBIAS ;
heightmap - > maxsegy + = CHUNKBIAS ;
if ( heightmap - > firstsegx < 0 )
heightmap - > firstsegx = 0 ;
if ( heightmap - > firstsegy < 0 )
heightmap - > firstsegy = 0 ;
if ( heightmap - > maxsegx > CHUNKLIMIT )
heightmap - > maxsegx = CHUNKLIMIT ;
if ( heightmap - > maxsegy > CHUNKLIMIT )
heightmap - > maxsegy = CHUNKLIMIT ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
}
2014-10-05 20:04:11 +00:00
void Terr_FinishTerrain ( model_t * mod )
2012-08-04 11:28:39 +00:00
{
2014-10-05 20:04:11 +00:00
heightmap_t * hm = mod - > terrain ;
2012-08-04 11:28:39 +00:00
# ifndef SERVERONLY
if ( qrenderer ! = QR_NONE )
{
2014-10-05 20:04:11 +00:00
if ( * hm - > skyname )
hm - > skyshader = R_RegisterCustom ( va ( " skybox_%s " , hm - > skyname ) , SUF_NONE , Shader_DefaultSkybox , NULL ) ;
2013-10-29 17:38:22 +00:00
else
hm - > skyshader = NULL ;
switch ( hm - > mode )
{
case HMM_BLOCKS :
2013-08-21 07:14:39 +00:00
hm - > shader = R_RegisterShader ( " terraintileshader " , SUF_NONE ,
2012-08-04 11:28:39 +00:00
" { \n "
" { \n "
" map $diffuse \n "
" } \n "
" } \n "
) ;
2013-10-29 17:38:22 +00:00
break ;
case HMM_TERRAIN :
2014-10-05 20:04:11 +00:00
hm - > shader = R_RegisterShader ( hm - > groundshadername , SUF_LIGHTMAP ,
2012-08-04 11:28:39 +00:00
" { \n "
2013-10-29 17:38:22 +00:00
" bemode rtlight \n "
" { \n "
" { \n "
" map $diffuse \n "
" blendfunc add \n "
" } \n "
2015-03-03 00:14:43 +00:00
//FIXME: these maps are a legacy thing, and could be removed if third-party glsl properly contains s_diffuse
2013-10-29 17:38:22 +00:00
" { \n "
" map $upperoverlay \n "
" } \n "
" { \n "
" map $loweroverlay \n "
" } \n "
" { \n "
" map $fullbright \n "
" } \n "
" { \n "
" map $lightmap \n "
" } \n "
" { \n "
" map $shadowmap \n "
" } \n "
2013-11-21 23:02:28 +00:00
" { \n "
" map $lightcubemap \n "
" } \n "
2013-10-29 17:38:22 +00:00
//woo, one glsl to rule them all
" program terrain#RTLIGHT \n "
" } \n "
" bemode depthdark \n "
" { \n "
" program depthonly \n "
" { \n "
" depthwrite \n "
" } \n "
" } \n "
" bemode depthonly \n "
" { \n "
" program depthonly \n "
" { \n "
" depthwrite \n "
2015-04-14 23:12:17 +00:00
" maskcolor \n "
2013-10-29 17:38:22 +00:00
" } \n "
" } \n "
2015-03-03 00:14:43 +00:00
//FIXME: these maps are a legacy thing, and could be removed if third-party glsl properly contains s_diffuse
2012-08-04 11:28:39 +00:00
" { \n "
" map $diffuse \n "
" } \n "
" { \n "
" map $upperoverlay \n "
" } \n "
" { \n "
" map $loweroverlay \n "
" } \n "
" { \n "
" map $fullbright \n "
" } \n "
" { \n "
" map $lightmap \n "
" } \n "
" program terrain \n "
" if r_terraindebug \n "
" program terraindebug \n "
2013-03-12 23:16:55 +00:00
" endif \n "
2012-08-04 11:28:39 +00:00
" } \n "
) ;
2013-10-29 17:38:22 +00:00
break ;
}
2012-08-04 11:28:39 +00:00
}
# endif
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2015-01-07 13:34:05 +00:00
int Fragment_ClipPolyToPlane ( float * inverts , float * outverts , int incount , float * plane , float planedist ) ;
2015-04-14 23:12:17 +00:00
static size_t Terr_GenerateBrushFace ( vecV_t * points , size_t maxpoints , vec4_t * planes , size_t numplanes , vec4_t face )
2015-01-07 13:34:05 +00:00
{
int p ;
vec4_t verts [ 128 ] ;
vec4_t verts2 [ 128 ] ;
vec4_t * cverts ;
int flip ;
2015-01-21 18:18:37 +00:00
// vec3_t d1, d2, n;
2015-01-07 13:34:05 +00:00
size_t numverts ;
//generate some huge quad/poly aligned with the plane
vec3_t tmp = { 0.1 , 0.04 , 0.96 } ;
vec3_t right , forward ;
// if (face[2] != 1)
// return 0;
CrossProduct ( face , tmp , right ) ;
VectorNormalize ( right ) ;
CrossProduct ( face , right , forward ) ;
VectorNormalize ( forward ) ;
VectorScale ( face , face [ 3 ] , verts [ 0 ] ) ;
VectorMA ( verts [ 0 ] , 8192 , right , verts [ 0 ] ) ;
VectorMA ( verts [ 0 ] , 8192 , forward , verts [ 0 ] ) ;
VectorScale ( face , face [ 3 ] , verts [ 1 ] ) ;
VectorMA ( verts [ 1 ] , 8192 , right , verts [ 1 ] ) ;
VectorMA ( verts [ 1 ] , - 8192 , forward , verts [ 1 ] ) ;
VectorScale ( face , face [ 3 ] , verts [ 2 ] ) ;
VectorMA ( verts [ 2 ] , - 8192 , right , verts [ 2 ] ) ;
VectorMA ( verts [ 2 ] , - 8192 , forward , verts [ 2 ] ) ;
VectorScale ( face , face [ 3 ] , verts [ 3 ] ) ;
VectorMA ( verts [ 3 ] , - 8192 , right , verts [ 3 ] ) ;
VectorMA ( verts [ 3 ] , 8192 , forward , verts [ 3 ] ) ;
numverts = 4 ;
//clip the quad to the various other planes
flip = 0 ;
for ( p = 0 ; p < numplanes ; p + + )
{
if ( planes [ p ] ! = face )
{
vec3_t norm ;
flip ^ = 1 ;
VectorNegate ( planes [ p ] , norm ) ;
if ( flip )
numverts = Fragment_ClipPolyToPlane ( ( float * ) verts , ( float * ) verts2 , numverts , norm , - planes [ p ] [ 3 ] ) ;
else
numverts = Fragment_ClipPolyToPlane ( ( float * ) verts2 , ( float * ) verts , numverts , norm , - planes [ p ] [ 3 ] ) ;
if ( numverts < 3 ) //totally clipped.
return 0 ;
}
}
if ( numverts > maxpoints )
return 0 ;
if ( flip )
cverts = verts2 ;
else
cverts = verts ;
for ( p = 0 ; p < numverts ; p + + )
{
VectorCopy ( cverts [ p ] , points [ p ] ) ;
}
return numverts ;
}
2015-01-07 13:56:16 +00:00
# ifndef SERVERONLY
2015-01-07 13:34:05 +00:00
void Terr_Brush_Draw ( heightmap_t * hm , batch_t * * batches , entity_t * e )
{
batch_t * b ;
size_t i , j ;
vbobctx_t ctx ;
2015-04-14 23:12:17 +00:00
brushbatch_t * bb ;
2015-01-07 13:34:05 +00:00
brushtex_t * bt ;
brushes_t * br ;
2015-04-14 23:12:17 +00:00
struct {
vecV_t coord [ 65536 ] ;
vec2_t texcoord [ 65536 ] ;
vec2_t lmcoord [ 65536 ] ;
vec3_t normal [ 65536 ] ;
vec3_t svector [ 65536 ] ;
vec3_t tvector [ 65536 ] ;
index_t index [ 65535 ] ;
} * arrays = NULL ;
2015-01-07 13:34:05 +00:00
size_t numverts = 0 ;
size_t numindicies = 0 ;
2015-04-14 23:12:17 +00:00
int w , h , lmnum ;
2015-01-07 13:34:05 +00:00
float scale [ 2 ] ;
2015-04-14 23:12:17 +00:00
lightmapinfo_t * lm ;
qboolean dorelight = true ;
# ifdef RUNTIMELIGHTING
//FIXME: lightmaps
//if we're enabling lightmaps, make sure all surfaces have known sizes first.
//allocate lightmap space for all surfaces, and then rebuild all textures.
//if a surface is modified, clear its lightmap to -1 and when its batches are rebuilt, it'll unlight naturally.
if ( hm - > recalculatebrushlighting )
{
unsigned int lmcount ;
unsigned int lmblocksize = 512 ; //LMBLOCK_SIZE_MAX
hm - > recalculatebrushlighting = false ;
if ( ! hm - > relightcontext )
{
for ( numverts = 0 , numindicies = 0 , i = 0 , br = hm - > wbrushes ; i < hm - > numbrushes ; i + + , br + + )
{
for ( j = 0 ; j < br - > numplanes ; j + + )
{
br - > faces [ j ] . lightmap = - 1 ;
br - > faces [ j ] . lmbase [ 0 ] = 0 ;
br - > faces [ j ] . lmbase [ 1 ] = 0 ;
}
}
for ( bt = hm - > brushtextures ; bt ; bt = bt - > next )
{
bt - > rebuild = true ;
bt - > firstlm = 0 ;
bt - > lmcount = 0 ;
}
BZ_Free ( hm - > brushlmremaps ) ;
hm - > brushlmremaps = NULL ;
hm - > brushmaxlms = 0 ;
}
else
{
Mod_LightmapAllocInit ( & hm - > brushlmalloc , false , lmblocksize , lmblocksize , 0 ) ;
hm - > brushlmscale = 1.0 / lmblocksize ;
//textures is to try to ensure that they are allocated consecutively.
for ( bt = hm - > brushtextures ; bt ; bt = bt - > next )
{
bt - > firstlm = hm - > brushlmalloc . lmnum ;
for ( numverts = 0 , numindicies = 0 , i = 0 , br = hm - > wbrushes ; i < hm - > numbrushes ; i + + , br + + )
{
for ( j = 0 ; j < br - > numplanes ; j + + )
{
if ( br - > faces [ j ] . tex = = bt )
{
if ( br - > faces [ j ] . lightdata )
{
Mod_LightmapAllocBlock ( & hm - > brushlmalloc , br - > faces [ j ] . lmextents [ 0 ] , br - > faces [ j ] . lmextents [ 1 ] , & br - > faces [ j ] . lmbase [ 0 ] , & br - > faces [ j ] . lmbase [ 1 ] , & br - > faces [ j ] . lightmap ) ;
br - > faces [ j ] . relit = true ;
}
else
{ //this surface has no lightmap info or something.
br - > faces [ j ] . lightmap = - 1 ;
br - > faces [ j ] . lmbase [ 0 ] = 0 ;
br - > faces [ j ] . lmbase [ 1 ] = 0 ;
}
}
}
}
bt - > rebuild = true ;
bt - > lmcount = hm - > brushlmalloc . lmnum - bt - > firstlm ;
if ( hm - > brushlmalloc . allocated [ 0 ] )
bt - > lmcount + + ;
if ( hm - > brushlmalloc . deluxe )
{
bt - > firstlm * = 2 ;
bt - > lmcount * = 2 ;
}
}
lmcount = hm - > brushlmalloc . lmnum ;
if ( hm - > brushlmalloc . allocated [ 0 ] )
lmcount + + ;
if ( hm - > brushlmalloc . deluxe )
lmcount * = 2 ;
if ( lmcount > hm - > brushmaxlms )
{
int first ;
hm - > brushlmremaps = BZ_Realloc ( hm - > brushlmremaps , sizeof ( * hm - > brushlmremaps ) * lmcount ) ;
first = Surf_NewLightmaps ( lmcount - hm - > brushmaxlms , hm - > brushlmalloc . width , hm - > brushlmalloc . height , hm - > brushlmalloc . deluxe ) ;
while ( hm - > brushmaxlms < lmcount )
hm - > brushlmremaps [ hm - > brushmaxlms + + ] = first + + ;
}
}
}
if ( hm - > relightcontext )
for ( i = 0 , br = hm - > wbrushes ; i < hm - > numbrushes ; i + + , br + + )
{
for ( j = 0 ; j < br - > numplanes ; j + + )
{
if ( br - > faces [ j ] . relight & & dorelight )
{
qbyte styles [ 4 ] = { 0 , 255 , 255 , 255 } ;
int texsize [ 2 ] = { br - > faces [ j ] . lmextents [ 0 ] - 1 , br - > faces [ j ] . lmextents [ 1 ] - 1 } ;
vec2_t exactmins , exactmaxs ;
int m , k ;
vec2_t lm ;
for ( m = 0 ; m < br - > faces [ j ] . numpoints ; m + + )
{
for ( k = 0 ; k < 2 ; k + + )
{
lm [ k ] = DotProduct ( br - > faces [ j ] . points [ m ] , br - > faces [ j ] . stdir [ k ] ) + br - > faces [ j ] . stdir [ k ] [ 3 ] ;
if ( m = = 0 )
exactmins [ k ] = exactmaxs [ k ] = lm [ k ] ;
else if ( lm [ k ] > exactmaxs [ k ] )
exactmaxs [ k ] = lm [ k ] ;
else if ( lm [ k ] < exactmins [ k ] )
exactmins [ k ] = lm [ k ] ;
}
}
dorelight = false ;
br - > faces [ j ] . relight = false ;
LightPlane ( hm - > relightcontext , hm - > lightthreadmem , styles , br - > faces [ j ] . lightdata , NULL , br - > planes [ j ] , br - > faces [ j ] . stdir , exactmins , exactmaxs , br - > faces [ j ] . lmbias , texsize , br - > faces [ j ] . lmscale ) ; //special version that doesn't know what a face is or anything.
br - > faces [ j ] . relit = true ;
}
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
if ( br - > faces [ j ] . relit & & br - > faces [ j ] . lightmap > = 0 )
2015-04-14 23:12:17 +00:00
{
int s , t ;
qbyte * out , * in ;
lm = lightmap [ hm - > brushlmremaps [ br - > faces [ j ] . lightmap ] ] ;
br - > faces [ j ] . relit = false ;
lm - > modified = true ;
lm - > rectchange . l = 0 ;
lm - > rectchange . t = 0 ;
lm - > rectchange . w = lm - > width ;
lm - > rectchange . h = lm - > height ;
in = br - > faces [ j ] . lightdata ;
out = lm - > lightmaps + ( br - > faces [ j ] . lmbase [ 1 ] * lm - > width + br - > faces [ j ] . lmbase [ 0 ] ) * lightmap_bytes ;
for ( t = 0 ; t < br - > faces [ j ] . lmextents [ 1 ] ; t + + )
{
for ( s = 0 ; s < br - > faces [ j ] . lmextents [ 0 ] ; s + + )
{
* out + + = in [ 2 ] ;
* out + + = in [ 1 ] ;
* out + + = in [ 0 ] ;
* out + + = 0xff ;
in + = 3 ;
}
out + = ( lm - > width - br - > faces [ j ] . lmextents [ 0 ] ) * lightmap_bytes ;
}
}
}
}
# endif
2015-01-07 13:34:05 +00:00
for ( bt = hm - > brushtextures ; bt ; bt = bt - > next )
{
if ( ! bt - > shader )
{
2015-04-14 23:12:17 +00:00
if ( ! Q_strcasecmp ( bt - > shadername , " clip " ) )
2015-01-07 13:34:05 +00:00
bt - > shader = R_RegisterShader ( bt - > shadername , SUF_LIGHTMAP , " { \n surfaceparm nodraw \n } " ) ;
else
2015-01-08 13:09:20 +00:00
bt - > shader = R_RegisterCustom ( bt - > shadername , SUF_LIGHTMAP , Shader_DefaultBSPQ1 , NULL ) ;
// bt->shader = R_RegisterShader_Lightmap(bt->shadername);
2015-04-14 23:12:17 +00:00
if ( ! Q_strncasecmp ( bt - > shadername , " sky " , 3 ) )
{
miptex_t * tx = W_GetMipTex ( bt - > shadername ) ;
if ( tx )
{
2015-05-03 19:57:46 +00:00
R_InitSky ( bt - > shader , bt - > shadername , ( qbyte * ) tx + tx - > offsets [ 0 ] , tx - > width , tx - > height ) ;
2015-04-14 23:12:17 +00:00
BZ_Free ( tx ) ;
}
else
R_BuildDefaultTexnums ( NULL , bt - > shader ) ;
}
else
R_BuildDefaultTexnums ( NULL , bt - > shader ) ;
2015-01-07 13:34:05 +00:00
}
if ( bt - > rebuild )
{
//FIXME: don't block.
if ( R_GetShaderSizes ( bt - > shader , & w , & h , false ) < 0 )
continue ;
bt - > rebuild = false ;
if ( w < 1 ) w = 64 ;
if ( h < 1 ) h = 64 ;
scale [ 0 ] = 1.0 / w ; //I hate needing this.
scale [ 1 ] = 1.0 / h ;
2015-04-14 23:12:17 +00:00
while ( bt - > batches )
{
bb = bt - > batches ;
bt - > batches = bb - > next ;
BE_VBO_Destroy ( & bb - > vbo . coord ) ;
BE_VBO_Destroy ( & bb - > vbo . indicies ) ;
BZ_Free ( bb ) ;
}
if ( ! arrays )
arrays = BZ_Malloc ( sizeof ( * arrays ) ) ;
2015-01-07 13:34:05 +00:00
2015-04-14 23:12:17 +00:00
for ( lmnum = - 1 ; lmnum < bt - > firstlm + bt - > lmcount ; ( ( lmnum = = - 1 ) ? ( lmnum = bt - > firstlm ) : ( lmnum = lmnum + 1 ) ) )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
i = 0 ;
br = hm - > wbrushes ;
for ( numverts = 0 , numindicies = 0 ; i < hm - > numbrushes ; i + + , br + + )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
//if a single batch has too many verts, cut it off before it overflows our maximum batch size, and hope we don't get a really really complex brush.
if ( numverts > 0xf000 | | numindicies > 0xf000 )
break ;
for ( j = 0 ; j < br - > numplanes ; j + + )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
if ( br - > faces [ j ] . tex = = bt /*&& !br->selected*/ & & br - > faces [ j ] . lightmap = = lmnum )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
size_t k , o ;
float s , t ;
for ( k = 0 , o = numverts ; k < br - > faces [ j ] . numpoints ; k + + , o + + )
{
VectorCopy ( br - > faces [ j ] . points [ k ] , arrays - > coord [ o ] ) ;
VectorCopy ( br - > planes [ j ] , arrays - > normal [ o ] ) ;
VectorCopy ( br - > faces [ j ] . stdir [ 0 ] , arrays - > svector [ o ] ) ;
VectorCopy ( br - > faces [ j ] . stdir [ 1 ] , arrays - > tvector [ o ] ) ;
//compute the texcoord planes
s = ( DotProduct ( arrays - > svector [ o ] , arrays - > coord [ o ] ) + br - > faces [ j ] . stdir [ 0 ] [ 3 ] ) ;
t = ( DotProduct ( arrays - > tvector [ o ] , arrays - > coord [ o ] ) + br - > faces [ j ] . stdir [ 1 ] [ 3 ] ) ;
arrays - > texcoord [ o ] [ 0 ] = s * scale [ 0 ] ;
arrays - > texcoord [ o ] [ 1 ] = t * scale [ 1 ] ;
//maths, maths, and more maths.
arrays - > lmcoord [ o ] [ 0 ] = ( br - > faces [ j ] . lmbase [ 0 ] + 0.5 + s / br - > faces [ j ] . lmscale - br - > faces [ j ] . lmbias [ 0 ] ) * hm - > brushlmscale ;
arrays - > lmcoord [ o ] [ 1 ] = ( br - > faces [ j ] . lmbase [ 1 ] + 0.5 + t / br - > faces [ j ] . lmscale - br - > faces [ j ] . lmbias [ 1 ] ) * hm - > brushlmscale ;
}
for ( k = 2 ; k < br - > faces [ j ] . numpoints ; k + + )
{ //triangle fans
arrays - > index [ numindicies + + ] = numverts + 0 ;
arrays - > index [ numindicies + + ] = numverts + k - 1 ;
arrays - > index [ numindicies + + ] = numverts + k - 0 ;
}
numverts + = br - > faces [ j ] . numpoints ;
2015-01-07 13:34:05 +00:00
}
}
}
2015-04-14 23:12:17 +00:00
if ( numverts | | numindicies )
{
bb = Z_Malloc ( sizeof ( * bb ) + ( sizeof ( bb - > mesh . xyz_array [ 0 ] ) + sizeof ( arrays - > texcoord [ 0 ] ) + sizeof ( arrays - > lmcoord [ 0 ] ) + sizeof ( arrays - > normal [ 0 ] ) + sizeof ( arrays - > svector [ 0 ] ) + sizeof ( arrays - > tvector [ 0 ] ) ) * numverts ) ;
bb - > next = bt - > batches ;
bt - > batches = bb ;
bb - > lightmap = lmnum ;
BE_VBO_Begin ( & ctx , ( sizeof ( arrays - > coord [ 0 ] ) + sizeof ( arrays - > texcoord [ 0 ] ) + sizeof ( arrays - > lmcoord [ 0 ] ) + sizeof ( arrays - > normal [ 0 ] ) + sizeof ( arrays - > svector [ 0 ] ) + sizeof ( arrays - > tvector [ 0 ] ) ) * numverts ) ;
BE_VBO_Data ( & ctx , arrays - > coord , sizeof ( arrays - > coord [ 0 ] ) * numverts , & bb - > vbo . coord ) ;
BE_VBO_Data ( & ctx , arrays - > texcoord , sizeof ( arrays - > texcoord [ 0 ] ) * numverts , & bb - > vbo . texcoord ) ;
BE_VBO_Data ( & ctx , arrays - > lmcoord , sizeof ( arrays - > lmcoord [ 0 ] ) * numverts , & bb - > vbo . lmcoord [ 0 ] ) ;
BE_VBO_Data ( & ctx , arrays - > normal , sizeof ( arrays - > normal [ 0 ] ) * numverts , & bb - > vbo . normals ) ;
BE_VBO_Data ( & ctx , arrays - > svector , sizeof ( arrays - > svector [ 0 ] ) * numverts , & bb - > vbo . svector ) ;
BE_VBO_Data ( & ctx , arrays - > tvector , sizeof ( arrays - > tvector [ 0 ] ) * numverts , & bb - > vbo . tvector ) ;
BE_VBO_Finish ( & ctx , arrays - > index , sizeof ( arrays - > index [ 0 ] ) * numindicies , & bb - > vbo . indicies ) ;
bb - > mesh . xyz_array = ( avec4_t * ) ( bb + 1 ) ;
memcpy ( bb - > mesh . xyz_array , arrays - > coord , sizeof ( * bb - > mesh . xyz_array ) * numverts ) ;
bb - > mesh . st_array = ( vec2_t * ) ( bb - > mesh . xyz_array + numverts ) ;
memcpy ( bb - > mesh . st_array , arrays - > texcoord , sizeof ( * bb - > mesh . st_array ) * numverts ) ;
bb - > mesh . lmst_array [ 0 ] = ( vec2_t * ) ( bb - > mesh . st_array + numverts ) ;
memcpy ( bb - > mesh . lmst_array [ 0 ] , arrays - > lmcoord , sizeof ( * bb - > mesh . lmst_array ) * numverts ) ;
bb - > mesh . normals_array = ( vec3_t * ) ( bb - > mesh . lmst_array [ 0 ] + numverts ) ;
memcpy ( bb - > mesh . normals_array , arrays - > normal , sizeof ( * bb - > mesh . normals_array ) * numverts ) ;
bb - > mesh . snormals_array = ( vec3_t * ) ( bb - > mesh . normals_array + numverts ) ;
memcpy ( bb - > mesh . snormals_array , arrays - > svector , sizeof ( * bb - > mesh . snormals_array ) * numverts ) ;
bb - > mesh . tnormals_array = ( vec3_t * ) ( bb - > mesh . snormals_array + numverts ) ;
memcpy ( bb - > mesh . tnormals_array , arrays - > tvector , sizeof ( * bb - > mesh . tnormals_array ) * numverts ) ;
bb - > pmesh = & bb - > mesh ;
bb - > mesh . numindexes = numindicies ;
bb - > mesh . numvertexes = numverts ;
}
}
2015-01-07 13:34:05 +00:00
}
2015-04-14 23:12:17 +00:00
for ( bb = bt - > batches ; bb ; bb = bb - > next )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
b = BE_GetTempBatch ( ) ;
if ( b )
{
j = 0 ;
if ( bb - > lightmap > = 0 )
b - > lightmap [ j + + ] = hm - > brushlmremaps [ bb - > lightmap ] ;
for ( ; j < MAXRLIGHTMAPS ; j + + )
b - > lightmap [ j ] = - 1 ;
b - > ent = e ;
b - > shader = bt - > shader ;
b - > flags = 0 ;
b - > mesh = & bb - > pmesh ;
b - > meshes = 1 ;
b - > buildmeshes = NULL ;
2015-05-03 19:57:46 +00:00
b - > skin = NULL ;
2015-04-14 23:12:17 +00:00
b - > texture = NULL ;
b - > vbo = & bb - > vbo ;
b - > next = batches [ b - > shader - > sort ] ;
batches [ b - > shader - > sort ] = b ;
}
2015-01-07 13:34:05 +00:00
}
}
2015-04-14 23:12:17 +00:00
if ( arrays )
BZ_Free ( arrays ) ;
2015-01-07 13:34:05 +00:00
}
2015-01-07 13:56:16 +00:00
# endif
2015-01-07 13:34:05 +00:00
2015-04-14 23:12:17 +00:00
static brushtex_t * Terr_Brush_FindTexture ( heightmap_t * hm , const char * texname )
2015-01-07 13:34:05 +00:00
{
brushtex_t * bt ;
if ( ! hm )
return NULL ;
for ( bt = hm - > brushtextures ; bt ; bt = bt - > next )
{
if ( ! strcmp ( bt - > shadername , texname ) )
return bt ;
}
bt = Z_Malloc ( sizeof ( * bt ) ) ;
bt - > next = hm - > brushtextures ;
hm - > brushtextures = bt ;
Q_strncpyz ( bt - > shadername , texname , sizeof ( bt - > shadername ) ) ;
return bt ;
}
2015-04-14 23:12:17 +00:00
static brushes_t * Terr_Brush_Insert ( model_t * model , heightmap_t * hm , brushes_t * brush )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
vecV_t facepoints [ 64 ] ;
unsigned int iface , oface , j , k ;
unsigned int numpoints ;
2015-01-07 13:34:05 +00:00
brushes_t * out ;
2015-04-14 23:12:17 +00:00
vec2_t mins , maxs ;
vec2_t lm ;
2015-07-30 16:26:15 +00:00
2015-01-07 13:34:05 +00:00
if ( ! hm )
2015-07-30 16:26:15 +00:00
{
if ( model & & model - > loadstate = = MLS_LOADING )
COM_WorkerPartialSync ( model , & model - > loadstate , MLS_LOADING ) ;
if ( model & & model - > loadstate = = MLS_LOADED )
{
char basename [ MAX_QPATH ] ;
COM_FileBase ( model - > name , basename , sizeof ( basename ) ) ;
model - > terrain = Mod_LoadTerrainInfo ( model , basename , true ) ;
hm = model - > terrain ;
if ( ! hm )
return NULL ;
Terr_FinishTerrain ( model ) ;
}
else
return NULL ;
}
2015-01-07 13:34:05 +00:00
hm - > wbrushes = BZ_Realloc ( hm - > wbrushes , sizeof ( * hm - > wbrushes ) * ( hm - > numbrushes + 1 ) ) ;
out = & hm - > wbrushes [ hm - > numbrushes ] ;
2015-04-14 23:12:17 +00:00
out - > selected = false ;
2015-01-07 13:34:05 +00:00
out - > contents = brush - > contents ;
2015-04-14 23:12:17 +00:00
out - > planes = BZ_Malloc ( ( sizeof ( * out - > planes ) + sizeof ( * out - > faces ) ) * brush - > numplanes ) ;
out - > faces = ( void * ) ( out - > planes + brush - > numplanes ) ;
ClearBounds ( out - > mins , out - > maxs ) ;
for ( iface = 0 , oface = 0 ; iface < brush - > numplanes ; iface + + )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
for ( j = 0 ; j < oface ; j + + )
{
if ( out - > planes [ j ] [ 0 ] = = brush - > planes [ iface ] [ 0 ] & &
out - > planes [ j ] [ 1 ] = = brush - > planes [ iface ] [ 1 ] & &
out - > planes [ j ] [ 2 ] = = brush - > planes [ iface ] [ 2 ] & &
out - > planes [ j ] [ 3 ] = = brush - > planes [ iface ] [ 3 ] )
break ;
}
if ( j < oface )
{
Con_DPrintf ( " duplicate plane \n " ) ;
continue ;
}
//generate points now (so we know the correct mins+maxs for the brush, and whether the plane is relevent)
numpoints = Terr_GenerateBrushFace ( facepoints , sizeof ( facepoints ) / sizeof ( facepoints [ 0 ] ) , brush - > planes , brush - > numplanes , brush - > planes [ iface ] ) ;
if ( ! numpoints )
{
Con_DPrintf ( " redundant face \n " ) ;
continue ; //this surface was chopped away entirely, and isn't relevant.
}
//copy the basic face info out so we can save/restore/query/edit it later.
Vector4Copy ( brush - > planes [ iface ] , out - > planes [ oface ] ) ;
out - > faces [ oface ] . tex = brush - > faces [ iface ] . tex ;
Vector4Copy ( brush - > faces [ iface ] . stdir [ 0 ] , out - > faces [ oface ] . stdir [ 0 ] ) ;
Vector4Copy ( brush - > faces [ iface ] . stdir [ 1 ] , out - > faces [ oface ] . stdir [ 1 ] ) ;
2015-01-07 13:34:05 +00:00
//make sure this stuff is rebuilt properly.
2015-04-14 23:12:17 +00:00
out - > faces [ oface ] . tex - > rebuild = true ;
//keep this stuff cached+reused, so everything is consistant. also work out min/max lightmap texture coords
out - > faces [ oface ] . points = BZ_Malloc ( numpoints * sizeof ( * out - > faces [ oface ] . points ) ) ;
Vector2Set ( mins , 0 , 0 ) ;
Vector2Set ( maxs , 0 , 0 ) ;
for ( j = 0 ; j < numpoints ; j + + )
{
AddPointToBounds ( facepoints [ j ] , out - > mins , out - > maxs ) ;
VectorCopy ( facepoints [ j ] , out - > faces [ oface ] . points [ j ] ) ;
for ( k = 0 ; k < 2 ; k + + )
{
lm [ k ] = DotProduct ( out - > faces [ oface ] . points [ j ] , out - > faces [ oface ] . stdir [ k ] ) + out - > faces [ oface ] . stdir [ k ] [ 3 ] ;
if ( j = = 0 )
mins [ k ] = maxs [ k ] = lm [ k ] ;
else if ( lm [ k ] > maxs [ k ] )
maxs [ k ] = lm [ k ] ;
else if ( lm [ k ] < mins [ k ] )
mins [ k ] = lm [ k ] ;
}
}
out - > faces [ oface ] . numpoints = numpoints ;
//determine lightmap scale, and extents. rescale the lightmap if it ought to have been subdivided.
out - > faces [ oface ] . relight = true ;
out - > faces [ oface ] . lmscale = 16 ;
for ( k = 0 ; k < 2 ; )
{
out - > faces [ oface ] . lmbias [ k ] = floor ( mins [ k ] / out - > faces [ oface ] . lmscale ) ;
out - > faces [ oface ] . lmextents [ k ] = ceil ( ( maxs [ k ] ) / out - > faces [ oface ] . lmscale ) - out - > faces [ oface ] . lmbias [ k ] + 1 ;
if ( out - > faces [ oface ] . lmextents [ k ] > 128 )
{ //surface is too large for lightmap data. just drop its resolution, because splitting the face in plane-defined geometry is a bad idea.
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
if ( out - > faces [ oface ] . lmscale > 256 )
{
out - > faces [ oface ] . relight = false ;
k + + ;
}
else
{
out - > faces [ oface ] . lmscale * = 2 ;
k = 0 ;
}
2015-04-14 23:12:17 +00:00
}
else
k + + ;
}
out - > faces [ oface ] . lightmap = - 1 ;
out - > faces [ oface ] . lmbase [ 0 ] = 0 ;
out - > faces [ oface ] . lmbase [ 1 ] = 0 ;
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
if ( out - > faces [ oface ] . relight )
{
out - > faces [ oface ] . lightdata = BZ_Malloc ( out - > faces [ oface ] . lmextents [ 0 ] * out - > faces [ oface ] . lmextents [ 1 ] * 3 ) ;
memset ( out - > faces [ oface ] . lightdata , 0x3f , out - > faces [ oface ] . lmextents [ 0 ] * out - > faces [ oface ] . lmextents [ 1 ] * 3 ) ;
}
else
out - > faces [ oface ] . lightdata = NULL ;
2015-04-14 23:12:17 +00:00
// Con_Printf("lm extents: %u %u (%i points)\n", out->faces[oface].lmextents[0], out->faces[oface].lmextents[1], numpoints);
oface + + ;
}
if ( oface < 4 )
{ //a brush with less than 4 planes cannot be a valid convex area (but can happen when certain redundant planes are chopped out). don't accept creation
//(we often get 2-plane brushes if the sides are sucked in)
for ( j = 0 ; j < oface ; j + + )
{
BZ_Free ( out - > faces [ j ] . lightdata ) ;
BZ_Free ( out - > faces [ j ] . points ) ;
}
BZ_Free ( out - > planes ) ;
return NULL ;
2015-01-07 13:34:05 +00:00
}
2015-04-14 23:12:17 +00:00
out - > numplanes = oface ;
if ( brush - > id )
out - > id = brush - > id ;
else
out - > id = + + hm - > brushidseq ;
// Con_Printf("brush %u (%i faces)\n", out->id, oface);
2015-01-07 13:34:05 +00:00
hm - > numbrushes + = 1 ;
2015-04-14 23:12:17 +00:00
hm - > recalculatebrushlighting = true ; //lightmaps need to be reallocated
//make sure the brush's bounds are added to the containing model.
AddPointToBounds ( out - > mins , model - > mins , model - > maxs ) ;
AddPointToBounds ( out - > maxs , model - > mins , model - > maxs ) ;
return out ;
2015-01-07 13:34:05 +00:00
}
2015-04-14 23:12:17 +00:00
static void Terr_Brush_DeleteIdx ( heightmap_t * hm , size_t idx )
2015-01-07 13:34:05 +00:00
{
int i ;
2015-04-14 23:12:17 +00:00
brushes_t * br = & hm - > wbrushes [ idx ] ;
if ( ! hm )
return ;
2015-01-07 13:34:05 +00:00
2015-04-14 23:12:17 +00:00
for ( i = 0 ; i < br - > numplanes ; i + + )
{
BZ_Free ( br - > faces [ i ] . lightdata ) ;
BZ_Free ( br - > faces [ i ] . points ) ;
br - > faces [ i ] . tex - > rebuild = true ;
}
2015-01-07 13:34:05 +00:00
2015-04-14 23:12:17 +00:00
BZ_Free ( br - > planes ) ;
hm - > numbrushes - - ;
//plug the hole with some other brush.
if ( hm - > numbrushes )
hm - > wbrushes [ idx ] = hm - > wbrushes [ hm - > numbrushes ] ;
}
static void Terr_Brush_DeleteId ( heightmap_t * hm , unsigned int brushid )
{
size_t i ;
brushes_t * br ;
if ( ! hm )
return ;
for ( i = 0 ; i < hm - > numbrushes ; i + + )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
br = & hm - > wbrushes [ i ] ;
if ( br - > id = = brushid )
2015-01-07 13:34:05 +00:00
{
2015-04-14 23:12:17 +00:00
Terr_Brush_DeleteIdx ( hm , i ) ;
break ;
2015-01-07 13:34:05 +00:00
}
2015-04-14 23:12:17 +00:00
}
}
# ifdef _WIN32
# include <malloc.h>
# else
# include <alloca.h>
# endif
static void Brush_Serialise ( sizebuf_t * sb , brushes_t * br )
{
unsigned int i ;
MSG_WriteLong ( sb , br - > id ) ;
MSG_WriteLong ( sb , br - > contents ) ;
MSG_WriteLong ( sb , br - > numplanes ) ;
for ( i = 0 ; i < br - > numplanes ; i + + )
{
MSG_WriteString ( sb , br - > faces [ i ] . tex - > shadername ) ;
MSG_WriteFloat ( sb , br - > planes [ i ] [ 0 ] ) ;
MSG_WriteFloat ( sb , br - > planes [ i ] [ 1 ] ) ;
MSG_WriteFloat ( sb , br - > planes [ i ] [ 2 ] ) ;
MSG_WriteFloat ( sb , br - > planes [ i ] [ 3 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 0 ] [ 0 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 0 ] [ 1 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 0 ] [ 2 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 0 ] [ 3 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 1 ] [ 0 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 1 ] [ 1 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 1 ] [ 2 ] ) ;
MSG_WriteFloat ( sb , br - > faces [ i ] . stdir [ 1 ] [ 3 ] ) ;
}
}
static qboolean Brush_Deserialise ( heightmap_t * hm , brushes_t * br )
{
unsigned int i ;
unsigned int maxplanes = br - > numplanes ;
br - > id = MSG_ReadLong ( ) ;
br - > contents = MSG_ReadLong ( ) ;
br - > numplanes = MSG_ReadLong ( ) ;
if ( br - > numplanes > maxplanes )
return false ;
for ( i = 0 ; i < br - > numplanes ; i + + )
{
//FIXME: as a server, we probably want to reject the brush if we exceed some texnum/memory limitation, so clients can't just spam new textures endlessly.
br - > faces [ i ] . tex = Terr_Brush_FindTexture ( hm , MSG_ReadString ( ) ) ;
br - > planes [ i ] [ 0 ] = MSG_ReadFloat ( ) ;
br - > planes [ i ] [ 1 ] = MSG_ReadFloat ( ) ;
br - > planes [ i ] [ 2 ] = MSG_ReadFloat ( ) ;
br - > planes [ i ] [ 3 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 0 ] [ 0 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 0 ] [ 1 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 0 ] [ 2 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 0 ] [ 3 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 1 ] [ 0 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 1 ] [ 1 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 1 ] [ 2 ] = MSG_ReadFloat ( ) ;
br - > faces [ i ] . stdir [ 1 ] [ 3 ] = MSG_ReadFloat ( ) ;
}
return true ;
}
# ifndef SERVERONLY
void CL_Parse_BrushEdit ( void )
{
model_t * mod = cl . model_precache [ 1 ] ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
int cmd = MSG_ReadByte ( ) ;
if ( cmd = = 0 )
Terr_Brush_DeleteId ( hm , MSG_ReadLong ( ) ) ;
else if ( cmd = = 1 )
{
brushes_t brush ;
memset ( & brush , 0 , sizeof ( brush ) ) ;
brush . numplanes = 128 ;
brush . planes = alloca ( sizeof ( * brush . planes ) * brush . numplanes ) ;
brush . faces = alloca ( sizeof ( * brush . faces ) * brush . numplanes ) ;
if ( ! Brush_Deserialise ( hm , & brush ) )
Host_EndGame ( " CL_Parse_BrushEdit: unparsable brush \n " ) ;
Terr_Brush_Insert ( mod , hm , & brush ) ;
}
else
Host_EndGame ( " CL_Parse_BrushEdit: unknown command %i \n " , cmd ) ;
}
# endif
# ifndef CLIENTONLY
qboolean SV_Parse_BrushEdit ( void )
{
model_t * mod = sv . models [ 1 ] ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
qboolean authorise = SV_MayCheat ( ) | | ( host_client - > penalties & BAN_VIP ) ;
int cmd = MSG_ReadByte ( ) ;
if ( cmd = = 0 )
{
unsigned int brushid = MSG_ReadLong ( ) ;
if ( ! authorise )
return true ;
Terr_Brush_DeleteId ( hm , brushid ) ;
MSG_WriteByte ( & sv . multicast , svcfte_brushedit ) ;
MSG_WriteByte ( & sv . multicast , 0 ) ;
MSG_WriteLong ( & sv . multicast , brushid ) ;
SV_MulticastProtExt ( vec3_origin , MULTICAST_ALL_R , ~ 0 , 0 , 0 ) ;
return true ;
}
else if ( cmd = = 1 )
{
brushes_t brush ;
memset ( & brush , 0 , sizeof ( brush ) ) ;
brush . numplanes = 128 ;
brush . planes = alloca ( sizeof ( * brush . planes ) * brush . numplanes ) ;
brush . faces = alloca ( sizeof ( * brush . faces ) * brush . numplanes ) ;
if ( ! Brush_Deserialise ( hm , & brush ) )
{
Con_Printf ( " SV_Parse_BrushEdit: %s sent an unparsable brush \n " , host_client - > name ) ;
return false ;
}
if ( ! authorise )
return true ;
Terr_Brush_DeleteId ( hm , brush . id ) ;
if ( ! Terr_Brush_Insert ( mod , hm , & brush ) )
return true ; //looks mostly valid, but something was degenerate. fpu precision...
//FIXME: expand the world entity's sizes if needed?
MSG_WriteByte ( & sv . multicast , svcfte_brushedit ) ;
MSG_WriteByte ( & sv . multicast , 1 ) ;
Brush_Serialise ( & sv . multicast , & brush ) ;
SV_MulticastProtExt ( vec3_origin , MULTICAST_ALL_R , ~ 0 , 0 , 0 ) ;
return true ;
}
else
{
Con_Printf ( " SV_Parse_BrushEdit: %s sent an unknown command: %i \n " , host_client - > name , cmd ) ;
return false ;
}
return true ;
}
# endif
typedef struct
{
int shadername ;
vec3_t planenormal ;
float planedist ;
vec3_t sdir ;
float sbias ;
vec3_t tdir ;
float tbias ;
} qcbrushface_t ;
static void * validateqcpointer ( pubprogfuncs_t * prinst , size_t qcptr , size_t elementsize , size_t elementcount )
{
//make sure that the sizes can't overflow
if ( elementcount > 0x10000 )
{
PR_BIError ( prinst , " brush: elementcount %u is too large \n " , ( unsigned int ) elementcount ) ;
return NULL ;
}
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
if ( qcptr < 0 | | qcptr + ( elementsize * elementcount ) > prinst - > stringtablesize )
2015-04-14 23:12:17 +00:00
{
PR_BIError ( prinst , " brush: invalid qc pointer \n " ) ;
return NULL ;
}
return prinst - > stringtable + qcptr ;
}
// {"brush_get", PF_brush_get, 0, 0, 0, 0, D(qcbrushface "int(float modelidx, int brushid, brushface_t *out_faces, int maxfaces, int *out_contents)", "Queries a brush's information. You must pre-allocate the face array for the builtin to write to. Return value is the number of faces retrieved, 0 on error.")},
void QCBUILTIN PF_brush_get ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
unsigned int brushid = G_INT ( OFS_PARM1 ) ;
unsigned int maxfaces = G_INT ( OFS_PARM3 ) ;
qcbrushface_t * out_faces = validateqcpointer ( prinst , G_INT ( OFS_PARM2 ) , sizeof ( * out_faces ) , maxfaces ) ;
unsigned int * out_contents = validateqcpointer ( prinst , G_INT ( OFS_PARM4 ) , sizeof ( * out_contents ) , 1 ) ;
unsigned int fa , i ;
brushes_t * br ;
//assume the worst.
G_INT ( OFS_RETURN ) = 0 ;
2015-04-27 06:19:33 +00:00
if ( G_INT ( OFS_PARM4 ) )
* out_contents = 0 ;
2015-04-14 23:12:17 +00:00
if ( ! hm )
return ;
for ( i = 0 ; i < hm - > numbrushes ; i + + )
{
br = & hm - > wbrushes [ i ] ;
if ( br - > id = = brushid )
{
2015-04-27 06:19:33 +00:00
if ( G_INT ( OFS_PARM4 ) )
* out_contents = br - > contents ;
if ( ! G_INT ( OFS_PARM2 ) )
G_INT ( OFS_RETURN ) = br - > numplanes ;
else
2015-04-14 23:12:17 +00:00
{
2015-04-27 06:19:33 +00:00
maxfaces = min ( br - > numplanes , maxfaces ) ;
2015-04-14 23:12:17 +00:00
2015-04-27 06:19:33 +00:00
for ( fa = 0 ; fa < maxfaces ; fa + + )
{
out_faces - > shadername = PR_TempString ( prinst , br - > faces [ fa ] . tex - > shadername ) ;
VectorCopy ( br - > planes [ fa ] , out_faces - > planenormal ) ;
out_faces - > planedist = br - > planes [ fa ] [ 3 ] ;
2015-04-14 23:12:17 +00:00
2015-04-27 06:19:33 +00:00
VectorCopy ( br - > faces [ fa ] . stdir [ 0 ] , out_faces - > sdir ) ;
out_faces - > sbias = br - > faces [ fa ] . stdir [ 0 ] [ 3 ] ;
VectorCopy ( br - > faces [ fa ] . stdir [ 1 ] , out_faces - > tdir ) ;
out_faces - > tbias = br - > faces [ fa ] . stdir [ 1 ] [ 3 ] ;
out_faces + + ;
}
G_INT ( OFS_RETURN ) = fa ;
2015-04-14 23:12:17 +00:00
}
return ;
}
}
}
// {"brush_create", PF_brush_create, 0, 0, 0, 0, D("int(float modelidx, brushface_t *in_faces, int numfaces, int contents)", "Inserts a new brush into the model. Return value is the new brush's id.")},
void QCBUILTIN PF_brush_create ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
unsigned int numfaces = G_INT ( OFS_PARM2 ) ;
qcbrushface_t * in_faces = validateqcpointer ( prinst , G_INT ( OFS_PARM1 ) , sizeof ( * in_faces ) , numfaces ) ;
unsigned int contents = G_INT ( OFS_PARM3 ) ;
unsigned int i ;
brushes_t brush , * nb ;
vec4_t * planes ;
struct brushface_s * faces ;
G_INT ( OFS_RETURN ) = 0 ;
if ( ! hm )
2015-07-30 16:26:15 +00:00
{
if ( mod & & mod - > loadstate = = MLS_LOADING )
COM_WorkerPartialSync ( mod , & mod - > loadstate , MLS_LOADING ) ;
if ( mod & & mod - > loadstate = = MLS_LOADED )
{
char basename [ MAX_QPATH ] ;
COM_FileBase ( mod - > name , basename , sizeof ( basename ) ) ;
mod - > terrain = Mod_LoadTerrainInfo ( mod , basename , true ) ;
hm = mod - > terrain ;
if ( ! hm )
return ;
Terr_FinishTerrain ( mod ) ;
}
else
return ;
}
2015-04-14 23:12:17 +00:00
planes = alloca ( sizeof ( * planes ) * numfaces ) ;
faces = alloca ( sizeof ( * faces ) * numfaces ) ;
for ( i = 0 ; i < numfaces ; i + + )
{
VectorCopy ( in_faces [ i ] . planenormal , planes [ i ] ) ;
planes [ i ] [ 3 ] = in_faces [ i ] . planedist ;
faces [ i ] . tex = Terr_Brush_FindTexture ( hm , PR_GetString ( prinst , in_faces [ i ] . shadername ) ) ;
VectorCopy ( in_faces [ i ] . sdir , faces [ i ] . stdir [ 0 ] ) ;
faces [ i ] . stdir [ 0 ] [ 3 ] = in_faces [ i ] . sbias ;
VectorCopy ( in_faces [ i ] . tdir , faces [ i ] . stdir [ 1 ] ) ;
faces [ i ] . stdir [ 1 ] [ 3 ] = in_faces [ i ] . tbias ;
}
//now emit it
brush . id = 0 ;
brush . contents = contents ;
brush . numplanes = numfaces ;
brush . planes = planes ;
brush . faces = faces ;
if ( numfaces )
{
nb = Terr_Brush_Insert ( mod , hm , & brush ) ;
if ( nb )
{
G_INT ( OFS_RETURN ) = nb - > id ;
# ifndef CLIENTONLY
if ( sv . state )
{
MSG_WriteByte ( & sv . multicast , svcfte_brushedit ) ;
MSG_WriteByte ( & sv . multicast , 1 ) ;
Brush_Serialise ( & sv . multicast , nb ) ;
SV_MulticastProtExt ( vec3_origin , MULTICAST_ALL_R , ~ 0 , 0 , 0 ) ;
return ;
}
# endif
# ifndef SERVERONLY
if ( cls . state )
{
MSG_WriteByte ( & cls . netchan . message , clcfte_brushedit ) ;
MSG_WriteByte ( & cls . netchan . message , 1 ) ;
Brush_Serialise ( & cls . netchan . message , nb ) ;
return ;
}
# endif
}
}
}
// {"brush_delete", PF_brush_delete, 0, 0, 0, 0, D("void(float modelidx, int brushid)", "Destroys the specified brush.")},
void QCBUILTIN PF_brush_delete ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
unsigned int brushid = G_INT ( OFS_PARM1 ) ;
if ( ! hm )
return ;
Terr_Brush_DeleteId ( hm , brushid ) ;
# ifndef CLIENTONLY
if ( sv . state )
{
MSG_WriteByte ( & sv . multicast , svcfte_brushedit ) ;
MSG_WriteByte ( & sv . multicast , 0 ) ;
MSG_WriteLong ( & sv . multicast , brushid ) ;
SV_MulticastProtExt ( vec3_origin , MULTICAST_ALL_R , ~ 0 , 0 , 0 ) ;
return ;
}
# endif
# ifndef SERVERONLY
if ( cls . state )
{
MSG_WriteByte ( & cls . netchan . message , clcfte_brushedit ) ;
MSG_WriteByte ( & cls . netchan . message , 0 ) ;
MSG_WriteLong ( & cls . netchan . message , brushid ) ;
return ;
}
# endif
}
// {"brush_selected", PF_brush_selected, 0, 0, 0, 0, D("float(float modelid, int brushid, int faceid, float selectedstate)", "Allows you to easily set transient visual properties of a brush. If brush/face is -1, applies to all. returns old value. selectedstate=-1 changes nothing (called for its return value).")},
void QCBUILTIN PF_brush_selected ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
unsigned int brushid = G_INT ( OFS_PARM1 ) ;
unsigned int faceid = G_INT ( OFS_PARM2 ) ;
unsigned int state = G_FLOAT ( OFS_PARM3 ) ;
unsigned int i ;
brushes_t * br ;
G_FLOAT ( OFS_RETURN ) = 0 ;
if ( ! hm )
return ;
// hm->recalculatebrushlighting = true;
for ( i = 0 ; i < hm - > numbrushes ; i + + )
{
br = & hm - > wbrushes [ i ] ;
if ( br - > id = = brushid )
{
G_FLOAT ( OFS_RETURN ) = br - > selected ;
if ( state > = 0 )
{
if ( br - > selected ! = state )
{
for ( i = 0 ; i < br - > numplanes ; i + + )
{
br - > faces [ i ] . tex - > rebuild = true ;
br - > faces [ i ] . relight = true ;
}
br - > selected = state ;
}
}
// return;
}
}
}
2015-07-30 16:26:15 +00:00
// {"brush_calcfacepoints",PF_brush_calcfacepoints,0,0, 0, 0, D("int(int faceid, brushface_t *in_faces, int numfaces, vector *points, int maxpoints)", "Determines the points of the specified face, if the specified brush were to actually be created.")},
void QCBUILTIN PF_brush_calcfacepoints ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
unsigned int faceid = G_INT ( OFS_PARM0 ) ;
unsigned int numfaces = G_INT ( OFS_PARM2 ) ;
qcbrushface_t * in_faces = validateqcpointer ( prinst , G_INT ( OFS_PARM1 ) , sizeof ( * in_faces ) , numfaces ) ;
unsigned int maxpoints = G_INT ( OFS_PARM4 ) ;
vec3_t * out_verts = validateqcpointer ( prinst , G_INT ( OFS_PARM3 ) , sizeof ( * out_verts ) , maxpoints ) ;
vecV_t facepoints [ 256 ] ;
vec4_t planes [ 256 ] ;
unsigned int j , numpoints ;
faceid - - ;
if ( faceid < 0 | | faceid > = numfaces )
{
G_INT ( OFS_RETURN ) = 0 ;
return ;
}
//make sure this isn't a dupe face
for ( j = 0 ; j < faceid ; j + + )
{
if ( in_faces [ j ] . planenormal [ 0 ] = = in_faces [ faceid ] . planenormal [ 0 ] & &
in_faces [ j ] . planenormal [ 1 ] = = in_faces [ faceid ] . planenormal [ 1 ] & &
in_faces [ j ] . planenormal [ 2 ] = = in_faces [ faceid ] . planenormal [ 2 ] & &
in_faces [ j ] . planedist = = in_faces [ faceid ] . planedist )
{
G_INT ( OFS_RETURN ) = 0 ;
return ;
}
}
//generate a list that Terr_GenerateBrushFace can actually use, silly, but lets hope this isn't needed to be nippy
for ( j = 0 ; j < numfaces ; j + + )
{
VectorCopy ( in_faces [ j ] . planenormal , planes [ j ] ) ;
planes [ j ] [ 3 ] = in_faces [ j ] . planedist ;
}
//generate points now (so we know the correct mins+maxs for the brush, and whether the plane is relevent)
numpoints = Terr_GenerateBrushFace ( facepoints , countof ( facepoints ) , planes , numfaces , planes [ faceid ] ) ;
G_INT ( OFS_RETURN ) = numpoints ;
if ( numpoints > maxpoints )
numpoints = maxpoints ;
//... and copy them out without padding. yeah, silly.
for ( j = 0 ; j < numpoints ; j + + )
{
VectorCopy ( facepoints [ j ] , out_verts [ j ] ) ;
}
}
2015-04-14 23:12:17 +00:00
// {"brush_getfacepoints",PF_brush_getfacepoints,0,0, 0, 0, D("int(float modelid, int brushid, int faceid, vector *points, int maxpoints)", "Allows you to easily set transient visual properties of a brush. If brush/face is -1, applies to all. returns old value. selectedstate=-1 changes nothing (called for its return value).")},
void QCBUILTIN PF_brush_getfacepoints ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
unsigned int brushid = G_INT ( OFS_PARM1 ) ;
unsigned int faceid = G_INT ( OFS_PARM2 ) ;
unsigned int maxpoints = G_INT ( OFS_PARM4 ) , p ;
vec3_t * out_verts = validateqcpointer ( prinst , G_INT ( OFS_PARM3 ) , sizeof ( * out_verts ) , maxpoints ) ;
size_t i ;
brushes_t * br ;
G_INT ( OFS_RETURN ) = 0 ;
if ( ! hm )
return ;
for ( i = 0 ; i < hm - > numbrushes ; i + + )
{
br = & hm - > wbrushes [ i ] ;
if ( br - > id = = brushid )
{
if ( ! faceid )
{
if ( maxpoints > = 2 )
{
VectorCopy ( br - > mins , out_verts [ 0 ] ) ;
VectorCopy ( br - > maxs , out_verts [ 1 ] ) ;
G_INT ( OFS_RETURN ) = 2 ;
}
else if ( maxpoints = = 1 )
{
VectorInterpolate ( br - > mins , 0.5 , br - > maxs , out_verts [ 0 ] ) ;
G_INT ( OFS_RETURN ) = 1 ;
}
}
else
{
faceid - - ;
if ( faceid > = br - > numplanes )
break ;
maxpoints = min ( maxpoints , br - > faces [ faceid ] . numpoints ) ;
for ( p = 0 ; p < maxpoints ; p + + )
VectorCopy ( br - > faces [ faceid ] . points [ p ] , out_verts [ p ] ) ;
G_INT ( OFS_RETURN ) = p ;
}
break ;
}
}
}
// {"brush_findinvolume",PF_brush_findinvolume,0,0, 0, 0, D("int(float modelid, vector *planes, float *dists, int numplanes, int *out_brushes, int *out_faces, int maxresults)", "Allows you to easily obtain a list of brushes+faces within the given bounding region. If out_faces is not null, the same brush might be listed twice.")},
void QCBUILTIN PF_brush_findinvolume ( pubprogfuncs_t * prinst , struct globalvars_s * pr_globals )
{
world_t * vmw = prinst - > parms - > user ;
model_t * mod = vmw - > Get_CModel ( vmw , G_FLOAT ( OFS_PARM0 ) ) ;
heightmap_t * hm = mod ? mod - > terrain : NULL ;
int in_numplanes = G_INT ( OFS_PARM3 ) ;
vec3_t * in_normals = validateqcpointer ( prinst , G_INT ( OFS_PARM1 ) , sizeof ( * in_normals ) , in_numplanes ) ;
float * in_distances = validateqcpointer ( prinst , G_INT ( OFS_PARM2 ) , sizeof ( * in_distances ) , in_numplanes ) ;
unsigned int maxresults = G_INT ( OFS_PARM6 ) ;
unsigned int * out_brushids = validateqcpointer ( prinst , G_INT ( OFS_PARM4 ) , sizeof ( * out_brushids ) , maxresults ) ;
unsigned int * out_faceids = G_INT ( OFS_PARM5 ) ? validateqcpointer ( prinst , G_INT ( OFS_PARM5 ) , sizeof ( * out_faceids ) , maxresults ) : NULL ;
unsigned int i , j , k , r = 0 ;
brushes_t * br ;
vec3_t best ;
float dist ;
//find all brushes/faces with a vetex within the region
//the brush is inside if any every plane has at least one vertex on the inner side
if ( hm )
for ( i = 0 ; i < hm - > numbrushes ; i + + )
{
br = & hm - > wbrushes [ i ] ;
for ( j = 0 ; j < in_numplanes ; j + + )
{
for ( k = 0 ; k < 3 ; k + + )
{
if ( in_normals [ j ] [ k ] < 0 )
best [ k ] = br - > maxs [ k ] ;
else
best [ k ] = br - > mins [ k ] ;
}
dist = DotProduct ( best , in_normals [ j ] ) ;
dist = in_distances [ j ] - dist ;
if ( dist < 0 )
break ;
}
if ( j = = in_numplanes )
{
//the box had some point on the near side of every single plane, and thus must contain at least part of the box
if ( r = = maxresults )
break ; //ran out
out_brushids [ r ] = br - > id ;
if ( out_faceids ) //FIXME: handle this properly.
out_faceids [ r ] = 0 ;
r + + ;
}
}
G_INT ( OFS_RETURN ) = r ;
}
void Terr_WriteBrushInfo ( vfsfile_t * file , brushes_t * br )
{
//( -0 -0 16 ) ( -0 -0 32 ) ( 64 -0 16 ) texname [x y z d] [x y z d] rotation sscale tscale
float * point [ 3 ] ;
int i ;
VFS_PRINTF ( file , " \n { " ) ;
for ( i = 0 ; i < br - > numplanes ; i + + )
{
point [ 0 ] = br - > faces [ i ] . points [ 0 ] ;
point [ 1 ] = br - > faces [ i ] . points [ 1 ] ;
point [ 2 ] = br - > faces [ i ] . points [ 2 ] ;
2015-07-30 16:26:15 +00:00
//%.9g is 'meant' to be lossless for a standard ieee single-precision float. (%.17g for a double)
VFS_PRINTF ( file , " \n ( %.9g %.9g %.9g ) ( %.9g %.9g %.9g ) ( %.9g %.9g %.9g ) \" %s \" [ %.9g %.9g %.9g %.9g ] [ %.9g %.9g %.9g %.9g ] 0 1 1 " ,
2015-04-14 23:12:17 +00:00
point [ 0 ] [ 0 ] , point [ 0 ] [ 1 ] , point [ 0 ] [ 2 ] ,
point [ 1 ] [ 0 ] , point [ 1 ] [ 1 ] , point [ 1 ] [ 2 ] ,
point [ 2 ] [ 0 ] , point [ 2 ] [ 1 ] , point [ 2 ] [ 2 ] ,
br - > faces [ i ] . tex ? br - > faces [ i ] . tex - > shadername : " " ,
br - > faces [ i ] . stdir [ 0 ] [ 0 ] , br - > faces [ i ] . stdir [ 0 ] [ 1 ] , br - > faces [ i ] . stdir [ 0 ] [ 2 ] , br - > faces [ i ] . stdir [ 0 ] [ 3 ] ,
br - > faces [ i ] . stdir [ 1 ] [ 0 ] , br - > faces [ i ] . stdir [ 1 ] [ 1 ] , br - > faces [ i ] . stdir [ 1 ] [ 2 ] , br - > faces [ i ] . stdir [ 1 ] [ 3 ]
) ;
}
VFS_PRINTF ( file , " \n } " ) ;
}
void Terr_WriteMapFile ( vfsfile_t * file , model_t * mod )
{
char token [ 8192 ] ;
int nest = 0 ;
const char * start , * entities = mod - > entities ;
int i ;
unsigned int entnum = 0 ;
heightmap_t * hm ;
start = entities ;
while ( entities )
{
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( token [ 0 ] = = ' } ' & & token [ 1 ] = = 0 )
{
nest - - ;
if ( ! nest )
{
if ( ! entnum )
{
// VFS_PRINTF(file, "\n//Worldspawn brushes go here");
hm = mod - > terrain ;
if ( hm )
for ( i = 0 ; i < hm - > numbrushes ; i + + )
Terr_WriteBrushInfo ( file , & hm - > wbrushes [ i ] ) ;
}
entnum + + ;
}
}
else if ( token [ 0 ] = = ' { ' & & token [ 1 ] = = 0 )
{
nest + + ;
}
else
{
if ( ! strcmp ( token , " model " ) )
{
int submodelnum ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( * token = = ' * ' )
submodelnum = atoi ( token + 1 ) ;
else
submodelnum = 0 ;
if ( submodelnum )
{
model_t * submod ;
Q_snprintfz ( token , sizeof ( token ) , " *%i:%s " , submodelnum , mod - > name ) ;
submod = Mod_FindName ( token ) ;
// VFS_PRINTF(file, "\nBrushes for %s go here", token);
hm = submod - > terrain ;
if ( hm )
{
for ( i = 0 ; i < hm - > numbrushes ; i + + )
Terr_WriteBrushInfo ( file , & hm - > wbrushes [ i ] ) ;
start = entities ;
}
}
}
else
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
}
VFS_WRITE ( file , start , entities - start ) ;
start = entities ;
}
}
void Mod_Terrain_Save_f ( void )
{
vfsfile_t * file ;
model_t * mod ;
const char * mapname = Cmd_Argv ( 1 ) ;
const char * fname = Cmd_Argv ( 2 ) ;
if ( Cmd_IsInsecure ( ) )
{
Con_Printf ( " Please use this command via the console \n " ) ;
return ;
}
if ( * mapname )
mod = Mod_FindName ( va ( " maps/%s " , mapname ) ) ;
# ifndef SERVERONLY
else if ( cls . state )
mod = cl . worldmodel ;
# endif
else
mod = NULL ;
if ( ! mod )
{
Con_Printf ( " no model loaded by that name \n " ) ;
return ;
}
if ( ! mod - > terrain | | mod - > loadstate ! = MLS_LOADED )
{
Con_Printf ( " that model has no content worth saving, or isn't fully loaded \n " ) ;
return ;
}
if ( ! * fname )
fname = mod - > name ;
else
fname = va ( " maps/%s.map " , fname ) ;
FS_CreatePath ( fname , FS_GAMEONLY ) ;
file = FS_OpenVFS ( fname , " wb " , FS_GAMEONLY ) ;
if ( ! file )
Con_Printf ( " unable to open %s \n " , fname ) ;
else
{
Terr_WriteMapFile ( file , mod ) ;
VFS_CLOSE ( file ) ;
}
}
qboolean Terr_ReformEntitiesLump ( model_t * mod , heightmap_t * hm , char * entities )
{
char token [ 8192 ] ;
int nest = 0 ;
int buflen = strlen ( entities ) ;
char * out , * start ;
int i ;
int submodelnum = 0 ;
qboolean isdetail = false ;
qboolean foundsubmodel = false ;
qboolean inbrush = false ;
int numplanes = 0 ;
vec4_t planes [ 64 ] ;
struct brushface_s faces [ 64 ] ;
int brushcontents = FTECONTENTS_SOLID ;
heightmap_t * subhm = NULL ;
model_t * submod = NULL ;
# ifdef RUNTIMELIGHTING
hm - > relightcontext = LightStartup ( NULL , mod , false ) ;
hm - > lightthreadmem = BZ_Malloc ( lightthreadctxsize ) ;
hm - > inheritedlightthreadmem = false ;
# endif
/*FIXME: we need to re-form the entities lump to insert model fields as appropriate*/
mod - > entities = out = ZG_Malloc ( & mod - > memgroup , buflen + 1 ) ;
while ( entities )
{
start = entities ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( token [ 0 ] = = ' } ' & & token [ 1 ] = = 0 )
{
nest - - ;
if ( inbrush )
{
brushes_t brush ;
//finish the brush
brush . contents = brushcontents ;
brush . numplanes = numplanes ;
brush . planes = planes ;
brush . faces = faces ;
brush . id = 0 ;
if ( numplanes )
Terr_Brush_Insert ( submod , subhm , & brush ) ;
numplanes = 0 ;
inbrush = false ;
continue ;
}
}
else if ( token [ 0 ] = = ' { ' & & token [ 1 ] = = 0 )
{
nest + + ;
if ( nest = = 1 )
{ //entering a new entity
foundsubmodel = false ;
isdetail = false ;
}
if ( nest = = 2 )
{
if ( isdetail ) //func_detail injects its brushes into the world model for some reason.
{
submod = mod ;
subhm = hm ;
}
else if ( ! foundsubmodel )
2015-01-07 13:34:05 +00:00
{
foundsubmodel = true ;
if ( submodelnum )
{
2015-04-14 23:12:17 +00:00
Q_snprintfz ( token , sizeof ( token ) , " *%i " , submodelnum ) ;
2015-01-07 13:34:05 +00:00
* out + + = ' m ' ;
* out + + = ' o ' ;
* out + + = ' d ' ;
* out + + = ' e ' ;
* out + + = ' l ' ;
* out + + = ' ' ;
* out + + = ' \" ' ;
for ( i = 0 ; token [ i ] ; i + + )
* out + + = token [ i ] ;
* out + + = ' \" ' ;
* out + + = ' ' ;
2015-04-14 23:12:17 +00:00
Q_snprintfz ( token , sizeof ( token ) , " *%i:%s " , submodelnum , mod - > name ) ;
2015-01-07 13:34:05 +00:00
submod = Mod_FindName ( token ) ;
if ( submod - > loadstate = = MLS_NOTLOADED )
{
submod - > type = mod_heightmap ;
submod - > entities = " " ;
subhm = submod - > terrain = Mod_LoadTerrainInfo ( submod , submod - > name , true ) ;
subhm - > exteriorcontents = FTECONTENTS_EMPTY ;
ClearBounds ( submod - > mins , submod - > maxs ) ;
submod - > funcs . NativeTrace = Heightmap_Trace ;
submod - > funcs . PointContents = Heightmap_PointContents ;
submod - > funcs . NativeContents = Heightmap_NativeBoxContents ;
submod - > funcs . LightPointValues = Heightmap_LightPointValues ;
submod - > funcs . StainNode = Heightmap_StainNode ;
submod - > funcs . MarkLights = Heightmap_MarkLights ;
submod - > funcs . ClusterForPoint = Heightmap_ClusterForPoint ;
submod - > funcs . ClusterPVS = Heightmap_ClusterPVS ;
# ifndef CLIENTONLY
submod - > funcs . FindTouchedLeafs = Heightmap_FindTouchedLeafs ;
submod - > funcs . EdictInFatPVS = Heightmap_EdictInFatPVS ;
submod - > funcs . FatPVS = Heightmap_FatPVS ;
# endif
submod - > loadstate = MLS_LOADED ;
2015-04-14 23:12:17 +00:00
# ifdef RUNTIMELIGHTING
subhm - > relightcontext = LightStartup ( hm - > relightcontext , submod , false ) ;
subhm - > lightthreadmem = hm - > lightthreadmem ;
subhm - > inheritedlightthreadmem = true ;
# endif
2015-01-07 13:34:05 +00:00
}
else
subhm = NULL ;
}
else
{
submod = mod ;
subhm = hm ;
}
submodelnum + + ;
}
inbrush = true ;
continue ;
}
}
else if ( inbrush )
{
//parse a plane
//( -0 -0 16 ) ( -0 -0 32 ) ( 64 -0 16 ) texname 0 -32 rotation sscale tscale
//( -0 -0 16 ) ( -0 -0 32 ) ( 64 -0 16 ) texname [x y z d] [x y z d] rotation sscale tscale
2015-04-14 23:12:17 +00:00
//( 0 0 1 16 ) texname [x y z d] [x y z d] rotation sscale tscale
2015-01-07 13:34:05 +00:00
brushtex_t * bt ;
vec3_t d1 , d2 ;
vec3_t points [ 3 ] ;
vec4_t texplane [ 2 ] ;
float scale [ 2 ] , rot ;
2015-04-14 23:12:17 +00:00
int p ;
qboolean hlstyle = false ;
2015-01-07 13:34:05 +00:00
memset ( points , 0 , sizeof ( points ) ) ;
for ( p = 0 ; p < 3 ; p + + )
{
if ( token [ 0 ] ! = ' ( ' | | token [ 1 ] ! = 0 )
break ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
points [ p ] [ 0 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
points [ p ] [ 1 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
points [ p ] [ 2 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( token [ 0 ] ! = ' ) ' | | token [ 1 ] ! = 0 )
{
2015-04-14 23:12:17 +00:00
// VectorClear(points[1]);
// VectorClear(points[2]);
points [ 1 ] [ 0 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( p = = 0 & & ! strcmp ( token , " ) " ) )
p = 4 ; //we just managed to read an entire plane instead of 3 points.
break ;
2015-01-07 13:34:05 +00:00
}
2015-04-14 23:12:17 +00:00
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
}
if ( p < 3 )
{
Con_Printf ( CON_ERROR " %s: malformed brush \n " , mod - > name ) ;
return false ;
}
if ( numplanes = = sizeof ( planes ) / sizeof ( planes [ 0 ] ) )
{
Con_Printf ( CON_ERROR " %s: too many planes in brush \n " , mod - > name ) ;
return false ;
2015-01-07 13:34:05 +00:00
}
bt = Terr_Brush_FindTexture ( subhm , token ) ;
if ( * token = = ' * ' )
{
2015-04-14 23:12:17 +00:00
if ( ! Q_strncasecmp ( token , " *lava " , 5 ) )
2015-01-07 13:34:05 +00:00
brushcontents = FTECONTENTS_LAVA ;
2015-04-14 23:12:17 +00:00
else if ( ! Q_strncasecmp ( token , " *slime " , 5 ) )
2015-01-07 13:34:05 +00:00
brushcontents = FTECONTENTS_SLIME ;
else
brushcontents = FTECONTENTS_WATER ;
}
2015-04-14 23:12:17 +00:00
else if ( ! Q_strncasecmp ( token , " *sky " , 4 ) )
brushcontents = FTECONTENTS_SKY ;
else if ( ! Q_strcasecmp ( token , " clip " ) )
2015-01-08 13:09:20 +00:00
brushcontents = FTECONTENTS_PLAYERCLIP ;
2015-01-07 13:34:05 +00:00
else
brushcontents = FTECONTENTS_SOLID ;
//FIXME: halflife format has the entire [x y z dist] plane specified.
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( * token = = ' [ ' )
{
2015-04-14 23:12:17 +00:00
hlstyle = true ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
2015-01-07 13:34:05 +00:00
texplane [ 0 ] [ 0 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 0 ] [ 1 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 0 ] [ 2 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 0 ] [ 3 ] = atof ( token ) ;
2015-04-14 23:12:17 +00:00
2015-01-07 13:34:05 +00:00
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
//]
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
//[
2015-04-14 23:12:17 +00:00
2015-01-07 13:34:05 +00:00
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 1 ] [ 0 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 1 ] [ 1 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 1 ] [ 2 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 1 ] [ 3 ] = atof ( token ) ;
2015-04-14 23:12:17 +00:00
2015-01-07 13:34:05 +00:00
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
//]
}
else
{
2015-04-14 23:12:17 +00:00
VectorClear ( texplane [ 0 ] ) ;
VectorClear ( texplane [ 1 ] ) ;
2015-01-07 13:34:05 +00:00
texplane [ 0 ] [ 3 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
texplane [ 1 ] [ 3 ] = atof ( token ) ;
}
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
rot = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
scale [ 0 ] = atof ( token ) ;
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
scale [ 1 ] = atof ( token ) ;
2015-04-14 23:12:17 +00:00
if ( p = = 4 )
{ //parsed an actual plane
VectorCopy ( points [ 0 ] , planes [ numplanes ] ) ;
planes [ numplanes ] [ 3 ] = points [ 1 ] [ 0 ] ;
}
else
{ //parsed 3 points.
VectorSubtract ( points [ 0 ] , points [ 1 ] , d1 ) ;
VectorSubtract ( points [ 2 ] , points [ 1 ] , d2 ) ;
CrossProduct ( d1 , d2 , planes [ numplanes ] ) ;
VectorNormalize ( planes [ numplanes ] ) ;
planes [ numplanes ] [ 3 ] = DotProduct ( points [ 1 ] , planes [ numplanes ] ) ;
}
2015-01-07 13:34:05 +00:00
faces [ numplanes ] . tex = bt ;
//quake's .maps use the normal to decide which texture directions to use in some lame axially-aligned way.
2015-04-14 23:12:17 +00:00
if ( ! hlstyle )
2015-01-07 13:34:05 +00:00
{
float a = fabs ( planes [ numplanes ] [ 0 ] ) , b = fabs ( planes [ numplanes ] [ 1 ] ) , c = fabs ( planes [ numplanes ] [ 2 ] ) ;
2015-04-14 23:12:17 +00:00
if ( a > = b & & a > = c )
2015-01-07 13:34:05 +00:00
texplane [ 0 ] [ 1 ] = 1 ;
else
texplane [ 0 ] [ 0 ] = 1 ;
if ( c > a & & c > b )
texplane [ 1 ] [ 1 ] = - 1 ;
else
texplane [ 1 ] [ 2 ] = - 1 ;
}
if ( rot )
{
int mas , mat ;
float s , t ;
float a = rot * ( M_PI / 180 ) ;
float cosa = cos ( a ) , sina = sin ( a ) ;
for ( mas = 0 ; mas < 2 & & ! texplane [ 0 ] [ mas ] ; mas + + ) ;
for ( mat = 0 ; mat < 2 & & ! texplane [ 1 ] [ mat ] ; mat + + ) ;
for ( i = 0 ; i < 2 ; i + + )
{
s = cosa * texplane [ i ] [ mas ] - sina * texplane [ i ] [ mat ] ;
t = sina * texplane [ i ] [ mas ] + cosa * texplane [ i ] [ mat ] ;
texplane [ i ] [ mas ] = s ;
texplane [ i ] [ mat ] = t ;
}
}
if ( ! scale [ 0 ] ) scale [ 0 ] = 1 ;
if ( ! scale [ 1 ] ) scale [ 1 ] = 1 ;
2015-04-14 23:12:17 +00:00
VectorScale ( texplane [ 0 ] , 1.0 / scale [ 0 ] , faces [ numplanes ] . stdir [ 0 ] ) ;
VectorScale ( texplane [ 1 ] , 1.0 / scale [ 1 ] , faces [ numplanes ] . stdir [ 1 ] ) ;
faces [ numplanes ] . stdir [ 0 ] [ 3 ] = texplane [ 0 ] [ 3 ] ;
faces [ numplanes ] . stdir [ 1 ] [ 3 ] = texplane [ 1 ] [ 3 ] ;
2015-01-07 13:34:05 +00:00
numplanes + + ;
continue ;
}
2015-04-14 23:12:17 +00:00
else
{
if ( ! strcmp ( token , " classname " ) )
{
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
if ( ! strcmp ( token , " func_detail " ) )
isdetail = true ;
}
else
entities = COM_ParseOut ( entities , token , sizeof ( token ) ) ;
}
2015-01-07 13:34:05 +00:00
while ( start < entities )
* out + + = * start + + ;
}
* out + + = 0 ;
2015-04-14 23:12:17 +00:00
mod - > numsubmodels = submodelnum ;
return true ;
2015-01-07 13:34:05 +00:00
}
2014-03-30 08:55:06 +00:00
qboolean QDECL Terr_LoadTerrainModel ( model_t * mod , void * buffer , size_t bufsize )
2005-08-26 22:49:36 +00:00
{
2015-01-07 13:34:05 +00:00
int exterior = FTECONTENTS_SOLID ;
2005-08-26 22:49:36 +00:00
heightmap_t * hm ;
2014-10-05 20:04:11 +00:00
char token [ MAX_QPATH ] ;
2012-04-09 19:12:12 +00:00
int sectsize = 0 ;
2015-01-07 13:34:05 +00:00
char * src ;
2012-04-09 19:12:12 +00:00
2015-01-07 13:34:05 +00:00
src = COM_ParseOut ( buffer , token , sizeof ( token ) ) ;
if ( ! strcmp ( token , " terrain " ) )
buffer = src ;
else if ( ! strcmp ( token , " { " ) )
exterior = FTECONTENTS_EMPTY ;
else
2006-03-12 09:19:31 +00:00
{
2007-09-23 15:28:06 +00:00
Con_Printf ( CON_ERROR " %s wasn't terrain map \n " , mod - > name ) ; //shouldn't happen
2006-03-12 09:19:31 +00:00
return false ;
}
2007-05-25 22:16:29 +00:00
2012-04-09 19:12:12 +00:00
mod - > type = mod_heightmap ;
2005-08-26 22:49:36 +00:00
2015-04-14 23:12:17 +00:00
ClearBounds ( mod - > mins , mod - > maxs ) ;
2013-10-29 17:38:22 +00:00
hm = Z_Malloc ( sizeof ( * hm ) ) ;
2012-07-21 08:06:07 +00:00
ClearLink ( & hm - > recycle ) ;
2013-10-29 17:38:22 +00:00
// ClearLink(&hm->collected);
2012-04-09 19:12:12 +00:00
COM_FileBase ( mod - > name , hm - > path , sizeof ( hm - > path ) ) ;
2015-04-14 23:12:17 +00:00
if ( ! Terr_ReformEntitiesLump ( mod , hm , buffer ) )
return false ;
2011-05-20 04:10:46 +00:00
2014-10-05 20:04:11 +00:00
strcpy ( hm - > groundshadername , " terrainshader " ) ;
strcpy ( hm - > skyname , " sky1 " ) ;
hm - > entitylock = Sys_CreateMutex ( ) ;
2012-04-09 19:12:12 +00:00
hm - > sectionsize = sectsize ;
2015-01-07 13:34:05 +00:00
if ( exterior )
{
hm - > firstsegx = - 1 ;
hm - > firstsegy = - 1 ;
hm - > maxsegx = + 1 ;
hm - > maxsegy = + 1 ;
}
else
{
hm - > firstsegx = 0 ;
hm - > firstsegy = 0 ;
hm - > maxsegx = 0 ;
hm - > maxsegy = 0 ;
}
hm - > exteriorcontents = exterior ; //sky outside the map
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2012-08-04 11:28:39 +00:00
Terr_ParseEntityLump ( mod - > entities , hm ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2015-04-14 23:12:17 +00:00
if ( hm - > firstsegx ! = hm - > maxsegx )
{
vec3_t point ;
point [ 0 ] = ( hm - > firstsegx - CHUNKBIAS ) * hm - > sectionsize ;
point [ 1 ] = ( hm - > firstsegy - CHUNKBIAS ) * hm - > sectionsize ;
point [ 2 ] = - 999999999999999999999999.f ;
AddPointToBounds ( point , mod - > mins , mod - > maxs ) ;
point [ 0 ] = ( hm - > maxsegx - CHUNKBIAS ) * hm - > sectionsize ;
point [ 1 ] = ( hm - > maxsegy - CHUNKBIAS ) * hm - > sectionsize ;
point [ 2 ] = 999999999999999999999999.f ;
AddPointToBounds ( point , mod - > mins , mod - > maxs ) ;
}
2012-07-20 01:46:05 +00:00
2012-01-17 07:57:46 +00:00
mod - > funcs . NativeTrace = Heightmap_Trace ;
2005-08-26 22:49:36 +00:00
mod - > funcs . PointContents = Heightmap_PointContents ;
2006-03-06 01:41:09 +00:00
mod - > funcs . NativeContents = Heightmap_NativeBoxContents ;
2005-08-26 22:49:36 +00:00
mod - > funcs . LightPointValues = Heightmap_LightPointValues ;
mod - > funcs . StainNode = Heightmap_StainNode ;
mod - > funcs . MarkLights = Heightmap_MarkLights ;
2014-05-23 02:02:51 +00:00
mod - > funcs . ClusterForPoint = Heightmap_ClusterForPoint ;
mod - > funcs . ClusterPVS = Heightmap_ClusterPVS ;
2005-08-26 22:49:36 +00:00
# ifndef CLIENTONLY
2010-07-11 02:22:39 +00:00
mod - > funcs . FindTouchedLeafs = Heightmap_FindTouchedLeafs ;
2005-08-26 22:49:36 +00:00
mod - > funcs . EdictInFatPVS = Heightmap_EdictInFatPVS ;
mod - > funcs . FatPVS = Heightmap_FatPVS ;
# endif
/* mod->hulls[0].funcs.HullPointContents = Heightmap_PointContents;
mod - > hulls [ 1 ] . funcs . HullPointContents = Heightmap_PointContents ;
mod - > hulls [ 2 ] . funcs . HullPointContents = Heightmap_PointContents ;
mod - > hulls [ 3 ] . funcs . HullPointContents = Heightmap_PointContents ;
*/
mod - > terrain = hm ;
2006-03-12 09:19:31 +00:00
2015-04-14 23:12:17 +00:00
# ifdef RUNTIMELIGHTING
if ( hm - > relightcontext )
LightReloadEntities ( hm - > relightcontext , mod - > entities ) ;
# endif
2006-03-12 09:19:31 +00:00
return true ;
2005-08-26 22:49:36 +00:00
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
void * Mod_LoadTerrainInfo ( model_t * mod , char * loadname , qboolean force )
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
{
heightmap_t * hm ;
2012-08-04 11:28:39 +00:00
heightmap_t potential ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
if ( ! mod - > entities )
return NULL ;
2012-08-04 11:28:39 +00:00
memset ( & potential , 0 , sizeof ( potential ) ) ;
Terr_ParseEntityLump ( mod - > entities , & potential ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
2013-10-29 17:38:22 +00:00
if ( potential . firstsegx > = potential . maxsegx | | potential . firstsegy > = potential . maxsegy )
{
//figure out the size such that it encompases the entire bsp.
potential . firstsegx = floor ( mod - > mins [ 0 ] / potential . sectionsize ) + CHUNKBIAS ;
potential . firstsegy = floor ( mod - > mins [ 1 ] / potential . sectionsize ) + CHUNKBIAS ;
potential . maxsegx = ceil ( mod - > maxs [ 0 ] / potential . sectionsize ) + CHUNKBIAS ;
potential . maxsegy = ceil ( mod - > maxs [ 1 ] / potential . sectionsize ) + CHUNKBIAS ;
2015-01-07 13:34:05 +00:00
if ( * loadname = = ' * ' )
{
potential . firstsegx = bound ( 0 , potential . firstsegx , CHUNKLIMIT ) ;
potential . firstsegy = bound ( 0 , potential . firstsegy , CHUNKLIMIT ) ;
potential . maxsegx = bound ( potential . firstsegx , potential . maxsegx , CHUNKLIMIT ) ;
potential . maxsegy = bound ( potential . firstsegx , potential . maxsegy , CHUNKLIMIT ) ;
}
else
{ //bound it, such that 0 0 will always be loaded.
potential . firstsegx = bound ( 0 , potential . firstsegx , CHUNKBIAS ) ;
potential . firstsegy = bound ( 0 , potential . firstsegy , CHUNKBIAS ) ;
potential . maxsegx = bound ( CHUNKBIAS + 1 , potential . maxsegx , CHUNKLIMIT ) ;
potential . maxsegy = bound ( CHUNKBIAS + 1 , potential . maxsegy , CHUNKLIMIT ) ;
}
2013-10-29 17:38:22 +00:00
if ( ! force )
2014-10-05 20:04:11 +00:00
{
char sect [ MAX_QPATH ] ;
Q_snprintfz ( sect , sizeof ( sect ) , " maps/%s/sect_%03x_%03x.hms " , loadname , potential . firstsegx + ( potential . maxsegx - potential . firstsegx ) / 2 , potential . firstsegy + ( potential . maxsegy - potential . firstsegy ) / 2 ) ;
if ( ! COM_FCheckExists ( sect ) )
{
Q_snprintfz ( sect , sizeof ( sect ) , " maps/%s/block_00_00.hms " , loadname ) ;
if ( ! COM_FCheckExists ( sect ) )
2013-10-29 17:38:22 +00:00
return NULL ;
2014-10-05 20:04:11 +00:00
}
}
2013-10-29 17:38:22 +00:00
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
hm = Z_Malloc ( sizeof ( * hm ) ) ;
2012-08-04 11:28:39 +00:00
* hm = potential ;
2014-10-05 20:04:11 +00:00
hm - > entitylock = Sys_CreateMutex ( ) ;
2012-07-21 08:06:07 +00:00
ClearLink ( & hm - > recycle ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
Q_strncpyz ( hm - > path , loadname , sizeof ( hm - > path ) ) ;
2014-10-05 20:04:11 +00:00
Q_strncpyz ( hm - > groundshadername , " terrainshader " , sizeof ( hm - > groundshadername ) ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
hm - > exteriorcontents = FTECONTENTS_EMPTY ; //bsp geometry outside the heightmap
return hm ;
}
2012-11-27 03:23:19 +00:00
2013-03-31 04:21:08 +00:00
void Mod_Terrain_Create_f ( void )
{
char * mname ;
char * mdata ;
mname = va ( " maps/%s.hmp " , Cmd_Argv ( 1 ) ) ;
mdata = va (
" terrain \n "
" { \n "
2013-05-11 05:03:07 +00:00
" classname \" worldspawn \" \n "
" message \" %s \" \n "
2013-09-06 22:57:44 +00:00
" _sky sky1 \n "
2013-10-29 17:38:22 +00:00
" _fog 0.02 \n "
2013-03-31 04:21:08 +00:00
" _segmentsize 1024 \n "
" _minxsegment -2048 \n "
" _minysegment -2048 \n "
" _maxxsegment 2048 \n "
" _maxysegment 2048 \n "
2014-05-10 13:42:13 +00:00
" //_defaultgroundtexture city4_2 \n "
" //_defaultwatertexture *water2 \n "
" //_defaultgroundheight -1024 \n "
" //_defaultwaterheight 0 \n " //hurrah, sea level.
2013-03-31 04:21:08 +00:00
// "_tiles 64 64 8 8\n"
" } \n "
" { \n "
" classname info_player_start \n "
" origin \" 0 0 1024 \" \n "
" } \n "
2013-05-11 05:03:07 +00:00
, Cmd_Argv ( 2 ) ) ;
2015-06-04 06:15:14 +00:00
COM_WriteFile ( mname , FS_GAMEONLY , mdata , strlen ( mdata ) ) ;
2014-05-10 13:42:13 +00:00
//FIXME: create 4 sections around the origin
2013-03-31 04:21:08 +00:00
}
2013-10-29 17:38:22 +00:00
//reads in the terrain a tile at a time, and writes it out again.
//the new version will match our current format version.
//this is mostly so I can strip out old format revisions...
# ifndef SERVERONLY
void Mod_Terrain_Convert_f ( void )
{
model_t * mod ;
heightmap_t * hm ;
if ( Cmd_FromGamecode ( ) )
return ;
if ( Cmd_Argc ( ) > = 2 )
mod = Mod_FindName ( va ( " maps/%s.hmp " , Cmd_Argv ( 1 ) ) ) ;
else if ( cls . state )
mod = cl . worldmodel ;
else
mod = NULL ;
if ( ! mod | | mod - > type = = mod_dummy )
return ;
hm = mod - > terrain ;
if ( ! hm )
return ;
{
char * texkill = Cmd_Argv ( 2 ) ;
hmsection_t * s ;
int x , sx ;
int y , sy ;
while ( Terr_Collect ( hm ) ) //collect as many as we can now, so when we collect later, the one that's collected is fresh.
;
for ( y = hm - > firstsegy ; y < hm - > maxsegy ; y + = SECTIONSPERBLOCK )
{
Sys_Printf ( " %g%% complete \n " , 100 * ( y - hm - > firstsegy ) / ( float ) ( hm - > maxsegy - hm - > firstsegy ) ) ;
for ( x = hm - > firstsegx ; x < hm - > maxsegx ; x + = SECTIONSPERBLOCK )
{
for ( sy = y ; sy < y + SECTIONSPERBLOCK & & sy < hm - > maxsegy ; sy + + )
{
for ( sx = x ; sx < x + SECTIONSPERBLOCK & & sx < hm - > maxsegx ; sx + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx , sy , TGS_WAITLOAD | TGS_NODOWNLOAD | TGS_NORENDER ) ;
2013-10-29 17:38:22 +00:00
if ( s )
{
if ( * texkill )
ted_texkill ( s , texkill ) ;
s - > flags | = TSF_EDITED ;
}
}
}
for ( sy = y ; sy < y + SECTIONSPERBLOCK & & sy < hm - > maxsegy ; sy + + )
{
for ( sx = x ; sx < x + SECTIONSPERBLOCK & & sx < hm - > maxsegx ; sx + + )
{
2014-10-05 20:04:11 +00:00
s = Terr_GetSection ( hm , sx , sy , TGS_WAITLOAD | TGS_NODOWNLOAD | TGS_NORENDER ) ;
2013-10-29 17:38:22 +00:00
if ( s )
{
if ( s - > flags & TSF_EDITED )
{
if ( Terr_SaveSection ( hm , s , sx , sy , true ) )
{
s - > flags & = ~ TSF_EDITED ;
}
}
}
}
}
while ( Terr_Collect ( hm ) )
;
}
}
Sys_Printf ( " %g%% complete \n " , 100.0f ) ;
}
}
# endif
2013-03-31 04:21:08 +00:00
void Mod_Terrain_Reload_f ( void )
{
model_t * mod ;
heightmap_t * hm ;
if ( Cmd_Argc ( ) > = 2 )
mod = Mod_FindName ( va ( " maps/%s.hmp " , Cmd_Argv ( 1 ) ) ) ;
# ifndef SERVERONLY
else if ( cls . state )
mod = cl . worldmodel ;
# endif
else
mod = NULL ;
if ( ! mod | | mod - > type = = mod_dummy )
return ;
hm = mod - > terrain ;
if ( ! hm )
return ;
if ( Cmd_Argc ( ) > = 4 )
{
hmsection_t * s ;
int sx = atoi ( Cmd_Argv ( 2 ) ) + CHUNKBIAS ;
int sy = atoi ( Cmd_Argv ( 3 ) ) + CHUNKBIAS ;
if ( hm )
{
s = Terr_GetSection ( hm , sx , sy , TGS_NOLOAD ) ;
if ( s )
{
s - > flags | = TSF_NOTIFY ;
}
}
}
else
Terr_PurgeTerrainModel ( mod , false , true ) ;
}
2012-11-27 03:23:19 +00:00
void Terr_Init ( void )
{
Cvar_Register ( & mod_terrain_networked , " Terrain " ) ;
2013-10-29 17:38:22 +00:00
Cvar_Register ( & mod_terrain_defaulttexture , " Terrain " ) ;
2013-11-21 23:02:28 +00:00
Cvar_Register ( & mod_terrain_savever , " Terrain " ) ;
2015-04-14 23:12:17 +00:00
Cmd_AddCommand ( " mod_terrain_save " , Mod_Terrain_Save_f ) ;
2013-03-31 04:21:08 +00:00
Cmd_AddCommand ( " mod_terrain_create " , Mod_Terrain_Create_f ) ;
Cmd_AddCommand ( " mod_terrain_reload " , Mod_Terrain_Reload_f ) ;
2013-10-29 17:38:22 +00:00
# ifndef SERVERONLY
Cmd_AddCommandD ( " mod_terrain_convert " , Mod_Terrain_Convert_f , " mod_terrain_convert [mapname] [texkill] \n Convert a terrain to the current format. If texkill is specified, only tiles with the named texture will be converted, and tiles with that texture will be stripped. This is a slow operation. " ) ;
# endif
Mod_RegisterModelFormatText ( NULL , " FTE Heightmap Map (hmp) " , " terrain " , Terr_LoadTerrainModel ) ;
2015-01-07 13:34:05 +00:00
Mod_RegisterModelFormatText ( NULL , " Quake Map Format (map) " , " { " , Terr_LoadTerrainModel ) ;
2012-11-27 03:23:19 +00:00
}
2005-08-26 22:49:36 +00:00
# endif