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

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

@ -402,6 +402,13 @@ bool lightingEngineViewscreen::addLight(int tileId,const lightSource& light)
lights[tileId].flicker=true;
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)
{
return lightCell(df::global::enabler->ccolor[colorId][0]/255.0f,
@ -446,32 +453,30 @@ void lightingEngineViewscreen::applyMaterial(int tileId,const matLightDef& mat,f
{
if(mat.isTransparent)
{
if(thickness > 0.999 && thickness < 1.001)
ocupancy[tileId]*=mat.transparency;
else
ocupancy[tileId]*=(mat.transparency.power(thickness));
addOclusion(tileId,mat.transparency,thickness);
}
else
ocupancy[tileId]=lightCell(0,0,0);
if(mat.isEmiting)
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);
if(m)
{
applyMaterial(tileId,*m,size);
applyMaterial(tileId,*m,size,thickness);
return true;
}
else if(def)
{
applyMaterial(tileId,*def,size);
applyMaterial(tileId,*def,size,thickness);
}
return false;
}
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);
lightCell ret=in;
coord2d innerCoord(x,y);
@ -647,7 +652,7 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(d.bits.hidden)
{
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::tiletype_shape shape = ENUM_ATTR(tiletype,shape,type);
@ -672,11 +677,11 @@ void lightingEngineViewscreen::doOcupancyAndLights()
}
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)
{
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
|| shape==df::tiletype_shape::STAIR_DOWN || shape==df::tiletype_shape::STAIR_UPDOWN)
@ -730,7 +735,8 @@ void lightingEngineViewscreen::doOcupancyAndLights()
for(int i=0;i<block->plants.size();i++)
{
df::plant* cPlant=block->plants[i];
if (cPlant->grow_counter <180000) //todo maybe smaller light/oclusion?
continue;
df::coord2d pos=cPlant->pos;
pos=worldToViewportCoord(pos,vp,window2d);
int tile=getIndex(pos.x,pos.y);
@ -825,24 +831,24 @@ void lightingEngineViewscreen::doOcupancyAndLights()
if(!mat)mat=&matWall;
if(def->light.isEmiting)
{
addLight(tile,def->light.makeSource());
addLight(tile,def->light.makeSource(def->size));
}
else if(mat->isEmiting)
{
addLight(tile,mat->makeSource());
addLight(tile,mat->makeSource(def->size));
}
if(def->light.isTransparent)
{
ocupancy[tile]*=def->light.transparency;
addOclusion(tile,def->light.transparency,def->size);
}
else
{
ocupancy[tile]*=mat->transparency;
addOclusion(tile,mat->transparency,def->size);
}
}
else
{
applyMaterial(tile,def->light);
applyMaterial(tile,def->light,def->size,def->thickness);
}
}
}
@ -903,9 +909,6 @@ matLightDef lua_parseMatDef(lua_State* L)
else
lua_pop(L,1);
GETLUAFLAG(ret.flicker,"flicker");
GETLUAFLAG(ret.useThickness,"useThickness");
GETLUAFLAG(ret.sizeModifiesPower,"sizeModifiesPower");
GETLUAFLAG(ret.sizeModifiesRange,"sizeModifiesRange");
return ret;
}
int lightingEngineViewscreen::parseMaterials(lua_State* L)
@ -994,6 +997,15 @@ int lightingEngineViewscreen::parseBuildings(lua_State* L)
engine->buildingDefs[std::make_tuple(type,subtype,custom)]=current;
GETLUAFLAG(current.poweredOnly,"poweredOnly");
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);
}

@ -103,9 +103,6 @@ struct matLightDef
bool isTransparent;
lightCell transparency;
bool isEmiting;
bool useThickness;
bool sizeModifiesPower;
bool sizeModifiesRange;
bool flicker;
lightCell emitColor;
int radius;
@ -117,7 +114,10 @@ struct matLightDef
lightSource makeSource(float size=1) const
{
//TODO implement sizeModifiesPower/range
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
@ -125,6 +125,8 @@ struct buildingLightDef
matLightDef light;
bool poweredOnly;
bool useMaterial;
float thickness;
float size;
};
class lightingEngineViewscreen:public lightingEngine
{
@ -151,6 +153,7 @@ private:
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 addLight(int tileId,const lightSource& light);
void addOclusion(int tileId,const lightCell& c,float thickness);
matLightDef* getMaterial(int matType,int matIndex);
buildingLightDef* getBuilding(df::building* bld);
@ -158,7 +161,7 @@ private:
//apply material to cell
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.
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)
{

@ -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
-- supported flags (but not implemented):
-- flicker
-- useThickness -- use thickness of stuff in transparency calculation
-- sizeModifiesPower
-- sizeModifiesRange
function addMaterial(id,transparency,emitance,radius,flags)
local matinfo
if type(id)=="string" then
@ -66,9 +63,13 @@ end
-- supported flags:
-- useMaterial --uses material, but the defined things overwrite
-- 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 mat=makeMaterialDef(transparency,emitance,radius,flags)
mat.size=size
mat.thickness=thickness
buildings[bld.type]=buildings[bld.type] or {}
if bld.subtype then
if bld.custom then