From d1253d63943593a820e991436881ef6a4ac46ca9 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 3 Dec 2009 12:21:21 +0000 Subject: [PATCH] added support for ambient light git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4737 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/tools.cpp | 2 +- source/src/world.cpp | 1 + source/src/world.h | 3 ++- source/src/worldio.cpp | 5 +++-- source/src/worldlight.cpp | 36 +++++++++++++++++++++++++----------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 997bb799..af014eb9 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -48,7 +48,7 @@ mapstats *loadmapstats(const char *filename, bool getlayout) if(s.hdr.version>=4) { lilswap(&s.hdr.waterlevel, 1); - lilswap(&s.hdr.maprevision, 1); + lilswap(&s.hdr.maprevision, 2); } else s.hdr.waterlevel = -100000; if(s.hdr.version<7) diff --git a/source/src/world.cpp b/source/src/world.cpp index f84cc866..cd98419e 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -460,6 +460,7 @@ bool empty_world(int factor, bool force) // main empty world creation routine copystring(hdr.maptitle, "Untitled Map by Unknown", 128); copystring(hdr.mediareq, "", 128); // MediaPack hdr.waterlevel = -100000; + hdr.ambient = 0; setwatercolor(); loopi(sizeof(hdr.reserved)/sizeof(hdr.reserved[0])) hdr.reserved[i] = 0; loopk(3) loopi(256) hdr.texlists[k][i] = i; diff --git a/source/src/world.h b/source/src/world.h index 5a8438af..8bea0508 100644 --- a/source/src/world.h +++ b/source/src/world.h @@ -46,7 +46,8 @@ struct header // map file format header int waterlevel; uchar watercolor[4]; int maprevision; - int reserved[13]; + int ambient; + int reserved[12]; char mediareq[128]; // new since version 7 (flowtron) // actually a maximum of 124 will ever be used (24*5+4) }; diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 534fff3f..deef44fe 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -370,7 +370,7 @@ void save_world(char *mname) lilswap(&tmp.version, 4); lilswap(&tmp.waterlevel, 1); tmp.maprevision += advancemaprevision; - lilswap(&tmp.maprevision, 1); + lilswap(&tmp.maprevision, 2); f->write(&tmp, sizeof(header)); int ne = hdr.numents; loopv(ents) @@ -473,12 +473,13 @@ bool load_world(char *mname) // still supports all map formats that have { lilswap(&hdr.waterlevel, 1); if(!hdr.watercolor[3]) setwatercolor(); - lilswap(&hdr.maprevision, 1); + lilswap(&hdr.maprevision, 2); curmaprevision = hdr.maprevision; } else { hdr.waterlevel = -100000; + hdr.ambient = 0; } if(hdr.version<7) hdr.mediareq[0] = '\0'; else diff --git a/source/src/worldlight.cpp b/source/src/worldlight.cpp index cd41fe34..62356abb 100644 --- a/source/src/worldlight.cpp +++ b/source/src/worldlight.cpp @@ -51,12 +51,9 @@ void lightray(float bx, float by, const persistent_entity &light, float fade = 1 loopi(steps) { sqr *s = S(x>>PRECBITS, y>>PRECBITS); - int tl = (l>>PRECBITS)+s->r; - s->r = tl>255 ? 255 : tl; - tl = (g>>PRECBITS)+s->g; - s->g = tl>255 ? 255 : tl; - tl = (b>>PRECBITS)+s->b; - s->b = tl>255 ? 255 : tl; + s->r = min((l>>PRECBITS)+s->r, 255); + s->g = min((g>>PRECBITS)+s->g, 255); + s->b = min((b>>PRECBITS)+s->b, 255); if(SOLID(s)) return; x += stepx; y += stepy; @@ -79,11 +76,22 @@ void lightray(float bx, float by, const persistent_entity &light, float fade = 1 if(OUTBORD(x>>PRECBITS, y>>PRECBITS)) return; - loopi(steps) + if(hdr.ambient > 0xFF) loopi(steps) { sqr *s = S(x>>PRECBITS, y>>PRECBITS); - int tl = (l>>PRECBITS)+s->r; - s->r = s->g = s->b = tl>255 ? 255 : tl; + s->r = min((l>>PRECBITS)+s->r, 255); + s->g = min((l>>PRECBITS)+s->g, 255); + s->b = min((l>>PRECBITS)+s->b, 255); + if(SOLID(s)) return; + x += stepx; + y += stepy; + l -= stepl; + stepl -= 25; + } + else loopi(steps) + { + sqr *s = S(x>>PRECBITS, y>>PRECBITS); + s->r = s->g = s->b = min((l>>PRECBITS)+s->r, 255); if(SOLID(s)) return; x += stepx; y += stepy; @@ -105,7 +113,6 @@ void lightray(float bx, float by, const persistent_entity &light, float fade = 1 l -= stepl; } } - } void calclightsource(const persistent_entity &l, float fade = 1, bool flicker = true) @@ -151,12 +158,19 @@ void fullbrightlight(int level) lastcalclight = totalmillis; } +VARF(ambient, 0, 0, 0xFFFFFF, if(!noteditmode()) { hdr.ambient = ambient; calclight(); }); + void calclight() { + bvec acol((hdr.ambient>>16)&0xFF, (hdr.ambient>>8)&0xFF, hdr.ambient&0xFF); + if(!acol.x && !acol.y) acol.x = acol.y = acol.z ? acol.z : 10; + else if(!maxtmus) acol.x = acol.y = acol.z = max(max(acol.x, acol.y), acol.z); // the old (white) light code, here for the few people with old video cards that don't support overbright loop(x,ssize) loop(y,ssize) { sqr *s = S(x,y); - s->r = s->g = s->b = 10; + s->r = acol.x; + s->g = acol.y; + s->b = acol.z; } loopv(ents)