Tanguy ⧓ Herrmann@dolanor@hachyderm.io

Been following Fat Old Yeti/Idiot Coder tutorial on how to create a rogue-like in Go:
fatoldyeti.com/posts/roguelike

As ebiten doesn't work on my ubuntu anymore, I made the choice to use g3n.rocks as I wanted to play with it for so long.

I'm still at step 2, but adapting g3n to just do 2D work without knowing g3n that much and being rusty in OpenGL made it a little bit more complex.

I just want to make g3n be abstracted and render in 3D some really 2D game mechanics. It's a little bit challenging as some loops are not at the same place (adding tiles to a 3D scene doesn't make you recalculate their position in the render loop, so you need to account for them only once).

And having my children challenge me along the way: "hey, can you make the wall nicer?", "can you add a 3D model instead".

So I dug into how to load a material with Displacement map, normal map, etc.

I'm having fun and I'm pretty proud about the result after a few hours of tinkering.

#golang #3d #g3n #ebiten #blender3d #roguelike

A realtime 3D render of of some kind of colorless figuring in the corner of a room with adorned wall.
2 2

불러오는 중…

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

IT'S ALIVE!

Now I can move the character.

It was way more adaptation as ebiten is more immediate mode and g3n is more retained, but I kind of like it as it is. I don't have a render loop, it is handled by the 3D engine.
I just use the update loop to update the position based on KeyPress events.

Problem is, now it interacts with the camera control as well, so I get to move my character and change the camera settings as well.

#golang #gamedev #3d #g3n

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

I also implemented the collision system in ECS following fatoldyeti.com/posts/roguelike

But some places I could go through walls, and sometimes I was blocked by some invisible blocks.
I couldn't see the pattern and the tiles seemed to be at the right places. So I decided to debug it the classical way: `printf` to the rescue!

`.` are the floor and `#` are the walls. They should be all around, but clearly, they aren't. There is a pattern to figure out, but it eluded me until I counted it.

For performance reason, all the tiles were added in a slice, instead of slices of slices.
I added them one after another in a double loop.

Basically, I inverted x and y, and so it was creating a slice of column first then rows. But I was displaying them and computing them by rows first and column next.

Pretty basic error, but the debug print made it all clear very fast.

#golang #g3n #roublard #3d #RogueLike

a textual visualization of the tiles in the slices of tiles. They don't look how they should.
a textual depiction of the room surrounded by # walls
The incriminating code with the correct double loop iterating y first, then x.

```go
func (l *Level) CreateTiles() []Tile {
	gd := NewGameData()
	tiles := make([]Tile, 0, gd.ScreenHeight*gd.ScreenWidth)

	for y := range gd.ScreenHeight {
		for x := range gd.ScreenWidth {
```
Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

it highlighted a problem where the display didn't show the logic, which is a code smell to me, and that's something I introduced while adapting to 3D.

On ebiten, the entities will be drawn every frame based on their location.
On g3n, I set their position at creation, and then the engine will render them where they are positioned. But the collision would happen on another part.

I wonder how I can make sure that WYSIWYG without coupling logic too much.

Pxl Phile@ppxl@social.tchncs.de
@dolanor@hachyderm.io 님에게 답글

@dolanor reading your text, I guess an mediator/event driven pattern could address this.

Having built an ego shooter decades ago, I know it's a PITA to get things right. But 3D games are an example of Things-need-to-go-fast and additional computational iterations could skew the view building/physics calc etc. In my view that's the reason they end up rather strongly coupled.

An event bus controller could even trigger different goroutines for different calculation types like model change, view render, physics.

Synchronizing all these at the right game tick would be a challenge. Some might be cancelled or rendered if even wrong to benefit following calls of the same type.

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글
Tanguy ⧓ Herrmann@dolanor@hachyderm.io

My 3D rogue-like attempt now has a field of view implemented and it dynamically updates on each move of the player.

That's pretty cool (at least for me)

(yes I said fog of vision instead of field of view, the next step is fog of war, but I mixed both together)

#gamedev #golang #3d #dev

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

I finally made it! Till the end of the tutorial!

web.archive.org/web/2024111123

I did the minimum to have the same behavior of the game.

Now I intend to refactor to remove all the code that used my fake ebiten library to have a minimal diff with the original upstream code.

And then, I will reorganize the code to more fit my style and g3n handling of game/render loop.

#golang #gamedev #3d #g3n #ebiten #roguelike #ecs

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

All right, done for the night. That was a productive session.
Sprinkled with some weird bugs/exceptions.
I had to hack around at some point to not be stuck in trying to figure out everything.

Ugly hacks, but I could focus on improving big chunks on the other side.

For now, 0 loss of feature, but a cleaner design. Me likey!

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

I'm finally gonna start migrating my projects from GitHub to Codeberg.

I have my own gitea instance for years (and I should update it to forgejo…) for my own private projects. So Codeberg makes complete sense for hosting my open source projects.

So, roublard is now available at codeberg.org/dolanor/roublard

My other "big" project is rip.rest . I have some more work to migrate it as I depend on it on a dev project and don't want to disrupt it more.

#golang #github #codeberg #gamedev #roguelike

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

Anyway, I advanced quite well lately thanks to the holidays.

Mostly reorganizing the code to be able to start adding more advanced rules and game mechanics.

I even added a very quirky death animation which is a double spin followed by a face plant. Totally ridiculous, but my kids and I loved it, so, for now, it stays.
Also, regarding that, goroutines are so great. I just start the animation in a goroutine, and forget about it.

#golang #gamedev #3d #g3n #roguelike #ecs

The 3D avatar of the roublard game surrounded by 2 finally dead skeletons in a dark dungeon showing normal maps textured floor and a faraway wall.
Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

I've done some good progress in refactoring the codebase, and it is to a point where I feel I want to add some features. So, since the weekend I did:

- imported a package I created for another game of mine (unpublished) so I can have advanced display of RPG dice roll information.
- integrated it in the current HUD log
- added some progress bar in the HUD (gui.Slider) to display health
- hacked in (30mn) a somewhat minecraft-like ability to create wall when clicked on a tile.

#golang #gamedev #3d #ecs #g3n #roguelike

A screenshot of roublard, a 3D rogue like with the player next to a defeated unicorn goblin janitor on a dungeon floor.

The log show details of the dice rolls:
Hit: 15 (1d20) + 1 (strength modifier) + 2 (weapon) = 18 VS AC: 10 (Base) + 7 (Reinforced leather boxer) = 17
Damage: 10 (1d10) + 2 (Lightning) = 12
Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

I've been blindly applying ECS with the tutorial.
Some part didn't make sense at all, and I thought it should be designed differently.

I do understand ECS theoretically, but in general, my brains gets it better when it gets concrete.

Little by little, it seems that ECS is clicking.
Especially when I started to code the attack logic. I feel I would have struggled to gather everything I needed to be able to compute that in a different way. So, YAY ECS.

#gamedev #ecs

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

In my quest to understand it more and dig deeper, I read this article: replicaisland.blogspot.com/200

And basically, from what I understand, it's mostly about using composition instead of inheritance. The usual culprit in software design since the GoF Design Patterns book.

Anyway, Go is designed with composition first hand, so I guess I'm in good company. And I'm wondering if I actually need an ECS framework or whatever.

#gamedev #ecs #golang

Tanguy ⧓ Herrmann@dolanor@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

A few years back, I started a video game as well, but never finished as it was multiplayer, so of course, it was too complicated to finish quickly.

In trying to create a generic system to compute those kind of values used in different part of the game, I arrived to some design of generic dynamic values that can be filtered when needed.

So I guess, I was making this ECS system without knowing it (at least the EC part of it). But I had the tags, the filter, the dynamic and generic. Nice little ego boost. Especially it was YEARS before I knew about ECS.

I might actually integrate it in this current game. Let's see how it evolves.

#gamedev #ecs #golang

rdnt:~$ _@rdnt@hachyderm.io
@dolanor@hachyderm.io 님에게 답글

@dolanor in ECS, you just don't have 'aggregate structs', you have plain arrays of components, and an 'entity' is simply some indexes in those components. Imagine a player entity actually simply being { positions[n], movement[m], health[o] }.

When you want to run a system, you would normally have to loop all 'entities', but the entities might have data irrelevant to the system in question. And they will, otherwise you would have pointers, which would be even worse performance-wise.

So instead, you loop the components themselves, only those relevant to the system. And the data access becomes a lot more performant, since the CPU will already have next entries from the two/three being-iterated slices in its caches.

ECS is an optimization, believe it or not. Composition is the elegant property that you want for sure. And ECS can be added on top to make data access much more performant.