Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

12176 Excellent


About Nypyren

  • Rank

Personal Information

  • Role
  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. It looks like ILMerge is a bit nicer to use lately: https://github.com/Microsoft/ILMerge If I'm reading the last part right, you can perform ILMerge as a build step automatically.
  2. Nypyren

    can 32bit games able to run in 64bit os?

    I can't think of any problems I've ever had with 32-bit EXEs on 64-bit Windows.
  3. https://en.wikipedia.org/wiki/Convex_hull_algorithms
  4. Nypyren

    wait loop

    A "frame" in any system in a game typically means the state or data that is relevant for one moment in time.
  5. Nypyren

    Communism 2.0

    "Even if you do absolutely nothing your whole life and live on the lowest tier, you still get to eat, survive, have healthcare, etc." Let's say everyone does this. Where would the food and healthcare come from? Or, let's say everyone wants to be an artist. But you can't eat (most) paintings. Paintings don't provide you healthcare. It seems like you would need to motivate people to provide a variety of useful goods and services by dynamically changing the amount of points you get based on supply and demand. But that's pretty much how capitalism works. The point system and things you're entitled to get from points sounds a lot like currency!
  6. Get the grid-aligned bounding box of your dynamic object (your player in this case). Convert its min and max coordinates to grid cell coordinates. That range of cells are the only ones you need to test for collisions. If you have block shapes other than just cubes, you can use 'shape templates' (id(s) stored per block - or associated with the block type - which represent what shape it is). You don't need to save the blocks around the player in a second data structure since you can access them from the block grid in constant time.
  7. 0 * 10 + 0 = 0 0 * 10 + 4 = 4 4 * 10 + 1 = 41 Am I missing something? What in the world are you using to parse these numbers? Why are you using floating point? All of the dotted-version-number schemes I've used use four integers. "exact floating point of 0.41" Floating point cannot represent 0.41 exactly. There's a useful tool you can use to experiment with floating point: https://www.h-schmidt.net/FloatConverter/IEEE754.html "You entered: 0.41" "Value actually stored in float: 0.4099999964237213134765625"
  8. Nypyren

    Unity coding error

    In C# you can have variables with the same name as types, and the meaning is taken from the context. In the above code there is a member field with the name 'Rigidbody'. This should work. However, the code above looks like there are too many closing } so the OnTriggerEnter2D doesn't seem to be in the same class. The above code shouldn't compile due to that extra }, but this might just be a copy-paste issue when posting the code here. If the OnTriggerEnter2D is in a different class where the 'Rigidbody' variable is no longer in scope, it will fall back to attempting to access a static member of the 'Rigidbody' type instead, which would explain the error in the original post.
  9. Nypyren

    Unity coding error

    The first error is due to a typo.
  10. Nypyren

    Unity GameObjects arrays

    Last time I used Java, it didn't have custom value types (structs) at all. There were primitive data types (a more limited selection than C#) and classes. I think they're working on adding value types, but I haven't kept up to date on Java since I never use it anymore. Most of the non-C++ languages I've used are closer to how C# works than how C++ works - passing references by default and using garbage collection. As far as I know there's no way to treat a class like a struct in C#. You usually just have to get used to working with references. Once you're used to it, it's not that big of a deal. I believe the reason why C# uses reference types primarily is due to the memory management model: garbage collection. Most of the complex headaches using C++ stem from memory management. Some language designers looked at C++ and decided the amount of control you get wasn't worth the added language complexity and programmer headaches. There are trade-offs. If you need absolute control over every aspect of memory management, you need C++. It's easy to be a 'slob' in garbage collecting languages - your program will work but if you just allocate objects foolishly without any thought behind it, you'll have memory and performance issues. You should be intelligent with allocations in C# just like in C++ but you won't have the same degree of control. As far as avoiding struct/class confusion in day-to-day work, what I do is configure the IDE to color-code all value types red and all reference types blue. That way I can instantly know what a particular variable is going to do when I use the = operator.
  11. Nypyren

    Unity GameObjects arrays

    If you find yourself wanting to copy, that's when you should use structs. The assignment operator for structs copies every single field just like you'd get with a memcpy. HOWEVER, if a member of a struct is a class type, that field will have just the pointer copied. On the other hand, every single "class" uses reference semantics: copying JUST the pointer, not the object being pointed at. It's just like every variable which is a 'class' type also has a C++ * type qualifier on its declaration. The only ways to copy the contents are to manually copy them, or use a struct instead. Sometimes you don't want to copy a struct. In those cases you can pass "pointers" to structs in two main ways: Make the struct the member of a class and pass the class, or use the 'ref' keyword. The ref keyword is basically the & type qualifier from C++, but can only be used in function argument lists. One of the major things you should beware of with structs is combining them with properties. A property works like a method, so a property for a struct will return a COPY of a struct. Collections (arrays, lists, etc) are classes which contain whatever type you declare them with, and the elements use their type's semantics - structs in an array will use copy semantics (assigning a[x] = a[x+1] will copy the whole struct, NOT just a reference). Any class types as an element of an array will make a pointer copy as you've discovered. Arrays themselves are classes, so you cannot copy the contents of an array to another array using the = operator. You have to either loop-and-copy-elements or use Array.Copy functions. Arrays are allocated on the heap by default. There is a way to allocate arrays on the stack with the stackalloc keyword, but you almost never want to do that. In your case of overwriting a[x] with a pointer to a different object, the former object will probably get garbage collected. Garbage collection works by periodically traversing allocated data structures, starting at the stack, static variables, thread locals, etc, and following every pointer. Any object that is traversed is "live" and is not deleted. Any objects that it can't reach by following all of the possible pointers are considered "unreachable" and are automatically deleted. If you had any other reachable variables pointing to the former contents of a[x], that would keep the object alive. There are some surprising cases where you can keep a reference to an object stored for longer than you intended (usually as delegates) and can be considered a "memory leak". There is another alternative to just 'use structs or classes to control copying behavior' - using immutable classes. The common problem with accidentally copying a class is that when you modify it via one variable, you affect anything else referring to it. If you make every field 'readonly', it results in something that behaves kind of like strings do: strings in C# are classes, but you can't modify their contents. So it's safe to copy them freely because you know you can't introduce mysterious bugs because you can't modify their contents. You are forced to create new strings instead. Copies are cheap to perform (because you're only copying a pointer address), but you get the safety you would from the uniqueness of a struct. If you're using Unity and monodevelop can't debug, that will happen if you've switched to the .Net 4.6 runtime. Monodevelop is being phased out. The recommendations are (on OSX) to use Visual Studio for Mac or JetBrains Rider. On Windows, use Visual Studio 2017 (either Community or Professional, depending on whether you're doing commercial work or not). All of these IDEs are vastly superior to MonoDevelop, can debug Unity, and will provide a much better overall experience working with C#.
  12. Just like a complex expression like x * y * z * w is made up of x*y, the result *z, the result *w, you can also chain multiple '.' operators together, or even include other operators as well. As long as the type of one of the sub-expressions isn't void, you can continue applying more operators. SceneManager.GetActiveScene().name.IndexOf('A') + 5; You can even do crazier stuff like return functions and then immediately call them: FunctionThatReturnsAFunction()();
  13. Nypyren

    Unity GameObjects arrays

    Alternatively, you could change MaLoc to a struct, in which case your existing code would work more like C++ where the array really does contain the MaLocs directly. There are other caveats of doing that, though: Passing MaLoc between functions would pass copies rather than pointers (unless you pass using the 'ref' keyword). This could be either good or bad depending on what you need to do with them.
  14. Events and delegates are on par with virtual and interface calls, which means if you want to decouple something, the alternatives are basically the same. If you use a profiler to find bottlenecks, it's unlikely that you'll see events themselves as the cause of any noticeable issue. If you're writing a bitmap processing engine though, it's probably not a good idea to call a virtual method once per pixel in a 2048x2048 texture. That's the kind of place where extra function calls or event calls may actually matter.
  15. In your example, I would have kept them decoupled and used events to let them notify each other. Then use a "higher level" initialization process to combine them. This way the individual classes don't need to know about each other (except for Items, presumably). For example in C#: public void InitSystems() { inventory = new Inventory(); questSystem = new QuestSystem(); logger = new Logger(); inventory.ItemAdded += item => questSystem.OnItemAdded(item); questSystem.RequirementsMet += quest => logger.Log($"Quest {quest.Name} has met all of its requirements."); } HOW I decide to do this is hard to describe. I try to think about what I need and break it into the simplest pieces first, get those working with placeholders in unit tests, then slowly combine the code to make the more complex pieces.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!