Оптимизация потребления ОЗУ(на байт 20 +-)

This commit is contained in:
DepressedTWM 2026-05-19 23:26:08 +04:00
parent 6a8fb7bd17
commit f216f616a0
8 changed files with 20 additions and 34 deletions

View file

@ -222,8 +222,7 @@ GlobalIBO &SharedState::globalIBO(){
void SharedState::bindTex(){
TEX::bind(p->globalTex);
if (p->globalTexDirty)
{
if (p->globalTexDirty){
TEX::allocEmpty(p->globalTexW, p->globalTexH);
p->globalTexDirty = false;
}

View file

@ -57,7 +57,6 @@ struct SoundBuffer{
static SoundBuffer *ref(SoundBuffer *buffer){
++buffer->refCount;
return buffer;
}

View file

@ -44,8 +44,8 @@ static const int atAreaH = 128*7 + atBuffer;
/* Autotile area */
static const int atArea = atAreaW * atAreaH;
static const int tilesetW = 256;
static const int tsLaneW = tilesetW / 2;
static const unsigned short tilesetW = 256;
static const unsigned short tsLaneW = tilesetW / 2;
static int freeArea(int width, int height){
return width * height - atArea;

View file

@ -56,7 +56,7 @@ static const int tilesetW = 8 * 32;
static const int autotileW = 3 * 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 atAreaH = autotileH * autotileCount;
@ -64,8 +64,8 @@ static const int atAreaH = autotileH * autotileCount;
static const int tsLaneW = tilesetW / 2;
/* Map viewport size */
//TODO: разные значения под разные разрешения экрана для оптимизации
static const int viewpW = 42;
static const int viewpH = 26;
static const char viewpW = 42;
static const char viewpH = 26;
static const size_t zlayersMax = viewpH + 5;

View file

@ -37,8 +37,7 @@ int oneDimCount(int tileDimension, int destDimension){
}
int twoDimCount(int tileW, int tileH, int destW, int destH) {
return oneDimCount(tileW, destW) *
oneDimCount(tileH, destH);
return oneDimCount(tileW, destW) * oneDimCount(tileH, destH);
}
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);
/* Full size quads */
for (int x = 0; x < fullCount; ++x)
{
for (int x = 0; x < fullCount; ++x){
Vertex *vert = &verts[x*4];
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;
}
if (partSize)
{
if (partSize){
Vertex *vert = &verts[fullCount*4];
_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);
/* Full size quads */
for (int y = 0; y < fullCount; ++y)
{
for (int y = 0; y < fullCount; ++y){
Vertex *vert = &verts[y*4];
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;
}
if (partSize)
{
if (partSize){
Vertex *vert = &verts[fullCount*4];
_sourceRect.h = partSize;
@ -128,16 +123,14 @@ int build(const IntRect &sourceRect, const IntRect &destRect, Vertex *verts) {
int qCount = 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]);
v += rowTileCount*4;
oy += sourceRect.h;
}
if (partSize)
{
if (partSize){
IntRect partSourceRect = sourceRect;
partSourceRect.h = partSize;

View file

@ -27,8 +27,7 @@
#include <algorithm>
#include <vector>
static inline int
wrapRange(int value, int min, int max){
static inline int wrapRange(int value, int min, int max){
if (value >= min && value <= max)
return value;

View file

@ -75,11 +75,9 @@ struct ViewportPrivate{
}
void recomputeOnScreen(){
SDL_Rect r1 = { screenRect.x, screenRect.y,
screenRect.w, screenRect.h };
SDL_Rect r1 = { screenRect.x, screenRect.y, screenRect.w, screenRect.h };
SDL_Rect r2 = { rect->x, rect->y,
rect->width, rect->height };
SDL_Rect r2 = { rect->x, rect->y, rect->width, rect->height };
SDL_Rect result;
isOnScreen = SDL_GetRectIntersection(&r1, &r2, &result);

View file

@ -28,7 +28,6 @@
#include <algorithm>
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);
}
@ -63,7 +62,7 @@ struct VorbisSource : ALDataSource{
} loop;
struct{
int channels;
unsigned short channels;
int rate;
int frameSize;
ALenum alFormat;
@ -176,8 +175,7 @@ struct VorbisSource : ALDataSource{
}
while (canRead > 16){
long res = ov_read(&vf, static_cast<char*>(bufPtr),
canRead, 0, sizeof(int16_t), 1, 0);
long res = ov_read(&vf, static_cast<char*>(bufPtr), canRead, 0, sizeof(int16_t), 1, 0);
if (res < 0){
/* Read error */