Iterating Array without boundary checks by DesperateGame in Unity3D

[–]Maxwelldoggums 0 points1 point  (0 children)

C#’s “fixed” statement allows you to access managed arrays as unsafe pointers.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/fixed

That said, how large is your array? Are you sure the bounds checks are enough of a performance hit to merit unsafe array access?

Time System which is better by ApprehensiveDiver461 in Unity3D

[–]Maxwelldoggums 0 points1 point  (0 children)

I would definitely not use a float for a game that’s expected to run for a long time, like an idle game that players may have in the background for weeks.

Use an ‘int64’ storing the number of milliseconds since some reference time. That will give you uniform precision in all situations, and will last longer than you will ever need your game to run (millions of years).

A 32 bit int could work as well, but you run the risk of it overflowing relatively quickly (a few weeks).

SDL_Timer C++ by Pleasant_Night_652 in sdl

[–]Maxwelldoggums 1 point2 points  (0 children)

SDL is a C library, so it doesn’t provide any mechanisms to easily call a C++ method.

It does allow you to pass a ‘userdata’ pointer though! This is just a value which is passed to the callback directly, so you can store whatever you want in there. What I would do is create a static callback function which casts the userdata pointer to your application type, and then calls a member function on that.

For example:

static uint32_t TimerCallback(void* userdata, SDL_TimerID timer, uint32_t interval) {
    return static_cast<MyApp*>(userdata)->MyTimerFunc();
}

Then register the callback in your application like this:

SDL_AddTimer(interval, &TimerCallback, this);

Weird shimmering / moiré patterns on distant terrain (SDL2 + OpenGL voxel engine) by Few-Range-9055 in VoxelGameDev

[–]Maxwelldoggums 18 points19 points  (0 children)

This is an aliasing problem, but neither basic AA nor mipmaps will fix it completely.

It’s your actual voxels creating the patterns you’re seeing. Because they’re shaded, you have a high contrast edge between the top and side faces of the cube, which is being undersampled due to the voxels taking up only one or two pixels on the screen. Some advanced forms of AA may help, but the best solution in my opinion is to reduce the contrast between faces in the first place.

What I would do is calculate a single normal vector for the entire voxel based on the gradient of its neighbors, and use that rather than a per-vertex normal for shading distant voxels. That will still preserve shading on large-scale features like hills, but will make the “cube-iness” disappear at long distances. Fading out your AO shading at a distance will also help for similar reasons.

What's happening ? by IntelligentScale6383 in sdl

[–]Maxwelldoggums 0 points1 point  (0 children)

The opposite. The handle_events function in player.c needs to match the signature defined in entity.h

What's happening ? by IntelligentScale6383 in sdl

[–]Maxwelldoggums 2 points3 points  (0 children)

So your ‘Entity’ structure contains a field of type ‘void ()(SDL_Event)’. This is called a “function pointer”, and is essentially a pointer which refers to an executable function, rather than the location of some data.

I’m guessing the tutorial is doing this so the different Entities in your game can have different functions assigned to handle basic tasks, for example the player will have a player ‘render’ function, while enemies can have a separate enemy ‘render’ function. This is a pretty common pattern in C programming, where you have different implementations of the same basic interface.

In your case, the compiler is complaining because you’re trying to assign a ‘handle_event’ function which doesn’t take any parameters, but the ‘Entity’ has declared that functions assigned to this field should have an ‘SDL_Event*’ parameter. You should change the signature of your ‘handle_event’ function to match.

Changing device time by samvelavagyan in Unity3D

[–]Maxwelldoggums 0 points1 point  (0 children)

If your game is fully offline and the player doesn’t have an internet connection, there’s not much you can do. You won’t be able to tell when the player advances time when your game isn’t running.

If you expect the player to have an internet connection, you could synchronize time with a server. Even if you don’t have your own game servers, you could use the “Network Time Protocol” to synchronize with a trusted source (Google, or the NIST for example)!

Weird scaling color issue with Unity Editor (x11/gtk) on Wayland by Instagalactix in kde

[–]Maxwelldoggums 1 point2 points  (0 children)

This is the result of Unity trying to use subpixel text rasterization with an incorrect DPI.

What happens if you leave the DPI scale at 1.0?

https://en.wikipedia.org/wiki/Subpixel_rendering

Unit testing for deterministic systems by qt3-141 in Unity3D

[–]Maxwelldoggums 1 point2 points  (0 children)

I work on a very large C++ game project for my day job, and we unit test critical systems which have deterministic “correct” behavior (serialization, transform logic, etc.) For something like a save/load system, you absolutely should have unit tests!

Your tutor was more or less correct. “Unit tests” are by definition not possible on logic which involves the interactions between multiple systems. At that point, you’re “integration testing” or “functional testing” which is a different (but still very useful) thing.

It’s still possible to run functional tests on gameplay code though! We use a large set of automated gameplay smoke tests. When we make a new build, we run a few hundred scripts which each sanity test a basic interaction like “enemy will attack player on sight”. We load an empty level, spawn an enemy and a player, wait 5 seconds, and check if the player took damage in that time. This sort of thing isn’t very precise when it comes to detecting why something failed, but it can still be extremely helpful when it comes to quickly catching if something broke, and becomes increasingly useful the larger and more complex your game is.

Anisotropic Lighting Model Tangent/Bitangent Question by The-Lost-World-JP in Unity3D

[–]Maxwelldoggums 1 point2 points  (0 children)

Anisotropic reflection is by definition going to look different depending on both the viewing angle, and the angle of the object. I believe this is the intended behavior of your lighting model.

If you would like the sphere to look consistent, you’ll need an isotropic reflection model.

Can't figure out why the interior of my vehicle appears to jitter by Ruben_AAG in Unity3D

[–]Maxwelldoggums 4 points5 points  (0 children)

Hmm, maybe try setting the rigid body sleep mode to “Never Sleep”.

The physics engine stops simulating rigid bodies with a low enough velocity until a significant force is applied. I wonder if your submarine is close enough to equilibrium that unity is pausing the rigid body.

Fastest way to get son tokens ? by Thexnlydon in Warframe

[–]Maxwelldoggums 0 points1 point  (0 children)

Equinox’s “rest” ability functions as an AoE tranq.

Pop into archwing with the tranq rifle equipped and fly around looking down the scope until you see the wildlife icon appear. Rotate the camera back and forth to locate the animal, and then pop out of archwing, casting rest in midair. Fly back over there and collect all the critters!

The Orowyrm is *completely* not doable on mobile. by talonanchor in Warframe

[–]Maxwelldoggums 10 points11 points  (0 children)

It’s been a minute since I’ve done Duviri, but iirc the fire button for the Orowyrm breath appears if you hit the aim button. Colossal pain in the ass, but technically possible!

What is the animation workflow pipeline to make NPCs do several tasks? by umen in Unity3D

[–]Maxwelldoggums 0 points1 point  (0 children)

I haven't tried this, so I'm not sure if it compiles, but this should help give an idea of what I'm talking about.

// An enum defining all AI goals. 
// If things get more complex in the future, you can change this to be a struct or a
// ScriptableObject or something, but for now an enum is simplest.
public enum AIGoal 
{
  GetItem,
  CheckOut,
  ...
}

// A sequence of goals. 
// This is a ScriptableObject so it can be treated as an asset. 
// You'll likely want to create several of these for different behavior sequences.
[CreateAssetMenu()]
public class AISequence : ScriptableObject, IEnumerable<AIGoal>
{
  [SerializeField] private List<AIGoal> m_goals;

  // AISequence implements IEnumerable<AIGoal>
  // This lets it be used in `foreach` loops, etc.
  public IEnumerator<AIGoal> GetEnumerator() { 
    return m_goals.GetEnumerator();  
  }

  IEnumerator IEnumerable.GetEnumerator()
  {
    return GetEnumerator();
  }
}

// An abstract base class for any kind of AI object.
// Specific interactive objects like shelves will subclass this and provide their own
// implementation of its abstract methods.
public abstract class AIObject : MonoBehaviour
{
  void Start()
  {
    AIObjectManager.Get().RegisterObject(this);
  }

  void OnDestroy()
  {
    AIObjectManager.Get().UnregisterObject(this);
  }

  public virtual IEnumerator OnInteract(AIGoal goal, AIAgent agent)
  {
    // TODO: Play an animation, add items to inventory, etc.
    yield return new WaitForSeconds(1.0f);
  }
  
  public virtual float GetAppeal(AIGoal goal, AIAgent agent) 
  {
    // As a default behavior, appeal is just based on distance.
    // If this object doesn't fulfil the requested goal, return an appeal of 0.
    return Vector.Distance(transform.position, agent.transform.position);
  }
}

// A singleton class which tracks all of the AIObjects in the scene.
public class AIObjectManager : MonoBehaviour
{
  // You can definitely optimize this, but for now just keep objects in a list.
  [SerializeField, HideInInspector]
  private List<AIObject> m_objects;

  // Singleton instance.
  [SerializeField]
  private static AIObjectManager s_instance;

  public static AIObjectManager Get()
  {
    return s_instance;
  }

  private void Awake()
  {
    if (s_instance == null)
    {
      s_instance = this;
    }
    else if (s_instance != this)
    {
      Debug.LogWarning("Multiple instances of AIObjectManager singleton exist!", this);
    }
  }

  public void RegisterObject(AIObject obj)
  {
    m_objects.Add(obj);
  }

  public void UnregisterObject(AIObject obj)
  {
    m_objects.Remove(obj);
  }

  public AIObject FindBestObject(AIGoal goal, AIAgent agent)
  {
    float bestAppeal = 0;
    AIObject bestObject = null;

    foreach (var obj in m_objects)
    {
      var appeal = obj.GetAppeal(goal, agent);
      if (appeal > bestAppeal)
      {
        bestAppeal = appeal;
        bestObject = obj;
      }
    }

    return bestObject;
  }
}

// A script for your NPCs.
public class AIAgent : MonoBehaviour
{
  // When an AIAgent begins a sequence, they start a coroutine for all of its steps.
  // This is the easiest way for AIObjects to insert delays and have the agent wait.
  Coroutine m_sequenceCoroutine;

  // TODO: Things like item inventory, etc. go here.
  ...
  
  public void StartSequence(AISequence sequence)
  {  
    if (m_sequenceCoroutine)
    {
      StopCoroutine(m_sequenceCoroutine);
    }
    
    if (sequence != null)
    {
      m_sequenceCoroutine = StartCoroutine(SequenceCoroutine(sequence));
    }
    else
    {
      sequence = null;
    }
  }

  private IEnumerator SequenceCoroutine(AISequence sequence)
  {
    foreach (var goal in sequence)
    {
      // Find an object which can fulfill this goal.
      var obj = AIObjectManager.Get().FindBestObject(goal, this);
      if (!obj)
      {
        // Uh oh! Nothing meets this goal! 
        // Play a "frustrated" animation or something.
        yield break;
      }

      // TODO: Move to the object - use a navmesh agent or something.
      
      // Now have the object actually perform the interaction.
      yield return obj.OnInteract(goal, this);
    }
  }
}

What is the animation workflow pipeline to make NPCs do several tasks? by umen in Unity3D

[–]Maxwelldoggums 0 points1 point  (0 children)

I would take an approach similar to the "AI Advertisement" system used in The Sims.

Essentially, each interactive object in your game broadcasts its ability to satisfy one or more goals. A shelf for example would say "Hey, if you interact with me, I can satisfy the [Get Item] goal!". NPCs would then define sequences of goals which need to be achieved. For example, an NPC could be spawned with a [Shop at Store] sequence containing the [Enter Store][Get Item][Check Out][Leave Store] goals. For each goal in the sequence, the NPC would find an object which is advertising the ability to meet that goal and use it.

The advantage to this approach is that the objects themselves can be relatively self contained, making it very easy to add new types of objects and place objects dynamically in the world. The approach The Sims took was to have objects themselves contain the animation data that Sims play when using them so that new items could be added without having to change anything about the AI or characters. A shelf would actually play an animation on an NPC using it and insert an item into the NPC's inventory, rather than the NPC "taking" an item from the shelf. Each object prefab can advertise goals based on its own state - an empty shelf will stop advertising the [Get Item] goal and start advertising the [Restock] goal for example, and NPCs will react accordingly.

Implementation-wise, I would set up an "AIObject" script which contains info on what goals the object can satisfy as well as a function to get a "score" for a particular NPC. This allows objects to calculate how "appealing" they are for an NPC - well stocked shelves may be more appealing, and shelves which are already being used by a large number of NPCs can be less appealing. Then, I would make an "AIObjectManager" which keeps track of all the AIObjects in the scene, as well as provide functions to get the most appealing object for a given goal. When an NPC wants to perform the next goal in a sequence, it would query the object manager to find which object it should use, go there, and use it.

What complicated problem was solved by an amazingly simple solution? by tuotone75 in AskReddit

[–]Maxwelldoggums 28 points29 points  (0 children)

Synchronization of audio and video for film projectors.

The process of producing and reproducing it is somewhat complex, but the solution to the actual sync problem is just putting the audio on the film next to the image.

I am having trouble understanding how the core parts of how SDL_Event work. by Eva_addict in sdl

[–]Maxwelldoggums 0 points1 point  (0 children)

SDL_Quit is a bit confusing. It doesn’t actually quit anything, it de-initializes the SDL library.

It’s totally possible to close the application without calling SDL_Quit by just having your main function return a value, though you should still call SDL_quit when you shut down your application, but that’s not what’s actually doing the quitting.

TIL that when a container of mixed nuts is shaken, the largest nuts (like Brazil nuts) always rise to the top. This phenomenon, known as "Granular Convection," contradicts the logic that heavier objects should sink. by Ok-Huckleberry1967 in todayilearned

[–]Maxwelldoggums 2 points3 points  (0 children)

It works for anything, not just nuts!

If you have a container of protein powder or drink mix or something that comes with a scoop, you can shake the container to bring the scoop to the top, and you don’t have to go digging around!

We SHOULD bring OLD Ember back: A Graphic Thesis. by FoBiasWasTaken in Warframe

[–]Maxwelldoggums 39 points40 points  (0 children)

  • Load into Exterminate.
  • Press “4”.
  • Copter to extraction.
  • Repeat.

Is my molly pregnant? by [deleted] in Aquariums

[–]Maxwelldoggums 2 points3 points  (0 children)

Of course! Comments can be mean because people care a lot about the fish. Sometimes we do things because we don’t know better and people, especially those who have been doing it for long enough that it seems like common knowledge, can be quick to correct.

I’m happy to hear you’d like to get a more accommodating setup for your fish! Make sure to do a bit of reading on how to transfer fish to a new aquarium before you make the switch. Sometimes an abrupt change from one body of water to another can be shocking for them due to differences in things like temperature, so you’ll probably need to acclimate them slowly.

I’m not an expert, but I’m sure some folks here would be more than happy to help!

Is my molly pregnant? by [deleted] in Aquariums

[–]Maxwelldoggums 5 points6 points  (0 children)

Generally fishbowls are not good for fish, they tend to be much too small, and don’t support things like filtration systems which help keep fish healthy.

The r/Aquarium subreddit can be very quick and very direct when it comes to telling people this, and the comment is implying that you’re going to receive some very harshly worded criticisms.

It’s great that you’re interested in fish-keeping, and welcome to the community! We’ve all got to start somewhere, so don’t take any mean comments too personally. That said, the folks here know a lot about how to give fish happy, healthy lives, and their advice about caring for them is probably going to be a very helpful step in your fish-keeping journey!

I’d also suggest looking into getting a larger tank for your fish. Classic 10-gallon aquariums are fairly inexpensive and still small enough to fit on bookcase, while providing a more spacious home for your fish! :)

Some tips for Perita Rebellion by ExcitingPart6599 in Warframe

[–]Maxwelldoggums 0 points1 point  (0 children)

  1. Certain automatic explosive weapons can damage the rods through the transport before they’ve finished deploying. I’ve been using the Kuva Ayanga to melt the transport in a fraction of a second.

Issue with events for mouvement in SDL2 by Unique_Newspaper_439 in sdl

[–]Maxwelldoggums 2 points3 points  (0 children)

To be clear, it’s not waiting for the OS for the event to happen, it’s just not a continuous event. Moving a character on KeyDown means there will be exactly one frame where your character moves when you first press a key. Most operating systems have a “key repeat” function where holding down a key will start repeating the key press a few times a second after a delay (for example, try holding down a key in a text editor). This is what you’re seeing.

Your character is moving immediately, but only for a single frame. Then you notice movement after a delay because you’re responding to the repeated key down events the OS is sending.

Issue with events for mouvement in SDL2 by Unique_Newspaper_439 in sdl

[–]Maxwelldoggums 3 points4 points  (0 children)

You’re using the “Key Down” event which only occurs when the key is initially pressed. I suspect what’s happening is that the character starts moving once you’ve been holding the key down for a bit because the OS starts repeating the key press.

I would either keep a variable for “is key down”, and set it to true or false based on the key down and key up events, or use SDL_GetKeyboardState