Example #1
0
    private void DestructiveExplosion(Room room, Vector2 pos, float rad, bool affectTerrain = true)
    {
        AbstractDestruction ad = new AbstractDestruction(room.world, room.GetWorldCoordinate(pos), pos, rad, room.game.GetNewID(), affectTerrain);

        room.abstractRoom.AddEntity(ad);
        ad.ApplyTerrain();
        ad.ApplyVisual();

        // All affected screens must have their caches cleared
        {
            Texture2D currentLevelTex = room.game.rainWorld.persistentData.cameraTextures[0, 0];
            for (int i = 0, len = room.cameraPositions.Length; i < len; i++)
            {
                Vector2    testCamPos   = room.cameraPositions[i];
                IntVector2 testLocalPos = new IntVector2(Mathf.FloorToInt(ad.realPos.x - testCamPos.x), Mathf.FloorToInt(ad.realPos.y - testCamPos.y));
                if ((testLocalPos.x < -rad) || (testLocalPos.y < -rad) || (testLocalPos.x > currentLevelTex.width + rad) || (testLocalPos.y > currentLevelTex.height + rad))
                {
                    continue;
                }
                DestructionCache.ClearCachedTexture(i);
                DestructionCache.SetScreenDirty(i);
            }
        }
    }
Example #2
0
    private void RoomCamera_ApplyPositionChange(On.RoomCamera.orig_ApplyPositionChange orig, RoomCamera self)
    {
        // Cache the current screen, if needed
        // This is done on screen transition so each bomb won't individually cache the screen
        // Don't cache if the room is changing, though
        if (DestructionCache.IsScreenDirty(self.currentCameraPosition) && !self.AboutToSwitchRoom)
        {
            DestructionCache.CacheTexture(self.currentCameraPosition, self.room.game.rainWorld.persistentData.cameraTextures[0, 0]);
        }

        orig.Invoke(self);

        // Destruction must also be applied when the camera changes position
        bool mustApplyTexture = false;

        // Use a cached version of the texture, if available
        if (DestructionCache.HasTexture(self.currentCameraPosition) && !DestructionCache.IsScreenDirty(self.currentCameraPosition))
        {
            DestructionCache.ApplyTexture(self.currentCameraPosition, self.room.game.rainWorld.persistentData.cameraTextures[0, 0]);
        }
        else
        {
            foreach (AbstractWorldEntity entity in self.room.abstractRoom.entities)
            {
                if (entity is AbstractDestruction ad)
                {
                    mustApplyTexture = true;
                    ad.ApplyVisual(false);
                }
            }
            if (mustApplyTexture)
            {
                self.room.game.rainWorld.persistentData.cameraTextures[0, 0].Apply();
            }
        }
    }
Example #3
0
 private void RoomCamera_ChangeRoom(On.RoomCamera.orig_ChangeRoom orig, RoomCamera self, Room newRoom, int cameraPosition)
 {
     orig.Invoke(self, newRoom, cameraPosition);
     DestructionCache.NewRoom(newRoom.cameraPositions.Length);
 }