Question/Problems with CyCamera().JustLookAtPlot() and CyCamera().SetLookAtSpeed()

civjo

Chieftain
Joined
Oct 3, 2010
Messages
67
Following piece of code works perfectly:
Code:
         pFocus = CyCamera()
         pFocus.ResetZoom()
         pFocus.JustLookAtPlot(pCity.getCityIndexPlot(2))
The problem begins if it is part of a loop, ie. 2 (or more) cities shall be shown. It just shows the last, probably because this one overwrites the old ones without any registration of the human eye.
So I inserted an enormous "wait"-loop, doing nothing else than consuming time before the second JustLookAtPlot. Now the code runs once past this point and "waits" before the second access as intended (checked by prints in the debug.log). BUT: Now the map isn't updated at all, it remains just at the last focus. Probably the screen (module) will be refreshed AFTER the user (module) has finished. -->> just wasting time (inside the 'user' code) will not work.

Has anybody realized a solution for this behaviour? Maybe kind of a "delay" function?

---

A workaround could be zoom out into orbit, zooming slowly close onto city, zoom out again, and repeat with 2. city. (Moving all the time if I don't know how to stand still :lol:)

I toyed around with CyCamera().SetLookAtSpeed() & CyCamera().GetLookAtSpeed(), but it is set to REALLY small amounts (1.xxxxe-38), and I cannot set another value?? What does this mean?

Has anybody used CyCamera().SetCameraMovementSpeed or GetCameraMovementSpeed?
 
What you're trying to do is something that should be frame-based, and not turn-based.

That means that the callback you should use is not something that happens every turn (or move, or action, or whatever it is you do), but something that is called on every frame rendered.

I'm not sure, but it seems either redraw() or update() should be what you're looking for.

You can use these to update a member which holds the time, and then when the time comes - jump to the new location. Or whatever logic you need.
 
What you're trying to do is something that should be frame-based, and not turn-based.
Ahh, I see (hopefully)
You refer to the 2. part, the "video" - workaround
Such a "movement" would mean repeatedly (eg. every frame) zoom in or out one step ("distance") and have the "time" element done by the ONFRAME base? Please explain more, if I'm completely wrong.

Short: my workaround doesn't work :crazyeye: This way of zooming in and out to the city would be nice, but generates extra work and doesn't solve the initial problem. What I want is basically to show 2/3 cities slowly / long enough to see some generated units. I thought of a simple "camera-zoomin" method followed by a zoomout method just to give time to see something instead of instantly hoping from one to the next location giving NO time to see anything at all.
(Now the game shows all the moving around units normally and then the movement to the last (if more than 1) city and stops. All fine. But all but the last city are skipped.)
I'm not sure, but it seems either redraw() or update() should be what you're looking for.
Suppose you mean I shall call such a method while in the timewasting loop and waiting for the first JustLookAtPlot to appear on the screen ... Am I wrong?
Found CyGInterfaceScreen().setForcedRedraw(BOOL bRequiresForcedRedraw)
I'll try and see ...

BTW, do I need a line like
from math import sqrt, sin
to be able to use those functions?? Using just */ isn't great

Or even better: would
from time import sleep
work? (just sleep(5) to "waste" 5seconds)
 
Not exactly.
What I mean is something much simpler:

The redraw()/update() methods of the screen are called on a per frame basis (at least that's my semi-guess).
You can add code there to be performed on a per-frame basis. You don't need to call these methods.

Then, for example, you can do this:
Suppose you want to show 2 cities one after the other (A & B).
You zoom in to city A (using the methods you've already found), and then set a local member (framesToZoom) of the screen to 100, and another member to the plot of city B.
Then, on every frame, you decrease framesToZoom by 1, and on the frame it reaches 0 you call the method to zoom into city B.

Again, I'm not sure any of this will work in this environment, but this is what I'd try.
 
The redraw()/update() methods of the screen
:confused:You are not talking about methods which are available through the PythonAPI ... do you?
You can add code there
wouldn't this mean to have a working C++ developers environment?
 
No C++.
I assume you're working on CvMainInterface.py. In that case - you have these methods there, as part of the screen class.
 
Thanks a lot for your help. I mean in my brain the € dropped just cent by cent ... :lol:
Our communication helped me to understand the problem more clearly.:goodjob:
After a review of CvMainInterface.py I asked myself whether this would not work in CvEventManager.py via
Code:
	[B]def onUpdate(self, argsList):
		'Called every frame'[/B]
		fDeltaTime = argsList[0]
		# allow camera to be updated
		CvCameraControls.g_CameraControls.onUpdate( fDeltaTime )
(This way this feature would only change files which are already altered by my mod.) In fact, it does not. I thought this function is 'Called every frame' ... No?

Ok. then I found onKbdEvent(self, argsList) in CvEventManager.py
Now this is really cute: I use the unused "j" key - so the player can switch to the next city when HE wants to.
 
Thanks a lot for your help. I mean in my brain the € dropped just cent by cent ... :lol:
Our communication helped me to understand the problem more clearly.:goodjob:

No problem ;)

After a review of CvMainInterface.py I asked myself whether this would not work in CvEventManager.py via
Code:
	[B]def onUpdate(self, argsList):
		'Called every frame'[/B]
		fDeltaTime = argsList[0]
		# allow camera to be updated
		CvCameraControls.g_CameraControls.onUpdate( fDeltaTime )
(This way this feature would only change files which are already altered by my mod.) In fact, it does not. I thought this function is 'Called every frame' ... No?

Just a guess, but maybe try changing USE_ON_UPDATE_CALLBACK in PythonCallbacksDefine.xml to 1?
Note that it might slow your game...

Ok. then I found onKbdEvent(self, argsList) in CvEventManager.py
Now this is really cute: I use the unused "j" key - so the player can switch to the next city when HE wants to.

Nice idea!
Does it work properly? How do you tell the player 'press j for next city'?
 
Nice idea!
:blush: I should have written: I stumbled over onKbdEvent ...
(Theoretically I knew about this function - and thinking sharply I would have found it after searching, but so it was pure luck :king:)
Does it work properly?
This is the best of all: it worked the first time without any hesitations, typing errors, type errors, etc. AND it feels great to just hit the magic key and it _moves_ majestically slow to the next city!! GREAT
after the last is done wrap around to the first ... You see: I love it.:crazyeye:

[[ I consider now to implement a "show me all my cities in MY order" feature ... with 'push forward' and 'push backward' the current city ]]*

How do you tell the player 'press j for next city'?
Where I had the loop with camera adjustment & input-popupmessage is now a simple popup:
Code:
   elif len(lFocusCities) > 1:
[...]
      rebelPopup.setBodyString("Several rebelling cities! Press the j key after all popups are done"
the loop with camera adjustment & input-popupmessage is now inside
Code:
def updateFocus():
   'called FROM onKbdEvent(self, argsList) when -j- key is pressed'
   """Switch City the Focus is thrown upon"""
[...]
      pFocus = CyCamera()                              # show city on map
      pFocus.SetCameraMovementSpeed (CameraMovementSpeeds.CAMERAMOVEMENTSPEED_SLOW)
      pFocus.ResetZoom()
      pFocus.JustLookAtPlot(pCity.getCityIndexPlot(2))       # decentered because of following popup

* mercy, no Lena pun intended !!!!!
 
Back
Top Bottom