Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 26 Feb 2007
Offline Last Active Yesterday, 09:17 PM

#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.



#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.

#5212543 Help, how is this style of graphics made?

Posted by Ravyne on 23 February 2015 - 03:50 PM

Taking it one bit further, you really do want to go full-blown 3D with a fixed camera perspective and orthographic projection these days. Not only was the historically-accurate way of doing this simply difficult for the artists, but tall,large,and overlapping objects or paths were very, very painful to account for on the programming side -- not impossible, but needlessly difficult when the whole issue can simply be side-stepped today by using proper 3D. And it complicates everything, not just rendering -- pathfinding, collision detection, even the simplest of game logic becomes needlessly tangled in the old way of doing it. And as a bonus, when using the full 3D method, you get proper lighting if you want, so things like bump-mapping and parallax mapping and shadows all work seamlessly.

#5212542 blast a solid black circle

Posted by Ravyne on 23 February 2015 - 03:41 PM

By the way, one optimal approach that's easy to adapt to your current code structure would be to leverage the symmetry of the circle to fill entire horizontal spans all in one go.


In this approach, change the second for loop to for(int x = -radius; x <= 0; x++), and then instead of filling a single pixel at that point, fill the entire horizontal line between here and the matching point on the far side of the circle. The point on the far side has an x coordinate of (radius - x). To fill the horizontal line, you can another for loop inside your if statement that fills pixels, where you currently fill just one pixel, and then put a break; statement at the end of your if block to exit the x loop early.


Better still, though, would be to use an optimized span-filler that can write multiple adjacent pixels at once, but it might not make much difference for small circles. You'll get the biggest win by reducing the number of iterations and multiplies; the method I described above does that.

#5212539 blast a solid black circle

Posted by Ravyne on 23 February 2015 - 03:31 PM

google "Circle rasterization" for optimal approaches.


For a naive approach, loop over the entire area of the square that covers the circle you want (Your for-loops are right for this), and fill the pixel whenever its distance to the center of the circle is less than the radius (this is what your if-statement does, it appears correct).


Inside your if-statement, I assume that bullet.x and bullet.y transform the circle from its own space into the world-space, where the bullet is. And I assume that pixel offset is calculating the in-memory address of the pixel (again, this appears correct). But its not clear what the variable ptr is, I assume it to be the base address of the framebuffer. If that's the case, your error is here, because you're modifying it every time you do +=.


Instead of the last two lines, do *(ptr + pixelOffset) = 0xff000000; instead.

#5212535 Is buying assets cheating?

Posted by Ravyne on 23 February 2015 - 03:20 PM

Only you can determine for yourself whether you're cheating, according to your own terms. Unless you're competing in some kind of organized event, there are no such terms and conditions on what you're allowed to do and still call yourself a game developer, besides, of course, making games.


Anyone who claims otherwise is forwarding the no true Scotsman fallacy.