Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 374 375 [376] 377 378 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 903737 times)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5625 on: March 21, 2014, 09:31:37 am »

Well yeah, I don't argue using C++ professionally for things that are outside of it's problem domain. And C++'s problem domain is for things that the 50% below average should really be kept away from anyway. If a business does hire them, then it's their job to teach them to lift them out of the 50% if they want to get something done.

Professionally, I wouldn't use C++ to write a Rest API, and I wouldn't use Java to write an OS. As a hobbyist side-project or proof of concept, sure. But I'd feel incredibly unprofessional if I seriously came to a manager with that suggestion.

As an aside, that keynote speech the video I linked to was taken from is a must-watch. It's quite interesting.
« Last Edit: March 21, 2014, 09:40:33 am by MorleyDev »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5626 on: March 23, 2014, 12:39:00 am »

Friggin d3 (from javascript) is being inconsistent >:I

function foldComment(par) {
    var base = d3.select(par.parentNode.parentNode);
    base.select(".unfoldedComment").style("display","none");
    base.select(".foldedComment").style("display", "");   
}


This bit of code, called on the <p> tags of this structure:

<div class="comment">
    <div class="unfoldedComment">
        <p></p>
        <div class="unfoldedComment">
            //.... many times nested, like Reddit comments
        </div>
    </div>
    <div class="foldedComment">
        <p></p>
    </div>
</div>


does not touch the style attribute of foldedComment at all. It does work on unfoldedComment, but foldedComment is untouched for no good reason. Is there anyone who can help? ;_;

foldedComment display="none" initially. unfoldedComment display= nothing initially.
After the above function is called, they should be swapped so foldedComment display="", and unfoldedComment display="none". But only unfoldedComment changes, while foldedComment's display tag doesn't change no matter what I put into the style() function's second parameter.

Edit: EVEN MORE perplexing is that everything goes as expected only on the bottommost nested comment. Because the comment tree is constructed recursively, there isn't any difference between the first comment and the last one.

edit 2: solved the problem, now have another problem @_@
« Last Edit: March 23, 2014, 07:59:40 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5627 on: March 26, 2014, 11:57:30 pm »

dunno.
I never found a use for a class that also wanted to be an array which couldn't be made more easily and in a safer manner using a plain container (arrays, standard lists, whatever) 
or a wrapper class over a standard container

edit: probably because I am biased to see array more as memory structure than as data structure so having behaviour behind [] makes me uneasy
If you have a container and you need to care about internal implementation details in order to use a simple access operator, you've already started off wrong enough that syntax won't save you no matter what it is.

I would also counter that you should be able to overload operators, as doing so maintains readability and consistency. I've used Actionscript, and that's a language in which you can't overload operators. It's awful.
You want a Vec3 class that can do standard vector operations with? Get friendly with "A.Add(B.Mult(C))" and similar. It ends up being an unreadable jumble of Lisp-like gobbledegook despite only involving common operators which are nearly always represented as operators rather than function even in the math. Oh, and does that code I wrote even compile? I dunno. It could be A.Add(Vec3) is an in-place add that has no return value. It could return the value with no side-effects. Or worst of all, it could return the results of an in-place add. Operator overloads come with implicit terms; which while they may not always be the case, gives a sturdy platform to build from. A + B * C implies that the entire equation is carried out with no side-effects and will return the result of the computation. Whereas A.Add(B.Mult(C)) suggests no such things. Likewise, and this is a somewhat important note, operator overloading maintains Order of Operations. Which does, in fact, mean that all your typical laws of math apply. So A + B * C = A.Add(B.Mult(C)) and not A.Add(B).Mult(C). Which, again, is all about implicit suggestions based on past experience in order to allow someone who doesn't know the implementation details to effectively use it.


@Morley: I believe the proper description isn't "it gives you the tools to shoot yourself in the foot," but rather "it gives you a length of rope." :P

And now something completely unrelated, here's something neat you can do with atomic GPU counters: http://renderingpipeline.com/2012/03/gpu-rasterizer-pattern/
Record and play back the GPU's rasterization process in ultra-slow-mo. With the 2-poly quad render, it's really like "Oh hey, there's the hardware units."

Also another thing; a GDC talk about geometric algebra applied to game development: http://www.terathon.com/gdc12_lengyel.pdf "Fundamentals of Grassmannian Algebra" basically covering quaternions, different types of vectors, different types of useful operations, ect. Worth a read if you want to know about why those weird game math tricks work.
« Last Edit: March 27, 2014, 12:02:31 am by alway »
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5628 on: March 27, 2014, 12:58:34 am »

Operator overloading is yet another feature that is extremely useful, but if misused or abused it leads to massive headaches.

Just follow the Principle of Least Astonishment and you're perfectly fine. For example, don't overload multiplication for vectors because it's very unclear whether you mean the dot or cross product. But please do overload matrix multiplication.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5629 on: March 27, 2014, 01:38:09 am »

Operator overloading is yet another feature that is extremely useful, but if misused or abused it leads to massive headaches.

Just follow the Principle of Least Astonishment and you're perfectly fine. For example, don't overload multiplication for vectors because it's very unclear whether you mean the dot or cross product. But please do overload matrix multiplication.
You should always mean component-wise multiply when multiplying 2 vectors. Dot and Cross products both fundamentally change the meaning of the outputs to entirely different types. As such, dot and cross products should be treated as functions.

Or to be less cryptic: The inner product (dot product) takes the 1-blade vectors and creates a 0-blade scalar; the exterior product (cross product) takes the 1-blade vectors and creates a 2-blade vector: Wikipedia: Blade(Geometry)
It's a fundamental shift from describing a linear value to describing a scalar or an oriented area.
« Last Edit: March 27, 2014, 01:45:13 am by alway »
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5630 on: March 27, 2014, 07:47:38 am »

I found this weird quirk with alpha blending in 3D.

In both Unity and Source, stacking a whole pile of transparent things (~100) at the same point in space causes severe lag when the camera is really close to them and is facing them. When the camera moves away (just a bit) it drastically improves.

I have no idea what is happening.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5631 on: March 27, 2014, 08:58:31 am »

It's your graphics card complaining; Unity and Source use fragment depth sorting for transparent objects, which is quite expensive on your graphics card; and it has to do a depth sort per pixel of screen space those transparent things occupy, which obviously makes your renderer slower the closer you are.
Logged

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #5632 on: March 27, 2014, 02:38:22 pm »

I think I'm starting to get the idea of how methods and class access works. Failing that was what killed my interest last time so I'm pretty happy about this method that works, but there's probably no need to make method for every random event that can happen when they are so similiar.

I currently have about five methods like in this in my program, and its getting pretty big and repetitive fast.

Code: [Select]
static void LaboratoryEvent()
        {
            Console.WriteLine("Noble Thorkud McFilosopher walks to your office." + "\n" + "He wants you to approve his architectural plans for new laboratory" + "\n" + "Approving the plan costs 20 wealth, and it increases happiness by 10" + "\n" + "'y'es or 'n'o?");
            string PlayerEventResponse = Console.ReadLine();
            if (PlayerEventResponse == "y" && Wealth >= 20)
            {
                Wealth -= 20;
                DisasterA++;
                HappinessA += 10;
                Console.WriteLine("The noble leaves smug as ever.");
            }
            else if (PlayerEventResponse == "n")
            {
                HappinessA--;
                Console.WriteLine("The noble leaves disappointed.");
            }
        }
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5633 on: March 27, 2014, 03:31:44 pm »

You could probably take the responses

Code: [Select]
Console.WriteLine("The noble leaves smug as ever.");
and put them into a generic event handler

Code: [Select]
EventApproval(<RESPONSE>,<EVENT TYPE>, [CITIZEN_CLASS])
So that it will approve/reject the stated event, and give a generic response. You can add an extra handler such as the [CITIZEN_CLASS] to further modify the end response printed to the screen, and keep all of the handling of what happens tucked away in a neat little function.

Of course, you have to type out all of what happens in the approval/rejection properly, but it would allow different people types to ask about different projects.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5634 on: March 27, 2014, 11:18:22 pm »

It's your graphics card complaining; Unity and Source use fragment depth sorting for transparent objects, which is quite expensive on your graphics card; and it has to do a depth sort per pixel of screen space those transparent things occupy, which obviously makes your renderer slower the closer you are.
Yep, this. And it's also why a lot of games try to avoid large amounts of transparency; it's one of those really hard problems in graphics programming. http://en.wikipedia.org/wiki/Order-independent_transparency

Edit: Actually, do you have a source about their OIT? Because I'm actually not so sure they do per-pixel sorting, and can't seem to find anything outright stating they do it; I'm only seeing per-object sorting. The per-fragment methods have only recently become practical for real-time rendering, and people reporting buggy unity transparency sorting seems to suggest that if they are using it, they only started in the past year or so.
And in fact, this suggests Source does not do so either: https://developer.valvesoftware.com/wiki/$translucent
Quote
Translucency can sometimes cause a material to flicker, or cause sorting issues with nearby surfaces. In both cases consider using $alphatest instead of $translucent when this happens. It drastically lowers quality, but will usually resolve the issue and is much faster to draw. It will also cast flashlight shadows, unlike translucents. Unlike $translucent which allows for varying degrees of opacity, alpha testing does not - portions of your texture are either 'on' or 'off'.
I also know for a fact that CryEngine doesn't have a solution to it, else our job would be much easier. OIT is one of our big headaches at the moment, particularly in the context of volumetric effects...
So per object sorting, yes, per triangle sorting, maybe, per pixel sorting, I'm thinking there's a good chance of no.
« Last Edit: March 28, 2014, 12:37:56 am by alway »
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5635 on: March 28, 2014, 12:59:59 am »

I couldnt find anything about fragment sorting in Unity either, just object sorting.

Some more testing, it seems to be the ammount of screen filled, not how close the camera is. I tested this by putting the camera in a position where everything was running smooth and scaled it all up. Which seems to be evidence for some sort of fragment thing.

Ugh, transparency in computer graphics is a pain in the ass. Why can't it just magically work somehow :(

EDIT:

I also know for a fact that CryEngine doesn't have a solution to it, else our job would be much easier. OIT is one of our big headaches at the moment, particularly in the context of volumetric effects...

Quote from: Wikipedia
The Sega Dreamcast games console included hardware support for automatic OIT

Go Sega!
« Last Edit: March 28, 2014, 01:06:52 am by alexandertnt »
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5636 on: March 29, 2014, 02:21:00 pm »

Here's a dumb question. Let's say I have a list of lists in python. I can't be sure that any of the inner lists are the same length as any other (in other words, I can't assume it's basically a rectangular array). How can I choose a random item from one of the inner lists in a way that gives me the same chance of picking any item in the entire system? I can't pick a random inner list and then pick a random item from it, since that makes it likelier for an item in a shorter list to appear.

The problem I'm trying to solve, if that helps, is picking random points from a grid, with some arbitrary regions excluded. I've determined that just picking at random and seeing if it's an excluded point, and trying again if it is, is too slow.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5637 on: March 29, 2014, 02:38:15 pm »

Well, the thing I'm going to suggest will probably also be slow, but you could try adding the lengths of the lists togheter into one number, then picking a random number between 1 and the total (or 0 and the total minus one, if you like). Then loop through the upper list, substracting the length of the inner list from the number until the length of the inner list is higher than the number, and then you do innerlist[remainingnumber]
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5638 on: March 29, 2014, 03:31:33 pm »

Alternatively, empty(/traverse and copy) all inner lists into one big list, counting the number of items as you go. Thereafter, bigList[randomNumber] should do it.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5639 on: March 29, 2014, 03:58:58 pm »

Yeah, I was kinda hoping there was a less expensive way of doing it than effectively piling it all into one big list. We'll see how that works out then.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.
Pages: 1 ... 374 375 [376] 377 378 ... 796