Added building size. Removed material flags (on by default)

develop
Warmist 2013-06-26 20:19:30 +03:00
parent d90a7bfb88
commit b7f28877a2
3 changed files with 44 additions and 28 deletions

@ -400,6 +400,13 @@ bool lightingEngineViewscreen::addLight(int tileId,const lightSource& light)
lights[tileId].flicker=true; lights[tileId].flicker=true;
return wasLight; return wasLight;
} }
void lightingEngineViewscreen::addOclusion(int tileId,const lightCell& c,float thickness)
{
if(thickness > 0.999 && thickness < 1.001)
ocupancy[tileId]*=c;
else
ocupancy[tileId]*=(c.power(thickness));
}
lightCell getStandartColor(int colorId) lightCell getStandartColor(int colorId)
{ {
return lightCell(df::global::enabler->ccolor[colorId][0]/255.0f, return lightCell(df::global::enabler->ccolor[colorId][0]/255.0f,
@ -444,32 +451,30 @@ void lightingEngineViewscreen::applyMaterial(int tileId,const matLightDef& mat,f
{ {
if(mat.isTransparent) if(mat.isTransparent)
{ {
if(thickness > 0.999 && thickness < 1.001) addOclusion(tileId,mat.transparency,thickness);
ocupancy[tileId]*=mat.transparency;
else
ocupancy[tileId]*=(mat.transparency.power(thickness));
} }
else else
ocupancy[tileId]=lightCell(0,0,0); ocupancy[tileId]=lightCell(0,0,0);
if(mat.isEmiting) if(mat.isEmiting)
addLight(tileId,mat.makeSource(size)); addLight(tileId,mat.makeSource(size));
} }
bool lightingEngineViewscreen::applyMaterial(int tileId,int matType,int matIndex,float size,const matLightDef* def) bool lightingEngineViewscreen::applyMaterial(int tileId,int matType,int matIndex,float size,float thickness,const matLightDef* def)
{ {
matLightDef* m=getMaterial(matType,matIndex); matLightDef* m=getMaterial(matType,matIndex);
if(m) if(m)
{ {
applyMaterial(tileId,*m,size); applyMaterial(tileId,*m,size,thickness);
return true; return true;
} }
else if(def) else if(def)
{ {
applyMaterial(tileId,*def,size); applyMaterial(tileId,*def,size,thickness);
} }
return false; return false;
} }
lightCell lightingEngineViewscreen::propogateSun(MapExtras::Block* b, int x,int y,const lightCell& in,bool lastLevel) lightCell lightingEngineViewscreen::propogateSun(MapExtras::Block* b, int x,int y,const lightCell& in,bool lastLevel)
{ {
//TODO unify under addLight/addOclusion
const lightCell matStairCase(0.9f,0.9f,0.9f); const lightCell matStairCase(0.9f,0.9f,0.9f);
lightCell ret=in; lightCell ret=in;
coord2d innerCoord(x,y); coord2d innerCoord(x,y);
@ -645,7 +650,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(d.bits.hidden) if(d.bits.hidden)
{ {
curCell=lightCell(0,0,0); curCell=lightCell(0,0,0);
continue; // do not process hidden stuff continue; // do not process hidden stuff, TODO other hidden stuff
} }
//df::tile_occupancy o = b->OccupancyAt(gpos); //df::tile_occupancy o = b->OccupancyAt(gpos);
df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,type); df::tiletype_shape shape = ENUM_ATTR(tiletype,shape,type);
@ -670,11 +675,11 @@ void lightingEngineViewscreen::doOcupancyAndLights()
} }
else if(!d.bits.liquid_type && d.bits.flow_size>0 ) else if(!d.bits.liquid_type && d.bits.flow_size>0 )
{ {
applyMaterial(tile,matWater, 1, (float)d.bits.flow_size/7.0f); applyMaterial(tile,matWater, (float)d.bits.flow_size/7.0f, (float)d.bits.flow_size/7.0f);
} }
if(d.bits.liquid_type && d.bits.flow_size>0) if(d.bits.liquid_type && d.bits.flow_size>0)
{ {
applyMaterial(tile,matLava); applyMaterial(tile,matLava,(float)d.bits.flow_size/7.0f,(float)d.bits.flow_size/7.0f);
} }
else if(shape==df::tiletype_shape::EMPTY || shape==df::tiletype_shape::RAMP_TOP else if(shape==df::tiletype_shape::EMPTY || shape==df::tiletype_shape::RAMP_TOP
|| shape==df::tiletype_shape::STAIR_DOWN || shape==df::tiletype_shape::STAIR_UPDOWN) || shape==df::tiletype_shape::STAIR_DOWN || shape==df::tiletype_shape::STAIR_UPDOWN)
@ -728,7 +733,8 @@ void lightingEngineViewscreen::doOcupancyAndLights()
for(int i=0;i<block->plants.size();i++) for(int i=0;i<block->plants.size();i++)
{ {
df::plant* cPlant=block->plants[i]; df::plant* cPlant=block->plants[i];
if (cPlant->grow_counter <180000) //todo maybe smaller light/oclusion?
continue;
df::coord2d pos=cPlant->pos; df::coord2d pos=cPlant->pos;
pos=worldToViewportCoord(pos,vp,window2d); pos=worldToViewportCoord(pos,vp,window2d);
int tile=getIndex(pos.x,pos.y); int tile=getIndex(pos.x,pos.y);
@ -823,24 +829,24 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(!mat)mat=&matWall; if(!mat)mat=&matWall;
if(def->light.isEmiting) if(def->light.isEmiting)
{ {
addLight(tile,def->light.makeSource()); addLight(tile,def->light.makeSource(def->size));
} }
else if(mat->isEmiting) else if(mat->isEmiting)
{ {
addLight(tile,mat->makeSource()); addLight(tile,mat->makeSource(def->size));
} }
if(def->light.isTransparent) if(def->light.isTransparent)
{ {
ocupancy[tile]*=def->light.transparency; addOclusion(tile,def->light.transparency,def->size);
} }
else else
{ {
ocupancy[tile]*=mat->transparency; addOclusion(tile,mat->transparency,def->size);
} }
} }
else else
{ {
applyMaterial(tile,def->light); applyMaterial(tile,def->light,def->size,def->thickness);
} }
} }
} }
@ -901,9 +907,6 @@ matLightDef lua_parseMatDef(lua_State* L)
else else
lua_pop(L,1); lua_pop(L,1);
GETLUAFLAG(ret.flicker,"flicker"); GETLUAFLAG(ret.flicker,"flicker");
GETLUAFLAG(ret.useThickness,"useThickness");
GETLUAFLAG(ret.sizeModifiesPower,"sizeModifiesPower");
GETLUAFLAG(ret.sizeModifiesRange,"sizeModifiesRange");
return ret; return ret;
} }
int lightingEngineViewscreen::parseMaterials(lua_State* L) int lightingEngineViewscreen::parseMaterials(lua_State* L)
@ -992,6 +995,15 @@ int lightingEngineViewscreen::parseBuildings(lua_State* L)
engine->buildingDefs[std::make_tuple(type,subtype,custom)]=current; engine->buildingDefs[std::make_tuple(type,subtype,custom)]=current;
GETLUAFLAG(current.poweredOnly,"poweredOnly"); GETLUAFLAG(current.poweredOnly,"poweredOnly");
GETLUAFLAG(current.useMaterial,"useMaterial"); GETLUAFLAG(current.useMaterial,"useMaterial");
lua_getfield(L,-1,"size");
current.size=luaL_optnumber(L,-1,1);
lua_pop(L,1);
lua_getfield(L,-1,"thickness");
current.thickness=luaL_optnumber(L,-1,1);
lua_pop(L,1);
lua_pop(L, 1); lua_pop(L, 1);
} }

@ -103,9 +103,6 @@ struct matLightDef
bool isTransparent; bool isTransparent;
lightCell transparency; lightCell transparency;
bool isEmiting; bool isEmiting;
bool useThickness;
bool sizeModifiesPower;
bool sizeModifiesRange;
bool flicker; bool flicker;
lightCell emitColor; lightCell emitColor;
int radius; int radius;
@ -117,7 +114,10 @@ struct matLightDef
lightSource makeSource(float size=1) const lightSource makeSource(float size=1) const
{ {
//TODO implement sizeModifiesPower/range //TODO implement sizeModifiesPower/range
return lightSource(emitColor,radius); if(size>0.999 && size<1.001)
return lightSource(emitColor,radius);
else
return lightSource(emitColor*size,radius*size);//todo check if this is sane
} }
}; };
struct buildingLightDef struct buildingLightDef
@ -125,6 +125,8 @@ struct buildingLightDef
matLightDef light; matLightDef light;
bool poweredOnly; bool poweredOnly;
bool useMaterial; bool useMaterial;
float thickness;
float size;
}; };
class lightingEngineViewscreen:public lightingEngine class lightingEngineViewscreen:public lightingEngine
{ {
@ -151,6 +153,7 @@ private:
void doLight(std::vector<lightCell> & target, int index); void doLight(std::vector<lightCell> & target, int index);
bool lightUpCell(std::vector<lightCell> & target, lightCell& power,int dx,int dy,int tx,int ty); bool lightUpCell(std::vector<lightCell> & target, lightCell& power,int dx,int dy,int tx,int ty);
bool addLight(int tileId,const lightSource& light); bool addLight(int tileId,const lightSource& light);
void addOclusion(int tileId,const lightCell& c,float thickness);
matLightDef* getMaterial(int matType,int matIndex); matLightDef* getMaterial(int matType,int matIndex);
buildingLightDef* getBuilding(df::building* bld); buildingLightDef* getBuilding(df::building* bld);
@ -158,7 +161,7 @@ private:
//apply material to cell //apply material to cell
void applyMaterial(int tileId,const matLightDef& mat,float size=1, float thickness = 1); void applyMaterial(int tileId,const matLightDef& mat,float size=1, float thickness = 1);
//try to find and apply material, if failed return false, and if def!=null then apply def. //try to find and apply material, if failed return false, and if def!=null then apply def.
bool applyMaterial(int tileId,int matType,int matIndex,float size=1,const matLightDef* def=NULL); bool applyMaterial(int tileId,int matType,int matIndex,float size=1,float thickness = 1,const matLightDef* def=NULL);
size_t inline getIndex(int x,int y) size_t inline getIndex(int x,int y)
{ {

@ -10,9 +10,6 @@ end
-- add material by id (index,mat pair or token string or a type number), flags is a table of strings -- add material by id (index,mat pair or token string or a type number), flags is a table of strings
-- supported flags (but not implemented): -- supported flags (but not implemented):
-- flicker -- flicker
-- useThickness -- use thickness of stuff in transparency calculation
-- sizeModifiesPower
-- sizeModifiesRange
function addMaterial(id,transparency,emitance,radius,flags) function addMaterial(id,transparency,emitance,radius,flags)
local matinfo local matinfo
if type(id)=="string" then if type(id)=="string" then
@ -66,9 +63,13 @@ end
-- supported flags: -- supported flags:
-- useMaterial --uses material, but the defined things overwrite -- useMaterial --uses material, but the defined things overwrite
-- poweredOnly --glow only when powered -- poweredOnly --glow only when powered
function addBuilding(id,transparency,emitance,radius,flags) function addBuilding(id,transparency,emitance,radius,flags,size,thickness)
size=size or 1
thickness=thickness or 1
local bld=buildingLookUp(id) local bld=buildingLookUp(id)
local mat=makeMaterialDef(transparency,emitance,radius,flags) local mat=makeMaterialDef(transparency,emitance,radius,flags)
mat.size=size
mat.thickness=thickness
buildings[bld.type]=buildings[bld.type] or {} buildings[bld.type]=buildings[bld.type] or {}
if bld.subtype then if bld.subtype then
if bld.custom then if bld.custom then