Skip to content

Commit

Permalink
fix #6087
Browse files Browse the repository at this point in the history
casualty of #416
  • Loading branch information
rt committed Nov 23, 2018
1 parent 9e01e1c commit b7bb119
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
13 changes: 6 additions & 7 deletions rts/Rendering/Textures/3DOTextureHandler.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions rts/Rendering/Textures/3DOTextureHandler.h
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "Rendering/GL/myGL.h"
#include "Rendering/Textures/TAPalette.h"
#include "System/float4.h"
#include "System/UnorderedMap.hpp"

Expand Down Expand Up @@ -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;
Expand Down
26 changes: 8 additions & 18 deletions rts/Rendering/Textures/TAPalette.cpp
@@ -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;
}
}

22 changes: 15 additions & 7 deletions rts/Rendering/Textures/TAPalette.h
Expand Up @@ -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.