-
Notifications
You must be signed in to change notification settings - Fork 10
How to Wire Up libxayagame in C#
Before you get started, you'll need libxayagame. There are statically linked binaries available here (they're in the "XayaStateProcessor" folder). You'll also need XAYAWrapper. It wraps the C++ libxayagame for use with C#. You can download that here. You'll also need to make RPC calls. That can be done any way you wish, but we've forked BitcoinLib and modified it for XAYA. You can get that project here. XAYAWrapper uses BitcoinLib and exposes it through xayaGameService
, so you'll need that DLL as well.
The following shows how to wire up libxayagame.
In your project:
-
Add a reference to XAYAWrapper by either adding the DLL or adding the project and then adding a reference to the project.
-
Add a
using
for XAYAWrapper.using XAYAWrapper;
-
Create a member variable for the wrapper.
XAYAWrapper wrapper;
-
In a thread, construct XAYAWrapper and call its Connect method.
wrapper = new XayaWrapper(appPath, host, "8900", ref result, CallbackFunctions.initialCallbackResult, CallbackFunctions.forwardCallbackResult, CallbackFunctions.backwardCallbackResult); result = wrapper.Connect(appPath, FLAGS_xaya_rpc_url, "8900", "0", "memory", "gamename", appPath + "\\..\\XayaStateProcessor\\database\\", appPath + "\\..\\XayaStateProcessor\\glogs\\");
-
In another thread, wait for notifications from the wrapper.
wrapper.xayaGameService.WaitForChange();
-
When a change comes in, get the current game state and deserialise it for your GameState definition.
BitcoinLib.Responses.GameStateResult actualState = wrapper.xayaGameService.GetCurrentState(); state = JsonConvert.DeserializeObject<GameState>(actualState.gamestate);
-
Send the notification to the front end.
sendingWorker.ReportProgress(0, state);
-
-
In the front end, get the game state from the notification thread and then update the front end.
UpdateMyGame((GameState)e.UserState);
-
Implement your game logic the 3 callbacks defined in XAYAWrapper.
- initialCallback
- forwardCallback
- backwardsCallback
Tutorials for how to implement those callbacks will be coming soon.
- Step 0: Blockchain Basics
- Step 1: xayad <⸺ start here
- Step 2: The Game State Processor
- Step 3a: libxayagame Component Relationships
- Step 3b: Compile libxayagame in Windows
- Step 3b: Compile libxayagame in Ubuntu
- Step 4: Run xayad for Games
- Step 5: Hello World! in C++
- Step 5: Hello World! in C#
- Step 5: Hello World! with SQLite
- Step 6a: Mover Overview
- Step 6b: Mover Console
- Step 6c: Mover Unity
- libxayagame Component Relationships
- How to Compile libxayagame in Ubuntu 20.04.03
- How to Compile libxayagame in Ubuntu 22.04
- How to Compile libxayagame in Windows
- Xayaships (How to get started playing)