Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In XNA, when is it appropriate to render your game content using more than one spritebatch? So far I've never used more than one, and have never noticed any downsides to this approach.
In what situations would using multiple spritebatches would be necessary?
There are very few cases in which using multiple SpriteBatches is necessary. One example that I see thrown around a lot is a situation in which you want to apply different post-processing/renderstates to different sets of sprites, which requires a separate SpriteBatch for each set.
It is usually considered good practice to use only one batch if at all possible, since drawing as many things as possible in one batch is much more performant than spreading the work across multiple batches. Additionally, since you can only control sort order within a single SpriteBatch, it may make it harder (or impossible) to control depth between sprites from different batches.
In short: there are conceivable situations in which you may want to do this, but it's not all that common and in general you should stick to using one SpriteBatch unless you know that you can't accomplish what you want without using more than one.
Here is a good example of when to use more than 1 SpriteBatch (Shawn's blog is--as usual--the definitive source).
SpriteBatch doesn't actually do any drawing until you call the End method. That means you can begin several overlapping batches with different settings, draw sprites in any order using any combination of the batch instances, and control what order the entire contents of each batch get drawn by the ordering of your End calls.
Note that this example is about optimizing performance for a scene with alpha-blending and sprites sorted by depth. When (or rather, if) you run into performance problems, there might be something to gain by using multiple SpriteBatches. Until then, you're probably better off keeping it simple.
It also may be easier in cases with DrawableGameComponents to have a SpriteBatch per DrawableGameComponent instead of trying to pass this around.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Say I have a singleton, FruitManager that looks after fruits. It has 3 arrays inside, favoriteApples, favoritePeaches, and favoriteOranges. The singleton can be accessed on any thread where these arrays can be read/written to.
Conventionally I'd use a DispatchQueue here to help the Reader/Writer problem, where I'd allow for concurrent reads but use a dispatch barrier block to make sure only one write action occurs at a time.
My question is, should I have a DispatchQueue for each of the 3 arrays (3 queues total)? Or just 1 dispatch queue for the entire class that would effectively lock writes to favoritePeaches if favoriteApples is being written to?
In answer to the one reader-writer vs one for each collection, it probably doesn’t matter. But there are a few considerations:
The only potential problem with only one reader-writer is that a block on one collection will block them all. So, if you’re doing anything computationally expensive in the synchronization of one or more of the collections, you might want a separate reader-writer for each so it doesn’t adversely affect the performance of the others.
Then again, you never want to do anything computationally expensive with reader-writer pattern, anyway. The “writer” is an asynchronous barrier, so that means that it will block any subsequent “readers” until the write is done. And if accessing the readers from the main queue, that will adversely affect the performance on the main thread (or from wherever you’re reading).
So, if it’s computationally expensive, you wouldn’t use reader-writer, anyway. (You’d probably want an asynchronous fetch method, breaking you out of the reader-writer pattern.) And if you’re not doing anything computationally expensive, then there’s little benefit to using separate reader-writer for each collection.
Setting up multiple reader-writers is fine if the three collections are entirely independent (as your simple example might suggest). But if there are any dependencies between the three collections (e.g. you’re reading from one to update the other), the code as potential to quickly become a mess.
So, bottom line, I’d lean towards a single reader-writer for the whole class for the sake of simplicity. But if you already have a thread-safe collection class that is using reader-writer (or any synchronization mechanism, for that matter) internally, then that it’s probably fine to use that within this class that has these three collections (as long as you don’t have any hairy dependencies between your three collections).
Needless to say, the above applies to any object shared amongst multiple threads, not just to singletons. The fact that you happen to be using using a singleton is irrelevant to the question at hand.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm starting a massive project for the first time. I was supposed to be one of the developers on this big project, and all of a sudden, the lead developer and his team backed out of the contract. Now I'm left managing this big project myself with a few junior developers under me and I'm trying to get a firm grasp on how this code should be broken up.
Logically, to me, the code should be broken up by the screens it has. I know that might not be how it SHOULD be done. so tell me, how SHOULD it be done? The app has about 6 screens total. It connects to a server, which maintains data about all other instances of the app on other phones. You could think of it as semi-social. it will also use the camera feature in certain parts, and it will definitely use geolocation. probably geofencing. It will obviously need an API to connect to the server. most likely more APIs than just the 1. I cant say much more about it without breaking an NDA.
So again, my question pertains to how the code should be broken up to make it as efficient as possible. Personally, i'll be doing little coding on the project. probably mostly code reviews, unit testing and planning. Should it have 1 file per screen, and parts that are repeated should have their own classes? should it be MVC? We're talking a 30k line app here, at its best and most efficient. is there a better way to break the code apart than the ways I've listed?
I guess my real question is, does anybody have good suggestions for books that would address my current issue? code clean was suggested, that's a good start. I've already read the mythical man month and code complete but they don't really address my current issue. i need suggestions for books that will help me learn how to structure and plan the creation of large code bases
As I'm sure you know this is a pretty vague question you could write a book answering it. In fact, I would recommend you read one, like Clean Code. But I'll take a stab at a 10,000 foot level overview.
First if you are doing an iPhone app, you will want to use MVC because that is how Apple has setup their frame work. That means each screen will have (at least) a view-controller, possibly a custom view or NIB.
In addition you will want your view controllers pointing to your model (your business objects) and not the other way around. These objects should implement the use cases without any user interface logic. That is what your view-controller and view will be doing.
How do you break apart your use cases? Well, that's highly specific to your program and I won't be able to tell you with a (lot of) details. There isn't a single right answer. But in general you want to isolate each object from other objects as much as possible. If ever object reference ever other object, then you don't really have an OO design, you have a mess. Especially when you are talking about unit tests and TDD. If when you test one part you end up pulling in the whole system, then you are not testing just one small unit, are you?
Really though, get a good book about OO design. It's a large subject that nobody will be able to explain in a SO answer. I think Clean Code is a good start, maybe other people will have other suggestions?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So I been watching tutorials on iOS development and it seems that every instructor in the video seem to have a good memory for methods in Objective-C which surprises me by the fact that every now and then I am working on a small project and I forget how to call a specific method like to append an NSString or to hide the TabBar from the bottom screen.
An instructor in a video seems to know which method to call whereas I wouldn't even think of calling that same method. For example, when the instructor creates an example iOS app to either leave no spaces in an NSString on a UITextfield, he would use a method that U would forget every often down to even Googling it.
Is it me that my memory isn't great since i am not exposed to methods often or do people study methods in order to fully have them all ready when a certain task should be done?
I feel that my mind isn't fully capable to memorize things like an instructor would with such an ease that it seems he can go by knowing a lot in Obj-C.
How would one get to know more on iOS and be able to memorize method calling without actually having to go to the trouble of trying to memorize them?
Chances are people doing videos have written a script for what they are going to. Including the steps, this is probably why they can recall methods that quickly. It's also something that comes from experience, as you begin to do more and more in Obj-C you will start to learn method names. It's unlikely that most people will memorise ALL of them but that's what the documentation is for + google :-)
Don't worry it'll come. You just need to practice, use xcode autocompletion and built-in doc.
In xcode just hit command + space to get available methods for the leading symbol.
Anyway nobody knows every methods by heart. You'll just end up remembering the ones you use the most.
I would say its impossible to memorize ALL methods, but as you keep coding you keep remembering more and more methods or ways of achieving things. I remember when i was just a beginner and the basic method "removeFromSuperview" was something new to me. In time, you learn much more complicated methods and since you basically use them everyday (if your not copying your code from somewhere) you learn them quite easy. So my answer - in time you can memorize anything but not everything.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I read many articles comparing programming languages.
There is a word that comes often: scalability. I actually tried to look for a simple and clear explanation, but haven't found anything.
Can you explain what the scalability term means?
Scalability is the ability of a program to scale. For example, if you can do something on a small database (say less than 1000 records), a program that is highly scalable would work well on a small set as well as working well on a large set (say millions, or billions of records).
Like gap said, it would have a linear growth of resource requirements. Look up Big-O notation for more details about how programs can require more computation the larger the data input gets. Something parabolic like Big-O(x^2) is far less efficient with large x inputs than something linear like Big-O(x).
Scalability is the trait where a software solution can handle increased loads of work. This can be larger data-sets, higher request rates, combination of size and velocity etc.
When talking about systems scalability, we usually differentiate between
"Scale up" - the ability to grow by using stronger hardware
"Scale out"- the ability to grow by adding more hardware
A solution that can scale out can usually grow to lager loads in a more cost effective way. An important thing to know here is Amdahl's law that states that the ability to scale out is limited by the sequential part of the software
Already great answers here, just wanted to add few things here.
Scalability can be achieved in 2 ways:
Vertical - In this way, you add more hardware like more RAM, processor or more nodes. You also introduce load balancer, which will help in routing the incoming calls to various servers based on the routing algorithm used. The application is now able to handle more load as load is being shared across the servers.
Horizontal - In horizontal scaling, you architect/design the application in such a way that it can behave well in case of more parallel traffic. You check how you are managing the memory, sessions , cache & state etc. If you are using the session to maintain the user information, under heavy load single server could be more busy managing the servers, so in this case you can check possibility of going stateless. It can also respond to incoming requests from same user in parallel instead serial replies which happens if sessions are being used.
My understanding is it means that a linear increase in output requested only demands a linear increase in resources.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I can think of quite a few components that need to be created when authoring a web application. I know it should probably be done incrementally, but I'd like to see what order you usually tackle these tasks in. Layout your usual order of events and some justification.
A few possible components or sections I've thought of:
Stories (i.e. pivotaltracker.com)
Integration tests (Rspec, Cucumber, ...)
Functional tests
Unit Tests
Controllers
Views
Javascript functionality
...
The question is, do you do everything piecemeal? (one story, one integration test, get it passing, move onto the next one, ...) OR complete all of one component first then move onto the next.
I'm a BDDer, so I tend to do outside-in. At a high level that means establishing the project vision first (you'd be amazed how few companies actually do this), identifying other stakeholders and their goals (legal, architecture, etc.) then breaking things down into feature sets, features and stories. A story is the smallest usable piece of code on which we can get feedback, and it may be associated with one or more scenarios. This is what Chris Matts calls "feature injection" - creating features because they are needed to support stakeholder goals and the project vision. I wrote an article about this a while back. I justify this because regardless of how good or well-tested your code is, it won't matter if it's the wrong code in the first place.
Once we have the story and scenarios, I tend to write the UI first, followed by the classes which support it. I wrote a blog post about a real-life example here - we were programming in Java so you might have to do things a bit differently with Rails, but the principles remain. I tend to start writing unit tests when there's actually behaviour to describe - that is, a class behaves differently depending on its context, on what has already happened before. Normally the first class will indeed be the controller, which I tend to populate with static data just to get the UI into shape. I'll write the first unit tests to help me get rid of that static data.
Doing the UI first lets me get feedback from stakeholders early, since it's the UI that the users will be interacting with. I then start with the "happy path" - the thing which lets the users do the most valuable thing - followed by the exceptional cases, validation, etc.
Then I do my best to persuade my PM to let us release our code early, because it's only when the users actually get hold of it to play with that you find out what you really did wrong.