Replace QVector, QList with std::vector, std::list
An exception is made of TexPool, which will need a bit more testing before transitioning to std containers. Also replace 'int' with 'size_t' where it is used only as an array index.
This commit is contained in:
parent
8215bc7e7d
commit
231e38ae8e
|
@ -224,14 +224,14 @@ static void runRMXPScripts()
|
|||
return;
|
||||
}
|
||||
|
||||
int scriptCount = RARRAY_LEN(scriptArray);
|
||||
size_t scriptCount = RARRAY_LEN(scriptArray);
|
||||
|
||||
QByteArray decodeBuffer;
|
||||
decodeBuffer.resize(0x1000);
|
||||
|
||||
QVector<Script> encScripts(scriptCount);
|
||||
std::vector<Script> encScripts(scriptCount);
|
||||
|
||||
for (int i = 0; i < scriptCount; ++i)
|
||||
for (size_t i = 0; i < scriptCount; ++i)
|
||||
{
|
||||
VALUE script = rb_ary_entry(scriptArray, i);
|
||||
|
||||
|
@ -250,7 +250,7 @@ static void runRMXPScripts()
|
|||
sc.unknown = FIX2UINT(scriptUnknown);
|
||||
}
|
||||
|
||||
for (int i = 0; i < scriptCount; ++i)
|
||||
for (size_t i = 0; i < scriptCount; ++i)
|
||||
{
|
||||
Script &sc = encScripts[i];
|
||||
|
||||
|
@ -280,7 +280,8 @@ static void runRMXPScripts()
|
|||
if (result != Z_OK)
|
||||
{
|
||||
static char buffer[256];
|
||||
snprintf(buffer, sizeof(buffer), "Error decoding script %d: '%s'",
|
||||
/* FIXME: '%zu' apparently gcc only? */
|
||||
snprintf(buffer, sizeof(buffer), "Error decoding script %zu: '%s'",
|
||||
i, sc.name.constData());
|
||||
|
||||
showMsg(buffer);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -312,7 +312,7 @@ MRB_METHOD(fileClose)
|
|||
}
|
||||
|
||||
static void
|
||||
readLine(FILE *f, QVector<char> &buffer)
|
||||
readLine(FILE *f, std::vector<char> &buffer)
|
||||
{
|
||||
buffer.clear();
|
||||
|
||||
|
@ -326,7 +326,7 @@ readLine(FILE *f, QVector<char> &buffer)
|
|||
if (c == '\n' || c == EOF)
|
||||
break;
|
||||
|
||||
buffer.append(c);
|
||||
buffer.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,19 +340,19 @@ MRB_METHOD(fileEachLine)
|
|||
mrb_get_args(mrb, "&", &block);
|
||||
|
||||
(void) f;
|
||||
QVector<char> buffer;
|
||||
std::vector<char> buffer;
|
||||
|
||||
mrb_value str = mrb_str_buf_new(mrb, 0);
|
||||
|
||||
while (feof(f) == 0)
|
||||
{
|
||||
GUARD_ERRNO( readLine(f, buffer); )
|
||||
if (buffer.isEmpty() && feof(f) != 0)
|
||||
if (buffer.empty() && feof(f) != 0)
|
||||
break;
|
||||
|
||||
size_t lineLen = buffer.count();
|
||||
size_t lineLen = buffer.size();
|
||||
mrb_str_resize(mrb, str, lineLen);
|
||||
memcpy(RSTRING_PTR(str), buffer.constData(), lineLen);
|
||||
memcpy(RSTRING_PTR(str), &buffer[0], lineLen);
|
||||
|
||||
mrb_yield(mrb, block, str);
|
||||
}
|
||||
|
@ -468,15 +468,15 @@ MRB_METHOD(fileReadLines)
|
|||
}
|
||||
|
||||
mrb_value ary = mrb_ary_new(mrb);
|
||||
QVector<char> buffer;
|
||||
std::vector<char> buffer;
|
||||
|
||||
while (feof(f) == 0)
|
||||
{
|
||||
GUARD_ERRNO( readLine(f, buffer); )
|
||||
if (buffer.isEmpty() && feof(f) != 0)
|
||||
if (buffer.empty() && feof(f) != 0)
|
||||
break;
|
||||
|
||||
mrb_value str = mrb_str_new(mrb, buffer.constData(), buffer.size());
|
||||
mrb_value str = mrb_str_new(mrb, &buffer[0], buffer.size());
|
||||
mrb_ary_push(mrb, ary, str);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../binding-util.h"
|
||||
#include "file.h"
|
||||
|
@ -40,7 +41,6 @@
|
|||
|
||||
#include <SDL_timer.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QByteArray>
|
||||
|
||||
|
@ -110,19 +110,27 @@ struct LinkBuffer
|
|||
{
|
||||
/* Key: val, Value: idx in vec */
|
||||
QHash<T, int> hash;
|
||||
QVector<T> vec;
|
||||
std::vector<T> vec;
|
||||
|
||||
bool contains(T value)
|
||||
{
|
||||
return hash.contains(value);
|
||||
}
|
||||
|
||||
bool containsIdx(int idx)
|
||||
{
|
||||
if (vec.empty())
|
||||
return false;
|
||||
|
||||
return (idx < vec.size());
|
||||
}
|
||||
|
||||
int add(T value)
|
||||
{
|
||||
int idx = vec.count();
|
||||
int idx = vec.size();
|
||||
|
||||
hash.insert(value, idx);
|
||||
vec.append(value);
|
||||
vec.push_back(value);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
@ -331,7 +339,7 @@ read_symlink(MarshalContext *ctx)
|
|||
{
|
||||
int idx = read_fixnum(ctx);
|
||||
|
||||
if (idx > ctx->symbols.vec.size()-1)
|
||||
if (!ctx->symbols.containsIdx(idx))
|
||||
throw Exception(Exception::ArgumentError, "bad symlink");
|
||||
|
||||
return ctx->symbols.lookup(idx);
|
||||
|
@ -342,7 +350,7 @@ read_link(MarshalContext *ctx)
|
|||
{
|
||||
int idx = read_fixnum(ctx);
|
||||
|
||||
if (idx > ctx->objects.vec.size()-1)
|
||||
if (!ctx->objects.containsIdx(idx))
|
||||
throw Exception(Exception::ArgumentError, "dump format error (unlinked)");
|
||||
|
||||
return ctx->objects.lookup(idx);
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
#include "rwmem.h"
|
||||
|
||||
#include <SDL_rwops.h>
|
||||
#include <QVector>
|
||||
|
||||
typedef QVector<char> ByteVec;
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<char> ByteVec;
|
||||
|
||||
static inline ByteVec *
|
||||
getRWPrivate(SDL_RWops *ops)
|
||||
|
@ -62,7 +63,7 @@ static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, si
|
|||
if (writeBytes == 1)
|
||||
{
|
||||
char byte = *static_cast<const char*>(buffer);
|
||||
v->append(byte);
|
||||
v->push_back(byte);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,7 @@ int RWMemGetData(SDL_RWops *ops, void *buffer)
|
|||
ByteVec *v = getRWPrivate(ops);
|
||||
|
||||
if (buffer)
|
||||
memcpy(buffer, v->constData(), v->size());
|
||||
memcpy(buffer, &(*v)[0], v->size());
|
||||
|
||||
return v->size();
|
||||
}
|
||||
|
|
|
@ -584,7 +584,7 @@ void Bitmap::radialBlur(int angle, int divisions)
|
|||
ColorQuadArray qArray;
|
||||
qArray.resize(5);
|
||||
|
||||
QVector<Vertex> &vert = qArray.vertices;
|
||||
std::vector<Vertex> &vert = qArray.vertices;
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ void Config::read()
|
|||
|
||||
QStringList _rtps = confFile.value("RTPs").toStringList();
|
||||
Q_FOREACH(const QString &s, _rtps)
|
||||
rtps << s.toUtf8();
|
||||
rtps.push_back(s.toUtf8());
|
||||
|
||||
confFile.beginGroup("Binding");
|
||||
|
||||
|
|
|
@ -23,10 +23,11 @@
|
|||
#define CONFIG_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QVariant>
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct Config
|
||||
{
|
||||
bool debugMode;
|
||||
|
@ -49,7 +50,7 @@ struct Config
|
|||
bool allowSymlinks;
|
||||
|
||||
QByteArray customScript;
|
||||
QVector<QByteArray> rtps;
|
||||
std::vector<QByteArray> rtps;
|
||||
|
||||
/* Any values in the [Binding]
|
||||
* group are collected here */
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <SDL_mutex.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -66,8 +67,6 @@ struct RGSS_entryHandle
|
|||
}
|
||||
};
|
||||
|
||||
typedef QList<QByteArray> QByteList;
|
||||
|
||||
struct RGSS_archiveData
|
||||
{
|
||||
PHYSFS_Io *archiveIo;
|
||||
|
@ -503,7 +502,7 @@ struct FileSystemPrivate
|
|||
/* All keys are lower case */
|
||||
QHash<QByteArray, QByteArray> pathCache;
|
||||
|
||||
QList<QByteArray> extensions[FileSystem::Undefined];
|
||||
std::vector<QByteArray> extensions[FileSystem::Undefined];
|
||||
|
||||
/* Attempt to locate an extension string in a filename.
|
||||
* Either a pointer into the input string pointing at the
|
||||
|
@ -552,8 +551,8 @@ struct FileSystemPrivate
|
|||
|
||||
if (type != FileSystem::Undefined)
|
||||
{
|
||||
QList<QByteArray> &extList = extensions[type];
|
||||
for (int i = 0; i < extList.count(); ++i)
|
||||
std::vector<QByteArray> &extList = extensions[type];
|
||||
for (size_t i = 0; i < extList.size(); ++i)
|
||||
{
|
||||
const char *ext = extList[i].constData();
|
||||
|
||||
|
@ -600,7 +599,8 @@ FileSystem::FileSystem(const char *argv0,
|
|||
p = new FileSystemPrivate;
|
||||
|
||||
/* Image extensions */
|
||||
p->extensions[Image] << "jpg" << "png";
|
||||
p->extensions[Image].push_back("jpg");
|
||||
p->extensions[Image].push_back("png");
|
||||
|
||||
/* Audio extensions */
|
||||
const Sound_DecoderInfo **di;
|
||||
|
@ -620,12 +620,13 @@ FileSystem::FileSystem(const char *argv0,
|
|||
break;
|
||||
}
|
||||
|
||||
p->extensions[Audio] << buf;
|
||||
p->extensions[Audio].push_back(buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* Font extensions */
|
||||
p->extensions[Font] << "ttf" << "otf";
|
||||
p->extensions[Font].push_back("ttf");
|
||||
p->extensions[Font].push_back("otf");
|
||||
|
||||
PHYSFS_init(argv0);
|
||||
PHYSFS_registerArchiver(&RGSS_Archiver);
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#define GLOBALIBO_H
|
||||
|
||||
#include "gl-util.h"
|
||||
#include <QVector>
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct GlobalIBO
|
||||
{
|
||||
IBO::ID ibo;
|
||||
QVector<uint32_t> buffer;
|
||||
std::vector<uint32_t> buffer;
|
||||
|
||||
GlobalIBO()
|
||||
{
|
||||
|
@ -40,25 +41,24 @@ struct GlobalIBO
|
|||
IBO::del(ibo);
|
||||
}
|
||||
|
||||
void ensureSize(int quadCount)
|
||||
void ensureSize(size_t quadCount)
|
||||
{
|
||||
if (buffer.size() >= quadCount*6)
|
||||
return;
|
||||
|
||||
int startInd = buffer.size() / 6;
|
||||
size_t startInd = buffer.size() / 6;
|
||||
buffer.reserve(quadCount*6);
|
||||
|
||||
for (int i = startInd; i < quadCount; ++i)
|
||||
for (size_t i = startInd; i < quadCount; ++i)
|
||||
{
|
||||
static const int indTemp[] = { 0, 1, 2, 2, 3, 0 };
|
||||
static const uint32_t indTemp[] = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
for (int j = 0; j < 6; ++j)
|
||||
buffer.append(i * 4 + indTemp[j]);
|
||||
for (size_t j = 0; j < 6; ++j)
|
||||
buffer.push_back(i * 4 + indTemp[j]);
|
||||
}
|
||||
|
||||
IBO::bind(ibo);
|
||||
IBO::uploadData(buffer.count() * sizeof(int),
|
||||
buffer.constData());
|
||||
IBO::uploadData(buffer.size() * sizeof(uint32_t), &buffer[0]);
|
||||
IBO::unbind();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -28,11 +28,9 @@
|
|||
#include <SDL_scancode.h>
|
||||
#include <SDL_mouse.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
const int Input::buttonCodeSize = 24;
|
||||
|
||||
struct ButtonState
|
||||
|
@ -279,13 +277,13 @@ static const Input::ButtonCode otherDirs[4][3] =
|
|||
|
||||
struct InputPrivate
|
||||
{
|
||||
QVector<KbBinding> kbBindings;
|
||||
QVector<JsAxisBinding> jsABindings;
|
||||
QVector<JsButtonBinding> jsBBindings;
|
||||
QVector<MsBinding> msBindings;
|
||||
std::vector<KbBinding> kbBindings;
|
||||
std::vector<JsAxisBinding> jsABindings;
|
||||
std::vector<JsButtonBinding> jsBBindings;
|
||||
std::vector<MsBinding> msBindings;
|
||||
|
||||
/* Collective binding array */
|
||||
QVector<Binding*> bindings;
|
||||
std::vector<Binding*> bindings;
|
||||
|
||||
ButtonState stateArray[Input::buttonCodeSize*2];
|
||||
|
||||
|
@ -369,16 +367,17 @@ struct InputPrivate
|
|||
{
|
||||
kbBindings.resize(staticKbBindingsN+defaultKbBindingsN);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < staticKbBindingsN; ++i)
|
||||
size_t n = 0;
|
||||
|
||||
for (size_t i = 0; i < staticKbBindingsN; ++i)
|
||||
kbBindings[n++] = KbBinding(staticKbBindings[i]);
|
||||
|
||||
for (int i = 0; i < defaultKbBindingsN; ++i)
|
||||
for (size_t i = 0; i < defaultKbBindingsN; ++i)
|
||||
kbBindings[n++] = KbBinding(defaultKbBindings[i]);
|
||||
|
||||
/* Add to binging array */
|
||||
for (int i = 0; i < kbBindings.count(); ++i)
|
||||
bindings.append(&kbBindings[i]);
|
||||
for (size_t i = 0; i < kbBindings.size(); ++i)
|
||||
bindings.push_back(&kbBindings[i]);
|
||||
}
|
||||
|
||||
void initJsBindings()
|
||||
|
@ -386,7 +385,7 @@ struct InputPrivate
|
|||
/* Create axis bindings */
|
||||
jsABindings.resize(4);
|
||||
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
jsABindings[i++] = JsAxisBinding(&EventThread::joyState.xAxis, 0x7FFF, Input::Right);
|
||||
jsABindings[i++] = JsAxisBinding(&EventThread::joyState.xAxis, -0x8000, Input::Left);
|
||||
jsABindings[i++] = JsAxisBinding(&EventThread::joyState.yAxis, 0x7FFF, Input::Down);
|
||||
|
@ -395,34 +394,34 @@ struct InputPrivate
|
|||
/* Create button bindings */
|
||||
jsBBindings.resize(defaultJsBindingsN);
|
||||
|
||||
for (int i = 0; i < defaultJsBindingsN; ++i)
|
||||
for (size_t i = 0; i < defaultJsBindingsN; ++i)
|
||||
jsBBindings[i] = JsButtonBinding(defaultJsBindings[i]);
|
||||
|
||||
/* Add to binging array */
|
||||
for (int i = 0; i < jsABindings.count(); ++i)
|
||||
bindings.append(&jsABindings[i]);
|
||||
for (size_t i = 0; i < jsABindings.size(); ++i)
|
||||
bindings.push_back(&jsABindings[i]);
|
||||
|
||||
for (int i = 0; i < jsBBindings.count(); ++i)
|
||||
bindings.append(&jsBBindings[i]);
|
||||
for (size_t i = 0; i < jsBBindings.size(); ++i)
|
||||
bindings.push_back(&jsBBindings[i]);
|
||||
}
|
||||
|
||||
void initMsBindings()
|
||||
{
|
||||
msBindings.resize(3);
|
||||
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
msBindings[i++] = MsBinding(SDL_BUTTON_LEFT, Input::MouseLeft);
|
||||
msBindings[i++] = MsBinding(SDL_BUTTON_MIDDLE, Input::MouseMiddle);
|
||||
msBindings[i++] = MsBinding(SDL_BUTTON_RIGHT, Input::MouseRight);
|
||||
|
||||
/* Add to binding array */
|
||||
for (int i = 0; i < msBindings.count(); ++i)
|
||||
bindings.append(&msBindings[i]);
|
||||
for (size_t i = 0; i < msBindings.size(); ++i)
|
||||
bindings.push_back(&msBindings[i]);
|
||||
}
|
||||
|
||||
void pollBindings(Input::ButtonCode &repeatCand)
|
||||
{
|
||||
for (int i = 0; i < bindings.count(); ++i)
|
||||
for (size_t i = 0; i < bindings.size(); ++i)
|
||||
pollBindingPriv(*bindings[i], repeatCand);
|
||||
|
||||
updateDir4();
|
||||
|
@ -466,7 +465,7 @@ struct InputPrivate
|
|||
{
|
||||
int dirFlag = 0;
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
dirFlag |= (getState(dirs[i]).pressed ? dirFlags[i] : 0);
|
||||
|
||||
if (dirFlag == deadDirFlags[0] || dirFlag == deadDirFlags[1])
|
||||
|
@ -480,7 +479,7 @@ struct InputPrivate
|
|||
/* Check if prev still pressed */
|
||||
if (getState(dir4Data.previous).pressed)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
{
|
||||
Input::ButtonCode other =
|
||||
otherDirs[(dir4Data.previous/2)-1][i];
|
||||
|
@ -494,7 +493,7 @@ struct InputPrivate
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if (!getState(dirs[i]).pressed)
|
||||
continue;
|
||||
|
@ -520,7 +519,7 @@ struct InputPrivate
|
|||
|
||||
dir8Data.active = 0;
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
Input::ButtonCode one = dirs[i];
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "global-ibo.h"
|
||||
#include "shader.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t index_t;
|
||||
|
@ -34,7 +36,7 @@ typedef uint32_t index_t;
|
|||
|
||||
struct ColorQuadArray
|
||||
{
|
||||
QVector<Vertex> vertices;
|
||||
std::vector<Vertex> vertices;
|
||||
|
||||
VBO::ID vbo;
|
||||
VAO::ID vao;
|
||||
|
@ -81,7 +83,7 @@ struct ColorQuadArray
|
|||
void commit()
|
||||
{
|
||||
VBO::bind(vbo);
|
||||
VBO::uploadData(vertices.size() * sizeof(Vertex), vertices.constData(), GL_DYNAMIC_DRAW);
|
||||
VBO::uploadData(vertices.size() * sizeof(Vertex), &vertices[0], GL_DYNAMIC_DRAW);
|
||||
VBO::unbind();
|
||||
|
||||
shState->ensureQuadIBO(quadCount);
|
||||
|
@ -110,7 +112,7 @@ struct ColorQuadArray
|
|||
|
||||
struct PointArray
|
||||
{
|
||||
QVector<Vertex> vertices;
|
||||
std::vector<Vertex> vertices;
|
||||
VBO::ID vbo;
|
||||
VAO::ID vao;
|
||||
|
||||
|
@ -143,13 +145,13 @@ struct PointArray
|
|||
Vertex vert;
|
||||
vert.pos = pos;
|
||||
vert.color = color;
|
||||
vertices.append(vert);
|
||||
vertices.push_back(vert);
|
||||
}
|
||||
|
||||
void commit()
|
||||
{
|
||||
VBO::bind(vbo);
|
||||
VBO::uploadData(vertices.size() * sizeof(Vertex), vertices.constData());
|
||||
VBO::uploadData(vertices.size() * sizeof(Vertex), &vertices[0]);
|
||||
VBO::unbind();
|
||||
}
|
||||
|
||||
|
@ -167,7 +169,7 @@ struct PointArray
|
|||
|
||||
int count()
|
||||
{
|
||||
return vertices.count();
|
||||
return vertices.size();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ struct SharedStatePrivate
|
|||
if (QFile::exists(archPath.constData()))
|
||||
fileSystem.addPath(archPath.constData());
|
||||
|
||||
for (int i = 0; i < config.rtps.count(); ++i)
|
||||
for (size_t i = 0; i < config.rtps.size(); ++i)
|
||||
fileSystem.addPath(config.rtps[i].constData());
|
||||
|
||||
fileSystem.createPathCache();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "tileatlas.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace TileAtlas
|
||||
{
|
||||
|
||||
|
@ -35,7 +37,8 @@ struct Column
|
|||
{}
|
||||
};
|
||||
|
||||
typedef QList<Column> ColumnList;
|
||||
// FIXME: this can be optimized to a vector
|
||||
typedef std::list<Column> ColumnList;
|
||||
|
||||
/* Autotile area width */
|
||||
static const int atAreaW = 96*4;
|
||||
|
@ -80,8 +83,8 @@ static ColumnList calcSrcCols(int tilesetH)
|
|||
{
|
||||
ColumnList cols;
|
||||
|
||||
cols << Column(0, 0, tilesetH);
|
||||
cols << Column(tsLaneW, 0, tilesetH);
|
||||
cols.push_back(Column(0, 0, tilesetH));
|
||||
cols.push_back(Column(tsLaneW, 0, tilesetH));
|
||||
|
||||
return cols;
|
||||
}
|
||||
|
@ -94,7 +97,7 @@ static ColumnList calcDstCols(int atlasW, int atlasH)
|
|||
const int underAt = atlasH - atAreaH;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
cols << Column(i*tsLaneW, atAreaH, underAt);
|
||||
cols.push_back(Column(i*tsLaneW, atAreaH, underAt));
|
||||
|
||||
if (atlasW <= atAreaW)
|
||||
return cols;
|
||||
|
@ -102,7 +105,7 @@ static ColumnList calcDstCols(int atlasW, int atlasH)
|
|||
const int remCols = (atlasW - atAreaW) / tsLaneW;
|
||||
|
||||
for (int i = 0; i < remCols; ++i)
|
||||
cols << Column(i*tsLaneW + atAreaW, 0, atlasH);
|
||||
cols.push_back(Column(i*tsLaneW + atAreaW, 0, atlasH));
|
||||
|
||||
return cols;
|
||||
}
|
||||
|
@ -113,18 +116,19 @@ static BlitList calcBlitsInt(ColumnList &srcCols, ColumnList &dstCols)
|
|||
|
||||
while (!srcCols.empty())
|
||||
{
|
||||
Column srcCol = srcCols.takeFirst();
|
||||
Q_ASSERT(srcCol.h > 0);
|
||||
Column srcCol = srcCols.front();
|
||||
srcCols.pop_front();
|
||||
|
||||
while (!dstCols.empty() && srcCol.h > 0)
|
||||
{
|
||||
Column dstCol = dstCols.takeFirst();
|
||||
Column dstCol = dstCols.front();
|
||||
dstCols.pop_front();
|
||||
|
||||
if (srcCol.h > dstCol.h)
|
||||
{
|
||||
/* srcCol doesn't fully fit into dstCol */
|
||||
blits << Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, dstCol.h);
|
||||
blits.push_back(Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, dstCol.h));
|
||||
|
||||
srcCol.y += dstCol.h;
|
||||
srcCol.h -= dstCol.h;
|
||||
|
@ -132,19 +136,19 @@ static BlitList calcBlitsInt(ColumnList &srcCols, ColumnList &dstCols)
|
|||
else if (srcCol.h < dstCol.h)
|
||||
{
|
||||
/* srcCol fits into dstCol with space remaining */
|
||||
blits << Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, srcCol.h);
|
||||
blits.push_back(Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, srcCol.h));
|
||||
|
||||
dstCol.y += srcCol.h;
|
||||
dstCol.h -= srcCol.h;
|
||||
dstCols.prepend(dstCol);
|
||||
dstCols.push_front(dstCol);
|
||||
srcCol.h = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* srcCol fits perfectly into dstCol */
|
||||
blits << Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, dstCol.h);
|
||||
blits.push_back(Blit(srcCol.x, srcCol.y,
|
||||
dstCol.x, dstCol.y, dstCol.h));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "etc-internal.h"
|
||||
|
||||
#include <QList>
|
||||
#include <vector>
|
||||
|
||||
namespace TileAtlas
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ struct Blit
|
|||
{}
|
||||
};
|
||||
|
||||
typedef QList<Blit> BlitList;
|
||||
typedef std::vector<Blit> BlitList;
|
||||
|
||||
/* Calculates the minimum atlas size required to hold
|
||||
* a tileset of height 'tilesetH'. If the required dimensions
|
||||
|
|
139
src/tilemap.cpp
139
src/tilemap.cpp
|
@ -39,16 +39,22 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
#include <SDL_surface.h>
|
||||
|
||||
extern const StaticRect autotileRects[];
|
||||
|
||||
typedef QVector<SVertex> SVVector;
|
||||
typedef std::vector<SVertex> SVVector;
|
||||
typedef struct { SVVector v[4]; } TileVBuffer;
|
||||
|
||||
/* Check if [C]ontainer contains [V]alue */
|
||||
template<typename C, typename V>
|
||||
inline bool contains(const C &c, const V &v)
|
||||
{
|
||||
return std::find(c.begin(), c.end(), v) != c.end();
|
||||
}
|
||||
|
||||
static const int tilesetW = 8 * 32;
|
||||
static const int autotileW = 3 * 32;
|
||||
static const int autotileH = 4 * 32;
|
||||
|
@ -220,7 +226,7 @@ struct GroundLayer : public ViewportElement
|
|||
|
||||
struct ScanRow : public ViewportElement
|
||||
{
|
||||
const int index;
|
||||
const size_t index;
|
||||
GLintptr vboOffset;
|
||||
GLsizei vboCount;
|
||||
TilemapPrivate *p;
|
||||
|
@ -233,7 +239,7 @@ struct ScanRow : public ViewportElement
|
|||
* holds the element count of the entire batch */
|
||||
GLsizei vboBatchCount;
|
||||
|
||||
ScanRow(TilemapPrivate *p, Viewport *viewport, int index);
|
||||
ScanRow(TilemapPrivate *p, Viewport *viewport, size_t index);
|
||||
|
||||
void draw();
|
||||
void drawInt();
|
||||
|
@ -270,10 +276,10 @@ struct TilemapPrivate
|
|||
|
||||
/* Indices of usable
|
||||
* (not null, not disposed) autotiles */
|
||||
QVector<uint8_t> usableATs;
|
||||
std::vector<uint8_t> usableATs;
|
||||
|
||||
/* Indices of animated autotiles */
|
||||
QVector<uint8_t> animatedATs;
|
||||
std::vector<uint8_t> animatedATs;
|
||||
} atlas;
|
||||
|
||||
/* Map size in tiles */
|
||||
|
@ -284,12 +290,12 @@ struct TilemapPrivate
|
|||
TileVBuffer groundVert;
|
||||
|
||||
/* Scanrow vertices */
|
||||
QVector<TileVBuffer> scanrowVert;
|
||||
std::vector<TileVBuffer> scanrowVert;
|
||||
|
||||
/* Base quad indices of each scanrow
|
||||
* in the shared buffer */
|
||||
QVector<int> scanrowBases;
|
||||
int scanrowCount;
|
||||
std::vector<int> scanrowBases;
|
||||
size_t scanrowCount;
|
||||
|
||||
/* Shared buffers for all tiles */
|
||||
struct
|
||||
|
@ -311,7 +317,7 @@ struct TilemapPrivate
|
|||
{
|
||||
VAO::ID vao;
|
||||
VBO::ID vbo;
|
||||
int quadCount;
|
||||
size_t quadCount;
|
||||
uint8_t alphaIdx;
|
||||
} flash;
|
||||
|
||||
|
@ -319,7 +325,7 @@ struct TilemapPrivate
|
|||
struct
|
||||
{
|
||||
GroundLayer *ground;
|
||||
QVector<ScanRow*> scanrows;
|
||||
std::vector<ScanRow*> scanrows;
|
||||
Scene::Geometry sceneGeo;
|
||||
Vec2i sceneOffset;
|
||||
|
||||
|
@ -449,7 +455,7 @@ struct TilemapPrivate
|
|||
VBO::del(flash.vbo);
|
||||
|
||||
tilesetCon.disconnect();
|
||||
for (int i = 0; i < autotileCount; ++i)
|
||||
for (size_t i = 0; i < autotileCount; ++i)
|
||||
{
|
||||
autotilesCon[i].disconnect();
|
||||
autotilesDispCon[i].disconnect();
|
||||
|
@ -487,12 +493,12 @@ struct TilemapPrivate
|
|||
void updateAutotileInfo()
|
||||
{
|
||||
/* Check if and which autotiles are animated */
|
||||
QVector<uint8_t> &usableATs = atlas.usableATs;
|
||||
QVector<uint8_t> &animatedATs = atlas.animatedATs;
|
||||
std::vector<uint8_t> &usableATs = atlas.usableATs;
|
||||
std::vector<uint8_t> &animatedATs = atlas.animatedATs;
|
||||
|
||||
usableATs.clear();
|
||||
|
||||
for (int i = 0; i < autotileCount; ++i)
|
||||
for (size_t i = 0; i < autotileCount; ++i)
|
||||
{
|
||||
if (!autotiles[i])
|
||||
continue;
|
||||
|
@ -503,12 +509,12 @@ struct TilemapPrivate
|
|||
if (autotiles[i]->megaSurface())
|
||||
continue;
|
||||
|
||||
usableATs.append(i);
|
||||
usableATs.push_back(i);
|
||||
|
||||
autotiles[i]->flush();
|
||||
|
||||
if (autotiles[i]->width() > autotileW)
|
||||
animatedATs.append(i);
|
||||
animatedATs.push_back(i);
|
||||
}
|
||||
|
||||
tiles.animated = !animatedATs.empty();
|
||||
|
@ -655,7 +661,7 @@ struct TilemapPrivate
|
|||
|
||||
SDL_Surface *tsSurf = tileset->megaSurface();
|
||||
|
||||
for (int i = 0; i < blits.count(); ++i)
|
||||
for (size_t i = 0; i < blits.size(); ++i)
|
||||
{
|
||||
TileAtlas::Blit &blitOp = blits[i];
|
||||
|
||||
|
@ -671,7 +677,7 @@ struct TilemapPrivate
|
|||
/* Regular tileset */
|
||||
FBO::bind(tileset->getGLTypes().fbo, FBO::Read);
|
||||
|
||||
for (int i = 0; i < blits.count(); ++i)
|
||||
for (size_t i = 0; i < blits.size(); ++i)
|
||||
{
|
||||
TileAtlas::Blit &blitOp = blits[i];
|
||||
|
||||
|
@ -729,19 +735,19 @@ struct TilemapPrivate
|
|||
/* Adjust to atlas coordinates */
|
||||
texRect.y += atInd * autotileH;
|
||||
|
||||
for (int k = 0; k < bufferCount(); ++k)
|
||||
for (size_t k = 0; k < bufferCount(); ++k)
|
||||
{
|
||||
FloatRect _texRect = texRect;
|
||||
|
||||
if (atlas.animatedATs.contains(atInd))
|
||||
if (contains(atlas.animatedATs, atInd))
|
||||
_texRect.x += autotileW*k;
|
||||
|
||||
SVertex v[4];
|
||||
Quad::setTexPosRect(v, _texRect, posRect);
|
||||
|
||||
/* Iterate over 4 vertices */
|
||||
for (int i = 0; i < 4; ++i)
|
||||
array->v[k].append(v[i]);
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
array->v[k].push_back(v[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -791,15 +797,16 @@ struct TilemapPrivate
|
|||
SVertex v[4];
|
||||
Quad::setTexPosRect(v, texRect, posRect);
|
||||
|
||||
for (int k = 0; k < bufferCount(); ++k)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
targetArray->v[k].append(v[i]);
|
||||
for (size_t k = 0; k < bufferCount(); ++k)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
targetArray->v[k].push_back(v[i]);
|
||||
}
|
||||
|
||||
void clearQuadArrays()
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
groundVert.v[i].clear();
|
||||
|
||||
scanrowVert.clear();
|
||||
scanrowBases.clear();
|
||||
}
|
||||
|
@ -818,34 +825,34 @@ struct TilemapPrivate
|
|||
handleTile(x, y, z);
|
||||
}
|
||||
|
||||
static int quadDataSize(int quadCount)
|
||||
static size_t quadDataSize(size_t quadCount)
|
||||
{
|
||||
return quadCount * sizeof(SVertex) * 4;
|
||||
}
|
||||
|
||||
int scanrowSize(int index)
|
||||
size_t scanrowSize(size_t index)
|
||||
{
|
||||
return scanrowBases[index+1] - scanrowBases[index];
|
||||
}
|
||||
|
||||
void uploadBuffers()
|
||||
{
|
||||
scanrowCount = scanrowVert.count();
|
||||
scanrowCount = scanrowVert.size();
|
||||
scanrowBases.resize(scanrowCount + 1);
|
||||
|
||||
/* Calculate total quad count */
|
||||
int groundQuadCount = groundVert.v[0].count() / 4;
|
||||
int quadCount = groundQuadCount;
|
||||
size_t groundQuadCount = groundVert.v[0].size() / 4;
|
||||
size_t quadCount = groundQuadCount;
|
||||
|
||||
for (int i = 0; i < scanrowCount; ++i)
|
||||
for (size_t i = 0; i < scanrowCount; ++i)
|
||||
{
|
||||
scanrowBases[i] = quadCount;
|
||||
quadCount += scanrowVert[i].v[0].count() / 4;
|
||||
quadCount += scanrowVert[i].v[0].size() / 4;
|
||||
}
|
||||
|
||||
scanrowBases[scanrowCount] = quadCount;
|
||||
|
||||
int bufferFrameQuadCount = quadCount;
|
||||
size_t bufferFrameQuadCount = quadCount;
|
||||
tiles.bufferFrameSize = quadCount * 6 * sizeof(uint32_t);
|
||||
|
||||
quadCount *= bufferCount();
|
||||
|
@ -853,19 +860,18 @@ struct TilemapPrivate
|
|||
VBO::bind(tiles.vbo);
|
||||
VBO::allocEmpty(quadDataSize(quadCount));
|
||||
|
||||
for (int k = 0; k < bufferCount(); ++k)
|
||||
for (size_t k = 0; k < bufferCount(); ++k)
|
||||
{
|
||||
VBO::uploadSubData(k*quadDataSize(bufferFrameQuadCount),
|
||||
quadDataSize(groundQuadCount), groundVert.v[k].constData());
|
||||
quadDataSize(groundQuadCount), &groundVert.v[k][0]);
|
||||
|
||||
for (int i = 0; i < scanrowCount; ++i)
|
||||
for (size_t i = 0; i < scanrowCount; ++i)
|
||||
{
|
||||
if (scanrowVert[i].v[0].empty())
|
||||
continue;
|
||||
|
||||
VBO::uploadSubData(k*quadDataSize(bufferFrameQuadCount) + quadDataSize(scanrowBases[i]),
|
||||
quadDataSize(scanrowSize(i)),
|
||||
scanrowVert[i].v[k].constData());
|
||||
quadDataSize(scanrowSize(i)), &scanrowVert[i].v[k][0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -928,7 +934,7 @@ struct TilemapPrivate
|
|||
|
||||
void updateFlash()
|
||||
{
|
||||
QVector<CVertex> vertices;
|
||||
std::vector<CVertex> vertices;
|
||||
|
||||
for (int x = 0; x < mapWidth; ++x)
|
||||
for (int y = 0; y < mapHeight; ++y)
|
||||
|
@ -943,17 +949,17 @@ struct TilemapPrivate
|
|||
Quad::setPosRect(v, posRect);
|
||||
Quad::setColor(v, color);
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
vertices.append(v[i]);
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
vertices.push_back(v[i]);
|
||||
}
|
||||
|
||||
flash.quadCount = vertices.count() / 4;
|
||||
flash.quadCount = vertices.size() / 4;
|
||||
|
||||
if (flash.quadCount == 0)
|
||||
return;
|
||||
|
||||
VBO::bind(flash.vbo);
|
||||
VBO::uploadData(sizeof(CVertex) * vertices.count(), vertices.constData());
|
||||
VBO::uploadData(sizeof(CVertex) * vertices.size(), &vertices[0]);
|
||||
VBO::unbind();
|
||||
|
||||
/* Ensure global IBO size */
|
||||
|
@ -965,20 +971,20 @@ struct TilemapPrivate
|
|||
delete elem.ground;
|
||||
elem.ground = 0;
|
||||
|
||||
for (int i = 0; i < elem.scanrows.count(); ++i)
|
||||
for (size_t i = 0; i < elem.scanrows.size(); ++i)
|
||||
delete elem.scanrows[i];
|
||||
|
||||
elem.scanrows.clear();
|
||||
}
|
||||
|
||||
void generateElements(QVector<int> &scanrowInd)
|
||||
void generateElements(std::vector<int> &scanrowInd)
|
||||
{
|
||||
elem.ground = new GroundLayer(this, viewport);
|
||||
|
||||
for (int i = 0; i < scanrowInd.count(); ++i)
|
||||
for (size_t i = 0; i < scanrowInd.size(); ++i)
|
||||
{
|
||||
int index = scanrowInd[i];
|
||||
elem.scanrows.append(new ScanRow(this, viewport, index));
|
||||
elem.scanrows.push_back(new ScanRow(this, viewport, index));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -987,26 +993,27 @@ struct TilemapPrivate
|
|||
destroyElements();
|
||||
|
||||
/* Only generate elements for non-emtpy scanrows */
|
||||
QVector<int> scanrowInd;
|
||||
for (int i = 0; i < scanrowCount; ++i)
|
||||
if (scanrowVert[i].v[0].count() > 0)
|
||||
scanrowInd.append(i);
|
||||
std::vector<int> scanrowInd;
|
||||
|
||||
for (size_t i = 0; i < scanrowCount; ++i)
|
||||
if (scanrowVert[i].v[0].size() > 0)
|
||||
scanrowInd.push_back(i);
|
||||
|
||||
generateElements(scanrowInd);
|
||||
}
|
||||
|
||||
void updateZOrder()
|
||||
{
|
||||
if (elem.scanrows.isEmpty())
|
||||
if (elem.scanrows.empty())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < elem.scanrows.count(); ++i)
|
||||
for (size_t i = 0; i < elem.scanrows.size(); ++i)
|
||||
elem.scanrows[i]->initUpdateZ();
|
||||
|
||||
ScanRow *prev = elem.scanrows.first();
|
||||
ScanRow *prev = elem.scanrows.front();
|
||||
prev->finiUpdateZ(0);
|
||||
|
||||
for (int i = 1; i < elem.scanrows.count(); ++i)
|
||||
for (size_t i = 1; i < elem.scanrows.size(); ++i)
|
||||
{
|
||||
ScanRow *row = elem.scanrows[i];
|
||||
row->finiUpdateZ(prev);
|
||||
|
@ -1025,9 +1032,9 @@ struct TilemapPrivate
|
|||
* single sized batches are possible. */
|
||||
void prepareScanrowBatches()
|
||||
{
|
||||
const QVector<ScanRow*> &scanrows = elem.scanrows;
|
||||
const std::vector<ScanRow*> &scanrows = elem.scanrows;
|
||||
|
||||
for (int i = 0; i < scanrows.size(); ++i)
|
||||
for (size_t i = 0; i < scanrows.size(); ++i)
|
||||
{
|
||||
ScanRow *batchHead = scanrows[i];
|
||||
batchHead->batchedFlag = false;
|
||||
|
@ -1124,7 +1131,7 @@ void GroundLayer::draw()
|
|||
|
||||
p->setTranslation(Normal, shader);
|
||||
|
||||
for (int i = 0; i < positionsN; ++i)
|
||||
for (size_t i = 0; i < positionsN; ++i)
|
||||
{
|
||||
const Position pos = positions[i];
|
||||
|
||||
|
@ -1147,7 +1154,7 @@ void GroundLayer::draw()
|
|||
shader.applyViewportProj();
|
||||
shader.setAlpha(flashAlpha[p->flash.alphaIdx] / 255.f);
|
||||
|
||||
for (int i = 0; i < positionsN; ++i)
|
||||
for (size_t i = 0; i < positionsN; ++i)
|
||||
{
|
||||
const Position pos = positions[i];
|
||||
|
||||
|
@ -1184,7 +1191,7 @@ void GroundLayer::onGeometryChange(const Scene::Geometry &geo)
|
|||
p->updateReplicas();
|
||||
}
|
||||
|
||||
ScanRow::ScanRow(TilemapPrivate *p, Viewport *viewport, int index)
|
||||
ScanRow::ScanRow(TilemapPrivate *p, Viewport *viewport, size_t index)
|
||||
: ViewportElement(viewport, 32 + index*32, p->elem.scanrowStamp),
|
||||
index(index),
|
||||
p(p),
|
||||
|
@ -1209,7 +1216,7 @@ void ScanRow::draw()
|
|||
|
||||
p->setTranslation(Normal, shader);
|
||||
|
||||
for (int i = 0; i < positionsN; ++i)
|
||||
for (size_t i = 0; i < positionsN; ++i)
|
||||
{
|
||||
const Position pos = positions[i];
|
||||
|
||||
|
@ -1338,7 +1345,7 @@ void Tilemap::setViewport(Viewport *value)
|
|||
|
||||
p->elem.ground->setViewport(value);
|
||||
|
||||
for (int i = 0; i < p->elem.scanrows.count(); ++i)
|
||||
for (size_t i = 0; i < p->elem.scanrows.size(); ++i)
|
||||
p->elem.scanrows[i]->setViewport(value);
|
||||
}
|
||||
|
||||
|
@ -1422,7 +1429,7 @@ void Tilemap::setVisible(bool value)
|
|||
return;
|
||||
|
||||
p->elem.ground->setVisible(value);
|
||||
for (int i = 0; i < p->elem.scanrows.count(); ++i)
|
||||
for (size_t i = 0; i < p->elem.scanrows.size(); ++i)
|
||||
p->elem.scanrows[i]->setVisible(value);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue