Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
-fixed memory leak when resetting the rendering buffers

- set max value for Env Map Resolution to 1000

- added ambient sound to the river of the farm map
  • Loading branch information
Christian Koehlke committed Aug 20, 2020
1 parent 23af6e8 commit 12fd804
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 14 deletions.
24 changes: 21 additions & 3 deletions Game/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void AudioManager::init()
}


music = play2D("audio/breakout.mp3", true);
music = play2D("audio/breakout.mp3", AudioType::music, true);

AudioManager::setVolume();
}
Expand All @@ -41,15 +41,33 @@ irrklang::vec3df AudioManager::glmVec3toIrrklang(glm::vec3 vector)
return irrklang::vec3df(vector.x, vector.y, vector.z);
}

irrklang::ISound* AudioManager::play2D(std::string musicFile, bool playLooped)
irrklang::ISound* AudioManager::play2D(std::string musicFile, AudioType audiotype, bool playLooped)
{
irrklang::ISound* sound = SoundEngine->play2D(musicFile.c_str(), playLooped, false, true);
if (!sound)
{
Logger::log("Error playing sound: " + musicFile);
return nullptr;
}
sound->setVolume(ConfigManager::music_volume);

switch (audiotype)
{
case AudioType::soundeffect:
{
sound->setVolume(ConfigManager::effect_volume);
break;
}
case AudioType::ambient:
{
sound->setVolume(ConfigManager::ambient_volume);
break;
}
case AudioType::voice:
{
sound->setVolume(ConfigManager::voice_volume);
break;
}
}

return sound;
}
Expand Down
3 changes: 2 additions & 1 deletion Game/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum AudioType {
soundeffect,
voice,
ambient,
music,
};


Expand All @@ -24,7 +25,7 @@ static class AudioManager

static irrklang::vec3df glmVec3toIrrklang(glm::vec3 vector);

static irrklang::ISound* play2D(std::string musicFile, bool playLooped = false);
static irrklang::ISound* play2D(std::string musicFile, AudioType audiotype = AudioType::soundeffect, bool playLooped = false);

static irrklang::ISound* play3D(std::string musicFile, glm::vec3 position, AudioType audiotype= AudioType::soundeffect, bool playLooped = false);

Expand Down
2 changes: 2 additions & 0 deletions Game/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ glm::vec2 Map::mapSize = glm::vec2(110,110);

unsigned int Map::skyboxTexture;

std::vector<irrklang::ISound*> Map::ambientSounds;

void Map::load(std::string mapFileName)
{
if (mapFileName.find(mapFileFolder) == std::string::npos) {
Expand Down
4 changes: 4 additions & 0 deletions Game/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <memory>
#include <string>

#include <irrKlang.h>



class Map
Expand Down Expand Up @@ -61,5 +63,7 @@ class Map
static glm::vec2 mapSize;

static unsigned int skyboxTexture;

static std::vector<irrklang::ISound*> ambientSounds;
};

3 changes: 2 additions & 1 deletion Game/Menu_Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Menu_Options::Menu_Options()

sL_envres = new UI_Element_Slider(500, Game::getWindowHeight() - 120, 200, 50, 0, "Reflektions-Aufloesung");
sL_envres->setMinValue(100);
sL_envres->setMaxValue(4000);
sL_envres->setMaxValue(1000);
sL_envres->setValue(ConfigManager::env_map_resolution);
sL_envres->setCallback([&] { changeEnvMapResolution(); return 0; });
addMenuElement(sL_envres);
Expand Down Expand Up @@ -168,6 +168,7 @@ void Menu_Options::changeShadowMapResolution()
Logger::log("changed Shadow Map Resolution to: " + std::to_string(newResolution) + " px");
ConfigManager::shadow_map_resolution = newResolution;
Renderer::initFrameBuffer();
Renderer::resetFrameCount();
}

void Menu_Options::changeEnvMapResolution()
Expand Down
3 changes: 3 additions & 0 deletions Game/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ void Object::move()
void Object::setPosition(glm::vec3 newPosition)
{
position = newPosition;

center = position;
center.y += dimensions.y / 2;
}

glm::vec3 Object::getPosition()
Expand Down
12 changes: 11 additions & 1 deletion Game/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ class Object
return envCubeMapFrameBuffer;
}

void setEnvCubeMapDepthBuffer(unsigned int newEnvCubeMapDepthBuffer)
{
envCubeMapDepthBuffer = newEnvCubeMapDepthBuffer;
}

int getEnvCubeMapDepthBuffer()
{
return envCubeMapDepthBuffer;
}

void enable()
{
enabled = true;
Expand Down Expand Up @@ -325,7 +335,7 @@ class Object

std::chrono::system_clock::time_point lastHitTimestamp = std::chrono::system_clock::now() - std::chrono::hours(1);

int envCubeMap=-1, envCubeMapFrameBuffer=-1;
int envCubeMap=-1, envCubeMapFrameBuffer=-1, envCubeMapDepthBuffer = -1;

int networkID = -1;
};
Expand Down
14 changes: 11 additions & 3 deletions Game/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,18 @@ void Renderer::initFrameBuffer()
{
if (object->getType() & ObjectType::Object_Character) continue;

unsigned int textureid = object->getEnvCubeMap();
glDeleteTextures(1, &textureid);
unsigned int cubemap = object->getEnvCubeMap();
glDeleteTextures(1, &cubemap);
object->setEnvCubeMap(-1);

unsigned int framebufferid = object->getEnvCubeMapFrameBuffer();
glDeleteFramebuffers(1, &framebufferid);
object->setEnvCubeMapFrameBuffer(-1);

unsigned int depthbufferid = object->getEnvCubeMapDepthBuffer();
glDeleteRenderbuffers(1, &depthbufferid);
object->setEnvCubeMapDepthBuffer(-1);
}
//envMapBuffer.destroy();

//create them new
for (std::shared_ptr<Object> object : Game::objects)
Expand Down Expand Up @@ -323,6 +329,8 @@ void Renderer::initFrameBuffer()
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// attach it
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer);

object->setEnvCubeMapDepthBuffer(depthbuffer);
}

frameBuffer.create(Renderer::getResolutionX(), Renderer::getResolutionY(), FrameBufferTextureType::colorMap | FrameBufferTextureType::stencilMap);
Expand Down
35 changes: 33 additions & 2 deletions Game/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ void ResourceManager::loadMap(std::string mapFileName)
}




//Player(s)
float fov = std::stof(ConfigManager::readConfig("fov"));
std::shared_ptr<Player> player = std::make_shared<Player>(Renderer::getShader(ShaderType::basic), glm::radians(fov), 1920, 1080);
Expand Down Expand Up @@ -420,6 +418,39 @@ void ResourceManager::loadMap(std::string mapFileName)
id++;
}





//ambient sounds
tinyxml2::XMLElement* xmlNodesounds = mapNode->FirstChildElement("sounds");
if (xmlNodesounds != NULL)
{
for (tinyxml2::XMLElement* xmlNodesound = xmlNodesounds->FirstChildElement("sound"); xmlNodesound != NULL; xmlNodesound = xmlNodesound->NextSiblingElement())
{
xmlNode = xmlNodesound->FirstChildElement("soundfile");
if (xmlNode)
{
std::string soundfilename = "audio\\";
soundfilename += xmlNode->GetText();

xmlNode = xmlNodesound->FirstChildElement("position");
if (xmlNode)
{
glm::vec3 position = glm::vec3(Helper::string_to_glmVec3(xmlNode->GetText()));
irrklang::ISound* sound = AudioManager::play3D(soundfilename, position, AudioType::ambient, true);
}
else
{
irrklang::ISound* sound = AudioManager::play2D(soundfilename, AudioType::ambient, true);
}
}

}
}



Logger::log("Loading Map - finished");
}

Expand Down
11 changes: 10 additions & 1 deletion Game/ToDO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
- main menu background in options menu?
- jump-climb walls should not be possible

- player name input box in main menu

- multiplayer connecting feedback
- options save and then render env maps

- Netcode optimisation
- dont broadcast to the sender of the data

- ambient sounds
- ambient sounds

- push boxes

- Multiplayer
- dedicated Server ✓
- Client/Server
- chat
- name above players
- bots not moving (killed?)
- cant shoot sometimes

- 3D Raypicking ✓

Expand Down Expand Up @@ -42,6 +50,7 @@
- slider ✓
- textedit
- numedit
- 3D text (text to texture -> texture in 3D world)

- Menu mouse interaction ✓

Expand Down
1 change: 1 addition & 0 deletions Game/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void UI::updateRot(std::shared_ptr<Player> object)
void UI::drawString(float x, float y, std::string text, glm::vec4 color)
{
fontShader->bind();

GLCALL(glUniform4fv(fontColorUniformIndex, 1, (float*)&color));

font->drawString(x, y, text.c_str(), fontShader);
Expand Down
4 changes: 2 additions & 2 deletions Game/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ windowed_resolution_height = 540

[Renderer - Reflection]
;the resolution of the environment map (the reflection quality)
env_map_resolution = 512
env_map_resolution = 316

;how many frames the engine should wait, before rendering the environment map again
;regardless of this value the env map is rendered at startup of the game
Expand All @@ -75,7 +75,7 @@ env_map_render_characters = 0
shadow_option = 2

;the resolution of the shadow map (the shadow quality)
shadow_map_resolution = 4096
shadow_map_resolution = 5000


[Others]
Expand Down
10 changes: 10 additions & 0 deletions Game/levels/level_farm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
<volume>0.8</volume>
<soundfile>river.mp3</soundfile>
</sound>
<sound>
<position>-40;0;50</position>
<volume>0.8</volume>
<soundfile>river.mp3</soundfile>
</sound>
<sound>
<position>40;0;50</position>
<volume>0.8</volume>
<soundfile>river.mp3</soundfile>
</sound>
</sounds>
<models>
<model>character.bmf</model>
Expand Down

0 comments on commit 12fd804

Please sign in to comment.