mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-22 23:06:18 +00:00
Оптимизация потребления ОЗУ(на байт 20 +-)
This commit is contained in:
parent
6a8fb7bd17
commit
f216f616a0
8 changed files with 20 additions and 34 deletions
|
|
@ -222,8 +222,7 @@ GlobalIBO &SharedState::globalIBO(){
|
||||||
void SharedState::bindTex(){
|
void SharedState::bindTex(){
|
||||||
TEX::bind(p->globalTex);
|
TEX::bind(p->globalTex);
|
||||||
|
|
||||||
if (p->globalTexDirty)
|
if (p->globalTexDirty){
|
||||||
{
|
|
||||||
TEX::allocEmpty(p->globalTexW, p->globalTexH);
|
TEX::allocEmpty(p->globalTexW, p->globalTexH);
|
||||||
p->globalTexDirty = false;
|
p->globalTexDirty = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,6 @@ struct SoundBuffer{
|
||||||
|
|
||||||
static SoundBuffer *ref(SoundBuffer *buffer){
|
static SoundBuffer *ref(SoundBuffer *buffer){
|
||||||
++buffer->refCount;
|
++buffer->refCount;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ static const int atAreaH = 128*7 + atBuffer;
|
||||||
/* Autotile area */
|
/* Autotile area */
|
||||||
static const int atArea = atAreaW * atAreaH;
|
static const int atArea = atAreaW * atAreaH;
|
||||||
|
|
||||||
static const int tilesetW = 256;
|
static const unsigned short tilesetW = 256;
|
||||||
static const int tsLaneW = tilesetW / 2;
|
static const unsigned short tsLaneW = tilesetW / 2;
|
||||||
|
|
||||||
static int freeArea(int width, int height){
|
static int freeArea(int width, int height){
|
||||||
return width * height - atArea;
|
return width * height - atArea;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ 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;
|
||||||
|
|
||||||
static const int autotileCount = 7;
|
static const unsigned char autotileCount = 7;
|
||||||
|
|
||||||
static const int atAreaW = autotileW * 4;
|
static const int atAreaW = autotileW * 4;
|
||||||
static const int atAreaH = autotileH * autotileCount;
|
static const int atAreaH = autotileH * autotileCount;
|
||||||
|
|
@ -64,8 +64,8 @@ static const int atAreaH = autotileH * autotileCount;
|
||||||
static const int tsLaneW = tilesetW / 2;
|
static const int tsLaneW = tilesetW / 2;
|
||||||
/* Map viewport size */
|
/* Map viewport size */
|
||||||
//TODO: разные значения под разные разрешения экрана для оптимизации
|
//TODO: разные значения под разные разрешения экрана для оптимизации
|
||||||
static const int viewpW = 42;
|
static const char viewpW = 42;
|
||||||
static const int viewpH = 26;
|
static const char viewpH = 26;
|
||||||
|
|
||||||
static const size_t zlayersMax = viewpH + 5;
|
static const size_t zlayersMax = viewpH + 5;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ int oneDimCount(int tileDimension, int destDimension){
|
||||||
}
|
}
|
||||||
|
|
||||||
int twoDimCount(int tileW, int tileH, int destW, int destH) {
|
int twoDimCount(int tileW, int tileH, int destW, int destH) {
|
||||||
return oneDimCount(tileW, destW) *
|
return oneDimCount(tileW, destW) * oneDimCount(tileH, destH);
|
||||||
oneDimCount(tileH, destH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int buildH(const IntRect &sourceRect, int width, int x, int y, Vertex *verts){
|
int buildH(const IntRect &sourceRect, int width, int x, int y, Vertex *verts){
|
||||||
|
|
@ -52,8 +51,7 @@ int buildH(const IntRect &sourceRect, int width, int x, int y, Vertex *verts){
|
||||||
FloatRect destRect(x, y, sourceRect.w, sourceRect.h);
|
FloatRect destRect(x, y, sourceRect.w, sourceRect.h);
|
||||||
|
|
||||||
/* Full size quads */
|
/* Full size quads */
|
||||||
for (int x = 0; x < fullCount; ++x)
|
for (int x = 0; x < fullCount; ++x){
|
||||||
{
|
|
||||||
Vertex *vert = &verts[x*4];
|
Vertex *vert = &verts[x*4];
|
||||||
|
|
||||||
Quad::setTexRect(vert, _sourceRect);
|
Quad::setTexRect(vert, _sourceRect);
|
||||||
|
|
@ -62,8 +60,7 @@ int buildH(const IntRect &sourceRect, int width, int x, int y, Vertex *verts){
|
||||||
destRect.x += sourceRect.w;
|
destRect.x += sourceRect.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partSize)
|
if (partSize){
|
||||||
{
|
|
||||||
Vertex *vert = &verts[fullCount*4];
|
Vertex *vert = &verts[fullCount*4];
|
||||||
|
|
||||||
_sourceRect.w = partSize;
|
_sourceRect.w = partSize;
|
||||||
|
|
@ -87,8 +84,7 @@ int buildV(const IntRect &sourceRect, int height, int ox, int oy, Vertex *verts)
|
||||||
FloatRect destRect(ox, oy, sourceRect.w, sourceRect.h);
|
FloatRect destRect(ox, oy, sourceRect.w, sourceRect.h);
|
||||||
|
|
||||||
/* Full size quads */
|
/* Full size quads */
|
||||||
for (int y = 0; y < fullCount; ++y)
|
for (int y = 0; y < fullCount; ++y){
|
||||||
{
|
|
||||||
Vertex *vert = &verts[y*4];
|
Vertex *vert = &verts[y*4];
|
||||||
|
|
||||||
Quad::setTexRect(vert, _sourceRect);
|
Quad::setTexRect(vert, _sourceRect);
|
||||||
|
|
@ -97,8 +93,7 @@ int buildV(const IntRect &sourceRect, int height, int ox, int oy, Vertex *verts)
|
||||||
destRect.y += sourceRect.h;
|
destRect.y += sourceRect.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partSize)
|
if (partSize){
|
||||||
{
|
|
||||||
Vertex *vert = &verts[fullCount*4];
|
Vertex *vert = &verts[fullCount*4];
|
||||||
|
|
||||||
_sourceRect.h = partSize;
|
_sourceRect.h = partSize;
|
||||||
|
|
@ -128,16 +123,14 @@ int build(const IntRect &sourceRect, const IntRect &destRect, Vertex *verts) {
|
||||||
int qCount = 0;
|
int qCount = 0;
|
||||||
|
|
||||||
int v = 0;
|
int v = 0;
|
||||||
for (int i = 0; i < fullCount; ++i)
|
for (int i = 0; i < fullCount; ++i){
|
||||||
{
|
|
||||||
qCount += buildH(sourceRect, width, ox, oy, &verts[v]);
|
qCount += buildH(sourceRect, width, ox, oy, &verts[v]);
|
||||||
|
|
||||||
v += rowTileCount*4;
|
v += rowTileCount*4;
|
||||||
oy += sourceRect.h;
|
oy += sourceRect.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partSize)
|
if (partSize){
|
||||||
{
|
|
||||||
IntRect partSourceRect = sourceRect;
|
IntRect partSourceRect = sourceRect;
|
||||||
partSourceRect.h = partSize;
|
partSourceRect.h = partSize;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static inline int
|
static inline int wrapRange(int value, int min, int max){
|
||||||
wrapRange(int value, int min, int max){
|
|
||||||
if (value >= min && value <= max)
|
if (value >= min && value <= max)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,9 @@ struct ViewportPrivate{
|
||||||
}
|
}
|
||||||
|
|
||||||
void recomputeOnScreen(){
|
void recomputeOnScreen(){
|
||||||
SDL_Rect r1 = { screenRect.x, screenRect.y,
|
SDL_Rect r1 = { screenRect.x, screenRect.y, screenRect.w, screenRect.h };
|
||||||
screenRect.w, screenRect.h };
|
|
||||||
|
|
||||||
SDL_Rect r2 = { rect->x, rect->y,
|
SDL_Rect r2 = { rect->x, rect->y, rect->width, rect->height };
|
||||||
rect->width, rect->height };
|
|
||||||
|
|
||||||
SDL_Rect result;
|
SDL_Rect result;
|
||||||
isOnScreen = SDL_GetRectIntersection(&r1, &r2, &result);
|
isOnScreen = SDL_GetRectIntersection(&r1, &r2, &result);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
static size_t vfRead(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
static size_t vfRead(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
||||||
//size_t SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size);
|
|
||||||
return SDL_ReadIO(static_cast<SDL_IOStream*>(datasource), ptr, size);
|
return SDL_ReadIO(static_cast<SDL_IOStream*>(datasource), ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +62,7 @@ struct VorbisSource : ALDataSource{
|
||||||
} loop;
|
} loop;
|
||||||
|
|
||||||
struct{
|
struct{
|
||||||
int channels;
|
unsigned short channels;
|
||||||
int rate;
|
int rate;
|
||||||
int frameSize;
|
int frameSize;
|
||||||
ALenum alFormat;
|
ALenum alFormat;
|
||||||
|
|
@ -176,8 +175,7 @@ struct VorbisSource : ALDataSource{
|
||||||
}
|
}
|
||||||
|
|
||||||
while (canRead > 16){
|
while (canRead > 16){
|
||||||
long res = ov_read(&vf, static_cast<char*>(bufPtr),
|
long res = ov_read(&vf, static_cast<char*>(bufPtr), canRead, 0, sizeof(int16_t), 1, 0);
|
||||||
canRead, 0, sizeof(int16_t), 1, 0);
|
|
||||||
|
|
||||||
if (res < 0){
|
if (res < 0){
|
||||||
/* Read error */
|
/* Read error */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue