]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Volume Mixer
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 4 Feb 2016 14:24:25 +0000 (09:24 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 4 Feb 2016 14:24:25 +0000 (09:24 -0500)
include/common.h
include/ui.h
main.cpp
src/config.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
xml/playerSpawnHill1.xml

index ea3b593f99386b25774516e4a422d32683136b96..0a8ba203f0275ff67065c9240a55d219147df69e 100644 (file)
@@ -126,6 +126,7 @@ extern unsigned int HLINE;
 
 extern float VOLUME_MASTER;
 extern float VOLUME_MUSIC;
+extern float VOLUME_SFX;
 /**
  * A 'wrapper' for libc's srand(), as we hope to eventually have our own random number
  * generator.
index 8582460ade15f017ce0d2f75488b857da1e8b4c6..38a49328db2ee80169718ad5b34ff153fc8defb2 100644 (file)
@@ -12,7 +12,7 @@
 #include <world.h>
 #include <ft2build.h>
 #include <SDL2/SDL_opengl.h>
-#include <fstream>
+#include <thread>
 #include FT_FREETYPE_H
 
 #define DEBUG
index a85cd4d1827b51472526387c242ea5fdb55967ff..c523c65737b06b5ce36e3e15c5de43c11d444dd3 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -189,7 +189,8 @@ unsigned int SCREEN_HEIGHT = 720;
 bool            FULLSCREEN    = false;
 
 float           VOLUME_MASTER = 50;
-float           VOLUME_MUSIC =  25;
+float           VOLUME_MUSIC  = 25;
+float           VOLUME_SFX    = 25;
 
 /*******************************************************************************
  * MAIN ************************************************************************
index 3ef1a3e7942146b14aabd97049a63350e7c0c972..8ec361de987b62415576e08312846e71441fca0b 100644 (file)
@@ -9,6 +9,7 @@ extern bool                     FULLSCREEN;
 
 extern float            VOLUME_MASTER;
 extern float            VOLUME_MUSIC;
+extern float            VOLUME_SFX;
 
 XMLDocument xml;
 XMLElement *scr;
@@ -41,17 +42,19 @@ void readConfig(){
 
        vol = xml.FirstChildElement("volume");
        VOLUME_MASTER = vol->FirstChildElement("master")->FloatAttribute("volume");
-       VOLUME_MUSIC = vol->FirstChildElement("music")->FloatAttribute("volume");
+       VOLUME_MUSIC  = vol->FirstChildElement("music")->FloatAttribute("volume");
+       VOLUME_SFX    = vol->FirstChildElement("sfx")->FloatAttribute("volume");
 
 }
 
 void updateConfig(){
        vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER);
        vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC);
+       vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX);
 
        Mix_Volume(0,VOLUME_MASTER);
+       Mix_Volume(1,VOLUME_SFX);
        Mix_VolumeMusic(VOLUME_MUSIC);
-
 }
 
 void saveConfig(){
index b36ea3d8577246b9ef0eafe35e8f07523b59cb20..5a9c42a5721ef879d26512a7ddf4bd31e4411eb1 100644 (file)
@@ -19,7 +19,7 @@ std::string sTexLoc[] = {     "assets/townhall.png",
                                                        "assets/house1.png", 
                                                        "assets/fountain1.png",
                                                        "assets/lampPost1.png",
-                                                       "assets/brazier.png"};
+                                                       "assets/brazzier.png"};
 
 GLuint waterTex;
 
index 8a24056e0c5a9ebc5e48272bb9e253839ea42a76..1103cfafccd9215a2d19d1e8075f360d276b8f56 100644 (file)
@@ -246,7 +246,9 @@ void initEverything(void){
        pauseMenu.parent = NULL;
 
 
-       optionsMenu.items.push_back(ui::createSlider({-512/2,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Shit", &VOLUME_MASTER));
+       optionsMenu.items.push_back(ui::createSlider({0-(float)SCREEN_WIDTH/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &VOLUME_MASTER));
+       optionsMenu.items.push_back(ui::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &VOLUME_MUSIC));
+       optionsMenu.items.push_back(ui::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &VOLUME_SFX));
        optionsMenu.child = NULL;
        optionsMenu.parent = &pauseMenu;
        // optionsMenu.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), );
index 47ad4350c5355aa34486ca4999b3c64b1d37350c..937367c522dd744920cebcc047fdf1704622e6d1 100644 (file)
@@ -88,7 +88,7 @@ void Menu::gotoParent(){
 
 void Menu::gotoChild(){
        if(child == NULL){
-               currentMenu = this;
+               currentMenu = NULL;
        }else{
                currentMenu = child;
        }
@@ -810,12 +810,21 @@ namespace ui {
                                char outSV[32];
                                sprintf(outSV, "%s: %.1f",m.slider.text, *m.slider.var);
 
-                               //width of the slider handle
-                               float sliderW = m.slider.dim.x * .05;
-
-                               //location of the slider handle
-                               m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
-
+                               float sliderW, sliderH;
+
+                               if(m.slider.dim.y > m.slider.dim.x){
+                                       //width of the slider handle
+                                       sliderW = m.slider.dim.x;
+                                       sliderH = m.slider.dim.y * .05;
+                                       //location of the slider handle
+                                       m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.y-sliderW);
+                               }else{
+                                       //width of the slider handle
+                                       sliderW = m.slider.dim.x * .05;
+                                       sliderH = m.slider.dim.y;
+                                       //location of the slider handle
+                                       m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
+                               }
                                //draw the background of the slider
                                glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, .5f);
                                glRectf(offset.x+m.slider.loc.x, 
@@ -825,14 +834,23 @@ namespace ui {
 
                                //draw the slider handle
                                glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, 1.0f);
-                               glRectf(offset.x+m.slider.loc.x+m.slider.sliderLoc,
-                                               offset.y+m.slider.loc.y,
-                                               offset.x+m.slider.loc.x + m.slider.sliderLoc + (m.slider.dim.x*.05),
-                                               offset.y+m.slider.loc.y + m.slider.dim.y);
-
-                               //draw the now combined slider text
-                               putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y/2)) - ui::fontSize/2, outSV);
-                               
+                               if(m.slider.dim.y > m.slider.dim.x){
+                                       glRectf(offset.x+m.slider.loc.x,
+                                               offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05),
+                                               offset.x+m.slider.loc.x + sliderW,
+                                               offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
+
+                                       //draw the now combined slider text
+                                       putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y*1.05)) - ui::fontSize/2, outSV);
+                               }else{
+                                       glRectf(offset.x+m.slider.loc.x+m.slider.sliderLoc,
+                                                       offset.y+m.slider.loc.y,
+                                                       offset.x+m.slider.loc.x + m.slider.sliderLoc + sliderW,
+                                                       offset.y+m.slider.loc.y + sliderH);
+
+                                       //draw the now combined slider text
+                                       putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y/2)) - ui::fontSize/2, outSV);
+                               }                               
                                //test if mouse is inside of the slider's borders
                                if(mouse.x >= offset.x+m.slider.loc.x && mouse.x <= offset.x+m.slider.loc.x + m.slider.dim.x){
                                        if(mouse.y >= offset.y+m.slider.loc.y && mouse.y <= offset.y+m.slider.loc.y + m.slider.dim.y){
@@ -846,26 +864,45 @@ namespace ui {
                                                        glVertex2f(offset.x+m.slider.loc.x,                                     offset.y+m.slider.loc.y+m.slider.dim.y);
                                                        glVertex2f(offset.x+m.slider.loc.x,                                     offset.y+m.slider.loc.y);
 
-                                                       //and a border around the slider handle
-                                                       glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
-                                                       glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y);
-                                                       glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y);
-                                                       glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y);
-                                                       glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
+                                                       if(m.slider.dim.y > m.slider.dim.x){
+                                                               //and a border around the slider handle
+                                                               glVertex2f(offset.x+m.slider.loc.x,               offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
+                                                               glVertex2f(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
+                                                               glVertex2f(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
+                                                               glVertex2f(offset.x+m.slider.loc.x,           offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
+                                                               glVertex2f(offset.x+m.slider.loc.x,           offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05));
+                                                       }else{
+                                                               //and a border around the slider handle
+                                                               glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
+                                                               glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y);
+                                                               glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y);
+                                                               glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y);
+                                                               glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
+                                                       }
 
                                                glEnd();
 
                                                //if we are inside the slider and click it will set the slider to that point
                                                if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
                                                        //change handle location
-                                                       *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
-
-                                                       //draw a white box over the handle
-                                                       glColor3f(1.0f,1.0f,1.0f);
-                                                       glRectf(offset.x+m.slider.loc.x + m.slider.sliderLoc, 
-                                                                       offset.y+m.slider.loc.y, 
-                                                                       offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), 
-                                                                       offset.y+m.slider.loc.y + m.slider.dim.y);
+                                                       if(m.slider.dim.y > m.slider.dim.x){
+                                                               *m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100;
+                                                               //draw a white box over the handle
+                                                               glColor3f(1.0f,1.0f,1.0f);
+                                                               glRectf(offset.x+m.slider.loc.x, 
+                                                                               offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05), 
+                                                                               offset.x+m.slider.loc.x + sliderW, 
+                                                                               offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH);
+
+                                                       }else{
+                                                               *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
+                                                               //draw a white box over the handle
+                                                               glColor3f(1.0f,1.0f,1.0f);
+                                                               glRectf(offset.x+m.slider.loc.x + m.slider.sliderLoc, 
+                                                                               offset.y+m.slider.loc.y, 
+                                                                               offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), 
+                                                                               offset.y+m.slider.loc.y + m.slider.dim.y);
+                                                       }
                                                }
 
                                                //makes sure handle can't go below or above min and max values
@@ -899,8 +936,8 @@ namespace ui {
                name += ".bmp";
                FILE* bmp = fopen(name.c_str(), "w+");
 
-               unsigned long header_size = sizeof(BITMAPFILEHEADER) +
-                                                                       sizeof(BITMAPINFOHEADER);
+               // unsigned long header_size = sizeof(BITMAPFILEHEADER) +
+               //                                                      sizeof(BITMAPINFOHEADER);
 
                BITMAPFILEHEADER bmfh;
                BITMAPINFOHEADER bmih;
@@ -911,7 +948,8 @@ namespace ui {
                bmfh.bfType = 0x4d42;
 
                bmfh.bfOffBits = 54;
-               bmfh.bfSize = header_size;
+               bmfh.bfSize = sizeof(BITMAPFILEHEADER) +
+                                         sizeof(BITMAPINFOHEADER);
                bmfh.bfReserved1 = 0;
                bmfh.bfReserved2 = 0;
 
@@ -937,6 +975,9 @@ namespace ui {
                fwrite(&bmih, 1,sizeof(BITMAPINFOHEADER),bmp);
                fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
 
+               delete[] pixels;
+
+               fclose(bmp);
        }
 
        void dialogAdvance(void){
@@ -1191,10 +1232,15 @@ DONE:
                                        break;
                                case SDLK_F12:
                                        // Make the BYTE array, factor of 3 because it's RBG.
-                                       static GLubyte* pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
+                                       static GLubyte* pixels;
+                                       pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
                                        glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
 
-                                       takeScreenshot(pixels);
+                                       static std::thread scr;
+                                       scr = std::thread(takeScreenshot,pixels);
+                                       scr.detach();
+                                       //takeScreenshot(pixels);
+
                                        std::cout << "Took screenshot" << std::endl;
                                        break;
                                default:
index 129ff4644e3cd191594673cd5ca96fa6262665fe..53e6a3cfc58fc338d80d7fb7fa3fd33e8349d3de 100644 (file)
@@ -5,7 +5,7 @@
        
        <link right="playerSpawnHill2.xml" />
        
-       <mob type="1" aggressive="true" />
+       <mob type="1" aggressive="false" />
        
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="true" />