Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 171 172 [173] 174 175 ... 796

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

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2580 on: June 24, 2012, 12:01:53 am »

I tend to make drivers that control dynamically created objects. Even if I forget to delete something, the garbage collection routines can clean it up during loading screens or whatever, since the driver class has control over everything that exists.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2581 on: June 24, 2012, 12:19:36 am »

I've a question about C++ and dynamic memory: I've been thinking that whenever there is a "new" somewhere in the code, there should always, always be a "delete" or "delete[]" somewhere else. Is this a reasonable guideline?
Yep. And the easiest way to detect when you haven't cleaned up your memory after yourself is to watch your program's memory usage for memory leaks with task manager or similar. If it is consistently using more and more memory when it shouldn't be, you know you forgot to clean up something. Usually it's best to put in the deletes immediately after putting in the news.

Also of note, the OS will typically clean up anything you forgot upon the program exiting; though relying on this is typically considered bad form. So if you forget one or two things along the way, it's not really the end of the world so long as they only occur once or twice during the course of the program running and so long as you don't plan on releasing the program to the general public. Though it's still bad form akin to programming without a beard.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2582 on: June 24, 2012, 02:05:14 am »

Thanks! You are all awesome people.

Also of note, the OS will typically clean up anything you forgot upon the program exiting; though relying on this is typically considered bad form.

Your use of the word "typically" frightens me. At times, I have not turned off my computer for months at a time. If I'm always launching and exiting a program that has lots of memory leaks, will the OS always clean up after the program, or...?
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2583 on: June 24, 2012, 02:23:47 am »

It *should*.

But like anything in computers that *should* be doing something, qualifiers such as "sometimes" "whenever" "always except on a blue monday" exist. You should be fine, if you haven't noticed any slowing down you *should* be fine :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2584 on: June 24, 2012, 03:22:15 pm »

Hehehe. I've been thinking about a good way to create binaural recording-like sound on the fly without HRTFs. HRTFs essentially being a big database of how to change sound incoming sounds to make it sound like a binaural recording. The problem with those is they are effectively static; they are compiled from data obtained by testing in a sound lab, rather than being effected by the environment in which you want the sound to be.

So my though process went like so:
"Hmm... a method akin to ray tracing would be good, as it takes into account global effects like echoes; but it needs to be continuous rather than discrete, as sound travels in waves."
"Ah, but they do for the most part reflect at the same angle as incidence... which means by positioning a new source behind the object at the same distance as the original source and propagate in a sphere within the reflective frustum from there, you would get wave reflection!"
"Which I guess would make it frustum tracing."
*Googles 'frustum tracing'*
First result:
http://www.youtube.com/watch?v=3aqSB-Ocr04
http://gamma.cs.unc.edu/SOUND/

Bingo. :D

Turning it into binaural then requires adding a second listener for the other ear (trivial), inserting a vaguely humanoid model for proper obscuring of the sound, and done. Though, granted, I probably won't have time to implement the part they did, let alone turn it into a full program capable of being called binaural. But ah well; still fun to think about.

It *should*.

But like anything in computers that *should* be doing something, qualifiers such as "sometimes" "whenever" "always except on a blue monday" exist. You should be fine, if you haven't noticed any slowing down you *should* be fine :)
Yeah, a little of this. But mostly it's referring to the variety of OS itself. Develop for Windows or Mac, and you will probably be fine. Someone running the Linux Extreme Esoteric Edition that they and their buddies modded themselves might have problems; or just someone running a version of a major OS who has a particular version with a particular bug that causes it to not clean up programs on very rare occasions. Which is why it's a case of being bad form, rather than "Save the memory, Save the world." It's just one more thing which could save you from having to sort through the really really weird bug reports.

Though looking at a stackoverflow question asking about it, a second reason is brought up: depending on what sort of tools you use, you (or someone working with your code) may or may not have one for detecting memory leaks in your arsenal; and it may or may not detect and count un-freed memory left to be freed by the OS as a memory leak. Which on its own isn't harmful, but will make finding real memory leaks amid the clutter of memory leak reports more difficult for you/them. Sort of like why you clean up compiler warnings despite knowing they are entirely benign.
« Last Edit: June 24, 2012, 04:13:20 pm by alway »
Logged

Lord Dullard

  • Bay Watcher
  • Indubitably.
    • View Profile
    • Cult: Awakening of the Old Ones
Re: if self.isCoder(): post() #Programming Thread
« Reply #2585 on: June 24, 2012, 04:28:47 pm »

I wanted to link this up. Very interesting article on HPA (hierarchical pathfinding algorithms):
http://aigamedev.com/open/review/near-optimal-hierarchical-pathfinding/

Quite a cool improvement over common A* pathfinding. I'd been considering writing something similar up for a while, but this has helped to cement the approach I think I'll be using.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2586 on: June 24, 2012, 08:57:08 pm »

Spoiler (click to show/hide)

It's always annoyed me how the sound positioning in first-person games is always crap. If an NPC is two floors above me, I can somehow hear their footsteps perfectly clearly. If anyone fires a gun in Counter-Strike, I know exactly where they are. And yet people spend hundreds of dollars on surround sound setups.

That looks amazing. Hopefully this technique will eventually become standard for all FPSs. Wait, that video is from 2009... Damnit game developers, stop spending money on better graphics. The graphics equivalent of today's sound is like having unshaded, untextured models.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2587 on: June 24, 2012, 11:07:43 pm »

Spoiler (click to show/hide)

It's always annoyed me how the sound positioning in first-person games is always crap. If an NPC is two floors above me, I can somehow hear their footsteps perfectly clearly. If anyone fires a gun in Counter-Strike, I know exactly where they are. And yet people spend hundreds of dollars on surround sound setups.

That looks amazing. Hopefully this technique will eventually become standard for all FPSs. Wait, that video is from 2009... Damnit game developers, stop spending money on better graphics. The graphics equivalent of today's sound is like having unshaded, untextured models.
That bolded text is actually precisely the reason for it; or at least a very large part of it. You see, something they don't tell you about those several hundred dollar surround sound setups is this:
They are inherently, irreconcilably flawed by their very nature. You simply cannot get the quality sound required. You can get some directionality, but it is effectively limited to crap 2 dimensional effects. The reason for this from what I read is because of both the varying distances from the speakers combined with interaction of the sound with the room the listener is in. Effectively you get sound effect -> environmental interaction -> HRTF -(speakers)>environmental interaction(room) ->HRTF(listener head) rather than simply sound effect->environmental interaction->HRTF->headphones.
So, in reality, so long as the headphones aren't so crappy as to not work properly, they will be capable of superior effects to surround sound; as evidenced by some of those binaural recordings like virtual barbershop.
Or at least, that's what I read online from biased sources who may or may not entirely know the truth; so take it with a hefty grain of salt. There was some talk of consoles being partly responsible due to their mostly non-use of headphones as well as rumblings about Creative monopolizing and killing off sound cards, but there seemed to be too many axes to grind in those directions for me to put much trust in those accounts.

Though the other big reason is one of performance; particularly regarding global sound interaction like that in the paper. They were getting "4-20 FPS" using a high-end modern multicore computer, doing nothing else but some very simply polygon rendering. For games, that's pretty much unacceptable.

That said... a high-end multicore processor from 2009 is a joke compared to a particular thing which could be use to make this run in real time in a potential game environment, even after adding a second listener and HRTF-y stuff.... Though it still would heavily constrain possible graphics. That method would be to use GPU processing; which is what I'm considering doing if I find the time (I won't, let's be honest here :P). By offloading such an embarrassingly parallel algorithm to a modern GPU's hundreds of cores, it could probably be made feasible for a game with limited graphical scope (as the GPU would be busy doing soundy-things).

The problem with sound is its absence from pretty much any discussion. Even at RIT, which is ranked #6 in the US for our undergrad Game Development department, there's been hardly a whisper about sound in our coursework in the undergrad program (though the grad program, ranked #2, does have a track which goes into sound specifically if you so choose). So yeah... It just isn't really a priority.

Though considering that paper is from '07, you shouldn't expect many games to use it. 5 years is actually a really short time to go from research paper to game in most cases. Usually it goes: "Hey! We just figured out something neat!" *5-20 years later* "Hey! By optimizing this and using the latest technology to do it exclusively, we can get it to do that neat thing in real time(note: real time is defined as 12FPS or higher)!" *2 years later* "By building on this previous paper, we have implemented this with further optimizations which make it doable in real time so long as you aren't doing much else!" and so on. Take for example Finite Element Method. That was around for half a century before being used in games; and even now it's still only starting to hit its stride in games with things like this: http://www.youtube.com/watch?v=A4aTyC2Ru_Y Processing speed is the name of the game when it comes to making games.
« Last Edit: June 24, 2012, 11:30:56 pm by alway »
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2588 on: June 25, 2012, 06:31:47 am »

Fantastic wall of text, Alway. I love reading stuff like that. All those links were awesome.


Anyway, I have yet another complex question about the basics of C++.

Code: [Select]
class Thing{

// stuff

};

Thing one;

int main(){

Thing two = Thing();

one = two; // this here

}

What exactly happens at the commented line? Does one reference the same thing as two? Or does it create a copy or something?
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2589 on: June 25, 2012, 06:33:12 am »

One becomes a copy of Two (assuming no wackiness with copy constructors). You can't have two objects point to the same data; that's what pointers do.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2590 on: June 25, 2012, 07:07:25 am »

That actually keeps tripping me up, lately. I'm so used to variable and pointer being identical that it fields weird to have to explicitly declare them. The implicit creation of new stuff on assignment just feels odd.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2591 on: June 25, 2012, 07:11:12 am »

That actually keeps tripping me up, lately. I'm so used to variable and pointer being identical that it fields weird to have to explicitly declare them. The implicit creation of new stuff on assignment just feels odd.

I see what you did there.
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2592 on: June 25, 2012, 07:15:37 am »

The opposite tripped me up with Python not long ago; I wanted to copy a bunch of data and started wondering why modifying one variable started affecting a dozen others :X
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2593 on: June 25, 2012, 10:59:36 am »

I kinda feel like writing up a post called C++ Is Not Java, with a bunch of examples of important differences.

But it probably won't happen.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2594 on: June 25, 2012, 11:16:29 am »

Which way does job do it? Is that a pointer-by-default language too?

Actually, I vaguely remember Java being a bit... inconsistent about its rules in regards to things like that...
Logged
Pages: 1 ... 171 172 [173] 174 175 ... 796