You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+11-6
Original file line number
Diff line number
Diff line change
@@ -98,14 +98,16 @@ This code is interesting for the following reasons :
98
98
99
99
- Its all written in Zig
100
100
- It uses the excellent http.zig library https://github.com/karlseguin/http.zig
101
-
- Note that the router is decorated inside the Game object ... the implications of this are that it is possible to create 'web components' using this
102
-
zig/htmx approach that are all self contained, and can be imported into other projects, without having to know about connecting up routes. Interesting.
103
-
- Uses SSE / Event Streams to keep it all realtime updates with pub/sub from multiple players
101
+
- Its about as simple as doing the same thing in Go, there is really nothing too nasty required in the code.
102
+
- The router, and all the HTML contents is part of the Game object ... the implications of this are that it is possible to create 'web components' using this
103
+
zig/htmx approach that are all self contained, and can be imported into other projects, without having to know about connecting up routes, or pulling in content. Interesting.
104
+
- Uses SSE / Event Streams to keep it all realtime updates with pub/sub from multiple players. Is simple, and it works.
105
+
- Demonstrates how to do threading, thread conditions / signalling, and using mutexes to make object updates thread safe.
104
106
- No websockets needed
105
107
- There is pretty much NO JAVASCRIPT on the frontend. It uses HTMX https://htmx.org ... which is an alternative approach to web clients, where the frontend is pure hypertext, and everything is done on the backend
106
108
- There is a tiny bit of JS, to update the session ID, but im still thinking up a way of getting rid of that as well.
107
-
- Uses std.fmt.print() as the templating engine. I didnt know before, but you can used named tags inside the comptime format string, and use those to reference fields in the args param.
108
-
Actually makes for a half decent templating tool.
109
+
- Uses std.fmt.print() as the templating engine. I didnt know before, but you can use named tags inside the comptime format string, and use those to reference fields in the args param.
110
+
Actually makes for a half decent templating tool, without having to find and import a templating lib.
109
111
110
112
111
113
## HTMX thoughts
@@ -115,7 +117,10 @@ Yeah, its pretty cool, worth adding to your toolbelt. Not sure its really a 'rep
115
117
What it is 100% excellent for though is for doing apps where there is a lot of shared state between users. (Like a turn based game !) In that case, doing everything on the server, and not having any state
116
118
at all on the frontend to sync, is really ideal. Its a good fit to this sort of problem.
117
119
120
+
Its super robust. You can do horrible things like reboot the backend, or hard refresh the front end(s) ... and it maintains state without a hiccup, and without needing any exception handling code at all.
121
+
Very nice. It would be a nightmare doing this in react.
122
+
118
123
There are some very complex things you could do with a turn-based-multiplayer-game type of model though (doesnt have to be a game even) And being able to do that without touching JS, or
119
124
writing a tonne of code to synch state on the frontends is really nice.
120
125
121
-
Its also a reasonable model for doing shared state between GUI frontends, just using the HTTP/SSE protocol too.
126
+
Its also a reasonable model for doing shared state between GUI frontends, just using the HTTP/SSE protocol too. Its just HTTP requests, so the networking is totally portable.
/// reboot will reboot the server back to the vanilla state. Call this when everything has timed out, and we want to go right back to the original start
143
150
fnreboot(self: *Self) void {
144
151
self.game_mutex.lock();
145
152
deferself.game_mutex.unlock();
@@ -153,6 +160,7 @@ fn reboot(self: *Self) void {
153
160
self.signal(.init);
154
161
}
155
162
163
+
/// restart will set the game back to the setup phase, using the current Game parameters
0 commit comments