Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 681 682 [683] 684 685 ... 796

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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10230 on: November 29, 2016, 02:55:44 pm »

For distance based attenuation, docs suggest you need to put an _ATTENUATION parameter: https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10231 on: November 29, 2016, 03:02:52 pm »

I recall having lighting problems due to how I specified lights in a game I was making, the order of matrix transforms matters.
« Last Edit: November 29, 2016, 03:12:50 pm by Reelya »
Logged

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10232 on: November 29, 2016, 06:53:42 pm »

Hey. It seems that I will have to do some C# - related work (not a lot, just a bit) some time in the future. I can do "hello world"-tier stuff in it, but not much beyond that (I'm usually a Python person). Are there some insights/useful tidbits that you would share with somebody who mostly has coding experience in Python?

This may be too general, but just... like, what should I do or look out for first?
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10233 on: November 29, 2016, 09:10:16 pm »

C# is pretty easy to learn. I got a decent understanding of it by just browsing the tutorialspoint pages on it when I didn't have anything better to do. Just be sure to keep access levels in mind, they're probably the most likely things to trip you up if you're used to Python.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10234 on: November 29, 2016, 09:18:30 pm »

C# is pretty easy to learn. I got a decent understanding of it by just browsing the tutorialspoint pages on it when I didn't have anything better to do. Just be sure to keep access levels in mind, they're probably the most likely things to trip you up if you're used to Python.
Hey, I did those too, with exactly the same motivation. Thank you, though.
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10235 on: November 30, 2016, 12:33:18 am »

The documentation is your friend, too.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10236 on: December 01, 2016, 03:10:04 am »

Speaking of documentation...

Somebody on Newgrounds wants to collaborate with me and asked me to write a player movement script which supports gamepads as well as kb + mouse. Even with just my two USB gamepads, I ran into a problem: no two controllers have the same axes bound to the same thumbsticks. In fact, that sort of consistency seems to be very rare. Unity's built-in joystick support requires you to create virtual controls ahead of time that only ever map to a specific axis on the controller, which cannot be changed after building the final game.

I finally downloaded a script from the Asset Store that had the answer: You can read specific joystick axes just by asking for them with names like "Axis 3", "Joystick 1 Axis 6", etc. using the functions that read the "virtual inputs" from the Input Manager.

This very important feature is not mentioned anywhere in the documentation, not even as a footnote.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10237 on: December 01, 2016, 03:47:36 am »

Pretty sure the input manager is documented pretty well all over the place, assuming you're talking about unity.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10238 on: December 01, 2016, 06:44:58 am »

It's not under the scripting pages for Input, GetAxis or GetAxisRaw, the most relevant pages. It's also not in any of the manual pages about the InputManager nor any of the tutorials.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10240 on: December 01, 2016, 11:15:51 am »

What I needed, and what isn't explained in the manual, is how to programmatically read joystick input without using the Input Manager. With multiple joysticks each having up to six axes (analog triggers), it would be an ungodly mess to try and manage that using the Input Manager. In addition, since it's a WebGL game, the player won't have the pre-launch options window to rebind the gamepad if it doesn't work.

Code: [Select]
void defineControl()
{
        if(Input.GetAxis("joystick 1 axis 3") > 0) // this axis NOT defined in Input Manager!
        {
             yAxis = "joystick 1 axis 3";
        }
}

I'll admit that the manual kind of implies it's possible with this line:

Quote
The names used to identify the keys are the same in the scripting interface and the Inspector.

... but that section was talking about keys and buttons, not axes. While I'll concede that it isn't totally undocumented, it's pretty unclear.
« Last Edit: December 01, 2016, 11:20:33 am by itisnotlogical »
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10241 on: December 02, 2016, 02:31:50 am »

Hey. It seems that I will have to do some C# - related work (not a lot, just a bit) some time in the future. I can do "hello world"-tier stuff in it, but not much beyond that (I'm usually a Python person). Are there some insights/useful tidbits that you would share with somebody who mostly has coding experience in Python?

This may be too general, but just... like, what should I do or look out for first?
Python lets you skip some programming 101 stuff, like telling a program what each variable is, or using all the function headers (private/public/static/ect).  Beyond that, once you know the basics enough to actually read it, C# is similar to Python.

One thing I would point out is that if you're used to Python lists will probably be more familiar than arrays.  Arrays are immutable, which will probably feel restrictive given how much Python lets you abuse its lists.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10242 on: December 02, 2016, 10:31:28 am »

Hey. It seems that I will have to do some C# - related work (not a lot, just a bit) some time in the future. I can do "hello world"-tier stuff in it, but not much beyond that (I'm usually a Python person). Are there some insights/useful tidbits that you would share with somebody who mostly has coding experience in Python?

This may be too general, but just... like, what should I do or look out for first?
Python lets you skip some programming 101 stuff, like telling a program what each variable is, or using all the function headers (private/public/static/ect).  Beyond that, once you know the basics enough to actually read it, C# is similar to Python.

One thing I would point out is that if you're used to Python lists will probably be more familiar than arrays.  Arrays are immutable, which will probably feel restrictive given how much Python lets you abuse its lists.
*the length (and type?  I don't know if Python gives a carp about what kind of variable you're storing) of an array is immutable.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10243 on: December 02, 2016, 12:25:33 pm »

Yeah, you'd use lists if you think the size is going to change. They're in the System.Collections.Generic namespace, along with dictionaries and other sorts of containers.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10244 on: December 02, 2016, 07:38:49 pm »

Use lists when you're adding or removing elements ad-hoc, and the order matters.

If the order doesn't matter, and you know you're never going to store more than "X" items, another thing you can do is use one array of length X, and whenever an item is removed, you over-write that item with the last item of the array, and decrement a "used" counter. That can be a lot more efficient.

Lists are for storing small things, where it's not worth your time to think up something more specific. But they're not very efficient, so they don't scale very well if the data size grows very large, or if you're often searching for specific list elements.

One important performance aspect is that subsequent list items may or may not be adjacent in memory. So if you make a list all at once at the start of your program, it will be fairly efficient. But if there was a separate thread also making a list at the same time, now you have two interleaved lists in memory, which means double the time to access list elements sequentially (it will have to cache twice as much memory to process the same elements from one list).

Also, as elements are added and removed during the program run, it's very unlikely that they'll stay in "correct" order in memory, so performance of the list will gradually decay. Feel free to ignore this if you're making lists < 100 elements, or the entire list is only processed occasionally. But if your entire list of things is being processed every frame, or you have e.g. 100 stars in a gravity sim and they're being processed against the other 99 stars, then nah, lists will be horrible, especially if new simulation elements could be added or destroyed after the start.

One good practice in object oriented languages is wrapper classes for libraries and containers. This will give you the most bang for your buck of most encapsulation choices.

~~~

A core OO principle is single responsibility: one "thing" is responsible for handling one "decision", and it's the only thing that's dependent on that design decision. e.g. say you decided to use Boost's dynamic arrays in your program. Just about the worst possible thing you could do would be to add "boost.h" to every cpp file and scatter Boost code all throughout your program. Now, your boss says "we can't use Boost library for <reason X>, remove all Boost code from the program". Now, to reverse that one decision, you need to change 1000's of lines of code and test various systems, and it's likely things are going to break in unpredictable ways, since you need to do 1000's of changes all at once, and can't incrementally change: it's all-or nothing.

So, a more clever way is to get the boost library, link that into a single cpp file, then make a .h file for that cpp file that makes an interface that only uses selected Boost features in a controlled fashion. After doing that, you'll find that it's quite easy to make your own replacement for the boost features you used, then test that in isolation until it's perfect. you can then roll that out as a replacement for the original feature, and it's more common than not that it's just going to work first try, or if not, the errors tend to be more easy to pin down and explain why they happened. You can also put debug statements into the wrapper layer: they can do bounds-checking, input-output checking etc.

So, similarly, when you make data structures that rely on some specific language feature, wrap them up behind a generic class interface. You'll be able to experiment with different choices much more easily when there's only one class which knows whether you decided to use a List or a Vector.
« Last Edit: December 02, 2016, 08:16:21 pm by Reelya »
Logged
Pages: 1 ... 681 682 [683] 684 685 ... 796