| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# #################################################################### |
| 5 |
# Copyright (C) 2005-2019 by the FIFE team |
| 6 |
# http://www.fifengine.net |
| 7 |
# This file is part of FIFE. |
| 8 |
# |
| 9 |
# FIFE is free software; you can redistribute it and/or |
| 10 |
# modify it under the terms of the GNU Lesser General Public |
| 11 |
# License as published by the Free Software Foundation; either |
| 12 |
# version 2.1 of the License, or (at your option) any later version. |
| 13 |
# |
| 14 |
# This library is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
# Lesser General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU Lesser General Public |
| 20 |
# License along with this library; if not, write to the |
| 21 |
# Free Software Foundation, Inc., |
| 22 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 |
# #################################################################### |
| 24 |
|
| 25 |
from .swig_test_utils import * |
| 26 |
import time |
| 27 |
|
| 28 |
class TestView(unittest.TestCase): |
| 29 |
|
| 30 |
def setUp(self): |
| 31 |
self.engine = getEngine() |
| 32 |
self.model = self.engine.getModel() |
| 33 |
self.map = self.model.createMap("map001") |
| 34 |
|
| 35 |
self.grid = self.model.getCellGrid("square") |
| 36 |
|
| 37 |
self.imgMgr = self.engine.getImageManager() |
| 38 |
|
| 39 |
self.obj1 = self.model.createObject('0','test_nspace') |
| 40 |
fife.ObjectVisual.create(self.obj1) |
| 41 |
img1 = self.imgMgr.load('tests/data/mushroom_007.png') |
| 42 |
self.obj1.get2dGfxVisual().addStaticImage(0, img1.getHandle()) |
| 43 |
|
| 44 |
self.obj2 = self.model.createObject('1','test_nspace') |
| 45 |
fife.ObjectVisual.create(self.obj2) |
| 46 |
img2 = self.imgMgr.get('tests/data/earth_1.png') |
| 47 |
self.obj2.get2dGfxVisual().addStaticImage(0, img2.getHandle()) |
| 48 |
|
| 49 |
self.screen_cell_w = img2.getWidth() |
| 50 |
self.screen_cell_h = img2.getHeight() |
| 51 |
|
| 52 |
self.layer = self.map.createLayer("layer001", self.grid) |
| 53 |
|
| 54 |
self.camcoord = fife.ExactModelCoordinate(2,0) |
| 55 |
|
| 56 |
print("Total Image Memory Used: " + str(self.imgMgr.getMemoryUsed())) |
| 57 |
|
| 58 |
def tearDown(self): |
| 59 |
self.engine.destroy() |
| 60 |
|
| 61 |
def testCamera(self): |
| 62 |
rb = self.engine.getRenderBackend() |
| 63 |
viewport = fife.Rect(0, 0, rb.getWidth(), rb.getHeight()) |
| 64 |
|
| 65 |
cam = self.map.addCamera("foo", viewport ) |
| 66 |
cam.setCellImageDimensions(self.screen_cell_w, self.screen_cell_h) |
| 67 |
cam.setRotation(45) |
| 68 |
cam.setTilt(40) |
| 69 |
cam.setLocation(fife.Location(self.layer)) |
| 70 |
cam.setViewPort(viewport) |
| 71 |
|
| 72 |
renderer = fife.InstanceRenderer.getInstance(cam) |
| 73 |
renderer.activateAllLayers(self.map) |
| 74 |
|
| 75 |
self.engine.initializePumping() |
| 76 |
|
| 77 |
for y in range(4): |
| 78 |
for x in range(4): |
| 79 |
i = self.layer.createInstance(self.obj2, fife.ModelCoordinate(x,y)) |
| 80 |
fife.InstanceVisual.create(i) |
| 81 |
self.engine.pump() |
| 82 |
time.sleep(0.01) |
| 83 |
i = self.layer.createInstance(self.obj1, fife.ModelCoordinate(0,0)) |
| 84 |
fife.InstanceVisual.create(i) |
| 85 |
i = self.layer.createInstance(self.obj1, fife.ModelCoordinate(2,1)) |
| 86 |
fife.InstanceVisual.create(i) |
| 87 |
|
| 88 |
for i in range(120): |
| 89 |
if i > 20 and i < 30: |
| 90 |
cam.setRotation(cam.getRotation() + 1) |
| 91 |
elif i > 30 and i < 40: |
| 92 |
cam.setRotation(cam.getRotation() - 1) |
| 93 |
elif i > 40 and i < 50: |
| 94 |
if i % 2 == 0: |
| 95 |
c = cam.getLocation().getExactLayerCoordinates() |
| 96 |
c.x += 0.1 |
| 97 |
c = cam.getLocation().setExactLayerCoordinates(c) |
| 98 |
elif i > 50 and i < 60: |
| 99 |
if i % 2 == 0: |
| 100 |
c = cam.getLocation().getExactLayerCoordinates() |
| 101 |
c.x -= 0.1 |
| 102 |
c = cam.getLocation().setExactLayerCoordinates(c) |
| 103 |
elif i > 60 and i < 70: |
| 104 |
cam.setTilt(cam.getTilt() + 1) |
| 105 |
elif i > 70 and i < 80: |
| 106 |
cam.setTilt(cam.getTilt() - 1) |
| 107 |
elif i > 80 and i < 90: |
| 108 |
cam.setZoom(cam.getZoom() + 0.010) |
| 109 |
elif i > 90 and i < 100: |
| 110 |
cam.setZoom(cam.getZoom() - 0.010) |
| 111 |
self.engine.pump() |
| 112 |
self.engine.finalizePumping() |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
TEST_CLASSES = [TestView] |
| 117 |
|
| 118 |
if __name__ == '__main__': |
| 119 |
unittest.main() |
| 120 |
|