Working on refactoring
This commit is contained in:
parent
928600acd4
commit
3c2c06ca40
@ -73,6 +73,8 @@ set(SOURCES
|
|||||||
../src/MenuManager.cpp
|
../src/MenuManager.cpp
|
||||||
../src/Space.h
|
../src/Space.h
|
||||||
../src/Space.cpp
|
../src/Space.cpp
|
||||||
|
../src/GameConstants.h
|
||||||
|
../src/GameConstants.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(space-game001 ${SOURCES})
|
add_executable(space-game001 ${SOURCES})
|
||||||
|
|||||||
@ -67,6 +67,8 @@ add_executable(space-game001
|
|||||||
../src/MenuManager.cpp
|
../src/MenuManager.cpp
|
||||||
../src/Space.h
|
../src/Space.h
|
||||||
../src/Space.cpp
|
../src/Space.cpp
|
||||||
|
../src/GameConstants.h
|
||||||
|
../src/GameConstants.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Установка проекта по умолчанию для Visual Studio
|
# Установка проекта по умолчанию для Visual Studio
|
||||||
|
|||||||
14
src/Game.cpp
14
src/Game.cpp
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "network/LocalClient.h"
|
#include "network/LocalClient.h"
|
||||||
#include "network/ClientState.h"
|
#include "network/ClientState.h"
|
||||||
|
#include "GameConstants.h"
|
||||||
|
|
||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
@ -217,12 +217,6 @@ namespace ZL
|
|||||||
|
|
||||||
void Game::drawUI()
|
void Game::drawUI()
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
|
||||||
static const std::string envShaderName = "env";
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
@ -242,10 +236,7 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::drawScene() {
|
void Game::drawScene() {
|
||||||
//For low quality:
|
|
||||||
glViewport(0, 0, Environment::width, Environment::height);
|
glViewport(0, 0, Environment::width, Environment::height);
|
||||||
//For high quality:
|
|
||||||
//glViewport(0, 0, Environment::projectionWidth, Environment::projectionHeight);
|
|
||||||
if (!loadingCompleted) {
|
if (!loadingCompleted) {
|
||||||
drawLoading();
|
drawLoading();
|
||||||
}
|
}
|
||||||
@ -266,9 +257,6 @@ namespace ZL
|
|||||||
|
|
||||||
void Game::drawLoading()
|
void Game::drawLoading()
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "default";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
|
|||||||
9
src/GameConstants.cpp
Normal file
9
src/GameConstants.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "GameConstants.h"
|
||||||
|
|
||||||
|
namespace ZL
|
||||||
|
{
|
||||||
|
const std::string defaultShaderName = "default";
|
||||||
|
const std::string envShaderName = "env";
|
||||||
|
const std::string textureUniformName = "Texture";
|
||||||
|
}
|
||||||
|
|
||||||
11
src/GameConstants.h
Normal file
11
src/GameConstants.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "render/Renderer.h"
|
||||||
|
|
||||||
|
namespace ZL
|
||||||
|
{
|
||||||
|
extern const std::string defaultShaderName;
|
||||||
|
extern const std::string envShaderName;
|
||||||
|
|
||||||
|
extern const std::string textureUniformName;
|
||||||
|
}
|
||||||
|
|
||||||
@ -8,6 +8,7 @@
|
|||||||
#include "Environment.h"
|
#include "Environment.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "utils/Utils.h"
|
#include "utils/Utils.h"
|
||||||
|
#include "GameConstants.h"
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
@ -195,8 +196,6 @@ namespace ZL {
|
|||||||
sparkQuad.data.TexCoordData = drawTexCoords;
|
sparkQuad.data.TexCoordData = drawTexCoords;
|
||||||
sparkQuad.RefreshVBO();
|
sparkQuad.RefreshVBO();
|
||||||
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(shaderProgramName);
|
renderer.shaderManager.PushShader(shaderProgramName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "GameConstants.h"
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
@ -61,8 +62,6 @@ namespace ZL {
|
|||||||
}
|
}
|
||||||
if (!(*tex)) return;
|
if (!(*tex)) return;
|
||||||
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ animOffsetX, animOffsetY, 0.0f });
|
renderer.TranslateMatrix({ animOffsetX, animOffsetY, 0.0f });
|
||||||
renderer.ScaleMatrix({ animScaleX, animScaleY, 1.0f });
|
renderer.ScaleMatrix({ animScaleX, animScaleY, 1.0f });
|
||||||
@ -140,8 +139,6 @@ namespace ZL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UiSlider::draw(Renderer& renderer) const {
|
void UiSlider::draw(Renderer& renderer) const {
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
if (texTrack) {
|
if (texTrack) {
|
||||||
glBindTexture(GL_TEXTURE_2D, texTrack->getTexID());
|
glBindTexture(GL_TEXTURE_2D, texTrack->getTexID());
|
||||||
@ -186,8 +183,6 @@ namespace ZL {
|
|||||||
void UiStaticImage::draw(Renderer& renderer) const {
|
void UiStaticImage::draw(Renderer& renderer) const {
|
||||||
if (!texture) return;
|
if (!texture) return;
|
||||||
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, texture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(mesh);
|
renderer.DrawVertexRenderStruct(mesh);
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include "StoneObject.h"
|
#include "StoneObject.h"
|
||||||
#include "utils/TaskManager.h"
|
#include "utils/TaskManager.h"
|
||||||
#include "TextModel.h"
|
#include "TextModel.h"
|
||||||
|
#include "GameConstants.h"
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
@ -185,11 +186,9 @@ namespace ZL {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
static const std::string defaultShaderName2 = "planetBake";
|
static const std::string planetBakeShaderName = "planetBake";
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
|
renderer.shaderManager.PushShader(planetBakeShaderName);
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
|
||||||
Triangle tr = planetData.getLodLevel().triangles[0];
|
Triangle tr = planetData.getLodLevel().triangles[0];
|
||||||
@ -292,11 +291,11 @@ namespace ZL {
|
|||||||
|
|
||||||
void PlanetObject::drawPlanet(Renderer& renderer)
|
void PlanetObject::drawPlanet(Renderer& renderer)
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName = "planetLand";
|
static const std::string planetLandShaderName = "planetLand";
|
||||||
|
|
||||||
static const std::string textureUniformName = "Texture";
|
static const std::string textureUniformName = "Texture";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(planetLandShaderName);
|
||||||
|
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
@ -318,10 +317,9 @@ namespace ZL {
|
|||||||
|
|
||||||
const Matrix4f viewMatrix = renderer.GetCurrentModelViewMatrix();
|
const Matrix4f viewMatrix = renderer.GetCurrentModelViewMatrix();
|
||||||
|
|
||||||
renderer.RenderUniform1i("Texture", 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.RenderUniform1i("BakedTexture", 1);
|
renderer.RenderUniform1i("BakedTexture", 1);
|
||||||
|
|
||||||
|
|
||||||
Triangle tr = planetData.getLodLevel().triangles[0]; // Берем базовый треугольник
|
Triangle tr = planetData.getLodLevel().triangles[0]; // Берем базовый треугольник
|
||||||
Matrix3f mr = GetRotationForTriangle(tr); // Та же матрица, что и при запекании
|
Matrix3f mr = GetRotationForTriangle(tr); // Та же матрица, что и при запекании
|
||||||
|
|
||||||
@ -367,10 +365,9 @@ namespace ZL {
|
|||||||
|
|
||||||
void PlanetObject::drawStones(Renderer& renderer)
|
void PlanetObject::drawStones(Renderer& renderer)
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName2 = "planetStone";
|
static const std::string planetStoneShaderName = "planetStone";
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
renderer.shaderManager.PushShader(planetStoneShaderName);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
@ -536,10 +533,7 @@ namespace ZL {
|
|||||||
|
|
||||||
void PlanetObject::drawCamp(Renderer& renderer)
|
void PlanetObject::drawCamp(Renderer& renderer)
|
||||||
{
|
{
|
||||||
static const std::string defaultShaderName2 = "default";
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName2);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
|
||||||
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user