Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions app/src/main/java/com/scrat/everchanging/Background.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,16 @@ final class Background extends TextureObject {
R.drawable.image_301 //Red
}};

private final float scale;
private float scale;

private int currentSeason = -1;

Background(final Context context) {
super(context, textureList, null);
readScale(context);
}

private void readScale(final Context context) {
final TypedValue outValue = new TypedValue();
context.getResources().getValue(R.dimen.background_scale, outValue, true);
scale = outValue.getFloat();
Expand All @@ -234,14 +237,18 @@ void createObject(final int season) {
iterator.release();
} else {
final Object object = objects.obtain(texture, scale);
object.setObjectScale(1.0f);
object.resetMatrix();
object.resetViewMatrix();
object.setScale(ratio, ratio); //Масштабируем по высоте, иначе не красиво.
object.setTranslate(width - (object.texture.width) * scale * 0.5f * ratio, (object.texture.height) * scale * 0.5f * ratio);
setObjectScaleAndTranslation(object);
}
}

private void setObjectScaleAndTranslation(final Object object) {
object.setObjectScale(1.0f);
object.resetMatrix();
object.resetViewMatrix();
object.setScale(ratio, ratio); //Масштабируем по высоте, иначе не красиво.
object.setTranslate(width - (object.texture.width) * scale * 0.5f * ratio, (object.texture.height) * scale * 0.5f * ratio);
}

void update(final int season, final int timesOfDay) {
int s = season == 5 ? 4 : season;
if (currentSeason != s) createObject(s);
Expand All @@ -255,4 +262,21 @@ void update(final int season, final int timesOfDay) {

iterator.release();
}

@Override
public void setupPosition(final int width, final int height, final float ratio) {
super.setupPosition(width, height, ratio);
readScale(textureManager.getContext());
if (objects.objectsInUseCount() != 0) {
final ReusableIterator<Object> iterator = objects.iterator();
iterator.acquire();

while (iterator.hasNext()) {
final Object object = iterator.next();
setObjectScaleAndTranslation(object);
}

iterator.release();
}
}
}
18 changes: 0 additions & 18 deletions app/src/main/java/com/scrat/everchanging/EverchangingRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ final class EverchangingRender implements GLSurfaceView.Renderer {

private int lastSceneMaxFps = Scene.MINIMUM_FPS;

private int lastSurfaceWidth;
private int lastSurfaceHeight;

EverchangingRender(final Context context, final FrameScheduler frameScheduler) {
this.context = context;
this.frameScheduler = frameScheduler;
Expand Down Expand Up @@ -198,21 +195,6 @@ public void onSurfaceCreated(final GL10 gl, final EGLConfig config) {

@Override
public void onSurfaceChanged(final GL10 gl, final int width, final int height) {
boolean dimensionsChanged = false;
if (lastSurfaceWidth != 0 && lastSurfaceHeight != 0) {
if (lastSurfaceWidth != width || lastSurfaceHeight != height) {
dimensionsChanged = true;
}
}

lastSurfaceWidth = width;
lastSurfaceHeight = height;

if (dimensionsChanged) {
scenes.clear();
onSurfaceCreated(gl, null);
}

final WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
assert windowManager != null;
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/com/scrat/everchanging/Foreground.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,16 @@ final class Foreground extends TextureObject {
{{0, 0, 0}, {0, 38, 0}, {84, 225, 0}},
};

private final float scale;
private float scale;

private int current = -1;

Foreground(final Context context) {
super(context, textureList, null);
readScale(context);
}

private void readScale(final Context context) {
final TypedValue outValue = new TypedValue();
context.getResources().getValue(R.dimen.foreground_scale, outValue, true);
scale = outValue.getFloat();
Expand All @@ -316,6 +319,18 @@ void update(final int foregroundIndex, final int timesOfDay) {
iterator.release();
}

@Override
public void setupPosition(final int width, final int height, final float ratio) {
super.setupPosition(width, height, ratio);
readScale(textureManager.getContext());

if (current != -1) {
objects.markAllAsUnused();
resetMatrix();
createObjects();
}
}

private void createObjects() {
int textureListCurrentLength = textureList[current].length;
if (!isWideScreen()) {
Expand All @@ -325,6 +340,7 @@ private void createObjects() {
for (int i = 0; i < textureListCurrentLength; i++) {
int textureIndex = textureManager.getTextureIndex(textureList[current][i]);
Object object = objects.obtain(textureManager.getTexture(textureIndex), scale);
object.resetMatrix();
object.resetViewMatrix();
object.setObjectScale(1.0f);
}
Expand All @@ -343,7 +359,6 @@ private void setObjectsPosition() {
final Object object = iterator.next();
float spriteWidth = object.texture.width * scale;
float spriteHeight = object.texture.height * scale;
object.resetMatrix();

final float y = deltaHeight - spriteHeight + offsetValues[current][index][0];

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/scrat/everchanging/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Object {
public boolean used;

public float scale = 1.0f;
private float textureScale = 1f;

public FloatBuffer vertexBuffer; //Буффер описания размеров прямоугольника
public TextureManager.Texture texture;
Expand Down Expand Up @@ -61,11 +62,13 @@ class Object {
vertexBuffer = objectVerticesBuffer.asFloatBuffer();
resetMatrix();

textureScale = scale;
if (texture != null) setTexture(texture, scale);
}

Object(TextureManager.Texture texture, float scale) {
this();
textureScale = scale;
if (texture != null) setTexture(texture, scale);
}

Expand Down Expand Up @@ -110,8 +113,9 @@ void copyFrom(final Object source) {
}

void setTexture(TextureManager.Texture texture, float scale) {
if (this.texture != texture) {
if (this.texture != texture || textureScale != scale) {
this.texture = texture;
this.textureScale = scale;
final float x_width = texture.width * scale;
final float y_height = texture.height * scale;
final float x_begin = (0 - texture.pivot[0]) * scale;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/scrat/everchanging/TextureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ float dipToPixels(final float dipValue) {
}
}

public Context getContext() {
return context;
}

Texture getTexture(final int index) {
return textures[index];
}
Expand Down