Skip to content

Feature | Parkor GameScript #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1c920a8
We can load the parkor game script
tylerthecoder Jul 17, 2024
dcd3a17
Compiles and jump script works
tylerthecoder Aug 3, 2024
a963caa
Added chunk insert, thx to Addie for chunk id math
tylerthecoder Aug 4, 2024
7a0bef3
Game scripts and chunk stuff
tylerthecoder Aug 10, 2024
6f9505b
Add getting player script and actions from js
tylerthecoder Aug 11, 2024
4ca43ff
App is loading now
tylerthecoder Aug 17, 2024
09bbf0b
refactor entities to a list of components
tylerthecoder Aug 18, 2024
b84b60e
Better Action System
tylerthecoder Aug 19, 2024
6b7d9e4
Almost all vectors build
tylerthecoder Sep 1, 2024
97d097f
All the tests pass!
tylerthecoder Sep 1, 2024
9bc687a
Everything is fucked and idk why, I fixed some of the wrappers
tylerthecoder May 18, 2025
4eb50e9
Can view things in the UI. The chunk rendering is messed up though
tylerthecoder May 18, 2025
0741de7
Rendering the blocks works again
tylerthecoder May 18, 2025
29cd276
Can move around the infinite world again
tylerthecoder May 18, 2025
a13c6f5
Can make gamescripts from js
tylerthecoder May 18, 2025
da7d68e
Request chunks
tylerthecoder May 19, 2025
df6234a
Can seralize entities
tylerthecoder May 19, 2025
f318941
Half way through game serialization
tylerthecoder May 19, 2025
2ff5efc
Sererializing works
tylerthecoder May 19, 2025
b69e209
Serializing the whole game works
tylerthecoder May 20, 2025
031b3cb
Rewrote the server, not tested, much simpler
tylerthecoder May 20, 2025
899f67a
WIP for mp games. added server runner script that handles the logic
tylerthecoder May 21, 2025
5cc1c80
Server is sending chunks and accepting player actions
tylerthecoder May 24, 2025
7f7fc90
Players can see eachother move
tylerthecoder May 24, 2025
9b9d213
Placing blocks works
tylerthecoder May 25, 2025
8908ba3
Making player controls better
tylerthecoder May 25, 2025
b676cea
Jumping and gravity works
tylerthecoder May 25, 2025
a5563ac
Fix rendering
tylerthecoder May 25, 2025
38de105
Collisions are basically perfect now!
tylerthecoder May 26, 2025
de817a5
Much better UI
tylerthecoder May 26, 2025
b88cc7b
belt works again
tylerthecoder May 26, 2025
7f1c03e
better entity ser and desr
tylerthecoder May 27, 2025
7f08c3b
basics of fireballs
tylerthecoder May 27, 2025
13ee641
Fireballs now show up
tylerthecoder May 27, 2025
6187117
Fireballs remove blocks and hurt players.
tylerthecoder May 28, 2025
7474b49
Some server fixes
tylerthecoder May 28, 2025
e1d2d5b
Server games work again
tylerthecoder Jun 3, 2025
7064712
faster chunk insertion
tylerthecoder Jun 4, 2025
4afc4d6
claude made basic form of game config. Needs work
tylerthecoder Jun 6, 2025
723eec6
Game scripts config. Chunk Getting is in rust now
tylerthecoder Jun 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
"gravitable",
"mult",
"toolbelt",
"Tsify",
"tylercraft",
"upsert",
"vecs",
"wasd"
],
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"files.exclude": {
// "bin/": true
},
"rust-analyzer.linkedProjects": ["lib/world/Cargo.toml"],
"search.exclude": {
"**/node_modules": true,
Expand All @@ -26,5 +24,10 @@
},
"editor.suggestSelection": "first",
"eslint.nodePath": ".yarn/sdks",
"typescript.enablePromptUseWorkspaceTsdk": true
"editor.defaultFormatter": "dbaeumer.vscode-eslint",

"typescript.enablePromptUseWorkspaceTsdk": true,
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
9 changes: 9 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"rust-analyzer": {
"linkedProjects": ["./lib/world/Cargo.toml"]
}
}
141 changes: 117 additions & 24 deletions DEVLOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,125 @@
# 06_03_25

I've worked more on optimizing the chunk insertion code. The release build of the app is much faster now and I'm happy with it.

I broke up the game updating code into a bunch of functions that I can run seperately and that is nice.

Next I want to work on setting the options for the game when you start it.

I think I can make it so options can be changed at run time.

# 06_02_25

I got the server working again. I want to fix chunk loading now, the chunks around me load in such a strange way, I can walk up to chunks and not have them load and I don't know why.

I've been profiling the code that inserts chunks, it isn't as optimal as it coudl be, but when I build in release mode it is pretty fast still on my computer when I have a full world generation. I think I shoudl maybe optimize the chunk insertion code a little bit still.

Okay, I brought the chunk insertion time down from around 30ms to 12ms. The biggest thing was removing hash maps and using arrays instead. I hate how slow rust hashmaps are.

# 05_27_25

I reworked the entity serialiaztion yesterday and I'm so happy with it now. Now I'm working on adding the fireballs back. They are working but they don't destory anything yet, I need to make them destroy blocks and hurt players.

What happens if you die? Maybe you just teleport back to the spawn.

Okay, now I'm testing the server again. I've found a couple errors and a lot fo files that didn't build. Now I'm getting an issue with the entity serialization, the components are not being serialized when being saved to the db. Idk what is going on.

# 05_26_25

I made the UI yesterday and it is coming along. I need to figure out what to do next. I think making the belt work seems good.
I also want to add back the fireball entity that breaks a block or injures a player. Then the players have health and they can get more health by eating a food item.

I also need to test the terrain generation and make that work better.I also need to add a button for saving while in single player mode.

# 05_25_25

I've fixed up the server now and multiplayer seems to work. I can now also add blocks to the game again. I don't know what is left for things that I'm confused about, maybe I should just start cleaning everything up now. Could work on mobile development as well.

List of things to do for single player:

- Add gravity and creative mode
- Fix movement controls
- Add back third person view

Claude found a bug that let the player fall through the world and came up with a good fix. That is crazy.

There are still times where the player can go through the world a little and I'm not sure why it happens. It is very rare. But now jumping and gravity works well.

Okay, I have fixed the movement. This is the best I have ever had it. I can run around complicated block structures and not clip through them or teleport. I had to do a better sorting system where I sorted by the amount a collision would move me, not how close one of my faces was to the collision.

# 05_21_25

I've worked on making the server runner. I'm relizing it doesn't make a lot of sense to serpatate out the sp-game-serivce and the runner. The cut between them isn't that clean. I will just make two different runners and then see what logic I need to abstract to make a good UI.

I've been thinking about the chunk flow. The server will be loading chunks with its sandbox game script, the client will also being doing this, but the client requests the chunks from the server instead of the terrain gen. This means the client could request a chunk too soon, but I shoudl probalby just load all the chunks around a player before they join? Maybe I can send them updates via sockets about what the server is doing.

I need to bring back fun loading spinners

Also the game shoudl have the property of chunkRequestor, not the client. The sandbox script shoudl be renamed to "loadchunksaroundentity" script and returns load requests to the game. The game then calls the request function on all chunks that the scripts returned, then the client will get from the server and give them to the local game and it will insert the chunks one by one.

## 05_19_25

We now can serialize the game state and save it to indexdb. It took a while to figure out how to serialize the entities. I went down a rabbit hole trying to get <https://github.com/dtolnay/typetag?tab=readme-ov-file> to work, but it doesn't support wasm-bindgen. I ended up just assuming everything was a player for now.

I've taken the strategy of "find the hardest problem and work on that until you know you can come back later and clean it up".

I've been thinking about how I can turn this into an RL training system. I'm pretty excited to try to do that.

The next hardest thing to me seems to be the server. It seem more complicated to me than it needs to be. This is how I think it should work:

- The server the game on a loop, anytime the game state changes it will be broadcast to all the clients.
- The server can change either because the game performs an action (like spawning an entity) or because the clients send actions to the server.
But I think there is a problem: If the game sends all of these diffs to the client, it will send an update to the client for every single action. That will be too much since the clients can compute the velocity themselves.

I think a good solution to this is to have "script actions" that are generated by game scripts. Then the server can mark the scripts whose actions will be sent to the client.
That way it can exclude scripts like "MovePlayer" but include ones like "SpawnCows" and then the client would not use the SpawnCow script.

I don't think we need to concept of "script actions". The scripts return GameDiffs in there update functions. I can just mark certain scripts to not have their diffs sent to the client.

This way "actions" are things that are predictable updates that are only made by clients. They can be sent over the wire. Scripts are logic that updates the game state in some way but may or may not be sent to the client.

Now when we receive an action from a client, we immediately apply it to the game state and send it to everyone. Then in the server update function, we run the game update, and send the diffs to the clients for only the scripts we want.

The client won't run the SandboxScript. The server will and it will just load chunks around the player. The player renderer then requests the chunks around the player. The render distance should be less than the load distance. So we shouldn't request chunks that aren't loaded. The get chunk logic should likely be moved to a rest endpoint.

Maybe I can use trpc to have everything be typed.

The game-service.ts, players.ts, and server-game.ts should all be combined into a single file.

I made a new SeverGameManager that i smuch much simplier. I'll have to move the game fetching and saving logic somewhere but it is nice.

I think I want it to be the case that players that aren't online are still entites in the game, they are just not moving.

That way I don't have to send welcome messages to everyone when they join. (But I still can for an "online" status) that would just need to be handled by the server instead of the engine and the clients would have differnet state.

Okay, everything is looking better. I haven't tested a thing but I'm going to go to sleep. I need to make a "server-runner" soon that copies a lot of the current runner but has different game scripts and sends actions to the server

## 05_18_25

This repo is in a messy state. It seems like a a lot of work is needed to clean it up. I think I was refactoring to have all of the entity logic in the rust code instead and I was half way through that. I think I'mm going to make a very simple
UI to begin with that uses the rust code and attempts to render everything instead of messing with the server stuff for now.

I got the actions to work in the UI. They are saved and updated. But the chunk rendering is a mess and isn't working.

Did a lot of work today making everything work with the UI. The wrapper isn't really needed as much anymore. I was half way through getting serializing to work but it isn't really done yet, some values aren't being saved to the DB.

## 07_11_24
Spent a while trying to figure out why cargo randomly rebuilt dependencies. Figured out it was turbo's issue? So I removed turbo and moved to just using yarn.

I also love the game script idea. It is cleaning things up nicely.
Spent a while trying to figure out why cargo randomly rebuilt dependencies. Figured out it was turbo's issue? So I removed turbo and moved to just using yarn.

I also love the game script idea. It is cleaning things up nicely.

## 06_22_24
Trying to get the collision detection to be better with the player and the world.

Trying to get the collision detection to be better with the player and the world.

Current plan:
- Make a lib funciton that takes a box (pos, dim) and a pos it wants to go to and return the position it can actually go to. If the box would hit something while moving to the new position, then find the shorted distance to make the box not collide with anything.

- Make a lib funciton that takes a box (pos, dim) and a pos it wants to go to and return the position it can actually go to. If the box would hit something while moving to the new position, then find the shorted distance to make the box not collide with anything.

Basic form of function:
- Take all the world points of the block corner and the world points of the new potition. Create a line segment for each of these. Make a function that determines if a line segment is intersecting the world and at which point it intersects. Then find the line segment that minimizes the distance traveled and update all the box positions with that and return the new position and the face that it hit. Only stop applying force to a player if they hit something below them.

- Take all the world points of the block corner and the world points of the new potition. Create a line segment for each of these. Make a function that determines if a line segment is intersecting the world and at which point it intersects. Then find the line segment that minimizes the distance traveled and update all the box positions with that and return the new position and the face that it hit. Only stop applying force to a player if they hit something below them.

## Some other date

Expand Down Expand Up @@ -138,8 +245,6 @@ Real issue seems to be that wasm_pack writes twice.

It now renders the chunks made in rust to the screen using the chunk mesh. Looks like it is including a couple extra faces that aren't needed but that can be fixed with time.



# 2 / 15 / 23

I've still been working here and there. Found a bug in the ray detection on the plane level. Test should be failing need to figure out why.
Expand All @@ -159,6 +264,7 @@ I think a better debug mode to aim to make is a way to have no chunks loaded, bu
Maybe also make it where the block face that is being looked at is highlighted

I guess to hot reload I could have something that looks like this

```
if (hot) {
const state = game.save()
Expand All @@ -169,7 +275,6 @@ if (hot) {

Got the placing of a debug block working, just have to figure out how to place the block when there are no chunks. Do I want to check on the client if the chunk exists before inserting or add an option to automatically create the chunk if one doesn't exist.


# 6 / 10 / 23

Seems like deleting a block doesn't update the mesh.
Expand All @@ -180,41 +285,35 @@ My idea to fix this is to add a dirty array to the chunk that is updated when a

That fixed it but it does not delete the dirty blocks in a chunk ever.


Seems to still be an issue with placing blocks. Sometimes a a block seems to be not found and the ray goes through it. Only seems to happen when x or y cord is negative.

Also might need to have a script that adds `type: module` to the package json in the wasm folder. That is preventing nodejs from loading the wasm module.


Think I want to work on high lighting the block that is being looked at for debug purposes. It will help with this stuff a lot.

Looks like the blocks that aren't being found are because the ray isn't even checking that block sometimes.

Found the issue. I made the ray check many more blocks while marching and it finds the correct one now.


It is now able to be built and deployed. But there seems still be be some minor issues

- infinite terrain generation doesn't work
- Transparent blocks have some issues
- Textures are rotated incorrectly


Working on infinite chunk generation. I want to make it so a single chunk is rendered a frame.

I made it where it now only sends a single chunk at a time to be loaded.


# 6 / 11 / 23

Added turbo repo and linting to the project. Moved everything around to make more sense and I think it is a good structure.
Want to work on fixing terrain gen next.


# 6 / 15 / 23

Multiplayer kind of works not but is not robust at all. And all the textures are rotated incorrectly.


Trying to think about the best way to have an entity be controlled by gpt4. Might want an "EntityController" that moves the entity around. Entities might have a "brain" that is passed in that controls the entity.

Maybe each entity needs a controller. The entity class controls the logic of the entity and the moves it can make. The controller calls those moves in interesting ways. The entity controller for a player might be a socket, a keyboard, or gpt4.
Expand All @@ -224,7 +323,6 @@ type entityController = {
update: () => void
}


examples
keyboardPlayerController {
setup() {
Expand All @@ -244,26 +342,21 @@ socketPlayerController {
}
}


# 08/23/23

Thinking of what to work on next. I think rewritting the terrain generator in rust could be a good project


# 09/03/23

I've got covid, so I've had time to rewrite this is rust a bit. I've created a terrain gen app that does smooth height transitions, generates trees, and generates flowers. Making the trees be spread a part randomly is hard, but I solved it by doing it chunk by chunk and lazily loading the tree in nearby chunks to make sure there is no overlap.
I've got covid, so I've had time to rewrite this is rust a bit. I've created a terrain gen app that does smooth height transitions, generates trees, and generates flowers. Making the trees be spread a part randomly is hard, but I solved it by doing it chunk by chunk and lazily loading the tree in nearby chunks to make sure there is no overlap.

I noticed that the transparency is broken and that some of the textures are rotated incorrectly. I think I will fix that next.



# 09/04/23

Fixed transparency, it was an issue with the new way I'm doing mesh generation. Fixed textured being rotated incorrectly too. Now noticing that a tree's leafs are not included if they go over a chunk boundary. Tackling that next.

Then I'll start thinking about biomes.
Fixed transparency, it was an issue with the new way I'm doing mesh generation. Fixed textured being rotated incorrectly too. Now noticing that a tree's leafs are not included if they go over a chunk boundary. Tackling that next.

Then I'll start thinking about biomes.

# 03/19/23

Expand Down
34 changes: 34 additions & 0 deletions Events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

The game has many scripts. The scripts control entities in the game.

Scripts have a list of actions that can be taken on them. These actions can be serilaized and sent over a server.
Example
(entityId, action, data) = ("player1", "move", "left")

You can query a player for all of its actions

Script data is not serilaized

Example Scripts
JumpScript,
MoveScript,
GravityScript,



Flow of events for user pressing space:
- JS creates a jump event
- Jump event sent over the wire (either to server or worker)
- Game recieves jump events and finds script for it
- Script looks up the event and executes it



Player Places block:
- Js creates a place block event
- Sent over wire
- Game recieves place block event and finds script for it
- Script looks up the event and executes it
- Chunks have been updateds so JS game scripts are called


Loading
Loading