Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ravyne

Member Since 26 Feb 2007
Offline Last Active Yesterday, 10:24 AM

#5214310 Resource Management

Posted by Ravyne on 03 March 2015 - 04:00 PM


So do you claim that singleton patterns are bad habit? I've seen them used many times while viewing engines' source codes.

 

Other's have already addressed it, and I don't want this thread to descend into yet another long discussion of Singleton's pitfalls like so many others have. But since you asked me, I'll defend my position briefly.

 

The single worst thing that the Singleton pattern does, IMO, is that it allows you to feel good about outright ignoring important and often multitudinous dependencies that really ought to be thought about carefully, or at the very least ought to be obvious. The globalness and alwaysness of Singleton allows this to happen, and its facade of OOP-ness fools you into thinking that this state of affairs is A-Okay. Furthermore, the singleness of Singleton allows you to make the dangerous assumption that there will only ever be one, and so your typical singleton object never stops to consider how it would have to be in order for more than one of them to cohabitate the same program; worse, many people who do not understand this actually favor this trait as a way to allow them to "simplify" their task -- and as a result, they implement singletons when they "only want one" right now, and come to regret it later when they find out they actually need two or more -- Singleton as an up-front design pattern should only be considered (end even then, not always accepted) when two instances *cannot* coexist, ever, by reasons or requirements that are beyond your control. And the kicker is that a simple global can be cajoled into providing all the essential properties of a singleton design for essentially zero implementation cost -- With the kind of Singleton people write to feel like good OOP citizens, you actually have to write a bunch of code to participate in all their pitfalls and downsides. Sheesh!




#5214297 Server for Unity game

Posted by Ravyne on 03 March 2015 - 02:55 PM

I've probably over-recommended it in the past for things that other approaches would be better suited, but I think what you want here is a RESTful API, at least as long as other clients don't need to see changes instantaneously (that is, if your design calls for one player being able to upload a map, and for another player to be able to download it sometime soon, but not instantaneously) -- there are things you can do to hasten the turn-around time, but at its core RESTful interfaces support multi-layer caching -- its one of the reasons the internet scales so well, but also introduces propagation delays where you might see a recently-cached version of the content that's older than what might have just changed on the server. When you request a restful resource (via a URL) the request can be intercepted by, say, a chache your ISP runs, and they might respond with something they have stored for that URL, rather than hitting up the actual server for it again. For content that's static, or infrequently changed, this is good -- otherwise Netflix would have ground the internet to a halt long ago.

 

There are lots of good resources on RESTful interfaces, but the basics of the API are that each URL represents a unique resource (a map, in your case), and there is a standard set of built-in http API methods that you can use to get, create (post), update, and delete these resources. Usually, the primary resource (URL) for the thing you're dealing with isn't really the thing itself, but might respond with a list of sub-resources that make up the thing in the form of URLs that represent each sub-resource, or things you can do to/with the sub-resources (you can think of these as members of a class). So, you would request the primary URL, and in the response you would find another URL to update the map data itself, for instance. I forget the official document that defines The acronym HATEOAS describes how to best-use this approach, and its the basis of Atom/RSS feeds, so its a well-proven concept. Also, I may not be saying it clearly, but REST is an architecture, its not a protocol -- as such there are some differences of opinion regarding details of implementation.

 

Azure and other similar cloud providers are one solution that provides a great deal of integration and value -- it has everything you need out-of-the-box. Having never done so before, I wrote a simple RESTful API on azure in less than a day, including all the setup and familiarizing myself with the basic features of azure. Another approach would be a using a host like Digital Ocean or Linode to host a collection of Docker containers that make up sub-services in your server (one for the database, one for blob-storage, one for the REST API, one for a load balancer, etc), with that, you can fairly easily spin up additional resources as you need them. There are third-party solutions for that, but its not all integrated like Azure is. Anyways, the buzzword today is "Micro-services" so you might want to google that.




#5214000 CRPG Pre-rendered Bacgrounds - Draw depth to Z-Buffer

Posted by Ravyne on 02 March 2015 - 01:31 PM

Seems reasonable to me. You can probably even draw all your opaque objects before rendering in your background, which should give you back most of your hierarchical-Z I would think. You'll need to do transparent objects afterwards, though, if you have any.




#5213777 Resource Management

Posted by Ravyne on 01 March 2015 - 06:50 PM


If you try to abstract a manager you will get back to a specialized class no matter what you do. Resource management needs to be fast as well any other module in the engine, and abstracting you're forced to add complexity in your scheme at some point. A lot of engines out there has some kind of asset manager, but the class is still specialized; each resource does not extend an asset.

 

I nearly started reading it wrong the first time, but this is important. You really do not want to have a base resource type that is required to be inherited from. This means there's tight coupling between resources and manager, and also that you cannot use your manager, then, with any existing class/struct or with any primitive type without first writing a wrapper class for it which inherits the base type. This leads to a lot of unnecessary boilerplate -- better would be for resources and their manager to be loosely coupled, then you can readily place any existing type into a properly-specialized manager, or even primitive types. There's no reason your manager should not readily accept, say, std::string, and there's no reason it should be precluded from accepting, say, int or bool types or C-style file handles (which, IIRC, are just integer identifiers), either. Irlan is right, also, about specialization at some point -- Its my experience also that you want separate managers for separate kinds of things (textures, meshes), rather than one uber-manager that holds all resources. You can (and IMO, should) however allow for a manager to manage an abstract type -- eg. one texture manager instead of texture2Dmanger+texture3Dmanager, etc.

 

Also, many people reach to singleton pattern for such managers, but I think this is wrong-headed. Do not allow your design to assume that only one manager of a single resource type (abstract or concrete) exists -- If you design such that many can co-exist, you can choose to use only one and get all the same traits of a system which only allows for one, but you cannot choose to create many if your design enforces only one.

 

Also, everything people have said about the specificity of "Manager" is correct, and I do not think you've clearly defined what your goals are -- Usually, a resource manager implies either a common-point-of-access, resource deduplication, on-demand resource retirement/restoration (for e.g. streaming), pooled allocation, or some combination of these things. It is my experience that each of these properties is best treated as a separate responsibility, and so, is encapsulated into its own class, and higher-level functionality achieved by orchestrating these classes together, either enforced through a higher-level class, or by policy.




#5213563 leave function definition "empty" (c++) ?

Posted by Ravyne on 28 February 2015 - 04:40 PM

I agree that the broader strokes of this design smell funny, I would encourage OP to consider a different line.

 

But, ignoring that for now and dealing with the problem at hand, I think what'd I'd do is make getSpecialItemName a function pointer, and set it to a default implementation. For a game to override this function, what they would do is create their own function with a compatible signature, and then set the getSpecialItemName function pointer to point to their function. This is basically implementing one-off virtual inheritence, though, and if you're implementing this all in C++ (but looks like you're using C, maybe?) you'd be better off just using the facilities provided by the language.

 

If you take this approach, do provide a default function, even if what it does is force the program to exit with an error code (because its an error for the client to call getItemName with an ID that invokes getSpecialItemName when it has not been provided). You could say "If the function pointer is null, then skip it." but then A) you'd have to check at every call site, and B) what would you then return anyways? To be clear, there's nothing preventing client code from setting the function pointer to null, so this doesn't prevent that error, but giving it a non-null default makes later assigning it one an explicit error.




#5213400 Ray vs Sphere Issue

Posted by Ravyne on 27 February 2015 - 04:04 PM

If you don't somehow ignore what's behind you, then you're not dealing with a ray, you're dealing with a line instead -- because ray's are directed, of course.

 

You can do that by culling, or you can do that by accepting all collisions on a preliminary basis, and then rejecting all but the nearest non-negative collision (or nearest negative, I suppose, depending on whether your frame of reference looks in a positive or negative direction down the axis). But, you need to preserve the signedness of the distance then, if you just have distance it's always positive, you can do a simple half-space test against a plane through your ray origin, and perpendicular to its direction.




#5213184 Will game maker hurt me in the long run?

Posted by Ravyne on 26 February 2015 - 02:31 PM


If you are serious about making games, you will not find it as a credential for getting a games job. I believe Game Maker is a purely hobbyist tool.

 

If your resume says, effectively, "I once made a game no one knows about in game-maker, download it here to see how unpolished and buggy it is." then yes, its not a very effective credential. Nor will it ever be an effective credential if your aim is to become a graphics or engine programmer.

 

If, on the other hand, you can show that you brought to completion a highly-polished, relatively bug-free game that at least the people who've played it seem to enjoy, even if there's not all that many of them, then that's an excellent credential for many roles in the games industry. Not the only one you need, most likely, but it makes a positive note on one of the most crucial credentials -- the ability to make and ship something complete and polished, and possibly to take and implement user feedback.

 

Fully 60% of the top-grossing mobile games are made in Unity, which is not very far removed from GameMaker -- I daresay that anyone who can make a very complete and very polished game in GameMaker is fully capable of wielding, or learning to wield, Unity very effectively.




#5213180 Non-Member Functions Improve Encapsulation?

Posted by Ravyne on 26 February 2015 - 02:17 PM

I think your confusion is that what you now understand to be a synonym for 'encapsulation' is that you have a class, and inside it you have all its data and operations -- this satisfies a goal of encapsulating the class's internals from the outside world, and that's indeed a good thing.

 

This is "encapsulation 101" so to speak, which is the view that every class is an island unto itself.

 

 

But what you might notice in some of the member functions of your class, is that you might have several of them that are (or could be) purely implemented in terms of other members of your class's public interface (both member functions and member variables). When you have such a function that could be implemented in terms of existing public interfaces, but you instead make it a member, now that function has access to all the protected and private members that it doesn't need to do its job -- while this may seem innocuous at first, often the members and variables that are marked protected or private are marked so because they're either a shared utility (in which case, your member that could be implemented as a non-member doesn't need access), or they're involved in the internal book-keeping of the class (in which case, its dangerous to give that kind of power away to any member who doesn't need it.) In short, even though your non-member-candidate is comfortable being a member, this decreases encapsulation by granting it powers and access that it does not need to to its job.

 

This is encapsulation 201 -- Here, encapsulation is viewed to mean that any code construct, all the way down to single functions, should strive to have only the minimum powers and access that it needs to perform its job. This transforms your job as a class designer from someone who blindly puts all the related parts and functions into the same bag, to someone who considers all the parts and functions that are needed, and then chooses the minimum set of parts and functions that can be put in the bag for which the others can be implemented in terms of what's in the bag.

 

This may seem like a somewhat academic exercise, in which you are erecting walls to protect yourself from self-sabotage, and you are. But it is not academic -- as one example of a benefit, should you ever find a bug in your non-member and you know that your public members do not misuse the private and protected ones, you can instantly narrow your search, based on the fact that you know it cannot access those protected or private members.

 

You are right though, that just making everything a non-member does not achieve encapsulation if as a result you simply take parts of the interface that should remain private and make them public so that you can access them via non-members (as in Getters and Setters, or simply making more members public). That is the opposite of encapsulation. A well-encapsulated class strives for its members to represent the smallest reasonable (that is, it may not be the absolute minima, but a minima tempered with pragmatism) interface that provides for its entire interface and general uses to be provided for.




#5213002 How do I know if I'm an intermediateprogramming level?

Posted by Ravyne on 25 February 2015 - 08:06 PM

 

I believe in you. You can do the thing.

I'm going to frame this and hang it over the office door.

 

I can't take credit -- there's a meme.

 

tiny-potato.jpg




#5212975 Why do games not have items 'one sale' in their stores

Posted by Ravyne on 25 February 2015 - 04:21 PM

 


does it really offer better gameplay?

I think this is the key question here. Especially for single player games the in-game economy is anyway hard to balance. Player must be willing to buy things in shops and have enough money to buy the things he wants. But he can't have enough money to buy everything.

However even with this conditions sale may be also source of frustration if expensive item he just bought goes on sale the next day or if such item doesn't go on sale despite waiting a lot of time.

The point of sales in real economy is only to stimulate income for shop. In-game sale for in-game currency doesn't have such goals - it is only to make player spend money, but how it could improve the gameplay?

I think any balance negatives could be mitigated by only having sales on consumable goods, and "common" or lower-level non-consumable goods like weapons and equipment. That way, no one's going to be miffed that they just spent 10,000 gold on the Sword of Burning and finding it 20% off the next day. Instead, the player gets choices like "Pheonix Down is only 400GP today, maybe I put my plans on hold to buy a few now, and go grind a bit more for Sword of Burning" -- its a small choice, but a meaningful one with balanced downsides and upsides; such choices are almost always interesting gameplay.

 

As for why seeing this is so rare, I have to think that its just because the notion of how video-game shops work was embedded into our subconscious back when adding even one more simple choice would cost valuable ROM space, or just effort. Or, particularly, most early games with shops were RPGs or borrowing RPG elements, which extend from Pen and Paper games -- no sales in Pen and Paper games, either :)




#5212965 How do I know if I'm an intermediateprogramming level?

Posted by Ravyne on 25 February 2015 - 03:22 PM

 


I asked this question, because I see often in books: "You need to have an intermediate level of programming knowledge"

Well, that is a very different question than the answers above are aimed at.

 

From that perspective, I'd say that it sounds as if you are at a stage where books aimed at "intermediate" programmers will be useful to you.

 

 

Agreed. For books, "intermediate programmer" seems to most-often mean "has basic programming competency, or more", the books say this because they aren't going to expend pages teaching you how to program from the ground up. The book is a 200 or 300-level course, not Programming 101. In the end, all you need to tackle most subjects is a willingness and drive to learn, to self-identify gaps in your knowledge and fill them on your own if needs be.

 

 

In a separate rant not solely directed at OP here -- What's with all the permission-seeking anyways? This forum is over-run with questions of this stripe in every topic. Permission to use this language or that language. Permission to use this library or that library. Permission to make this game or that game. Permission to read this book or that book. Permission, Permission, Permission.

 

Stop asking for permission and just go do stuff! Ask for advice, direction, opinions, help -- but enough with the permission already. Based on that advice, direction, opinions, help, and most importantly your own honest self-assessment, do what you think is best for you. By definition, you have to over-reach to learn just about anything at all that's worth learning -- no one ever got smart by being satisfied that they were already smart enough. Comfort is the enemy of progress, Challenge is its ally.

 

What's the worst thing that could happen by picking the 'wrong' book? You might have to read it more slowly? You might have to read it twice? You might have to put it back on the shelf for awhile, and go learn about the things attempting the book made you realize you don't know? I don't see anything resembling a failure here.

 

I believe in you. You can do the thing. 




#5212820 How do I know if I'm an intermediateprogramming level?

Posted by Ravyne on 24 February 2015 - 07:19 PM

Said most simply -- You're not 'intermediate' until you know exactly why you're not yet an expert.

 

Kidding aside, though, you're not an intermediate programmer in any language just by ticking things off a list. If there's any meaningful definition at all--and its very likely there is not--its probably something that requires both a working (but not expert) knowledge of all aspects of the language, and a body of experience using that knowledge to solve real, non-trivial problems in defensibly elegant ways.




#5212819 blast a solid black circle

Posted by Ravyne on 24 February 2015 - 07:10 PM

Specifically, it looks like you want this function, Ahmed.




#5212799 Is it time to upgrade to Dx11?

Posted by Ravyne on 24 February 2015 - 05:16 PM

Might want to hold off a bit if it isn't a major issue yet; DX12 will bring another major API shift and with Win10 going 'free' for anyone with Win7 or Win8 it could well get a lot of traction.

 

For very experienced developers, hobby or otherwise, I think this advice rings true. But I'm no so sure for less-experienced devs, or those who don't care about ultimate performance at the cost of dealing with the much-more explicit model of D3D12. I think ultimately there will end up being an "easy mode" API that puts the training wheels back on Direct3D 12 for those who want a simpler model and don't need unfettered performance, but as far as I've heard, no such thing is coming immediately, and Direct3D11.x will sort of serve that role in the meantime.

 

And as Hodgeman suggests, the best thing to probably do now is to use D3D11 in a way that prefers the constructs and patterns that'll stick around in the new world order.

 

 

That said, there's probably a balance to be struck, too -- We all know the hoops one must jump through in old-world Direct3D to make a scene look good in only a few thousand draw calls (and etc.), and I think there's a case yet to be made whether dealing with the newly-explicit threading models and synchronization issues (+more)of D3D12 are a greater or lesser headache than that in the long run. But at least for the immediate term D3D11 (and 9, even, if you want to target Asia) makes a lot of sense until everyone is on Windows 10, and that will give more-experienced, early-adopters of Direct3D 12 time to figure out what best-practices are for the less-experienced to follow.




#5212737 Getting Destroyed in Programmer Screeners

Posted by Ravyne on 24 February 2015 - 11:42 AM

just a couple general observations:

 

You really do need to be good at matrices and vectors. And at least have some familiarity with Eulers, concepts like gimbal lock, and quaternions.

 

Matrices and vectors underpin most of the kind of math you're going to encounter in everyday tasks -- you need to be able to scratch out some problems on the back of a napkin or whiteboard these things. Its not just about programming, its also about being able to communicate effectively with your peers.

 

Second, keep in mind that part of the way people evaluate you is to see where your limits are. One strategy for interviewing people is to just keep asking deeper and deeper questions until the candidate sinks. Its great if you can complete everything, and you should always make an attempt, but you probably shouldn't feel as though you have to solve every problem correctly before sending it back. But always show your work and thought process, even if you only get part way or come to the wrong answer; a wrong answer with reason is better than the wrong answer on its own, and its often no worse than the correct answer on its own (which right or not, doesn't tell anyone about how you solve problems).

 

 

Overall advice: These are not quizzes like you remember from school. The point is not to score 100%, its for the interviewer to attain insight into your skills, knowledge, working practices, and sometimes personality. Always try to have your positive traits shine through, even when you get stuck not being able to provide the correct answer. Most places would rather hire the humble, hard-working, but fallible human than the silent, unattainable genius.






PARTNERS