udomacenje zombija in uboj\
This commit is contained in:
@@ -13,7 +13,6 @@ class TerrainSystem {
|
||||
this.decorations = []; // Array za save/load compat
|
||||
this.decorationsMap = new Map(); // Fast lookup key->decor
|
||||
this.cropsMap = new Map(); // Store dynamic crops separately
|
||||
|
||||
// Render state monitoring
|
||||
this.visibleTiles = new Map(); // Key: "x,y", Value: Sprite
|
||||
this.visibleDecorations = new Map(); // Key: "x,y", Value: Sprite
|
||||
@@ -22,6 +21,13 @@ class TerrainSystem {
|
||||
this.offsetX = 0;
|
||||
this.offsetY = 0;
|
||||
|
||||
// Culling optimization
|
||||
this.lastCullX = -9999;
|
||||
this.lastCullY = -9999;
|
||||
|
||||
// Object Pools
|
||||
// Tiles will use Blitter, so no Sprite Pool needed for them.
|
||||
this.blitters = new Map(); // Key: textureKey, Value: Blitter Object
|
||||
// Object Pools
|
||||
this.tilePool = new ObjectPool(
|
||||
() => {
|
||||
@@ -251,6 +257,8 @@ class TerrainSystem {
|
||||
// Zagotovi teksture
|
||||
this.createTileTextures();
|
||||
|
||||
// DELETED Blitter Init
|
||||
|
||||
// Zagotovi decoration teksture - check for custom sprites first
|
||||
if (!this.scene.textures.exists('flower')) {
|
||||
TextureGenerator.createFlowerSprite(this.scene, 'flower');
|
||||
@@ -496,7 +504,7 @@ class TerrainSystem {
|
||||
|
||||
// Force Visual Update immediately?
|
||||
// updateCulling will catch it on next frame, but to be safe:
|
||||
// Or leave it to update loop.
|
||||
this.lastCullX = -9999; // Force update
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -524,7 +532,9 @@ class TerrainSystem {
|
||||
const key = `${x},${y}`;
|
||||
this.cropsMap.set(key, cropData);
|
||||
this.tiles[y][x].hasCrop = true;
|
||||
// updateCulling loop will pick it up on next frame
|
||||
this.tiles[y][x].hasCrop = true;
|
||||
// updateCulling loop will pick it up on next frame but we force it
|
||||
this.lastCullX = -9999;
|
||||
}
|
||||
|
||||
removeCrop(x, y) {
|
||||
@@ -558,14 +568,32 @@ class TerrainSystem {
|
||||
|
||||
// Update culling (called every frame)
|
||||
updateCulling(camera) {
|
||||
// Throttling Optimization - TEMPORARILY DISABLED FOR DEBUG
|
||||
// const dist = Phaser.Math.Distance.Between(camera.scrollX, camera.scrollY, this.lastCullX, this.lastCullY);
|
||||
// if (dist < 50) return;
|
||||
|
||||
// Debug log once
|
||||
if (!this.hasLogged) {
|
||||
console.log('UpdateCulling running. Camera:', camera.scrollX, camera.scrollY);
|
||||
this.hasLogged = true;
|
||||
}
|
||||
|
||||
this.lastCullX = camera.scrollX;
|
||||
this.lastCullY = camera.scrollY;
|
||||
|
||||
// ... (rest of setup)
|
||||
|
||||
const view = camera.worldView;
|
||||
const buffer = 200;
|
||||
// Optimization: Adjust buffer based on View Distance setting
|
||||
let buffer = 200;
|
||||
if (this.scene.settings && this.scene.settings.viewDistance === 'LOW') {
|
||||
buffer = 50;
|
||||
}
|
||||
const left = view.x - buffer - this.offsetX;
|
||||
const top = view.y - buffer - this.offsetY;
|
||||
const right = view.x + view.width + buffer - this.offsetX;
|
||||
const bottom = view.y + view.height + buffer - this.offsetY;
|
||||
|
||||
// Calculate visible bounding box (rough)
|
||||
const p1 = this.iso.toGrid(left, top);
|
||||
const p2 = this.iso.toGrid(right, top);
|
||||
const p3 = this.iso.toGrid(left, bottom);
|
||||
@@ -576,6 +604,12 @@ class TerrainSystem {
|
||||
const minGridY = Math.floor(Math.min(p1.y, p2.y, p3.y, p4.y));
|
||||
const maxGridY = Math.ceil(Math.max(p1.y, p2.y, p3.y, p4.y));
|
||||
|
||||
// Debug bounds once
|
||||
if (!this.hasLoggedBounds) {
|
||||
console.log('Culling Bounds:', minGridX, maxGridX, minGridY, maxGridY);
|
||||
this.hasLoggedBounds = true;
|
||||
}
|
||||
|
||||
const startX = Math.max(0, minGridX);
|
||||
const endX = Math.min(this.width, maxGridX);
|
||||
const startY = Math.max(0, minGridY);
|
||||
@@ -587,118 +621,112 @@ class TerrainSystem {
|
||||
|
||||
for (let y = startY; y < endY; y++) {
|
||||
for (let x = startX; x < endX; x++) {
|
||||
const key = `${x},${y}`;
|
||||
neededKeys.add(key);
|
||||
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
|
||||
const key = `${x},${y}`;
|
||||
neededKeys.add(key);
|
||||
|
||||
// Tile Logic
|
||||
if (!this.visibleTiles.has(key)) {
|
||||
const tilePos = this.iso.toScreen(x, y);
|
||||
const tileData = this.tiles[y][x];
|
||||
// Tile Logic
|
||||
if (!this.visibleTiles.has(key)) {
|
||||
const tilePos = this.iso.toScreen(x, y);
|
||||
const tileData = this.tiles[y][x];
|
||||
|
||||
const sprite = this.tilePool.get();
|
||||
sprite.setTexture(tileData.texture);
|
||||
// Get from Pool
|
||||
const sprite = this.tilePool.get();
|
||||
sprite.setTexture(tileData.texture);
|
||||
|
||||
// Elevation effect: MOČAN vertikalni offset za hribe
|
||||
const elevationOffset = tileData.elevation * -25; // Povečano iz -10 na -25
|
||||
sprite.setPosition(
|
||||
tilePos.x + this.offsetX,
|
||||
tilePos.y + this.offsetY + elevationOffset
|
||||
);
|
||||
// Elevation effect
|
||||
const elevationOffset = tileData.elevation * -25;
|
||||
sprite.setPosition(
|
||||
tilePos.x + this.offsetX,
|
||||
tilePos.y + this.offsetY + elevationOffset
|
||||
);
|
||||
|
||||
// DRAMATIČNO senčenje glede na višino
|
||||
if (tileData.type === 'grass') {
|
||||
let brightness = 1.0;
|
||||
|
||||
if (tileData.elevation > 0.5) {
|
||||
// Visoko = svetlo (1.0 - 1.5)
|
||||
brightness = 1.0 + (tileData.elevation - 0.5) * 1.0;
|
||||
// Senčenje
|
||||
if (tileData.type.includes('grass')) {
|
||||
let brightness = 1.0;
|
||||
if (tileData.elevation > 0.5) {
|
||||
brightness = 1.0 + (tileData.elevation - 0.5) * 1.0;
|
||||
} else {
|
||||
brightness = 0.7 + tileData.elevation * 0.6;
|
||||
}
|
||||
sprite.setTint(Phaser.Display.Color.GetColor(
|
||||
Math.min(255, Math.floor(92 * brightness)),
|
||||
Math.min(255, Math.floor(184 * brightness)),
|
||||
Math.min(255, Math.floor(92 * brightness))
|
||||
));
|
||||
} else {
|
||||
// Nizko = temno (0.7 - 1.0)
|
||||
brightness = 0.7 + tileData.elevation * 0.6;
|
||||
sprite.clearTint();
|
||||
}
|
||||
|
||||
sprite.setTint(Phaser.Display.Color.GetColor(
|
||||
Math.min(255, Math.floor(92 * brightness)),
|
||||
Math.min(255, Math.floor(184 * brightness)),
|
||||
Math.min(255, Math.floor(92 * brightness))
|
||||
));
|
||||
// FIXED DEPTH FOR DEBUG
|
||||
sprite.setDepth(-1000);
|
||||
sprite.setVisible(true);
|
||||
|
||||
this.visibleTiles.set(key, sprite);
|
||||
}
|
||||
|
||||
sprite.setDepth(this.iso.getDepth(x, y) - 2000); // Tiles always in background
|
||||
// Crop Logic
|
||||
if (this.tiles[y][x].hasCrop) {
|
||||
neededCropKeys.add(key);
|
||||
if (!this.visibleCrops.has(key)) {
|
||||
const cropData = this.cropsMap.get(key);
|
||||
if (cropData) {
|
||||
const cropPos = this.iso.toScreen(x, y);
|
||||
const tileData = this.tiles[y][x];
|
||||
const elevationOffset = tileData.elevation * -25;
|
||||
|
||||
this.visibleTiles.set(key, sprite);
|
||||
}
|
||||
const sprite = this.cropPool.get();
|
||||
sprite.setTexture(`crop_stage_${cropData.stage}`);
|
||||
sprite.setPosition(
|
||||
cropPos.x + this.offsetX,
|
||||
cropPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
|
||||
);
|
||||
// Crop depth = Y pos
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
sprite.setDepth(depth);
|
||||
|
||||
// Elevation effect matching tile logic
|
||||
const tileData = this.tiles[y][x];
|
||||
const elevationOffset = tileData.elevation * -25;
|
||||
|
||||
// Crop Logic
|
||||
if (this.tiles[y][x].hasCrop) {
|
||||
neededCropKeys.add(key);
|
||||
if (!this.visibleCrops.has(key)) {
|
||||
const cropData = this.cropsMap.get(key);
|
||||
if (cropData) {
|
||||
const cropPos = this.iso.toScreen(x, y);
|
||||
const sprite = this.cropPool.get();
|
||||
sprite.setTexture(`crop_stage_${cropData.stage}`);
|
||||
sprite.setPosition(
|
||||
cropPos.x + this.offsetX,
|
||||
cropPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
|
||||
);
|
||||
// Crop depth = Y pos
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
sprite.setDepth(depth);
|
||||
|
||||
this.visibleCrops.set(key, sprite);
|
||||
this.visibleCrops.set(key, sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decoration Logic
|
||||
if (this.tiles[y][x].hasDecoration) {
|
||||
neededDecorKeys.add(key);
|
||||
// Decoration Logic
|
||||
if (this.tiles[y][x].hasDecoration) {
|
||||
neededDecorKeys.add(key);
|
||||
|
||||
if (!this.visibleDecorations.has(key)) {
|
||||
// Fast lookup from map
|
||||
const decor = this.decorationsMap.get(key);
|
||||
if (!this.visibleDecorations.has(key)) {
|
||||
// Fast lookup from map
|
||||
const decor = this.decorationsMap.get(key);
|
||||
const tileData = this.tiles[y][x];
|
||||
const elevationOffset = tileData.elevation * -25;
|
||||
|
||||
if (decor) {
|
||||
const decorPos = this.iso.toScreen(x, y);
|
||||
const sprite = this.decorationPool.get();
|
||||
sprite.setTexture(decor.type);
|
||||
if (decor) {
|
||||
const decorPos = this.iso.toScreen(x, y);
|
||||
const sprite = this.decorationPool.get();
|
||||
sprite.setTexture(decor.type);
|
||||
|
||||
// Apply same elevation offset as tile
|
||||
sprite.setPosition(
|
||||
decorPos.x + this.offsetX,
|
||||
decorPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
|
||||
);
|
||||
// Apply same elevation offset as tile
|
||||
sprite.setPosition(
|
||||
decorPos.x + this.offsetX,
|
||||
decorPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
|
||||
);
|
||||
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
// Depth strategy: Base of object sorting.
|
||||
// Add small offset based on type if needed, but mainly use Y
|
||||
sprite.setDepth(depth);
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
// Depth strategy: Base of object sorting.
|
||||
// Add small offset based on type if needed, but mainly use Y
|
||||
sprite.setDepth(depth);
|
||||
|
||||
// Apply scale if present
|
||||
if (decor.scale) sprite.setScale(decor.scale);
|
||||
else sprite.setScale(1);
|
||||
// Apply scale if present
|
||||
if (decor.scale) sprite.setScale(decor.scale);
|
||||
else sprite.setScale(1);
|
||||
|
||||
sprite.flipX = (x + y) % 2 === 0;
|
||||
sprite.flipX = (x + y) % 2 === 0;
|
||||
|
||||
// INTERACTIVITY FIX: Allow clicking sprites directly
|
||||
sprite.setInteractive({ pixelPerfect: true, useHandCursor: true });
|
||||
// Sprites are just visual now, interaction handled by InteractionSystem via grid
|
||||
// sprite.setInteractive(...) removed to fix conflicts
|
||||
|
||||
// Clear old listeners
|
||||
sprite.off('pointerdown');
|
||||
// Add click listener
|
||||
sprite.on('pointerdown', (pointer) => {
|
||||
if (this.scene.interactionSystem) {
|
||||
// Manually trigger interaction logic
|
||||
this.scene.interactionSystem.handleDecorationClick(x, y);
|
||||
}
|
||||
});
|
||||
|
||||
this.visibleDecorations.set(key, sprite);
|
||||
this.visibleDecorations.set(key, sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user