Permalink
Browse files

fix #6087

casualty of #416
  • Loading branch information...
rt
rt committed Nov 23, 2018
1 parent 9e01e1c commit b7bb119e8e1c1425dd9abb750903784aecc1bbde
@@ -186,13 +186,13 @@ std::vector<TexFile> C3DOTextureHandler::LoadTexFiles()
std::vector<TexFile> texFiles;
const std::vector<std::string>& filesBMP = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp");
std::vector<std::string> files = CFileHandler::FindFiles("unittextures/tatex/", "*.tga");
const std::vector<std::string>& bmpFiles = CFileHandler::FindFiles("unittextures/tatex/", "*.bmp");
std::vector<std::string> tgaFiles = CFileHandler::FindFiles("unittextures/tatex/", "*.tga");
files.insert(files.end(), filesBMP.begin(), filesBMP.end());
texFiles.reserve(files.size() + CTAPalette::NUM_PALETTE_ENTRIES);
tgaFiles.insert(tgaFiles.end(), bmpFiles.begin(), bmpFiles.end());
texFiles.reserve(tgaFiles.size() + CTAPalette::NUM_PALETTE_ENTRIES);
for (const std::string& s: files) {
for (const std::string& s: tgaFiles) {
const std::string s2 = StringToLower(FileSystem::GetBasename(s));
// avoid duplicate names and give tga images priority
@@ -208,8 +208,7 @@ std::vector<TexFile> C3DOTextureHandler::LoadTexFiles()
}
}
if (paletteFile.FileExists())
palette.Init(paletteFile);
palette.Init(paletteFile);
for (unsigned a = 0; a < CTAPalette::NUM_PALETTE_ENTRIES; ++a) {
TexFile texFile;
@@ -7,6 +7,7 @@
#include <vector>
#include "Rendering/GL/myGL.h"
#include "Rendering/Textures/TAPalette.h"
#include "System/float4.h"
#include "System/UnorderedMap.hpp"
@@ -38,6 +39,8 @@ class C3DOTextureHandler
private:
spring::unordered_map<std::string, UnitTexture> textures;
CTAPalette palette;
GLuint atlas3do1 = 0;
GLuint atlas3do2 = 0;
int bigTexX = 0;
@@ -1,27 +1,17 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "TAPalette.h"
#include "System/FileSystem/FileHandler.h"
CTAPalette palette;
CTAPalette::CTAPalette()
{
for (auto& color: p) {
color[0] = 0;
color[1] = 0;
color[2] = 0;
color[3] = 255;
}
}
void CTAPalette::Init(CFileHandler& paletteFile)
{
for (auto& color: p) {
for (auto& channel: color) {
paletteFile.Read(&color, 1);
}
color[3] = 255;
if (!paletteFile.FileExists())
return;
for (SColor& color: colors) {
paletteFile.Read(&color.i, 4);
// ignore alpha
color.a = 255;
}
}
@@ -3,21 +3,29 @@
#ifndef TA_PALETTE_H
#define TA_PALETTE_H
#include <cstdint>
#include "System/Color.h"
class CFileHandler;
class CTAPalette {
public:
enum { NUM_PALETTE_ENTRIES = 256 };
CTAPalette() {
for (SColor& color: colors) {
color.r = 0;
color.g = 0;
color.b = 0;
}
}
CTAPalette();
void Init(CFileHandler&);
inline const unsigned char* operator[] (int a) const { return p[a]; }
const uint8_t* operator[] (unsigned int a) const { return colors[a]; }
void Init(CFileHandler&);
public:
static constexpr unsigned int NUM_PALETTE_ENTRIES = 256;
private:
unsigned char p[NUM_PALETTE_ENTRIES][4];
SColor colors[NUM_PALETTE_ENTRIES];
};
extern CTAPalette palette;
#endif /* TA_PALETTE_H */

0 comments on commit b7bb119

Please sign in to comment.