How can independent game-modules block system-wide behaviour

We’ve stumbled at an inconvenient design in a game and wondering, whether there is nothing simpler. The background needs some explaining so I’m sorry for the wall of text.

The setting

We have a player class. The player knows how to walk around in the world. At certain occasions, we want to disable the player from being able to walk around.

At first, we just wanted to stop our player from walking when they open the inventory menu.

The player can also walk around the world and inspect objects. This also is supposed to disable walking for the player.

Here is the problem however: You can open the inventory while inspecting an item. There was a bug: the inventory code did not know about the inspection code. As such, if you closed the inventory during inspection, the inventory code allowed the player to walk again.

Our solution

Naturally, to fix this problem we came up with a layer of indirection. It is somewhat similar to semaphores. In a nutshell our indirection is this class:

class ActionBlocker:  void Block(EBlockableAction) void Unblock(EBlockableAction)  Map<EBlockableAction, Array<Actions>> 

The EBlockableAction describes the type in-game action. For example, we have EBlockableAction::Inventory and EBlockableAction::Inspection.

When the inventory is opened, its code simply calls Block(EBlockableAction::Inventory). Likewise, when the inventory is closed it calls Unblock(EBlockableAction::Inventory). It is similar for the inspection code.

Each enum is assigned to an array of actions: each action can be performed and reversed. In the example above, one action is you can enable walking (perform) and disable walking (reverse).

The Block function goes through each action assigned to the enum and performs the action. The Unblock function tells each action to reverse.

Internally, each action has a counter of how many times it was requested to be performed. The action is only performed initially, i.e. when that counter goes from 0 to 1. Likewise, the action is only reversed, once every code that requested for that action to be performed requests for it to be reversed, i.e. when the counter goes from 1 to 0.

I hope the way the system works is clear now (if not I can further explain it).

The problem with our solution

We expanded this system across the game. The number of enum entries has grown. Each enum also has multiple actions now, e.g. there is an action to toggle mouse cursor visibility, another action for ignoring certain types of keyboard inputs, and more.

What we won: all gameplay code is independent from each other. They do not need to talk to each other to sync blocking certain types of things in-game.

What we lost: It is difficult to debug debug the overall system’s behaviour. When multiple features interact and block the same things, it is hard to know what is really blocking what.

The system is configured in a separate file. Sometimes it is not obvious that a certain gameplay action will block certain other features in the game.

It has happened on multiple occasions that we were left wondering why a certain input key was being ignored by our game. It was then often traced back to a Block call not getting made. This is difficult to debug.

My question(s)

We are looking for a more simple system than this. Do you have feedback / suggestions? Maybe you have encountered a similar scenario in the past and can enlighten your solution.

We’re left wondering whether this solution really is the way to go and it is just the nature of inter-feature dependencies that makes the system so complex, and not the code design itself…

Independent volume for Bluetooth headphones

I have Plantronics BackBeat Fit 2100 headphones. They were working fine with my Moto X4 (Android 9, May 2019 update) until this afternoon, at which point the volume controls stopped working.

Before: the headphone volume and phone system volume were independent. The phone dictated the max volume the headphones could reach. If I set the volume on the headphones to their max, I would get a “Volume maximum” message played through the headphones, but not if I set the phone volume to its max.

After: the headphone volume and phone system volume are tied together. The volume controls on the headphones don’t work at all. If I set the phone volume to maximum, I get the “Volume maximum” message played through the headphones.

I changed the developer option to disable “Absolute” volume, but this had no effect. What could have happened?

A vertex transitive graph has a near perfect/ matching missing an independent set of vertices

Consider a power of cycle graph $ C_n^k$ , represented as a Cayley graph with generating set $ \{1,2,\ldots, k,n-k,\ldots,n-1\}$ on the Group $ \mathbb{Z}_n$ . Supposing I remove an independent set of vertices of the form $ \{i,i+k+1,\ldots,\lfloor\frac{n}{k+1}\rfloor+i\}$ or a single vertex. Then, is it possible to obtain a perfect/ near perfect matching when I remove the independent set of vertices always? If not, then is it possible in case the graph is an even power of cycle?

I hope yes, as we can pair the vertices between any two independent sets of the above form or between the indpendent set and the single vertex to get a maximal matching which is near perfect(in case the order of induced subgraph is odd) or perfect(in case the order of the induced subgraph is even). Any counterexamples? Also, can we generalize this, if true, to any vertex transitive graph, that is, does there exist an indpendent set(non-singleton) of vertices, such that removing that set induces a perfect/near-perfect matching? Thanks beforehand.

Calculating probability of detection given two independent searches

Assume you are searching an area for a missing item. The item is static and does not move.

The probability of the item being in the area is 0.6; the expected search effectiveness is 0.4. Thus, the probability of detecting the item in a given search is 0.6 * 0.4 = 0.24.

Assuming each search is independent of the one before, how do you calculate the combined probability of detection for two searches? Intuitively, it can’t be twice as good as there will be some overlap in searches, nor can it be less than 0.24, if the two searches directly correspond.

window manager independent screen resizing

Recently, I came in contact with screen resizing on windows 7, and I find it very nice. It works like so:

    monitor 1                       monitor 2 -------------------------   ---------------------------- |          |            |   |             |            |  |          |            |   |             |            | |          |            |   |             |            | |   1      |    2       |   |    3        |    4       | |          |            |   |             |            | |          |            |   |             |            | |          |            |   |             |            | -------------------------   ---------------------------- 

Say you have an application opened in monitor 1, currently in focus.

  • If you press mod4+up, it goes fullscreen on monitor 1 (that is, it covers areas 1 and 2).

  • If you press mod4+left, it goes halfscreen on monitor 1 (that is, it covers area 1).

  • If you press mod4+right, it goes halfscreen on monitor 1 (but now it covers area 2).

  • Press mod4+right again, and it goes halfscreen on monitor 2 (area 3)

  • Press mod4+right again, and it goes halfscreen on monitor 2 (area 4)

  • Press mod4+up again, and it goes fullscreen on monitor 2 (areas 3 and 4)

My question: I want to reproduce this behaviour, using a window manager independent trio of programs:

  • p_right moves right: goes from fullscreen in monitor 1 to area 2, to area 3, to area 4
  • p_left moves left
  • p_full makes the app fullscreen on the current monitor
  • p_right and p_left are clever: they only send the program to another monitor if there is one there.

Of course, then I´ll have to connect my applications to my window manager so that the programs get called when a key combination is pressed

How would I go about doing that? Do I have to program against X/Wayland, or is there some utility I can use, and my programs can become relatively trivial bash scripts?

Are the projections of a Gaussian random vector onto two independent isotropic random vectors are independent?

Let $ Z\sim N(0,I_{n})$ be a standard normal Gaussian random vector in $ \mathbb{R}^{n}$ , and let $ V_1$ and $ V_2$ be two isotropic and independent random vectors in $ \mathbb{R}^n$ . They also have the same distribution, although I’m not sure if this matters. Can we say anything about the projection values $ \left<Z, V_1\right>$ and $ \left<Z, V_2\right>$ ?

I know that if $ V_1$ and $ V_2$ are fixed orthogonal vectors, then the projection values are independent. What if they’re not? Thank you in advance!

Architecture for independent modules writing in the same database

Let’s say I have a database with a table called “invoices”.

Then I have a web application where users can manually create invoices against said table. I also have a desktop application that can create invoices programatically. I may have other software modules that can all create invoices.

To manage the operations against the database I’m using an ORM framework (Entity Framework specifically). I want to do this for all the modules.

But, if each module has its own DbContext, the problem I face is that when two modules want to create invoices at the same time, the IDs of the new records will be the same, and then one of the CREATE operations will fail.

To prevent this, my approach is to develop a web API that will act as the only entry point to write new data to the database. The only DbContext I will use for writing data will live inside this API, so colliding IDs will not happen.

Is this solution right? Does this have any possible drawbacks?