GKRTree doesn't want to work at all, any other similar method? - swift

I'm making a game, where i need to define the object in the radius of the explosion in certain radius. Firstly, i was making it through distance between all objects, but i saw that there is GKRTree class in GameplayKit. But after many tries, it doesn't want to work at all. It just returns empty array in any case. I want to know, are GKRTree class broken or what. If yes, are there any other method to do the same stuff as GKRTree in swift or github. Because i dont want to calculate distance, since it can be use a lot of cpu.
Thanks
Edit: I tried what is described in this answer https://stackoverflow.com/a/38655862/11687591, but it dont work. And there are no another solution about this problem. There is some links, where somebody is talking about broken gkrtree and there is no answer. https://www.reddit.com/r/swift/comments/63frk6/does_anyone_have_a_working_example_of_gkrtree/
https://twitter.com/StayOnTheMove/status/1067067053419520000?s=20
And that's all. One things that i've tried that i created 2 circles. One of them is not moving and in one position all the time. Another is moving to my touch position. Second is smaller than the other one. Larger is a little bit transparent so i can see other circle. I also use print() to see all things that happening in the code. And after all of that, even if there is clearly situation where one circle is inside other one, gkrtree.entities method don't work and it returns empty array.

For what it's worth, GamePlayKit.GKRTree is recently failing for me as of Xcode 11.5+. The following line,
import GameKit
class blah {
private var searchTree: GKRTree<RouteSegment>?
public init() {
searchTree = GKRTree.init(maxNumberOfChildren: 3)
}
}
Using a let expression also gets a nil value.
Edit:
The reason it was returning nil is because I didn't have GameplayKit in the linking phase of the project. Duh. By default, all the iOS frameworks are on the search path, which doesn't mean they will be available at runtime. I'm not sure why Apple chose this mechanism. When I traced the assembly code step into the init() function, I found it just returned nil; there must be some stubs in the API.
Solution for me: make sure that GameplayKit is in the linked binaries phase in the project settings.

Related

Activating Inactive Same-Name Different-Tag Game Objects

For some reason, I cannot change the name of a game object (an avatar) but I need to have 2 different versions of it and activate them in code.
So, duplicating the avatar is not an option, but I still need to create an identical one and make a change in editor mode, so that based on a condition, whether one or the other is chosen.
It occurred to me, now that changing the name is not possible, perhaps I can give the other a different tag and activate the right one based on the selected scenario.
So, I checked out a few manual docs and some forum posts and came up with the following 3 alternatives to place in my Start() but none works:
void Start()
{
if ( GameObject.FindGameObjectWithTag("John") )
gameObject.FindGameObjectWithTag("John").SetActive(true);
if ( GameObject.FindWithTag("John") )
gameObject.FindWithTag("John").SetActive(true);
}
Can someone please help me understand what I am doing wrong and how I can achieve this: find an object that is not active (from among 2 inactive objects with the same name but different tags: one untagged and the other tagged as, say, John)
Couldn't be easier, just assign them to different variables
public GameObject johnCharacterOnLeft;
public GameObject johnCharacterWhoJoinsLater;
void Start()
{
johnCharacterOnLeft.SetActive(true);
johnCharacterOnLeft.Whatever(true);
johnCharacterOnLeft.Whatever(true);
johnCharacterOnLeft.Whatever(true);
johnCharacterWhoJoinsLater.SetActive(false);
johnCharacterWhoJoinsLater.Whatever(false);
johnCharacterWhoJoinsLater.Whatever(false);
...
}
Note, as a rule when you are learning, do not use Find. It's that simple. Use public variables and drag to connect in the inspector.
(If anyone reading does not yet know how to drag to connect in the inspector, check any basic tutorial.)
If you do want to find all objects with a certain tag:
GameObject[] allCats;
allCats = GameObject.FindGameObjectsWithTag("cat");
foreach (GameObject g in allCats)
Debug.Log("I found one, name is: " +g.name);
If you want to find one of those with a certain name you have to search through them all..
GameObject[] allCats;
allCats = GameObject.FindGameObjectsWithTag("cat");
foreach (GameObject g in allCats)
{
Debug.Log("I found one, name is: " +g.name);
if ( g.name == "Felix" )
{
Debug.Log("I did find Felix the cat");
g.Whatever ...
}
If you do want to find all objects with a certain name...
It's very important to understand that
...you just can't do that in Unity - it simply makes no sense.
Life's life that - Find is a hack you should never really use anyway, other than in rare situations. If you (for some reason?) need to "find" all game objects with a certain name, you have to simply look through every single thing in the scene (which is not particularly easy to do). You can easily google this. But there is, absolutely, no reason you would ever do this.
Note that, just one example .. say you had a number of "cat" thing in your scene. Very simply - nothing more complicated than this - you would have them all in the same "folder". (That is to say, all under the same holder game object.) That is just one incredibly simple approach to utterly avoid the sort of problem you're having.
Again there literally is no way to find "all game objects with the same name" - the Find call is a hack that should never have been in Unity; they explicitly don't have
And most importantly don't forget...Find doesn't work if inactive!
The Find call is a hack that should never have been in Unity: always remember it does not even work on inactive objects. Inasmuch as they threw in a "find name" concept, it's probably for the best that it doesn't work on inactive objects: but the whole thing is a shambles - just don't use "find", ever.
Particularly as a beginner just drag in the inspector - it's honestly that easy. (And again, in almost all cases your stuff will start inactive, so of course you have to do that since you can't "find" inactive stuff.)
(And a note - don't forget that if you're simply finding a "boss" type script, say your Scores or SoundEffects, never use find. Just do this easy idiom. )

what makes a variable be visible (intellij idea)

With intellij idea, how do I find out what makes a variable be visible?
An example of when it is hard:
Suppose you look at class A, and you see a variable something. If you jump to source you see that it's defined in trait X. But you don't extend trait X directly. What do you extend, then, that makes this variable visible? If you have a deeply nested hierarchy, tracking can be hard.
Any recommendations or solutions?
EDIT: Please vote for the feature if you're interested: http://youtrack.jetbrains.com/issue/IDEA-124369
I don't think that IntelliJ IDEA has any shortcut for "finding what makes a variable visible".
However you can determine it using the "Find Usages" option (Alt + F7). For example:
import java.nio._
object TempObj extends App {
def func = 2
val p = file.Paths.get("some-path")
func
}
So Find Usages on "file", tells you that its from the Package "file" (in heading of the new Tab it also shows the complete package name, ex: Find Usages of java.nio.file in Project Files).
Whereas Find Usages on func will tell you that its a Method (And the Tab heading now says: Find Usages of func() in Project and Libraries)
So now in way you can determine, what exactly makes the variable visible. This also works for imports since it shows the package from which it is imported and you can then look for import of that packages.
I know of two almost-solutions to this problem.
Go-to-declaration, as you mentioned, solves this problem in the case of local variables.
More generally, the "find usages" feature gives you a neat little breakdown by type and file of different uses of the variable. From this you can see if it's involved in a static import.
It's not perfect, but with a moment's thought these two are generally sufficient to figure out what you want.
Use ctrl+b or F4 to jump to source code. Alternatively you can use ctrl+shift+a to get option/action. You can find shortcuts at http://gaerfield.github.io/ide-shortcuts/ as well. Hope it will help.
From what I understood you want to see the code that creates an Object you use, for instance Mystery someMystery;.
That gives you two options to populate someMystery:
someMystery = ... where ... is your code to populate
someMystery and if that is the case you should follow
that code (with ctrl+B as far as you need to) to the point where it
actually creates the Mystery object.
Use CDI to populate that object instance for you, in which case you should look into the CDI mechanism in order to see in what way the object instance is populated.
In either way IMO there is no way to know for sure if the someMystery instance is of some more concrete class than Mystery, because it is decided in runtime, not in compile time, so your next bet would be to run the program in debug and see what object goes into someMystery, although you are not guaranteed to get the same type of object every time.
PS. My answer is based entirely on my java understanding of the topic, can't say if it is valid for scala also.
This might not be exactly the answer you were hoping to get.
However, quoting yourself,
If you have a deeply nested hierarchy, tracking can be hard.
Have you considered using composition over inheritance? Perhaps this would remove the need for the feature you are looking for.
Deeply nested hierarchy doesn't sound good. I understand your pain about that.
When you override vals or defs there is a little circle next to the line number that shows where it is from even when it is from nested hierarchy. Hovering over vals with the command key down also shows you a little tooltip where it is from.
Does this help?
https://youtu.be/r3D9axSlBo8
if you want class, field or method to be visible, you need to implement them as public. If it was your question.

Marmalade IwUIController causes crash when accessing IwUIElement objects

I created an app that works which is similar to the examples from the Marmalade SDK. Then I tried to move the IwUIController derived class in a separate files .h/.cpp to clean the code up a bit but I get a crash every time I try to access any IwUIElement? For example:
CIwUIImage* image = IwSafeCast<CIwUIImage*>(pScreen->GetChildNamed("Image"));
pScreen is declared as
static CIwUIElement *pScreen;
and then in main(): pScreen = CIwUIElement::CreateFromResource("Screen");
What can be the reason for these crashes? Does the Controller class need to be in the same file as main()? I've tried to debug and the pointer appears to be passed properly.
Not sure it really counts as an answer, but I don't have enough stackoverflow reputation to comment apparently;-)
If you've got C++ code that worked OK until you split it into two files, I would seriously check the #include and other declarations are the same in the new two files as they were in the originals. 9 times out of 10, my experience is that for some reason something is not the same. Actually one specific issue worth checking for is that a struct or class is only partly declared (e.g. a forward declaration) in one file and has lost its parent.
Having said that, as Creator, said what were the symptoms of the crash? Is this possibly the dynamic cast failing of IwSafeCast failing?

Making UIBezierPath more like NSBezierPath with elementCount and elementAtIndex

When moving some Cocoa code to Cocoa Touch I was disappointed to find that UIBezierPath is missing the "Accessing Elements of a Path" methods:
– elementCount
– elementAtIndex:
– elementAtIndex:associatedPoints:
– removeAllPoints
– setAssociatedPoints:atIndex:
The only way to get at these elements in Cocoa Touch seems to be through CGPathApply. Before I try to recreate this as a subclass or category of UIBezierPath, I was wondering if this had already been done. Does anyone have an idea if something like this is already available?
I made a port on https://github.com/seivan/UIBezierPathPort but it's with Swift.
Has a test suite and documentation.
Works as of Beta 5.
Technically you should be able to use Swift on a Obj-C project.
Let me know how you like it.
I've bumped into the same problem a couple of months ago and couldn't find anything readily available back then. (Truth be told, since going the CGPathApply route wasn't that bad for my needs, I didn't look very hard to be honest).
The applier function is called for every CGPathElement in the CGPath, such an element consists of a CGPathElementType and a C-array of CGPoints.
Since a CGPathElementType is an enum with only five different values
enum CGPathElementType {
kCGPathElementMoveToPoint,
kCGPathElementAddLineToPoint,
kCGPathElementAddQuadCurveToPoint,
kCGPathElementAddCurveToPoint,
kCGPathElementCloseSubpath
};
You don't need to write that much code to do (control)point manipulation / inspection of a path. Having the same interface available would've been nice though.

What is scala.mobile supposed to accomplish?

...and why has the package this misleading name (I assumed it had something to do with JavaME or mobile/smart phones)?
I found no references on the internet about scala.mobile.Code or scala.mobile.Location at all nor did I manage to do anything with those classes except getting ClassCastExcetions or NoSuchMethodErrors.
Actually there is not even a single test against scala.mobile in the Scala's test tree which could help understanding that code.
The classes really smell like they were forgotten in the source tree a long time ago and got accidentally released since that.
Maybe I just missed something about them?
Update:
scala.mobile was removed in Scala 2.9.
I just checked the source code.
When Scala changed the name mangling of class files a few years ago and it seems people forgot to update these classes accordingly.
So my answer would be:
At least Location has no purpose, because it is not possible to get anything sensible out of it (except exceptions) and Code without Location is severely limited. It works though if you pass the class literal to Code directly:
import scala.mobile._
val c = new Code(classOf[scala.collection.mutable.StringBuilder])
c.apply[StringBuilder, String]("append")("Foo")
c.apply[String]("toString")() // returns "Foo"
c.apply[Int]("length")() // returns 3
Looks like yet-another implementation in the standard library of reflection-slightly-nicer.
The description of Location pretty much explains what that is about:
The class Location provides a create method to instantiate objects
from a network location by specifying the URL address of the jar/class file.
It might be used by remote actors. Maybe.
As for why it has this misleading name? Well, back in 2004 smart phones had really low penetration, so maybe the association wasn't all that strong.