From e2ac8efadde00ac28cfa367a182477042b4b8964 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Wed, 22 Oct 2014 12:08:42 +0200 Subject: [PATCH] remove restrictions on mapmodel rotation Until now, the angles of mapmodels (and ctf-flags) were rounded to the nearest 15-degree-step during rendering. This patch moves the rounding to the time of placement of the model. Now the angle can be changed freely after the model has been placed. This commit also changes the angle resolution to 0.25 degree. When changing the angle (press "1" + scrollwheel), additionally pressing editmeta (a.k.a. LCTRL) changes the increments of the wheel from 1 to 10. During a savemap with format 9, the angle resolution is reduced again, to keep compatibility. Therefore, this features is only for testing right now. It won't be preserved during a save (at least, as long as format 9 is used) --- config/scripts.cfg | 2 +- source/src/editing.cpp | 4 ++-- source/src/entities.cpp | 6 +++--- source/src/entity.h | 6 +++--- source/src/world.cpp | 2 +- source/src/worldio.cpp | 13 +++++++++++++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/config/scripts.cfg b/config/scripts.cfg index 11ccd225..25162f18 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -224,7 +224,7 @@ delta_edit_1 = [ if $flrceil [ vdelta $arg1 ] [ vdelta (- 0 $arg1) ] ] // Change delta_edit_2 = [ edittex $flrceil $arg1 ] // Change floor/ceiling textures... delta_edit_3 = [ edittex (+ $flrceil 1) $arg1 ] // Change wall/upper-wall textures... delta_edit_4 = [ equalize $flrceil ] // Equalize floor/ceiling... -delta_edit_5 = [ entproperty 0 $arg1 ] // Changes the first value on entities... +delta_edit_5 = [ entproperty 0 (* $arg1 (at "1 10" $editmetakeydown)) ] // Changes the first value on entities... delta_edit_6 = [ entproperty $editaxis $arg1 ] // Move map entity... delta_edit_7 = [ entproperty 1 $arg1 ] // Changes the second value on entities... delta_edit_8 = [ entproperty 2 $arg1 ] // Changes the third value on entities... diff --git a/source/src/editing.cpp b/source/src/editing.cpp index f858ea8b..1dd923a2 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -26,8 +26,8 @@ sqr rtex; VAR(editing, 1, 0, 0); VAR(unsavededits, 1, 0, 0); -bool editmetakeydown = false; -COMMANDF(editmeta, "d", (bool on) { editmetakeydown = on; } ); +VAR(editmetakeydown, 1, 0, 0); +COMMANDF(editmeta, "d", (bool on) { editmetakeydown = on ? 1 : 0; } ); void toggleedit(bool force) { diff --git a/source/src/entities.cpp b/source/src/entities.cpp index d61491b0..ae5d1f55 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -67,7 +67,7 @@ void rendermapmodels() { mapmodelinfo &mmi = getmminfo(e.attr2); if(!&mmi) continue; - rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor+mmi.zoff+e.attr3), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 10.0f); + rendermodel(mmi.name, ANIM_MAPMODEL|ANIM_LOOP, e.attr4, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor+mmi.zoff+e.attr3), e.attr1 / 4.0f, 0, 10.0f); } } } @@ -218,7 +218,7 @@ void renderentities() if(e.type==CTF_FLAG) { defformatstring(path)("pickups/flags/%s", team_basestring(e.attr2)); - rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); + rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor), e.attr1 / 4.0f, 0, 120.0f); } else if((e.type == CLIP || e.type == PLCLIP) && showclips && !stenciling) renderclip(e); else if(e.type == MAPMODEL && showclips && showmodelclipping && !stenciling) @@ -271,7 +271,7 @@ void renderentities() if(OUTBORD(f.pos.x, f.pos.y)) break; entity &e = *f.flagent; defformatstring(path)("pickups/flags/%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); - if(f.flagent->spawned) rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(f.pos.x, f.pos.y, f.state==CTFF_INBASE ? (float)S(int(f.pos.x), int(f.pos.y))->floor : f.pos.z), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); + if(f.flagent->spawned) rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(f.pos.x, f.pos.y, f.state==CTFF_INBASE ? (float)S(int(f.pos.x), int(f.pos.y))->floor : f.pos.z), e.attr1 / 4.0f, 0, 120.0f); break; } case CTFF_IDLE: diff --git a/source/src/entity.h b/source/src/entity.h index 286f644b..1d75cd7d 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -6,13 +6,13 @@ enum // static entity types I_CLIPS, I_AMMO, I_GRENADE, I_HEALTH, I_HELMET, I_ARMOUR, I_AKIMBO, // helmet : 2010may16 -> mapversion:8 - MAPMODEL, // attr1 = angle, attr2 = idx + MAPMODEL, // attr1 = angle, attr2 = idx, attr3 = elevation, attr4 = texture CARROT, // attr1 = tag, attr2 = type LADDER, CTF_FLAG, // attr1 = angle, attr2 = red/blue SOUND, - CLIP, - PLCLIP, + CLIP, // attr1 = elevation, attr2 = xradius, attr3 = yradius, attr4 = height + PLCLIP, // attr1 = elevation, attr2 = xradius, attr3 = yradius, attr4 = height MAXENTTYPES }; diff --git a/source/src/world.cpp b/source/src/world.cpp index ae27dbc1..58e78fbc 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -286,11 +286,11 @@ entity *newentity(int index, int x, int y, int z, char *what, int v1, int v2, in case MAPMODEL: e.attr4 = e.attr3; e.attr3 = e.attr2; - e.attr2 = (uchar)e.attr1; case PLAYERSTART: case CTF_FLAG: e.attr2 = v1; e.attr1 = (int)camera1->yaw; + if(type != PLAYERSTART) e.attr1 = (e.attr1 + 7 - (e.attr1 + 7) % 15) * 4; break; } syncentchanges(true); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index e765e06a..43b7a553 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -486,6 +486,7 @@ void save_world(char *mname, bool skipoptimise, bool addcomfort) int writeextra = 0; if(hx.maxlen) tmp.headersize += writeextra = clamp(hx.maxlen, 0, MAXHEADEREXTRA); if(writeextra || skipoptimise) tmp.version = 10; // 9 and 10 are the same, but in 10 the headersize is reliable - if we don't need it, stick to 9 + bool oldmapmodelscaling = tmp.version < 10; tmp.maprevision += advancemaprevision; DEBUG("version " << tmp.version << " headersize " << tmp.headersize << " entities " << tmp.numents << " factor " << tmp.sfactor << " revision " << tmp.maprevision); lilswap(&tmp.version, 4); @@ -501,6 +502,7 @@ void save_world(char *mname, bool skipoptimise, bool addcomfort) { if(!ne--) break; persistent_entity tmp = ents[i]; + if(oldmapmodelscaling && tmp.type == MAPMODEL) tmp.attr1 = tmp.attr1 / 4; lilswap((short *)&tmp, 4); f->write(&tmp, sizeof(persistent_entity)); } @@ -638,6 +640,17 @@ bool load_world(char *mname) // still supports all map formats that have if(e.attr1>32) e.attr1 = 32; // 12_03 and below } transformoldentities(hdr.version, e.type); + if(hdr.version < 10) + { + switch(e.type) + { + case CTF_FLAG: + case MAPMODEL: + e.attr1 = e.attr1 + 7 - (e.attr1 + 7) % 15; // round the angle to the nearest 15-degree-step + e.attr1 = (e.attr1 % 360) * 4; // cut down to less that one rotation and set resolution to 0.25 degree + break; + } + } if(e.type == PLAYERSTART && (e.attr2 == 0 || e.attr2 == 1 || e.attr2 == 100)) { if(e.attr2 == 100)