added a terrain editor

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4072 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2012-07-14 23:20:06 +00:00
parent 584d2776cc
commit db40d60b95
4 changed files with 1001 additions and 696 deletions

View file

@ -8,7 +8,8 @@ enum
MODE_LIGHTEDIT=1,
MODE_SPLINEEDIT=2,
MODE_PARTICLEEDIT=3
MODE_TERRAINEDIT=3,
MODE_PARTICLEEDIT=4,
};
var vector vidsize = '640 480 0';
@ -16,6 +17,7 @@ vector curmousepos;
vector mousediff;
vector originalmousepos;
float mousedown;
float shiftdown;
/*the renderscene builtin in the parent progs is redirected to here*/
void() wrap_renderscene =
@ -88,10 +90,14 @@ void() wrap_renderscene =
setproperty(VF_DRAWENGINESBAR, 0);
setproperty(VF_DRAWCROSSHAIR, 0);
vidsize = getproperty(VF_SIZE);
if (autocvar_ca_editormode == MODE_LIGHTEDIT)
editor_lights_add();
else if (autocvar_ca_editormode == MODE_SPLINEEDIT)
editor_spline_add();
else if (autocvar_ca_editormode == MODE_TERRAINEDIT)
editor_terrain_add(curmousepos);
renderscene();
@ -119,6 +125,16 @@ void() wrap_renderscene =
col = '1 1 1';
drawrawstring('64 0 0'*(MODE_PARTICLEEDIT-1), "PARTICLES", '8 8 0', col, 1);
if (autocvar_ca_editormode == MODE_TERRAINEDIT)
col = '1 0 0';
else if (curmousepos_y < 8 && curmousepos_x >= 64*(MODE_TERRAINEDIT-1) && curmousepos_x < 64*MODE_TERRAINEDIT)
col = '0 0 1';
else
col = '1 1 1';
drawrawstring('64 0 0'*(MODE_TERRAINEDIT-1), "TERRAIN", '8 8 0', col, 1);
if (autocvar_ca_editormode == MODE_LIGHTEDIT)
editor_lights_overlay(curmousepos);
else if (autocvar_ca_editormode == MODE_SPLINEEDIT)
@ -129,6 +145,8 @@ void() wrap_renderscene =
}
else if (autocvar_ca_editormode == MODE_PARTICLEEDIT)
editor_particles_overlay(curmousepos);
else if (autocvar_ca_editormode == MODE_TERRAINEDIT)
editor_terrain_overlay(curmousepos);
drawcharacter(curmousepos - '4 4', '+', '8 8', '1 1 1', 1);
};
@ -164,6 +182,11 @@ float (float event, float parama, float paramb) wrap_InputEvent =
if (editor_particles_key(parama, paramb, curmousepos))
return TRUE;
}
else if (autocvar_ca_editormode == MODE_TERRAINEDIT)
{
if (editor_terrain_key(parama, paramb, curmousepos))
return TRUE;
}
if (parama == 512)
{
mousedown = 1;
@ -218,9 +241,6 @@ float (float event, float parama, float paramb) wrap_InputEvent =
/*this is a fallback function, in case the main progs does not have one*/
void(float width, float height, float do2d) CSQC_UpdateView =
{
vidsize_x = width;
vidsize_y = height;
vidsize_z = 0;
clearscene();
setproperty(VF_DRAWENGINESBAR, 1);
setproperty(VF_DRAWCROSSHAIR, 1);

View file

@ -1,9 +1,10 @@
../csprogs.dat
../csaddon.dat
//pr_dumpplatform -FFTE -Fdefines -TCS -O csplat
opts.qc
csplat.qc
editor_lights.qc
editor_terrain.qc
textfield.qc
editor_particles.qc
menu.qc

View file

@ -29,7 +29,8 @@ float intermission;
vector v_forward, v_up, v_right;
vector view_angles;
float trace_allsolid, trace_startsolid, trace_fraction;
vector trace_endpos, trace_plane_normal;
shared vector trace_endpos;
vector trace_plane_normal;
float trace_plane_dist;
entity trace_ent;
float trace_inopen;
@ -88,6 +89,8 @@ void end_sys_fields;
.entity tag_entity;
.float skeletonindex;
.vector colormod;
.vector glowmod;
.vector gravitydir;
.float friction;
.float erp;
.float jointtype;
@ -108,7 +111,6 @@ void end_sys_fields;
.float bonecontrol5;
.float subblendfrac;
.float basesubblendfrac;
.vector glowmod;
.float ideal_pitch;
.float pitch_speed;
var float physics_mode = 2;
@ -479,6 +481,10 @@ void(float buf, float fl) writefloat = #280;
#endif
float*(float skel) skel_mmap = #282;
void(entity ent, float bonenum, vector org, optional vector angorfwd, optional vector right, optional vector up) skel_set_bone_world = #283;
void*(int size) memalloc = #384;
void(void *ptr) memfree = #385;
void(void *dst, void *src, int size) memcpy = #386;
void(void *dst, int val, int size) memset = #387;
#ifdef CSQC
void() clearscene = #300;
void(float mask) addentities = #301;
@ -487,7 +493,7 @@ void(entity ent) addentity = #302;
float(float property, ...) setproperty = #303;
void() renderscene = #304;
float(vector org, float radius, vector lightcolours) dynamiclight_add = #305;
void(string texturename) R_BeginPolygon = #306;
void(string texturename, optional float flags) R_BeginPolygon = #306;
void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex = #307;
void() R_EndPolygon = #308;
#define getviewprop getproperty
@ -667,7 +673,11 @@ float(string name) cvar_type = #495;
//string(float fieldnum, entity ent) getentityfieldstring = #499;
//float(float fieldnum, entity ent, string s) putentityfieldstring = #500;
//void(float to, string s, float sz) WritePicture = #501;
//string() ReadPicture = #501;
string(string filename) whichpack = #503;
#ifdef CSQC
__variant(float entnum, float fieldnum) getentity = #504;
#endif
string(string in) uri_escape = #510;
string(string in) uri_unescape = #511;
float(entity ent) num_for_edict = #512;

View file

@ -0,0 +1,274 @@
enum
{
ter_reload = 0, //reload the entire thing
ter_save = 1, //save the entire heightmap
ter_sethole = 2,
ter_height_set = 3, //set heights to a specific value
ter_height_smooth = 4, //smooth the heights slightly (non-destructive)
ter_height_spread = 5, //smooth the heights slightly (leaves center as-is)
ter_height_raise = 6, //raise the terrain in a bell (negative value to lower)
ter_height_lower = 7, //lower the terrain in a bell (negative value to raise)
ter_tex_kill = 8, //set section texture
ter_tex_get = 9, //get section texture
ter_mixpaint = 10, //paint a specific texture
ter_mixconcentrate = 11, //figure out which is the strongest mixed texture and make it stronger
ter_mixnoise = 12, //add random noise to the affected samples
ter_mixblur = 13, //blur the texture mixture
ter_blank,
ter_radius,
ter_quant,
ter_tex,
ter_count
};
static var float eradius = 256;
static var float equant = 8;
static var vector emix = '1 0 0';
static string tex[8];
static float curtool;
static int painttex;
static string toolname[ter_count] =
{
"reload",
"save",
"holes",
"height set",
"height smooth",
"height spread",
"height raise",
"height lower",
"tex kill",
"tex get",
"mix paint",
"mix concentrate",
"mix noise",
"mix blur",
"",
"rad",
"quant",
"tex"
};
#define terrain_edit terrain_editfoo
__variant(float action, ...) terrain_edit = #278;
float(float keyc, float unic, vector m) editor_terrain_key =
{
if (curtool == ter_tex)
{
string txt;
float nt = curtool;
if (curtool == ter_radius)
txt = itos((int)eradius);
if (curtool == ter_quant)
txt = itos((int)equant);
if (curtool == ter_tex)
txt = tex[painttex];
if (keyc == 10 || keyc == 13)
nt = ter_mixpaint;
else if (keyc == 127)
txt = substring(txt, 0, -2);
else if (keyc == 8)
txt = "";
else if (unic)
txt = strcat(txt, chr2str(unic));
if (curtool == ter_radius)
eradius = stof(txt);
if (curtool == ter_quant)
equant = stof(txt);
if (curtool == ter_tex)
{
txt = strzone(txt);
strunzone(tex[painttex]);
tex[painttex] = txt;
}
curtool = nt;
}
else if (keyc == 13 || keyc == 512)
{
if (m_x < 128)
curtool = floor((m_y-16) / 8);
else
{
vector t = unproject(m + '0 0 8192');
vector o = unproject(m);
if (vlen(o - t) > 8192)
t = o + normalize(t)*8192;
traceline(o, t, TRUE, world);
switch(curtool)
{
case ter_reload:
case ter_save:
terrain_edit(curtool);
break;
case ter_sethole: //use view center instead of targetted - you cannot target that which is not there
terrain_edit(curtool, trace_endpos, eradius, equant);
break;
case ter_height_set:
case ter_height_smooth:
case ter_height_raise:
case ter_height_lower:
terrain_edit(curtool, trace_endpos, eradius, equant);
break;
case ter_tex_get:
strunzone(tex[0]);
strunzone(tex[1]);
strunzone(tex[2]);
strunzone(tex[3]);
tex[0] = strzone(terrain_edit(curtool, trace_endpos, 0, 0));
tex[1] = strzone(terrain_edit(curtool, trace_endpos, 0, 1));
tex[2] = strzone(terrain_edit(curtool, trace_endpos, 0, 2));
tex[3] = strzone(terrain_edit(curtool, trace_endpos, 0, 3));
break;
// case ter_mixset:
// terrain_edit(curtool, trace_endpos, eradius, equant, emix);
// break;
case ter_mixpaint:
terrain_edit(curtool, trace_endpos, eradius, equant, tex[painttex]);
break;
case ter_tex_kill:
terrain_edit(curtool, trace_endpos, eradius, equant, tex[painttex]);
break;
case ter_mixconcentrate:
case ter_mixnoise:
case ter_mixblur:
terrain_edit(curtool, trace_endpos, eradius, equant);
break;
}
}
}
else if (unic == '+' || unic == '=')
eradius += 16;
else if (unic == '-')
eradius -= 16;
else if (unic == '[')
equant -= 1;
else if (unic == ']')
equant += 1;
else if (unic == '{')
painttex = (painttex + 7) & 7;
else if (unic == '}')
painttex = (painttex + 1) & 7;
else if (unic == '1')
painttex = 0;
else if (unic == '2')
painttex = 1;
else if (unic == '3')
painttex = 2;
else if (unic == '4')
painttex = 3;
else if (unic == '5')
painttex = 4;
else if (unic == '6')
painttex = 5;
else if (unic == '7')
painttex = 6;
else if (unic == '8')
painttex = 7;
else
return FALSE;
return TRUE;
};
shared vector v_forward;
shared vector v_right;
shared vector v_up;
void(vector mousepos) editor_terrain_add =
{
float s,c;
float r;
vector tx, p, col;
float a;
if (mousepos_x < 128)
return;
vector t = unproject(mousepos + '0 0 8192');
vector o = unproject(mousepos);
if (vlen(o - t) > 8192)
t = o + normalize(t)*8192;
traceline(o, t, TRUE, world);
shaderforname("terrainedit",
"{"
"{\n"
"map terrainedit\n"
"blendfunc add\n"
"rgbgen vertex\n"
"alphagen vertex\n"
"}\n"
"}");
r = eradius;//sqrt(eradius*eradius/2);
s = sin(gettime(5)) * r;
c = cos(gettime(5)) * r;
col_x = (sin(gettime(5))+1.5)*0.1;
R_BeginPolygon("terrainedit");
for (a = 0; a < 3.14*2; a += 3.14*2/8)
{
tx_x = sin(a);
tx_y = cos(a);
//-1 -1
p_x = trace_endpos_x + tx_x*c - tx_y*s;
p_y = trace_endpos_y + tx_y*c + tx_x*s;
p_z = trace_endpos_z + 5;
tx = (tx*0.5)+'0.5 0.5 0';
R_PolygonVertex(p, tx, col, 1);
}
R_EndPolygon();
};
vector vidsize;
void(vector mousepos) editor_terrain_overlay =
{
float i;
vector pos;
vector colour;
pos = '128 0 0';
pos_y = vidsize_y - 32;
drawfill('0 16 0', pos, '0 0 0', 0.3);
pos = '0 16 0';
for (i = 0; i < ter_count; i+=1)
{
if (curtool == i)
colour = '1 0 0';
else if (mousepos_x < 128 && mousepos_y >= pos_y && mousepos_y < pos_y + 8)
colour = '0 0 1';
else
colour = '1 1 1';
if (i == ter_radius)
drawstring(pos, sprintf("radius: %g", eradius), '8 8 0', colour, 1, 0);
else if (i == ter_quant)
drawstring(pos, sprintf("quantity: %g", equant), '8 8 0', colour, 1, 0);
else if (i == ter_tex)
{
if (curtool == ter_tex_get)
{
drawstring(pos, sprintf("Tex0: %s", tex[0]), '8 8 0', colour, 1, 0); pos_y += 8;
drawstring(pos, sprintf("Tex1: %s", tex[1]), '8 8 0', colour, 1, 0); pos_y += 8;
drawstring(pos, sprintf("Tex2: %s", tex[2]), '8 8 0', colour, 1, 0); pos_y += 8;
drawstring(pos, sprintf("Tex3: %s", tex[3]), '8 8 0', colour, 1, 0);
}
else
drawstring(pos, sprintf("Tex%1i: %s", painttex, tex[painttex]), '8 8 0', colour, 1, 0);
}
else
drawstring(pos, toolname[i], '8 8 0', colour, 1, 0);
pos_y += 8;
}
};