Mike and I have been talking about how to easily build simple networked social applications with ReactVR for a while, so I spent some time hacking over the Christmas break to see if I could build a ReactVR version of the pairs game in Oculus Rooms. Pairs is simple and fun, but also interesting as it’s real time and has the potential to generate conflicting updates that need to be resolved.
Redux seemed like a promising starting point as it reifies events and allows flexible event processing in a similar way to MASSIVE-3. I used websockets as they are already supported by ReactVR along with wsrelay to network the clients.
With those pieces in place the simplest way to network the clients is to implement a middleware function to send every action generated in one client to all the others. In the case of actions which show a tile this is sufficient as the action is idempotent. If two players click on a square at the same time, the order that the actions are reduced in doesn’t matter: in either case the result is that the element is revealed. We can exploit the idempotency by optimistically processing the action locally before sending it to other clients to minimise network latency.
Scoring is trickier. While each client can tell when a pair has been revealed, only the first player to reveal the pair should score a point. As the actions to reveal tiles are potentially processed in different orders on each client that could lead to inconsistent scores even if only the first is processed. A simple way to avoid this inconsistency is to nominate one client to be the master and only have that client generate score actions. This can be implemented as another middleware to avoid generating actions inside a reducer.
The master client can also be made responsible for sending the current state of the simulation to new clients to support late joining.
With those parts done the app is usable and makes an interesting example of one possible way to network ReactVR applications. This was the first time I’d used React, ReactVR or Redux and I was very impressed by how easy to use and flexible they are. With the addition of some small pieces of middleware Redux can be used to implement a distributed simulation with flexible consistency mechanisms to trade off latency and consistency. The pairs example shows that even within a simple application applying different consistency mechanisms to different actions and parts of the application state is useful.
The next things to experiment with are using WebRTC to allow peer to peer communication between clients to further reduce latency, add a server to allow trusted and hidden state and allowing clients to subscribe to a subset of actions to allow heterogeneous clients and interest management.
If you’d like to play the ReactVR version of pairs or see the rest of the code, it’s available on github here.
Creating A Safe Environment For People In VR
At the 3rd Party Dev State of the Union at EVE Fanfest 2016 earlier this year, CCP FoxFour drew my attention to a limitation of the current approach used by crestmatic to generate CREST documentation: it only discovers resources always reachable from the API root from the perspective of the ...read more
Strange Tales From Other Worlds
Towards A Generic Media Type System
The early days of RESTful hypermedia API design tends to involve lots of homogeneous collections. In the case of CREST vnd.ccp.eve.Api-v1 pointed to the logged in vnd.ccp.eve.ccp.Capsuleer-v1 which pointed to a vnd.eve.ccp.CharacterCollection-v1 of contacts which pointed to many vnd.ccp ...read more
A year ago I gave a talk at EVE Vegas about building RESTful CREST applications. My #1 recommendation was to specify representations in requests, but that’s hard to do when there is little documentation on which representations are available and what they contain.
Fortunately CREST is self describing: send ...read more
Free Tests For Everyone!
Modern software development is sometimes colourfully described as being similar to firing tracer bullets at a target. Rather than spending time doing a lot of research, design and specification up front, the smallest, simplest version of the software is built and the feedback gathered from its use is used to ...read more
Investing In Testing
Last year I was talking to an engineer at Droidcon London who was working on an Android app with 100% test coverage. I immediately asked whether he thought 100% test coverage was worthwhile: many software engineering teams strive to achieve 100% test coverage, but few succeed because it’s an ...read more
There have been a number of blog posts recently about exciting new organisational structures. As Cory points out “Every early stage company thinks it has reinvented management”: a very dangerous belief when betting on a new organisational structure can be much riskier than betting on the wrong product.
It starts ...read more
Beyond Time Dilation?
EVE online is a remarkable game. On Monday over 2000 people spent over 20 hours destroying virtual spaceships worth 200,000 USD in real money in what was the likely the largest battle in a video game ever. That EVE is capaple of supporting such large engagements is an amazing ...read more
In mid-2004 I first started exploring Second Life. Version 1.4 had just been released and Philip Rosedale had said in the press release “My fantasy is to be Uma Thurman in Kill Bill, and now I can. I’d pay $10 for her yellow jumpsuit and sword moves and ...read more
Parse By The Sea
Brighton Digital Festival
The Brighton Digital Festival starts this week and I’m very happy to be helping out with Facebook London‘s contributions: Parse By The Sea, a mobile app Hackathon featuring Parse on the 26th of September, and helping to Connect The Brighton Digital Festival by sponsoring Metranet to provide high ...read more