• 13
• 15
• 27
• 9
• 9
• Similar Content

• While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend....

• I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
- Does Unity support such plugins / assets that will fulfill all my above requirements?
- Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
- What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
- How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
- Any assets I could use (for free to try basis in debug) that are relevant for my game?
- Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
• By GytisDev
Hello,
me and few friends are developing simple city building game with unity for a school project, think something like Banished but much simpler. I was tasked to create the path-finding for the game so I mostly followed this tutorial series up to episode 5. Then we created simple working system for cutting trees. The problem is that the path-finding is working like 90% of the time, then it get stuck randomly then there's clearly a way to the objective (tree). I tried looking for some pattern when it happens but can't find anything. So basically I need any tips for how I should approach this problem.
Use this image to visualize the problem.
• By aymen
please any know how can i' calculate the centroid from any number vertices

• Good day sir/maam. I am developing a game for my thesis and im done with multiplayer and plan to start the implementation of AI but i dont know how/where to start. Please give an advice. I am developing it in C# using UNITY.
Im am now collected all pieces that has possible moves but i am stuck on which best move to select. I hope you will help me. This is link explained the game https://en.wikipedia.org/wiki/Game_of_the_Generals

Unity How to detect if an object is the last element in an array

This topic is 3410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm creating a simple object tracking system based on the Enginuity articles, primarily for learning purposes. It uses reference counting and comes with a simple garbage collector. When an object's RefCount reaches zero the objetc is considered dead and might potentially be deleted at any time. If the RefCount is above zero the object is considered alive. The garbage collector works with a dead and live list. Pretty basic. I've got everything working except for arrays. When allocating an array on the heap the address of the first element (the address obtained in an overloaded operator new[]) is added to the deadlist. It is my intention that every object in an array of tracked objects should hold the address of the first object in the array. Whenever an object in the array is alive it increases the RefCount of the first objetc in the array by one. This makes sure that the first object's RefCount (the one checked by the garbage collector) isnt zero when any of the other objects in the array are being used. I use a static variable to hold what type of object is currently being constructed. The constructor then assigns this value to a non-static member var. Since tracked objects may contain other tracked objects within themselves this static variable is actually a stack of variables. Here is my problem: When do I pop MM_HEAP_ARRAY(_TRAIL) off the stack? ie when do I know that the entire array has been constructed? My first idea was to try to retrieve x in an expression "new Object[x]" inside the overloaded operator new[]. operator new[] would then push the value onto the static stack. This would be the easiest approach but to my knowlage it isnt possible (at least without non-portable hacks). Since we do know the size of the block of memory allocted I tried to test for static_cast<byte*>(this)+sizeof(*this)==static_cast<byte*>(start_address)+mem_size This isnt good since I use a TrackedObject base class that others derive from and sizeof(*this) returns the size of the base class, not the size of the actuall object in the array. For those interested, here is another thread where I tried to tackle the problem I'm having a bit differently. It didnt work out. Thanks for any replies.

Share on other sites
Assuming all the array memory is contiguous, couldn't you just subtract the pointer of object 0 from the pointer to object 1 to get the size of the object? And since you know the size of the memory, the pointer to the last object should be sizeofmemory - sizeofobject.

I think new allocates everything contiguously, but I'm not 100% on my pointer arithmetic...

Share on other sites
That would indeed work and I have considered it. The only caveat with this approach is that it is legal (and quite possible if the number of elements to allocate is determined at runtime) for the user to allocate an array of size 1.

If the size of the array is 1 the MM_HEAP_ARRAY on top of the StaticStack would have to be poped in the first elements constructor. At that point there is no way (that I know of, this is the real problem really) to tell if there are more elements after the first.

Thanks very much for the fast response though!

PS
Quote:
 I think new allocates everything contiguously, but I'm not 100% on my pointer arithmetic...

It does so pointer arithmetic is ok

Share on other sites
You could probably just do something like:

(T is just a template type, or whatever type the array is)

int size = 0;T * temp = new T[2];size = &temp[1] - &temp[0];

Every time before you build an array.

In other words just build a 2 element array of the type you want each time, then go ahead and make the ACTUAL array.

Share on other sites
Do you know about Boosts smart pointers?

Your design choices sound a bit awkward. You're building a reference counting system but at the same time you're complicating it with arrays of objects, where only the first object is treated as reference-counted? Why so? What do you really want to achieve here? What practical problems are you trying to solve? Why do you want to use arrays instead of stl containers?

Share on other sites
Thank you for the replies MortusMaximus and Captain P. Unfortunately you seem to have misunderstood the situation Im in.

I am creating an underlying tracking system, how the user wishes to create objects that uses that system is beyond my control. Therefore I have to "complicating it with arrays of objects" since I want the system to be transparent and deal with all different situations.

Also, as stated in the OP, Im doing this as a learning exercice. Therefore Boost is not an option just yet (until I expand to what will become a bigger framework).

The statement that "only the first object is treated as reference-counted" is not entirely correct. All objects are tracked with its own RefCount, the first element is special only in that it represents the entire array in the garbage collector. Since it's the first element that gets delete[]ed, and therefore is responsible for the lives of all the elements, it has to keep track of them.

On a side note, in MortusMaximus example a simple sizeof(T) would do since we know the type T of the objects we want to create. That is not the case for us since we only have controll over and can execute code in the base class.

So Im still stuck Im afraid..

EDIT - I am willing to change my design if anyone has a better idea of how to do this. The system should not impose any restrictions on how the objects can be used though.

EDIT2 - just noticed that the size var in MortusMaximus example would be 1. ie 1 object would fit between the two addresses. This is how pointer arithmetic works, as far as I know. To get the size in bytes you would have to reinterpret_cast to byte* then do the substraction.

Cheers

[Edited by - Thunder Sky on November 15, 2008 11:24:05 AM]