From e08983ddccf0beee79e63bdf3ef1b839ea947c7a Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Tue, 12 Jan 2016 07:37:19 -0500 Subject: [PATCH] Light posts --- assets/lampPost1.png | Bin 0 -> 309 bytes assets/townhall.png | Bin 0 -> 802 bytes include/entities.h | 15 +++--- include/world.h | 4 +- src/entities.cpp | 102 +++++++++++++++++++++++++-------------- src/ui.cpp | 3 ++ src/world.cpp | 8 +-- test.frag | 22 +++++++-- xml/playerSpawnHill1.xml | 1 + 9 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 assets/lampPost1.png create mode 100644 assets/townhall.png diff --git a/assets/lampPost1.png b/assets/lampPost1.png new file mode 100644 index 0000000000000000000000000000000000000000..24f180712229c46a000061def2ccaf031d5b08de GIT binary patch literal 309 zcmeAS@N?(olHy`uVBq!ia0vp^azI?c!3HFs&UJbUq&N#aB8wRqxP?KOkzv*x383I} zPZ!6KjC*fyDe@f(;5qiO&qv8Xrg4El%kMV@yZId#aJU~(_`uJcCb_uQX4AfB_gPFY z$;aRNsHWx=DB|k6?#r)~t4ZtP@205z-5D<0Il1FR(SEtTKP>M0*v6{Q^O-gKPW_`x zd(*w|WbOYk@8ib!-Z=Y`?+<%k-+r~kbCt)vD^q_I-AggO_imk?F!S;D=(n|*d;1^H zIo|d^>)d0n^T~&e!zVm{6=eJO{Eypfwr+k}!o-FflyQCzJ93=sa~Ml>Y|`w|w)<WXNX4zUcTeXXRuFKwnDFy|{meWm&8|t?{ANBZeYdLn2-~wNwt}~J@_)+$vn!bIXrzgk%{HOm`%Bt*nmQgHk&Fc4MGTn--+Qz4^ zIJF#KBcOQg?~kq5`p=iDF76Y$Y&1JSw^?2{boHbkjR|)jSDjM`Nm28Bf2aJJ*3y`F z*Z+R*kKB+RpLQz3H2K`*nJbOX{atoPEXme$s$$6clT{_saVhKd4DH%hH+vp@x0UHl z!M$CZBTTh}uSB)q3iFsHfA#K>Rg$U&%h%YPl8~Fb)Jt-LV7TwZzjZdx4&PsSZ0>4r z(??hTtaEYyvh})a>9;9b$`_Q=SNkQ;H&SrdUuhQ6+iUfFm3EiulT$q}io2)UP1-!= z;BVb|YcA`~+*lQ}a#M2M|9D2;SfcZ71zx{usXaC| zy`l5S2m3cH=6vuXJot|zh`nLFin$b)iM?KbaBJo+wr$c5Is)8Bm^xUK8Y37sf;b9dKn~*(CLpIF zVu#1G|Nn)vgO7KxE)_tL0dpjoK$mdKI;Vst0Hm>FApigX literal 0 HcmV?d00001 diff --git a/include/entities.h b/include/entities.h index f26863e..d7ad2c0 100644 --- a/include/entities.h +++ b/include/entities.h @@ -37,12 +37,13 @@ enum MOB_SUB { }; enum BUILD_SUB{ - TOWN_HALL = 1, - HOUSE, - HOUSE2, - HOUSE3, - HOUSE4, - FOUNTAIN + TOWN_HALL = 0, + HOUSE = 1, + HOUSE2 = 2, + HOUSE3 = 3, + HOUSE4 = 4, + FOUNTAIN = 5, + LAMP_POST = 6 }; typedef struct { @@ -211,7 +212,7 @@ public: Structures(); ~Structures(); - unsigned int spawn(_TYPE, BUILD_SUB, float, float, World *); + unsigned int spawn(BUILD_SUB, float, float, World *); char *save(void); void load(char *s); diff --git a/include/world.h b/include/world.h index 0e85462..7eb8c02 100644 --- a/include/world.h +++ b/include/world.h @@ -176,8 +176,8 @@ public: std::vector particles; std::vector light; - void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside); - void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside); + void addStructure(BUILD_SUB sub,float x,float y,World *inside); + void addVillage(int bCount, int npcMin, int npcMax,World *inside); void addMob(int t,float x,float y); void addMob(int t,float x,float y,void (*hey)(Mob *)); void addNPC(float x,float y); diff --git a/src/entities.cpp b/src/entities.cpp index 57a20ef..627946b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -13,6 +13,14 @@ extern Player *player; extern const char *itemName; +std::string sTexLoc[] = { "assets/townhall.png", + "assets/house1.png", + "assets/house2.png", + "assets/house1.png", + "assets/house1.png", + "assets/fountain1.png", + "assets/lampPost1.png"}; + void getRandomName(Entity *e){ unsigned int tempNum,max=0; char *bufs; @@ -119,9 +127,6 @@ Structures::Structures(){ //sets the structure type alive = false; near = false; - tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png"); - ntex = new Texturec(1, "assets/house1N.png"); - inWorld = NULL; name = NULL; @@ -282,7 +287,7 @@ void Entity::draw(void){ //draws the entities case MS_DOOR: case MS_PAGE: default: - glActiveTexture(GL_TEXTURE0 + 0); + glActiveTexture(GL_TEXTURE0); tex->bind(0); break; } @@ -290,27 +295,25 @@ void Entity::draw(void){ //draws the entities case STRUCTURET: for(auto &strt : currentWorld->build){ if(this == strt){ - if(strt->bsubtype == HOUSE){ - glActiveTexture(GL_TEXTURE1); - ntex->bind(0); - //When rendering an objectwith this program. - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(0); - //glBindSampler(0, linearFiltering); - - - }else if(strt->bsubtype == HOUSE2){ - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(1); - }else if(strt->bsubtype == FOUNTAIN){ - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(2); + switch(strt->bsubtype){ + /*case HOUSE: + glActiveTexture(GL_TEXTURE1); + ntex->bind(0); + //When rendering an objectwith this program. + glActiveTexture(GL_TEXTURE0); + tex->bind(0); + //glBindSampler(0, linearFiltering); + break;*/ + default: + glActiveTexture(GL_TEXTURE0); + tex->bind(0); + break; } } } break; default: - glActiveTexture(GL_TEXTURE0 + 0); + glActiveTexture(GL_TEXTURE0); tex->bind(0); break; } @@ -442,16 +445,16 @@ void Object::interact(void){ * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World *oi){ +unsigned int Structures::spawn(BUILD_SUB sub, float x, float y, World *oi){ loc.x = x; loc.y = y; - type = t; - + type = STRUCTURET; + alive = true; - width = 50 * HLINE; - height = 40 * HLINE; bsubtype = sub; + int s = -1; + s = sub; inWorld = oi; @@ -459,20 +462,45 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World * * tempN is the amount of entities that will be spawned in the village. Currently the village * will spawn bewteen 2 and 7 villagers for the starting hut. */ - + /* tex = new Texturec(7,"assets/townhall.png", + "assets/house1.png", + "assets/house2.png", + "assets/house1.png", + "assets/house1.png", + "assets/fountain1.png", + "assets/lampPost1.png")*/; + unsigned int tempN = (getRand() % 5 + 2); - - for(unsigned int i = 0;i < tempN;i++){ - - /* - * This is where the entities actually spawn. A new entity is created - * with type NPC. - */ - - inWorld->addNPC(loc.x + i * HLINE ,100); - + switch(s){ + case HOUSE: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 50 * HLINE; + height = 40 * HLINE; + for(unsigned int i = 0;i < tempN;i++){ + + /* + * This is where the entities actually spawn. A new entity is created + * with type NPC. + */ + + oi->addNPC(loc.x + i * HLINE ,100); + + } + break; + case FOUNTAIN: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 50 * HLINE; + height = 40 * HLINE; + break; + case LAMP_POST: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 10 * HLINE; + height = 40 * HLINE; + oi->addLight({x+SCREEN_WIDTH/2,y+30*HLINE},{1.0f,1.0f,1.0f}); + break; + default: + break; } - return 0; } diff --git a/src/ui.cpp b/src/ui.cpp index 64ebe92..0d01033 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -822,6 +822,9 @@ DONE: case SDLK_f: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); break; + case SDLK_g: + currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld); + break; default: break; } diff --git a/src/world.cpp b/src/world.cpp index e66fb0d..b06802c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1055,9 +1055,9 @@ LOOOOP: goto LOOOOP; } } -void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ +void World::addStructure(BUILD_SUB sub, float x,float y,World *inside){ build.push_back(new Structures()); - build.back()->spawn(t,sub,x,y,this); + build.back()->spawn(sub,x,y,this); build.back()->inWorld=this; build.back()->inside = (World *)inside; ((IndoorWorld *)inside)->outside = this; @@ -1065,11 +1065,11 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ entity.push_back(build.back()); } -void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){ +void World::addVillage(int bCount, int npcMin, int npcMax,World *inside){ std::cout << npcMin << ", " << npcMax << std::endl; //int xwasd; for(int i = 0; i < bCount; i++){ - addStructure(t,HOUSE,x_start + (i * 300),100,inside); + addStructure(HOUSE,x_start + (i * 300),100,inside); /*std::cout<<"1\n"; HERE: xwasd = (rand()%(int)x+1000*HLINE); diff --git a/test.frag b/test.frag index 083fc0b..80c741b 100644 --- a/test.frag +++ b/test.frag @@ -1,17 +1,22 @@ -#version 130 +#version 120 uniform sampler2D sampler; uniform int numLight; -uniform vec2 lightLocation[255]; +uniform vec2 lightLocation[1024]; uniform vec3 lightColor; uniform float amb; +float b = .0005; +float minLight = .05; +float radius = sqrt(1.0 / (b * minLight)); + void main(){ vec4 color = vec4(0.0f,0.0f,0.0f,0.0f); for(int i = 0; i < numLight; i++){ vec2 loc = lightLocation[i]; float dist = length(loc - gl_FragCoord.xy); - float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist); + //float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist); + float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation; color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f); } @@ -20,4 +25,13 @@ void main(){ color += vec4(amb,amb,amb,1.0f+amb); gl_FragColor = tex * vec4(color)*tex.a; -} \ No newline at end of file +} + +/*b values + .002 10 + .008 50 + .0005 200 + .00008 500 + .00002 1000 + .00005 2000 +*/ \ No newline at end of file diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 5a0e51f..60f7e7a 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -7,6 +7,7 @@ + -- 2.39.5