소스 검색

Merge branch 'developer' into feature/Controller

Kenneth van Ewijk 9 년 전
부모
커밋
4effce6fea
7개의 변경된 파일47개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 1
      Enemy.cpp
  2. 31 8
      HeightMap.cpp
  3. 1 2
      Portal.cpp
  4. 8 0
      SoundSystem.cpp
  5. 1 0
      SoundSystem.h
  6. 4 5
      World.cpp
  7. 1 1
      World.h

+ 1 - 1
Enemy.cpp

@@ -32,7 +32,7 @@ Enemy::~Enemy()
 	if (model)
 		Model::unload(model);
 
-	delete music;
+	CrystalPoint::GetSoundSystem().UnloadSound(hit_sound_id);
 }
 
 void Enemy::draw()

+ 31 - 8
HeightMap.cpp

@@ -29,28 +29,51 @@ HeightMap::HeightMap(const std::string &file, World* world)
 		return imgData[(x + y * width) * 4 + offset];
 	};
 
-	for (int y = 0; y < height-1; y++)
+	std::vector<std::vector<Vec3f>> faceNormals(width-1, std::vector<Vec3f>(height-1, Vec3f(0,1,0)));
+	for (int y = 0; y < height - 1; y++)
 	{
-		for (int x = 0; x < width-1; x++)
+		for (int x = 0; x < width - 1; x++)
 		{
 			int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
 			Vec3f ca(0, heightAt(x, y + 1) - heightAt(x, y), 1);
 			Vec3f ba(1, heightAt(x + 1, y) - heightAt(x, y), 0);
+			Vec3f normal = ca.cross(ba);
+			normal.Normalize();
+			faceNormals[x][y] = normal;
+		}
+	}
+
+	for (int y = 0; y < height-1; y++)
+	{
+		for (int x = 0; x < width-1; x++)
+		{
+			int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
 
 			if (valueAt(x, y, GREEN) > 0)
 			{
 				world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, 0, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
 			}
 
-			Vec3f normal = ca.cross(ba);
-			normal.Normalize();
-
 			for (int i = 0; i < 4; i++)
 			{
-				float h = heightAt(x + offsets[i][0], y + offsets[i][1]);
-				vertices.push_back(Vertex{ (float)(x + offsets[i][0]), h, (float)(y + offsets[i][1]),
+				int xx = x + offsets[i][0];
+				int yy = y + offsets[i][1];
+
+				Vec3f normal(0, 0, 0);
+				if(xx < width-1 && yy < height-1)
+					normal = normal + faceNormals[xx][yy];
+				if(xx > 0 && yy < height-1)
+					normal = normal + faceNormals[xx-1][yy];
+				if (xx > 0 && yy > 0)
+					normal = normal + faceNormals[xx-1][yy-1];
+				if (yy > 0 && xx < width-1)
+					normal = normal + faceNormals[xx][yy-1];
+				normal.Normalize();
+
+				float h = heightAt(xx, yy);
+				vertices.push_back(Vertex{ (float)(xx), h, (float)(yy),
 									normal.x, normal.y, normal.z,
-									(x + offsets[i][0]) / (float)height, (y + offsets[i][1]) / (float)width } );
+									(xx) / (float)height, (yy) / (float)width } );
 			}
 		}
 	}

+ 1 - 2
Portal.cpp

@@ -30,7 +30,7 @@ Portal::Portal(const std::string &fileName,
 Portal::~Portal()
 {
 //	Model::unload(model);
-//	delete music;
+	CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
 }
 
 void Portal::collide()
@@ -46,7 +46,6 @@ bool Portal::enter(float deltaTime)
 {
 	if (delay > 3 && started)
 	{
-		delete music;
 		delay = 0;
 		return true;
 	}

+ 8 - 0
SoundSystem.cpp

@@ -48,3 +48,11 @@ Sound* SoundSystem::GetSound(unsigned int inID)
 		return nullptr;
 	return sounds[inID];
 }
+
+void SoundSystem::UnloadSound(unsigned int inID)
+{
+	if (inID > sounds.size())
+		return;
+	delete sounds[inID];
+	//sounds.erase(sounds.begin() + inID);
+}

+ 1 - 0
SoundSystem.h

@@ -24,6 +24,7 @@ public:
 
 	unsigned int LoadSound(const char* inWavPath, bool inLooping);
 	Sound* GetSound(unsigned int inID);
+	void UnloadSound(unsigned int inID);
 
 private:
 	ALCdevice* device;

+ 4 - 5
World.cpp

@@ -8,8 +8,7 @@
 #include <algorithm>
 #include "WorldHandler.h"
 
-World::World(const std::string &fileName):
-	music_id(-1)
+World::World(const std::string &fileName)
 {
 	nextworld = false;
 
@@ -183,8 +182,8 @@ World::World(const std::string &fileName):
 
 	if (!v["world"]["music"].isNull())
 	{
-		music_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
-		music = CrystalPoint::GetSoundSystem().GetSound(music_id);
+		sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
+		music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
 	}
 
 	if (!v["portal"].isNull())
@@ -218,7 +217,7 @@ World::~World()
 {
 	delete heightmap;
 	music->Stop();
-	delete music;
+	CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
 	delete skybox;	
 	delete portal;
 }

+ 1 - 1
World.h

@@ -27,7 +27,7 @@ private:
 
 	bool nextworld;
 	
-	int music_id,maxCrystals,maxEnemies;
+	int sound_id,maxCrystals,maxEnemies;
 
 	std::vector<Entity*> entities;
 	std::vector<Enemy*> enemies;