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