瀏覽代碼

Merged LoadFont/GetFont

Sanjay Madhav 8 年之前
父節點
當前提交
11d5aa9348
共有 9 個文件被更改,包括 43 次插入58 次删除
  1. 2 2
      .gitignore
  2. 12 17
      Chapter11/Game.cpp
  3. 0 1
      Chapter11/Game.h
  4. 13 16
      Chapter12/Game.cpp
  5. 0 1
      Chapter12/Game.h
  6. 2 2
      Chapter12/Shaders/Skinned.vert
  7. 12 16
      Chapter13/Game.cpp
  8. 0 1
      Chapter13/Game.h
  9. 2 2
      Chapter13/Shaders/Skinned.vert

+ 2 - 2
.gitignore

@@ -8,6 +8,6 @@ Release/
 *.xccheckout
 *.stackdump
 .vs
-Chapter15/Assets/Saved.gplevel
-Chapter15/Assets/*.bin
+Chapter14/Assets/Saved.gplevel
+Chapter14/Assets/*.bin
 External/FMOD

+ 12 - 17
Chapter11/Game.cpp

@@ -292,7 +292,6 @@ void Game::GenerateOutput()
 
 void Game::LoadData()
 {
-	LoadFont("Assets/Carlito-Regular.ttf");
 	// Load English text
 	LoadText("Assets/English.gptext");
 
@@ -349,7 +348,6 @@ void Game::LoadData()
 	// UI elements
 	mHUD = new HUD(this);
 	
-
 	// Start music
 	mMusicEvent = mAudioSystem->PlayEvent("event:/Music");
 
@@ -455,20 +453,6 @@ void Game::PushUI(UIScreen* screen)
 	mUIStack.emplace_back(screen);
 }
 
-void Game::LoadFont(const std::string& fileName)
-{
-	Font* font = new Font(this);
-	if (font->Load(fileName))
-	{
-		mFonts.emplace(fileName, font);
-	}
-	else
-	{
-		font->Unload();
-		delete font;
-	}
-}
-
 Font* Game::GetFont(const std::string& fileName)
 {
 	auto iter = mFonts.find(fileName);
@@ -478,7 +462,18 @@ Font* Game::GetFont(const std::string& fileName)
 	}
 	else
 	{
-		return nullptr;
+		Font* font = new Font(this);
+		if (font->Load(fileName))
+		{
+			mFonts.emplace(fileName, font);
+		}
+		else
+		{
+			font->Unload();
+			delete font;
+			font = nullptr;
+		}
+		return font;
 	}
 }
 

+ 0 - 1
Chapter11/Game.h

@@ -46,7 +46,6 @@ public:
 	GameState GetState() const { return mGameState; }
 	void SetState(GameState state) { mGameState = state; }
 	
-	void LoadFont(const std::string& fileName);
 	class Font* GetFont(const std::string& fileName);
 
 	void LoadText(const std::string& fileName);

+ 13 - 16
Chapter12/Game.cpp

@@ -292,7 +292,6 @@ void Game::GenerateOutput()
 
 void Game::LoadData()
 {
-	LoadFont("Assets/Carlito-Regular.ttf");
 	// Load English text
 	LoadText("Assets/English.gptext");
 
@@ -474,20 +473,6 @@ void Game::PushUI(UIScreen* screen)
 	mUIStack.emplace_back(screen);
 }
 
-void Game::LoadFont(const std::string& fileName)
-{
-	Font* font = new Font(this);
-	if (font->Load(fileName))
-	{
-		mFonts.emplace(fileName, font);
-	}
-	else
-	{
-		font->Unload();
-		delete font;
-	}
-}
-
 Font* Game::GetFont(const std::string& fileName)
 {
 	auto iter = mFonts.find(fileName);
@@ -497,10 +482,22 @@ Font* Game::GetFont(const std::string& fileName)
 	}
 	else
 	{
-		return nullptr;
+		Font* font = new Font(this);
+		if (font->Load(fileName))
+		{
+			mFonts.emplace(fileName, font);
+		}
+		else
+		{
+			font->Unload();
+			delete font;
+			font = nullptr;
+		}
+		return font;
 	}
 }
 
+
 void Game::LoadText(const std::string& fileName)
 {
 	// Clear the existing map, if already loaded

+ 0 - 1
Chapter12/Game.h

@@ -46,7 +46,6 @@ public:
 	GameState GetState() const { return mGameState; }
 	void SetState(GameState state) { mGameState = state; }
 	
-	void LoadFont(const std::string& fileName);
 	class Font* GetFont(const std::string& fileName);
 
 	void LoadText(const std::string& fileName);

+ 2 - 2
Chapter12/Shaders/Skinned.vert

@@ -1,9 +1,9 @@
 // ----------------------------------------------------------------
 // From Game Programming in C++ by Sanjay Madhav
 // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
-//
+// 
 // Released under the BSD License
-// See LICENSE.txt for full details.
+// See LICENSE in root directory for full details.
 // ----------------------------------------------------------------
 
 // Request GLSL 3.3

+ 12 - 16
Chapter13/Game.cpp

@@ -293,7 +293,6 @@ void Game::GenerateOutput()
 
 void Game::LoadData()
 {
-	LoadFont("Assets/Carlito-Regular.ttf");
 	// Load English text
 	LoadText("Assets/English.gptext");
 
@@ -503,20 +502,6 @@ void Game::PushUI(UIScreen* screen)
 	mUIStack.emplace_back(screen);
 }
 
-void Game::LoadFont(const std::string& fileName)
-{
-	Font* font = new Font(this);
-	if (font->Load(fileName))
-	{
-		mFonts.emplace(fileName, font);
-	}
-	else
-	{
-		font->Unload();
-		delete font;
-	}
-}
-
 Font* Game::GetFont(const std::string& fileName)
 {
 	auto iter = mFonts.find(fileName);
@@ -526,7 +511,18 @@ Font* Game::GetFont(const std::string& fileName)
 	}
 	else
 	{
-		return nullptr;
+		Font* font = new Font(this);
+		if (font->Load(fileName))
+		{
+			mFonts.emplace(fileName, font);
+		}
+		else
+		{
+			font->Unload();
+			delete font;
+			font = nullptr;
+		}
+		return font;
 	}
 }
 

+ 0 - 1
Chapter13/Game.h

@@ -46,7 +46,6 @@ public:
 	GameState GetState() const { return mGameState; }
 	void SetState(GameState state) { mGameState = state; }
 	
-	void LoadFont(const std::string& fileName);
 	class Font* GetFont(const std::string& fileName);
 
 	void LoadText(const std::string& fileName);

+ 2 - 2
Chapter13/Shaders/Skinned.vert

@@ -1,9 +1,9 @@
 // ----------------------------------------------------------------
 // From Game Programming in C++ by Sanjay Madhav
 // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
-//
+// 
 // Released under the BSD License
-// See LICENSE.txt for full details.
+// See LICENSE in root directory for full details.
 // ----------------------------------------------------------------
 
 // Request GLSL 3.3